Using for all entry and read table

AIM: Write a 2 table content {zcust_details1, zcust_details2} into a single screen.


REPORT  ZFor_all_entry_PRO1.

Types: begin of STR,
           kunnr type zcust_details1-kunnr,
           country type zcust_details1-country,
           end of STR.

Types: begin of str1,
           kunnr type zcust_details2-kunnr,
           pur_ord_no type zcust_details2-pur_ord_no,
           total_amount type zcust_details2-total_amount,
           end of str1.

 data: IT_zcust_details1 type standard table of str,
         wa_zcust_details1 type str,
         IT_zcust_details2 type standard table of str1,
         wa_zcust_details2 type str1.

SELECT kunnr
              country
      from zcust_details1
      into table it_zcust_details1.

if sy-subrc = 0.
  SELECT kunnr
                 pur_ord_no
                 total_amount
         from zcust_details2
         into table it_zcust_details2
         for all entries in it_zcust_details1                    "For all entry of it_zcust_details1 internal table.
         where kunnr = it_zcust_details1-kunnr.

    if sy-subrc = 0.
        loop at it_zcust_details2 into wa_zcust_details2.
        write: / wa_zcust_details2-kunnr,
                   wa_zcust_details2-pur_ord_no,
                   wa_zcust_details2-total_amount.
        read table IT_zcust_details1 into wa_zcust_details1 with key kunnr = wa_zcust_details2-kunnr.  "Read table with key table1-kunnr = table2-kunnr.

    if sy-subrc = 0.
        write: wa_zcust_details1-country.
    endif.
       endloop.
    endif.
  endif.

Share this

Related Posts