Select with Joins in SAP ABAP
SELECT WITH JOINS statement is used to read data simultaneously from multiple database tables .
As per performance standards, SELECT WITH JOINS for more than 3 tables is not advisable, as it puts heavy load on database
Syntax :
SELECT T1~FIELD1
T1~FIELD2
T2~FIELD1
T2~FIELD2
INTO TABLE <ITAB>
FROM T1 INNER JOIN T2 ON ( T1~FIELD1 = T2~FIELD )
WHERE T1~FIELD = <SOME VALUE> .
** Here T1 and T2 are database tables, FIELD1 and FIELD2 are fields in respective tables
Example of using SELECT JOINS in SAP ABAP
**DATA DECLERATIONS
TYPES: BEGIN OF T_MARA,
MATNR LIKE MARA-MATNR, "FIELD1 FROM MARA TABLE
MTART TYPE MARA-MTART, "FIELD2 FROM MARA TABLE
MAKTX TYPE MAKT-MAKTX, "FIELD1 FROM MAKT TABLE
SPRAS TYPE MAKT-SPRAS, "FIELD2 FROM MAKT TABLE
END OF T_MARA.
DATA: IT_MARA TYPE TABLE OF T_MARA .
DATA : WA_MARA TYPE T_MARA.
SELECT MARA~MATNR
MARA~MTART
MAKT~MAKTX
MAKT~SPRAS
INTO TABLE IT_MARA
FROM MARA INNER JOIN MAKT ON ( MARA~MATNR = MAKT~MATNR )
UP TO 50 ROWS.
LOOP AT IT_MARA INTO WA_MARA.
WRITE : / WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MAKTX, WA_MARA-SPRAS .
ENDLOOP.
No comments:
Post a Comment