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

Transpose rows and columns

Former Member
0 Likes
1,172

Hello I have an internal table:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

After execution the data should be transposed to display as

1 5 9 13

2 6 10 14

3 7 11 15

4 8 12 16.

Is there any way I can code this or create a dynamic table?

Please help me in this.

Thanks

Hello I have an internal table:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

After execution the data should be transposed to display as

1 5 9 13

2 6 10 14

3 7 11 15

4 8 12 16.

Is there any way I can code this or create a dynamic table?

Please help me in this.

Thanks

6 REPLIES 6
Read only

Former Member
0 Likes
867

Hi,

This is possible only when it is n*n strcuture...I mean... If there are 4 flds in an itab, then the data should also be of 4 records...

Suppose.. if...data is like this,,

fld1 fld2 fld3 fld4

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

17 18 19 20

Now how can you transpose it?

Please give a little clear requirement..in this situation

Read only

0 Likes
867

No I am not able to transpose it any ways.. I have just quoted an example.

Read only

Former Member
0 Likes
867

declare another table.

loop at itab1 into wa_itab1.

split wa_itab1 at '' into table itab2 .

endloop.

Read only

Former Member
0 Likes
867

do like this.

read the internal table line by line, each field and concatenate into a string, or an internal table having only one line,

then read the line by index in multiples of 4,like read first entry then 5th and 9th so on

Read only

0 Likes
867

Thanks kartik,

Already tried this. What if I have n number of columns and rows?

Read only

former_member222860
Active Contributor
0 Likes
867

Hi Dishant,

Here's the logic to transpose rows into columns for n...of

data: begin of itab occurs 0,
        word(100),
        word1(100),
       end of itab.

data: begin of jtab occurs 0,
        word(100),
        word1(100),
       end of jtab.

itab-word = 'field1'.
itab-word1 = 'value1'.
append itab.

itab-word = 'field2'.
itab-word1 = 'value2'.
append itab.

itab-word = 'field3'.
itab-word1 = 'value3'.
append itab.

itab-word = 'field4'.
itab-word1 = 'value4'.
append itab.


loop at itab.
   concatenate jtab-word itab-word into jtab-word separated bY SPACE.
   concatenate jtab-word1 itab-word1 into jtab-word1 separated bY SPACE.
endloop.
  append jtab.
 loop at jtab.
   write:/ jtab-word, jtab-word1.
 endloop.

thanks\

Mahesh