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

Problem with collect statement

Former Member
0 Likes
766

Hi All

I have an internal table with below data:

DATA : BEGIN OF gt_catsdb OCCURS 0,

pernr LIKE catsdb-pernr,

workdate LIKE catsdb-workdate,

rproj LIKE catsdb-rproj,

catshours LIKE catsdb-catshours,

END OF gt_catsdb.

now i want to use collect statement for catshours field.

Can anybody help me this? its very urgent. Pls give the excat data declaration.

Thanks

Babita

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
721

Hi,

Select pernr workdate rproj catshours

into ( itab-pernr, itab-workdate,itab-rproj, itab-catshours)

where pernr in S_pernr.

collect Itab.

endselect.

or

Select pernr workdate rproj catshours

into table ITAB where pernr in S_pernr.

sort itab by pernr workdate.

loop at itab.

at end of pernr.

read table itab index sy-tabix.

SUM.

move-corresponding to ITAB1.

append iTAB1.

endat.

clear itab1.

endloop.

reward if useful

regards,

Anji

6 REPLIES 6
Read only

Former Member
0 Likes
721

Hi..,

In general we use APPEND to fill the interanal table .. instead of that just say COLLECT after filling the internal table..

DATA : BEGIN OF gt_catsdb OCCURS 0,

pernr LIKE catsdb-pernr,

workdate LIKE catsdb-workdate,

rproj LIKE catsdb-rproj,

catshours LIKE catsdb-catshours,

END OF gt_catsdb.

fill the values into the header line of the table gt_catsdb.

after filling use <b>COLLECT gt_catsdb.</b>

gt_catsdb-pernr = '0018'.

gt_catsdb-workdate = sy=datum.

gt_catsdb-rproj = 'NAME'.

gt_catsdb-catshours = 12.

COLLECT gt_catsdb.

thats it !!

regards,

sai ramesh

Read only

Former Member
0 Likes
722

Hi,

Select pernr workdate rproj catshours

into ( itab-pernr, itab-workdate,itab-rproj, itab-catshours)

where pernr in S_pernr.

collect Itab.

endselect.

or

Select pernr workdate rproj catshours

into table ITAB where pernr in S_pernr.

sort itab by pernr workdate.

loop at itab.

at end of pernr.

read table itab index sy-tabix.

SUM.

move-corresponding to ITAB1.

append iTAB1.

endat.

clear itab1.

endloop.

reward if useful

regards,

Anji

Read only

Former Member
0 Likes
721

hi

DATA : BEGIN OF gt_catsdb OCCURS 0,

pernr LIKE catsdb-pernr,

workdate LIKE catsdb-workdate,

rproj LIKE catsdb-rproj,

catshours LIKE catsdb-catshours,

END OF gt_catsdb.

collect gt-catsdb

loop at gt-catsdb

write: gt-catsdb_catshours

endloop

Read only

Former Member
0 Likes
721

hi,

The collect statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key.

If the internal table does not already contain a row with an identical key, the COLLECT statement has the same effect as the following form of the INSERT statement:

for example you can use collect satement

loop at itab into wa.

collect wa into gt_catsdb.

endloop.

remember itab has the same structure as gt_catbd and with some different values which are to be collected into gt_catsdb.

The cathours will get added if with same key and appended if the key is not found,

reward if useful,

regards,

nazeer

Read only

Former Member
0 Likes
721

Hi,

The COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/frameset.htm

Regards,

Suresh

Read only

Former Member
0 Likes
721

thanks to everyone for their prompt replies. points awarded. problem solved...