‎2008 Mar 11 5:47 AM
Hi all,
I wrote code like this.
Here I am getting the values,but when ever ia m reading the table in a loop max1 = ilist1-zzmax_cpi. value is always getting same value.
please give me the solution
SELECT *
INTO TABLE wknvv FROM knvv
WHERE vkorg IN sales_or
AND vtweg IN dist_cha
AND spart IN div
AND vkbur IN sales_of .
SELECT vbeln auart kunnr zzmax_cpi INTO table ilist1 FROM vbak
for all entries in wknvv
WHERE
vbtyp = 'G'
AND kunnr = wknvv-kunnr
AND auart IN contr_ty.
SELECT vbeln posnr abgru ZZASSET_TAG INTO table wvbap FROM vbap
for all entries in ilist1
WHERE vbeln = ilist1-vbeln
AND abgru = ''.
SELECT * INTO table wveda FROM veda
for all entries in ilist1
WHERE vbeln = ilist1-vbeln
AND vposn = wvbap-posnr
AND vkuegru = ''
AND venddat IN dates .
LOOP AT wknvv .
read table ilist1 with key kunnr = wknvv-kunnr BINARY SEARCH .
max1 = ilist1-zzmax_cpi.
if sy-subrc = 0 and max1 is not initial.
read table wvbap with key vbeln = ilist1-vbeln BINARY SEARCH .
if sy-subrc = 0.
read table wvbap with key vbeln = ilist1-vbeln BINARY SEARCH .
endif.
IF sy-subrc = 0.
MOVE-CORRESPONDING wvbap TO wlist .
MOVE-CORRESPONDING wveda TO wlist .
MOVE-CORRESPONDING wknvv TO wlist .
APPEND wlist.
ENDIF .
endif.
ENDLOOP.
‎2008 Mar 11 5:54 AM
HI
After statement
APPEND wlist.
inside loop you should add
clear: wknvv.
regards
Aditya
‎2008 Mar 11 5:54 AM
HI
After statement
APPEND wlist.
inside loop you should add
clear: wknvv.
regards
Aditya
‎2008 Mar 11 5:57 AM
Hi Rakesh,
You are using BINARY search in read statements. For this internal tables must be sorted.
Sort you internal tables before the loop.
Plz revert if need more clarifications.
Reward if helpful.
Regards,
Mandeep
‎2008 Mar 11 5:58 AM
Hi,
Few mistakes i have identified in this code.
1. Before using for all entries please check the driver table is initial or not.
2. BINARY SEARCH WILL not work if u dont sort the internal tables.
Check below modified code.
SELECT *
INTO TABLE wknvv FROM knvv
WHERE vkorg IN sales_or
AND vtweg IN dist_cha
AND spart IN div
AND vkbur IN sales_of .
IF NOT wknvv[] IS INITIAL.
SELECT vbeln auart kunnr zzmax_cpi INTO table ilist1 FROM vbak
for all entries in wknvv
WHERE
vbtyp = 'G'
AND kunnr = wknvv-kunnr
AND auart IN contr_ty.
IF NOT ilist1[] IS INITIAL.
SELECT vbeln posnr abgru ZZASSET_TAG INTO table wvbap FROM vbap
for all entries in ilist1
WHERE vbeln = ilist1-vbeln
AND abgru = ''.
SELECT * INTO table wveda FROM veda
for all entries in ilist1
WHERE vbeln = ilist1-vbeln
AND vposn = wvbap-posnr
AND vkuegru = ''
AND venddat IN dates .
ENDIF.
ENDIF.
SORT: ilist1 BY kunnr,
wvbap BY vbeln.*
LOOP AT wknvv .
read table ilist1 with key kunnr = wknvv-kunnr BINARY SEARCH .
max1 = ilist1-zzmax_cpi.
if sy-subrc = 0 and max1 is not initial.
read table wvbap with key vbeln = ilist1-vbeln BINARY SEARCH .
if sy-subrc = 0.
read table wvbap with key vbeln = ilist1-vbeln BINARY SEARCH .
endif.
IF sy-subrc = 0.
MOVE-CORRESPONDING wvbap TO wlist .
MOVE-CORRESPONDING wveda TO wlist .
MOVE-CORRESPONDING wknvv TO wlist .
APPEND wlist.
ENDIF .
endif.
ENDLOOP.
Hope this will solve ur problem.
Thanks,
Vinod.
Edited by: Vinod Kumar Vemuru on Mar 11, 2008 11:32 AM
‎2008 Mar 11 6:04 AM
‎2008 Mar 11 6:22 AM
Hi,
read table ilist1 with key kunnr = wknvv-kunnr BINARY SEARCH .
in this statement, you are not using the key field of VBAK ie VBELN, that is why you are gettin same entries.
ILIST1 is gettin populated based on VBAK, in which VBELN is the key field, but you are reading based on kunnr, so you will get duplicate entries as present in the internal table ILIST1.
Reward if helpful.
Regards.
‎2008 Mar 11 6:24 AM