‎2009 Apr 09 11:32 AM
Hi Gurus...........
i have my code below ...problem is that when it goes for the first time if get the
value but when it goes again in to the loop , first loop is getting exected
the second and the third loop returns sy-subrc 4 thou it has value.....
iam not able to find it out y????can you plzzz helppp???
Code of loop
===============
LOOP AT it_pos INTO wa_pos .
READ TABLE it_kna1 INTO wa_kna1 WITH KEY kunnr = wa_pos-konto .
IF sy-subrc = 0.
wa_final-name1 = wa_kna1-name1.
wa_final-xblnr = wa_pos-xblnr.
read table it_t005u into wa_t005u with key bland = wa_kna1-regio.
If sy-subrc = 0.
wa_final-bezei = wa_t005u-bezei.
Endif.
Endif.
Loop at it_vbrp into wa_vbrp where vbeln = wa_bkpf-vbeln.
read table it_vbrk into wa_vbrk with key vbeln = wa_vbrp-vbeln.
If sy-subrc = 0.
wa_final-knumv = wa_vbrk-knumv.
Endif.
wa_final-arktx = wa_vbrp-arktx.
wa_Final-fkimg = wa_vbrp-fkimg.
move wa_final-arktx to wa_final-a.
move wa_final-fkimg to wa_final-b.
qty = wa_vbrp-fkimg.
split qty at '.' into text2 text3.
move text2 to wa_final-b.
concatenate wa_Final-a '-' wa_final-b into wa_final-c separated by space.
wa_final-name1 = wa_kna1-name1.
wa_final-xblnr = wa_pos-xblnr.
Loop at it_konv into wa_konv where knumv = wa_vbrk-knumv and kposn = wa_vbrp-posnr.
wa_pos-dmshb = ( wa_konv-kwert ) - ( ( wa_konv-kwert * ra_data ) / 100 ).
wa_final-dmbtr = wa_pos-dmshb.
Endloop.
Endloop.
Append wa_final to it_final
clear: wa_bkpf, wa_kna1, wa_t005u,wa_vbrk, wa_vbrp, wa_konv, wa_final, wa_pos.
ENDLOOP.Edited by: Matt on Apr 9, 2009 1:20 PM - added tags
‎2009 Apr 09 11:46 AM
Hi,
Your complete logic is wrong.
See in the second loop itself you are again and again assigning values to wa_final structure so it will take only the last value.
and at the end you are Appending the wa_final's value to the internal table, that is wrong.
plz varify your logic.
‎2009 Apr 09 12:00 PM
thanks for the reply ...but the logic is not wrong....since again i want the same datas for the line item in the second loop i have used the first loops final field again in second thats it and in third loop i am making the calculations thats it
‎2009 Apr 09 12:48 PM
Hi,
As already mentioned by the other guys above, your append statement is not correct. It should have been before the endloop for VBRP.
Regards.
‎2009 Apr 09 1:42 PM
Hi Beginer,
the way u have appended the Final internal table is not right...in this case u will never get the first line item of the 2nd Loop...but u will keep getting the last line item of vbrk and vbrp. Same is the case for the 3rd Loop. I don't know how this satisfies your requirement. and about the sy-subrc values for 2nd and 3rd loop...there may be any kind of error....may be the internal tables it_vbrp, it_vbrk, it_konv are initial...or may be the Read statement has failed as there were no matching entries ......and so on. Just put a break point at the start of the 1st Loop and debug. I think that will help.
‎2009 Apr 09 11:58 AM
Position of your append is wrong ...
it should be above all the endloop.
Edited:
LOOP AT it_pos INTO wa_pos .
*** logic ***
READ TABLE it_kna1 INTO wa_kna1 WITH KEY kunnr = wa_pos-konto .
*** logic ***
read table it_t005u into wa_t005u with key bland = wa_kna1-regio.
*** logic ***
Loop at it_vbrp into wa_vbrp where vbeln = wa_bkpf-vbeln.
*** logic ***
read table it_vbrk into wa_vbrk with key vbeln = wa_vbrp-vbeln.
*** logic ***
Loop at it_konv into wa_konv where knumv = wa_vbrk-knumv and kposn = wa_vbrp-posnr.
*** logic ***
Append wa_final to it_final "Check position of this statement.
Endloop.
Endloop.
ENDLOOP.Regards,
Lalit Mohan Gupta.
Edited by: Lalit Mohan Gupta on Apr 9, 2009 4:45 PM - Written the skeleton of code. Label Edited
‎2009 Apr 09 12:06 PM
Hi Beginer,
In the 2nd loop, where is the value of wa_bkpf-vbeln coming from, Just keep a break point before the second loop and before the 3rd loop,
Regards
Kumar M.
‎2009 Apr 09 12:11 PM
Hi,
In the second loop, check the value of wa_bkpf-vbeln(either present or not) and also whether it is present in the internal table it_vbrp or not.
Regards,
Nihar
‎2009 Apr 09 2:08 PM
Hi,
In your source code you are clearing the content of wa_bkpf after your first loop step and wa_bkpf-vbeln is the criteria that makes you enter the second loop.
That explains why you are getting a subrc = 4 issue for next loop steps.
LOOP AT it_pos INTO wa_pos .
.............
............
Loop at it_vbrp into wa_vbrp where vbeln = wa_bkpf-vbeln.
............
Endloop.
Append wa_final to it_final
+clear: wa_bkpf, wa_kna1, wa_t005u,wa_vbrk, wa_vbrp, wa_konv, wa_final, wa_pos.+
ENDLOOP.
The way you manage your "loops" may lead to performance issues. You could find a better solution.
Issa