SAP ABAP Sample Report :
REPORT zselect_multiple NO STANDARD PAGE HEADING.
*// Tables declaration
TABLES : vbak.
*// Types declaration for VBAK
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
END OF ty_vbak.
*// Types declaration for VBAP
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_vbap.
*// Types declaration for Final Internal table
TYPES : BEGIN OF ty_final,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_final.
*// Internal table declaration
DATA : lt_vbak TYPE TABLE OF ty_vbak,
lt_vbap TYPE TABLE OF ty_vbap,
lt_final TYPE TABLE OF ty_final.
*// Work area declaration
DATA : wa_vbak TYPE ty_vbak,
wa_vbap TYPE ty_vbap,
wa_final TYPE ty_final.
*// Variable declaration
DATA : lv_count TYPE i.
*// Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-100.
SELECT-OPTIONS s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF BLOCK blk1.
*// Retrieve data from VBAK
IF s_vbeln IS NOT INITIAL.
SELECT vbeln erdat erzet ernam angdt
FROM vbak
INTO TABLE lt_vbak
WHERE vbeln IN s_vbeln.
*// Retrieve data from VBAP
IF lt_vbak IS NOT INITIAL.
SELECT vbeln posnr matnr matwa matkl arktx
FROM vbap
INTO TABLE lt_vbap
FOR ALL ENTRIES IN lt_vbak
WHERE vbeln = lt_vbak-vbeln.
ENDIF.
ELSE.
MESSAGE 'Please enter selection screen field value' TYPE 'I'.
EXIT.
ENDIF.
*// Populate data into final internal table
LOOP AT lt_vbap INTO wa_vbap. " Item Table
READ TABLE lt_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vbeln.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbak-vbeln.
wa_final-erdat = wa_vbak-erdat.
wa_final-erzet = wa_vbak-erzet.
wa_final-ernam = wa_vbak-ernam.
wa_final-angdt = wa_vbak-angdt.
wa_final-posnr = wa_vbap-posnr.
wa_final-matnr = wa_vbap-matnr.
wa_final-matwa = wa_vbap-matwa.
wa_final-matkl = wa_vbap-matkl.
wa_final-arktx = wa_vbap-arktx.
APPEND wa_final TO lt_final.
CLEAR wa_final.
ENDIF.
ENDLOOP.
*// Count number of records in LT_FINAL table
DESCRIBE TABLE lt_final LINES lv_count.
WRITE : /10 'Number of Sales Records:', lv_count.
ULINE.
SKIP 1.
*// Display output
LOOP AT lt_final INTO wa_final.
WRITE : / wa_final-vbeln, wa_final-erdat, wa_final-erzet, wa_final-ernam, wa_final-angdt,
wa_final-posnr, wa_final-matnr, wa_final-matwa, wa_final-matkl, wa_final-arktx.
ENDLOOP.
*// Tables declaration
TABLES : vbak.
*// Types declaration for VBAK
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
END OF ty_vbak.
*// Types declaration for VBAP
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_vbap.
*// Types declaration for Final Internal table
TYPES : BEGIN OF ty_final,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
angdt TYPE angdt_v,
posnr TYPE posnr_va,
matnr TYPE matnr,
matwa TYPE matwa,
matkl TYPE matkl,
arktx TYPE arktx,
END OF ty_final.
*// Internal table declaration
DATA : lt_vbak TYPE TABLE OF ty_vbak,
lt_vbap TYPE TABLE OF ty_vbap,
lt_final TYPE TABLE OF ty_final.
*// Work area declaration
DATA : wa_vbak TYPE ty_vbak,
wa_vbap TYPE ty_vbap,
wa_final TYPE ty_final.
*// Variable declaration
DATA : lv_count TYPE i.
*// Selection screen design
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-100.
SELECT-OPTIONS s_vbeln FOR vbak-vbeln.
SELECTION-SCREEN END OF BLOCK blk1.
*// Retrieve data from VBAK
IF s_vbeln IS NOT INITIAL.
SELECT vbeln erdat erzet ernam angdt
FROM vbak
INTO TABLE lt_vbak
WHERE vbeln IN s_vbeln.
*// Retrieve data from VBAP
IF lt_vbak IS NOT INITIAL.
SELECT vbeln posnr matnr matwa matkl arktx
FROM vbap
INTO TABLE lt_vbap
FOR ALL ENTRIES IN lt_vbak
WHERE vbeln = lt_vbak-vbeln.
ENDIF.
ELSE.
MESSAGE 'Please enter selection screen field value' TYPE 'I'.
EXIT.
ENDIF.
*// Populate data into final internal table
LOOP AT lt_vbap INTO wa_vbap. " Item Table
READ TABLE lt_vbak INTO wa_vbak WITH KEY vbeln = wa_vbap-vbeln.
IF sy-subrc EQ 0.
wa_final-vbeln = wa_vbak-vbeln.
wa_final-erdat = wa_vbak-erdat.
wa_final-erzet = wa_vbak-erzet.
wa_final-ernam = wa_vbak-ernam.
wa_final-angdt = wa_vbak-angdt.
wa_final-posnr = wa_vbap-posnr.
wa_final-matnr = wa_vbap-matnr.
wa_final-matwa = wa_vbap-matwa.
wa_final-matkl = wa_vbap-matkl.
wa_final-arktx = wa_vbap-arktx.
APPEND wa_final TO lt_final.
CLEAR wa_final.
ENDIF.
ENDLOOP.
*// Count number of records in LT_FINAL table
DESCRIBE TABLE lt_final LINES lv_count.
WRITE : /10 'Number of Sales Records:', lv_count.
ULINE.
SKIP 1.
*// Display output
LOOP AT lt_final INTO wa_final.
WRITE : / wa_final-vbeln, wa_final-erdat, wa_final-erzet, wa_final-ernam, wa_final-angdt,
wa_final-posnr, wa_final-matnr, wa_final-matwa, wa_final-matkl, wa_final-arktx.
ENDLOOP.