ABAP 测试用报表模板

********************************************************************
* 事务代码:                                                       *
* 程序名称:                                                       *
* 程序目的:                                         *
* 设 计 人:                                                       *
* 开 发 人:                                                       *
* 设计时间:2023-05-29                                             *
* 程序类型: ABAP/4 程序 ,报表程序                                 *
* 应用类型: XX                                                     *
* 描    述:                                           *
*(修改日志)--------------------------------------------------------*
*                                                                  *
* 日志号   修改人  修改时间       修改说明              传输号码     *
*  ----    ----    ------         -----------
*   001    Seele   2023-05-29     创建报表程序                     *
********************************************************************

REPORT ZDEMO_SEELE09.

*----------------------------------------------------------------------*
* 数据库表声明/Database table declaration
*----------------------------------------------------------------------*
TABLES:mkpf,  " 物料凭证抬头
       mara,
       mseg.  " 物料凭证行项目

*----------------------------------------------------------------------*
* 结构声明类型/Structure type declaration
*----------------------------------------------------------------------*
*&---主表数据/master table data
TYPES:BEGIN OF ty_output,

        matnr      TYPE makt-matnr           , " 物料
        maktx      TYPE makt-maktx           , " 物料描述
        spras      TYPE makt-spras           , " 语言代码

        box        TYPE c                    , " 选择框

      END OF ty_output.

*----------------------------------------------------------------------*
* 全局变量定义/Global variable definition
*----------------------------------------------------------------------*
*&---全局内表定义
DATA:gt_output TYPE TABLE OF ty_output.  " 主数据表

*&---全局结构定义
DATA:gs_output TYPE ty_output.           " 主数据结构

*&---全局变量定义
DATA:gv_uname TYPE user_addr-name_last.  " 用户名

*&---------------------------------------------------------------------*
*& 字段串定义/Field-symbols                                            *
*&---------------------------------------------------------------------*
FIELD-SYMBOLS: TYPE ty_output.

*&---------------------------------------------------------------------*
*&  ALV TYPE/ALV 类型定义
*&---------------------------------------------------------------------*
*&---ALV数据组,类型池
TYPE-POOLS:slis,
           vrm.

*&---定义ALV显示的字段列及其描述等属性
DATA:gt_fieldcat TYPE TABLE OF lvc_s_fcat, " ALV 控制: 字段目录
     gs_fieldcat TYPE lvc_s_fcat,          " ALV 控制: 字段目录
     gs_layout   TYPE lvc_s_layo.          " ALV 控制: 布局结构

*&---------------------------------------------------------------------*
*&  Macro 宏定义
*&---------------------------------------------------------------------*
DEFINE mcr_set_catalog.
  gs_fieldcat-fieldname  = &1. " 字段技术名称
  gs_fieldcat-coltext    = &2. " 显示名称
  gs_fieldcat-ref_table  = &3. " 参照表
  gs_fieldcat-ref_field  = &4. " 参照表字段
  gs_fieldcat-qfieldname = &5. " 参考计量单位的字段名称
  gs_fieldcat-key        = &6. " key 值
  gs_fieldcat-edit       = &7. " 可编辑

  APPEND gs_fieldcat TO gt_fieldcat.
  CLEAR  gs_fieldcat.
END-OF-DEFINITION.

*&---------------------------------------------------------------------*
*& Selection Screen/选择屏幕
*&---------------------------------------------------------------------*
*&---选择屏幕块
SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME TITLE TEXT-101.

*&---范围
  SELECT-OPTIONS:s_matnr FOR mara-matnr .            " 物料凭证

SELECTION-SCREEN END OF BLOCK blk01.

*&---------------------------------------------------------------------*
*& Start-of-selection/开始选择屏幕                                     *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---内表数据获取

  PERFORM frm_get_data.

  IF gt_output IS INITIAL.
    MESSAGE s000(zmm001) DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

*&---------------------------------------------------------------------*
*& end-of-selection/结束选择屏幕(程序结束处理,输出等)               *
*&---------------------------------------------------------------------*
END-OF-SELECTION.

*&===ALV 输出
*&---设置ALV输出格式
  PERFORM frm_init_layout.
*&---设置ALV输出字段
  PERFORM frm_set_fieldcat.
*&---ALV 显示
  PERFORM frm_display_alv.

*&---------------------------------------------------------------------*
*&      Form  frm_get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_10     text
*----------------------------------------------------------------------*
FORM frm_get_data.

  DATA:lv_tabix TYPE i,
       lv_atinn TYPE ausp-atinn.

  FREE:gt_output.
  SELECT
    matnr,  " 物料编码
    maktx,  " 物料描述
    spras   " 语言代码
  FROM makt
  WHERE
    matnr IN @s_matnr
  INTO CORRESPONDING FIELDS OF TABLE @gt_output
  UP TO 10 ROWS.

ENDFORM.                    " frm_get_data
*&---------------------------------------------------------------------*
*&      Form  frm_init_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_init_layout .
  CLEAR gs_layout.
  gs_layout-zebra      = 'X' .    " 斑马线
  gs_layout-cwidth_opt = 'X' .    " 自动调整ALVL列宽
  gs_layout-no_toolbar = 'X' .    " 隐藏工具栏
  gs_layout-sel_mode   = 'A'.     "选择模式
  gs_layout-box_fname  = 'BOX'.   "选择字段
ENDFORM.                    " frm_init_layout
*&---------------------------------------------------------------------*
*&      Form  frm_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .
*&---ALV 输出字段目录,涉及字段必须大写
  mcr_set_catalog: 'MATNR'       TEXT-A01    'MAKT'      'MATNR'       '' ''  '', " 物料
                   'MAKTX'       TEXT-A02    'MAKT'      'MAKTX'       '' ''  '', " 物料描述
                   'SPRAS'       TEXT-A03    'MAKT'      'SPRAS'       '' ''  '', " 语言代码


ENDFORM.                    " frm_fieldcat

*&---------------------------------------------------------------------*
*&      Form  frm_display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_display_alv .
*&---ALV 显示函数
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      is_layout_lvc            = gs_layout
      it_fieldcat_lvc          = gt_fieldcat[]
      i_callback_pf_status_set = 'FRM_USER_STATUS'
      i_callback_user_command  = 'FRM_USER_COMMAND'
      i_default                = 'X'
      i_save                   = 'A'
    TABLES
      t_outtab                 = gt_output
    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.                    " frm_display_alv
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  frm_user_status
*&---------------------------------------------------------------------*
*       设置用户菜单栏状态
*----------------------------------------------------------------------*
*  -->  pt_extab        需要排除的菜单按钮
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_user_status USING ps_extab TYPE slis_t_extab.  "GUI
  SET PF-STATUS 'STATUS_1000' EXCLUDING ps_extab.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  frm_user_command
*&---------------------------------------------------------------------*
*       菜单栏事件
*----------------------------------------------------------------------*
*  -->  pv_ucomm        触发的功能码
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_user_command USING pv_ucomm LIKE sy-ucomm  "user_command
                            pv_selfield TYPE slis_selfield.

  DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
  DATA:lv_answer TYPE c .
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.

  CALL METHOD lr_grid->check_changed_data. "将更新后的数据传到alv所对应的内表

  pv_selfield-refresh = 'X'. "刷新数据
  pv_selfield-row_stable = 'X'.
  pv_selfield-col_stable = 'X'.

  CASE pv_ucomm.
    WHEN 'DOWN'.
      PERFORM frm_download.
  ENDCASE.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_download .

ENDFORM.

你可能感兴趣的:(模板,开发语言)