Improve join in ABAP
* Previously, if we want to fetch the data of all columns of a table, we cannot use * for that particular table in the join.
* In SAP ABAP new syntax, we can use * to fetch the data of all columns of a particular table in the join.
Report
REPORT zab_rp_join_improve.
DATA: lv_matnr TYPE matnr.
TYPES: BEGIN OF ls_data,
matnr TYPE matnr,
meins TYPE meins,
spras TYPE spras,
maktx TYPE maktx,
maktg TYPE maktg,
END OF ls_data.
DATA: lt_data TYPE TABLE OF ls_data,
lr_data TYPE ls_data.
SELECT-OPTIONS : s_matnr FOR lv_matnr.
IF s_matnr IS NOT INITIAL.
SELECT a~matnr a~meins b~spras b~maktx b~maktg
FROM mara AS a JOIN makt AS b
ON a~matnr = b~matnr
INTO TABLE lt_data
WHERE a~matnr IN s_matnr AND b~spras = sy-langu.
ENDIF.
IF lt_data IS NOT INITIAL.
LOOP AT lt_data INTO lr_data.
WRITE: / lr_data-matnr , lr_data-meins, lr_data-spras, lr_data-maktx, lr_data-maktg.
ENDLOOP.
ENDIF.
Report-NEW
REPORT zab_rp_join_improve.
DATA: lv_matnr TYPE matnr.
SELECT-OPTIONS : s_matnr FOR lv_matnr.
IF s_matnr IS NOT INITIAL.
SELECT a~matnr,a~meins,b~*
FROM mara AS a JOIN makt AS b
ON a~matnr = b~matnr
INTO TABLE @data(lt_data)
WHERE a~matnr IN @s_matnr AND b~spras = @sy-langu.
ENDIF.
IF lt_data IS NOT INITIAL.
LOOP AT lt_data INTO data(lr_data).
WRITE: / lr_data-matnr , lr_data-meins, lr_data-b-spras, lr_data-b-maktx, lr_data-b-maktg.
ENDLOOP.
ENDIF.
Input
Output
********************************Thank You*****************************
Comments
Post a Comment