Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482001
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类: 其他平台

2020-08-11 15:14:29

REPORT zdemo09.

TABLES mara.

DATA:go_table  TYPE REF TO cl_salv_table.

DATA:BEGIN OF gs_itab,
     matnr TYPE makt-matnr,
     maktx TYPE makt-maktx,
     count TYPE i,
     sel,
     END OF gs_itab,
     gt_itab LIKE TABLE OF gs_itab.

SELECT-OPTIONS:s_matnr FOR mara-matnr.

START-OF-SELECTION.
  PERFORM frm_get_data.

END-OF-SELECTION.
  PERFORM frm_out_data.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_get_data.
  SELECT matnr maktx INTO TABLE gt_itab
    UP TO 100 ROWS
    FROM makt
    WHERE spras EQ sy-langu
      AND matnr IN s_matnr.
ENDFORM.                    "FRM_GET_DATA

*----------------------------------------------------------------------*
*       CLASS l_cl_handle_events DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS l_cl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODSon_double_click
                  FOR EVENT double_click OF cl_salv_events_table
                  IMPORTING
                    row  "行
                    column"列

    METHODSon_user_command
                  FOR EVENT added_function OF cl_salv_events_table
                  IMPORTING e_salv_function.

    METHODSon_link_click
             FOR EVENT link_click OF cl_salv_events_table
             IMPORTING row column.
ENDCLASS.                    "l_cl_handle_events DEFINITION

*----------------------------------------------------------------------*
*       CLASS l_cl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS l_cl_handle_events IMPLEMENTATION.
  METHOD on_double_click.
    PERFORM show_cell_info USING row column 'DOUBLE_CLICK'.
  ENDMETHOD.                    "on_double_click

  METHOD on_user_command.
    PERFORM handle_user_command USING e_salv_function.
  ENDMETHOD.                    "on_user_command

  METHOD on_link_click.

    PERFORM on_link_click USING row column.
  ENDMETHOD.                    "on_link_click
ENDCLASS.                    "l_cl_handle_events IMPLEMENTATION

*&---------------------------------------------------------------------*
*&      Form  FRM_OUT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_out_data.
  DATAlo_layout TYPE REF TO cl_salv_layout,
        ls_program TYPE salv_s_layout_key."该结构包含了布局变式所属程序名
  DATAlo_columns TYPE REF TO cl_salv_columns.

  TRY.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table go_table
        CHANGING
          t_table      gt_itab ).
    CATCH cx_salv_msg.
  ENDTRY.

  go_table->set_screen_status(
  pfstatus 'STANDARD'
  report sy-repid
    set_functions go_table->c_functions_all ).

*  lr_functions = gr_table->get_functions( ).
*  lr_functions->set_default( abap_true ).

  lo_columns go_table->get_columns).
  lo_columns->set_optimizeabap_true ).
  PERFORM set_columns_technical USING lo_columns.

  lo_layout go_table->get_layout).
  ls_program-report sy-repid.
  lo_layout->set_keyls_program ).
  lo_layout->set_save_restrictioncl_salv_layout=>restrict_none ).

  PERFORM frm_set_functions.

  DATAlo_event TYPE REF TO cl_salv_events_table.
  lo_event go_table->get_event).

  DATAlo_handle_event TYPE REF TO l_cl_handle_events.
  CREATE OBJECT lo_handle_event.
  SET HANDLER lo_handle_event->on_double_click FOR lo_event.
  SET HANDLER lo_handle_event->on_user_command FOR lo_event.
  SET HANDLER lo_handle_event->on_link_click FOR lo_event.

  go_table->display).

ENDFORM.                    "FRM_OUT_DATA

*&---------------------------------------------------------------------*
*&      Form  set_columns_technical
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IR_COLUMNS text
*----------------------------------------------------------------------*
FORM set_columns_technical USING po_columns TYPE REF TO cl_salv_columns.
***设置ALV的字段属性
  DATAlo_column TYPE REF TO cl_salv_column.

  DEFINE m_set_text.
    lo_column po_columns->get_column&1 ).
    lo_column->set_short_text&2 ).
    lo_column->set_medium_text&2 ).
    lo_column->set_long_text&2 ).
  END-OF-DEFINITION.

  m_set_text 'COUNT' '计数'.
  m_set_text 'SEL' '选择'.

  DATAlo_columns TYPE REF TO cl_salv_column_list.
  TRY.
      lo_columns ?= po_columns->get_column'SEL' ).
      lo_columns->set_cell_typeif_salv_c_cell_type=>checkbox_hotspot ).
      lo_columns->set_output_length10 ).
    CATCH cx_salv_not_found.                            "#EC NO_HANDLER
  ENDTRY.
ENDFORM.                    " set_columns_technical(

*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FUNCTIONS
*&---------------------------------------------------------------------*
*       text 画屏幕可用
*----------------------------------------------------------------------*
FORM frm_set_functions.
*  DATA: lo_functions TYPE REF TO cl_salv_functions_list.
*  lo_functions = go_table->get_functions( ).
*  lo_functions->set_all( abap_true )."Activate All Generic ALV Functions
*
*  INCLUDE .
*  DATA: lv_icon TYPE string.
*  lv_icon = icon_refresh.
*
*  TRY.
*      "附加按钮,只适用于 可控模式 下的SALV
*      lo_functions->add_function(
*        name = 'ZREFRESH'
*        icon = lv_icon
*        text = '刷新按钮'
*        tooltip = '刷新数据'

*        position = if_salv_c_function_position=>right_of_salv_functions ).
*    CATCH cx_salv_existing .
*    CATCH cx_salv_wrong_call .
*  ENDTRY.

ENDFORM.                    "FRM_SET_FUNCTIONS



*&---------------------------------------------------------------------*
*&      Form  show_cell_info
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PV_ROW     text
*      -->PV_COLUMN  text
*      -->PV_TEXT    text
*----------------------------------------------------------------------*
FORM show_cell_info USING pv_row pv_column pv_text.

  MESSAGE pv_text TYPE 'I'.
ENDFORM.                    "show_cell_info

*&---------------------------------------------------------------------*
*&      Form  handle_user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->PV_UCOMM   text
*----------------------------------------------------------------------*
FORM handle_user_command USING pv_ucomm.
  CASE pv_ucomm.
    WHEN 'CREATE'.
  ENDCASE.
ENDFORM.                    "handle_user_command

*&---------------------------------------------------------------------*
*&      Form  on_link_click
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->ROW        text
*      -->COLUMN     text
*----------------------------------------------------------------------*
FORM on_link_click USING pv_row pv_column.
  DATA:ls_stable  TYPE lvc_s_stbl.

  MOVE 'X' TO ls_stable-row.
  MOVE 'X' TO ls_stable-col.

  IF pv_column EQ 'SEL' AND pv_row NE 0.
    READ TABLE gt_itab INTO gs_itab INDEX pv_row.
    IF gs_itab-sel EQ 'X'.
      gs_itab-sel ''.
    ELSE.
      gs_itab-sel 'X'.
    ENDIF.
    MODIFY gt_itab FROM gs_itab INDEX pv_row.
    go_table->refreshs_stable =  ls_stable ).
  ENDIF.

ENDFORM.                    "on_link_click
阅读(6240) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~