7. Simple Inner Joins

 REPORT Z_MATERIAL_SEARCH.
 
*** Material Search Program
TYPES : BEGIN OF ty_material,
          matnr TYPE mara-matnr,
          maktx TYPE makt-maktx,
        END OF ty_material.

DATA : wa_material TYPE ty_material,
       lt_material TYPE TABLE OF ty_material.

PARAMETERS : p_matnr TYPE mara-matnr.

*** Report Execution Start - F8 button ( Execute )
START-OF-SELECTION.
 
*** Write Header of the Report.
WRITE: 10 'Material No', 50 'Material Descripton'.
ULINE.

IF p_matnr IS NOT INITIAL.
*** Select statement with Inner Join
   SELECT a~matnr b~maktx
     FROM
     mara AS a INNER JOIN makt AS b
     ON a~matnr = b~matnr
     INTO TABLE lt_material
     WHERE a~matnr = p_matnr.
   IF sy-subrc EQ 0.
      LOOP AT lt_material INTO wa_material.
         WRITE :/ wa_material-matnr UNDER 'Material No',
                  wa_material-maktx UNDER 'Material Description'.
      ENDLOOP.
   ENDIF..
ENDIF.

Output :

%d bloggers like this: