‎2008 Jan 18 5:01 PM
Dear All,
My internal table is
Matnr W_value
1140 2000
1150 3000
1160 4000
I have to select matnr based on w_value compared to vbap-netwr.
i.e if my vbap-netwr is 2600 I have to select 1140 as this is between 2000 - 3000. in the same way if my netwr is 3300, I should select 1150.
Please help me in code.
I am already in loop VBAP. I think i have to read internal table and select matnr accordingly.
And have internal tables values as stated above. please help.
Regards
madhu
‎2008 Jan 18 5:39 PM
What do you do if VBAP-NETWR is less than 2000? Considering you have a logic to work in that situation, you can use the following logic for your problem.
sort itab by w_value
clear l_index.
loop at itab where w_value > vbap-netwr.
l_index = sy-tabix.
exit.
endloop.
if l_index is initial.
describe table itab lines l_index.
endif.
if l_index = 1.
"sticky situation. What do we do now?
else.
subtract 1 from l_index.
read table itab index l_index.
endif.
MATNR you are looking for is in ITAB-MATNR at this point. Of course, you have to test this thoroughly.
Edited by: Sudhi Karkada on Jan 18, 2008 6:47 PM
‎2008 Jan 18 5:07 PM
loop at it_vbap in wa_vbap .
if netwr in ('2000','2999').
read table it_value with key w_value = '2000'.
move it_value-matnr to output.
endif.
if netwr in ('3000', '3999').
read table it_value with key w_value = '3000'.
move it_value-matnr to output.
endif.
..
.
endloop.
‎2008 Jan 18 5:12 PM
Hi jack,
Thanks for reply, can we write this withour hard coding the values.
Regards
Madhu
‎2008 Jan 18 5:58 PM
if not to hard code, you can build a range table and use it...
constants : c_2000 type w_value value '2000'.
...
..
ranges: ra_value type w_value,
ra_value2 type w_value.
example to build range
MOVE 'I' TO ra_labor-sign.
MOVE 'EQ' TO ra_labor-option.
MOVE c_2000 TO ra_labor-low. <<<<<<<<,3000
MOVE c_2999 TO ra_labor-high. <<<3999
APPEND ra_labor.
loop at it_vbap in wa_vbap.
if netwr in ra_value.
read table it_value with key w_value = '2000'.
move it_value-matnr to output.
endif.
if netwr in ra_value2.
read table it_value with key w_value = '3000'.
move it_value-matnr to output.
endif.
..
.
endloop.
‎2008 Jan 18 5:17 PM
‎2008 Jan 18 5:17 PM
hi Madhu,
to look for the value you need:
SORT itab BY w_walue.
LOOP AT itab INTO wa.
wa_prev = wa. ==> to save line temporarly
IF vbap-netwr LT wa-w_value.
==> you need matnr from wa_prev.
ENDIF.
ENDLOOP.
hope this helps
ec
‎2008 Jan 18 5:37 PM
Hi Eric,
Thankf for reply. this seems to work.
You mean always I have to compare with previous line and present line but the values of wa_prev-w_value will be equal to wa-w_value ??
Please explain me clearly.
Thanks You
madhu
‎2008 Jan 18 5:39 PM
What do you do if VBAP-NETWR is less than 2000? Considering you have a logic to work in that situation, you can use the following logic for your problem.
sort itab by w_value
clear l_index.
loop at itab where w_value > vbap-netwr.
l_index = sy-tabix.
exit.
endloop.
if l_index is initial.
describe table itab lines l_index.
endif.
if l_index = 1.
"sticky situation. What do we do now?
else.
subtract 1 from l_index.
read table itab index l_index.
endif.
MATNR you are looking for is in ITAB-MATNR at this point. Of course, you have to test this thoroughly.
Edited by: Sudhi Karkada on Jan 18, 2008 6:47 PM
‎2008 Jan 18 5:50 PM
Hi Sudhi,
Thank you very much for your reply. This is really helpful.
if VBAP_netwr is less than 2000, I dont want to do anything. other wise your peice of code seems to behelpful.
I will try and update in forum.
Thank You,
regards
madhu