Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

please help witht his code

Former Member
0 Likes
1,035

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,006

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

8 REPLIES 8
Read only

former_member156446
Active Contributor
0 Likes
1,006

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.

Read only

0 Likes
1,006

Hi jack,

Thanks for reply, can we write this withour hard coding the values.

Regards

Madhu

Read only

0 Likes
1,006

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.

Read only

Former Member
0 Likes
1,006

You can declare a tvarvc varibale or declare a ranges table

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,006

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

Read only

0 Likes
1,006

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

Read only

Former Member
0 Likes
1,007

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

Read only

0 Likes
1,006

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