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

Custom calculation of TOTALS in ALV Grid



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Thu Oct 04, 2007 9:04 pm    Post subject: Custom calculation of TOTALS in ALV Grid Reply with quote

Custom calculation of TOTALS in ALV Grid

This code works under 4.6C and NW04S to.

Code:
*&---------------------------------------------------------------------*
*& Report ZF_SZJ_050
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zf_szj_050.

TYPES: BEGIN OF xtyp_sum,
carrid LIKE sflight-carrid,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
percent TYPE p,
END OF xtyp_sum.

DATA: xt_sum TYPE TABLE OF xtyp_sum.
FIELD-SYMBOLS: <x_sum> TYPE xtyp_sum.

START-OF-SELECTION.

  SELECT carrid SUM( seatsmax ) SUM( seatsocc )
  INTO TABLE xt_sum
  FROM sflight
  GROUP BY carrid.

END-OF-SELECTION.
  LOOP AT xt_sum ASSIGNING <x_sum>.
    COMPUTE: <x_sum>-percent =
    <x_sum>-seatsocc / <x_sum>-seatsmax * 100.
  ENDLOOP.
  CALL SCREEN 9000.

*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
  SET PF-STATUS 'STAT9000'.
  SET TITLEBAR '900'.
ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module BUILD_ALV OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE build_alv OUTPUT.
  DATA: lt_fcat TYPE lvc_t_fcat,
  lh_fcat TYPE lvc_s_fcat.
  DATA: lref_al TYPE REF TO cl_gui_alv_grid,
  lref_dc TYPE REF TO cl_gui_docking_container.
  DATA: lh_repid LIKE sy-repid.
  DATA: lref_data TYPE REF TO data.
  FIELD-SYMBOLS: <l_sum_tab> TYPE table,
  <l_sum> TYPE xtyp_sum.
  CLEAR lh_fcat. REFRESH lt_fcat.

  lh_fcat-ref_table = 'SFLIGHT'.
  lh_fcat-fieldname = 'CARRID'.
  APPEND lh_fcat TO lt_fcat.
  lh_fcat-ref_table = 'SFLIGHT'.
  lh_fcat-fieldname = 'SEATSMAX'.
  lh_fcat-do_sum = 'X'.
  APPEND lh_fcat TO lt_fcat.
  lh_fcat-ref_table = 'SFLIGHT'.
  lh_fcat-fieldname = 'SEATSOCC'.
  lh_fcat-do_sum = 'X'.
  APPEND lh_fcat TO lt_fcat.
  lh_fcat-fieldname = 'PERCENT'.
  lh_fcat-inttype = 'P'.
  lh_fcat-seltext = '%'.
  lh_fcat-coltext = '%'.
  lh_fcat-do_sum = 'X'.
  APPEND lh_fcat TO lt_fcat.

  lh_repid = sy-repid.

  IF sy-batch NE 'X'.
    CREATE OBJECT lref_dc
    EXPORTING
* PARENT =
    repid = lh_repid
    dynnr = '9000'
* SIDE = DOCK_AT_LEFT
    extension = 2000
* STYLE =
* LIFETIME = lifetime_default
* CAPTION =
* METRIC = 0
* RATIO =
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
* EXCEPTIONS
* CNTL_ERROR = 1
* CNTL_SYSTEM_ERROR = 2
* CREATE_ERROR = 3
* LIFETIME_ERROR = 4
* LIFETIME_DYNPRO_DYNPRO_LINK = 5
* others = 6
    .
  ENDIF.
  CREATE OBJECT lref_al
  EXPORTING
* I_SHELLSTYLE = 0
* I_LIFETIME =
  i_parent = lref_dc
* I_APPL_EVENTS = space
* I_PARENTDBG =
* I_APPLOGPARENT =
* I_GRAPHICSPARENT =
* I_NAME =
* I_FCAT_COMPLETE = SPACE
* EXCEPTIONS
* ERROR_CNTL_CREATE = 1
* ERROR_CNTL_INIT = 2
* ERROR_CNTL_LINK = 3
* ERROR_DP_CREATE = 4
* others = 5
  .
  CALL METHOD lref_al->set_table_for_first_display
* EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
  CHANGING
  it_outtab = xt_sum
  it_fieldcatalog = lt_fcat
* IT_SORT =
* IT_FILTER =
* EXCEPTIONS
* INVALID_PARAMETER_COMBINATION = 1
* PROGRAM_ERROR = 2
* TOO_MANY_LINES = 3
* others = 4
  .

  CALL METHOD lref_al->get_subtotals
  IMPORTING
  ep_collect00 = lref_data
* EP_COLLECT01 =
* EP_COLLECT02 =
* EP_COLLECT03 =
* EP_COLLECT04 =
* EP_COLLECT05 =
* EP_COLLECT06 =
* EP_COLLECT07 =
* EP_COLLECT08 =
* EP_COLLECT09 =
* ET_GROUPLEVELS =
  .

  ASSIGN lref_data->* TO <l_sum_tab>.
  READ TABLE <l_sum_tab> ASSIGNING <l_sum> INDEX 1.
  IF sy-subrc EQ 0.
    <l_sum>-carrid = 'SUM:'.
    COMPUTE: <l_sum>-percent =
    <l_sum>-seatsocc / <l_sum>-seatsmax * 100.
    CALL METHOD lref_al->refresh_table_display
    EXPORTING
* IS_STABLE =
    i_soft_refresh = 'X'
* EXCEPTIONS
* FINISHED = 1
* others = 2
    .
  ENDIF.

ENDMODULE. " BUILD_ALV OUTPUT
*&---------------------------------------------------------------------*
*& Module EXIT_COMMAND INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE exit_command INPUT.
  LEAVE PROGRAM.
ENDMODULE. " EXIT_COMMAND INPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
  LEAVE PROGRAM.
ENDMODULE. " USER_COMMAND_9000 INPUT

pbo and pai of screen 9000

process before output.
*---------------------------------------------------------------------*
*       MODULE STATUS_9000                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE status_9000.
*---------------------------------------------------------------------*
*       MODULE BUILD_ALV                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE build_alv.

process after input.

  MODULE user_command_9000.

  module exit_command at exit-command.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List 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.