Skip to Content
author's profile photo Former Member
Former Member

unable to display subtotal text in ALV

Hello Frens,

I have developed an ALV report using function modules. The requirement is i have display sub totals and subtotal texts for fields AUMNG and LFMNG from MVKE table. I' am able to display subtotals, but unable to display subtotal texts. here is my coding.

REPORT zdak_alv_sort_tots_subtots MESSAGE-ID zcn.

************************************************************************

* TYPE-POOLS *

************************************************************************

TYPE-POOLS: slis.

************************************************************************

* TABLES *

************************************************************************

TABLES: mvke.

************************************************************************

* TYPES *

************************************************************************

TYPES: BEGIN OF ty_mvke,

matnr TYPE matnr,

vkorg TYPE vkorg,

vtweg TYPE vtweg,

aumng TYPE minau,

lfmng TYPE minlf,

schme TYPE schme,

vrkme TYPE vrkme,

END OF ty_mvke.

************************************************************************

* INTERNAL TABLES *

************************************************************************

DATA: it_mvke TYPE STANDARD TABLE OF ty_mvke,

it_fieldcat TYPE slis_t_fieldcat_alv,

it_sort TYPE slis_t_sortinfo_alv,

it_events TYPE slis_t_event.

************************************************************************

* WORK AREAS *

************************************************************************

DATA: wa_fieldcat TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv,

wa_sort TYPE slis_sortinfo_alv,

wa_events TYPE slis_alv_event.

************************************************************************

* VARIABLES *

************************************************************************

DATA: v_cprog TYPE sy-repid.

************************************************************************

* CONSTANTS *

************************************************************************

************************************************************************

* SELECTION SCREEN *

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_matnr FOR mvke-matnr.

PARAMETERS: p_rad1 RADIOBUTTON GROUP r1 DEFAULT 'X', " Normal ALV Display

p_rad2 RADIOBUTTON GROUP r1, " Sorted ALV Display

p_rad3 RADIOBUTTON GROUP r1. " Sorted ALV Display with subtotals and totals

SELECTION-SCREEN END OF BLOCK b1.

************************************************************************

* INITIALIZATION *

************************************************************************

INITIALIZATION.

wa_layout-colwidth_optimize = 'X'.

v_cprog = sy-repid.

************************************************************************

* START-OF-SELECTION *

************************************************************************

START-OF-SELECTION.

PERFORM get_data.

PERFORM prep_fieldcat.

IF p_rad2 EQ 'X'.

PERFORM build_sorttable.

ELSEIF p_rad3 EQ 'X'.

PERFORM build_sort_table.

PERFORM build_events.

ENDIF.

************************************************************************

* END-OF-SELECTION *

************************************************************************

END-OF-SELECTION.

PERFORM alv_display.

*&---------------------------------------------------------------------*

*& Form GET_DATA

*&---------------------------------------------------------------------*

FORM get_data .

SELECT matnr vkorg vtweg aumng lfmng schme vrkme

FROM mvke

INTO TABLE it_mvke

WHERE matnr IN s_matnr.

IF sy-subrc EQ 0.

SORT it_mvke BY matnr.

ENDIF.

ENDFORM. " GET_DATA

*&---------------------------------------------------------------------*

*& Form PREP_FIELDCAT

*&---------------------------------------------------------------------*

FORM prep_fieldcat .

wa_fieldcat-col_pos = '1'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Material Number'(003).

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '2'.

wa_fieldcat-fieldname = 'VKORG'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Sales Organization'(004).

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '3'.

wa_fieldcat-fieldname = 'VTWEG'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Distribution Channel'(005).

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '4'.

wa_fieldcat-fieldname = 'AUMNG'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Minimum order quantity'(006).

IF p_rad3 EQ 'X'.

wa_fieldcat-do_sum = 'X'.

ELSE.

wa_fieldcat-do_sum = ' '.

ENDIF.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '5'.

wa_fieldcat-fieldname = 'LFMNG'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Minimum delivery quantity'(007).

IF p_rad3 EQ 'X'.

wa_fieldcat-do_sum = 'X'.

ELSE.

wa_fieldcat-do_sum = ' '.

ENDIF.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '6'.

wa_fieldcat-fieldname = 'SCHME'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'UOM of delivery unit'(008).

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '7'.

wa_fieldcat-fieldname = 'VRKME'.

wa_fieldcat-tabname = 'IT_MVKE'.

wa_fieldcat-reptext_ddic = 'Sales unit'(009).

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " PREP_FIELDCAT

*&---------------------------------------------------------------------*

*& Form BUILD_SORTTABLE

*&---------------------------------------------------------------------*

FORM build_sorttable .

wa_sort-spos = '01'.

wa_sort-fieldname = 'MATNR'.

wa_sort-tabname = 'IT_MVKE'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

ENDFORM. " BUILD_SORTTABLE

*&---------------------------------------------------------------------*

*& Form BUILD_SORT_TABLE

*&---------------------------------------------------------------------*

FORM build_sort_table .

wa_sort-spos = '01'.

wa_sort-fieldname = 'MATNR'.

wa_sort-tabname = 'IT_MVKE'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

* wa_sort-fieldname = 'MATNR'.

* wa_sort-tabname = 'IT_MVKE'.

** wa_sort-group = 'UL'.

* wa_sort-up = 'X'.

* APPEND wa_sort TO it_sort.

* CLEAR wa_sort.

wa_sort-spos = '04'.

wa_sort-fieldname = 'AUMNG'.

wa_sort-tabname = 'IT_MVKE'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-spos = '05'.

wa_sort-fieldname = 'LFMNG'.

wa_sort-tabname = 'IT_MVKE'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

ENDFORM. " BUILD_SORT_TABLE

*&---------------------------------------------------------------------*

*& Form ALV_DISPLAY

*&---------------------------------------------------------------------*

FORM alv_display .

IF NOT it_mvke IS INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_cprog

is_layout = wa_layout

it_fieldcat = it_fieldcat

* IT_EXCLUDING =

* IT_SPECIAL_GROUPS =

it_sort = it_sort

* IT_FILTER =

* IS_SEL_HIDE =

* I_DEFAULT = 'X'

* I_SAVE = ' '

* IS_VARIANT =

it_events = it_events

* IT_EVENT_EXIT =

* IS_PRINT =

* IS_REPREP_ID =

* I_SCREEN_START_COLUMN = 0

* I_SCREEN_START_LINE = 0

* I_SCREEN_END_COLUMN = 0

* I_SCREEN_END_LINE = 0

* I_HTML_HEIGHT_TOP = 0

* I_HTML_HEIGHT_END = 0

* IT_ALV_GRAPHICS =

* IT_HYPERLINK =

* IT_ADD_FIELDCAT =

* IT_EXCEPT_QINFO =

* IR_SALV_FULLSCREEN_ADAPTER =

* IMPORTING

* E_EXIT_CAUSED_BY_CALLER =

* ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_mvke

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 e000 WITH 'No data found for the selection criteria'(002).

ENDIF.

ENDFORM. " ALV_DISPLAY

*&---------------------------------------------------------------------*

*& Form BUILD_EVENTS

*&---------------------------------------------------------------------*

FORM build_events .

CONSTANTS: c_formname_subtotal_text TYPE slis_formname VALUE 'SUBTOTAL_TEXT'.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events

EXCEPTIONS

list_type_wrong = 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.

ELSE.

READ TABLE it_events INTO wa_events

WITH KEY name = slis_ev_subtotal_text.

IF sy-subrc EQ 0.

MOVE c_formname_subtotal_text TO wa_events-form.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

ENDIF.

ENDFORM. " BUILD_EVENTS

*&---------------------------------------------------------------------*

*& Form SET_SUBTOTAL_TEXT

*&---------------------------------------------------------------------*

FORM subtotal_text CHANGING p_total TYPE any

p_subtot_text TYPE slis_subtot_text.

* Order Quantity

IF p_subtot_text-criteria = 'AUMNG'.

p_subtot_text-display_text_for_subtotal = 'Order Quantity Total'(010).

ENDIF.

IF p_subtot_text-criteria = 'LFMNG'.

p_subtot_text-display_text_for_subtotal = 'Delivery Quantity Total'(011).

ENDIF.

ENDFORM. "SET_SUBTOTAL_TEXT

I have gone thru many links and similar examples and also tried all the options to get the subtotal texts displayed.

as an last option i have posted my coding in SCN.

Can you please help me know where the mistake is being done.

Thanks,

abaper.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Apr 24, 2012 at 04:25 PM

    Hi,

    There must be duplicate column for the field on which you require sort, for your radio button 3, you must have duplicate column for MATNR, AUMNG and LFMNG and values must be filled with corresponding field values. The fieldcatalog 'NO_OUT' must be set to 'X' so that these are not displayed in output. So when the internal table will be sorted on those duplicate columns the records will be sorted and original values field columns will be displayed.

    Check on the code attached.

    Thanks & Regards

    Bala Krishna


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 25, 2012 at 12:09 PM

    Hi Balakrishna,

    Thank you very much for providing the solution. It perfectly solved my porblem.

    I was not aware of maintaining duplicate columns for the purpose of sorting. After going thru your

    explanation I have got an idea on the mechanism involved.

    Once again thank you for providing the solution.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.