F SAP ABAP ALV Block List program | CodeTheta

SAP ABAP ALV Block List program

November 14, 2019

Code :
REPORT ZVP_ALV_BLOCKED.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_MARA,
        MATNR TYPE MARA-MATNR,
        MTART TYPE MARA-MTART,
        MBRSH TYPE MARA-MBRSH,
        MATKL TYPE MARA-MATKL,
        MEINS TYPE MARA-MEINS,
      END OF TY_MARA.

TYPESBEGIN OF TY_MAKT,
        MATNR TYPE MAKT-MATNR,
        SPRAS TYPE MAKT-SPRAS,
        MAKTX TYPE MAKT-MAKTX,
      END OF TY_MAKT.

DATAIT_MARA TYPE TABLE OF TY_MARA,
      WA_MARA TYPE TY_MARA,

      IT_MAKT TYPE TABLE OF TY_MAKT,
      WA_MAKT TYPE TY_MAKT.

DATAIT_FCAT_MARA TYPE SLIS_T_FIELDCAT_ALV"FOR MARA TABLE
      WA_FCAT_MARA TYPE SLIS_FIELDCAT_ALV,

      IT_FCAT_MAKT TYPE SLIS_T_FIELDCAT_ALV"FOR MAKT TABLE
      WA_FCAT_MAKT TYPE SLIS_FIELDCAT_ALV,

      IT_EVENTS TYPE SLIS_T_EVENT,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

PARAMETERSP_MTART TYPE MARA-MTART.

SELECT MATNR
       MTART
       MBRSH
       MATKL
       MEINS
  FROM MARA INTO TABLE IT_MARA UP TO ROWS WHERE MTART P_MTART.

  IF IT_MARA IS NOT INITIAL.
    SELECT MATNR
           SPRAS
           MAKTX
      FROM MAKT INTO TABLE IT_MAKT UP TO ROWS
      FOR ALL ENTRIES IN IT_MARa WHERE MATNR IT_MARA-MATNR.
  ENDIF.

"FOR MARA TABLE
WA_FCAT_MARA-COL_POS '1'.
WA_FCAT_MARA-FIELDNAME 'MATNR'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MATNR'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '2'.
WA_FCAT_MARA-FIELDNAME 'MTART'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MTART'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '3'.
WA_FCAT_MARA-FIELDNAME 'MBRSH'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MBRSH'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '4'.
WA_FCAT_MARA-FIELDNAME 'MATKL'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MATKL'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

WA_FCAT_MARA-COL_POS '5'.
WA_FCAT_MARA-FIELDNAME 'MEINS'.
WA_FCAT_MARA-TABNAME 'IT_MARA'.
WA_FCAT_MARA-REF_TABNAME 'MARA'.
WA_FCAT_MARA-REF_FIELDNAME 'MEINS'.
APPEND WA_FCAT_MARA TO IT_FCAT_MARA.
CLEAR WA_FCAT_MARA.

"FOR MAKT TABLE
WA_FCAT_MAKT-COL_POS '1'.
WA_FCAT_MAKT-FIELDNAME 'MATNR'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'MATNR'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

WA_FCAT_MAKT-COL_POS '2'.
WA_FCAT_MAKT-FIELDNAME 'SPRAS'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'SPRAS'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

WA_FCAT_MAKT-COL_POS '3'.
WA_FCAT_MAKT-FIELDNAME 'MAKTX'.
WA_FCAT_MAKT-TABNAME 'IT_MAKT'.
WA_FCAT_MAKT-REF_TABNAME 'MAKT'.
WA_FCAT_MAKT-REF_FIELDNAME 'MAKTX'.
APPEND WA_FCAT_MAKT TO IT_FCAT_MAKT.
CLEAR WA_FCAT_MAKT.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
  EXPORTING
    I_CALLBACK_PROGRAM             SY-REPID.
*   I_CALLBACK_PF_STATUS_SET       = ' '
*   I_CALLBACK_USER_COMMAND        = ' '
*   IT_EXCLUDING                   =

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        WA_LAYOUT
    IT_FIELDCAT                      IT_FCAT_MARA
    I_TABNAME                        'IT_MARA'
    IT_EVENTS                        IT_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_MARA
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
  EXPORTING
    IS_LAYOUT                        WA_LAYOUT
    IT_FIELDCAT                      IT_FCAT_MAKT
    I_TABNAME                        'IT_MAKT'
    IT_EVENTS                        IT_EVENTS
*   IT_SORT                          =
*   I_TEXT                           = ' '
  TABLES
    T_OUTTAB                         IT_MAKT
* EXCEPTIONS
*   PROGRAM_ERROR                    = 1
*   MAXIMUM_OF_APPENDS_REACHED       = 2
*   OTHERS                           = 3
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* 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