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

Adding a column in an internal table

Former Member
0 Likes
1,344

Hi,

I want to know how to add different rows of a column in an internal table.

My code :

-


Declaration Part-----

types : begin of imchb,

clabs like mchb-clabs,

cumlm like mchb-cumlm,

cinsm like mchb-cinsm,

tot_val_stock type p decimals 3,

pm_percent type p decimals 6,

end of imchb.

data : int_inv type standard table of imchb with header line,

wa_inv like line of int_inv.

Then I do few calculations and display it in the column pm_percent.

Now I want to sum this column.

-


Summation---

loop

at int_inv into wa_inv.

at end of pm_percent.

sum.

endat.

endloop.

write 😕 wa_inv-pm_percent.

However , wa_inv-pm_percent only gives me the value of the last row of the column.

Kindly suggest .

Hi,

I want to know how to add different rows of a column in an internal table.

My code :

-


Declaration Part-----

types : begin of imchb,

clabs like mchb-clabs,

cumlm like mchb-cumlm,

cinsm like mchb-cinsm,

tot_val_stock type p decimals 3,

pm_percent type p decimals 6,

end of imchb.

data : int_inv type standard table of imchb with header line,

wa_inv like line of int_inv.

Then I do few calculations and display it in the column pm_percent.

Now I want to sum this column.

-


Summation---

loop

at int_inv into wa_inv.

at end of pm_percent.

sum.

endat.

endloop.

write 😕 wa_inv-pm_percent.

However , wa_inv-pm_percent only gives me the value of the last row of the column.

Kindly suggest .

7 REPLIES 7
Read only

Former Member
0 Likes
1,162

Hi,

In your loop you have the statement "AT END"... I think that's the issue. Debug your code and check the value of that field.

Read only

0 Likes
1,162

If they are the quantity fields, try using the collect statement with in the loop.

Read only

Former Member
0 Likes
1,162

Hi abilasa,

loop at int_inv into wa_inv.
collect wa_inv.
endloop.

so, wa_inv-pm_percent will contain the total value.

but remember when doing the collect, the other fields in the internal table must be of character type and they should be like the key field.

let me know if your problem solves.

thanks,

Sakthi Sri.

Read only

Former Member
0 Likes
1,162

Hi,

Please try this code:



loop at int_inv into wa_inv.
    lv_count = lv_count + 1.
    AT END OF posnr.   <------- The field you want to sum..
      gs_total-posnr      = wa_inv-posnr.
      gs_total-cov_total  = lv_count.
      APPEND gs_total TO gt_total.
      CLEAR : gs_total,
              lv_count,
              wa_inv.
    ENDAT.
  ENDLOOP.

Read only

0 Likes
1,162

Hi ,

This seemed to do the trick.

loop at int_inv.

sum .

new-line.

endloop.

write 😕

'----


'.

write : /60 'The sum of precious metal (Gold Content)' , 105

int_inv-pm_percent.

Thanks for all your input.

Read only

0 Likes
1,162

Answered.Closing this message.

Read only

Former Member
0 Likes
1,162

Answered.Closing this message.