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

Internal table

Former Member
0 Likes
428

Hi all,

I have an internal internal table like given below.

F1 F2 F3 F4 F5 F6 F7 F8

1 ab c d e

1 ab f g h

2 bc x y z i j

3 cd i j k l m n

If F1 & F2 have common values, then I need the output as like this,

F1 F2 F3 F4 F5 F6 F7 F8

1 ab c d e f g h

2 bc x y z i j

3 cd i j k l m n

Any sample code available please post me

Thanks

U. Uma

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
406

Hi,

I tried and its working fine.you just copy the code below and run.you will get same.

REPORT zstemp_qty2_ LINE-SIZE 255 .

DATA:BEGIN OF itab OCCURS 0,

f1(1),

f2(2),

f3(1),

f4(1),

f5(1),

f6(1),

f7(1),

f8(1),

END OF itab.

DATA:v_indx LIKE sy-index.

DATA:itab1 LIKE itab OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

itab-f1 = '1' . itab-f2 = 'ab'.

itab-f3 = 'c'. itab-f4 = 'd'.

itab-f5 = 'e'.

APPEND itab. CLEAR itab.

itab-f1 = '1' . itab-f2 = 'ab'.

itab-f3 = 'f'. itab-f4 = 'g'.

itab-f5 = 'h'.

APPEND itab. CLEAR itab.

itab-f1 = '2' .

itab-f2 = 'bc'.

itab-f3 = 'x'.

itab-f4 = 'y'.

itab-f5 = 'z'.

itab-f6 = 'i'.

itab-f7 = 'j'.

APPEND itab. CLEAR itab.

itab-f1 = '3' .

itab-f2 = 'cd'.

itab-f3 = 'i'.

itab-f4 = 'j'.

itab-f5 = 'k'.

itab-f6 = 'l'.

itab-f7 = 'm'.

itab-f8 = 'n'.

APPEND itab. CLEAR itab.

itab1[] = itab[] . " copy the data frm one table to other

LOOP AT itab.

v_indx = sy-tabix + 1.

READ TABLE itab1 INDEX v_indx.

IF sy-subrc = 0 AND itab-f1 = itab-f1 AND itab1-f2 = itab-f2.

itab-f5 = itab1-f3.

itab-f6 = itab1-f4.

itab-f7 = itab1-f5.

MODIFY itab TRANSPORTING f5 f6 f7.

CLEAR itab.

DELETE itab1 INDEX v_indx.

ENDIF.

ENDLOOP.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.

LOOP AT itab.

WRITE: / itab-f1,itab-f2,itab-f3,itab-f4,

itab-f5,itab-f6,itab-f7,itab-f8.

ENDLOOP.

Regds

Sivaparvathi

Please reward points if helpful...................

Edited by: Siva Parvathi on Dec 20, 2007 9:13 AM

4 REPLIES 4
Read only

Vijay
Active Contributor
0 Likes
406

hi

sort itab by f1 f2.

DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2.

this will solve ur problem.

regards

vijay

reward points if helpfull

Read only

Former Member
0 Likes
406

Hi Uma,

Do like this

Data: wa1 like line of itab,

cnt type i,

lv_lines type i.

Describe table itab lines lv_lines.

Loop at itab into wa.

cnt = cnt + 1.

if sy-index GT 1.

if wa1-F1 EQ wa-F1.

concatenate wa1-F2 wa-F2 into wa1-F2.

append wa1 to itab.

delete itab from wa.

endif.

endif.

if cnt = lv_lines.

exit.

endif.

Move wa to wa1.

Endloop.

Regards,

Satish

Read only

former_member404244
Active Contributor
0 Likes
406

Hi,

Try like this

V_INDEX = 2.

LOOP AT ITAB INTO WA.

READ TABLE ITAB1 INTO WA1 INDEX V_INDEX.

IF WA1-F1 = WA-F1 AND WA1-F2 = WA-F2.

MOVE : WA-F1 TO WA2-F1,

WA-F2 TO WA2-F2,

WA-F3 TO WA2-F3,

WA-F4 TO WA2-F4,

WA-F5 TO WA2-F5,

WA1-F3 TO WA2-F6,

WA1-F4 TO WA2-F7.

APPEND ITAB1 FROM WA2.

CLEAR: WA1,WA2,WA.

ENDIF.

V_INDEX = V_INDEX + 1.

ENDLOOP.

Regards,

Nagaraj

Read only

Former Member
0 Likes
407

Hi,

I tried and its working fine.you just copy the code below and run.you will get same.

REPORT zstemp_qty2_ LINE-SIZE 255 .

DATA:BEGIN OF itab OCCURS 0,

f1(1),

f2(2),

f3(1),

f4(1),

f5(1),

f6(1),

f7(1),

f8(1),

END OF itab.

DATA:v_indx LIKE sy-index.

DATA:itab1 LIKE itab OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

itab-f1 = '1' . itab-f2 = 'ab'.

itab-f3 = 'c'. itab-f4 = 'd'.

itab-f5 = 'e'.

APPEND itab. CLEAR itab.

itab-f1 = '1' . itab-f2 = 'ab'.

itab-f3 = 'f'. itab-f4 = 'g'.

itab-f5 = 'h'.

APPEND itab. CLEAR itab.

itab-f1 = '2' .

itab-f2 = 'bc'.

itab-f3 = 'x'.

itab-f4 = 'y'.

itab-f5 = 'z'.

itab-f6 = 'i'.

itab-f7 = 'j'.

APPEND itab. CLEAR itab.

itab-f1 = '3' .

itab-f2 = 'cd'.

itab-f3 = 'i'.

itab-f4 = 'j'.

itab-f5 = 'k'.

itab-f6 = 'l'.

itab-f7 = 'm'.

itab-f8 = 'n'.

APPEND itab. CLEAR itab.

itab1[] = itab[] . " copy the data frm one table to other

LOOP AT itab.

v_indx = sy-tabix + 1.

READ TABLE itab1 INDEX v_indx.

IF sy-subrc = 0 AND itab-f1 = itab-f1 AND itab1-f2 = itab-f2.

itab-f5 = itab1-f3.

itab-f6 = itab1-f4.

itab-f7 = itab1-f5.

MODIFY itab TRANSPORTING f5 f6 f7.

CLEAR itab.

DELETE itab1 INDEX v_indx.

ENDIF.

ENDLOOP.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.

LOOP AT itab.

WRITE: / itab-f1,itab-f2,itab-f3,itab-f4,

itab-f5,itab-f6,itab-f7,itab-f8.

ENDLOOP.

Regds

Sivaparvathi

Please reward points if helpful...................

Edited by: Siva Parvathi on Dec 20, 2007 9:13 AM