Application Development 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: 

Reg: Collect statement in internal table

Former Member
0 Kudos

Hi,

Can any one tell me wether we can use the collect statement in an internal table which has no header line

if it can be used can anyone please send me a sample snippet

Thanks In ADVANCE

Guhapriyan Subrahmanyam

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

COLLECT is used to create unique or compressed datasets. The key fields are the default key fields of the internal table itab.

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

******************

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

*****************

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

Thanks.

If it helps you award points and close the thread.

5 REPLIES 5

Former Member
0 Kudos

Hi,

COLLECT is used to create unique or compressed datasets. The key fields are the default key fields of the internal table itab.

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

******************

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

*****************

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.

Thanks.

If it helps you award points and close the thread.

Former Member
0 Kudos

Yeap, there is no problem.

But you need a structure, like this:

data: w_1 type ty_1 ,

it_1 type table of ty_1 .

collect w_1 into it_1 .

Alexandre Nogueira

Former Member
0 Kudos

Hi Guhapriyan,

I have used the collect statement in the way as shown..

DATA : BEGIN of I_ALLOCATIONS OCCURS 0,

PSPNR LIKE PRPS-PSPNR,

PSPID LIKE PROJ-PSPID,

PSPHI LIKE PRPS-PSPHI,

POST1 LIKE PROJ-POST1,

ZZLOB LIKE PROJ-ZZLOB,

WERKS LIKE PROJ-WERKS,

SOBID LIKE HRP1001-SOBID,

OBJID LIKE HRP1001-OBJID,

BEGDA LIKE HRP1001-BEGDA,

ENDDA LIKE HRP1001-ENDDA,

PROZT LIKE HRP1001-PROZT,

LOB LIKE HRP1000-STEXT,

TEMP TYPE P decimals 2,

TYPE(3),

ZROLE LIKE PA0001-ZROLE,

HOLID TYPE P decimals 2,

LEAVE TYPE P decimals 2,

DAYS TYPE P decimals 2,

END of I_ALLOCATIONS.

DATA: I_ALLOCATION LIKE I_ALLOCATIONS OCCURS 0 WITH HEADER LINE.

************Populate I_ALLOCATIONS **************

LOOP AT I_ALLOCATIONS.

COLLECT I_ALLOCATIONS INTO I_ALLOCATION.

ENDLOOP.

Actually i had requirement like u, but this one is rather simple...

Get the required data in an I_Table which dont require Header line..

Later on collect this particular I_Table in other I_Table1 with the Header Line...

Regards,

Abhishek

abdul_hakim
Active Contributor
0 Kudos

Yes u can add line into itab which has no header line.

Check the below link.

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/frameset.htm

Regards,

Abdul

Former Member
0 Kudos

If you use only COLLECT to fill an internal table, COLLECT makes sure that the internal table does not contain two entries with the same default key fields.

If, besides its default key fields, the internal table contains number fields (see also ABAP/4 number types ), the contents of these number fields are added together if the internal table already contains an entry with the same key fields.

If the default key of an internal table processed with COLLECT is blank, all the values are added up in the first table line.

If you specify wa INTO , the entry to be processed is taken from the explicitly specified work area wa . If not, it comes from the header line of the internal table itab .

After COLLECT , the system field SY-TABIX contains the index of the - existing or new - table entry with default key fields which match those of the entry to be processed.