Application Development 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: 

converting columns to rows

Former Member
0 Kudos
646

Hi,

I have the following structure :

4 keys followed by 94 data columns.

Ex: A B C D 1 2 3 4 ....

and I would like to convert it into

A B C D sy-datum 1

A B C D sy-datum-1 2

Can anyone help me with the code.

thanks

amit

1 ACCEPTED SOLUTION

Former Member
0 Kudos
94

Hi,

I tried this 4 keys and additional three fields..It worked..

DATA: BEGIN OF S_STRUC,

KEY1,

KEY2,

KEY3,

KEY4,

FIRST TYPE CHAR10 VALUE 'FIRST',

SECOND TYPE CHAR10 VALUE 'SECOND',

THRIRD TYPE CHAR10 VALUE 'THIRD',

END OF S_STRUC.

DATA: ITAB LIKE S_STRUC OCCURS 0 WITH HEADER LINE.

DATA: V_INT TYPE INT4.

FIELD-SYMBOLS: <FS>, <FS1>.

DO 3 TIMES.

V_INT = SY-INDEX + 4.

ITAB-KEY1 = 'A'.

ITAB-KEY2 = 'B'.

ITAB-KEY3 = 'C'.

ITAB-KEY4 = 'D'.

ASSIGN COMPONENT V_INT OF STRUCTURE S_STRUC TO <FS>.

ASSIGN COMPONENT V_INT OF STRUCTURE ITAB TO <FS1>.

<FS1> = <FS>.

APPEND ITAB.

ENDDO.

LOOP AT ITAB.

WRITE: / ITAB.

ENDLOOP.

Thanks,

Naren

Message was edited by: Narendran Muthukumaran

5 REPLIES 5

Former Member
0 Kudos
94

Hi,

Try this..

DATA: ITAB LIKE STRUCTURE OCCURS 0 WITH HEADER LINE.

DATA: V_INT TYPE INT4.

FIELD-SYMBOLS: <FS>, <FS1>.

DO 90 TIMES.

V_INT = SY-INDEX + 4.

ITAB-KEY1 = 'A'.

ITAB-KEY2 = 'B'.

ITAB-KEY3 = 'C'.

ITAB-KEY4 = 'D'.

ASSIGN COMPONENT V_INT OF STRUCTURE S_STRUC TO <FS>.

ASSIGN COMPONENT V_INT OF STRUCTURE ITAB TO <FS1>.

<FS1> = <FS>.

APPEND ITAB.

ENDDO.

Thanks,

Naren

0 Kudos
94

Naren,

Thanks , but I maybe not reading the code correctly.

If V_INT is incremented by 4

ASSIGN COMPONENT V_INT OF STRUCTURE S_STRUC TO <FS>.

this statement will correctly get me the first column in the first run but in the second run it will skip the next 3 columns .

Am i missing something.

thanks again for the quick response.

regards

amit

Former Member
0 Kudos
94

Hi,

If you see the incrementing part..I am incrementing sy-index + 4.

Which means..First time it will be 5..Second time it will be 6..

Thanks,

Naren

Former Member
0 Kudos
95

Hi,

I tried this 4 keys and additional three fields..It worked..

DATA: BEGIN OF S_STRUC,

KEY1,

KEY2,

KEY3,

KEY4,

FIRST TYPE CHAR10 VALUE 'FIRST',

SECOND TYPE CHAR10 VALUE 'SECOND',

THRIRD TYPE CHAR10 VALUE 'THIRD',

END OF S_STRUC.

DATA: ITAB LIKE S_STRUC OCCURS 0 WITH HEADER LINE.

DATA: V_INT TYPE INT4.

FIELD-SYMBOLS: <FS>, <FS1>.

DO 3 TIMES.

V_INT = SY-INDEX + 4.

ITAB-KEY1 = 'A'.

ITAB-KEY2 = 'B'.

ITAB-KEY3 = 'C'.

ITAB-KEY4 = 'D'.

ASSIGN COMPONENT V_INT OF STRUCTURE S_STRUC TO <FS>.

ASSIGN COMPONENT V_INT OF STRUCTURE ITAB TO <FS1>.

<FS1> = <FS>.

APPEND ITAB.

ENDDO.

LOOP AT ITAB.

WRITE: / ITAB.

ENDLOOP.

Thanks,

Naren

Message was edited by: Narendran Muthukumaran

0 Kudos
94

Naren,

Thanks makes sense , i am awarding full points as it will take me sometime to work on this code and if i future doubts i will get back to this thread.

thanks

amit