Using Select with Joins in ABAP 7.4


Example of using Select Joins with ABAP 7.4, OPEN SQL joins ABAP 7.4


In SAP NetWeaver 7.4, SAP has simplified OPEN SQL to query database tables by using SQL JOINS, below are the examples and differences to ABAP 7.4 and prior to 7.4.

In the below example we will be joining MARA and MAKT tables to read data from database tables.

Select Joins before ABAP 7.4

DATA : LV_MTART TYPE MARA-MTART,
       LV_SPRAS TYPE MAKT-SPRAS.

TYPES: BEGIN OF T_MARA,
  MATNR LIKE MARA-MATNR,  
  MTART TYPE MARA-MTART,  
  MAKTX TYPE MAKT-MAKTX,  
  SPRAS TYPE MAKT-SPRAS, 
END OF T_MARA.

DATA: IT_MATERIAL TYPE  TABLE OF T_MARA .
DATA : WA_MATERIAL TYPE T_MARA.

lv_mtart = 'FERT'.
lv_spras = 'E'.

SELECT MARA~MATNR
       MARA~MTART
       MAKT~MAKTX
       MAKT~SPRAS
  INTO  TABLE IT_MATERIAL
  FROM MARA INNER JOIN MAKT ON ( MARA~MATNR = MAKT~MATNR )
  WHERE mara~mtart = lv_Mtart AND makt~spras = lv_spras .


LOOP AT IT_MATERIAL INTO WA_MATERIAL.
  WRITE : / WA_MATERIAL-MATNR, WA_MATERIAL-MTART, WA_MATERIAL-MAKTX, WA_MATERIAL-SPRAS .
ENDLOOP.

Using Select Joins after ABAP 7.4 with inline declarations

DATA(lv_Mtart) = 'FERT'.
DATA(lv_spras) = 'E'.

SELECT MARA~MATNR, MARA~MTART, makt~MAKTX, makt~spras
  FROM MARA INNER JOIN makt ON mara~matnr = makt~matnr

  WHERE mara~mtart = @lv_mtart
  AND makt~SPRAS = @lv_spras
  INTO TABLE @DATA(it_materials).

LOOP AT it_materials INTO DATA(wa_material).
  WRITE : / WA_MATERIAL-MATNR, WA_MATERIAL-MTART, WA_MATERIAL-MAKTX, WA_MATERIAL-SPRAS .
ENDLOOP.

You can also use select * in Select Joins in ABAP 7.4

DATA(lv_Mtart) = 'FERT'.
DATA(lv_spras) = 'E'.

SELECT MARA~*, makt~*
  FROM MARA INNER JOIN makt ON mara~matnr = makt~matnr

  WHERE mara~mtart = @lv_mtart
  AND makt~SPRAS = @lv_spras
  INTO TABLE @DATA(it_materials).

LOOP AT it_materials INTO DATA(wa_materials).
WRITE:/ wa_materials-MARA-MATNR, wa_materials-makt-maktx.
ENDLOOP.


Learner Questions

No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question


    Was this lesson helpful to you? Yes No 0 People out of 0 think this lesson helpful

    Lesson Navigation

    ←Previous Chapter
    Next Chapter →