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

ALV USING `FUNCTION MODULE

Former Member
0 Likes
544

1.WHAT IS THE PROCEDURE TO GRAND TOTAL CURRENCY FIELDS BY USING ALV WITH FM?

2. WHAT IS THE PURPOSE OF IT_SORT IN ALV_GRID_DISPLAY?

3. WHILE DOING SUBTOTAL & GRANDTOTAL TO THE FIELDS , IS IT COMPULSORY TO DO SORTING, IF SO PLZ EXPLAIN?

KINDLY HELP ME.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
521

Hi Saritha,

1. To do grand totals , in the Field catalog for that currency fields

wa_fieldcat-datatype = 'CURR'.

wa_fieldcat-DOSUM = 'SUM'.

2 . IT_SORT is used to do subtotals in ALV

3 . No it is not compulsort to SORT itab but it is better to do sorting

4 REPLIES 4
Read only

Sm1tje
Active Contributor
0 Likes
521

1. Not quite sure about requirement.

2. You can do a sorting before displaying data.

3. No need to do that at all, but would be better for subtotals for example.

Read only

Former Member
0 Likes
521

Check this program.

BCALV_TEST_FULLSCREEN

You have to build sort for the totals and subtotals.

Thanks,

Vamshi.

Read only

Former Member
0 Likes
521

hi saritha,

The functional module for gand total can be obtained like this,

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

Also 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

And for regarding the sorting please read the below documentation.

When ever we select data from data base table to internal table it may/maynot come in sorted order by primary keys of the table. Same SELECT Query may return different order of records for different executions.To ensure that our records in internal table are in proper order before using them we will use the statement SORT. Also if u want to arrange the records of the internal table based on non primary keys or combination of primary and nonprimary keys then we will use sort statement.

from the above documentation i think it is clear that we have to perform sort for the data.

Reward points if usefull,

Thanks & regards,

Kalyan.

Read only

Former Member
0 Likes
522

Hi Saritha,

1. To do grand totals , in the Field catalog for that currency fields

wa_fieldcat-datatype = 'CURR'.

wa_fieldcat-DOSUM = 'SUM'.

2 . IT_SORT is used to do subtotals in ALV

3 . No it is not compulsort to SORT itab but it is better to do sorting