Convert Columns into Rows (internal tables) - Urgent Help Pleasse..

Hi friends i'm having a little problem and hope you can help me..Here's the situation.
I have an internal table like shown below
(Key)                   (Key)               (Key)          (Key)
PATH_ID     |      GROUP     |      LINE     |     ATRIBUTE          |    VALUE
ASLN2                1                      1                Company_Code       5146
ASLN2                1                      1                Account_Code        400405
ASLN2                1                      1                Profit_Centre          AA00N2
ASLN2                1                      2                Company_Code       5146
ASLN2                1                      2                Account_Code       400705
ASLN2                1                      2                Profit_Centre          AA00N2
ASLN3                1                      1                Company_Code       5146
ASLN3                1                      1                Account_Code        400405
ASLN3                1                      1                Profit_Centre          AA00N2
ASLN3                1                      2                Company_Code       5146
ASLN3                1                      2                Account_Code       400705
ASLN3                1                      2                Profit_Centre          AA00N2
and i want to convert this internal table to one like below
PATH_ID      |      GROUP      |      LINE     |      Company Code   |    Account Code    |    Profit Centre
ASLN2                1                      1                 5146                     400405                   AA00N2
ASLN2                1                      2                 5146                     400705                   AA00N2
ASLN3                1                      1                 5146                     400405                   AA00N2
ASLN3                1                      2                 5146                     400705                   AA00N2
but i'm a bit of stuck, all those key fields are making me confused...anyone have a marvelous ( ) idea of how to implement this transformation ?
best regards,
Ricardo Monteiro

Itab1 with the structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
Itab2 with structure PATH_ID | GROUP | LINE | ATRIBUTE | VALUE
Itab3 with the final structure PATH_ID | GROUP | LINE | Company Code | Account Code | Profit Centre
move itab1 to itab2.
sort itab2 by path_id group line.
delete adjacent duplicates from itab2 comparing path_id group line.
loop at itab2.
  clear itab3.
  move:
     itab2-pathid to itab3-pathid,
     itab2-group to itab3-group,
     itab2-line to itab3-line.  
  loop at itab1where pathid = itab2-pathid
                        and group = itab2-group
                        and line   = itab2-line.
      IF itab1-ATRIBUTE = ' Company_Code'.
         itab3-Company_Code = itab1-attribute.
      elseif itab1-ATRIBUTE = ' Account_Code '.
         itab3-Account_Code = itab1-attribute.
      elseif itab1-ATRIBUTE = ' Profit_Centre ' .
         itab3-profit_center = itab1-attribute.
      endif
  endloop.
  append itab3.
endloop.
try this.
Thanks,
rajinikanth

Similar Messages

  • To convert columns into row

    Hi All,
    I need help in building view which actually can show columns data as row.
    e.g.
    row is as follows
    Name Age Salary
    ABC 25 10000
    BBC 28 12000
    The above tables data I want to get as
    Name ABC BBC
    Age 25 28
    Salary 10000 12000
    Thanks in advance.

    Even if I don't really understand such requirement, I wrote some times ago such function to play around that :
    Re: Converting Columns into rows
    Nicolas.

  • Converting columns into rows

    Dear all....I need to convert all columns into rows in a table. For example table has following columns:
    Emp_Cod........Val1......Val2......Val3
    1 a b c
    Now I wish that each column should display as a value like:
    Emp_Cod........Val1
    1 a
    1 b
    1 c
    Now the one way to solve this job is to write a union statement for each column but for this I'll have to write equal number of select statements as there are columns.
    What I need that is there anyway to write minimum code for this job, is there any alternate way???

    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t unpivot(v for c in(val1,val2,val3));
    EMP_CODE  C     V                                                      
            1  VAL1  a                                                      
            1  VAL2  b                                                      
            1  VAL3  c                                                      
    SQL> col COLUMN_VALUE for a20
    SQL> with t as(select 1 emp_code, 'a' val1, 'b' val2, 'c' val3 from dual)
      2  select*from t,table(sys.odcivarchar2list(val1,val2,val3));
    EMP_CODE  V  V  V  COLUMN_VALUE                                        
            1  a  b  c  a                                                   
            1  a  b  c  b                                                   
            1  a  b  c  c                                                   

  • How to convert columns into rows using  transpose function

    Hi
    anybody tell me how to convert columns values into rows using transpose function.

    Since BluShadow went to all the trouble to put it together, someone should use it.
    See the post titled How do I convert rows to columns? here SQL and PL/SQL FAQ
    John

  • How to convert  columns into rows

    present result
    Mat_num        comp_code   disc          amount     
    800000     SG01      SAPLF005                    0.00
    800000     SG01      SAPLF005               31,500.00
    6300001    SPM       SAPLF005                    0.00
    6300001    SPM       SAPLF005              108,888.00
    APS100     SMTP      SAPLF005                    0.00
    APS100     SMTP      SAPLF005                    0.00
    required format
    Mat_num       disc             SG01          SMTP          SPM
    800000   SAPLF005   31,500.00           0.00          0.00
    800000   SAPLF005        0.00           0.00          0.00 
    6300001  SAPLF005        0.00         0.00     108,888.00     
    6300001  SAPLF005        0.00         0.00           0.00  
    APS100   SAPLF005        0.00         0.00           0.00 
    APS100   SAPLF005        0.00         0.00           0.00
    Plain Text Attachment [ Scan and Save to Computer ]
    REPORT  Z_CALC2                                 .
    TABLES : KNC1.
    TYPE-POOLS: SLIS.
      type-pools : abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
    DATA: BEGIN OF ITAB OCCURS 0,
              KUNNR LIKE KNC1-KUNNR,
              BUKRS LIKE KNC1-BUKRS,
              GJAHR LIKE KNC1-GJAHR,
              USNAM LIKE KNC1-USNAM,
              UMSAV LIKE KNC1-UMSAV,
          END OF ITAB.
    *Result table
    TYPES BEGIN OF RES_ITAB.
    * RES_ITAB(10) TYPE C DEFAULE 'ZRES_ITAB'.
    INCLUDE STRUCTURE ZRES_ITAB.
    TYPES END OF RES_ITAB.
    SELECT-OPTIONS : CCODE FOR KNC1-BUKRS DEFAULT 'SG01' TO 'SPM '.
    DATA : BEGIN OF COMP_ITAB OCCURS 0,
              BUKRS LIKE KNC1-BUKRS,
           END OF COMP_ITAB.
    DATA: COLS TYPE I,
          gap(10) TYPE c,
          Company_title type string .
    start-of-selection.
      perform get_NUM_COLS.
      perform get_structure.
      perform create_dynamic_itab.
      perform get_data.
    *  perform write_out.
    FORM GET_NUM_COLS.
    SELECT KUNNR BUKRS GJAHR USNAM UMSAV INTO TABLE ITAB FROM KNC1 WHERE
    BUKRS IN CCODE.
    CLEAR ITAB.
    *CLEAR RES_ITAB.
    LOOP AT ITAB .
         COMP_ITAB-BUKRS = ITAB-BUKRS.
         APPEND COMP_ITAB.
    CLEAR COMP_ITAB.
    ENDLOOP.
    SORT COMP_ITAB BY BUKRS.
    DELETE ADJACENT DUPLICATES FROM COMP_ITAB.
    DESCRIBE TABLE COMP_ITAB LINES COLS.
    ENDFORM.
    *Get table structure
    form get_structure.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
    data : ref_table_des type ref to cl_abap_structdescr.
    data fld_pos type i value 1.
    * Get the structure of the table.
      ref_table_des ?=
                  cl_abap_typedescr=>describe_by_name( 'ZRES_ITAB' ).
      idetails[] = ref_table_des->components[].
      loop at idetails into xdetails.
        clear xfc.
        XFC-COL_POS = fld_pos.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
        fld_pos = fld_pos + 1.
      endloop.
      DO  COLS TIMES.
        clear xfc.
        READ TABLE COMP_ITAB INDEX SY-INDEX.
        XFC-COL_POS = fld_pos.
        xfc-fieldname = COMP_ITAB-BUKRS .
        xfc-datatype = 'F'.
    *    xfc-inttype = 'F'.   'details-type_kind.
        xfc-intlen = 14.
    *    xfc-decimals = xdetails-decimals.
        append xfc to ifc.
        fld_pos = fld_pos + 1.
      ENDDO.
      clear xfc.
        XFC-COL_POS = fld_pos.
        xfc-fieldname = 'RECORD_TOTAL' .
        xfc-datatype = 'F'.
        xfc-inttype  = 'F'.
        xfc-intlen = 14.
    *    xfc-decimals = xdetails-decimals.
        append xfc to ifc.
    endform.
    form create_dynamic_itab.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc
                   importing
                      ep_table        = dy_table.
      assign dy_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    endform.
    form get_data.
    LOOP AT ITAB.
            <DYN_WA>-KUNNR = ITAB-KUNNR.
            <DYN_WA>-USNAM = ITAB-USNAM.
            DO COLS TIMES.
               IF <DYN_WA>
    DESCRIBE TABLE <dyn_table>.
    *WRITE:/ SY-TFILL.
    * Select Data from table.
    * <dyn_table> = ITAB[].
    *LOOP AT ITAB.
    *    RES-KUNNR = ITAB-KUNNR.
    *    RES-USNAM = ITAB-USNAM.
    *    CASE ITAB-GJAHR.
    *        WHEN 2005.
    *            RES-UMSAV1 = ITAB-UMSAV.
    *        WHEN 2006.
    *            RES-UMSAV2 = ITAB-UMSAV.
    *        WHEN 2007.
    *            RES-UMSAV3 = ITAB-UMSAV.
    *    ENDCASE.
    *    RES-TOTAL = RES-UMSAV1 + RES-UMSAV2 + RES-UMSAV3 .
    * APPEND RES.
    *ENDLOOP.
    endform.
    form write_out.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    endform.
    Edited by: Alvaro Tejada Galindo on Feb 28, 2008 11:56 AM

    solved myself

  • Convert columns into rows

    SQL>create table TEST1
    TRAIN_ID VARCHAR2(10) not null,
    ALIES VARCHAR2(15),
    VAL VARCHAR2(20)
    Now I insert data into test1 table.
    SQL> select* from test2;
    TRAIN_ID NAM DOB
    A ASHIS 11/11/1974
    B SOUGATA 20/06/1977
    Now how can I select data in the following
    output ? Please suggest me.
    TRAIN_ID ALIES VAL
    A NAM ASHIS
    A DOB 11/11/1974
    B NAM SOUGATA
    B DOB 20/06/1977

    SELECT *
      FROM(
    SELECT tran_id, 'NAM' alies, nam val
      FROM test2
    UNION ALL
    SELECT tran_id, 'DOB' alies, TO_CHAR(dob, 'DD/MM/YYYY') val
      FROM test2
    ORDER BY tran_idwould appear to do what you want, though I'm not sure why you'd want it. Note that you'll have to convert all the values to a single data type (in this case VARCHAR2), which would make operating on the data quite painful later on...
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How can i add two table into one internal table

    I WANT TO ADD THIS TWO DIFFERENT TABLE INTO ONE INTERNAL TABLE PLEASE HELP.
    TABLES: J_1IEXCHDR, J_1IEXCDTL.
    SELECT * FROM J_1IEXCHDR WHERE STATUS = 'P'.
    WRITE: / J_1IEXCHDR-LIFNR,
              J_1IEXCHDR-DOCNO,
              J_1IEXCHDR-EXYEAR,
              J_1IEXCHDR-BUDAT.
    SELECT * FROM J_1IEXCDTL WHERE TRNTYP = J_1IEXCHDR-TRNTYP
                              AND DOCYR  = J_1IEXCHDR-DOCYR
                              AND DOCNO  = J_1IEXCHDR-DOCNO.
       WRITE: / J_1IEXCDTL-EXBAS,
                J_1IEXCDTL-EXBED,
                J_1IEXCDTL-RDOC1,
                J_1IEXCDTL-ECS.
    ENDSELECT.
    ENDSELECT.
    THANKS IN ADVANCED.

    U have to link these 2 tables like this
    <b>SELECT
    J_1IEXCHDR~DOCNO
    FROM J_1IEXCHDR inner join J_1IEXCDTL
    on J_1IEXCHDRDOCYR  = J_1IEXCDTLDOCYR
    WHERE STATUS = 'P'.</b>
    this is sample code only, and u have to check the F.key relationship.
    Regards
    Prabhu

  • Moving columns of an internal table to rows of an another internal table.

    Hi
    i have an internal table with 20 fields for single record .Now i need to move the 20 fields
    (of similar length) of single record into internal table with those 20 fields as 20 records i.e i need to make rows of first internal table into columns of second internal table.
    hope iam clear.

    HI Deepthi,
    Try with this Logic...
    IF NOT ITAB[] IS INITIAL.
          LOOP AT ITAB FROM 7.
            ITAB2-FIELD1 = ITAB-FIELD1.
            ITAB2-FIELD2 = ITAB-FIELD2.
            APPEND : ITAB2.
            CLEAR : ITAB2.
          ENDLOOP.
          DO 27 TIMES.
            CASE CNT.
              WHEN '1'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD6.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD6.
              WHEN '2'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD7.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD7.
              WHEN '3'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD8.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD8.
              WHEN '4'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD9.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD9.
              WHEN '5'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD10.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD10.
              WHEN '6'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD11.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD11.
              WHEN '7'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD12.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD12.
              WHEN '8'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD13.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD13.
              WHEN '9'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD14.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD14.
              WHEN '10'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD15.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD15.
              WHEN '11'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD16.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD16.
              WHEN '12'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD17.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD17.
              WHEN '13'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD18.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD18.
              WHEN '14'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD19.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD19.
              WHEN '15'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD20.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD20.
              WHEN '16'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD21.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD21.
              WHEN '17'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD22.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD22.
              WHEN '18'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD23.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD23.
              WHEN '19'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD24.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD24.
              WHEN '20'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD25.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD25.
              WHEN '21'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD26.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD26.
              WHEN '22'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD27.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD27.
              WHEN '23'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD28.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD28.
              WHEN '24'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD29.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD29.
              WHEN '25'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD30.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD30.
              WHEN '26'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD31.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD31.
              WHEN '27'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD32.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD32.
              WHEN '28'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD33.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD33.
              WHEN '29'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD34.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD34.
              WHEN '30'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD35.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD35.
              WHEN '31'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD36.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD36.
              WHEN '32'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD37.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD37.
              WHEN '33'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD38.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD38.
              WHEN '34'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD39.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD39.
              WHEN '35'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD40.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD40.
              WHEN '36'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD41.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD41.
              WHEN '37'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD42.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD42.
              WHEN '38'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD43.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD43.
              WHEN '39'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD44.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD44.
              WHEN '40'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD45.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD45.
              WHEN '41'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD46.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD46.
              WHEN '42'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD47.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD47.
              WHEN '43'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD48.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD48.
              WHEN '44'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD49.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD49.
              WHEN '45'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD50.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD50.
              WHEN '46'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD51.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD51.
              WHEN '47'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD52.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD52.
              WHEN '48'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD53.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD53.
              WHEN '49'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD54.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD54.
              WHEN '50'.
                READ TABLE ITAB INDEX 4.
                ITAB3-FIELD1 = ITAB-FIELD55.
                READ TABLE ITAB INDEX 5.
                ITAB3-FIELD2 = ITAB-FIELD55.
            ENDCASE.
            APPEND ITAB3.
            CLEAR ITAB3.
            CNT = CNT + 1.
          ENDDO.
        ENDIF.
      ENDIF.
    Regards,
    Santosh

  • How to join two internal table rows in alternative manner into one internal table?

    How to join two internal table rows in alternative manner into one internal table?
    two internal tables are suppose itab1 &  itab2 & its data
    Header 1
    Header 2
    Header 3
    a
    b
    c
    d
    e
    f
    g
    h
    i
    Header 1
    Header 2
    Header 3
    1
    2
    3
    4
    5
    6
    7
    8
    9
    INTO itab3 data
    Header 1
    Header 2
    Header 3
    a
    b
    c
    1
    2
    3
    d
    e
    f
    4
    5
    6
    g
    h
    i
    7
    8
    9

    Hi Soubhik,
    I have added two additional columns for each internal table.
    Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
    Row_Count  - It represents the Row Count Number, increase the row count value 1 by one..
    ITAB1:
    Header 1
    Header 2
    Header 3
    Table_Count
    Row_Count
    a
    b
    c
    1
    1
    d
    e
    f
    1
    2
    g
    h
    i
    1
    3
    ITAB2:
    Header 1
    Header 2
    Header 3
    Table_Count
    Row_Count
    1
    2
    3
    2
    1
    4
    5
    6
    2
    2
    7
    8
    9
    2
    3
    Create the Final Internal table as same as the ITAB1/ITAB2 structure.
    "Data Declarations
    DATA: IT_FINAL LIKE TABLE OF ITAB1.          "Final Internal Table
    FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1,     "TAB1
                                   <FS_TAB2> TYPE TY_TAB2.     "TAB2
    "Assign the values for the additional two column for ITAB1
    LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
         <FS_TAB1>-TABLE_COUNT = 1.             "Table value same for all row
         <FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
    ENDLOOP.
    "Assign the values for the additional two column for ITAB2
    LOOP AT ITAB2 ASSIGNING <FS_TAB2>.    
         <FS_TAB2>-TABLE_COUNT = 2.                  "Table value same for all row
         <FS_TAB2>-ROW_COUNT = SY-TABIX.      "Index value
    ENDLOOP.
    "Copy the First Internal Table 'ITAB1' to Final Table
    IT_FINAL[] = ITAB1[].
    "Copy the Second Internal Table 'ITAB2' to Final Table
    APPEND IT
    LOOP AT ITAB2 INTO WA_TAB2.
    APPEND WA_TAB2 TO IT_FINAL.
    ENDLOOP.
    "Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
    SORT IT_FINAL BY  ROW_COUNT TABLE_COUNT.
    After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
    Regards
    Rajkumar Narasimman

  • How to send multiple row data into an internal table??

    I have a view with table control.i want to select multiple row and send all the row data into an internal table.i am able to select multiple row but all the selected row data is not going to the internal table.....only a particular row data which is lead selected is going.
    Do anyone can help me regarding this issue?
    Thanks in advance,
    Subhasis.

    Hey,
    Some code example:
    declaring an internal table and work area to get all the elements from the node.
    data : lt_Elements type  WDR_CONTEXT_ELEMENT_SET,
             ls_Element type  WDR_CONTEXT_ELEMENT_SET,
    considering flights is my node.
             lt_data type sflight.
    Node_Flights is the ref of the node to which ur table is binded.
    Use Code Inspector to read the node.
    lt_Element = Node_Flights->GET_ELEMENTS
    loop at lt_elements into ls_Element.
    l_bollean =   ls_elements->is_selected ( returns abap true/false ).
        if l_bollean IS INITIAL.
           append ls_Element to lt_data.
       endif.
    Hope this would help.
    Cheers,
    Ashish

  • Excel data transfer into SAP internal table with GUI_UPLOAD

    hi all,
      i m using SRM4 system and i wanted to develop one report which will upload data from excel and convert it into IT.
    i know that many threads are posted on this topic.
    but my requirement is slight different. in the system only one function module is available that is "GUI_UPLOAD" and we want that user shd not save file as tab delimited before calling this fm. instead, program shd take care of all these things...
    please suggest something asap..
    helpful ans will be rewarded..
    thanks,
    jigs.

    Dear Jigs,
    Please go though the following lines of code:
    D A T A D E C L A R A T I O N *
    TABLES: ANEP,
    BKPF.
    TYPES: BEGIN OF TY_TABDATA,
    MANDT LIKE SY-MANDT, " Client
    ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number
    ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred
    ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year
    ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period
    ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1
    ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2
    ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3
    END OF TY_TABDATA.
    Declaration of the Internal Table with Header Line comprising of the uploaded data.
    DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.
    INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
    DATA: END OF IT_FILE_UPLOAD.
    S E L E C T I O N - S C R E E N *
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,
    BEGIN OF BLOCK B2 WITH FRAME.
    PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.
    SELECTION-SCREEN: END OF BLOCK B2,
    END OF BLOCK B1.
    E V E N T : AT S E L E C T I O N - S C R E E N *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
    PROGRAM_NAME = SYST-REPID
    DYNPRO_NUMBER = SYST-DYNNR
    FIELD_NAME = ' '
    STATIC = 'X'
    MASK = '.'
    CHANGING
    FILE_NAME = P_FNAME
    EXCEPTIONS
    MASK_TOO_LONG = 1
    OTHERS = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    E V E N T : S T A R T - O F - S E L E C T I O N *
    START-OF-SELECTION.
    Upload Excel file into Internal Table.
    PERFORM UPLOAD_EXCEL_FILE.
    Organize the uploaded data into another Internal Table.
    PERFORM ORGANIZE_UPLOADED_DATA.
    E V E N T : E N D - O F - S E L E C T I O N *
    END-OF-SELECTION.
    *& Form UPLOAD_EXCEL_FILE
    text
    --> p1 text
    <-- p2 text
    FORM UPLOAD_EXCEL_FILE .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
    FILENAME = P_FNAME
    I_BEGIN_COL = 1
    I_BEGIN_ROW = 3
    I_END_COL = 7
    I_END_ROW = 32000
    TABLES
    INTERN = IT_FILE_UPLOAD
    EXCEPTIONS
    INCONSISTENT_PARAMETERS = 1
    UPLOAD_OLE = 2
    OTHERS = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " UPLOAD_EXCEL_FILE
    *& Form ORGANIZE_UPLOADED_DATA
    text
    --> p1 text
    <-- p2 text
    FORM ORGANIZE_UPLOADED_DATA .
    SORT IT_FILE_UPLOAD BY ROW
    COL.
    LOOP AT IT_FILE_UPLOAD.
    CASE IT_FILE_UPLOAD-COL.
    WHEN 1.
    WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.
    WHEN 2.
    WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.
    WHEN 3.
    WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.
    WHEN 4.
    WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.
    WHEN 5.
    WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.
    WHEN 6.
    WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.
    WHEN 7.
    WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.
    ENDCASE.
    AT END OF ROW.
    WA_TABDATA-MANDT = SY-MANDT.
    APPEND WA_TABDATA TO IT_TABDATA.
    CLEAR: WA_TABDATA.
    ENDAT.
    ENDLOOP.
    ENDFORM. " ORGANIZE_UPLOADED_DATA
    In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.
    Regards,
    Abir
    Don't forget to award points *

  • Adding a column in an internal table

    Hi,
    I want to know how to add different rows of a  column in an internal table.
    My code :
    Declaration Part-----
    types : begin of imchb,
            clabs like mchb-clabs,
            cumlm like mchb-cumlm,
            cinsm like mchb-cinsm,
            tot_val_stock type p decimals 3,
            pm_percent type p decimals 6,
            end of imchb.
    data : int_inv type standard table of imchb with header line,
           wa_inv like line of int_inv.
    Then I do few calculations and display it in the column pm_percent.
    Now I want to sum this column.
    Summation---
    loop
    at int_inv into wa_inv.
    at end of pm_percent.
    sum.
    endat.
    endloop.
    write :/ wa_inv-pm_percent.
    However , wa_inv-pm_percent only gives me the value of the last row of the column.
    Kindly suggest .

    Hi,
    Please try this code:
    loop at int_inv into wa_inv.
        lv_count = lv_count + 1.
        AT END OF posnr.   <------- The field you want to sum..
          gs_total-posnr      = wa_inv-posnr.
          gs_total-cov_total  = lv_count.
          APPEND gs_total TO gt_total.
          CLEAR : gs_total,
                  lv_count,
                  wa_inv.
        ENDAT.
      ENDLOOP.

  • How to read data in correct format from EXCEL file into an internal table??

    Hi Experts,
    My requirement is to upload data from an excel file on presentation server into an internal table on <b>SRM</b> server.
    I used 'GUI_UPLOAD' function module to achieve the same but all the the data is getting uploaded in # only.I had set in the 'HAS_FIELD_SEPARATOR' to 'X' to overcome this problem.
    But all the efforts are in vain. The function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' doesn't exist on SRM Server and I am not getting any other function module having similar functionality available on SRM server.
    I have written the following code:-
    TYPES: BEGIN OF ty_addr_loc,
             userid    TYPE xubname,      "User Id
             addr_code TYPE char4,        "3 Digit Site Location Code/4 Digit
                                                       "Alternate Address
             loc_id    TYPE bbp_location, "Indicator: Address is standard address
            END OF ty_addr_loc.
    *Retrieving file name
    parameters: p_file type rlgrap-filename.
      DATA:
        Local variable holding file name
          l_file TYPE string,
        Local Variable holding the file type,
          l_type TYPE filetype VALUE 'ASC',
        Local Variable holding the field separator
          l_sep  TYPE char01,
          i_tab type standard table of ty_addr_loc.
    Clearing local variables
      CLEAR:
            l_file,
            l_sep.
    Initializing the local variables
      MOVE p_file TO l_file.
      l_sep = 'X'.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                      = l_file
          filetype                      = l_type
          has_field_separator           = l_sep
       HEADER_LENGTH                 = 0
       READ_BY_LINE                  = 'X'
       DAT_MODE                      = ' '
       CODEPAGE                      = ' '
       IGNORE_CERR                   = ABAP_TRUE
       REPLACEMENT                   = '#'
       CHECK_BOM                     = ' '
       VIRUS_SCAN_PROFILE            =
       NO_AUTH_CHECK                 = ' '
    IMPORTING
       FILELENGTH                    =
       HEADER                        =
        TABLES
          data_tab                     = i_tab
       EXCEPTIONS
         file_open_error               = 1
         file_read_error               = 2
         no_batch                      = 3
         gui_refuse_filetransfer       = 4
         invalid_type                  = 5
         no_authority                  = 6
         unknown_error                 = 7
         bad_data_format               = 8
         header_not_allowed            = 9
         separator_not_allowed         = 10
         header_too_long               = 11
         unknown_dp_error              = 12
         access_denied                 = 13
         dp_out_of_memory              = 14
         disk_full                     = 15
         dp_timeout                    = 16
         OTHERS                        = 17
      IF sy-subrc <> 0.
      Throwing an information message
        MESSAGE i003. "Data Upload Failed
        LEAVE LIST-PROCESSING.
      ENDIF.
    Please tell me a way out. I have to make a delivery urgently.
    Thanks in advance,
    Swati Gupta

    Hi
    Try the FM <b>KCD_EXCEL_OLE_TO_INT_CONVERT</b>
    Sample:
      call function 'KCD_EXCEL_OLE_TO_INT_CONVERT'
           exporting
                filename                = i_filename
                i_begin_col             = l_begin_col
                i_begin_row             = l_begin_row
                i_end_col               = l_end_col
                i_end_row               = l_end_row
           tables
                intern                  = xt_intern
           exceptions
                INCONSISTENT_PARAMETERS = 201
                UPLOAD_OLE              = 201.
      if sy-subrc <> 0.
        e_subrc = sy-subrc.
        exit.
      endif.
    <b>reward if Helpful.</b>

  • Upload an XML file into the Internal table

    Hi Guys,
    I want to know, how to upload an xml file into the Internal table through ABAP programming

    you just wanted to load the xml file into internal table (as a table of binary strings)or load the xml data mapped to itab row columns
    for the first one you can simply use gui_upload
    and for the second one you need to load the xml file using gui_upload and use XLST program to transform into an itab
    Regards
    Raja

  • Collect data from a dynamic XML file into multiple internal tables

    I need to convert the XML file into multiple internal tables. I tried many links and posts in SDN but still was facing difficulty in achieving this. Can some one tell me where I am going wrong.
    My XML file is of the following type.It is very complex and the dynamice.
    The following tags occur more than once in the XML file. The "I" and "L" tags and its child tags can occur ones or more than once for each XML file and it is not constant. i.e in one file they can occur 1 time and in another they can occur 100 times.
    "I" and "L" are child tags of <C>
    <I>
           <J>10</J>
             <K>EN</K>
      </I>
    <L>
             <J>20</J>
              <N>BB</N>
      </L>
    Tags <C> and <F> occur only ones for each XML file. <C> is the child tag of "A" and "F" is the child tag of <C>.
    I need to collect <D>, <E> in one internal table ITAB.
    I need to collect <G>, <H> in one internal table JTAB.
    I need to collect <J>, <K> in one internal table KTAB.
    I need to collect <J>, <N> in one internal table PTAB.
    Below is the complete XML file.
    ?xml version="1.0" encoding="iso-8859-1" ?>
    <A>
        <B/>
        <C>
           <D>RED</D>
           <E>999</E>
        <F>
           <G>TRACK</G>
           <H>PACK</H>
        </F>
        <I>
           <J>10</J>
           <K>EN</K>
        </I>
        <I>
           <J>20</J>
           <K>TN</K>
        </I>
        <I>
           <J>30</J>
           <K>KN</K>
        </I>
        <L>
           <J>10</J>
           <N>AA</N>
        </L>
        <L>
           <J>20</J>
           <N>BB</N>
        </L>
        <L>
           <J>30</J>
           <N>CC</N>
        </L>
        </C>
      </A>
    With the help of SDN I am able to gather the values of <D> <E> in one internal table.
    Now if I need to gather
    <G>, <H> in one internal table JTAB.
    <J>, <K> in one internal table KTAB.
    <J>, <N> in one internal table PTAB.
    I am unable to do. I am following  XSLT transformation method. If some one has some suggestions. Please help.
    Here is my ABAP program
    TYPE-POOLS abap.
    CONSTANTS gs_file TYPE string VALUE 'C:\TEMP\ABCD.xml'.
    * This is the structure for the data from the XML file
    TYPES: BEGIN OF ITAB,
             D(10) TYPE C,
             E(10) TYPE C,
           END OF ITAB.
    * Table for the XML content
    DATA: gt_itab       TYPE STANDARD TABLE OF char2048.
    * Table and work ares for the data from the XML file
    DATA: gt_ITAB     TYPE STANDARD TABLE OF ts_ITAB,
          gs_ITAB     TYPE ts_ITAB.
    * Result table that contains references
    * of the internal tables to be filled
    DATA: gt_result_xml TYPE abap_trans_resbind_tab,
          gs_result_xml TYPE abap_trans_resbind.
    * For error handling
    DATA: gs_rif_ex     TYPE REF TO cx_root,
          gs_var_text   TYPE string.
    * Get the XML file from your client
    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename                = gs_file
      CHANGING
        data_tab                = gt_itab1
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        no_authority            = 6
        unknown_error           = 7
        bad_data_format         = 8
        header_not_allowed      = 9
        separator_not_allowed   = 10
        header_too_long         = 11
        unknown_dp_error        = 12
        access_denied           = 13
        dp_out_of_memory        = 14
        disk_full               = 15
        dp_timeout              = 16
        not_supported_by_gui    = 17
        error_no_gui            = 18
        OTHERS                  = 19.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    * Fill the result table with a reference to the data table.
    * Within the XSLT stylesheet, the data table can be accessed with
    * "IITAB".
    GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
    gs_result_xml-name = 'IITAB'.
    APPEND gs_result_xml TO gt_result_xml.
    * Perform the XSLT stylesheet
    TRY.
        CALL TRANSFORMATION zxslt
        SOURCE XML gt_itab1
        RESULT (gt_result_xml).
      CATCH cx_root INTO gs_rif_ex.
        gs_var_text = gs_rif_ex->get_text( ).
        MESSAGE gs_var_text TYPE 'E'.
    ENDTRY.
    * Now let's see what we got from the file
    LOOP AT gt_ITAB INTO gs_ITAB.
      WRITE: / 'D:', gs_ITAB-D.
      WRITE: / 'E :', gs_ITAB-E.
    ENDLOOP.
    Transformation
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
      <xsl:strip-space elements="*"/>
      <xsl:template match="/">
        <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
          <asx:values>
            <IITAB>
              <xsl:apply-templates select="//C"/>
            </IITAB>
          </asx:values>
        </asx:abap>
      </xsl:template>
      <item>
          <D>
            <xsl:value-of select="D"/>
          </D>
          <E>
            <xsl:value-of select="E"/>
          </E>
        </item>
      </xsl:template>
    </xsl:transform>
    Now the above pgm and transformation work well and I am able to extract data into the ITAB. Now what changes should I make in transformation and in pgm to collect
    <G>, <H> in one internal table JTAB.
    <J>, <K> in one internal table KTAB.
    <J>, <N> in one internal table PTAB.
    Please help..i am really tring hard to figure this out. I am found lot of threads addressing this issue but not my problem.
    Kindly help.
    Regards,
    VS

    Hi Rammohan,
    Thanks for the effort!
    But I don't need to use GUI upload because my functionality does not require to fetch data from presentation server.
    Moreover, the split command advised by you contains separate fields...f1, f2, f3... and I cannot use it because I have 164 fields.  I will have to split into 164 fields and assign the values back to 164 fields in the work area/header line.
    Moreover I have about 10 such work areas.  so the effort would be ten times the above effort! I want to avoid this! Please help!
    I would be very grateful if you could provide an alternative solution.
    Thanks once again,
    Best Regards,
    Vinod.V

Maybe you are looking for