Skip to Content

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 04:03 PM

    if you have the main internal table in this order:

    ASLN2 1 1 Company_Code 5146
      ASLN2 1 1 Account_Code 400405
      ASLN2 1 1 Profit_Centre AA00N2

    1° Company_Code

    2° Account_Code

    3° Profit_Centre

    you can do like that:

    LOOP AT ti_main.
      ti_aux-PATH_ID = ti_main-PATH_ID.
      ti_aux-GROUP = ti_main-GROUP.
      ti_aux-LINE = ti_main-LINE.
      
      CASE ti_main-ATRIBUTE.
        WHEN 'Company_Code'.
          ti_aux-Company_Code = ti_main-VALUE.
        WHEN 'Account_Code'.
          ti_aux-Account_Code = ti_main-VALUE.
        WHEN 'Profit_Centre'.
          ti_aux-Profit_Centre = ti_main-VALUE.
      ENDCASE.
      
      IF ti_main-ATRIBUTE EQ 'Profit_Centre'.
        APPEND ti_aux.
      ENDIF.
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 04:01 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded