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

Processing an intenal table

Former Member
0 Likes
980

Hi All,

I have an internal table which has following values:

Project Indicator Cost

P001 I 10000

P001 I 20000

P001 D 500

P001 D 1000

P002 I 2000

P002 I 1000

I need to do a processing in such a way that i get following data in another internal table.

Project Indicator Cost

P001 I 30000

P001 D 1500

P002 I 3000

How do I achieve this ?

Regards,

Satya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
949

Hi,

You can create a new internal table with just the three fields and then use COLLECT to sum up the records..



LOOP AT ITAB INTO WA.

* move the values.
  WA_COLLECT-PROJECT = WA-PROJECT.
  WA_COLLECT-INDICATOR = WA-INDICATOR.
  WA_COLLECT-COST = WA-COST. 

* Use collect.
   COLLECT WA_COLLECT TO ITAB_COLLECT.  

ENDLOOP.

* Now the values will be consolidated based on project and indicator..

Thanks,

Naren

10 REPLIES 10
Read only

Former Member
0 Likes
949

append the all the records to internal table then use delete adjacent duplicates command.

Read only

Former Member
0 Likes
950

Hi,

You can create a new internal table with just the three fields and then use COLLECT to sum up the records..



LOOP AT ITAB INTO WA.

* move the values.
  WA_COLLECT-PROJECT = WA-PROJECT.
  WA_COLLECT-INDICATOR = WA-INDICATOR.
  WA_COLLECT-COST = WA-COST. 

* Use collect.
   COLLECT WA_COLLECT TO ITAB_COLLECT.  

ENDLOOP.

* Now the values will be consolidated based on project and indicator..

Thanks,

Naren

Read only

Former Member
0 Likes
949

hi Satya,

do this way ..


sort itab by project indicator.
loop at itab.
at new project.
sum.
it_final-project = itab-project.
it_final-indicator = itab-indicator.
append it_final.
clear : it_final, itab..
endloop.

Read only

Former Member
0 Likes
949

HI Satya ,

Use the collect statement.

The code will look some thing like this

Loop at it_1 into wa_1.
 collect wa_1 into it_2.
endloop.

Hope this helps.

Regards

Arun

Read only

Former Member
0 Likes
949

hi satya,

welcome to sdn,

use <b>collect</b> statement in loop to calcualte project related costs,

reward points if helpful,

regards,

seshu.

Read only

Former Member
0 Likes
949

Hi

Write

sort itab by project indicator.

Loop at ITAB.

at end of indicator.

read table itab index sy-tabix.

sum.

move-corresponding itab to itab1.

append itab1.

endat.

clear itab1.

endloop

<b>Reward points for useful Answers</b>

Regards

Anji

Read only

Former Member
0 Likes
949

sort itab1 by firstfieldname secondfieldname

loop at itab1 into wa1

amount = amount + wa1-thirdfield name .

at end of second field name .

wa2-thirdfield name = amount.

append wa2 to itab2 .

clear amount.

end at.

endloop.

itab2 will contains the required entires

Read only

S0025444845
Active Participant
0 Likes
949

Hi,

for this You can use collect statement,write collect on abap editor and press F1 help, u will get it.

regards,

sudha

Read only

Former Member
0 Likes
949

use the below logic for you display


sort  you itab so that the  sequence will be there
sort  itab  by  PROJECT INDICATOR.
LOOP AT ITAB .
*****for  new  Project  based on sorting  .
Atnew PROJECT .
Endat .

Atend INDICATOR.
***** Total will be done  on  indicator  Using  sum
SUM .
final-PROJECT = WA-PROJECT.
final -INDICATOR = WA-INDICATOR.
final -COST = WA-COST. 
Endat
****appending in new  table
Append  final . 
ENDLOOP.

****DIsplay Output
LOOP AT  FINAL.
WRITE : / final-PROJECT ,final -INDICATOR ,final -COST  .
ENDLOOP.

Girish

Read only

Former Member
0 Likes
949

Hi,

<b>fallow the fallowing steps</b>

1. first sort the internal table (sort).

2.then based on previous value check with current value.

ex: take some temp workarea and store 1st record , when internal table workarea is holding the value of 2nd record then compare those records....... if both char datatype values are same then add the integer types.( equal operator ).

3. store those new value into an new internal table.(append).

4. loop that new internal table . then U will get the acctual result (loop).

don't forget to give points of itis usefill for U.