‎2010 Oct 14 4:03 AM
Hi,
My query is that ADRC table has 2 entries for a customer... in the below logic I am getting only 1 entry detail of that customer in the O/P table ... how to get both in the output table?
Thank You,
SB.
Preparing output table.
IF mt_flag = ''.
LOOP AT lt_vbrk INTO lw_vbrk.
Read table ZVATCN
READ TABLE lt_zvatcn INTO lw_zvatcn WITH KEY vbeln = lw_vbrk-vbeln.
IF sy-subrc = 0.
lw_output-vbeln = lw_zvatcn-vbeln.
lw_output-zvatcn = lw_zvatcn-zvatcn.
lw_output-zcrdat = lw_zvatcn-zcrdat.
Read tavle VBRP
READ TABLE lt_vbrp INTO lw_vbrp WITH KEY vbeln = lw_vbrk-vbeln.
IF sy-subrc = 0.
lw_output-fkimg = lw_vbrp-fkimg.
lw_output-meins = lw_vbrp-meins.
lw_output-matnr = lw_vbrp-matnr.
lw_output-arktx = lw_vbrp-arktx.
lw_output-net_amt = lw_vbrp-netwr + lw_vbrp-mwsbp.
ENDIF.
Read table KNA1.
READ TABLE lt_vbrk_kna1 INTO lw_vbrk_kna1 WITH KEY kunnr = lw_vbrk-kunag
land1 = lw_vbrk-land1.
IF sy-subrc = 0.
READ TABLE lt_adrc INTO lw_adrc WITH KEY addrnumber = lw_vbrk_kna1-adrnr
country = lw_vbrk_kna1-land1.
IF sy-subrc = 0.
lw_output-name = lw_adrc-name1.
lw_output-nation = lw_adrc-nation.
ENDIF.
ENDIF.
lw_output-bstnk_vf = lw_vbrk-bstnk_vf.
ENDIF.
APPEND lw_output TO lt_output.
clear : lw_output-vbeln, lw_output-name, lw_output-nation,lw_output-arktx,
lw_output-matnr, lw_output-meins,lw_output-fkimg, lw_output-net_amt,
lw_output-bstnk_vf, lw_output-zvatcn, lw_output-zcrdat.
ENDLOOP.
ENDIF.
‎2010 Oct 14 5:26 AM
you are looping at vbrk table. where vbeln is unique key so one iteration.
now you read adrc so it will give you only one hit => one entry into o/p table.
if you loop executes for second time for same vbeln then you will have the same entry getting duplicated into the o/p table from ADRC.
ADRC may have two entries for that address_number based on date and natio of key combination but read statement will pick only one entry .
here you need to check that one loop iteration with a read inside will yield only one entry from adrc .
‎2010 Oct 14 6:10 AM
READ statement will only select one entry.
Say, you have 2 entries in your internal table lt_adrc with adrnr 0001
i.e Customer ABC and Customer XYZ
In this case, READ statement will always only fetch the first row that fulfills the condition. i.e. Customer ABC