join multiple tables using new syntax and display in ALV using joins in ABAP
In this example I'm fetching data from 3 tables i.e. VBAK, VABP, MAKT with using joins.
Report
REPORT zab_rp_sale_order_new_join.
TABLES: vbak.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
lr_layout TYPE slis_layout_alv.
SELECT-OPTIONS: s_erdat FOR vbak-erdat.
IF s_erdat IS INITIAL.
MESSAGE 'Data is not found' TYPE 'E'.
ELSE.
SELECT a~vbeln, b~posnr,b~matnr,b~kwmeng,b~vrkme,c~maktx
FROM vbak AS a LEFT OUTER JOIN vbap AS b
ON a~vbeln = b~vbeln
INNER JOIN makt AS c
ON b~matnr = c~matnr
INTO TABLE @DATA(lt_final)
WHERE a~erdat IN @s_erdat.
lr_layout-colwidth_optimize = 'X'.
lt_fieldcat = VALUE #(
( col_pos = 1 fieldname = 'VBELN' seltext_l = 'SALE DOCUMENT' )
( col_pos = 2 fieldname = 'POSNR' seltext_l = 'SALE ITEM' )
( col_pos = 3 fieldname = 'MATNR' seltext_l = 'MATERIAL NUMBER' )
( col_pos = 4 fieldname = 'KWMENG' seltext_l = 'QUANTITY' )
( col_pos = 5 fieldname = 'VRKME' seltext_l = 'SALE UNIT' )
( col_pos = 6 fieldname = 'MAKTX' seltext_l = 'MATERIAL DESCRIPTION' ) ).
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lr_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = lt_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDIF.
Input
Output
******************************Thank You***************************
Comments
Post a Comment