‎2008 Oct 17 2:11 AM
I have two internal tables gt_vbak & gt_knvp
and they have values as
Internal table :gtvbak_
VBELN VKORG BSTNK KUNNR J_3ADEPM kunn2
6049039794|6055 |MTEST1EDI_2 |6006921000| | |
6049039797|6055 |MTEST1EDI_2 |6006921000| | |
Internal table gtknvp_
KUNNR KUNN2 VKORG SPART PARVW
6006921000|6006923307|6055 |01|WE |
6006921000|6006923308|6055 |0 |WE |
My below logic is not working in updating 6006923307 & 6006923308 values in gt_vbak interal table's corresponding kunn2. In two records also gt_vbak-kunn2 values is storing as 6006923308 .
How can I write this logic in this case like both kunnr and vkorg of both itabs are same ?
LOOP AT gt_vbak INTO wa_vbak.
*READ TABLE gt_knvp INTO wa_knvp
*with key kunnr = wa_vbak-kunnr
*vkorg = wa_vbak-vkorg.
LOOP AT gt_knvp INTO wa_knvp
WHERE kunnr = wa_vbak-kunnr
AND vkorg = wa_vbak-vkorg.
wa_vbak-kunn2 = wa_knvp-kunn2.
ENDLOOP. " LOOP AT gt_knvp INTO wa_knvp
THANKS IN ADV
‎2008 Oct 17 3:35 AM
LOOP AT gt_vbak INTO wa_vbak.
LOOP AT gt_knvp INTO wa_knvp
WHERE kunnr = wa_vbak-kunnr
AND vkorg = wa_vbak-vkorg.
wa_vbak-kunn2 = wa_knvp-kunn2.
COLLECT wa_vbak to GT_vbak1. ( BY DECLARING GT_VBAK1)ENDLOOP. " LOOP AT gt_knvp INTO wa_knvp
THANKS IN ADV
‎2008 Oct 17 2:21 AM
Hi Sam Kumar,
You didn't used MODIFY statement.
LOOP AT gt_vbak INTO wa_vbak.
READ TABLE gt_knvp INTO wa_knvp
with key kunnr = wa_vbak-kunnr
vkorg = wa_vbak-vkorg.
if sy-subrc = 0.
wa_vbak-kunn2 = wa_knvp-kunn2.
MODIFY GT_VBAK FROM WA_VBAK
TRANSPORTING KUNN2
WHERE kunnr = wa_vbak-kunnr and
vkorg = wa_vbak-vkorg.
endif.
ENDLOOP.
Regards,
R.Nagarajan.
-
We can -
Edited by: Nagarajan Ramamoorthy on Oct 17, 2008 10:24 AM
‎2008 Oct 17 2:27 AM
you are selecting gt_knvp based on 2 fields KUNNR and VKORG, and both the records in this table satsfies that condition, so it is using the last record. If you want unique, you need to take SPART also into consideration.
KUNNR KUNN2 VKORG SPART PARVW
6006921000|6006923307|6055 |01|WE |
6006921000|6006923308|6055 |0 |WE |
Wen you would select KUNNR and VKORG from VBAK internal table, both the above records will be selected and it will update KUNN2 with the last record.
‎2008 Oct 17 2:28 AM
I appreciate your honesty.
I do used modify but read stmt always brings first vaue...
Instead of read if i use loop at second itab , it always brings and modify with second record's kunn2
‎2008 Oct 17 2:30 AM
Read will always bring the 1st value, Loop will always bring the 2nd value, as both the entries are same in your table for those 2 fields KUNNR and VKORG
‎2008 Oct 17 2:32 AM
sorry typing mistake : SPART value also 01 - ie same in both reocrds
KUNNR KUNN2 VKORG SPART PARVW
6006921000|6006923307|6055 |01|WE |
6006921000|6006923308|6055 |01|WE |
how can i get subsequent records ?
‎2008 Oct 17 2:38 AM
So you have 2 shiptos for the same sold to. Why dont you read the shipto from VBPA sales order itself, and use that in your VBAp internal table. Using KNVP you will always get the same value and that might not match the shipto with the corresponding entry in slaes order
‎2008 Oct 17 3:27 AM
‎2008 Oct 17 3:29 AM
Where? What are you trying to do? you have 2 internal tables, and you want to update a field ( KUNN2 ) in 1st with KUNN2 in other table, but the otjer table has 2 values for the same criteria, collect or anything else would nto work.
state your requirement clearly, else no one would be able to help
‎2008 Oct 17 3:35 AM
LOOP AT gt_vbak INTO wa_vbak.
LOOP AT gt_knvp INTO wa_knvp
WHERE kunnr = wa_vbak-kunnr
AND vkorg = wa_vbak-vkorg.
wa_vbak-kunn2 = wa_knvp-kunn2.
COLLECT wa_vbak to GT_vbak1. ( BY DECLARING GT_VBAK1)ENDLOOP. " LOOP AT gt_knvp INTO wa_knvp
THANKS IN ADV
‎2008 Oct 17 3:38 AM
you knwo your requirements better. go thru those one more time and see if the code does the same.