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
595

hi,

my internal table is like this,

having 3 fields

number, material, quantiy values are

1,mat1,10

2,mat2,20

3,mat1,30

4,mat3,40

and i want o/p as mat1=30

mat2= 20,mat3=40

pls help me.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
570

Hi,

Sort itab by matnr.

Delete adjacent duplicates from itab comparing matnr.

5 REPLIES 5
Read only

Former Member
0 Likes
570

If you are sure with your table format you can do this way:

<field-symbols>: <f_fs1> type data,

<f_fs2> type any.

data: l_text type string.

loop at itab into <f_fs1>.

do 3 times.

ASSIGN COMPONENT sy-index OF STRUCTURE <f_fs1> TO <f_fs2>.

if sy-index eq 1.

l_text = <f_fs2>

else.

concatenate <f_fs2> l_text into l_text.

enddo.

endloop.

regards,

SV.

Read only

Former Member
0 Likes
571

Hi,

Sort itab by matnr.

Delete adjacent duplicates from itab comparing matnr.

Read only

Former Member
0 Likes
570

Hi ,

U can use append sorted by statement.

and define internal table size is occurs 3.

it will append internal table upto 3 records only.

and mentioned the sort field by last field i mean ur number field (10,20,30)

then u will get correct answer.

try with this.

mean while i try and send you code.

thanks,

surendra Babu vemula

Read only

karol_seman
Active Participant
0 Likes
570

Hi Venkat,

to get collected values check the key word "COLLECT".

To remove duplicates sort the table by field you want to eliminate duplicates and use DELETE ADJACENT DUPLICATES FROM <itab> comparing <f1> ... <fn>

Regards,

Karol

Read only

Former Member
0 Likes
570

Hi venkat,

you use this code and try you will get exact code what u r expecting.

DATA: BEGIN OF itab OCCURS 3,

f1 TYPE i,

f2(10) TYPE c,

f3 TYPE i,

END OF itab.

*

itab-f1 = 1.

itab-f2 = 'MAT1'.

itab-f3 = 10.

APPEND itab.

CLEAR itab.

*

itab-f1 = 2.

itab-f2 = 'MAT2'.

itab-f3 = 20.

APPEND itab.

CLEAR itab.

*

itab-f1 = 3.

itab-f2 = 'MAT1'.

itab-f3 = 30.

APPEND itab.

CLEAR itab.

*

itab-f1 = 4.

itab-f2 = 'MAT3'.

itab-f3 = 40.

APPEND itab.

CLEAR itab.

*

SORT itab BY f2 f3 DESCENDING.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f2.

*

LOOP AT itab.

WRITE: / itab-f2, '=', itab-f3.

ENDLOOP.

output:

MAT1 = 30

MAT2 = 20

MAT3 = 40

thanks,

surendra babu vemula