Skip to Content
author's profile photo Former Member
Former Member

please help witht his code

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    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.
      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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • 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.

    Add a comment
    10|10000 characters needed characters exceeded

    • 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.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 05:17 PM

    You can declare a tvarvc varibale or declare a ranges table

    Add a comment
    10|10000 characters needed characters exceeded

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

    Add a comment
    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 ??

      Please explain me clearly.

      Thanks You

      madhu

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.