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_changedFOR EVENT data_changed OF cl_gui_alv_gridIMPORTING er_data_changed,handle_data_changed_finishedFOR EVENT data_changed_finished OF cl_gui_alv_gridIMPORTINGe_modifiedet_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_dialogEXPORTING
*        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          =CHANGINGfile_table              = lt_filetablerc                      = lv_rc
*        user_action             =
*        file_encoding           =EXCEPTIONSfile_open_dialog_failed = 1cntl_error              = 2error_no_gui            = 3not_supported_by_gui    = 4OTHERS                  = 5.READ TABLE lt_filetable INTO ls_filetable INDEX 1.IF sy-subrc <> 0.
*     Implement suitable error handling hereENDIF.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 w3objidu_file_name TYPE string.DATA: ls_key TYPE wwwdatatab,lv_filename TYPE string,lv_path TYPE string,lv_fullpath TYPE string."判断模板是否存在SELECT SINGLE * FROM wwwdataWHERE relid EQ 'MI'AND objid EQ @u_objidINTO 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_dialogEXPORTING
*      window_title              =default_extension         = cl_gui_frontend_services=>filetype_exceldefault_file_name         =  u_file_name
*      with_encoding             =
*      file_filter               =
*      initial_directory         =
*      prompt_on_overwrite       = 'X'CHANGINGfilename                  = lv_filenamepath                      = lv_pathfullpath                  = lv_fullpath
*      user_action               =
*      file_encoding             =EXCEPTIONScntl_error                = 1error_no_gui              = 2not_supported_by_gui      = 3invalid_default_file_name = 4OTHERS                    = 5.IF sy-subrc <> 0.
*   Implement suitable error handling hereENDIF.CHECK lv_fullpath NE ''.
*   下载SMW0模版CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'EXPORTINGkey = ls_keydestination = 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 .
*   添加前导0LOOP 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'. "将类型设置为NENDIF.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 TABLEUSING    u_file  TYPE rlgrap-filenameu_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'EXPORTINGfilename          = u_filei_begin_col       = 1i_begin_row       = 2i_end_col         = 99i_end_row         = 65536TABLESintern            = lt_internEXCEPTIONSinconsistent_parameters   = 1upload_ole                = 2OTHERS                    = 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,&4MESSAGE 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,&4MESSAGE 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,&4MESSAGE 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】字段会被打上Xgs_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_ACTIVEi_structure_name       = 'ZFI_MFWB'
*     I_CLIENT_NEVER_DISPLAY = 'X'
*     I_BYPASSING_BUFFER     = I_BYPASSING_BUFFER
*     I_INTERNAL_TABNAME     = I_INTERNAL_TABNAMECHANGINGct_fieldcat            = gt_fieldcatEXCEPTIONSinconsistent_interface = 1program_error          = 2OTHERS                 = 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 hereENDIF.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'EXPORTINGi_callback_program                = sy-repidi_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_layoutit_fieldcat_lvc                   = gt_fieldcati_save                            = 'U'is_variant                        = gs_variantit_events                         = lt_event
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           = E_EXIT_CAUSED_BY_CALLER
*     ES_EXIT_CAUSED_BY_USER            = ES_EXIT_CAUSED_BY_USERTABLESt_outtab                          = gt_outputEXCEPTIONSprogram_error                     = 1OTHERS                            = 2.IF sy-subrc <> 0.
* Implement suitable error handling hereENDIF.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-ucommu_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_ADAPTERIMPORTINGe_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'IMPORTINGe_grid = lr_grid.lr_grid->get_frontend_layout(IMPORTINGes_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(EXPORTINGis_stable = ls_stableEXCEPTIONSfinished = 1OTHERS = 2 ).IF sy-subrc <> 0.MESSAGE ID sy-msgidTYPE sy-msgtyNUMBER sy-msgnoWITH 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_titleu_questionCHANGING ch_confirm.DATA: lv_answer TYPE char1.CLEAR: ch_confirm.CLEAR: lv_answer.CALL FUNCTION 'POPUP_TO_CONFIRM'EXPORTINGtitlebar              = u_titletext_question         = u_questiondefault_button        = '2'display_cancel_button = ''IMPORTINGanswer                = lv_answerEXCEPTIONStext_not_found        = 1OTHERS                = 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'EXPORTINGname                  = ch_output-iconIMPORTINGresult                = ch_output-iconEXCEPTIONSicon_not_found        = 1outputfield_too_short = 2OTHERS                = 3.IF sy-subrc <> 0.ENDIF.
ENDFORM.

使用的结构

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

上传下载模板

在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2023 re:Invent 用 PartyRock 10 分钟构建你的 AI 应用

前言 一年一度的亚马逊云科技的 re:Invent 可谓是全球云计算、科技圈的狂欢&#xff0c;每次都能带来一些最前沿的方向标&#xff0c;这次也不例外。在看完一些 keynote 和介绍之后&#xff0c;我也去亲自体验了一些最近发布的内容。其中让我感受最深刻的无疑是 PartyRock 了。…

【数据结构】每天五分钟,快速入门数据结构(二)——链表

目录 一 构建一个单向链表 二 特点 三 时间复杂度 四 相关算法 1.判断链表是否成环及成环位置 2.链表反转 五 Java中的LinkedList 类 1.使用 2.LinkedList 方法 一 构建一个单向链表 // 设计链表结构class ListNode {int val;ListNode next;ListNode(){}ListNode(int…

LeetCode 2583.二叉树中的第 K 大层和:层序遍历 + 排序

【LetMeFly】2583.二叉树中的第 K 大层和&#xff1a;层序遍历 排序 力扣题目链接&#xff1a;https://leetcode.cn/problems/kth-largest-sum-in-a-binary-tree/ 给你一棵二叉树的根节点 root 和一个正整数 k 。 树中的 层和 是指 同一层 上节点值的总和。 返回树中第 k …

Oracle迁移到mysql-表结构的坑

1.mysql中id自增字段必须是整数类型 id BIGINT AUTO_INCREMENT not null, 2.VARCHAR2改为VARCHAR 3.NUMBER(16)改为decimal(16,0) 4.date改为datetime 5.mysql范围分区必须int格式&#xff0c;不能list类型 ERROR 1697 (HY000): VALUES value for partition …

【Java】RestClient的使用

RestClient的使用 先导入Maven坐标&#xff0c;要和elasticsearch和kibana的版本保持一致 <dependency><groupId>org.elasticsearch.client</groupId><artifactId>elasticsearch-rest-high-level-client</artifactId><version>7.12.1<…

JAVA工程师面试专题-Mysql篇

一、基础 1、mysql可以使用多少列创建索引&#xff1f; 16 2、mysql常用的存储引擎有哪些 存储引擎Storage engine&#xff1a;MySQL中的数据、索引以及其他对象是如何存储的&#xff0c;是一套文件系统的实现。常用的存储引擎有以下&#xff1a; Innodb引擎&#xff1a;In…

单片机04__基本定时器__毫秒微秒延时

基本定时器__毫秒微秒延时 基本定时器介绍&#xff08;STM32F40x&#xff09; STM32F40X芯片一共包含14个定时器&#xff0c;这14个定时器分为3大类&#xff1a; 通用定时器 10个 TIM9-TIM1和TIM2-TIM5 具有基本定时器功能&#xff0c; 还具有输入捕获&#xff0c;输出比较功…

Django——ORM增删改查

基本对象 model.objects 创建数据 可以通过django编写的命令行方式快捷创建数据 python manage.py shell 如果对模型层有任何修改都需要重启shell&#xff0c;否则操作容易出错 在shell中我们需要先引入我们的模型&#xff0c;如from bookstore.models import Book 然后通过…

【接口加密】Java中的接口加密实践

目录 2.1 Java加密相关的基础知识 2.1.1 Java加密框架概述 2.1.2 Java加密常用算法介绍 2.2 Java中的接口加密实现 2.2.1 使用Java加密标准&#xff08;JCE&#xff09;实现接口加密 2.2.2 通过Bouncy Castle库实现接口加密 2.2.3 第三方加密工具的集成与应用 2.3 Java…

Uniapp-小程序简单的时间选择组件-年月日时分

文章目录 前言一、组件效果二、组件代码使用 总结 前言 uniapp小程序开发系列。本文实现一个简单时间选择控件。uniapp用个心仪时间控件真的麻烦。官方给得要么年月日&#xff0c;要么时分。产品只要年月日时分。这该怎么玩。旧项目没有引入ui框架&#xff0c;我也不想去引入&…

如何连接ACL认证的Redis

点击上方蓝字关注我 应用程序连接开启了ACL认证的Redis时与原先的方式有差别&#xff0c;本文介绍几种连接开启ACL认证的Redis的Redis的方法。 对于RedisACL认证相关内容&#xff0c;可以参考历史文章&#xff1a; Redis权限管理体系(一&#xff09;&#xff1a;客户端名及用户…

【二十七】【C++】二叉树练习

606. 根据二叉树创建字符串 给你二叉树的根节点 root &#xff0c;请你采用前序遍历的方式&#xff0c;将二叉树转化为一个由括号和整数组成的字符串&#xff0c;返回构造出的字符串。 空节点使用一对空括号对 "()" 表示&#xff0c;转化后需要省略所有不影响字符串与…

【无刷电机学习】各种电机优势比较

目录 0 参考出处 1 有刷与无刷比较 2 交流与直流比较 3 内转子与外转子比较 4 Delta型与Y型定子绕向比较 5 低压BLDC的一些优点 0 参考出处 【仅作自学记录&#xff0c;不出于任何商业目的。如有侵权&#xff0c;请联系删除&#xff0c;谢谢&#xff01;】 维基百科…

C++力扣题目139--单词拆分 198--打家劫舍 213--打家劫舍II 337打家劫舍III

139.单词拆分 力扣题目链接(opens new window) 给定一个非空字符串 s 和一个包含非空单词的列表 wordDict&#xff0c;判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 说明&#xff1a; 拆分时可以重复使用字典中的单词。 你可以假设字典中没有重复的单词。 …

Unity中URP实现水体效果(水的深度)

文章目录 前言一、搭建预备场景1、新建一个面片&#xff0c;使其倾斜一个角度&#xff0c;来模拟水底和岸边的效果2、随便创建几个物体&#xff0c;作为与水面接触的物体3、再新建一个面片&#xff0c;作为水面 二、开始编写水体的Shader效果1、新建一个URP基础Shader2、把水体…

knife4j springboot3使用

简介 在日常开发中&#xff0c;写接口文档是我们必不可少的&#xff0c;而Knife4j就是一个接口文档工具&#xff0c;可以看作是Swagger的升级版&#xff0c;但是界面比Swagger更好看&#xff0c;功能更丰富 使用 我使用的是springboot3.2.3 knife4j 4.3.0,knife4j 4.4版本有…

自动化操作读写Excel —— xlrd 和 xlwt 模块参数说明与代码实战【第95篇—自动化操作读写Excel 】

自动化操作读写Excel —— xlrd 和 xlwt 模块参数说明与代码实战 在日常工作中&#xff0c;Excel表格是不可或缺的数据处理工具。为了提高工作效率&#xff0c;Python中的xlrd和xlwt模块为我们提供了强大的功能&#xff0c;使得自动化操作Excel变得更加简便。本文将介绍xlrd和…

利用nginx内部访问特性实现静态资源授权访问

在nginx中&#xff0c;将静态资源设为internal&#xff1b;然后将前端的静态资源地址改为指向后端&#xff0c;在后端的响应头部中写上静态资源地址。 近期客户对我们项目做安全性测评&#xff0c;暴露出一些安全性问题&#xff0c;其中一个是有些静态页面&#xff08;*.html&…

线性代数:向量、张量、矩阵和标量

线性代数&#xff1a;向量、张量、矩阵和标量 背景 在线性代数中&#xff0c;向量、张量、矩阵和标量都属于基础概念&#xff0c;特别是最近AI的爆火&#xff0c;向量和张量的概念也越来越普及&#xff0c;本文将介绍下这些基本概念。 1. 标量&#xff08;Scalar&#xff0…

解密与恢复:应对. helper勒索病毒的实用建议

引言&#xff1a; 近年来&#xff0c;勒索病毒已成为网络安全领域的一大威胁&#xff0c;而其中一种名为.helper的勒索病毒备受关注。本文将介绍.helper勒索病毒的特点、数据恢复方法以及预防措施&#xff0c;帮助读者更好地理解和防范这种恶意软件的攻击。如不幸感染这个勒索…