开源中文网

您的位置: 首页 > Linux应用 > SAP > 正文

ALV Class 应用中遇到的若干问题说明

来源:  作者:

  1. 向ALV录入数据时,同步内表与表格显示内容时,用 call method grid->CHECK_CHANGED_DATA importing E_VALID = name. 进行同步数据。
  2. alv设置每个格的颜色及在每个cell里加按钮

REPORT  Z_PZ_TEST_ALV.
types: begin of ILIST_S,
      name1(10),
      name2(10),
      name3(10),
      name4(10),
 end of ILIST_S.
data: ILIST type standard table of ILIST_S  with header line .
data: begin of list occurs 0.
        include structure iLIST.
        data rowcolor(4) type c .
        data cellcolors type lvc_t_scol .
        data carrid_handle type int4 .
        data connid_handle type int4 .
        data cellstyles type lvc_t_styl .
data: end of list.
*---------------------------------------------------------------------*
*       CLASS t_gird_event_receiver DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class t_gird_event_receiver definition inheriting from cl_gui_alv_grid." zalv_event_receiver.
  public section.
    data: item(10).
    methods handle_user_command
       for event user_command of cl_gui_alv_grid
           importing e_ucomm.
    methods handle_data_changed
       for event data_changed of cl_gui_alv_grid
           importing
           er_data_changed
           e_onf4
           e_onf4_before
           e_onf4_after
           e_ucomm.
    methods handle_data_changed_finished
           for event data_changed_finished of cl_gui_alv_grid
           importing e_modified
                     et_good_cells.
    methods handle_click
            for event double_click of cl_gui_alv_grid
            importing e_row
                      e_column
                      es_row_no.
    methods handle_hotspot_click
            for event hotspot_click of cl_gui_alv_grid
            importing e_row_id
                      e_column_id
                      es_row_no.
endclass.                    "T_GIRD_EVENT_RECEIVER DEFINITION
*---------------------------------------------------------------------*
*       CLASS T_GIRD_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
class t_gird_event_receiver implementation.
  method handle_user_command.
  endmethod.                    "handle_user_command
  method handle_data_changed.
  endmethod.                    "handle_data_changed
  method handle_data_changed_finished.
  endmethod.                    "handle_DATA_CHANGED_FINISHED
  method handle_click.
*   importing E_ROW
*                     E_COLUMN
*                     ES_ROW_NO.
    data: a(10).
    a = 'PZ'.
  endmethod.                    "handle_click
  method handle_hotspot_click.
  endmethod.                    "HANDLE_HOTSPOT_CLICK

endclass.                    "T_GIRD_EVENT_RECEIVER IMPLEMENTATION
data: ok_code like sy-ucomm.
data: l_valid(1) type c.
data: go_grid             type ref to cl_gui_alv_grid.

data: gt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat,
      gs_variant  type disvariant ,
      gt_sort     type lvc_t_sort,
      gs_sort     type lvc_s_sort,
      gt_filt     type lvc_t_filt,
      gs_filt     type lvc_s_filt,
      ls_cell     type lvc_s_styl,
      sla         type lvc_s_layo,
      gt_f4       type lvc_t_f4,
      gs_f4       type lvc_s_f4.
INITIALIZATION.
    data: ls_fieldcat type lvc_s_fcat.
    clear ls_fieldcat.
    ls_fieldcat-fieldname     = 'NAME1'.
    ls_fieldcat-scrtext_l     = 'NAME1'.
    append ls_fieldcat to  gt_fieldcat.
    clear ls_fieldcat.
    ls_fieldcat-fieldname     = 'NAME2'.
    ls_fieldcat-scrtext_l     = 'NAME2'.
*    ls_fieldcat-emphasize = 'C610'.
    append ls_fieldcat to  gt_fieldcat.
    clear ls_fieldcat.
    ls_fieldcat-fieldname     = 'NAME3'.
    ls_fieldcat-scrtext_l     = 'NAME3'.
    append ls_fieldcat to  gt_fieldcat.
LIST-NAME1 = 'HOW'.
LIST-NAME2 = 'ARE'.
APPEND LIST.
LIST-NAME1 = 'HOW'.
LIST-NAME2 = 'ARE'.
LIST-ROWCOLOR = 'C410'.
APPEND LIST.
DATA ls_style TYPE lvc_s_styl .
READ TABLE list INDEX 2 .
ls_style-fieldname = 'NAME3' .
ls_style-style = cl_gui_alv_grid=>mc_style_button .
APPEND ls_style TO list-cellstyles .
MODIFY list INDEX 2 .
DATA ls_cellcolor TYPE lvc_s_scol .
READ TABLE list INDEX 1 .
ls_cellcolor-fname = 'NAME3' .
ls_cellcolor-color-col = '5' .
ls_cellcolor-color-int = '1' .
ls_cellcolor-color-inv = '1'.
APPEND ls_cellcolor TO list-cellcolors .
MODIFY list INDEX 1 .
SLA-stylefname = 'CELLSTYLES'.
SLA-ctab_fname = 'CELLCOLORS'.
SLA-info_fname = 'ROWCOLOR'.
create object go_grid
      exporting
        i_parent = cl_gui_container=>screen0.
START-OF-SELECTION.
WRITE:/ '.'.
call method go_grid->set_table_for_first_display
    exporting
      is_variant                    = gs_variant
      i_save                        = 'A'
      is_layout                     = sla
    changing
      it_outtab                     = list[]
      It_fieldcatALOG                   = gt_fieldcat[]
    exceptions
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      others                        = 4.

3. SPLITER IN ALV

*----------------------------------------------------------------------*
*   INCLUDE ZPZALV02_TOP                                               *
*----------------------------------------------------------------------*
TABLES: USR02,TDEVC.

DATA:
* Reference to document
       DG_DYNDOC_ID       TYPE REF TO CL_DD_DOCUMENT,
* Reference to split container
       DG_SPLITTER          TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
* Reference to grid container
       DG_PARENT_GRID     TYPE REF TO CL_GUI_CONTAINER,
* Reference to html container
       DG_HTML_CNTRL        TYPE REF TO CL_GUI_HTML_VIEWER,
* Reference to html container
       DG_PARENT_HTML     TYPE REF TO CL_GUI_CONTAINER.
 

*---------------------------------------------------------------------*
*       CLASS ZALV_EVENT_RECEIVER DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class ZALV_EVENT_RECEIVER definition.
  PUBLIC SECTION.
    methods handle_total_txt
    for event SUBTOTAL_TEXT of CL_GUI_ALV_GRID
    importing
              ES_SUBTOTTXT_INFO
              EP_SUBTOT_LINE
              E_EVENT_DATA.
    methods handle_DOUBLE_CLICK
          for event DOUBLE_CLICK of cl_gui_alv_grid
          importing
          E_ROW
          E_COLUMN
          ES_ROW_NO.
    methods handle_TOP_OF_PAGE
         for event TOP_OF_PAGE of cl_gui_alv_grid
         importing E_DYNDOC_ID.
ENDCLASS.
*---------------------------------------------------------------------*
*       CLASS ZALV_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS ZALV_EVENT_RECEIVER IMPLEMENTATION.
  method handle_total_txt.
    break zhenpan.
  endmethod.
  method handle_DOUBLE_CLICK.
    break zhenpan.
  endmethod.
  method handle_TOP_OF_PAGE.
  PERFORM EVENT_TOP_OF_PAGE USING   E_DYNDOC_ID.
*  CALL METHOD E_DYNDOC_ID->ADD_TEXT
*    EXPORTING
*      TEXT = 'Report Title:'.
*  CALL METHOD E_DYNDOC_ID->NEW_LINE.
*  CALL METHOD E_DYNDOC_ID->ADD_GAP EXPORTING WIDTH = 10.
*  CALL METHOD E_DYNDOC_ID->ADD_TEXT
*    EXPORTING
*      TEXT = 'yes'.
*   CALL METHOD E_DYNDOC_ID->DISPLAY_DOCUMENT.
   BREAK ZHENPAN.
  endmethod.
ENDCLASS.

TYPE-POOLS: slis.
DATA: go_grid type ref to cl_gui_alv_grid.
data: event_receiver type ref to zalv_event_receiver.
data: gt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat.
DATA:INFO type standard table of X031L.
DATA: INFO_TAB type X031L .
data: ls_fieldcat type lvc_s_fcat.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
      is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.
DATA:V_HTML             TYPE REF TO CL_DD_DOCUMENT,
        V_HTML_VIEW        TYPE REF TO CL_GUI_HTML_VIEWER.
DATA: V_SPLIT            TYPE REF TO CL_GUI_EASY_SPLITTER_CONTAINER.

*********

*&---------------------------------------------------------------------*
*& Report  ZPZALV02                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZPZALV02                      .
INCLUDE ZPZALV02_TOP.

SELECT-OPTIONS: LNAME FOR USR02-BNAME.

START-OF-SELECTION.
  create object event_receiver.
  TYPES: BEGIN OF LIST_T.
  TYPES VD(1).
  TYPES LOGON_NAME TYPE USR02-BNAME.
  TYPES NAME(10).
  TYPES CREATE_TIME TYPE D.
  TYPES DEVCLASS(20).
  TYPES T1 TYPE I.
  TYPES T2 TYPE I.
  TYPES: END OF LIST_T.
  DATA: TAB TYPE LIST_T.
  DATA: LIST TYPE TABLE OF LIST_T.
  SELECT  ERDAT
         DEVCLASS
         NAME_LAST
         T1~BNAME
         INTO (TAB-CREATE_TIME,TAB-DEVCLASS,TAB-NAME,TAB-LOGON_NAME)
         FROM USR02 AS T1
         INNER JOIN USR21 AS T2 ON T2~BNAME = T1~BNAME
         INNER JOIN TDEVC ON T1~BNAME = TDEVC~AS4USER
         INNER JOIN USER_ADDR ON USER_ADDR~BNAME = T1~BNAME
         WHERE T1~BNAME IN LNAME.
    TAB-T1 = TAB-T1 + 1.
    TAB-T2 = TAB-T2 + 1.
    APPEND TAB TO LIST.
  ENDSELECT.
 

CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'LOGON_NAME'.
  ls_fieldcat-scrtext_l = '登陆名称'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'NAME'.
  ls_fieldcat-scrtext_l = '用户名称'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'DEVCLASS'.
  ls_fieldcat-scrtext_l = '开发类'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'CREATE_TIME'.
  ls_fieldcat-scrtext_l = '用户创建时间'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'T1'.
  ls_fieldcat-scrtext_l = 'T1'.
  ls_fieldcat-DO_SUM = 'X'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'T2'.
  ls_fieldcat-scrtext_l = 'T2'.
*  ls_fieldcat-DO_SUM = 'X'.
  APPEND ls_fieldcat TO  gt_fieldcat.

END-OF-SELECTION.
CALL SCREEN 100.
FORM EVENT_TOP_OF_PAGE USING   DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
      CALL METHOD DG_DYNDOC_ID->ADD_TEXT
    EXPORTING
      TEXT      = 'Test Report'
      SAP_STYLE = CL_DD_AREA=>HEADING.
    PERFORM HTML.
ENDFORM.
FORM HTML.
  DATA : DL_LENGTH  TYPE I,                           " Length
         DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id
* Creating html control
  IF DG_HTML_CNTRL IS INITIAL.
    CREATE OBJECT DG_HTML_CNTRL
         EXPORTING
              PARENT    = DG_PARENT_HTML.
  ENDIF.
* Reuse_alv_grid_commentary_set
  CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
    EXPORTING
      DOCUMENT = DG_DYNDOC_ID
      BOTTOM   = SPACE
    IMPORTING
      LENGTH   = DL_LENGTH.
* Get TOP->HTML_TABLE ready
  CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.
* Set wallpaper
  CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND
    EXPORTING
      PICTURE_ID = DL_BACKGROUND_ID.
* Connect TOP document to HTML-Control
  DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.
* Display TOP document
  CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT
    EXPORTING
      REUSE_CONTROL      = 'X'
      PARENT             = DG_PARENT_HTML
    EXCEPTIONS
      HTML_DISPLAY_ERROR = 1.
ENDFORM.                    " HTML
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ZPZALV02_S1'.
*  SET TITLEBAR 'xxx'.
CREATE OBJECT DG_DYNDOC_ID
                   EXPORTING STYLE = 'ALV_GRID'.
* Create Splitter for custom_container
  CREATE OBJECT DG_SPLITTER
             EXPORTING PARENT  = cl_gui_container=>screen0
                       ROWS    = 2
                       COLUMNS = 1.
* Split the custom_container to two containers and move the reference
* to receiving containers g_parent_html and g_parent_grid
  "i am allocating the space for grid and top of page
  CALL METHOD DG_SPLITTER->GET_CONTAINER
    EXPORTING
      ROW       = 1
      COLUMN    = 1
    RECEIVING
      CONTAINER = DG_PARENT_HTML.
  CALL METHOD DG_SPLITTER->GET_CONTAINER
    EXPORTING
      ROW       = 2
      COLUMN    = 1
    RECEIVING
      CONTAINER = DG_PARENT_GRID.
  CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
    EXPORTING
      ID     = 1
      HEIGHT = 5.
  create object go_grid exporting
                        i_parent = DG_PARENT_GRID.
  SET HANDLER event_receiver->handle_total_txt FOR go_grid.
  set handler event_receiver->handle_DOUBLE_CLICK for go_grid.
  set handler event_receiver->handle_TOP_OF_PAGE for go_grid.


  DATA: SLA TYPE LVC_S_LAYO.

DATA: LS_VARI TYPE DISVARIANT.
  LS_VARI-REPORT      = SY-REPID.
  LS_VARI-HANDLE      = SPACE.
  LS_VARI-LOG_GROUP   = SPACE.
  LS_VARI-USERNAME    = SPACE.
  LS_VARI-VARIANT     = SPACE.
  LS_VARI-TEXT        = SPACE.
  LS_VARI-DEPENDVARS  = SPACE.
  call method go_grid->set_table_for_first_display
      exporting
      is_variant                    = LS_VARI
        i_save                        = 'A'
        is_layout                     = sla
      changing
        it_outtab                     = LIST[]
        it_fieldcatalog               = gt_fieldcat[]
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4.
* Initializing document
  CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.

* Processing events
  CALL METHOD GO_GRID->LIST_PROCESSING_EVENTS
    EXPORTING
      I_EVENT_NAME = 'TOP_OF_PAGE'
      I_DYNDOC_ID  = DG_DYNDOC_ID.
  "end }
ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
    WHEN 'BACK'.
       SET SCREEN 0.LEAVE SCREEN.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

4. 小计与合计

*&---------------------------------------------------------------------*
*& Report  ZPZALV02                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZPZALV02                      .
TABLES: USR02,TDEVC.
*---------------------------------------------------------------------*
*       CLASS ZALV_EVENT_RECEIVER DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class ZALV_EVENT_RECEIVER definition.
  PUBLIC SECTION.
    methods handle_total_txt
    for event SUBTOTAL_TEXT of CL_GUI_ALV_GRID
    importing
              ES_SUBTOTTXT_INFO
              EP_SUBTOT_LINE
              E_EVENT_DATA.
    methods handle_DOUBLE_CLICK
          for event DOUBLE_CLICK of cl_gui_alv_grid
          importing
          E_ROW
          E_COLUMN
          ES_ROW_NO.
ENDCLASS.
*---------------------------------------------------------------------*
*       CLASS ZALV_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS ZALV_EVENT_RECEIVER IMPLEMENTATION.
  method handle_total_txt.
    break zhenpan.
  endmethod.
  method handle_DOUBLE_CLICK.
    break zhenpan.
  endmethod.
ENDCLASS.

TYPE-POOLS: slis.
DATA: go_grid type ref to cl_gui_alv_grid.
data: event_receiver type ref to zalv_event_receiver.
data: gt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat.
DATA:INFO type standard table of X031L.
DATA: INFO_TAB type X031L .
data: ls_fieldcat type lvc_s_fcat.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
      is_fcat LIKE LINE OF it_fcat.
DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.

SELECT-OPTIONS: LNAME FOR USR02-BNAME.

START-OF-SELECTION.
  create object event_receiver.
  TYPES: BEGIN OF LIST_T.
  TYPES VD(1).
  TYPES LOGON_NAME TYPE USR02-BNAME.
  TYPES NAME(10).
  TYPES CREATE_TIME TYPE D.
  TYPES DEVCLASS(20).
  TYPES T1 TYPE I.
  TYPES T2 TYPE I.
  TYPES: END OF LIST_T.
  DATA: TAB TYPE LIST_T.
  DATA: LIST TYPE TABLE OF LIST_T.
  SELECT  ERDAT
         DEVCLASS
         NAME_LAST
         T1~BNAME
         INTO (TAB-CREATE_TIME,TAB-DEVCLASS,TAB-NAME,TAB-LOGON_NAME)
         FROM USR02 AS T1
         INNER JOIN USR21 AS T2 ON T2~BNAME = T1~BNAME
         INNER JOIN TDEVC ON T1~BNAME = TDEVC~AS4USER
         INNER JOIN USER_ADDR ON USER_ADDR~BNAME = T1~BNAME
         WHERE T1~BNAME IN LNAME.
    TAB-T1 = TAB-T1 + 1.
    TAB-T2 = TAB-T2 + 1.
    APPEND TAB TO LIST.
  ENDSELECT.

  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'LOGON_NAME'.
  ls_fieldcat-scrtext_l = '登陆名称'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'NAME'.
  ls_fieldcat-scrtext_l = '用户名称'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'DEVCLASS'.
  ls_fieldcat-scrtext_l = '开发类'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'CREATE_TIME'.
  ls_fieldcat-scrtext_l = '用户创建时间'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'T1'.
  ls_fieldcat-scrtext_l = 'T1'.
  ls_fieldcat-DO_SUM = 'X'.
  APPEND ls_fieldcat TO  gt_fieldcat.
  CLEAR ls_fieldcat.
  ls_fieldcat-fieldname     = 'T2'.
  ls_fieldcat-scrtext_l = 'T2'.
*  ls_fieldcat-DO_SUM = 'X'.
  APPEND ls_fieldcat TO  gt_fieldcat.

END-OF-SELECTION.
  SET PF-STATUS 'ZPZALV02_S1'.
  create object go_grid exporting
                        i_parent = cl_gui_container=>screen0.
  SET HANDLER event_receiver->handle_total_txt FOR go_grid.
  set handler event_receiver->handle_DOUBLE_CLICK for go_grid.

 

  DATA: SLA TYPE LVC_S_LAYO.

  sla-GRID_TITLE = '用户和开发类列表'.
  SLA-SEL_MODE = 'D'.
*  sla-TOTALS_TEXT = 'total txt'.
*  sla-SUBTOTALS_TEXT = 'subtotal txt'.
*  sla-TOTALS_BEF = 'X'.
* SLA-NUMC_TOTAL = 'X'.
  DATA:   IT_SORT TYPE LVC_T_SORT.
  DATA:   IT_TAB TYPE LVC_S_SORT.
  IT_TAB-FIELDNAME = 'LOGON_NAME'.
  IT_TAB-SPOS = '1'.
  IT_TAB-UP = 'X'.
  IT_TAB-DOWN = SPACE.
  IT_TAB-SELTEXT = 'T1'.
  IT_TAB-SUBTOT = 'X'.
  APPEND IT_TAB TO IT_SORT.
  IT_TAB-FIELDNAME = 'NAME'.
  IT_TAB-SPOS = '1'.
  IT_TAB-UP = 'X'.
  IT_TAB-DOWN = SPACE.
  IT_TAB-SELTEXT = 'T2'.
  IT_TAB-SUBTOT = 'X'.
  APPEND IT_TAB TO IT_SORT.
 

 call method go_grid->set_table_for_first_display
      exporting
*      is_variant                    = gs_variant
        i_save                        = 'A'
        is_layout                     = sla
      changing
        it_outtab                     = LIST[]
        it_fieldcatalog               = gt_fieldcat[]
        IT_SORT = IT_SORT[]
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        others                        = 4.
  WRITE:/.

AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'P1'.

*INSERT IT_TAB INTO  IT_SORT INDEX 1.
      CALL METHOD GO_GRID->SET_SORT_CRITERIA
            EXPORTING IT_SORT = IT_SORT.
      DATA: NAME(1).
      Call method go_grid->CHECK_CHANGED_DATA
                   importing E_VALID = name.
  ENDCASE.

 
 

5. 标准工具栏按钮funtion code

&DETAIL 
&&SEP00
&CHECK  
&REFRESH 
&&SEP01
&LOCAL&CUT
&LOCAL&COPY  
&LOCAL&PASTE
&LOCAL&UNDO 
&&SEP02
&LOCAL&APPEND
&LOCAL&INSERT_ROW 
&LOCAL&DELETE_ROW
&LOCAL&COPY_ROW 
&&SEP03  
&SORT_ASC 
&SORT_DSC 
&FIND
&FIND_MORE 
&MB_FILTER  
&&SEP04  
&MB_SUM 
&MB_SUBTOT 
&&SEP05  
&PRINT_BACK 
&PRINT_BACK_PREVIEW   
&MB_EXPORT
&COL0
&&SEP06  
&GRAPH 
&&SEP07 
&INFO

6. 多行标题和图片
*&---------------------------------------------------------------------*
*& Report  ZPZTEST04                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
 Report  ZPZTEST04  .
type-pools : slis.
*ALV Formatting tables /structures
data: gt_fieldcat type slis_t_fieldcat_alv.
data: gt_events type slis_t_event.
data: gs_layout type slis_layout_alv.
data: gt_page type slis_t_listheader.
data: gs_page type slis_listheader.
data: v_repid like sy-repid.
*ALV Formatting work area
data: w_fieldcat type slis_fieldcat_alv.
data: w_events type slis_alv_event.
data: gt_bsid type table of bsid with header line.
initialization.
perform build_events.
perform build_page_header.
start-of-selection.
*perform build_comment. "top_of_page - in initialization at present
select * from bsid into table gt_bsid up to 10 rows.
*perform populate_for_fm using '1' '3' 'BUKRS' '8' 'GT_BSID' 'Whee'.
*USING = Row, Column, Field name, display length, table name, heading
*OR
perform build_fieldcat.
gs_layout-zebra = 'X'.

*top of page event does not work without I_callback_program
v_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = v_repid
i_structure_name = 'BSID'
* i_background_id = 'ALV_BACKGROUND'
i_grid_title = 'This is the grid title'
* I_GRID_SETTINGS =
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_events = gt_events[]
tables
t_outtab = gt_bsid.
************************************************************************
* Form..............: populate_for_fm
* Description.......: Populates fields for function module used in ALV
************************************************************************
form populate_for_fm using p_row
p_col
p_fieldname
p_len
p_table
p_desc.
w_fieldcat-row_pos = p_row. "Row Position
w_fieldcat-col_pos = p_col. "Column Position
w_fieldcat-fieldname = p_fieldname. "Field name
w_fieldcat-outputlen = p_len. "Column Lenth
w_fieldcat-tabname = p_table. "Table name
w_fieldcat-reptext_ddic = p_desc. "Field Description
w_fieldcat-input = '1'.
append w_fieldcat to gt_fieldcat.
clear w_fieldcat.
endform. " populate_for_fm
*&---------------------------------------------------------------------*
*& Form build_events
*&---------------------------------------------------------------------*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events.
read table gt_events with key name = slis_ev_user_command
into ls_event.
if sy-subrc = 0.
move slis_ev_user_command to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move slis_ev_top_of_page to ls_event-form.
append ls_event to gt_events.
endif.
endform. " build_events
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* When user command is called it uses 2 parameters. The itab
* passed to the ALV is in whatever order it currently is on screen.
* Therefore, you can read table itab index rs_selfield-tabindex to get
* all data from the table. You can also check r_ucomm and code
* accordingly.
*&---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
read table gt_bsid index rs_selfield-tabindex.
* error checking etc.
set parameter id 'KUN' field gt_bsid-kunnr.
call transaction 'XD03' and skip first screen.
endform.
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* Your own company logo can go here if it has been saved (OAOR)
* If the logo is larger than the size of the headings in gt_page,
* the window will not show full logo and will have a scroll bar. Thus,
* it is a good idea to have a standard ALV header if you are going to
* use logos in your top of page.
*&---------------------------------------------------------------------*
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_page
i_logo = 'ENJOYSAP_LOGO'.
endform.
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*&---------------------------------------------------------------------*
*Many and varied fields are available here. Have a look at documentation
*for FM REUSE_ALV_LIST_DISPLAY and REUSE_ALV_FIELDCATALOG_MERGE
*----------------------------------------------------------------------*
form build_fieldcat.
w_fieldcat-fieldname = 'BUDAT'.
w_fieldcat-seltext_m = 'Dte pst'.
w_fieldcat-ddictxt(1) = 'M'.
* Can change the position of fields if you do not want them in order
* of the DDIC or itab
* w_fieldcat-row_pos = '1'.
* w_fieldcat-col_pos = '10'.
append w_fieldcat to gt_fieldcat.
clear w_fieldcat.
endform. " build_fieldcat
*&---------------------------------------------------------------------*
*& Form build_page_header
*&---------------------------------------------------------------------*
* gt_page is used in top of page (ALV subroutine - NOT event)
* *H = Header, S = Selection, A = Action
*----------------------------------------------------------------------*
form build_page_header.
* For Headers, Key is not printed and is irrelevant. Will not cause
* a syntax error, but is not used.
gs_page-typ = 'H'.
gs_page-info = 'Header 1'.
append gs_page to gt_page.
gs_page-typ = 'H'.
gs_page-info = 'Header 2'.
append gs_page to gt_page.
* For Selections, the Key is printed (bold). It can be anything up to 20
* bytes. It gets printed in order of code here, not by key value.
gs_page-typ = 'S'.
gs_page-key = 'And the winner is:'.
gs_page-info = 'Selection 1'.
append gs_page to gt_page.
gs_page-typ = 'S'.
gs_page-key = 'Runner up:'.
gs_page-info = 'Selection 2'.
append gs_page to gt_page.
* For Action, Key is also irrelevant.
gs_page-typ = 'A'.
gs_page-info = 'Action goes here'.
append gs_page to gt_page.
endform. " build_page_header

Tags:ALV Class
相关文章列表:
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明