2022 Mar 07 11:52 AM

I need to upload this excel file into sap and get the output in the below format using control break statement. but while using sum with 'at end of' event the negative values are getting summed up. For each doc item only one record and it should get added or substracted according to debit or credit.
TYPE-POOLS: truxs.
2022 Mar 07 11:53 AM
TYPE-POOLS: truxs.
2022 Mar 07 12:39 PM
Please merge your code into your question, and please select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!
NB: SUM is still not deprecated, but I would recommend not using it because it's more obvious to anyone what means "subtotal = subtotal + amount", and "total = total + subtotal", and less prone to errors and questions...
2022 Mar 08 1:44 PM
But again the 2nd(item No.) column should also get sorted and and summed up.
for every item number there should be one entry.
2022 Mar 08 4:16 PM
Sorry I can't read your code (missing indentation and color). I suggest that you write easy and understandable code like:
LOOP AT input_lines ASSIGNING FIELD-SYMBOL(<input_line>).
ASSIGN aggregated_lines[ doc_number = <input_line>-doc_number
item_no = <input_line>-item_no ]
TO FIELD-SYMBOL(<aggregated_line>).
IF sy-subrc <> 0. " not found
INSERT VALUE #( doc_number = <input_line>-doc_number
item_no = <input_line>-item_no )
INTO TABLE aggregated_lines
ASSIGNING <aggregated_line>.
ENDIF.
<aggregated_line>-amount = <aggregated_line>-amount + <input_line>-...
ENDLOOP.
Then calculate the sub-totals and grand total.
Then generate the Excel file.
It will make your life easier to have simple code, organized in several sections, and using meaningful names.