F ALV Subtotal Program in SAP ABAP | CodeTheta

ALV Subtotal Program in SAP ABAP

October 11, 2019

Code :
REPORT ZVP_ALV_SUBTOTAL.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_VBAP,
        VBELN TYPE VBAP-VBELN,
        MATNR TYPE VBAP-MATNR,
        POSAR TYPE VBAP-POSAR,
        NETPR TYPE VBAP-NETPR,
      END OF TY_VBAP.

DATAIT_VBAP TYPE TABLE OF TY_VBAP,
      WA_VBAP TYPE TY_VBAP,

      IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT TYPE SLIS_FIELDCAT_ALV,
      IT_SORT   TYPE SLIS_T_SORTINFO_ALV,
      WA_SORT   TYPE SLIS_SORTINFO_ALV,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV.


SELECT  VBELN
        MATNR
        POSAR
        NETPR
  FROM VBAP INTO TABLE IT_VBAP UP TO 12 ROWS.


WA_FCAT-COL_POS '1'.
WA_FCAT-FIELDNAME 'VBELN'.
WA_FCAT-SELTEXT_M 'VBELN'.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-COL_POS '2'.
WA_FCAT-FIELDNAME 'MATNR'.
WA_FCAT-SELTEXT_M 'MATNR'.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-COL_POS '3'.
WA_FCAT-FIELDNAME 'POSAR'.
WA_FCAT-SELTEXT_M 'POSAR'.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-COL_POS '4'.
WA_FCAT-FIELDNAME 'NETPR'.
WA_FCAT-SELTEXT_M 'NETPR'.
WA_FCAT-DO_SUM 'X'.
APPEND WA_FCAT TO IT_FCAT.

WA_SORT-SPOS '2'.
WA_SORT-FIELDNAME 'MATNR'.
WA_SORT-UP 'X'.
WA_SORT-SUBTOT 'X'.
APPEND WA_SORT TO IT_SORT.


WA_LAYOUT-COLWIDTH_OPTIMIZE 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
   IS_LAYOUT                         WA_LAYOUT
   IT_FIELDCAT                       IT_FCAT
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
   IT_SORT                           IT_SORT
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          IT_VBAP
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.


Output :

IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment