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

Help !!

Former Member
0 Likes
728

Hi,

I have fields A,B, C in my Internal Table. Now i have to group them by A and B. I.e. if the records in the A and B records are Identical then we group them and display as one line and the contents of C need to be added and displayed in the new record. Please let me know how to achieve this.

eg : A B C

1 2 3 - Record 1

1 2 4 - Record 2

1 3 5 - Record 3

Expected Result:

A B C

1 2 7 - Record 1 - (Added C Contents Record 1 and Record2 above)

1 3 5 - Record 2

Thanks,

FS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
706

Hi,

Declare the fields that you going to make group as character and adding field to be integer.

Copy and paste the below code :

types : begin of tp_itab,
        A type c,
        b type c,
        c type i,
        end of tp_itab.

data: ig_itab type standard table of tp_itab,
      wg_itab type tp_itab.

data: ig_out type standard table of tp_itab,
      wg_out type tp_itab.

wg_itab-a = '1'.
wg_itab-b  = '2'.
wg_itab-c  = 3.
append wg_itab to ig_itab.

wg_itab-a = '1'.
wg_itab-b  = '2'.
wg_itab-c  = 4.
append wg_itab to ig_itab.

wg_itab-a = '1'.
wg_itab-b  = '3'.
wg_itab-c  = 5.
append wg_itab to ig_itab.

loop at ig_itab into wg_itab.
collect wg_itab into ig_out.
clear wg_itab.
endloop.

loop at ig_out into wg_out.
write : / wg_out-a, wg_out-b, wg_out-c.
clear wg_out.
endloop.

Regards,

Raghu

5 REPLIES 5
Read only

Former Member
0 Likes
706

HI

you can do

loop at itab.

collect itab.

endloop.

Regards

Aditya

Read only

Former Member
0 Likes
706

Hi

You can do the following way.

data: beign of itab occurs 0,

A type char2,

B type char2,

c type i,

end of itab.

data: it_out like itab occurs 0.

loop at itab.

collect itab into it_out.

endloop.

You can get the sum based on yr column A and B.

Reward points if it is helpful.

Regards

Raja

Read only

Former Member
0 Likes
707

Hi,

Declare the fields that you going to make group as character and adding field to be integer.

Copy and paste the below code :

types : begin of tp_itab,
        A type c,
        b type c,
        c type i,
        end of tp_itab.

data: ig_itab type standard table of tp_itab,
      wg_itab type tp_itab.

data: ig_out type standard table of tp_itab,
      wg_out type tp_itab.

wg_itab-a = '1'.
wg_itab-b  = '2'.
wg_itab-c  = 3.
append wg_itab to ig_itab.

wg_itab-a = '1'.
wg_itab-b  = '2'.
wg_itab-c  = 4.
append wg_itab to ig_itab.

wg_itab-a = '1'.
wg_itab-b  = '3'.
wg_itab-c  = 5.
append wg_itab to ig_itab.

loop at ig_itab into wg_itab.
collect wg_itab into ig_out.
clear wg_itab.
endloop.

loop at ig_out into wg_out.
write : / wg_out-a, wg_out-b, wg_out-c.
clear wg_out.
endloop.

Regards,

Raghu

Read only

0 Likes
706

Thanks All,

Raghu that was very helpful. Thank You Very Much.

Regards,

FS

Read only

Former Member
0 Likes
706

Hi,

data : begin of itab occurs 0,

A(1) type n,

B(1) type n,

C type i,

end of itab.

itab-A = '1'.

itab-B = '2'.

itab-C = 3.

collect itab.

itab-A = '1'.

itab-B = '2'.

itab-C = 4.

collect itab.

itab-A = '1'.

itab-B = '3'.

itab-C = 5.

collect itab.

loop at itab.

write : / itab-A, itab-B,itab-C.

endloop.

Thanks.