Former Member

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.

I am already in loop VBAP. I think i have to read internal table and select matnr accordingly.

Regards

10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Jan 18, 2008 at 05: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.
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

10|10000 characters needed characters exceeded
• Former Member

Hi Sudhi,

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

• Posted on Jan 18, 2008 at 05: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.

10|10000 characters needed characters exceeded
• Raj S Former Member

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.

• Former Member
Posted on Jan 18, 2008 at 05:17 PM

You can declare a tvarvc varibale or declare a ranges table

10|10000 characters needed characters exceeded
• Posted on Jan 18, 2008 at 05:17 PM

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

10|10000 characters needed characters exceeded
• Former Member

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 ??