I'm learning abap and trying to join three tables: vbap, vbak, makt.
Here is my SELECT statement code:
IF s_ernam is INITIAL.
SELECT K~auart K~ernam K~erdat K~vbeln P~pstyv P~posnr P~matnr P~zmeng P~zieme
FROM vbak AS K INNER JOIN vbap as P on K~vbeln = P~vbeln
INTO TABLE sales
WHERE K~auart in s_auart
and K~erdat in s_erdat
and P~pstyv in s_pstyv.
ELSE.
SELECT K~auart K~ernam K~erdat K~vbeln P~pstyv P~posnr P~matnr P~zmeng P~zieme
FROM vbak AS K INNER JOIN vbap as P on K~vbeln = P~vbeln
INTO TABLE sales
WHERE K~auart in s_auart
and K~erdat in s_erdat
and P~pstyv in s_pstyv
and K~ernam = s_ernam.
ENDIF.
SELECT maktx
FROM makt
INTO TABLE gt_makt
FOR ALL ENTRIES IN sales
WHERE matnr = sales-matnr.
LOOP AT sales INTO wa_sales.
READ TABLE gt_makt
INDEX sy-index
INTO wa_makt.
wa_int_sales-auart = wa_sales-auart.
wa_int_sales-ernam = wa_sales-ernam.
wa_int_sales-erdat = wa_sales-erdat.
wa_int_sales-pstyv = wa_sales-pstyv.
wa_int_sales-vbeln = wa_sales-vbeln.
wa_int_sales-posnr = wa_sales-posnr.
wa_int_sales-matnr = wa_sales-matnr.
wa_int_sales-zmeng = wa_sales-zmeng.
wa_int_sales-zieme = wa_sales-zieme.
wa_int_sales-maktx = wa_makt-maktx.
APPEND wa_int_sales to int_sales.
ENDLOOP.