Skip to Content
-1
Former Member
Jan 10, 2018 at 09:45 PM

HANA Stored procedure logic to loop through each line item

2526 Views

Hi,

I need some urgent help.

I'm need to join BKPF and BSEG tables and using fields like BKPF.TCODE, BSEG.KOART I have to derive a new column value with some flag.

My end result needs to have one entry per document number and one category based on my conditions. But I need to evaluate each line item for multiple conditions and based on the overall result I need to derive the flag value per document number.

I am trying to use a case statement for the conditions and a subquery but I am having difficulty figuring out how to loop through each line item and derive the flag for each document number. This is an example of the query I am trying to use for one of the rules I have. Thank you and any help is greatly appreciated!

SELECT "BELNR, 'XXXXXX' AS CATEGORY

FROM "table_BKPF_BSEG" A

WHERE"BELNR" IN

(SELECT B."BELNR "FROM "table_BSEG"

WHERE A."BELNR" = B."BELNR"

AND ((A."TCODE"='XXXX' AND B."KOART"='X')

OR

A."TCODE"='XXXX')

GROUPBY "BELNR"

)

ORDERBY "BELNR"