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

moving data

Former Member
0 Likes
1,859

Hi

i have a internal table which contains data like

a1 a2 a3

100 10

100 20

100 30

100 1000

100 2000

i need the data like

100 1000 10

100 2000 20

100 30

can any one help its urgent me

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,835

hi

try this code.

data : count type i,

count1 type i.

loop at itab1 .

count = sy-tabix.

read table itab2 with key a1 = itab2-a1.

count1 = sy-tabix.

if sy-subrc = 0.

itab1-a2 = itab2-a2.

delete itab2 index count1 .

modify itab1 index count transporting a2.

endif.

endloop.

If you require itab2 data to be stored or not to be deleted try using a buffer .

I have tested this code it works.

Please reward if useful.

13 REPLIES 13
Read only

Former Member
0 Likes
1,836

hi

try this code.

data : count type i,

count1 type i.

loop at itab1 .

count = sy-tabix.

read table itab2 with key a1 = itab2-a1.

count1 = sy-tabix.

if sy-subrc = 0.

itab1-a2 = itab2-a2.

delete itab2 index count1 .

modify itab1 index count transporting a2.

endif.

endloop.

If you require itab2 data to be stored or not to be deleted try using a buffer .

I have tested this code it works.

Please reward if useful.

Read only

Former Member
0 Likes
1,835

Hi,

This is the fixed data in your internal; table? only thease are the records?

You mean two coumns data has to come into 3 columns ?

what's the logic for the second column? 10, 20 , 30, 1000, 2000

to come to 1000,2000, 30, what's this sequence/ we can hard code like that, but can't sort or do nothing?

I hope the requirement is not correct.

Regards,

Anji

Read only

Former Member
0 Likes
1,835

the data above one is not displayed correctly

a1 , a2 , a3

100 , , 10

100 , , 20

100 , , 30

100 , 1000 ,

100 , 2000 ,

i need

100 , 1000 , 10

100 , 2000 , 20

100 , , 30

Read only

Former Member
0 Likes
1,835

itab1 has

a1 a2 a3

100 10

100 20

100 30

itab2 has

a1 a4

100 1000

100 2000

loop at itab1.

read table itab2 with key a1 = itab1-a1

a4+0(2) = itab1-a2.

if sy-subrc = 0.

<move data>.

<append data>.

endif.

endloop.

Read only

Former Member
0 Likes
1,835

the data above one is not displayed correctly

a1 , a2 , a3

100 , , 10

100 , , 20

100 , , 30

100 , 1000 ,

100 , 2000 ,

i need

100 , 1000 , 10

100 , 2000 , 20

100 , , 30

Read only

Former Member
0 Likes
1,835

Hi Kiran,

Let me know ur reqmnt

Read only

0 Likes
1,835

i have one internal table that contains data like

a1 field contains

1000

1000

1000

1000

1000

a2 field contains

space

space

space

1000

2000

a3 contain

10

20

30

space

space

now i want to move second field value to up

finally i need

100 1000 10

100 2000 20

100 space 30

suppose if the second field contain 3 values and third field contains 2 values i want

100 1000 10

100 2000 20

100 3000 space

plz hlp me

Read only

0 Likes
1,835

can any one plz help me

Read only

Former Member
0 Likes
1,835

hlp me any one

Read only

0 Likes
1,835

Hi,

Hope this helps:

DATA: BEGIN OF itab OCCURS 0,

a1 TYPE i,

a2 TYPE i,

a3 TYPE i,

a4 TYPE i,

END OF itab.

DATA: fieldtext1(20).

DATA: fieldtext2(20).

DATA: f1 TYPE n.

DATA: f2 TYPE n.

FIELD-SYMBOLS: <fs1> TYPE ANY.

FIELD-SYMBOLS: <fs2> TYPE ANY.

ITAB-A1 = 10.

ITAB-A2 = 0.

ITAB-A3 = 25.

ITAB-A4 = 12.

APPEND ITAB.

LOOP AT itab.

DO 4 TIMES.

f1 = sy-index.

CONCATENATE 'ITAB-A' f1 INTO fieldtext1.

ASSIGN (fieldtext1) TO <fs1>.

f2 = sy-index + 1.

CONCATENATE 'ITAB-A' f2 INTO fieldtext2.

ASSIGN (fieldtext2) TO <fs2>.

IF <fs1> = 0.

<fs1> = <fs2>.

CLEAR: <fs2>.

ENDIF.

ENDDO.

MODIFY itab.

ENDLOOP.

End result will be:

itab-a1 = 10.

itab-a2 = 25.

itab-a3 = 12.

itab-a4 = 0.

In this you need to follow the field naming convention.

Regards,

S. Chandra Mouli.

Read only

Former Member
0 Likes
1,835

Hi Kiran,

The data is of which type, CHAR(4) or TYPE I or NUMC.

Read only

0 Likes
1,835

those are character fields

Read only

former_member784222
Active Participant
0 Likes
1,835

Hi Kiran,

Please discard the code from my previous post:

the following will be the code. You can modify it for character field as well.

Instead of checking <fs1> = 0, you can check <fs1> = space.

<i>DATA: BEGIN OF itab OCCURS 0,

a1 TYPE i,

a2 TYPE i,

a3 TYPE i,

a4 TYPE i,

END OF itab.

DATA: fieldtext1(20).

DATA: fieldtext2(20).

DATA: f1 TYPE n.

DATA: f2 TYPE n.

DATA: outer TYPE i.

FIELD-SYMBOLS: <fs1> TYPE ANY.

FIELD-SYMBOLS: <fs2> TYPE ANY.

itab-a1 = 0.

itab-a2 = 10.

itab-a3 = 0.

itab-a4 = 12.

APPEND itab.

LOOP AT itab.

DO 4 TIMES.

f1 = sy-index.

outer = sy-index.

CONCATENATE 'ITAB-A' f1 INTO fieldtext1.

ASSIGN (fieldtext1) TO <fs1>.

WHILE <fs1> = 0.

f2 = outer + sy-index.

CONCATENATE 'ITAB-A' f2 INTO fieldtext2.

ASSIGN (fieldtext2) TO <fs2>.

IF <fs1> = 0.

<fs1> = <fs2>.

CLEAR: <fs2>.

ENDIF.

IF f2 = 5 OR <fs1> NE 0.

EXIT.

ENDIF.

ENDWHILE.

ENDDO.

MODIFY itab.

ENDLOOP.

LOOP AT itab.

ENDLOOP.</i>

Try and revert.

Thanks and regards,

S. Chandra Mouli.