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: 

internal table field addition

Former Member
0 Kudos

hello experts.

i am having a variable total and its value is 200.

I want to do additon with the fields in the internal table.

i am having 3 fields in the internal table. based on one field i want to do addition other field.

field1 field2 field 3

-


-


-


1) 10001001 100 ( 200*100) / final_total here 200 is total variable

2) 10001001 100 (200* 100)/ final_total

3) 10001003 409 ( 200 * 409) / final_total

4) 10001005 589 ( 200 * 589) / final_total

5) 10001005 345 etc

6) 10002105 984

7) 10002105 100

😎 10003105 409

-


final_total

now based on field one i need to do additon as shown above . please tell me how to do this.

Thanks for all the replies.

2 REPLIES 2

Former Member
0 Kudos

Add third field AVG to your internal table ITAB.

Once ITAB is populated with values of Field1 and field2. sort ITAB.

Use following pseudo logic.

LOOP AT ITAB.

L_TABIX = SY-TABIX.

AT FIRST.

  • Get final total

LOOP AT ITAB.

FINALTOTAL = FINALTOTAL + ITAB-FIELD2.

ENDLOOP.

ENDAT.

AT NEW FIELD1.

READ ITAB INDEX L_TABIX.

  • Get total for field 1.

LOOP AT ITAB WHERE FIELD1 = ITAB-FIELD1.

TOTAL = TOTAL + ITAB-FIELD2.

ENDLOOP.

ENDAT.

ITAB-FIELD3 = TOTAL * ITAB-FIELD2 / FINALTOTAL.

MODIFY ITAB INDEX L_tABIX TRANSPORTING FIELD3.

ENDLOOP.

Hope this helps.

ashish

Former Member
0 Kudos

hi shiva,

Loop at itab into wa.

wa-f3 = (200 * f3) / f3.

modify itab from wa.

clear wa.

endloop.

<b>Reward for helpful answers.</b>

Satish