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: 

Sum in ALV for rtwo different fields acc to currency wise

Former Member
0 Kudos

hi,

I have an internal table in which following are the fields

Currency

Amount(in different currency)

Amount1(in USD only)

Now i have to take total sum according to currency wise like for AUD,INR those are visible in mine currency field through ALV.

I am getting the total sum but for Amount(in USD only) gives sum according to currency wise. But it is in USD only so sum for USD has to be shown.

Now to do that so that i get the sum .

4 REPLIES 4

Former Member
0 Kudos

Hi,

hope this will help you,

For the totals of each currencies, I just inserted the following code in my form 'fill_fieldcat':

wa_fieldcat-fieldname = 'DMBTR'.

wa_fieldcat-ref_fieldname = 'DMBTR'.

wa_fieldcat-ref_tabname = 'BSEG'.

wa_fieldcat-cfieldname = 'WAERS'

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

And of course, there must be a currency field that will serve as the reference for the calculation of totals for the different currencies

Reward if found helpful...

Cheers,

Chandra Sekhar.

0 Kudos

Hi, Chandra, By ur code total is coming right but in front of AUD. But i am taking the sum of USD. So how to print in front of right currency

former_member386202
Active Contributor
0 Kudos

Hi,

refer this code

&----


*& Form sub_field_cat

&----


  • text

----


FORM sub_field_cat .

it_fieldcat1-fieldname = 'PERNR'.

it_fieldcat1-seltext_m = text-003.

it_fieldcat1-col_pos = 0.

it_fieldcat1-outputlen = 8.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

it_fieldcat1-fieldname = 'WORKDATE'.

it_fieldcat1-seltext_m = text-012.

it_fieldcat1-col_pos = 1.

it_fieldcat1-outputlen = 8.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

it_fieldcat1-fieldname = 'WEKLY'.

it_fieldcat1-seltext_m = text-015.

it_fieldcat1-col_pos = 2.

it_fieldcat1-outputlen = 7.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

it_fieldcat1-fieldname = 'LGART'.

it_fieldcat1-seltext_m = text-013.

it_fieldcat1-col_pos = 3.

it_fieldcat1-outputlen = 4.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

it_fieldcat1-fieldname = 'STDAZ'.

it_fieldcat1-seltext_m = text-014.

it_fieldcat1-col_pos = 4.

it_fieldcat1-outputlen = 7.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

it_fieldcat1-fieldname = 'RAUFNR'.

it_fieldcat1-seltext_m = text-016.

it_fieldcat1-col_pos = 5.

it_fieldcat1-outputlen = 12.

APPEND it_fieldcat1 TO it_fieldcat1.

CLEAR it_fieldcat1.

ENDFORM. " sub_field_cat

&----


*& Form sub_display_data

&----


  • text

----


FORM sub_display_data .

*--To sort the output through material number

DATA : lwa_sort TYPE slis_sortinfo_alv.

DATA : lit_sort TYPE slis_t_sortinfo_alv.

*--Pass the values to the table

lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '1'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = 'X'. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '2'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '3'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

wa_layout-colwidth_optimize = 'X'.

IF NOT it_final2[] IS INITIAL.

*--Call the function module to display the ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = wa_layout

i_callback_program = v_repid

it_fieldcat = it_fieldcat1[]

i_default = c_chk

i_save = c_save

it_sort = lit_sort

TABLES

t_outtab = it_final2

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-017.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " sub_display_data

Reagrds,

Prashant

Clemenss
Active Contributor
0 Kudos

Hi Anurodh,

you have to establish a refernce between ammount and currency key in field catalog.

If you create a DDIC structure you will be forced to set the currency key field for the amount field. A fieldcatalog created from DDIC structure will do itz automatically.

Look at the following code. It works for 'old-fashioned' fieldcatalogs. The OO approach is the same but fieldnames are slightly different.


FORM alv_fieldcat_enhance
  CHANGING pt_alv_fieldcat                TYPE slis_t_fieldcat_alv.
  FIELD-SYMBOLS:
    <alv_fieldcat>                        TYPE slis_fieldcat_alv.
  LOOP AT pt_alv_fieldcat ASSIGNING <alv_fieldcat>.
    CASE <alv_fieldcat>-fieldname.
      WHEN 'DMBTR'.
        <alv_fieldcat>-do_sum             = gc_true.
        <alv_fieldcat>-cfieldname         = gc_cfieldname_hwaer.
    ENDCASE." <alv_fieldcat>-fieldname.
  ENDLOOP." at pt_alv_fieldcat assigning <fieldcat_alv>.
ENDFORM.              

Regards,

Clemens