Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Applies to:

This is a code sample which applies to SAP ABAP Code.

Summary

This 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:  

   
Company:     Selligence Technologies Services Pvt. Ltd.
Created on:    04 August 2009
Author(s) Bio
Shaik Sajid is a Senior ABAP Consultant. He has been involved in various SAP Projects ( such as Product Development, Upgrade, End to End R/3 Implementation ) as a Technical Consultant in ABAP.

Functionality

When 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).
Programmers may need to do validation with this total amount, either in their Custom report or User exits or Enhancements.
So the code in this tutorial shows how to calculate the total amount of the GL Account Line items for a Particular GL Account and Company code combination (i.e., the logic behind the calculation of Total Amount for Transaction FBL3N).

Source Code

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT 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

Click to visit...

Useful Information

The Code shows how to Calculate the Total Amount which you get in the Report RFITEMGL (transaction FBL3N).