2008 Apr 23 11:58 AM
Hi All
I have a requirement,
where i have 2 fields
employee & Amount
suppose i have repeated entreis for the employess
a---- 10
a---- 10
a---- 10
a---- 10
b----5
b----5
Hence now my answer should be something lile foe field A answer is 40 rs & field B has 10 rs.
any inputs plz
Regards
Rohini
Hi All
I have a requirement,
where i have 2 fields
employee & Amount
suppose i have repeated entreis for the employess
a---- 10
a---- 10
a---- 10
a---- 10
b----5
b----5
Hence now my answer should be something lile foe field A answer is 40 rs & field B has 10 rs.
any inputs plz
Regards
Rohini
2008 Apr 23 12:06 PM
Use collect statement. This will add the numeric values when the data is appended in the internal table
2008 Apr 23 12:09 PM
hi
use collect insted of append when you are entering data nto table. and be sure that the field is of numeric data type otherwise the value cannot be added
regards
prasanth
2008 Apr 23 12:09 PM
Hi,
As suggested collect statement will suit your requirement
declare another internal table internaltable2 of the same type containing the 2 fields internaltable1 and also a workarea
loop at internaltable1 to workarea.
collect workarea to internaltable2
endloop.
Regards
Byju
2008 Apr 23 12:12 PM
Use the following code:
*&---------------------------------------------------------------------*
*& Report ZTEST_PRG6
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest_prg6.
TYPES: BEGIN OF types_data,
fld1 TYPE char4,
fld2 TYPE dmbtr,
END OF types_data.
DATA: lt_data TYPE STANDARD TABLE OF types_data,
ls_data TYPE types_data.
ls_data-fld1 = 'A'.
ls_data-fld2 = 10.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
ls_data-fld1 = 'A'.
ls_data-fld2 = 10.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
ls_data-fld1 = 'A'.
ls_data-fld2 = 10.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
ls_data-fld1 = 'A'.
ls_data-fld2 = 10.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
ls_data-fld1 = 'B'.
ls_data-fld2 = 05.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
ls_data-fld1 = 'B'.
ls_data-fld2 = 05.
COLLECT ls_data INTO lt_data.
CLEAR: ls_data.
SORT lt_data BY fld1.
LOOP AT lt_data INTO ls_data.
WRITE:/ ls_data-fld1,
ls_data-fld2.
ENDLOOP.
Hope That Helps
Anirban M.
2008 Apr 23 12:13 PM
Hi Rohoni,
U can use either collect or SUM statements to achieve this.
or else following logic.
SORT itab BY employee.
LOOP AT itab INTO wa.
logic1
w_amount = w_amount + wa-amount.
AT END OF employee.
WRITE w_amount.
CLEAR w_amount.
ENDAT.
logic2
SUM.
AT END OF employee.
WRITE wa-amount.
ENDAT.
ENDLOOP.
Thanks,
Vinod.
2008 Apr 23 12:30 PM
Its better to use COLLECT statement,but be sure that the fields that have to be added should of type I,P,F data types only.
2008 Apr 23 12:32 PM
Its Better to use COLLECT statement,but make sure that the fields which are to be added are of data type I,P,F.
Reward if helpful
cheers
Amith
2010 May 12 9:48 AM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |