11-19-2007 2:40 PM
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.
11-19-2007 2:45 PM
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
11-19-2007 2:44 PM
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.
11-19-2007 2:44 PM
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
11-19-2007 2:45 PM
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
11-19-2007 2:45 PM
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
11-19-2007 2:51 PM
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.
11-19-2007 2:54 PM
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