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

Select statement

Hi gurus,

I have a condition where I have an internal table it_tab1 and it_tab1 has material number and price, now I passes this material no. into marc to get the plan information of the corresponding material and for this I have written this code:

select werks matnr from it_tab1 into table it_tab2

from marc

where matnr = it_tab1-matnr.

is this statment right?

and now I need to create one more internal table that will have three fields matnr, price and werks and now I need to join it_tab1 and it_tab2 to get price, matnr and werks in my third internal table.

can you please help me out to do this.

Thanks

Rajeev

Message was edited by:

Rajeev Gupta

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2007 at 08:08 PM

    It should be like this

    select matnr werks from it_tab1 into table it_tab2

    from marc

    <b>for all entries in itab1</b>

    where matnr = it_tab1-matnr.

    Once you get data from MARC into ITAB2.

    Sort ITAB1 by MATNR.

    SORT ITAB2 BY MATNR.

    LOOP AT ITAB2.

    READ TABLE ITAB1 WITH KEY MATNR = ITAB2-MATNR BINARY SEARCH.

    IF SY-SUBRC EQ 0.

    ITAB3-MATNR = ITAB1-MATNR.

    ITAB3-WERKS = ITAB2-WERKS.

    ITAB3-PRICE = ITAB1-PRICE.

    APPEND ITAB3.

    CLEAR ITAB3.

    ENDIF.

    ENDLOOP.

    Hope this will help you.

    ashish

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2007 at 08:09 PM

    Hi,

    Please try this.

    select werks matnr 
    for all entries in it_tab1 
    into table it_tab2
    from marc 
    where matnr = it_tab1-matnr.
    
    loop at it_tab2.
      read table it_tab1 with key matnr = it_tab2-matnr binary search.
    
      if sy-subrc = 0.
        it_tab3-matnr = it_tab2-matnr.
        it_tab3-werks = it_tab2-werks.
        it_tab3-price = it_tab1-price.
        append it_tab3.
        clear it_tab3.
      endif.
    
    endloop.
    

    Regards,

    Ferry Lianto

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2007 at 08:11 PM

    Hi

    the select statement is wrong

    if not it_tab1[] is initial.

    select werks matnr into table it_tab2

    from marc

    for all entries of it_tab1

    where matnr = it_tab1-matnr.

    endif.

    loop at it_tab1.

    move it_tab1 records to it_tab3.

    read table it_tab2 with key matnr = it_tab1-matnr.

    move the records to it_tab3.

    append it_tab3.

    clear it_tab3.

    endloop.

    Regards

    Anji

    Add a comment
    10|10000 characters needed characters exceeded

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.