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: 

collect

Former Member
0 Kudos

can we use COLLECT statement on character field?

i got one old report. in that it was written collect statement on character field.

thanks in advance,

Ramakrishna.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

COLLECT allows you to create unique or summarized datasets.

The system first tries to find a table entry corresponding to the table key.

The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa.

The line type of itab must be flat - that is, it cannot itself contain any internal tables.

All the components that do not belong to the key must be numeric types

( ABAP Numeric Types).

<b></b><b></b>

Bye,

KC

6 REPLIES 6

Former Member
0 Kudos

Hi

  • Using Collect Statement

DATA : BEGIN OF ITAB OCCURS 0,

COL1(3) TYPE C,

COL2 TYPE I,

END OF ITAB.

ITAB-COL1 = 'ABC'.

ITAB-COL2 = 50.

COLLECT ITAB.

ITAB-COL1 = 'ABC'.

ITAB-COL2 = 100.

COLLECT ITAB.

ITAB-COL1 = 'ABC'.

ITAB-COL2 = 150.

COLLECT ITAB.

ITAB-COL1 = 'PQR'.

ITAB-COL2 = 100.

COLLECT ITAB.

ITAB-COL1 = 'PQR'.

ITAB-COL2 = 100.

COLLECT ITAB.

ITAB-COL1 = 'XYZ'.

ITAB-COL2 = 200.

COLLECT ITAB.

LOOP AT ITAB.

WRITE : / ITAB-COL1, ITAB-COL2.

ENDLOOP.

SORT ITAB.

LOOP AT ITAB.

AT FIRST.

WRITE: / 'AT NEW STATEMENT'.

ULINE.

ENDAT.

AT NEW COL1.

WRITE: / ' AT FIRST OF :', ITAB-COL1.

ENDAT.

WRITE : / ITAB-COL1, ITAB-COL2.

AT LAST.

ULINE.

ENDAT.

ENDLOOP.

Former Member
0 Kudos

Hi Krishna,

You can use COLLECT on Char field. But values will not get accumulated. It will work as Append statement.

Reward if this helps,

Satish

naimesh_patel
Active Contributor
0 Kudos

Collect works like:

ITAB:

CHAR  CNT
N1     100
N1     200
N2     300
N2     400

Than collect

LOOP AT ITAB.
  MOVE-CORRESPONDING ITAB TO IT_SUM
  COLLECT IT_SUM.
ENDLOOP.

After this IT_SUM will have:

N1   300
N3   700

So, COLLECT actually collects all the interger, type P and type F values based on the Character fields.

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi,

COLLECT allows you to create unique or summarized datasets.

The system first tries to find a table entry corresponding to the table key.

The key values are taken either from the header line of the internal table itab, or from the explicitly-specified work area wa.

The line type of itab must be flat - that is, it cannot itself contain any internal tables.

All the components that do not belong to the key must be numeric types

( ABAP Numeric Types).

<b></b><b></b>

Bye,

KC

0 Kudos

hi chand,

situation is there is one structure with <b><u>only one</u></b> character field.

an internal table created with thwt structure in the program.

and they used collect statement on this internal table.

0 Kudos

Ok.. this was done to collect all the unique records for that perticular table.

CHAR  char
N1     N1
N1     N1
N2     N4
N2     N3

Than collect

LOOP AT ITAB.
  MOVE-CORRESPONDING ITAB TO IT_SUM
  COLLECT IT_SUM.
ENDLOOP.

After this IT_SUM will have:

N1   N1
N2   N3
N2   N4

You can avoid this COLLECT code by:

SORT ITAB.
DELETE ADJACENT DUPLICATES FROM ITAB.

Regards,

Naimesh Patel