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

collect statement

Former Member
0 Likes
1,081

lets say I was collecting this:

employee name deduction contribution

john doe 500 0

john doe 0 500

for some reason my program appends this instead of collecting it, any ideas.

thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,006

Ok, I don't see anything wrong with your table structure. I did a little program and it is working fine.



types:
begin of data_struc_totals,
group(12) type c, "group
curr like t5ud3-curre,
pen_num type i, "number of pensioners
reg_num type i, "number of regulars
pen_rem type p decimals 2, "remittance pensioners
reg_rem type p decimals 2, "remittance regulars
pen_cov type p decimals 2, "coverage pensioners
reg_cov type p decimals 2, "coverage regulars
rem_tot type p decimals 2,"Grand Total
cov_tot type p decimals 2,
grand_tot type p decimals 2,
end of data_struc_totals.

data: itab type table of data_struc_totals with header line.

start-of-selection.



clear itab.
itab-group      = 'A'.
itab-curr       = 'USD'.
itab-pen_num    = '3'.
itab-reg_num    = '2'.
itab-pen_rem    = '5.00'.
collect itab.

clear itab.
itab-group      = 'A'.
itab-curr       = 'USD'.
itab-pen_num    = '1'.
itab-reg_num    = '3'.
itab-pen_rem    = '10.00'.
collect itab.


check sy-subrc  = 0.


This code writes one line in the table

A,USD,4,5,15

Can you post some more of your code showing exactly where you problem is.

Regards,

Rich Heilman

10 REPLIES 10
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,006

What is the structure of you internal table. What are the fields/types. Maybe post some relevant code.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,006

Hi Jamie,

For a collect to work, your fields that need to be added should be of numeric type(P,I or F). They cannot be C or N.

Srinivas

Read only

Former Member
0 Likes
1,006

types:

begin of data_struc_totals,

group(12) type c, "group

curr like t5ud3-curre,

pen_num type i, "number of pensioners

reg_num type i, "number of regulars

pen_rem type p decimals 2, "remittance pensioners

reg_rem type p decimals 2, "remittance regulars

pen_cov type p decimals 2, "coverage pensioners

reg_cov type p decimals 2, "coverage regulars

rem_tot type p decimals 2,"Grand Total

cov_tot type p decimals 2,

grand_tot type p decimals 2,

end of data_struc_totals.

here is the data structure,

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,007

Ok, I don't see anything wrong with your table structure. I did a little program and it is working fine.



types:
begin of data_struc_totals,
group(12) type c, "group
curr like t5ud3-curre,
pen_num type i, "number of pensioners
reg_num type i, "number of regulars
pen_rem type p decimals 2, "remittance pensioners
reg_rem type p decimals 2, "remittance regulars
pen_cov type p decimals 2, "coverage pensioners
reg_cov type p decimals 2, "coverage regulars
rem_tot type p decimals 2,"Grand Total
cov_tot type p decimals 2,
grand_tot type p decimals 2,
end of data_struc_totals.

data: itab type table of data_struc_totals with header line.

start-of-selection.



clear itab.
itab-group      = 'A'.
itab-curr       = 'USD'.
itab-pen_num    = '3'.
itab-reg_num    = '2'.
itab-pen_rem    = '5.00'.
collect itab.

clear itab.
itab-group      = 'A'.
itab-curr       = 'USD'.
itab-pen_num    = '1'.
itab-reg_num    = '3'.
itab-pen_rem    = '10.00'.
collect itab.


check sy-subrc  = 0.


This code writes one line in the table

A,USD,4,5,15

Can you post some more of your code showing exactly where you problem is.

Regards,

Rich Heilman

Read only

0 Likes
1,006

your just putting collect itab,

I'm putting collect itab into (results table).

Read only

0 Likes
1,006

k, what does your results table look like, and how are you moving the data from one table to the other. Please post some relevant code.



types:
begin of data_struc_totals,
group(12) type c, "group
curr like t5ud3-curre,
pen_num type i, "number of pensioners
reg_num type i, "number of regulars
pen_rem type p decimals 2, "remittance pensioners
reg_rem type p decimals 2, "remittance regulars
pen_cov type p decimals 2, "coverage pensioners
reg_cov type p decimals 2, "coverage regulars
rem_tot type p decimals 2,"Grand Total
cov_tot type p decimals 2,
grand_tot type p decimals 2,
end of data_struc_totals.

data: itab type table of data_struc_totals with header line.
data: itab2 type table of data_struc_totals with header line.


start-of-selection.

  clear itab.
  itab-group      = 'A'.
  itab-curr       = 'USD'.
  itab-pen_num    = '3'.
  itab-reg_num    = '2'.
  itab-pen_rem    = '5.00'.
  append itab.

  clear itab.
  itab-group      = 'A'.
  itab-curr       = 'USD'.
  itab-pen_num    = '1'.
  itab-reg_num    = '3'.
  itab-pen_rem    = '10.00'.
  append itab.

  check sy-subrc  = 0.


  loop at itab.
    move-corresponding itab to itab2.
    collect itab into itab2.
  endloop.

  check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

0 Likes
1,006

data: i_results_totals type table of data_struc_totals with header line.

data: wa_results_totals type data_struc_totals. "Work area

collect wa_results_totals into i_results_totals.

here is the output

OP 40-44 0 0.00 0.00 111 1,561.81 0.00 1,561.81 0.00 0.00

OP 45-49 0 0.00 0.00 127 3,303.88 60,000.00 3,303.88 60,000.00 0.00

OP 50-54 0 0.00 0.00 119 4,992.77 60,000.00 4,992.77 60,000.00 0.00

OP 50-54 40 3,752.47 42,760,000.00 0 0.00 0.00 3,752.47 42,760,000.00 0.00

OP 55-59 0 0.00 0.00 79 5,690.44 60,000.00 5,690.44 60,000.00 0.00

OP 55-59 167 22,895.74 160,000,000.00 0 0.00 0.00 22,895.74 160,000,000.00 0.00

you see how it is not collecting the 55-59 group or the 50-54 group all the time. It does it for a while then appends another line and uses that one for collecting.

Read only

0 Likes
1,006

Just a hunch!

Check to see if the currencies (CURR) are the same for all the lines. Seems like that is the problem.

Rishi

Read only

0 Likes
1,006

that was a good hunch.

thanks a bunch

Read only

0 Likes
1,006

Thought that it was understood that anything left of the first numerical field to be collected is the key.....

program will collect by key only, in your case group and currency.

Regards,

Rich Heilman