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: 

regarding ALV

Former Member
0 Kudos

Hi,

In alv display, how to restrict the subtotal of a particular field.

What i mean is for a particular field i am displaying sub total using field catalog do_sum = 'X'.

if the field contains 50 40 20 then subtoatal would be 110.

if sutotal is greater than 100 i need to display it as 100.

As it is system generated value comming from ALV how can i restrict.

Regards,

Mr.A

3 REPLIES 3

Former Member
0 Kudos

You cannot restrict this....instead you can add the subtotal row at end of the internal table which you are displaying. This row holds all the subtotal of the coloums you required as per uur requirement.

Former Member
0 Kudos

Hi,

The below code changes the subtotal values....

Apply it in ur code....


REPORT zalv_subtot_change.
TYPE-POOLS: slis,
            kkblo.

DATA : BEGIN OF it_vbap OCCURS 0,
       vbeln LIKE vbap-vbeln,
       posnr LIKE vbap-posnr,
       kwmeng LIKE vbap-kwmeng,
       netwr LIKE vbap-netwr,
       netpr LIKE vbap-netpr,
       END   OF it_vbap.

DATA: wa_vbap LIKE LINE OF it_vbap.

DATA: t_fieldcat   TYPE slis_t_fieldcat_alv.

DATA:  wa_fieldcat   TYPE slis_fieldcat_alv.

START-OF-SELECTION.

  SELECT vbeln posnr kwmeng netwr
         INTO CORRESPONDING FIELDS OF TABLE it_vbap
         FROM  vbap
         UP TO 20 ROWS.

  PERFORM create_field_catalog.
  PERFORM create_alv_output.

*&---------------------------------------------------------------------*
*&      Form  create_field_catalog
*&---------------------------------------------------------------------*
FORM create_field_catalog .

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
   EXPORTING
     i_program_name               = sy-repid
     i_internal_tabname           = 'IT_VBAP'
*     I_STRUCTURE_NAME             =
*     I_CLIENT_NEVER_DISPLAY       = 'X'
     i_inclname                   = sy-repid
*     I_BYPASSING_BUFFER           =
*     I_BUFFER_ACTIVE              =
    CHANGING
      ct_fieldcat                  = t_fieldcat
*   EXCEPTIONS
*     INCONSISTENT_INTERFACE       = 1
*     PROGRAM_ERROR                = 2
*     OTHERS                       = 3
            .
  IF sy-subrc = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT t_fieldcat INTO wa_fieldcat.
    CASE wa_fieldcat-fieldname.
      WHEN 'KWMENG'.
        wa_fieldcat-do_sum = 'X'.
      WHEN 'NETWR'.
        wa_fieldcat-do_sum = 'X'.
      WHEN 'NETPR'.
        wa_fieldcat-do_sum = 'X'.
    ENDCASE.
    MODIFY t_fieldcat FROM wa_fieldcat.
  ENDLOOP.

ENDFORM.                    " create_field_catalog


*&---------------------------------------------------------------------*
*&      Form  create_alv_output
*&---------------------------------------------------------------------*
*       Generate ALV Grid output
*----------------------------------------------------------------------*
FORM create_alv_output .
  DATA: l_repid LIKE sy-repid,
        l_layout TYPE slis_layout_alv,
        l_print  TYPE  slis_print_alv.

  DATA: it_sort TYPE slis_t_sortinfo_alv,
        ls_sort TYPE slis_sortinfo_alv.

  DATA: it_filter TYPE slis_t_filter_alv,
        ls_filter TYPE slis_filter_alv.

  DATA: it_event_exit TYPE slis_t_event_exit,
        ls_event_exit TYPE slis_event_exit.

  DATA: t_event      TYPE slis_t_event,
        wa_event      TYPE slis_alv_event.


  l_repid = sy-repid.

  l_layout-no_totalline = 'X'.

  ls_sort-spos = '1'.
  ls_sort-fieldname = 'POSNR'.
  ls_sort-tabname = 'IT_VBAP'.
  ls_sort-up = 'X'.
  ls_sort-subtot = 'X'.
  APPEND ls_sort TO it_sort.


  ls_event_exit-ucomm = '&ILT'.
  ls_event_exit-after = 'X'.
  APPEND ls_event_exit TO it_event_exit.


*  CLEAR wa_event.
*  wa_event-name = 'USER_COMMAND'.
*  wa_event-form = 'USER_COMMAND'.
*  APPEND wa_event TO t_event.

  CLEAR wa_event.
  wa_event-name = 'PF_STATUS_SET'.
  wa_event-form = 'TOP_OF_PAGE'.
  APPEND wa_event TO t_event.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = l_repid
*      i_callback_top_of_page = 'TOP_OF_PAGE'
      is_layout              = l_layout
      is_print               = l_print
      it_sort                = it_sort
      it_filter              = it_filter
      it_fieldcat            = t_fieldcat[]
      it_events              = t_event
      it_event_exit          = it_event_exit
    TABLES
      t_outtab               = it_vbap
    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.

ENDFORM.                    " create_alv_output

*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM top_of_page USING lt_extab TYPE kkblo_t_extab.

  DATA: lo_grid TYPE REF TO cl_gui_alv_grid.

  SET PF-STATUS 'STANDARD'.

* get the global reference
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lo_grid.

* get the subtotal
  DATA: it_01 TYPE REF TO data.

  CALL METHOD lo_grid->get_subtotals
    IMPORTING
      ep_collect01 = it_01.

* change the data
  FIELD-SYMBOLS: <ft_tab> TYPE ANY TABLE,
                 <fs_tab> TYPE ANY,
                 <fs_value1> TYPE ANY,
                 <fs_value2> TYPE ANY,
                 <ff_field> TYPE ANY.
  ASSIGN it_01->* TO <ft_tab>.


  LOOP AT <ft_tab> ASSIGNING <fs_tab>.
    ASSIGN COMPONENT 'NETPR' OF STRUCTURE <fs_tab> TO <ff_field>.
    ASSIGN COMPONENT 'KWMENG' OF STRUCTURE <fs_tab> TO <fs_value1>.
    ASSIGN COMPONENT 'NETWR' OF STRUCTURE <fs_tab> TO <fs_value2>.
    <ff_field> = <fs_value2> / <fs_value1> .
  ENDLOOP.

* Refresh the table display
  CALL METHOD lo_grid->refresh_table_display
    EXPORTING
      i_soft_refresh = 'X'.


ENDFORM.                    " top_of_page

regards

Sukriti...

Former Member
0 Kudos

Hi,

Define the field of your own in an internal table.Do neccesary coding like if the subtotal is greater then 100 then populate that field as 100 else before field has to be output in the alv....

Regards,

Rohan.