当前位置: 首页 > news >正文

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.

使用的结构

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

上传下载模板

在这里插入图片描述

相关文章:

ABAP 导入Excel表示例程序

目录 ABAP 导入excel示例程序创建程序使用的结构上传下载模板 ABAP 导入excel示例程序 批量导入程序&#xff0c;需要使用到导入模板&#xff0c;首先需要创建程序&#xff0c;之后是需要创建excel导入模板&#xff0c;并且需要将excel导入模板上传到SAP系统里面&#xff0c;之…...

Spring之AOP源码解析(中)

前言 在上一篇文章中,我们讲解了Spring中那些注解可能会产生AOP动态代理,我们通过源码发现,完成AOP相关操作都和ProxyFactory这个类有密切关系,这一篇我们将围绕这个类继续解析 演示 作用 ProxyFactory采用策略模式生成动态代理对象,具体生成cglib动态代理还是jdk动态代理,…...

《Docker极简教程》--Docker卷和数据持久化--Docker卷的使用

一、基本操作 1.1 创建Docker卷 创建 Docker 卷是在 Docker 中管理持久化数据的重要步骤之一。通过 Docker 卷&#xff0c;可以将数据与容器解耦&#xff0c;实现数据的持久化存储&#xff0c;并且可以在容器之间共享数据。以下是创建 Docker 卷使用 docker volume create 命…...

【Logback】如何在项目中快速引入Logback日志?

目录 1、引入相关依赖或者 jar 包 2、使用logback日志 3、引入logback配置文件 4、打印logback内部状态信息 Logback 是 Java 社区中使用最广泛的日志框架之一。它是其前身 Log4j 的替代品。Logback 比所有现有的日志框架速度更快&#xff0c;占用空间更小&#xff0c;而且…...

【Linux从青铜到王者】 基础IO

本篇重点&#xff1a;文件描述符&#xff0c;重定向&#xff0c;缓冲区&#xff0c;磁盘结构&#xff0c;文件系统&#xff0c;inode理解文件的增删查改&#xff0c;查找一个文件为什么一定要有路径&#xff0c;动静态库&#xff0c;有的时候为什么找不到库&#xff0c;动态库的…...

C++之类作用域

目录 1、全局作用域 2、类作用域 2.1、设计模式之Pimpl 2.2、单例模式的自动释放 2.2.0、检测内存泄漏的工具valgrind 2.2.1、可以使用友元形式进行设计 2.2.2、内部类加静态数据成员形式 2.2.3、atexit方式进行 2.2.4、pthread_once形式 作用域可以分为类作用域、类名…...

SpringCloud Gateway网关 全局过滤器[AntPathMatcher 某些路径url禁止访问] 实现用户鉴权

前提&#xff1a;先保证Gateway网关项目 和 Nacos注册中心 等可以正常访问和调用&#xff0c;搭建方法可查看博文SpringCloud Gateway网关 项目创建 及 整合Nacos开发_spring gateway如何设置工程名称-CSDN博客 类似的全局鉴权方案&#xff0c;参考如下&#xff1a; SpringClo…...

ELK介绍以及搭建

基础环境 hostnamectl set-hostname els01 hostnamectl set-hostname els02 hostnamectl set-hostname els03 hostnamectl set-hostname kbased -i s/SELINUXenforcing/SELINUXdisabled/ /etc/selinux/config systemctl stop firewalld & systemctl disable firewalld# 安…...

Spring中的ApplicationContext.publishEvent

简单理解 其实就是监听处理。比如找工作平台上&#xff0c;雇主 employer 发布自己的雇佣条件&#xff0c;目的是平台中有符合条件的求职者时&#xff0c;及时向雇主推荐。求职者发布简历&#xff0c;当平台发现某个求职者比较符合条件&#xff0c;就触发被动&#xff0c;推荐…...

jackson、gson、fastjson和json-lib四种主流json解析框架对比

一、四种框架的介绍和对比 在Java中&#xff0c;Jackson、Gson、Fastjson和json-lib都是流行的JSON解析框架&#xff0c;它们各自有一些特点和优势。下面是对它们进行简要介绍和对比&#xff1a; 1.1 介绍 1&#xff09; Jackson: Jackson是由FasterXML开发的一个高性能的J…...

已解决:IDEA中@Autowired自动注入MyBatis Mapper报红警告的几种解决方法

今天在使用 IDEA 使用 MyBatis 的时候遇到了这种情况&#xff1a; 可以看到 userMapper 下有个红色的波浪警告&#xff0c;虽然代码没有任何问题&#xff0c;能正常运行&#xff0c;但是这个红色警告在这里杵着确实让人很窝心。 于是我在网上找了找&#xff0c;最终明白了原因…...

在jar里限制指定的包名才可调用(白名单)。

1. 在jar包中定义一个接口&#xff0c;例如 用于检查传入的hash值是否匹配预设的值。 2. 在调用接口的地方&#xff0c;获取当前应用的hash值。 3. 将当前应用的hash值与预设的值进行比较&#xff0c;如果匹配&#xff0c;则允许调用接口&#xff1b;否则&#xff0c;拒绝调用。…...

python 提取PDF文字

使用pdfplumber&#xff0c;不能提取扫描的pdf和插入的图片。 import pdfplumberfile_path rD:\UserData\admindesktop\官方文档\1903_Mesh-Models-Overview_FINAL.pdf with pdfplumber.open(file_path) as pdf:page pdf.pages[0]print(page.extract_text()) # 所以文字prin…...

电气机械5G智能工厂数字孪生可视化平台,推进电气机械行业数字化转型

电气机械5G智能工厂数字孪生可视化平台&#xff0c;推进电气机械行业数字化转型。随着科技的不断发展&#xff0c;数字化转型已经成为各行各业发展的重要趋势。电气机械行业作为传统制造业的重要组成部分&#xff0c;也面临着数字化转型的挑战和机遇。为了更好地推进电气机械行…...

C# (WebApi)整合 Swagger

SpringBoot-整合Swagger_jboot整合swagger-CSDN博客 C# webapi 也可以整合Swagger webapi运行其实有个自带的HELP页面 但是如果觉得UI不好看&#xff0c;且没办法显示方法注释等不方便的操作&#xff0c;我们也可以整合Swagger 一、使用NuGet控制台安装Swagger 在菜单中选择…...

导入excel某些数值是0

目录 导入excel某些数值是0数据全部都是0原因解决 部分数据是0原因解决 导入excel某些数值是0 数据全部都是0 有一列“工单本月入库重量”全部的数据都是0 原因 展示的时候&#xff0c;展示的字段和内表需要展示的字段不一致&#xff0c;导致显示的是0。 解决 修改展示的字…...

wo-gradient-card是一款采用uniapp实现的透明辉光动画卡片

采用uniapp-vue3实现&#xff0c;透明辉光动画卡片&#xff0c;卡片内容包含标签、标题、副标题、图片 支持H5、微信小程序&#xff08;其他小程序未测试过&#xff0c;可自行尝试&#xff09; 可用于参考学习 可到插件市场下载尝试&#xff1a; https://ext.dcloud.net.cn/plu…...

Spark: a little summary

转眼写spark一年半了&#xff0c;从之前写机器学习组件、做olap到后面做图计算&#xff0c;一直都是用的spark&#xff0c;惭愧的是没太看过里面的源码。这篇文章的目的是总结一下Spark里面比较重要的point&#xff0c;重点部分会稍微看一下源代码&#xff0c;因为spark是跟cli…...

018—pandas 生成笛卡尔积排列组合合并多列字符串数据

思路&#xff1a; 本需求需要将给定的几列数据&#xff0c;生成一个排列组合形式的数据列&#xff0c;利用到 Pandas 多层索引生成的笛卡尔积的方法。 二、使用步骤 1.引入库 代码如下&#xff08;示例&#xff09;&#xff1a; import pandas as pd2.读入数据 代码如下&…...

【算法与数据结构】链表、哈希表、栈和队列、二叉树(笔记二)

文章目录 四、链表理论五、哈希表理论五、栈和队列理论5.1 单调栈 六、二叉树理论6.1 树的定义6.2 二叉树的存储方式6.3 二叉树的遍历方式6.4 高度和深度 最近博主学习了算法与数据结构的一些视频&#xff0c;在这个文章做一些笔记和心得&#xff0c;本篇文章就写了一些基础算法…...

bugku3

前女友 md5 进去又是讴歌乱进的东西 源代码 看到code.txt,访问一下 <?php if(isset($_GET[v1]) && isset($_GET[v2]) && isset($_GET[v3])){$v1 $_GET[v1];$v2 $_GET[v2];$v3 $_GET[v3];if($v1 ! $v2 && md5($v1) md5($v2)){if(!strcmp($v3,…...

相机的白平衡

相机的白平衡是指相机根据拍摄环境的光源色温&#xff0c;调整图像中白色看起来应该是白色的功能。白平衡的设置对于确保图像中的颜色准确性非常重要&#xff0c;因为不同光源的色温会使白色看起来有不同的色调。 通常&#xff0c;相机提供了一些预设的白平衡模式&#xff0c;…...

刷题日记-Day2- Leedcode-977. 有序数组的平方,209. 长度最小的子数组,59. 螺旋矩阵 II-Python实现

刷题日记Day2 977 有序数组的平方209. 长度最小的子数组59. 螺旋矩阵 II 977 有序数组的平方 链接&#xff1a;https://leetcode.cn/problems/squares-of-a-sorted-array/description/ 给你一个按 非递减顺序 排序的整数数组 nums&#xff0c;返回 每个数字的平方 组成的新数组…...

Linux命令-chcon命令(修改对象(文件)的安全上下文)

说明 chcon命令 是修改对象&#xff08;文件&#xff09;的安全上下文&#xff0c;比如&#xff1a;用户、角色、类型、安全级别。也就是将每个文件的安全环境变更至指定环境。使用 --reference 选项时&#xff0c;把指定文件的安全环境设置为与参考文件相同。chcon命令位于 /…...

【漏洞复现】大华DSS视频管理系统信息泄露漏洞

Nx01 产品简介 大华DSS数字监控系统是一个在通用安防视频监控系统基础上设计开发的系统&#xff0c;除了具有普通安防视频监控系统的实时监视、云台操作、录像回放、报警处理、设备治理等功能外&#xff0c;更注重用户使用的便利性。 Nx02 漏洞描述 大华DSS视频管理系统存在信…...

websocket了解下

websocket请求长啥样 GET /chat HTTP/1.1 Host: example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ Sec-WebSocket-Version: 13 啥是websocket websocket是http的一种&#xff0c;服务器可以主动向客户端推送信息&#xff0c;…...

docker install private registry 【docker 安装 registry 仅证书认证】

预备条件&#xff1a; 安装docker 我们设定镜像仓库域名为registry01.dev.com 配置/etc/hosts 192.168.23.51 registry01.dev.com安装 registry #!/bin/bashreg_ip$1 reg_n$2 reg_port$3if [ $# -eq 0 ]; thenecho "Usage: $0 [reg_ip] [registry_name]"echo &q…...

JavaWeb——004Maven SpringBootWeb入门

一、Maven 1、什么是maven&#xff1f; 2、Maven的作用是什么&#xff1f;&#xff08;3种&#xff09; 1.1、方便的依赖管理 依赖管理&#xff1a;有了Maven&#xff0c;我们就不用再手动导入Jar包了&#xff0c;我们只需要在配置文件当中&#xff0c;简单描述一下项目所需要…...

数据结构与算法-常用排序算法

一、常用排序说明 当涉及排序算法时&#xff0c;理解每个算法的工作原理、时间复杂度和空间复杂度是至关重要的。下面对常用排序算法进行详细说明&#xff1a; 1、冒泡排序&#xff08;Bubble Sort&#xff09;&#xff1a; 工作原理&#xff1a;比较相邻的元素并交换&am…...

链表之“无头单向非循环链表”

目录 ​编辑 1.顺序表的问题及思考 2.链表 2.1链表的概念及结构 2.2无头单向非循环链表的实现 1.创建结构体 2.单链表打印 3.动态申请一个节点 3.单链表尾插 4.单链表头插 5.单链表尾删 6.单链表头删 7.单链表查找 8.单链表在pos位置之前插入x 9.单链表删除pos位…...