ABAP 导入Excel表示例程序

目录

  • ABAP 导入excel示例程序
    • 创建程序
    • 使用的结构
    • 上传下载模板

ABAP 导入excel示例程序

批量导入程序,需要使用到导入模板,首先需要创建程序,之后是需要创建excel导入模板,并且需要将excel导入模板上传到SAP系统里面,之后才可以下载下来进行导入。

创建程序

ABAP 批量导入excel,右击创建程序:
在这里插入图片描述

*&---------------------------------------------------------------------*
*& Report z_test_import_excel
*&---------------------------------------------------------------------*
*& TYPE:Report
*& Description:批量导入excel测试
*& Creator:刘洪裕
*& Created On:2024219*&---------------------------------------------------------------------*
*                           Change History
* ----------        -------------       -------------      -------------
*   Version          Date                Change By           Description
* ----------        -------------       -------------      -------------
*   N                2024.2.19           Hongyu.Liu          创建
*&---------------------------------------------------------------------*
Report z_test_import_excel NO STANDARD PAGE HEADING MESSAGE-ID zfimf01.

TABLES: sscrfields.

"定义相关变量
*TYPES: BEGIN OF ty_data,
*   werks TYPE zfi_mfwb-werks,  "工厂
*   zmj_matnr TYPE zfi_mfwb-zmj_matnr,  "模具料号
*   zcp_matnr TYPE zfi_mfwb-zcp_matnr,  "挤压产出成品料号
*   zdmczl TYPE zfi_mfwb-zdmczl,  "单套模具预计产出重量
*   zsfty TYPE zfi_mfwb-zsfty,  "是否通用
*   zwhrj TYPE zfi_mfwb-zwhrj,  "维护日期
*   zwhr TYPE zfi_mfwb-zwhr,  "维护人
*END OF ty_data.
*DATA gs_data TYPE  ty_data.  "工作区
*DATA gt_data TYPE TABLE OF ty_data.  "内表


*&---------------------------------------------------------------------*
*&  定义相关变量
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ts_output,  "展示结构
         "INCLUDE STRUCTURE zfi_mfwb.
         werks     TYPE zfi_mfwb-werks,  "工厂
         zxlh      TYPE zfi_mfwb-zxlh,  "序列号
         zmj_matnr TYPE zfi_mfwb-zmj_matnr,  "模具料号
         zcp_matnr TYPE zfi_mfwb-zcp_matnr,  "挤压产出成品料号
         "zdmczl TYPE p DECIMALS 2 ,  "单套模具预计产出重量,两位小数
         zdmczl    TYPE zfi_mfwb-zdmczl,  "单套模具预计产出重量
         "zsfty     TYPE zfi_mfwb-zsfty,  "是否通用
         zsfty     TYPE abap_bool,  "是否通用
         zwhrj     TYPE zfi_mfwb-zwhrj,  "维护日期
         zwhr      TYPE zfi_mfwb-zwhr,  "维护人
         zsfbf     TYPE zfi_mfwb-zsfbf,  "是否报废
         type      TYPE bapiret2-type,
         message   TYPE char100,   "bapiret2-message,
         icon      TYPE text20,
         slbox     TYPE c,
         celltab   TYPE  lvc_t_styl, "设置单元格编辑状态
END OF ts_output.
TYPES: BEGIN OF ty_data,"导入数据结构
         werks     TYPE zfi_mfwb-werks,  "工厂
         zxlh      TYPE zfi_mfwb-zxlh,  "序列号
         zmj_matnr TYPE zfi_mfwb-zmj_matnr,  "模具料号
         zcp_matnr TYPE zfi_mfwb-zcp_matnr,  "挤压产出成品料号
         "zdmczl TYPE p DECIMALS 2 ,  "单套模具预计产出重量,两位小数
         zdmczl    TYPE zfi_mfwb-zdmczl,  "单套模具预计产出重量
         "zdmczl    LIKE vbap-ntgew,  "单套模具预计产出重量
         zsfty     TYPE zfi_mfwb-zsfty,  "是否通用
         zwhrj     TYPE zfi_mfwb-zwhrj,  "维护日期
         zwhr      TYPE zfi_mfwb-zwhr,  "维护人
       END OF ty_data.

*DATA: is_data TYPE ty_data.   "导入结构的工作区
*DATA: it_data TYPE TABLE OF ty_data.  "导入结构的工作表
CONSTANTS:cos_template TYPE w3objid VALUE 'ZFIMFWB01',
          cos_filename TYPE string VALUE '模具分摊维护表导入模板.xlsx'.

DATA: gs_layout TYPE lvc_s_layo,
      gt_fieldcat TYPE lvc_t_fcat,
      gs_fieldcat TYPE lvc_s_fcat,
      gs_variant TYPE disvariant. "屏幕变式

DATA: gt_output TYPE STANDARD TABLE OF ts_output WITH DEFAULT KEY,
      gs_output TYPE ts_output.
"DATA: gt_input TYPE TABLE OF zfi_mfwb.  "内表结构与zfi_mfwb一致
DATA: gt_input TYPE TABLE OF ty_data.  "导入模板数据
DATA: gt_output_old TYPE STANDARD TABLE OF ts_output WITH DEFAULT KEY."被修改前的数据

DATA: gt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE. "用来存储屏幕字段参数值,传递录屏参数
DATA: gt_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE. "记录执行BDC过程中产生的消息

DATA: gv_mode TYPE c VALUE 'N'.

* 用于 修改要提示,删除要提示
DATA:gv_edit_flag  TYPE c, "X 表示修改过
     gv_save_flag  TYPE c, "X 表示已经保存。
     gv_check_flag TYPE c, "X 表示已经保存。
     gv_sref_flag  TYPE c, "X 表示刷新。
     gv_line       TYPE int4. "行数

CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_data_changed
        FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING er_data_changed,
      handle_data_changed_finished
        FOR EVENT data_changed_finished OF cl_gui_alv_grid
        IMPORTING
          e_modified
          et_good_cells.
  ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_data_changed.
*    PERFORM FRM_DATA_CHANGED
*                  USING ER_DATA_CHANGED.
  ENDMETHOD.
  METHOD handle_data_changed_finished.
*    PERFORM FRM_DATA_CHANGED_FINISH
*                  USING E_MODIFIED ET_GOOD_CELLS.
    ENDMETHOD.
  ENDCLASS.
*&---------------------------------------------------------------------*
*&  选择屏幕
*&---------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1. "这是在屏幕的执行按钮后的位置添加一个功能按钮

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001.
  PARAMETERS p_file TYPE rlgrap-filename  MODIF ID m1.
SELECTION-SCREEN END OF BLOCK blk1.

*&---------------------------------------------------------------------*
*&  定义相关变量
*&---------------------------------------------------------------------*

FORM frm_init_data.
  DATA: ls_textfield TYPE smp_dyntxt. "菜单制作器:动态文本的程序接口
  ls_textfield-icon_id  = '@49@'.
  ls_textfield-icon_text  = '下载导入模板'.
  sscrfields-functxt_01 = ls_textfield.
  ENDFORM.


*&---------------------------------------------------------------------*
*&  屏幕事件
*&---------------------------------------------------------------------*

INITIALIZATION. "初始化
  "选择屏幕添加按钮
  PERFORM frm_init_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR  p_file. "按选择帮助<F4>键时触发该事件
  PERFORM frm_get_file_name CHANGING p_file.

AT SELECTION-SCREEN.  "在此事件里可以进行对用户输入进行完整性进行检查。
* 处理选择屏幕的按钮 下载模板
  PERFORM frm_screen_button_event.

" AT SELECTION SCREEN OUTPUT事件(也就是PBO) ,在这个事件里你可以通过修改系统默认screen内表修改屏幕的某些属性
AT SELECTION-SCREEN OUTPUT.
* 修改选择屏幕的元素的状态
  PERFORM modify_selction_screen_status.

START-OF-SELECTION. "仅在选择屏幕处理结束之后触发,即当用户点击“执行”按钮时
  PERFORM frm_check_authority.
  PERFORM batch_input.
  PERFORM alv_display USING 'X'.
*&---------------------------------------------------------------------*
*& Form frm_get_file_name:获取文件名称
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- P_FILE
*&---------------------------------------------------------------------*
FORM frm_get_file_name CHANGING cv_file.
  DATA: lt_filetable TYPE filetable,  "表类型
        ls_filetable TYPE file_table, "结构类型
        lv_rc TYPE i.
  FREE lt_filetable.
  CLEAR: lv_rc.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
*        window_title            =
        default_extension       = cl_gui_frontend_services=>filetype_excel
*        default_filename        =
        file_filter             = cl_gui_frontend_services=>filetype_excel
*        with_encoding           =
*        initial_directory       =
*        multiselection          =
    CHANGING
        file_table              = lt_filetable
        rc                      = lv_rc
*        user_action             =
*        file_encoding           =
    EXCEPTIONS
        file_open_dialog_failed = 1
        cntl_error              = 2
        error_no_gui            = 3
        not_supported_by_gui    = 4
        OTHERS                  = 5
            .
  READ TABLE lt_filetable INTO ls_filetable INDEX 1.
    IF sy-subrc <> 0.
*     Implement suitable error handling here
    ENDIF.
    IF sy-subrc EQ 0.
      cv_file = ls_filetable-filename.
    ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_screen_button_event:点击下载模板按钮
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_screen_button_event .
  CASE sscrfields-ucomm.
    WHEN 'FC01'.
      PERFORM frm_download_template USING cos_template cos_filename.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form modify_selction_screen_status
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM modify_selction_screen_status .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_check_authority
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_check_authority .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form batch_input
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM batch_input .
*   EXCEL数据到内表
  PERFORM file_data_input.
*   转换内表
  PERFORM file_data_convert.
*   检查数据
  PERFORM file_data_check.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form alv_display:展示alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&---------------------------------------------------------------------*
FORM alv_display  USING  u_edit TYPE abap_bool .
  PERFORM set_alv_layout.
  PERFORM build_fieldcat USING u_edit.
  PERFORM call_alv_func.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_download_template:下载模板
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> COS_TEMPLATE
*&      --> COS_FILENAME
*&---------------------------------------------------------------------*
FORM frm_download_template  USING    u_objid TYPE w3objid
                                     u_file_name TYPE string.
  DATA: ls_key TYPE wwwdatatab,
        lv_filename TYPE string,
        lv_path TYPE string,
        lv_fullpath TYPE string.

  "判断模板是否存在
  SELECT SINGLE * FROM wwwdata
    WHERE relid EQ 'MI'
    AND objid EQ @u_objid
    INTO CORRESPONDING FIELDS OF @ls_key.
  IF sy-subrc NE 0.
*   模板&1不存在
    MESSAGE s007 WITH u_objid.
    RETURN.
  ENDIF.
*   调用函数打开文件选择框

  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
*      window_title              =
      default_extension         = cl_gui_frontend_services=>filetype_excel
      default_file_name         =  u_file_name
*      with_encoding             =
*      file_filter               =
*      initial_directory         =
*      prompt_on_overwrite       = 'X'
    CHANGING
      filename                  = lv_filename
      path                      = lv_path
      fullpath                  = lv_fullpath
*      user_action               =
*      file_encoding             =
    EXCEPTIONS
      cntl_error                = 1
      error_no_gui              = 2
      not_supported_by_gui      = 3
      invalid_default_file_name = 4
      OTHERS                    = 5
          .
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.
  CHECK lv_fullpath NE ''.
*   下载SMW0模版
  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      key = ls_key
      destination = CONV localfile( lv_fullpath ).

ENDFORM.
*&---------------------------------------------------------------------*
*& Form file_data_input:EXCEL数据到内表
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM file_data_input .
* 数据EXCEL-》内表
  PERFORM frm_excel_to_table TABLES gt_input USING p_file 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form file_data_convert:转换内表
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM file_data_convert .
*   添加前导0
  LOOP AT gt_input ASSIGNING FIELD-SYMBOL(<lfs_input>).
    <lfs_input>-zmj_matnr = |{ <lfs_input>-zmj_matnr ALPHA = IN }|.
    <lfs_input>-zcp_matnr = |{ <lfs_input>-zcp_matnr ALPHA = IN }|.
    ENDLOOP.
  gt_output = CORRESPONDING #( gt_input ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form file_data_check:检查数据
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM file_data_check .
  IF gt_output IS NOT INITIAL.
    LOOP AT gt_output ASSIGNING FIELD-SYMBOL(<ls_output>).
      CLEAR:<ls_output>-type,
           <ls_output>-message.
      IF <ls_output>-werks IS INITIAL.
          <ls_output>-type = 'E'.
          <ls_output>-message = '工厂不能为空;'.
      ENDIF.
      IF <ls_output>-zmj_matnr IS INITIAL.
           <ls_output>-type = 'E'.
           <ls_output>-message = <ls_output>-message && '模具料号不能为空;'.
      ENDIF.
      IF <ls_output>-zcp_matnr IS INITIAL.
            <ls_output>-type = 'E'.
            <ls_output>-message = <ls_output>-message && '挤压产出成品料号不能为空;'.
      ENDIF.
      IF <ls_output>-type <> 'E'. "如果关键值不为空
          <ls_output>-type = 'N'. "将类型设置为N
      ENDIF.
      PERFORM set_light CHANGING <ls_output>. "设置提示灯
    ENDLOOP.

  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_excel_to_table
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> GT_INPUT
*     -->U_FILE       文件
*     -->U_START_ROW  文件内的数据从哪行开始取
*&---------------------------------------------------------------------*
FORM frm_excel_to_table  TABLES   et_input TYPE STANDARD TABLE
                         USING    u_file  TYPE rlgrap-filename
                                  u_start_row TYPE i.
  DATA: lt_intern TYPE STANDARD TABLE OF zalsmex_tabline.
  FREE: lt_intern.

*DATA FILENAME    TYPE RLGRAP-FILENAME.
*DATA I_BEGIN_COL TYPE I.
*DATA I_BEGIN_ROW TYPE I.
*DATA I_END_COL   TYPE I.
*DATA I_END_ROW   TYPE I.
*DATA INTERN      TYPE STANDARD TABLE OF ZALSMEX_TABLINE.

  CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename          = u_file
      i_begin_col       = 1
      i_begin_row       = 2
      i_end_col         = 99
      i_end_row         = 65536
    TABLES
      intern            = lt_intern
    EXCEPTIONS
      inconsistent_parameters   = 1
      upload_ole                = 2
      OTHERS                    = 3
            .
  IF sy-subrc NE 0.
  ENDIF.
  SORT lt_intern BY row col.
  LOOP AT lt_intern INTO DATA(ls_intern).
    "下面检查是否是数字
    AT NEW row. "如果字段row及row的左侧全部字段的数据,与上一行数据不一致,则执行代码。
      APPEND INITIAL LINE TO et_input ASSIGNING FIELD-SYMBOL(<ls_input>). "创建一个新行,并分配指针
    ENDAT.
    ASSIGN COMPONENT ls_intern-col OF STRUCTURE <ls_input> TO FIELD-SYMBOL(<lv_val>)."就是在每次循环中,都会分配一个结构的字段,是根据索引来决定的
    IF <lv_val> IS ASSIGNED.
      IF ls_intern-col EQ 5.  "如果是第5列(是否通用)
        <lv_val> = ls_intern-value.
      ENDIF.
      TRY.
        <lv_val> = ls_intern-value.
      CATCH cx_sy_conversion_no_number INTO DATA(lr_cx_sy_conversion_no_number).
*&1&2&3,&4
        MESSAGE e003 WITH ls_intern-row ls_intern-col ls_intern-value lr_cx_sy_conversion_no_number->get_text( ).
      CATCH cx_sy_conversion_overflow INTO DATA(lr_cx_sy_conversion_overflow).
*&1&2&3,&4
        MESSAGE e003 WITH ls_intern-row ls_intern-col ls_intern-value lr_cx_sy_conversion_overflow->get_text( ).
      CATCH cx_root INTO DATA(lr_cx_root).
*&1&2&3,&4
        MESSAGE e003 WITH ls_intern-row ls_intern-col ls_intern-value lr_cx_root->get_text( ).
      ENDTRY.
      UNASSIGN <lv_val>.  "取消分配
    ENDIF.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_alv_layout:设置alv的layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM set_alv_layout .
  CLEAR: gs_layout,gs_variant.
  gs_layout-zebra = 'X'.  "斑马线
  gs_layout-cwidth_opt = 'X'.  "自动列宽
  gs_layout-box_fname = 'SLBOX'.  "选择框字段名 "用户在ALV控件的行选中,对应的内存中【SLBOX】字段会被打上X
  gs_variant-report = sy-repid.
  gs_variant-handle = '01'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> U_EDIT
*&---------------------------------------------------------------------*
FORM build_fieldcat  USING    e_edit TYPE abap_bool.
  IF gt_fieldcat IS INITIAL.  "如果gt_fieldcat是初始状态
    APPEND VALUE  #( fieldname = 'ICON' ref_field  = 'ID' ref_table  = 'ICON'  scrtext_l = '状态' )  TO  gt_fieldcat[].
    APPEND VALUE  #( fieldname = 'MESSAGE'  ref_field = 'MESSAGE' ref_table = 'BAPIRET2' scrtext_l = '' ) TO gt_fieldcat[].
  ENDIF.
* DATA CT_FIELDCAT TYPE LVC_T_FCAT.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE        = I_BUFFER_ACTIVE
      i_structure_name       = 'ZFI_MFWB'
*     I_CLIENT_NEVER_DISPLAY = 'X'
*     I_BYPASSING_BUFFER     = I_BYPASSING_BUFFER
*     I_INTERNAL_TABNAME     = I_INTERNAL_TABNAME
    CHANGING
      ct_fieldcat            = gt_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
*     循环字段,修改显示的列名
  CLEAR gs_fieldcat.
  LOOP AT gt_fieldcat INTO gs_fieldcat.
    IF gs_fieldcat-fieldname = 'ZMJ_MATNR'.
      gs_fieldcat-coltext = '模具料号'.
    ELSEIF gs_fieldcat-fieldname = 'ZXLH'.
      gs_fieldcat-coltext = '序列号'.
    ELSEIF gs_fieldcat-fieldname = 'ZCP_MATNR'.
      gs_fieldcat-coltext = '挤出产出成品料号'.
    ELSEIF gs_fieldcat-fieldname = 'ZDMCZL'.
      gs_fieldcat-coltext = '单套模具预计产出重量'.
      gs_fieldcat-edit = 'X'."可编辑
*        gs_fieldcat-edit = ''."不可编辑
*        IF p_file IS INITIAL. "如果不是导入文件的操作,则设置重量为编辑
*          gs_fieldcat-edit = 'X'."可编辑
*        ENDIF.
    ELSEIF gs_fieldcat-fieldname = 'ZSFTY'.
      gs_fieldcat-coltext = '是否通用'.
      gs_fieldcat-edit = 'X'."可编辑
    ELSEIF gs_fieldcat-fieldname = 'ZWHRJ'.
      gs_fieldcat-coltext = '维护日期'.
    ELSEIF gs_fieldcat-fieldname = 'ZWHR'.
      gs_fieldcat-coltext = '维护人'.
    ELSEIF gs_fieldcat-fieldname = 'ZSFBF'.
      gs_fieldcat-coltext = '是否报废'.
      "gs_fieldcat-edit = 'X'."可编辑
    ENDIF.
    MODIFY gt_fieldcat FROM gs_fieldcat.
    CLEAR gs_fieldcat.
  ENDLOOP.
  IF sy-subrc <> 0.
*     Implement suitable error handling here
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form call_alv_func:调用alv显示函数
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM call_alv_func .
  DATA: lt_event TYPE slis_t_event,
        ls_event TYPE slis_alv_event.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
   EXPORTING
     i_callback_program                = sy-repid
     i_callback_pf_status_set          = 'SET_PF_STATUS'
     i_callback_user_command           = 'USER_COMMAND'
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     i_callback_html_top_of_page       = 'FRM_TOP_OF_PAGE'
     is_layout_lvc                     = gs_layout
     it_fieldcat_lvc                   = gt_fieldcat
     i_save                            = 'U'
     is_variant                        = gs_variant
     it_events                         = lt_event
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           = E_EXIT_CAUSED_BY_CALLER
*     ES_EXIT_CAUSED_BY_USER            = ES_EXIT_CAUSED_BY_USER
    TABLES
      t_outtab                          = gt_output
   EXCEPTIONS
     program_error                     = 1
     OTHERS                            = 2
            .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& FORM FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM frm_top_of_page USING p_cl_dd TYPE REF TO cl_dd_document.

ENDFORM.

*&---------------------------------------------------------------------*
*& FORM SET_PF_STATUS
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& -->  P1        TEXT
*& <--  P2        TEXT
*&---------------------------------------------------------------------*
FORM set_pf_status USING u_t_extab TYPE slis_t_extab.
  SET PF-STATUS 'STANDARD' EXCLUDING u_t_extab.
  SET TITLEBAR 'STANDARD'.
ENDFORM.

*&---------------------------------------------------------------------*
*& FORM USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING u_v_ucomm LIKE sy-ucomm
                        u_s_selfield TYPE slis_selfield.
  DATA: lr_grid TYPE REF TO cl_gui_alv_grid,
        lv_error TYPE char1,
        lv_confirm  TYPE c.
  DATA: lt_mod_data TYPE lvc_t_modi,
        ls_mod_data TYPE lvc_s_modi.
  DATA: lo_data TYPE REF TO cl_alv_changed_data_protocol.

*DATA IR_SALV_FULLSCREEN_ADAPTER TYPE REF TO CL_SALV_FULLSCREEN_ADAPTER.
*DATA ET_EXCLUDING               TYPE SLIS_T_EXTAB.
*DATA E_REPID                    TYPE SY-REPID.
*DATA E_CALLBACK_PROGRAM         TYPE SY-REPID.
*DATA E_CALLBACK_ROUTINE         TYPE SLIS_FORMNAME.
*DATA E_GRID                     TYPE REF TO CL_GUI_ALV_GRID.
*DATA ET_FIELDCAT_LVC            TYPE LVC_T_FCAT.
*DATA ER_TRACE                   TYPE REF TO CL_ALV_TRACE.
*DATA E_FLG_NO_HTML              TYPE C.
*DATA ES_LAYOUT_KKBLO            TYPE KKBLO_LAYOUT.
*DATA ES_SEL_HIDE                TYPE SLIS_SEL_HIDE_ALV.
*DATA ET_EVENT_EXIT              TYPE KKBLO_T_EVENT_EXIT.
*DATA ER_FORM_TOL                TYPE REF TO CL_SALV_FORM.
*DATA ER_FORM_EOL                TYPE REF TO CL_SALV_FORM.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
*   EXPORTING
*     IR_SALV_FULLSCREEN_ADAPTER       = IR_SALV_FULLSCREEN_ADAPTER
   IMPORTING
     e_GRID                          = lr_grid.
  lr_grid->check_changed_data( ).
  CASE u_v_ucomm.
    WHEN 'SAVE'.
      PERFORM file_data_check.
      PERFORM refresh_alv.
      PERFORM user_command_import_check CHANGING lv_error.
      CHECK lv_error  = ''.
      PERFORM check_user_decision USING '确认' '确定保存?' CHANGING lv_confirm.
      CHECK lv_confirm EQ abap_true.
      PERFORM user_command_import.
      gv_save_flag = 'X'.
    WHEN  'EXIT'.
      LEAVE TO SCREEN 0.
      CLEAR: gv_edit_flag,gv_save_flag.
    WHEN OTHERS.
  ENDCASE.
  PERFORM refresh_alv.
  ENDFORM.
*&---------------------------------------------------------------------*
*& Form refresh_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM refresh_alv .
  DATA: lr_grid TYPE REF TO cl_gui_alv_grid,
        ls_stable TYPE lvc_s_stbl.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.

  lr_grid->get_frontend_layout(
    IMPORTING
      es_layout = DATA(ls_layout)
  ).
  ls_layout-cwidth_opt = abap_true.
  lr_grid->set_frontend_layout( is_layout = ls_layout ).

  ls_stable-row = 'X'.
  ls_stable-col = 'X'.

  lr_grid->refresh_table_display(
    EXPORTING
      is_stable = ls_stable
    EXCEPTIONS
      finished = 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.
*&---------------------------------------------------------------------*
*& Form user_command_import_check
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LV_ERROR
*&---------------------------------------------------------------------*
FORM user_command_import_check  CHANGING c_error TYPE char1.
  CLEAR c_error.
  IF lines( gt_output ) = 0.
    MESSAGE s000 WITH '导入数据为空' DISPLAY LIKE 'E'.
    c_error = 'X'.
    EXIT.
  ENDIF.
  IF NOT line_exists( gt_output[ slbox = 'X' ] ).
    MESSAGE s000 WITH '至少选中一行数据' DISPLAY LIKE 'E'.
    c_error = 'X'.
    EXIT.
  ENDIF.

  IF line_exists( gt_output[ type = 'E' slbox = 'X' ] ).
    MESSAGE s000 WITH '数据检查不通过,不可导入' DISPLAY LIKE 'E'.
    c_error = 'X'.
    EXIT.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form check_user_decision:确认用户决定
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&      --> P_
*&      <-- LV_CONFIRM
*&---------------------------------------------------------------------*
FORM check_user_decision  USING    u_title
                                    u_question
                           CHANGING ch_confirm.
  DATA: lv_answer TYPE char1.
  CLEAR: ch_confirm.

  CLEAR: lv_answer.
  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      titlebar              = u_title
      text_question         = u_question
      default_button        = '2'
      display_cancel_button = ''
    IMPORTING
      answer                = lv_answer
    EXCEPTIONS
      text_not_found        = 1
      OTHERS                = 2.
  IF sy-subrc NE 0.
  ENDIF.

  IF lv_answer EQ '1'.
    ch_confirm = abap_true.
  ELSE.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form user_command_import
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM user_command_import .
  DATA: gs_input TYPE zfi_mfwb.  "工作区结构与zfi_mfwb一致
   LOOP AT gt_output ASSIGNING FIELD-SYMBOL(<lfs_output>) WHERE slbox = abap_true.
     MOVE-CORRESPONDING <lfs_output> TO gs_input.
     gs_input-mandt = sy-mandt.  "当前集团号
     gs_input-zwhrj = sy-datum. "当前日期
     gs_input-zwhr = sy-uname. "当前登录用户名
     INSERT zfi_mfwb FROM gs_input.
     IF sy-subrc <> 0.
       <lfs_output>-type = 'E'.
       IF sy-subrc = 4.
         <lfs_output>-message = '导入失败!数据库已存在此条数据'.
       ENDIF.
     ENDIF.
     IF sy-subrc = 0.
       <lfs_output>-type = 'S'.
       <lfs_output>-message = '导入成功!'.
     ENDIF.
     PERFORM set_light CHANGING <lfs_output>. "设置提示灯
   ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form USER_COMMAND_EXIT_CHECK
*&---------------------------------------------------------------------*
*& 如果没保存就退出 弹框提示
*&---------------------------------------------------------------------*
*&      <-- LV_ERROR
*&---------------------------------------------------------------------*
FORM user_command_exit_check CHANGING c_error.
  DATA: lv_confirm TYPE c.

*  IF p_cre = 'X'.
*    IF NOT line_exists( gt_output[ type = 'E' ] ).
*      gv_edit_flag = 'X'.
*    ENDIF.
*  ENDIF.

  IF gv_edit_flag = 'X' AND gv_save_flag = '' .
    PERFORM check_user_decision USING '确认'
                                        '还没保存,确定退出?'
                                  CHANGING lv_confirm.
    IF lv_confirm EQ abap_true.
    ELSE.
      c_error = 'X'.
      EXIT.
    ENDIF.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form set_light:设置提示灯
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- <LS_OUTPUT>
*&---------------------------------------------------------------------*
FORM set_light  CHANGING ch_output TYPE ts_output.
  IF ch_output-type EQ 'E'.   "失败状态
    ch_output-icon = 'ICON_RED_LIGHT'.
  ELSEIF ch_output-type EQ 'S'.   "成功状态
    ch_output-icon = 'ICON_GREEN_LIGHT'.
  ELSEIF ch_output-type EQ 'N'.   "空状态
    ch_output-icon = 'ICON_YELLOW_LIGHT'.
  ENDIF.
  CALL FUNCTION 'ICON_CREATE'
    EXPORTING
      name                  = ch_output-icon
    IMPORTING
      result                = ch_output-icon
    EXCEPTIONS
      icon_not_found        = 1
      outputfield_too_short = 2
      OTHERS                = 3.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.

使用的结构

双击结构名称,结构的字段如下:
在这里插入图片描述

上传下载模板

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/399578.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Code-Audit(代码审计)习题记录

介绍&#xff1a; 自己懒得搭建靶场了&#xff0c;靶场地址是 GitHub - CHYbeta/Code-Audit-Challenges: Code-Audit-Challenges为了方便在公网练习&#xff0c;可以随地访问&#xff0c;本文所有的题目均来源于网站HSCSEC-Code Audit 1、习题一 题目内容如下&#xff1a; 1…

运行jar时提示缺少依赖的类

供应商丢过来一个jar&#xff0c;是用Java写的Windows桌面程序&#xff0c;运行jar时提示缺少依赖的类&#xff0c;一看就是打包没带依赖的库&#xff0c;下面是解决方法&#xff1a; 1、解压缩jar&#xff0c;查看 META-INF 目录下的 MANIFEST.MF&#xff0c;看看都引用了哪些…

FlinkCDC详解

1、FlinkCDC是什么 1.1 CDC是什么 CDC是Chanage Data Capture&#xff08;数据变更捕获&#xff09;的简称。其核心原理就是监测并捕获数据库的变动&#xff08;例如增删改&#xff09;&#xff0c;将这些变更按照发生顺序捕获&#xff0c;将捕获到的数据&#xff0c;写入数据…

Cesium for Unreal 从源码编译到应用——插件编译

一、安装环境 Unreal Engine 5.3 CMake 3.17.5 Microsoft Visual Studio 2019 二、源码准备 下载cesium-unreal-samples工程。 git clone https://github.com/CesiumGS/cesium-unreal-samples.git 然后在工程目录创建Plugins文件夹&#xff0c;并下载cesium-unreal工程。 …

演练纪实│同创永益助力中交财务公司成功开展灾备应急演练

12月26日同创永益协助中交财务公司顺利完成核心业务系统、高性能云平台等关键业务系统的子系统验证演练&#xff0c;以及模拟切换演练、同城灾备应急演练。 同创永益北方交付二组的同事在演练前与中交财务公司演练负责人紧密沟通&#xff0c;展现了出色的专业素养和团队协作能力…

Vue3学习——标签的ref属性

在HTML标签上&#xff0c;可以使用相同的ref名称&#xff0c;得到DOM元素ref放在组件上时&#xff0c;拿到的是组件实例&#xff08;组件defineExpose暴露谁&#xff0c;ref才可以看到谁&#xff09; <script setup lang"ts"> import RefPractice from /compo…

测试C#调用Emgucv读取并显示视频文件

微信公众号“CSharp编程大全”的文章《C# 视频播放》介绍了基于emgucv读取视频文件并播放的用法&#xff08;百度文章名没有找到对象的文章地址&#xff0c;有兴趣的可以在微信中搜索该公众号并查看文章具体内容&#xff09;&#xff0c;本文学习并测试Emgucv播放视频文件的基本…

拼多多关键字搜索API-通过关键字获取拼多多商品列表商品价格商品id商品链接

拼多多根据关键词取商品列表 API 返回值说明 item_search-根据关键词取商品列表 公共参数 请求地址: pinduoduo/item_search 名称类型必须描述keyString是调用key&#xff08;必须以GET方式拼接在URL中&#xff09;secretString是调用密钥api_nameString是API接口名称&…

Mysql系列之命令行登录、连接工具登录、数据库表常用命令

登录与常用命令 连接工具登录命令行登录数据库1、查看数据库2、指定数据库3、查看当前数据库4、建库语句 数据表1、查看数据表2、查看表结构信息3、查看建表语句4、建表语句 连接工具登录 首先下载mysql连接工具&#xff0c;解压后直接打开软件&#xff0c;按以下步骤操作&…

☀️将大华摄像头画面接入Unity 【2】配置Unity接监控画面

一、前言 上一篇咱们将大华摄像头接入到电脑上了&#xff0c;接下来准备接入到unity画面。 接入到监控就涉及到各种视频流的格式rtsp、rtmp、m3u8。 Unity里有一些播放视频流的插件&#xff0c;主要的就是AVPro Video 和 UMP等&#xff0c;这次我用的是UMP 最好使用2.0.3版本…

顺序表详解(SeqList)

本文使用C语言进行顺序表的代码实现。 博主将使用代码和相关知识相结合的方式进行讲解&#xff0c;简单易懂&#xff0c;懵懂的大学生一听就会~ 顺序表是一种线性表的存储结构&#xff0c;它将数据元素存储在一段连续的存储空间中&#xff0c;每个元素占据一个存储单元&#x…

VSCODE中使用Django处理后端data和data models

链接&#xff1a; Python and Django tutorial in Visual Studio Code MVC的理解 在实际的程序中采用MVC的方式进行任务拆分。 Model&#xff08;模型&#xff09;负责封装应用程序的数据和业务逻辑部分。Model包含数据结构&#xff0c;数据处理逻辑以及相关的操作方法&#…

Camunda和SpringBoot的兼容版本

官网 https://docs.camunda.org/manual/7.15/user-guide/spring-boot-integration/version-compatibility/ Camunda和SpringBoot的兼容版本

安达发|APS生产排程的多机台产线详解

在生产管理中&#xff0c;APS&#xff08;高级计划与排程&#xff09;系统它可以帮助企业实现生产过程的优化和效率提升。特别是在多机台产线的生产环境中&#xff0c;APS系统的作用更加明显。本文将详细解析APS生产排程的多机台产线&#xff0c;包括允许使用的最大设备数&…

ai数字仿真辩论主持人提升用户体验

Ai虚拟主持人是元宇宙和AI人工智能技术在播音主持行业的重要应用&#xff0c;AI虚拟主持人能极大提升新闻资讯内容的精准度&#xff0c;改变单一的播报形式。 首先&#xff0c;AI虚拟主持人极大地提升了节目的制作效率和灵活性。传统主持人需要花费大量时间进行彩排和录制&…

【JGit】分支管理实践

本文紧接【JGit】简述及学习资料整理。 以下梳理了使用 JGit 进行 Git 操作的实践 JGit实践 主函数 public static void main(String[] args) throws Exception {String localDir "D:\\tmp\\git-test\\";String gitUrl "http://192.168.181.1:3000/root/g…

PFA容量瓶在半导体晶圆化学机械抛光中的用处是什么?

PFA容量瓶又称可溶性聚四氟乙烯容量瓶、特氟龙容量瓶容量瓶&#xff0c;有螺纹和插口两种可供选择&#xff0c;常用有10ml、25ml、50ml、100ml、250ml、500ml、1000ml规格 Teflon系列PFA容量瓶是一个透明的长颈瓶&#xff0c;瓶体为梨形&#xff0c;便于摇荡液体和刷洗。每一个…

Linux进程(一)信号-----信号产生

前言 在 Linux 中&#xff0c;进程具有独立性&#xff0c;进程在运行后可能 “放飞自我”&#xff0c;这是不利于管理的&#xff0c;于是需要一种约定俗成的方式来控制进程的运行&#xff0c;这就是 进程信号&#xff0c;本文将会从什么是进程信号开篇&#xff0c;讲述各种进程…

harmony 鸿蒙系统学习 安装ohpm报错 ohpm install failed

一. 安装配置 DevEco Studio 安装包时报错 execute ohpm install failed. Install task failed: ArkTS 3.2.12.5. Install ArkTS dependencies failed. 解决办法 找原因&#xff0c;首先&#xff0c;我的电脑中之前安装过node&#xff0c;也许是因为这个。&#xff08;其实…

Redis之缓存雪崩问题解决方案

文章目录 一、书接上文二、介绍三、解决方案1. 锁2. 不同的过期时间3. 缓存预热和定时任务 一、书接上文 Redis之缓存穿透问题解决方案实践SpringBoot3Docker 二、介绍 缓存雪崩&#xff0c;指大量的缓存失效&#xff0c;大量的请求又同时落在数据库。主要的一种诱因是key设…