This sap programming report with sample code using abap programming language explains you how to use alv block list to append the report.


REPORT ZALVBLOCK .

TYPE-POOLS : SLIS.

TABLES : AFKO,AFPO.

TYPES : BEGIN OF SAFPO ,
AUFNR LIKE AFPO-AUFNR,
POSNR LIKE AFPO-POSNR,
PLNUM LIKE AFPO-PLNUM,
STRMP LIKE AFPO-STRMP,
MATNR LIKE AFPO-MATNR,
PSMNG LIKE AFPO-PSMNG,
MEINS LIKE AFPO-MEINS,
END OF SAFPO.
TYPES : BEGIN OF SAFKO,
AUFNR LIKE AFKO-AUFNR,
END OF SAFKO.
DATA : IAFKO TYPE TABLE OF SAFKO WITH HEADER LINE,
IAFPO TYPE TABLE OF SAFPO WITH HEADER LINE.

DATA : IFIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT1 TYPE SLIS_FIELDCAT_ALV,
ILAYOUT1 TYPE SLIS_LAYOUT_ALV,
IEVENT1 TYPE SLIS_T_EVENT,
WEVENT1 TYPE SLIS_ALV_EVENT,
IKEYINFO1 TYPE SLIS_KEYINFO_ALV.

DATA : IFIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT2 TYPE SLIS_FIELDCAT_ALV,
ILAYOUT2 TYPE SLIS_LAYOUT_ALV,
IEVENT2 TYPE SLIS_T_EVENT,
WEVENT2 TYPE SLIS_ALV_EVENT.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_AUFNR FOR AFKO-AUFNR,
S_GLTRP FOR AFKO-GLTRP.

SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID.
  • I_CALLBACK_PF_STATUS_SET = ' '
  • I_CALLBACK_USER_COMMAND = ' '
  • IT_EXCLUDING =
.

PERFORM GET_DATA.
PERFORM BUILD_FIELDCAT.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_EVENT.
PERFORM BUILD_KEYINFO.

PERFORM BUILD_FIELDCAT2.
PERFORM BUILD_LAYOUT2.
PERFORM BUILD_EVENT2.

PERFORM DISPLAY_BLOCK1.

PERFORM DISPLAY_BLOCK2.

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.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
&---------------------------------------------------------------------
*& Form GET_DATA
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM GET_DATA .
SELECT AUFNR FROM AFKO INTO CORRESPONDING FIELDS OF TABLE IAFKO
WHERE AUFNR IN S_AUFNR AND GLTRP IN S_GLTRP.

SELECT AUFNR POSNR PLNUM STRMP MATNR PSMNG MEINS FROM AFPO INTO CORRESPONDING FIELDS OF TABLE
IAFPO WHERE AUFNR IN S_AUFNR.
ENDFORM. " GET_DATA
&---------------------------------------------------------------------
*& Form BUILD_FIELDCAT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_FIELDCAT .
REFRESH : IFIELDCAT1.

*WFIELDCAT1-FIELDNAME = 'AUFNR'.
*WFIELDCAT1-COL_POS = '1'.
*WFIELDCAT1-SELTEXT_L = 'Order No'.
*APPEND WFIELDCAT1 TO IFIELDCAT1.
*CLEAR WFIELDCAT1.
WFIELDCAT1-FIELDNAME = 'GLTRP'.
WFIELDCAT1-COL_POS = '1'.
WFIELDCAT1-SELTEXT_L = 'Basic Finish Time'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GSTRP'.
WFIELDCAT1-COL_POS = '2'.
WFIELDCAT1-SELTEXT_L = 'Basic Start Time'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GAMNG'.
WFIELDCAT1-COL_POS = '3'.
WFIELDCAT1-SELTEXT_L = 'Total Order Qty'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

WFIELDCAT1-FIELDNAME = 'GMEIN'.
WFIELDCAT1-COL_POS = '4'.
WFIELDCAT1-SELTEXT_L = 'UOM'.
APPEND WFIELDCAT1 TO IFIELDCAT1.
CLEAR WFIELDCAT1.

ENDFORM. " BUILD_FIELDCAT
&---------------------------------------------------------------------
*& Form BUILD_LAYOUT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_LAYOUT .
ILAYOUT1-COLWIDTH_OPTIMIZE = 'X'.
ILAYOUT1-ZEBRA = 'X'.

ENDFORM. " BUILD_LAYOUT
&---------------------------------------------------------------------
*& Form BUILD_EVENT
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_EVENT .

WEVENT1-FORM = 'TOPOFLIST1'.
WEVENT1-NAME = SLIS_EV_TOP_OF_LIST.
APPEND WEVENT1 TO IEVENT1.

ENDFORM. " BUILD_EVENT
&---------------------------------------------------------------------
*& Form DISPLAY_BLOCK1
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM DISPLAY_BLOCK1 .
*CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_HS_APPEND'
  • EXPORTING
  • IS_LAYOUT = ILAYOUT1
  • IT_FIELDCAT = IFIELDCAT2
  • IS_KEYINFO = IKEYINFO1
  • I_HEADER_TABNAME = 'IAFKO'
  • I_ITEM_TABNAME = 'IAFPO'
  • IT_EVENTS = IEVENT1
    • IT_SORT =
    • I_TEXT = ' '
  • TABLES
  • T_OUTTAB_HEADER = IAFKO
  • T_OUTTAB_ITEM = IAFPO
    • EXCEPTIONS
    • PROGRAM_ERROR = 1
    • MAXIMUM_OF_APPENDS_REACHED = 2
    • OTHERS = 3
  • .
*IF SY-SUBRC 0.
    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
*
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT1
IT_FIELDCAT = IFIELDCAT1
I_TABNAME = 'IAFKO'
IT_EVENTS = IEVENT1
  • IT_SORT =
  • I_TEXT = ' '
TABLES
T_OUTTAB = IAFKO
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
IF SY-SUBRC 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_BLOCK1

FORM TOPOFLIST1.

WRITE :/10 'TABLE AFKO CONTENTS'.
WRITE :/(30) SY-ULINE.

ENDFORM.
&---------------------------------------------------------------------
*& Form BUILD_FIELDCAT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_FIELDCAT2 .
REFRESH : IFIELDCAT2.
WFIELDCAT2-FIELDNAME = 'AUFNR'.
WFIELDCAT2-COL_POS = '1'.
WFIELDCAT2-SELTEXT_L = 'Order No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'POSNR'.
WFIELDCAT2-COL_POS = '2'.
WFIELDCAT2-SELTEXT_L = 'Order Item No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'PLNUM'.
WFIELDCAT2-COL_POS = '3'.
WFIELDCAT2-SELTEXT_L = 'Planned Order No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'STRMP'.
WFIELDCAT2-COL_POS = '4'.
WFIELDCAT2-SELTEXT_L = 'Strt Dt Plnd ordr No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'MATNR'.
WFIELDCAT2-COL_POS = '5'.
WFIELDCAT2-SELTEXT_L = 'Material No'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'PSMNG'.
WFIELDCAT2-COL_POS = '6'.
WFIELDCAT2-SELTEXT_L = 'Pland Ordr Qty'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.

WFIELDCAT2-FIELDNAME = 'MEINS'.
WFIELDCAT2-COL_POS = '7'.
WFIELDCAT2-SELTEXT_L = 'UOM'.
APPEND WFIELDCAT2 TO IFIELDCAT2.
CLEAR WFIELDCAT2.
ENDFORM. " BUILD_FIELDCAT2
&---------------------------------------------------------------------
*& Form BUILD_LAYOUT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_LAYOUT2 .
ILAYOUT2-COLWIDTH_OPTIMIZE = 'X'.
ILAYOUT2-ZEBRA = 'X'.
ENDFORM. " BUILD_LAYOUT2
&---------------------------------------------------------------------
*& Form BUILD_EVENT2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_EVENT2 .

WEVENT2-FORM = 'TOPOFLIST2'.
WEVENT2-NAME = SLIS_EV_TOP_OF_LIST.
APPEND WEVENT2 TO IEVENT2.
CLEAR WEVENT2.

ENDFORM. " BUILD_EVENT2
&---------------------------------------------------------------------
*& Form DISPLAY_BLOCK2
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM DISPLAY_BLOCK2 .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT2
IT_FIELDCAT = IFIELDCAT2
I_TABNAME = 'IAFPO'
IT_EVENTS = IEVENT2
  • IT_SORT =
  • I_TEXT = ' '
TABLES
T_OUTTAB = IAFPO
  • EXCEPTIONS
  • PROGRAM_ERROR = 1
  • MAXIMUM_OF_APPENDS_REACHED = 2
  • OTHERS = 3
.
IF SY-SUBRC <> 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " DISPLAY_BLOCK2

FORM TOPOFLIST2.
WRITE : /10 'TABLE AFPO CONTENTS'.
WRITE :/(35) SY-ULINE.
ENDFORM.
&---------------------------------------------------------------------
*& Form BUILD_KEYINFO
&---------------------------------------------------------------------
  • text
----------------------------------------------------------------------
  • --> p1 text
  • <-- li="" p2="" text="">
----------------------------------------------------------------------
FORM BUILD_KEYINFO .
IKEYINFO1-HEADER01 = 'AUFNR'.
IKEYINFO1-ITEM01 = 'AUFNR'.
ENDFORM. " BUILD_KEYINFO



Serkan AKKAVAK
Computer Engineer
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com