Skip to main content

Hello! I've been having trouble with my queries in the Accounts Payable Case Study Training. Specificaclly, in the section 'Transform - Add an Activity: Set or Remove Payment Block'. I've been able to insert all the other activities without any problems, but I'm stuck at this one.

 

Here are the instructions: 

 

celonis-instructions 

Here is the codes I've tried at first:

 

```

INSERT INTO _CEL_AP_ACTIVITIES

(

 _CASE_KEY

, _ACTIVITY_EN

, _EVENTTIME

, _SORTING

)

SELECT

  BSEG.MANDT||BSEG.BUKRS||BSEG.BELNR||BSEG.GJAHR||BSEG.BUZEI AS _CASE_KEY

  , CASE

    WHEN CDPOS.VALUE_NEW IS NULL THEN 'Remove payment block'

    WHEN CDPOS.VALUE_OLD IS NULL THEN 'Set payment block'

  END AS _ACTIVITY_EN

  , CAST(CDHDR.UDATE || CDHDR.UTIME AS TIMESTAMP) AS _EVENTTIME

  , CASE

    WHEN CDPOS.VALUE_OLD IS NULL THEN 20

    WHEN CDPOS.VALUE_NEW IS NULL THEN 30

  END AS _SORTING

FROM BSEG AS BSEG

JOIN BKPF AS BKPF ON 1=1

  AND BSEG.MANDT=BKPF.MANDT

  AND BSEG.BUKRS=BKPF.BUKRS

  AND BSEG.BELNR=BKPF.BELNR

  AND BSEG.GJAHR=BKPF.GJAHR

  AND BSEG.BSCHL = '31'

JOIN CDPOS AS CDPOS ON 1=1

  AND BSEG.MANDT=CDPOS.MANDANT

  AND CDPOS.VALUE_NEW IS NULL OR CDPOS.VALUE_OLD IS NULL

  AND CDPOS.FNAME = 'ZLSPR'

JOIN CDHDR AS CDHDR ON 1=1

  AND BSEG.MANDT=CDHDR.MANDANT 

;

```

 

Than I asked a friend for help and we came up with this new code:

 

```

INSERT INTO _CEL_AP_ACTIVITIES(_CASE_KEY, _ACTIVITY_EN, _EVENTTIME, _SORTING)

SELECT

  TAB_0._ACTIVITY_EN,

  TAB_0._CASE_KEY,

  CAST(CDHDR.UDATE || CDHDR.UTIME AS TIMESTAMP) AS _EVENTTIME,

  CASE

    WHEN TAB_0._ACTIVITY_EN = 'Set payment block' THEN 20

    WHEN TAB_0._ACTIVITY_EN = 'Remove payment block' THEN 30

  END AS _SORTING

FROM (SELECT

  (BSEG.MANDT||BSEG.BUKRS||BSEG.BELNR||BSEG.GJAHR||BSEG.BUZEI) AS _CASE_KEY,

  CASE

    WHEN CDPOS.VALUE_NEW IS NULL THEN 'Remove payment block'

    WHEN CDPOS.VALUE_OLD IS NULL THEN 'Set payment block'

  END AS _ACTIVITY_EN,

  BSEG.MANDT AS MANDT

  FROM BSEG

  JOIN CDPOS ON BSEG.MANDT = CDPOS.MANDANT

    AND (CDPOS.VALUE_NEW IS NULL OR CDPOS.VALUE_OLD IS NULL)

    AND CDPOS.FNAME = 'ZLSPR'

    AND BSEG.BSCHL = '31') AS TAB_0

  JOIN CDHDR ON TAB_0.MANDT=CDHDR.MANDANT;

```

 

For some reason, I keep getting the following error:

 

`Execution error: ERROR: Execution time exceeded run time cap of 00:20`

 

 

I don't know what's going on. Can anybody help me understand what I should do to make the query work?

The error message suggests that the execution of the SQL statement is taking too long and exceeds the runtime cap of 20 minutes. This can happen due to various reasons, such as large data volume, slow performance of the database server, or an inefficient query design.

 

I don't see any logical issue with the query, but removing the subquery and testing the same in a different environment could also help to determine if the issue is related to the query itself or the environment in which it's running.

 

 

INSERT INTO _CEL_AP_ACTIVITIES (_CASE_KEY, _ACTIVITY_EN, _EVENTTIME, _SORTING)

SELECT (BSEG.MANDT||BSEG.BUKRS||BSEG.BELNR||BSEG.GJAHR||BSEG.BUZEI) AS _CASE_KEY,

CASE

WHEN CDPOS.VALUE_NEW IS NULL THEN 'Remove payment block'

WHEN CDPOS.VALUE_OLD IS NULL THEN 'Set payment block'

END AS _ACTIVITY_EN,

CAST(CDHDR.UDATE || CDHDR.UTIME AS TIMESTAMP) AS _EVENTTIME,

CASE

WHEN CDPOS.VALUE_NEW IS NULL THEN 30

WHEN CDPOS.VALUE_OLD IS NULL THEN 20

END AS _SORTING

FROM BSEG

JOIN CDPOS ON BSEG.MANDT = CDPOS.MANDANT

AND (CDPOS.VALUE_NEW IS NULL OR CDPOS.VALUE_OLD IS NULL)

AND CDPOS.FNAME = 'ZLSPR'

AND BSEG.BSCHL = '31'

JOIN CDHDR ON BSEG.MANDT = CDHDR.MANDANT;


The error message suggests that the execution of the SQL statement is taking too long and exceeds the runtime cap of 20 minutes. This can happen due to various reasons, such as large data volume, slow performance of the database server, or an inefficient query design.

 

I don't see any logical issue with the query, but removing the subquery and testing the same in a different environment could also help to determine if the issue is related to the query itself or the environment in which it's running.

 

 

INSERT INTO _CEL_AP_ACTIVITIES (_CASE_KEY, _ACTIVITY_EN, _EVENTTIME, _SORTING)

SELECT (BSEG.MANDT||BSEG.BUKRS||BSEG.BELNR||BSEG.GJAHR||BSEG.BUZEI) AS _CASE_KEY,

CASE

WHEN CDPOS.VALUE_NEW IS NULL THEN 'Remove payment block'

WHEN CDPOS.VALUE_OLD IS NULL THEN 'Set payment block'

END AS _ACTIVITY_EN,

CAST(CDHDR.UDATE || CDHDR.UTIME AS TIMESTAMP) AS _EVENTTIME,

CASE

WHEN CDPOS.VALUE_NEW IS NULL THEN 30

WHEN CDPOS.VALUE_OLD IS NULL THEN 20

END AS _SORTING

FROM BSEG

JOIN CDPOS ON BSEG.MANDT = CDPOS.MANDANT

AND (CDPOS.VALUE_NEW IS NULL OR CDPOS.VALUE_OLD IS NULL)

AND CDPOS.FNAME = 'ZLSPR'

AND BSEG.BSCHL = '31'

JOIN CDHDR ON BSEG.MANDT = CDHDR.MANDANT;

Thank you for trying to help!

 

I don't have a different environment to testthe code. I've tried the code you've suggestedm but the same error is thrown. I've tried running the code without the INSERT INTO bit (starting at SELECT) and I could visualize the table in the output. The error is thrown everytime I try to insert the data into the activity table.

 

 


Reply