Applies to:This is a code sample which applies to SAP ABAP Code. SummaryThis Article has the code for the Calculation of the total amount of the GL Account Line items (FBL3N). That is when the transaction FBL3N is run, the standard SAP Report shows the Total Amount for the line items belonging to a particular GL account. Now sometimes in Custom Programs it would be necessary to have validation with this Total Amount. So in the Custom Program we can use this code for the calculation of the Total amount. Author: FunctionalityWhen the Standard SAP Report RFITEMGL (transaction FBL3N) is executed for a GL Account, it would display the Total Amount (does addition and subtraction of the line item's amount). Source Codereport ZTEST171 . *****************Screen Parameters*********************************** parameters: V_HKONT TYPE HKONT OBLIGATORY, V_BUKRS TYPE BUKRS OBLIGATORY. ***********************Data Declaration****************************** TYPES : BEGIN OF ST_BSIS, DMBTR TYPE DMBTR, SHKZG TYPE SHKZG, END OF ST_BSIS. DATA: IT_BSIS TYPE TABLE OF ST_BSIS, WA_BSIS LIKE LINE OF IT_BSIS. DATA: WA_MAIN_BSIS TYPE ST_BSIS. "Work Area, Actual Total amount will be stored ************************Data Initialisation*************************** start-of-selection. REFRESH : IT_BSIS. CLEAR : WA_MAIN_BSIS,WA_BSIS. ********************Actual Code for Calculating Total Amount********** SELECT * FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSIS WHERE BUKRS EQ V_BUKRS AND HKONT EQ V_HKONT. IF SY-SUBRC eq 0 and IT_BSIS is not initial. LOOP AT IT_BSIS INTO WA_BSIS. IF WA_MAIN_BSIS-DMBTR IS INITIAL AND WA_MAIN_BSIS-SHKZG IS INITIAL. WA_MAIN_BSIS-DMBTR = WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = WA_BSIS-SHKZG. ELSE. IF WA_BSIS-SHKZG EQ 'S'. " S indicates Positive IF WA_MAIN_BSIS-SHKZG EQ 'S'. WA_MAIN_BSIS-DMBTR = WA_MAIN_BSIS-DMBTR + WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'S'. ELSEIF WA_MAIN_BSIS-SHKZG EQ 'H'. IF WA_MAIN_BSIS-DMBTR GT WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'H'. WA_MAIN_BSIS-DMBTR = WA_MAIN_BSIS-DMBTR - WA_BSIS-DMBTR. ELSEIF WA_MAIN_BSIS-DMBTR LE WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'S'. WA_MAIN_BSIS-DMBTR = WA_BSIS-DMBTR - WA_MAIN_BSIS-DMBTR. ENDIF. ENDIF. ELSEIF WA_BSIS-SHKZG EQ 'H'. " H indicates Negative IF WA_MAIN_BSIS-SHKZG EQ 'H'. WA_MAIN_BSIS-DMBTR = WA_MAIN_BSIS-DMBTR + WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'H'. ELSEIF WA_MAIN_BSIS-SHKZG EQ 'S'. IF WA_MAIN_BSIS-DMBTR GE WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'S'. WA_MAIN_BSIS-DMBTR = WA_MAIN_BSIS-DMBTR - WA_BSIS-DMBTR. ELSEIF WA_MAIN_BSIS-DMBTR LT WA_BSIS-DMBTR. WA_MAIN_BSIS-SHKZG = 'H'. WA_MAIN_BSIS-DMBTR = WA_BSIS-DMBTR - WA_MAIN_BSIS-DMBTR. ENDIF. ENDIF. ENDIF. ENDIF. ENDLOOP. ENDIF. **********************Display Output************************* IF WA_MAIN_BSIS-SHKZG = 'H'. write:/ 'The Total Amount for the given GL Account ', space,V_HKONT,'is -',WA_MAIN_BSIS-DMBTR. ELSEIF WA_MAIN_BSIS-SHKZG = 'S'. write:/ 'The Total Amount for the given GL Account ', space,V_HKONT,'is + ',WA_MAIN_BSIS-DMBTR. ENDIF. Related Content
|
| ||||||||||||