SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Subtotal в функции REUSE_ALV_LIST_DISPLAY



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
inna
Участник
Участник



Joined: 25 Mar 2008
Posts: 32

PostPosted: Fri May 09, 2008 6:56 pm    Post subject: Subtotal в функции REUSE_ALV_LIST_DISPLAY Reply with quote

Подскажите что можно выводить в Subtotal строку кроме суммарного значения? Мне вот надо ещё - среднее, текст (зависит от того что в поле fieldcat). Не пойму: неужели это не предусмотрено?
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 165
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Sat May 10, 2008 5:22 pm    Post subject: Reply with quote

Инна, в одном из старых постов я приводил текст события SUBTOTAL_TEXT для alv grid. В примере добавляется слово 'Итого' перед subtotal текстом.
Также смотрите пример SUBTOTAL_TEXT в программе BCALV_TEST_LIST_EVENTS

Используется два поля с подсуммами
Code:
CLASS lcl_ils DEFINITION DEFERRED.

DATA:  FCODE LIKE SY-UCOMM,
       FCODE2 LIKE SY-UCOMM,
       SCODE LIKE SY-UCOMM.

DATA:
      gc_alv          TYPE scrfname VALUE  'CONTAINER',
      gc_custom_alv   TYPE REF TO cl_gui_custom_container,
      grid_alv        TYPE REF TO cl_gui_alv_grid.

DATA: gt_alv   TYPE STANDARD TABLE OF ZMSD_GL WITH HEADER LINE,
      gwa_alv TYPE ZMSD_GL,
      field_catalog TYPE lvc_t_fcat WITH HEADER LINE,
      gs_layout_alv TYPE lvc_s_layo,
      gt_sort       TYPE lvc_t_sort WITH HEADER LINE.

DATA: alv_event_receiver TYPE REF TO lcl_ils.

*&---------------------------------------------------------------------*
*&       Class LCL_ILS
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_ils DEFINITION.
  PUBLIC SECTION.

    METHODS handle_subtotal_text for event subtotal_text of cl_gui_alv_grid
      importing
      es_subtottxt_info
      ep_subtot_line
      e_event_data.
ENDCLASS.               "LCL_ILS

*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_ils
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_ils IMPLEMENTATION.

* добавляет слово 'Итого' перед subtotal текстом
  METHOD handle_subtotal_text.
    DATA: LEN TYPE I,
         POS TYPE I.
    assign ep_subtot_line->* to <fs1>.
    es_subtottxt_info = es_subtottxt_info.
    assign  e_event_data->m_data->* to <fs>.
    LEN = STRLEN( <fs> ).
    WHILE POS < LEN.
      IF <fs>+POS(1) EQ ' '.
        EXIT.
      ENDIF.
      POS = POS + 1.
    ENDWHILE.
    IF POS < LEN.
      SHIFT <fs> BY POS PLACES.
      CONCATENATE 'Итого '(103) <fs> INTO <fs>.
    ENDIF.
  ENDMETHOD.

ENDCLASS.               "lcl_ils

*&---------------------------------------------------------------------*
*&      Module  STATUS_0200  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.

  SET PF-STATUS 'STATUS_0200'.
  SET TITLEBAR 'TITLE_0200'.
  PERFORM FILL_KORR_TABLE.

  IF gc_custom_alv IS INITIAL.
    CREATE OBJECT gc_custom_alv
         EXPORTING
           container_name = gc_alv
         EXCEPTIONS
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5.
    if sy-subrc ne 0.
* add your handling, for example
      call function 'POPUP_TO_INFORM'
           exporting
                titel = sy-repid
                txt2  = sy-subrc
                txt1  = 'The control could not be created'(510).
    endif.

    CREATE OBJECT grid_alv
      EXPORTING
      i_parent = gc_custom_alv
      I_APPL_EVENTS = 'X'.      " Enable PBO/PAI

    PERFORM MASK_COLUMNS TABLES field_catalog GT_SORT.

    gs_layout_alv-grid_title = text-100.

    CALL METHOD grid_alv->set_table_for_first_display
       EXPORTING
            is_layout = gs_layout_alv
            i_save    = 'U'
            i_default = 'X'
       CHANGING
           it_fieldcatalog = field_catalog[]
           it_outtab       = gt_alv[]
           it_sort         = gt_sort[].

    IF alv_event_receiver IS INITIAL.
      CREATE OBJECT alv_event_receiver.
      set handler alv_event_receiver->handle_subtotal_text for grid_alv.
      SET HANDLER alv_event_receiver->on_dblclick FOR grid_alv.
    ENDIF.

    call method cl_gui_control=>set_focus exporting control = grid_alv.

  ENDIF.

ENDMODULE.                 " STATUS_0200  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
  SCODE = FCODE2.
  CLEAR FCODE2.
  CASE SCODE.
    WHEN 'EXIT' OR 'CANC' OR 'BACK'.
       call method gc_custom_alv->free.
       free alv_event_receiver.
       free grid_alv.
       free gc_custom_alv.
       LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0200  INPUT

*&---------------------------------------------------------------------*
*&      Form  MASK_COLUMNS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
form MASK_COLUMNS
      tables  p_gt_fieldcat type lvc_t_fcat
              p_GT_SORT type lvc_t_SORT.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name       = 'ZMSD_GL'
       CHANGING
            ct_fieldcat            = p_gt_fieldcat[].

    LOOP AT field_catalog.
      IF field_catalog-fieldname = 'BUKRS'
        OR field_catalog-fieldname = 'WAERS'
        OR  field_catalog-fieldname = 'SAKNRD'
        OR  field_catalog-fieldname = 'SAKNRK'
        OR  field_catalog-fieldname = 'SHKZG'.
        field_catalog-key_sel = 'X'.
        field_catalog-no_out = 'X'.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'PERIOD'.
        field_catalog-no_out = 'X'.
        field_catalog-EDIT_MASK = '==ZPRD'.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'PERIOD_VISIBLE'.
        IF X_PERIOD NE 'X'.
          field_catalog-no_out = 'X'.
        ELSE.
          field_catalog-EDIT_MASK = '==ZPRD'.
          field_catalog-OUTPUTLEN = 15.
        ENDIF.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'DMBTRD'
        OR field_catalog-fieldname = 'DMBTRK'.
        field_catalog-DO_SUM = 'X'.
        field_catalog-CURRENCY = 'X'.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'KS'.
        field_catalog-OUTPUTLEN = 10.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'DS_VISIBLE'.
        field_catalog-OUTPUTLEN = 20.
        modify field_catalog.
      ELSEIF field_catalog-fieldname = 'DS'.
        field_catalog-no_out = 'X'.
        modify field_catalog.
      ENDIF.
    ENDLOOP.

    GT_SORT-fieldname = 'DS'.
    GT_SORT-up = 'X'.
    GT_SORT-spos = 1.
    GT_SORT-SUBTOT = 'X'.
    APPEND GT_SORT to P_GT_SORT.

    IF X_PERIOD EQ 'X'.
      CLEAR GT_SORT.
      GT_SORT-fieldname = 'PERIOD'.
      GT_SORT-up = 'X'.
      GT_SORT-spos = 1.
      GT_SORT-SUBTOT = 'X'.
      APPEND GT_SORT to P_GT_SORT.
    ENDIF.

endform.                               " MASK_COLUMNS
Back to top
View user's profile Send private message Blog Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.