Google Search - Blog...........

ABAP - Example On Blocking ALV List/Grid Display

REPORT ZPR_02.

TYPE-POOLS: SLIS.

* Tables Declaration.
TABLES: MARA.

*Internal tables and data declaration.
DATA: BEGIN OF IT_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MBRSH LIKE MARA-MBRSH,
END OF IT_MARA,

BEGIN OF IT_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
EKGRP LIKE MARC-EKGRP,
END OF IT_MARC,

BEGIN OF IT_MARD OCCURS 0,
MATNR LIKE MARD-MATNR,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
END OF IT_MARD.

DATA: WA_FIELD_CAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELD_CAT1 TYPE SLIS_T_FIELDCAT_ALV,
IT_FIELD_CAT2 TYPE SLIS_T_FIELDCAT_ALV,
IT_FIELD_CAT3 TYPE SLIS_T_FIELDCAT_ALV,
WA_KEYINFO TYPE SLIS_KEYINFO_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV,
IT_EVENTS1 TYPE SLIS_T_EVENT WITH HEADER LINE,
IT_EVENTS2 TYPE SLIS_T_EVENT WITH HEADER LINE,
IT_EVENTS3 TYPE SLIS_T_EVENT WITH HEADER LINE.
*------------------------------------------------------------------------*
*Selection Screen.
*------------------------------------------------------------------------
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
*------------------------------------------------------------------------*
*Start Of selection.
*------------------------------------------------------------------------*
START-OF-SELECTION.

*Selecting the data.
PERFORM SELECT_DATA.

*Populating the field catelogue.
PERFORM BUILD_FIELD_CAT.

*Displaying the final output.
PERFORM DISPLY_OUTPUT.

*&---------------------------------------------------------------------
**& Form Select_data
*&---------------------------------------------------------------------*
* Selecting the data.
*----------------------------------------------------------------------*
FORM SELECT_DATA .
SELECT MATNR
MTART
MBRSH
FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR.

IF NOT IT_MARA[] IS INITIAL.
SELECT MATNR
WERKS
EKGRP
FROM MARC
INTO TABLE IT_MARC
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR EQ IT_MARA-MATNR.
ENDIF.

IF NOT IT_MARC[] IS INITIAL.
SELECT MATNR
WERKS
LGORT
LABST
FROM MARD
INTO TABLE IT_MARD
FOR ALL ENTRIES IN IT_MARC
WHERE MATNR = IT_MARC-MATNR
AND WERKS = IT_MARC-WERKS.
ENDIF.
ENDFORM. " Select_data
*&---------------------------------------------------------------------
**& Form Build_field_cat
*&---------------------------------------------------------------------*
* Populating the field catelogue.
*----------------------------------------------------------------------*
FORM BUILD_FIELD_CAT .

DEFINE M_FIELDCAT1.
WA_FIELD_CAT-TABNAME = &1.
WA_FIELD_CAT-FIELDNAME = &2.
WA_FIELD_CAT-SELTEXT_L = &3.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT1.
END-OF-DEFINITION.

DEFINE M_FIELDCAT2.
WA_FIELD_CAT-TABNAME = &1.
WA_FIELD_CAT-FIELDNAME = &2.
WA_FIELD_CAT-SELTEXT_L = &3.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT2.
END-OF-DEFINITION.

DEFINE M_FIELDCAT3.
WA_FIELD_CAT-TABNAME = &1.
WA_FIELD_CAT-FIELDNAME = &2.
WA_FIELD_CAT-SELTEXT_L = &3.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT3.
END-OF-DEFINITION.

M_FIELDCAT1 'MARA' 'MATNR' 'Material No'.
M_FIELDCAT1 'MARA' 'MTART' 'Material type'.
M_FIELDCAT1 'MARA' 'MBRSH' 'Industry Sector'.
M_FIELDCAT2 'MARC' 'MATNR' 'Material No'.
M_FIELDCAT2 'MARC' 'WERKS' 'Plant'.
M_FIELDCAT2 'MARC' 'EKGRP' 'Purchasing Group'.
M_FIELDCAT3 'MARD' 'MATNR' 'Material No'.
M_FIELDCAT3 'MARD' 'WERKS' 'Plant'.
M_FIELDCAT3 'MARD' 'LGORT' 'Storage Loc'.
M_FIELDCAT3 'MARD' 'LABST' 'Valued Stock'.

IT_EVENTS1-NAME = 'TOP_OF_PAGE'.
IT_EVENTS1-FORM = 'F_TOP_OF_PAGE_ONE'.
APPEND IT_EVENTS1. CLEAR IT_EVENTS1.

IT_EVENTS2-NAME = 'TOP_OF_PAGE'.
IT_EVENTS2-FORM = 'F_TOP_OF_PAGE_TWO'.
APPEND IT_EVENTS2. CLEAR IT_EVENTS2.

IT_EVENTS3-NAME = 'TOP_OF_PAGE'.
IT_EVENTS3-FORM = 'F_TOP_OF_PAGE_THREE'.
APPEND IT_EVENTS3. CLEAR IT_EVENTS3.

ENDFORM. " Build_field_cat
*&---------------------------------------------------------------------
**& Form disply_output
*&---------------------------------------------------------------------
** Displaying the final output.
*----------------------------------------------------------------------*
FORM DISPLY_OUTPUT .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING I_CALLBACK_PROGRAM = SY-REPID.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = IT_LAYOUT
IT_FIELDCAT = IT_FIELD_CAT1[]
I_TABNAME = 'IT_MARA'
IT_EVENTS = IT_EVENTS1[]
TABLES
T_OUTTAB = IT_MARA .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = IT_LAYOUT
IT_FIELDCAT = IT_FIELD_CAT2[]
I_TABNAME = 'IT_MARC'
IT_EVENTS = IT_EVENTS2[]
TABLES T_OUTTAB = IT_MARC .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = IT_LAYOUT
IT_FIELDCAT = IT_FIELD_CAT3[]
I_TABNAME = 'IT_MARD'
IT_EVENTS = IT_EVENTS3[]
TABLES T_OUTTAB = IT_MARD .

*&---------------------------------------------------------------------*
*& Form top_of_page_one
*&---------------------------------------------------------------------
* * text
*----------------------------------------------------------------------*
FORM F_TOP_OF_PAGE_ONE.
WRITE: / 'Header details (MARA)'.
ENDFORM. "top_of_page_one

*&---------------------------------------------------------------------
**& Form top_of_page_one
*&---------------------------------------------------------------------
** text*----------------------------------------------------------------------*
FORM F_TOP_OF_PAGE_TWO.
WRITE: / 'Item details (MARC)'.
ENDFORM. "top_of_page_one

*&---------------------------------------------------------------------
**& Form top_of_page_one
*&---------------------------------------------------------------------
** text
*----------------------------------------------------------------------*
FORM F_TOP_OF_PAGE_THREE.
WRITE: / 'Item details (MARD)'.
ENDFORM. "top_of_page_one

ALSO READ:

- Change The Layout Of The ALV List/Grid Display.

- Add Color In ALV List/Grid Display.

- Use Of Double Click On ALV Grid/List Display.

- Hierarchical ALV Grid/List Display Report Program.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.

2 comments:

  1. Excellent way of explaining code

    ReplyDelete
  2. Hi,

    This prg is very useful for the beginners, i tried it but if you want the ALV to get displayed after 'REUSE_ALV_BLOCK_LIST_APPEND'
    you should use CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    EXPORTING
    IS_PRINT = GT_PRINT.

    ReplyDelete