Skip to Content

Internal Table Column Processing

Hi Friends,

I have a requirement where in i need to collate values in field1, field2 in a internal table in to a single field in another table.

Is there any other opton other than looping at itab1 and inserting the values of field1, field2 into itab2 one after the other.

Thank you.

Thanks,

Uday

For eg:

Itab1 has two columns Product1, Product2 and itab2 has one field Product.

M124, M126

M125, M127

M128, M129


Expected Result

-----------------------

iTAB2

M124

M126

M125

M127

M128

M129

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2013 at 01:12 PM

    Hi Uday,

    as you have ITAB2 field similar to the first field in ITAB1. For First column you can directly assign value of ITAB1 to ITAB2.

    itab2[] = itab1[]. this copies the first column avoiding 1 append statement in code.

    and then loop at itab1 and append the second column.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 02:28 PM

    I dont think a loop can be avoided.

    However you can reduce the number of lines with this logic.


    FIELD-SYMBOLS <FS1> TYPE ANY.

    ITAB2[] = ITAB1[].
    ASSIGN WA_ITAB1-FIELD2 TO <FS1>.


    LOOP AT ITAB1 INTO WA_ITAB1.
    APPEND <FS1> TO ITAB2.
    ENDLOOP.


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 06:10 AM

    Hi.

    Please try this logic.

    Loop at Itab1 .

    Itab2-Produc t= Itab1 -Product1.

    Append itab2.

    Itab2-Produc t= Itab1 –Product2.

    Append itab2.

    Endloop.

    Regards.

    JN

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 06:13 AM

    Hi,

    No there is no other alternative than LOOPing at the itab1.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 06:15 AM

    Hello Udaya Bhaskar.

    Code your business logic to fetch product names directly into ITAB2 instead of ITAB1 😊

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 07:04 AM

    Hi,

    if you need the 1st internal table, too, then the only other way might be a selection from database.

    SELECT ... INTO TABLE itab2 FOR ALL ENTRIES in ITAB1 WHERE product = itab1-product1 OR product = itab1-product2.

    If OR doesn't work split SELECT into SELECT INTO TABLE itab1 FOR ALL ENTRIES in ITAB1 WHERE product1 ... and SELECT APPENDING TABLE itab1 FOR ALL ENTRIES in ITAB1 WHERE product2 ...

    The LOOP and APPEND remains the easiest way to create itab2.

    Regards,

    Klaus

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 07:23 AM

    Hi Udaya Bhaskar Perecharla,

    I think there is no other way other than loop....😔

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2013 at 11:27 AM

    Hi Udaya,

    Too Curious to know why you don't wish to use loop at internal table.😕

    If there is Performance issue use parallel cursor method.

    otherwise use read table.

    But what is the problem with loop command Please Explain.ℹ️

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2013 at 12:48 PM

    DEAR UDAY,

    TRY THIS PLEASE.

    data: BEGIN OF itab1 OCCURS 0,

    col1 type char10,

    col2 type char10,

    END OF itab1.

    data: BEGIN OF itab2 OCCURS 0,

    product type matnr,

    END OF itab2.

    DATA: V_LINES TYPE I.

    DATA: COUNTER TYPE I.

    itab1-col1 = 'M124'.

    itab1-col2 = 'M126'.

    APPEND ITAB1.

    CLEAR: ITAB1.

    itab1-col1 = 'M125'.

    itab1-col2 = 'M127'.

    APPEND ITAB1.

    CLEAR: ITAB1.

    itab1-col1 = 'M128'.

    itab1-col2 = 'M129'.

    APPEND ITAB1.

    CLEAR: ITAB1.

    DESCRIBE TABLE ITAB1 LINES V_LINES.

    DO V_LINES TIMES.

    COUNTER = COUNTER + 1.

    READ TABLE ITAB1 INDEX COUNTER.

    IF SY-SUBRC EQ 0.

    ITAB2-PRODUCT = ITAB1-COL1.

    APPEND ITAB2.

    CLEAR: ITAB2.

    ITAB2-PRODUCT = ITAB1-COL2.

    APPEND ITAB2.

    CLEAR: ITAB2.

    ENDIF.

    ENDDO.

    SORT ITAB2 BY PRODUCT.

    LOOP AT ITAB2.

    WRITE:/ ITAB2-PRODUCT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 02, 2013 at 04:32 AM

    Thanks everyone for your quick response and sharing ideas on my query. I have got some optimum approach in this thread.

    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.