代码demo-内部订单批量投料

为了简化用户操作,开发内部订单批量投料功能
在这里插入图片描述
用户可以批量上传,或者选择对应的物料,输入库位和内部订单号后进行过账操作
在这里插入图片描述
对用户选择的内部订单做校验,内部订单是否正确
在这里插入图片描述内部订单的公司是否和工厂对应的公司一致等等
在这里插入图片描述

下面展示ZPPA0011代码

REPORT ZPPA0011 MESSAGE-ID zpp..INCLUDE ZPPA0011_TOP.
INCLUDE ZPPA0011_FRM.INITIALIZATION.DATA but_down(255) TYPE c.CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本EXPORTINGname   = icon_xls   " 按钮的图片的名字text   = '下载模板'                   "按钮的文本
*     info   = '请下载模板来批导入数据'IMPORTINGresult = but_downEXCEPTIONSOTHERS = 0.sscrfields-functxt_01 = but_down.AT SELECTION-SCREEN.CASE sscrfields-ucomm.WHEN 'FC01'.PERFORM frm_down_template.ENDCASE.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.PERFORM frm_get_file USING p_file.START-OF-SELECTION.PERFORM frm_run."主程序

下面展示ZPPA0011_TOP代码

TABLES: sscrfields.
TABLES:mara,mseg.
TYPE-POOLS: icon, slis.DATA : BEGIN OF itab_sdata OCCURS 0,werks TYPE string, "工厂lgort TYPE string, "库位aufnr TYPE string, "内部订单matnr TYPE string, "物料代码menge TYPE string, "数量END OF itab_sdata."ALV显示数据结构
DATA : BEGIN OF itab_data OCCURS 0,sel(1),"选择icon         TYPE icon_d,     "状态标识bukrs        TYPE coas-bukrs, "公司butxt        TYPE t001-butxt,werks        TYPE marc-werks, "工厂name1        TYPE name1,matnr        TYPE marc-matnr, "物料编码maktx        TYPE makt-maktx, "物料描述meins        TYPE stko-bmein, "单位labst        TYPE mard-labst, "库存量bdmng        TYPE afpo-wemng, "已投料量menge        TYPE stpo-menge, "本次录入数量lgort        TYPE stpo-lgort, "库位lgobe        TYPE goitem-lgobe, "库位描述budat        TYPE mkpf-budat, "过账日期xlokez       TYPE char1, "冲销标识type(1),message(100),"处理结果aufnr        TYPE afpo-aufnr, "内部订单ktext        TYPE coas-ktext, "内部订单描述field_style  TYPE lvc_t_styl, " 为内表添加设置编辑状态所需的字段END OF itab_data.*-------- ALV 结构设置
DATA: wa_fieldcat TYPE  lvc_s_fcat,it_fieldcat TYPE  lvc_t_fcat,g_layout    TYPE slis_layout_alv,g_title     TYPE lvc_title,pos         TYPE i,l_field     TYPE slis_fieldcat_alv,   "字段列结构l_fieldcat  TYPE slis_t_fieldcat_alv, "字段列内表l_status_01 TYPE slis_formname VALUE 'L_STATUS_01'.DATA: gt_events TYPE slis_t_event,gs_event  LIKE LINE OF gt_events.
DATA: gt_event_exit TYPE slis_t_event_exit WITH HEADER LINE.DATA:lv_gjahr TYPE gjahr,lv_monat TYPE monat,lv_poper TYPE poper,lv_begda TYPE d,lv_endda TYPE d.DEFINE add_col.CLEAR wa_fieldcat.ADD 1 TO pos.wa_fieldcat-col_pos = pos.wa_fieldcat-fieldname = &1.wa_fieldcat-ref_field = &2.wa_fieldcat-ref_table = &3.wa_fieldcat-scrtext_m = &4.wa_fieldcat-tabname = &5.wa_fieldcat-outputlen = &6.wa_fieldcat-f4availabl = &7.wa_fieldcat-hotspot = &8.wa_fieldcat-checkbox = &9.IF wa_fieldcat-fieldname = 'MATNR'.wa_fieldcat-edit_mask = '==ALPHA'."隐藏前导零ENDIF.IF wa_fieldcat-fieldname = 'MENGE'.wa_fieldcat-edit = 'X'.wa_fieldcat-emphasize = 'C510'.ENDIF.IF wa_fieldcat-fieldname = 'AUFNR'.wa_fieldcat-edit = 'X'.wa_fieldcat-emphasize = 'C510'.ENDIF.IF wa_fieldcat-fieldname = 'LGORT'.
*     wa_fieldcat-edit = 'X'.wa_fieldcat-outputlen = '6'.ENDIF.wa_fieldcat-scrtext_l = wa_fieldcat-scrtext_m.wa_fieldcat-scrtext_s = wa_fieldcat-scrtext_m.wa_fieldcat-coltext   = wa_fieldcat-scrtext_m.APPEND wa_fieldcat TO it_fieldcat.
END-OF-DEFINITION.CLASS lcl_event_receiver DEFINITION DEFERRED.DATA: go_events_receiver TYPE REF TO lcl_event_receiver.
*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.PUBLIC SECTION.METHODS:handle_data_changedFOR EVENT data_changed OF cl_gui_alv_gridIMPORTING er_data_changed.
ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------
CLASS lcl_event_receiver IMPLEMENTATION.METHOD handle_data_changed.PERFORM handle_data_changed USING er_data_changed.ENDMETHOD.                    "HANDLE_BUTTON_CLICK
ENDCLASS .                    "lcl_event_receiver IMPLEMENTATIONTABLES afpo.SELECTION-SCREEN:FUNCTION KEY 1.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-020.PARAMETERS:p_werks  TYPE  marc-werks.PARAMETERS:p_budat  TYPE matdoc-budat DEFAULT sy-datum.PARAMETERS:p_file   TYPE rlgrap-filename MODIF ID m2. "上传路径PARAMETERS:p_aufnr  TYPE aufk-aufnr      MODIF ID m1.SELECT-OPTIONS: s_mtart FOR mara-mtart   MODIF ID m1.SELECT-OPTIONS: s_matnr FOR mara-matnr   MODIF ID m1.SELECT-OPTIONS: s_lgort FOR mseg-lgort   MODIF ID m1.
SELECTION-SCREEN:END OF BLOCK b1.SELECTION-SCREEN: BEGIN OF BLOCK a1 WITH FRAME TITLE TEXT-010.SELECTION-SCREEN BEGIN OF LINE.SELECTION-SCREEN POSITION 5.PARAMETERS : r1 RADIOBUTTON GROUP grp DEFAULT 'X' USER-COMMAND sele.SELECTION-SCREEN COMMENT 10(12) TEXT-011 FOR FIELD r1.SELECTION-SCREEN POSITION 30.PARAMETERS : r2 RADIOBUTTON GROUP grp.SELECTION-SCREEN COMMENT 35(12) TEXT-012 FOR FIELD r2.SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN: END OF BLOCK a1.AT SELECTION-SCREEN OUTPUT.LOOP AT SCREEN ."屏幕组CASE screen-group1.WHEN 'M1'.IF r1 EQ 'X' .screen-active = 0.                "设置屏幕隐藏ELSE .screen-active = 1.                "设置屏幕显示ENDIF .WHEN 'M2'.IF r1 EQ 'X' .screen-active = 1.                "设置屏幕隐藏ELSE .screen-active = 0.                "设置屏幕显示ENDIF .ENDCASE .MODIFY SCREEN .                        "修改选择屏幕属性ENDLOOP .

下面展示ZPPA0011_FRM代码

FORM frm_run .PERFORM frm_get_data.PERFORM frm_display_data."展示数据
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .REFRESH itab_data[]."获取日期PERFORM frm_get_date.IF r1 = 'X '.PERFORM frm_get_from_excel."从EXCEL数据中读取ELSE.PERFORM frm_get_from_database."读取有库存数据并展示ENDIF.IF itab_data[] IS INITIAL.MESSAGE '没有满足条件的记录' TYPE 'S'.STOP.ENDIF.ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_display_data .REFRESH: it_fieldcat.CLEAR g_layout.DATA: x_layout TYPE lvc_s_layo.*  g_layout-zebra       = 'X'.   "ALV行的颜色间隔更换(间隔色带)x_layout-stylefname  = 'FIELD_STYLE'. " 将内表中的字段名存入显示格式x_layout-zebra = 'X'.   "ALV行的颜色间隔更换(间隔色带)add_col 'SEL'        space space '选择'                   'ITAB_DATA' '3' space 'X'   'X'.add_col 'ICON'       space space '状态'                   'ITAB_DATA' '4' space space space.add_col 'NAME1'      'NAME1'  'GOITEM'  '工厂名称'        'ITAB_DATA' '15' space space space.add_col 'MAKTX'      space space '物料描述'               'ITAB_DATA' '20' space space space.add_col 'BDMNG'     space space '本月已投料数量'          'ITAB_DATA' '8' space space space.add_col 'MEINS'      space space '单位'                   'ITAB_DATA' '4' space space space.add_col 'LABST'      space space '当前库存'               'ITAB_DATA' '8' space space space.add_col 'MENGE'      'MENGE'  'GOITEM'    '领用数量'      'ITAB_DATA' '10' space space space.add_col 'LGORT'      'LGORT'  'GOITEM'   '库位代码'       'ITAB_DATA' '4' space space space.add_col 'LGOBE'      'LGOBE'  'GOITEM'   '库位描述'       'ITAB_DATA' '10' space space space.add_col 'AUFNR'      'AUFNR'  'AUFK'     '内部订单'       'ITAB_DATA' '12' space space space.add_col 'KTEXT'      space space '内部订单描述'           'ITAB_DATA' '20' space space space.add_col 'XLOKEZ'     space space '冲销'                   'ITAB_DATA' '3' space 'X'   'X'.add_col 'MESSAGE'    space space '处理消息'               'ITAB_DATA' '40' space space space.add_col 'WERKS'      'WERKS'  'GOITEM'  '工厂代码'        'ITAB_DATA' '4' space space space.add_col 'BUKRS'      space space '公司代码'               'ITAB_DATA' '4' space space space.add_col 'BUTXT'      space space '公司名称'               'ITAB_DATA' '14' space space space.add_col 'MATNR'      space space '物料代码'               'ITAB_DATA' '10' space space space.gs_event-name = 'CALLER_EXIT'.gs_event-form = 'FRM_CELL_CHANGE'.APPEND gs_event TO gt_events.CLEAR gs_event.CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'EXPORTINGi_callback_program       = sy-repidi_callback_pf_status_set = 'L_STATUS100'i_callback_user_command  = 'FRM_USER_COMMAND'is_layout_lvc            = x_layoutit_fieldcat_lvc          = it_fieldcati_save                   = 'A'it_events                = gt_events              "注册事件TABLESt_outtab                 = itab_dataEXCEPTIONSprogram_error            = 1OTHERS                   = 2.IF sy-subrc NE 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDFORM.FORM l_status100 USING extab TYPE slis_t_extab.SET  PF-STATUS  'MAIN'.
ENDFORM.                    "L_STATUS100*&---------------------------------------------------------------------*
*&      Form  frm_user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.DATA: ref TYPE REF TO cl_gui_alv_grid.CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'IMPORTINGe_grid = ref.CALL METHOD ref->check_changed_data.CASE r_ucomm.WHEN '&IC1'.IF rs_selfield-fieldname = 'SEL'.READ TABLE itab_data INDEX rs_selfield-tabindex.IF itab_data-sel = ''.itab_data-sel = 'X'.ELSE.itab_data-sel = ''.ENDIF.MODIFY itab_data INDEX rs_selfield-tabindex.CLEAR itab_data.ENDIF.IF rs_selfield-fieldname = 'XLOKEZ'.READ TABLE itab_data INDEX rs_selfield-tabindex.IF itab_data-xlokez = ''.itab_data-xlokez = 'X'.ELSE.itab_data-xlokez = ''.ENDIF.MODIFY itab_data INDEX rs_selfield-tabindex.CLEAR itab_data.ENDIF.WHEN 'ALL'.itab_data-sel = 'X'.MODIFY itab_data FROM itab_data  TRANSPORTING sel   WHERE sel = '' .WHEN 'SAL'.itab_data-sel = ''.MODIFY itab_data FROM itab_data  TRANSPORTING sel   WHERE sel = 'X' .WHEN '&IMP'.PERFORM frm_excute.WHEN '&QUERY'.PERFORM frm_query.WHEN '&REF'.PERFORM frm_get_data.WHEN '&CHG'.PERFORM frm_change_date.ENDCASE.PERFORM frm_re_alv.
ENDFORM.                    "FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form frm_excute
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_excute .DATA:ls_goodsmvt_head TYPE bapi2017_gm_head_01.DATA:lt_goodsmvt_item    TYPE TABLE OF bapi2017_gm_item_create,ls_goodsmvt_item    TYPE bapi2017_gm_item_create,lt_extensionin      TYPE TABLE OF bapiparex,ls_extensionin      TYPE bapiparex,lv_materialdocument TYPE bapi2017_gm_head_ret-mat_doc,lv_matdocumentyear  TYPE bapi2017_gm_head_ret-doc_year,lv_matzeile         TYPE mseg-zeile,lv_goodsmvt_code    TYPE bapi2017_gm_code.DATA:lt_return TYPE TABLE OF bapiret2,ls_return LIKE LINE OF lt_return.DATA ls_xmseg  TYPE bapi_te_xmseg.DATA lv_index TYPE sy-tabix.LOOP AT itab_data WHERE sel = 'X' AND type NE 'S'.IF itab_data-menge =< 0.itab_data-icon = icon_red_light.itab_data-type = 'E'.itab_data-message = '请填写数量'.MODIFY itab_data.CLEAR itab_data.CONTINUE.ENDIF.IF itab_data-lgort IS INITIAL.itab_data-icon = icon_red_light.itab_data-type = 'E'.itab_data-message = '请填写库位'.MODIFY itab_data.CLEAR itab_data.CONTINUE.ENDIF.CLEAR lv_index.lv_index = lv_index + 1.CLEAR:ls_goodsmvt_item, ls_goodsmvt_head,ls_return,ls_extensionin.REFRESH:lt_return,lt_goodsmvt_item,lt_extensionin."赋值逻辑ls_goodsmvt_head-pstng_date = p_budat."记账日期ls_goodsmvt_head-doc_date   = sy-datum."凭证日期lv_goodsmvt_code = '03'.ls_goodsmvt_item-material   = itab_data-matnr."物料代码ls_goodsmvt_item-plant      = itab_data-werks."工厂代码ls_goodsmvt_item-stge_loc   = itab_data-lgort."库位ls_goodsmvt_item-orderid    = itab_data-aufnr.ls_goodsmvt_item-entry_qnt  = itab_data-menge."数量"冲销处理逻辑IF itab_data-xlokez IS NOT INITIAL .ls_goodsmvt_item-move_type = '262'.ELSE.ls_goodsmvt_item-move_type  = '261'.ENDIF.APPEND ls_goodsmvt_item TO lt_goodsmvt_item.CLEAR: ls_goodsmvt_item.CALL FUNCTION 'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header  = ls_goodsmvt_headgoodsmvt_code    = lv_goodsmvt_codeIMPORTINGmaterialdocument = lv_materialdocumentmatdocumentyear  = lv_matdocumentyearTABLESgoodsmvt_item    = lt_goodsmvt_itemextensionin      = lt_extensioninreturn           = lt_return.READ TABLE lt_return INTO ls_return INDEX 1.IF ls_return-type = 'E' OR ls_return-type = 'A'.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.itab_data-type = 'E'.itab_data-icon = icon_red_light.itab_data-message = |处理失败:|.LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.itab_data-message = |{ itab_data-message },{ ls_return-message }|.ENDLOOP.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.itab_data-type = 'S'.itab_data-icon = icon_green_light.itab_data-message = |录入成功,生成凭证{ lv_materialdocument }|.SELECT SUM( CASE bwartWHEN '262' THEN menge * -1ELSE mengeEND) AS bdmngINTO @itab_data-bdmngFROM nsdm_e_msegWHERE bwart IN ('261','262')AND werks = @itab_data-werksAND lgort = @itab_data-lgortAND matnr = @itab_data-matnrAND aufnr = @itab_data-aufnrAND budat_mkpf BETWEEN @lv_begda AND @lv_endda."更新库存SELECT SINGLE labstFROM mardINTO @itab_data-labstWHERE matnr = @itab_data-matnrAND werks = @itab_data-werksAND lgort = @itab_data-lgort.MODIFY itab_data TRANSPORTING labst WHERE matnr = itab_data-matnr AND werks = itab_data-werks AND lgort = itab_data-lgort.ENDIF.MODIFY itab_data.CLEAR  itab_data.ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_re_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_re_alv .DATA:lv_grid   TYPE REF TO cl_gui_alv_grid,is_stable TYPE lvc_s_stbl,ls_layout TYPE lvc_s_layo.CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'IMPORTINGe_grid = lv_grid.
* 获取ALV变化过后的布局参数CALL METHOD lv_grid->get_frontend_layoutIMPORTINGes_layout = ls_layout.* 重新回写自适应宽度ls_layout-zebra      = 'X'.
*  ls_layout-cwidth_opt = 'X'.* 回写ALV变化过后的布局参数CALL METHOD lv_grid->set_frontend_layoutEXPORTINGis_layout = ls_layout.
* 刷新ALV布局is_stable-col = 'X'.
*  is_stable-row = 'X'.CALL METHOD lv_grid->refresh_table_displayEXPORTINGis_stable = is_stable.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_query
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_query .DATA: lv_va TYPE slis_vari.   " Tcode MB51对应程序变式,将变式清空FIELD-SYMBOLS: <lt_pay_data> TYPE ANY TABLE,<lt_temp>     TYPE ANY TABLE,<ls_data>.DATA lr_pay_data TYPE REF TO data.RANGES:s_bwart FOR resb-bwart,s_werks FOR resb-werks,s_budat FOR mseg-budat_mkpf,s_aufnr FOR resb-aufnr,s_lgort FOR resb-lgort,s_matnr FOR resb-matnr.lv_va = ''."工厂s_werks-low = p_werks.s_werks-option = 'EQ'.s_werks-sign   = 'I'.APPEND s_werks.CLEAR  s_bwart.s_bwart-low = '261'.s_bwart-option = 'EQ'.s_bwart-sign   = 'I'.APPEND s_bwart.CLEAR  s_bwart.s_bwart-low = '262'.s_bwart-option = 'EQ'.s_bwart-sign   = 'I'.APPEND s_bwart.CLEAR  s_bwart.s_budat-low  = lv_begda.s_budat-high = lv_endda.s_budat-option = 'BT'.s_budat-sign   = 'I'.APPEND s_budat.CLEAR s_budat.LOOP AT itab_data WHERE sel = 'X'.s_matnr-low = itab_data-matnr.s_matnr-option = 'EQ'.s_matnr-sign   = 'I'.APPEND s_matnr.CLEAR  s_matnr.IF itab_data-aufnr IS NOT INITIAL.s_aufnr-low    = itab_data-aufnr.s_aufnr-option = 'EQ'.s_aufnr-sign   = 'I'.APPEND s_aufnr.CLEAR s_aufnr.ENDIF.IF itab_data-lgort IS NOT INITIAL.s_lgort-low    = itab_data-lgort.s_lgort-option = 'EQ'.s_lgort-sign   = 'I'.APPEND s_lgort.CLEAR s_lgort.ENDIF.CLEAR itab_data.ENDLOOP.cl_salv_bs_runtime_info=>set(EXPORTINGdisplay  = abap_truemetadata = abap_falsedata     = abap_true ).SUBMIT rm07docs                " Tcode MB51对应程序WITH matnr IN s_matnr   "物料WITH werks IN s_werks   "工厂WITH bwart IN s_bwart"移动类型WITH budat IN s_budat "过账日期WITH lgort IN s_lgortWITH aufnr IN s_aufnrWITH rhier_l  = ''WITH rflat_l  = abap_true"扁平结构WITH database = abap_true "读取数据库WITH alv_def  = lv_va"变式清空,否则会影响取数内容AND RETURN.ENDFORM.*&---------------------------------------------------------------------*
*&      Form  CALLER_EXIT
*&---------------------------------------------------------------------*
*& ALV单元格事件
*&---------------------------------------------------------------------*
*&      -->E_GRID     text
*&---------------------------------------------------------------------*
FORM frm_cell_change USING e_grid TYPE slis_data_caller_exit.DATA:lr_grid TYPE REF TO cl_gui_alv_grid.CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'IMPORTINGe_grid = lr_grid.CREATE OBJECT go_events_receiver.SET HANDLER go_events_receiver->handle_data_changed FOR lr_grid.lr_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_enter ).lr_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_modified ).
ENDFORM.                    "CALLER_EXIT*&---------------------------------------------------------------------*
*& Form handle_data_changed
*&---------------------------------------------------------------------*
*& ALV单元格数据修改事件
*&---------------------------------------------------------------------*
*&      --> ER_DATA_CHANGED
*&      --> SENDER
*&---------------------------------------------------------------------*
FORM handle_data_changed  USING er_data_changed TYPE REF TO cl_alv_changed_data_protocol.DATA:lv_msg       TYPE char255,lv_condition TYPE char10.DATA:ls_good_cells TYPE lvc_s_modi.FIELD-SYMBOLS: <f_field> TYPE any .DATA:lr_grid TYPE REF TO cl_gui_alv_grid.DATA:ls_stable TYPE lvc_s_stbl .ls_stable-col = 'X'.ls_stable-row = 'X'.CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'IMPORTINGe_grid = lr_grid.LOOP AT er_data_changed->mt_good_cells INTO ls_good_cells .READ TABLE itab_data ASSIGNING FIELD-SYMBOL(<fs_output>) INDEX ls_good_cells-row_id.IF sy-subrc = 0.ASSIGN COMPONENT ls_good_cells-fieldname OF STRUCTURE <fs_output> TO <f_field>.<f_field> = ls_good_cells-value.IF ls_good_cells-fieldname = 'LGORT'.SELECT SINGLE lgobeFROM t001lINTO @<fs_output>-lgobeWHERE werks = @<fs_output>-werksAND lgort = @<fs_output>-lgort.IF <fs_output>-lgort IS INITIAL.SELECT SUM( labst )FROM mardINTO @<fs_output>-labstWHERE matnr = @<fs_output>-matnrAND werks = @<fs_output>-werks.ELSE.SELECT SINGLE labstINTO @<fs_output>-labstFROM mardWHERE werks = @<fs_output>-werksAND matnr = @<fs_output>-matnrAND lgort = @<fs_output>-lgort.ENDIF.IF sy-subrc <> 0.CLEAR <fs_output>-labst.ENDIF.ELSEIF ls_good_cells-fieldname = 'AUFNR'."当更改内部订单号时,进行校验IF <fs_output>-aufnr IS NOT INITIAL."判断内部订单公司与当前工厂公司是否一致SELECT SINGLE ktext,bukrs,autypFROM coasINTO @DATA(lw_coas)WHERE aufnr = @<fs_output>-aufnrAND autyp = '01'.IF lw_coas IS INITIAL.<fs_output>-icon = icon_red_light.<fs_output>-message = '输入的订单号不是内部订单,请确认'.ELSEIF lw_coas IS NOT INITIAL AND lw_coas-bukrs <> <fs_output>-bukrs.<fs_output>-icon = icon_red_light.<fs_output>-message = '所选内部订单的公司代码与工厂所属公司代码不一致'.ELSE."内部订单描述<fs_output>-ktext = lw_coas-ktext."获取已投料信息  订单号+ 物料 + 261 -262SELECT SUM( CASE bwartWHEN '262' THEN menge * -1ELSE mengeEND) AS bdmngINTO @<fs_output>-bdmngFROM nsdm_e_msegWHERE bwart IN ('261','262')AND werks = @<fs_output>-werksAND lgort = @<fs_output>-lgortAND matnr = @<fs_output>-matnrAND aufnr = @<fs_output>-aufnrAND budat_mkpf BETWEEN @lv_begda AND @lv_endda.CLEAR:<fs_output>-icon,<fs_output>-message.ENDIF.ELSE.CLEAR:<fs_output>-icon,<fs_output>-message.ENDIF.ENDIF.ENDIF.ENDLOOP.CALL METHOD lr_grid->refresh_table_displayEXPORTINGis_stable      = ls_stablei_soft_refresh = 'X'EXCEPTIONSfinished       = 1.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_auth_chk
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_auth_chk.AUTHORITY-CHECK OBJECT 'M_BEST_WRK'ID 'WERKS' FIELD p_werksID 'ACTVT' DUMMY.IF sy-subrc <> 0.MESSAGE s000 WITH '没有工厂' p_werks '的操作权限' DISPLAY LIKE 'E'.STOP.ENDIF.
ENDFORM.
FORM frm_call_sm30.DATA:gs_vimsellist LIKE vimsellist,gt_vimsellist LIKE TABLE OF gs_vimsellist.gs_vimsellist-viewfield  = 'WERKS'.gs_vimsellist-operator   = 'EQ'.gs_vimsellist-value      = p_werks.APPEND gs_vimsellist TO gt_vimsellist.CALL FUNCTION 'VIEW_MAINTENANCE_CALL'EXPORTINGaction                       = 'U'view_name                    = 'ZPPA0010_A'TABLESdba_sellist                  = gt_vimsellistEXCEPTIONSclient_reference             = 1foreign_lock                 = 2invalid_action               = 3no_clientindependent_auth    = 4no_database_function         = 5no_editor_function           = 6no_show_auth                 = 7no_tvdir_entry               = 8no_upd_auth                  = 9only_show_allowed            = 10system_failure               = 11unknown_field_in_dba_sellist = 12view_not_found               = 13maintenance_prohibited       = 14OTHERS                       = 15.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_date
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_date .CALL FUNCTION 'FI_PERIOD_DETERMINE'EXPORTINGi_budat = p_budati_bukrs = '3000'IMPORTINGe_gjahr = lv_gjahre_monat = lv_monat.lv_poper = lv_monat.CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'EXPORTINGi_gjahr        = lv_gjahri_periv        = 'Y4'i_poper        = lv_poperIMPORTINGe_date         = lv_begdaEXCEPTIONSinput_false    = 1t009_notfound  = 2t009b_notfound = 3OTHERS         = 4.CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'EXPORTINGi_gjahr        = lv_gjahri_periv        = 'Y4'i_poper        = lv_poperIMPORTINGe_date         = lv_enddaEXCEPTIONSinput_false    = 1t009_notfound  = 2t009b_notfound = 3OTHERS         = 4.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_change_date
*&---------------------------------------------------------------------*
*& 更改过账日期
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_change_date ."弹出可以填写字段的函数方法DATA : lt_sval TYPE  TABLE  OF  sval,ls_sval LIKE  LINE  OF  lt_sval.DATA:l_returncode TYPE string ."过账日期CLEAR ls_sval .ls_sval-tabname = 'BKPF' .  "表名ls_sval-fieldname = 'BUDAT' . "字段名ls_sval-field_obl = 'X' .          "是否为必填APPEND ls_sval TO lt_sval.CALL FUNCTION 'POPUP_GET_VALUES'EXPORTING
*     NO_VALUE_CHECK  = ' 'popup_title     = '请填写'
*     START_COLUMN    = '5'
*     START_ROW       = '5'IMPORTINGreturncode      = l_returncodeTABLESfields          = lt_svalEXCEPTIONSerror_in_fields = 1OTHERS          = 2.LOOP AT lt_sval INTO DATA(lw_sval) WHERE tabname = 'BKPF' AND fieldname = 'BUDAT'.p_budat = lw_sval-value.CLEAR lw_sval.EXIT.ENDLOOP.REFRESH lt_sval.PERFORM frm_get_date."重新获取日期"更新投料数据LOOP AT itab_data.SELECT SUM( CASE bwartWHEN '262' THEN menge * -1ELSE mengeEND) AS bdmngINTO @itab_data-bdmngFROM nsdm_e_msegWHERE bwart IN ('261','262')AND werks = @itab_data-werksAND lgort = @itab_data-lgortAND matnr = @itab_data-matnrAND aufnr = @itab_data-aufnrAND budat_mkpf BETWEEN @lv_begda AND @lv_endda.MODIFY itab_data.CLEAR itab_data.ENDLOOP.ENDFORM.*&---------------------------------------------------------------------*
*& Form FRM_DOWN_TEMPLATE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_down_template .DATA: lo_objdata LIKE wwwdatatab,p_name     TYPE string,p_path     TYPE string,p_fullname TYPE string,p_dest     TYPE rlgrap-filename,li_rc      TYPE sy-subrc,lv_objid   TYPE w3objid,ls_str     TYPE string.lv_objid = 'ZPPA0011'.ls_str = 'ZPPA0011_内部订单消耗领料登记模板.xlsx'.CALL METHOD cl_gui_frontend_services=>file_save_dialogEXPORTINGwindow_title      = '选择下载路径'default_extension = 'XLSX'default_file_name = ls_strCHANGINGfilename          = p_namepath              = p_pathfullpath          = p_fullname.IF p_fullname IS INITIAL.STOP.ENDIF.SELECT SINGLE relid objid FROM wwwdataINTO CORRESPONDING FIELDS OF  lo_objdataWHERE srtf2 = 0AND relid = 'MI'AND objid = lv_objid.IF sy-subrc <> 0.MESSAGE '下载模板失败!' TYPE 'S' DISPLAY LIKE 'E'.STOP.ENDIF.p_dest = p_fullname.CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'EXPORTINGkey         = lo_objdatadestination = p_destIMPORTINGrc          = li_rc.IF li_rc = 0.MESSAGE '模版下载成功' TYPE 'S'.ELSE.MESSAGE '模版下载失败' TYPE 'S' DISPLAY LIKE 'E'.STOP.ENDIF.
ENDFORM.*&---------------------------------------------------------------------*
*& Form FRM_GET_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM frm_get_file  USING  p_file.CALL FUNCTION 'WS_FILENAME_GET'EXPORTINGdef_filename     = p_filemask             = ',*.xlsx,*.XLSX,*.XLS,*.xls,*.txt,*.TXT.'
*'',*.xls,*.XLS.'如果读入txt文件,在后边就需要用函数mode             = 'O'title            = 'File Name'IMPORTINGfilename         = p_fileEXCEPTIONSinv_winsys       = 1no_batch         = 2selection_cancel = 3selection_error  = 4OTHERS           = 5.ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_from_excel
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_from_excel .TYPE-POOLS: truxs.DATA: p_text_data TYPE truxs_t_text_data,pp_file     TYPE string,i_file      TYPE ibipparms-path.pp_file = p_file.CALL FUNCTION 'GUI_UPLOAD'EXPORTINGfilename                = pp_filefiletype                = 'ASC'has_field_separator     = 'X'read_by_line            = 'X'TABLESdata_tab                = p_text_dataEXCEPTIONSfile_open_error         = 1file_read_error         = 2no_batch                = 3gui_refuse_filetransfer = 4invalid_type            = 5no_authority            = 6unknown_error           = 7bad_data_format         = 8header_not_allowed      = 9separator_not_allowed   = 10header_too_long         = 11unknown_dp_error        = 12access_denied           = 13dp_out_of_memory        = 14disk_full               = 15dp_timeout              = 16OTHERS                  = 17.IF sy-subrc <> 0.CASE sy-subrc.WHEN 1.MESSAGE 'FILE_OPEN_ERROR ' TYPE 'E'.WHEN 2.MESSAGE 'FILE_READ_ERROR ' TYPE 'E'.WHEN 3.MESSAGE 'NO_BATCH' TYPE 'E'.WHEN 4.MESSAGE 'GUI_REFUSE_FILETRANSFER  ' TYPE 'E'.WHEN 5.MESSAGE 'INVALID_TYPE ' TYPE 'E'.WHEN 6.MESSAGE ' NO_AUTHORITY' TYPE 'E'.WHEN 7.MESSAGE 'UNKNOWN_ERROR' TYPE 'E'.WHEN 8.MESSAGE 'BAD_DATA_FORMAT ' TYPE 'E'.WHEN 9.MESSAGE 'HEADER_NOT_ALLOWED' TYPE 'E'.WHEN 10.MESSAGE 'SEPARATOR_NOT_ALLOWED' TYPE 'E'.WHEN 11.MESSAGE 'HEADER_TOO_LONG ' TYPE 'E'.WHEN 12.MESSAGE 'UNKNOWN_DP_ERROR' TYPE 'E'.WHEN 13.MESSAGE ' ACCESS_DENIED ' TYPE 'E'.WHEN 14.MESSAGE 'DP_OUT_OF_MEMORY ' TYPE 'E'.WHEN 15.MESSAGE 'DISK_FULL  ' TYPE 'E'.WHEN 16.MESSAGE 'DP_TIMEOUT' TYPE 'E'.WHEN 17.MESSAGE ' OTHERS  ' TYPE 'E'.WHEN OTHERS.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDCASE.ENDIF.CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'EXPORTING
*     I_FIELD_SEPERATOR    =
*     I_LINE_HEADER        =i_tab_raw_data       = p_text_datai_filename           = p_fileTABLESi_tab_converted_data = itab_sdataEXCEPTIONSconversion_failed    = 1OTHERS               = 2.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.DELETE itab_sdata INDEX 1.
*LOOP AT itab_sdata.MOVE-CORRESPONDING itab_sdata TO itab_data."物料代码补零CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'EXPORTINGinput        = itab_data-matnrIMPORTINGoutput       = itab_data-matnrEXCEPTIONSlength_error = 1OTHERS       = 2.IF sy-subrc <> 0.
*       Implement suitable error handling hereENDIF."物料描述SELECT SINGLE maktxFROM maktINTO @itab_data-maktxWHERE matnr = @itab_data-matnr."获取内部订单描述、公司代码、工厂代码SELECT SINGLE ktext,bukrsFROM coasINTO ( @itab_data-ktext, @itab_data-bukrs )WHERE aufnr = @itab_data-aufnr."判断内部订单的公司与库存工厂对公司是否一致SELECT SINGLE t001k~bukrs,t001~butxt,t001w~name1FROM t001 INNER JOIN t001k ON t001~bukrs = t001k~bukrsINNER JOIN t001w ON t001w~bwkey = t001k~bwkeyINTO @DATA(lw_t001)WHERE t001w~werks = @itab_data-werks.IF lw_t001-bukrs <> itab_data-bukrs.itab_data-icon = icon_red_light.itab_data-type = 'E'.itab_data-message = '内部订单对应公司与库存工厂所属公司不一致'.ELSE.itab_data-name1 = lw_t001-name1.itab_data-butxt = lw_t001-butxt.ENDIF.SELECT SUM( CASE bwartWHEN '262' THEN menge * -1ELSE mengeEND) AS bdmngINTO @itab_data-bdmngFROM nsdm_e_msegWHERE bwart IN ('261','262')AND werks = @itab_data-werksAND lgort = @itab_data-lgortAND matnr = @itab_data-matnrAND aufnr = @itab_data-aufnrAND budat_mkpf BETWEEN @lv_begda AND @lv_endda."更新库存SELECT SINGLE labstFROM mardINTO @itab_data-labstWHERE matnr = @itab_data-matnrAND werks = @itab_data-werksAND lgort = @itab_data-lgort.itab_data-sel  = 'X'.itab_data-icon = icon_light_out.APPEND itab_data.CLEAR: itab_sdata,itab_data .ENDLOOP.REFRESH itab_sdata[].
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_from_mb52
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_from_database .DATA: lv_va TYPE slis_vari.   " Tcode MB51对应程序变式,将变式清空FIELD-SYMBOLS: <lt_pay_data> TYPE ANY TABLE,<ls_data>.DATA lr_pay_data  TYPE REF TO data.IF p_aufnr IS NOT INITIAL."获取内部订单描述、公司代码、工厂代码SELECT SINGLE ktext,bukrsFROM coasINTO @DATA(lw_coas)WHERE aufnr = @p_aufnrAND autyp = '01'.IF lw_coas IS INITIAL.MESSAGE '输入的订单号不是内部订单号!' TYPE 'I'.EXIT.ELSE."判断内部订单的公司与库存工厂对公司是否一致SELECT SINGLE t001k~bukrs,t001~butxt,t001w~name1FROM t001 INNER JOIN t001k ON t001~bukrs = t001k~bukrsINNER JOIN t001w ON t001w~bwkey = t001k~bwkeyINTO @DATA(lw_t001)WHERE t001w~werks = @p_werks.ENDIF.ELSE."判断内部订单的公司与库存工厂对公司是否一致SELECT SINGLE t001k~bukrs,t001~butxt,t001w~name1FROM t001 INNER JOIN t001k ON t001~bukrs = t001k~bukrsINNER JOIN t001w ON t001w~bwkey = t001k~bwkeyINTO @lw_t001WHERE t001w~werks = @p_werks.ENDIF.lv_va = '/YT01'.RANGES:s_werks FOR resb-werks."工厂s_werks-low = p_werks.s_werks-option = 'EQ'.s_werks-sign   = 'I'.APPEND s_werks.REFRESH:itab_data."设置执行时不显示,只获取ALV数据cl_salv_bs_runtime_info=>set(display = abap_falsemetadata = abap_falsedata  = abap_true )."MB52的程序SUBMIT rm07mlbsWITH matnr IN s_matnrWITH werks IN s_werksWITH lgort IN s_lgortWITH negativ = ''WITH pa_sond = 'X'WITH xmchb = 'X'WITH nozero = 'X'"0库存标识WITH novalues = ''WITH pa_hsq = ''WITH pa_flt = 'X'WITH p_vari = lv_vaAND RETURN.TRY ."可以获取MB52cl_salv_bs_runtime_info=>get_data_ref(IMPORTING r_data = lr_pay_data ).ASSIGN lr_pay_data->* TO <lt_pay_data>.CATCH  cx_salv_bs_sc_runtime_info.MESSAGE '无法获取ALV数据'  TYPE  'E'.ENDTRY.cl_salv_bs_runtime_info=>clear_all( ).IF <lt_pay_data> IS ASSIGNED.LOOP AT <lt_pay_data> ASSIGNING <ls_data>.MOVE-CORRESPONDING <ls_data> TO itab_data.IF lw_coas IS NOT INITIAL.itab_data-aufnr = p_aufnr.itab_data-ktext = lw_coas-ktext.ENDIF.itab_data-bukrs = lw_t001-bukrs.itab_data-butxt = lw_t001-butxt.APPEND itab_data.CLEAR:  itab_data.ENDLOOP.CLEAR: lw_coas,lw_t001.ENDIF.
ENDFORM.

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

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

相关文章

python中,or、not的用法

or的用法 在python中,or运算符是一个逻辑运算符&#xff0c;用于在多个条件中选择至少一个为真&#xff08;True&#xff09;的情况。 如果条件中的任意一个为真&#xff0c;整个表达式的结果就为真 如&#xff1a; 示例1: 检查两个数字中至少有一个正数 示例2: x True y …

Python语言创建爬虫代理IP池详细步骤和代码示例

目录 一、引言 二、代理IP的选择 三、使用代理IP的代码示例 四、创建代理IP池的代码示例 五、总结 一、引言 在爬虫程序中&#xff0c;代理IP的使用是避免IP被封禁、提高爬取效率的重要手段。本文将详细介绍如何使用Python语言创建一个爬虫代理IP池&#xff0c;包括代理I…

寿险公司通过开源治理保障数字创新,安全打通高质量服务新通道

某寿险公司致力于为消费者提供人性化的产品和服务&#xff0c;在中国保险市场中始终保持前列。该寿险公司以挖掘和满足客户需求为出发点&#xff0c;从产品开发、渠道销售、运营流程和售后服务等各环节&#xff0c;借助数字化工具&#xff0c;不断地努力探索并提升服务品质。 精…

JavaScript添加快捷键、取消浏览器默认的快捷操作、js查看键盘按钮keycode值

document.addEventListener("keydown",function (event) {// 如果不知道按键对应的数字&#xff08;keyCode&#xff09;是多少可以弹出查看一下// alert(event.keyCode)if (event.ctrlKey && event.altKey && event.view["0"] null){if(…

[cocos creator]EditBox,editing-return事件,清空输入框

需求&#xff1a; 监听EditBox&#xff0c;editing-return 回车事件&#xff0c;在输入框内点击回车后&#xff0c;发送内容&#xff0c;并清空输入框 问题&#xff1a; 设置node.getComponent(EditBox).string ; 没有效果 解决办法&#xff1a; //设置string 为空 this.v…

采集软件大全-全网免费的采集软件大全

采集软件大揭秘&#xff1a;从排名到任意网站采集的全方位解读 在数字时代&#xff0c;信息是黄金&#xff0c;而采集软件就是那把能够淘金的工具。无论是市场调研、竞品分析还是SEO优化&#xff0c;采集软件都扮演着不可或缺的角色。在这个领域里&#xff0c;有许多选择&…

MySQL进阶知识:SQL性能优化

目录 SQL性能分析 SQL执行频率 慢查询日志 profile详情 explain执行计划 索引的使用 最左前缀法则 范围查询 索引列运算 字符串加引号 模糊查询 or连接的条件 数据分布影响 SQL提示 覆盖索引 前缀索引 索引设计原则 SQL优化 insert优化 主键优化 页分裂 …

Windows安装Kafka3.6,单机

Kafka版本&#xff1a;kafka_2.13-3.6.0 Windows10系统 安装与配置 下载 kafka_2.13-3.6.0.tgz 下载并解压Kafka 3.6.0的压缩包到你选择的目录。 Kafka3.6.0下载链接https://kafka.apache.org/downloads 说明&#xff1a;Kafka3.6内置了Zookeeper&#xff0c;使用内置的Zo…

游戏缺少d3dx9_43.dll修复方法分享,快速解决dll缺失问题

在计算机使用过程中&#xff0c;我们常常会遇到一些错误提示&#xff0c;其中之一就是“找不到d3dx9_43.dll文件”。这个错误通常出现在运行某些游戏或应用程序时&#xff0c;d3dx9_43.dll是一个动态链接库文件&#xff0c;它是DirectX 9的一部分&#xff0c;用于支持游戏中的3…

涵盖多种功能,龙讯旷腾Module第二期:电子结构及声子计算

Module是什么 在PWmat的基础功能上&#xff0c;我们针对用户的使用需求开发了一些顶层模块&#xff08;Module&#xff09;。这些Module中的一部分是与已有的优秀工具的接口&#xff0c;一部分是以PWmat的计算结果为基础得到实际需要的物理量&#xff0c;一部分则是为特定的计…

增加F110 付款方式的乱记录

随便记录一下&#xff0c;基本上有这些信息可以了 为了保持PRD与测试机一致的银行代码&#xff0c;需要先在DEV&#xff0c;QAS 改成4 外部给号 主要都是在FBZP 开户行维护-FI12_HBANK/FI12 S4hana 里面有的没有办法在FI12 维护只能去NWBC NWBC&#xff1a;维护银行账户并关联…

使用yolov7进行多图像视频识别

1.yolov7你可以让你简单的部署,比起前几代来说特别简单 #下面是我转换老友记的测试视频,可以看到几乎可以准确预测 2.步骤 1.在github官网下载代码 https://github.com/WongKinYiu/yolov7 2.点击下载权重文件放到项目中 3.安装依赖,我的python版本是3.6的 pip install -r requ…