Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

invert table - columns per rows

Former Member
0 Likes
665

hi experts,

how can i do this.. i want to print the columns of a i-table as rows.. like inverting the table.. for example something like...

table1

  • col1 col2 col3

row1 1.00 2.00 3.00

row2 4.00 5.00 6.00

waht i want is to get this

  • row1 row2

col1 1.00 4.00

col2 2.00 5.00

col3 3.00 6.00

is there like a function ?? or someone had have done this???

thx in advanceee

4 REPLIES 4
Read only

former_member194669
Active Contributor
0 Likes
563

Please search this forum with keyword "dynamic AND Internal AND table " you can find examples

a®

Read only

Former Member
0 Likes
563

Hi,

You can try something like this.

Internal table itab_1 has 2 rows:

11 12

21 22

itab_2 will have inversed data as follows:

11 21

12 22


TYPES: BEGIN OF t_itab,
        fld1 TYPE i,
        fld2 TYPE i,
      END OF t_itab.
DATA: itab_1 TYPE t_itab OCCURS 0 WITH HEADER LINE,
       itab_2 TYPE t_itab OCCURS 0 WITH HEADER LINE.

DATA: v_counter TYPE i,
      v_index LIKE sy-index.
FIELD-SYMBOLS: <fs1> TYPE ANY,
               <fs2> TYPE ANY.
itab_1-fld1 = '11'.
itab_1-fld2 = '12'.
APPEND itab_1.
itab_1-fld1 = '21'.
itab_1-fld2 = '22'.
APPEND itab_1.

DESCRIBE TABLE itab_1 LINES v_counter.

DO v_counter TIMES.
  v_index = sy-index.
  LOOP AT itab_1.

    CASE v_index.
      WHEN '1'.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE itab_2 TO <fs1>.
        MOVE itab_1-fld1 TO <fs1>.

      WHEN '2'.
        ASSIGN COMPONENT sy-tabix OF STRUCTURE itab_2 TO <fs2>.
        MOVE itab_1-fld2 TO <fs2>.
    ENDCASE.
  ENDLOOP.
  APPEND itab_2.
ENDDO.

Cheers,

Vikram

Read only

0 Likes
563

thx Vikram for the answer but.. my internal table have a column for each day of the month .. so i have like a 30 columns and like 20 rows ..

how can i take each column and append it to another table row??

thx in advance

Read only

0 Likes
563

well in case someone has the same problem, wat i did was a loop for the table as many columns it has, and passing the values with field symbols to the new table

do (columns)

loop table

endloop.

enddo.

greetings.