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

Internal table basic's .

Hi ,

i have a internal table when looped will print the records as follows .

ramu raju kumar anil

ramu raju swetha anil

ramu raju ranjith anil

now i want the internal table to print as follows

ramu raju kumar,swetha,ranjith anil

the 3rd field which is different should be seperated by comma .

how do i write the code .

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Oct 30, 2008 at 03:48 PM

    Imagining that your table fields can not be moved around then this is how

    you can get the work done

    * Imagin the table ITAB has the following fields and values
    * FD1    FD2   FD3     FD4
    * ramu   raju   kumar   anil
    * ramu   raju   swetha  anil
    * ramu   raju   ranjith   anil 
    
    ITAB1[] = ITAB2[] = ITAB3[] = ITAB4[] = ITAB[].
    sort ITAB1 by FD1.
    DELETE ADJACENT DUPLICATES FROM ITAB1 comparing FD1.
    
    sort ITAB2 by FD2.
    DELETE ADJACENT DUPLICATES FROM ITAB2 comparing FD2.
    
    sort ITAB3 by FD3.
    DELETE ADJACENT DUPLICATES FROM ITAB3 comparing FD3.
    
    sort ITAB4 by FD4.
    DELETE ADJACENT DUPLICATES FROM ITAB4 comparing FD4.
    
    loop at itab1.
    write itab1-fd1.
    endloop.
    
    loop at itab2.
    write itab1-fd2.
    endloop.
    
    loop at itab3.
    write : ',' , itab1-fd3.
    endloop.
    
    loop at itab4.
    write : ',' ,itab1-fd4.
    endloop.
    
    

    Hope this will work, out of curiosity what is the business case for this anyway?

    Franc

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 30, 2008 at 04:01 PM

    Hello, try this:

    DATA: BEGIN OF itab OCCURS 0,
           fld1(50),
           fld2(50),
           fld3(50),
           fld4(50),
          END OF itab.
    
    DATA: itab2 LIKE TABLE OF itab,
          gs_itab2 LIKE LINE OF itab2.
    
    * Appear internal table itab*
    
    FIELD-SYMBOLS: <fs_itab> LIKE LINE OF itab,
                   <fs_itab2> LIKE LINE OF itab.
    
    LOOP AT itab ASSIGNING <fs_itab>.
      READ TABLE itab2 ASSIGNIGN <fs_itab2> 
                       WITH KEY fld1 = <fs_itab>-fld1
                                fld2 = <fs_itab>-fld2
                                fld4 = <fs_itab>-fld4.
      IF sy-subrc = 0.
        CONCATENATE <fs_itab2>-fld3 ',' <fs_itab>-fld3 INTO <fs_itab2>-fld3.
      ELSE.
        gs_itab2 = <fs_itab>.
        APPEND gs_itab2 TO itab2.
      ENDIF.
    ENDLOOP.

    Thanks and Regards.

    David Carballido

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 30, 2008 at 04:16 PM

    Hi Pradeep,

    Do it in this way.

    create another table with the same structure named it_tab2.

    IT_TAB2[] = IT_TAB[].
    Loop at itab.
      READ TABLE IT_TAB WITH KEY FIELD1 = IT_TAB-FIELD1 
                                                        FIELD2 = IT_TAB-FIELD2
                                                        FIELD3 = IT_TAB-FIELD3.
      IF SY-SUBRC = 0.
         WRITE:/ IT_TAB2-FIELD
      ELSE.
        WRITE:/.
      ENDIF.
    Endloop.
    
    

    Thanks,

    Chidanand

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 19, 2011 at 06:00 PM

    This message was moderated.

    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.