内向交货单MIGO过账模板
作者:互联网
***********************************************************************
* Program Name : ZMMF027 *
* Program Title : 按采购订单收货 *
* Application : *
* Description : *
* Func Spec ID : ZMM027 *
* Requested by : *
* Author : ZHANGS *
* Req Date : 2019-04-19 *
***********************************************************************
* MODIFICATIONS (latest entry at the top) *
* ------------------------------------------------------------------- *
* TASK-NO DATE NAME (COMPANY) DESCRIPTION *
* ------- ---- ---- --------- ----------- *
***********************************************************************
REPORT zmmf027.
TABLES:sscrfields.
TYPES: BEGIN OF ty_upload,
ebeln TYPE string, "内向交货单号
ebelp TYPE string, "采购订单行项目
bldat TYPE string, "凭证日期
budat TYPE string, "过账日期
bwart TYPE string, "移动类型
werks TYPE string, "工厂
lgort TYPE string, "库存地点
matnr TYPE string, "物料
menge TYPE string, "数量
meins TYPE string, "单位
dmbtr TYPE string, "金额
grund TYPE string, "移动原因
sgtxt TYPE string, "项目文本
END OF ty_upload.
DATA: gs_upload TYPE ty_upload,
gt_upload TYPE TABLE OF ty_upload.
TYPES: BEGIN OF ty_itab,
zkey TYPE lips-posnr, "分组
ebeln TYPE lips-vbeln, "内向交货单号
ebelp TYPE lips-posnr, "采购订单行项目
bldat TYPE mkpf-bldat, "凭证日期
budat TYPE mkpf-budat, "过账日期
bwart TYPE mseg-bwart, "移动类型
werks TYPE mseg-werks, "工厂
lgort TYPE mseg-lgort, "库存地点
lgort_t TYPE t001l-lgobe, "库存地点描述
matnr TYPE mseg-matnr, "物料
matnr_t TYPE makt-maktx, "物料描述
menge TYPE mseg-menge, "数量
meins TYPE mseg-meins, "单位
dmbtr TYPE mseg-dmbtr, "外来金额
grund TYPE mseg-grund, "移动原因
sgtxt TYPE mseg-sgtxt, "项目文本
mblnr TYPE mseg-mblnr, "物料凭证
mjahr TYPE mseg-mjahr, "年度
statu TYPE bapiret2-type,
msg TYPE bapiret2-message,
chk_lights TYPE char1, "-- 数据检查指示灯 -
END OF ty_itab.
DATA: gs_itab TYPE ty_itab,
gt_itab TYPE TABLE OF ty_itab.
FIELD-SYMBOLS: <fs_itab> TYPE ty_itab.
DATA: gv_error TYPE char1. "错误标识
DATA: gt_fcat TYPE lvc_t_fcat,
ga_fcat TYPE lvc_s_fcat,
gc_grid TYPE REF TO cl_gui_alv_grid.
DEFINE add_fields.
CLEAR ga_fcat .
ga_fcat-fieldname = &1. "内表的字段名
ga_fcat-scrtext_l = &2. "字段描述.
ga_fcat-ref_table = &3. "输出数据的内表名
ga_fcat-ref_field = &4. "为key
ga_fcat-colddictxt = 'L'.
ga_fcat-checkbox = &5. "字段描述.
ga_fcat-edit = &6. "字段描述.
ga_fcat-f4availabl = &7. "F4
ga_fcat-outputlen = &8. "输出长度
APPEND ga_fcat TO gt_fcat.
END-OF-DEFINITION.
DATA : functxt TYPE smp_dyntxt.
DATA : gv_temp TYPE wwwdatatab-objid VALUE 'ZMM027'."SMW0 对象名
SELECTION-SCREEN BEGIN OF BLOCK blc_001 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_file TYPE rlgrap-filename MEMORY ID f04."
SELECTION-SCREEN END OF BLOCK blc_001.
SELECTION-SCREEN: FUNCTION KEY 1.
INITIALIZATION.
"下载模板按钮
functxt-icon_id = icon_xls.
functxt-icon_text = '下载模板'.
sscrfields-functxt_01 = functxt.
*---------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
"Help
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01' .
DATA: g_file TYPE sapb-sappfad.
DATA: e_error TYPE char255.
CLEAR e_error.
PERFORM frm_download_excel_fromserver USING gv_temp g_file
CHANGING e_error.
IF e_error IS INITIAL.
MESSAGE '下载成功!' TYPE 'S'.
ELSE.
MESSAGE e_error TYPE 'E'.
ENDIF.
WHEN OTHERS.
ENDCASE.
START-OF-SELECTION.
IF p_file IS INITIAL .
MESSAGE '请选择导入文件路径' TYPE 'S' DISPLAY LIKE 'E' .
EXIT.
ENDIF .
PERFORM frm_upload_data.
PERFORM frm_check_data .
PERFORM frm_display_alv.
FORM frm_download_excel_fromserver USING p_objid LIKE wwwdatatab-objid
p_file LIKE sapb-sappfad
CHANGING e_error TYPE char255.
DATA:lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
CONCATENATE p_objid '.XLSX' INTO ls_objnam.
SELECT SINGLE relid objid FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = p_objid.
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
CONCATENATE '不存在模板' ls_objnam ',请检查' INTO e_error.
RETURN.
ENDIF.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = '内向交货单收货批导模板.xlsx'
mode = 'S'
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
ls_destination = p_file.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '下载模板' ls_objnam '失败,请检查!' INTO e_error.
ENDIF.
ENDFORM. "sub_download_excel_fromserver
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_upload_data .
DATA: lt_data TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' "读取excel文件中的内容
EXPORTING
filename = p_file
i_begin_col = '1'
i_begin_row = '3'
i_end_col = '59'
i_end_row = '9999'
TABLES
intern = lt_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE s000(oo) WITH 'EXCEL导入失败' DISPLAY LIKE 'E'.
STOP.
ENDIF.
SORT lt_data BY row col value.
DATA: lv_index LIKE sy-index.
FIELD-SYMBOLS: <fs_excel> TYPE any.
LOOP AT lt_data.
CLEAR lv_index.
lv_index = lt_data-col+2(2).
ASSIGN COMPONENT lv_index OF STRUCTURE gs_upload TO <fs_excel>.
IF sy-subrc EQ 0.
<fs_excel> = lt_data-value.
ENDIF.
AT END OF row.
APPEND gs_upload TO gt_upload.
CLEAR gs_upload.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_check_data .
DATA: lv_zkey TYPE lips-posnr.
IF gt_upload[] IS INITIAL.
MESSAGE s000(oo) WITH '没有上传数据' DISPLAY LIKE 'E'.
STOP.
ENDIF.
lv_zkey = 1.
CLEAR gs_upload.
LOOP AT gt_upload INTO gs_upload.
CLEAR gs_itab.
MOVE-CORRESPONDING gs_upload TO gs_itab.
gs_itab-zkey = lv_zkey. "分组
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = gs_itab-matnr
IMPORTING
output = gs_itab-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gs_itab-meins
language = sy-langu
IMPORTING
output = gs_itab-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
"采购订单号
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_itab-ebeln
IMPORTING
output = gs_itab-ebeln.
gs_itab-chk_lights = 3. "代表正确 1代表出错,2代表警告
APPEND gs_itab TO gt_itab.
CLEAR gs_upload.
AT END OF ebeln.
lv_zkey = lv_zkey + 1.
ENDAT.
ENDLOOP.
CHECK gt_itab IS NOT INITIAL.
DATA: lt_makt TYPE TABLE OF makt,
ls_makt TYPE makt.
REFRESH lt_makt.
SELECT * FROM makt INTO TABLE lt_makt WHERE spras = sy-langu.
SORT lt_makt BY matnr.
DATA: lt_lips TYPE TABLE OF lips,
ls_lips TYPE lips.
REFRESH lt_lips.
SELECT *
FROM lips
INTO TABLE lt_lips
FOR ALL ENTRIES IN gt_itab
WHERE vbeln = gt_itab-ebeln
AND posnr = gt_itab-ebelp.
LOOP AT gt_itab ASSIGNING <fs_itab>.
<fs_itab>-chk_lights = 3. "代表正确 1代表出错,2代表警告
* CLEAR LS_MAKT.
* READ TABLE LT_MAKT INTO LS_MAKT WITH KEY MATNR = <FS_ITAB>-MATNR BINARY SEARCH.
* IF SY-SUBRC NE 0.
* <FS_ITAB>-CHK_LIGHTS = 1.
* <FS_ITAB>-MSG = '物料不存在'.
* ENDIF.
CLEAR ls_lips.
READ TABLE lt_lips INTO ls_lips WITH KEY vbeln = <fs_itab>-ebeln
posnr = <fs_itab>-ebelp.
IF sy-subrc NE 0.
<fs_itab>-chk_lights = 1.
CONCATENATE <fs_itab>-msg '内向交货单及行项目不存在或已经删除' INTO <fs_itab>-msg SEPARATED BY ';'.
ELSE.
IF ls_lips-matnr NE <fs_itab>-matnr.
<fs_itab>-chk_lights = 1.
CONCATENATE <fs_itab>-msg '输入的物料与采购订单的物料不一致' INTO <fs_itab>-msg SEPARATED BY ';'.
ENDIF.
<fs_itab>-matnr_t = ls_lips-arktx. "短文本
ENDIF.
IF <fs_itab>-msg IS NOT INITIAL.
SHIFT <fs_itab>-msg LEFT DELETING LEADING ';'.
ENDIF.
IF <fs_itab>-chk_lights = 1.
<fs_itab>-statu = 'E'.
gv_error = 'X'.
ELSEIF <fs_itab>-chk_lights = 3.
<fs_itab>-statu = 'S'.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display_alv .
DATA: ls_layout TYPE lvc_s_layo,
ls_repid TYPE sy-repid.
CLEAR:ls_layout.
ls_layout-zebra = 'X'.
ls_layout-sel_mode = 'A'.
ls_layout-excp_fname = 'CHK_LIGHTS'.
ls_layout-cwidth_opt = 'X'.
* ls_layout-box_fieldname = 'SEL'."不用做选中,直接点前面的行号就代表选中
* ls_repid = sy-repid.
PERFORM frm_get_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_grid_title = lv_grid_title
* I_BUFFER_ACTIVE = 'X'
i_default = 'X'
i_save = 'X'
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
it_fieldcat_lvc = gt_fcat[]
is_layout_lvc = ls_layout
* it_events = lt_event
TABLES
t_outtab = gt_itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM frm_get_fieldcat .
add_fields 'STATU' '状态' '' '' '' '' '' ''.
add_fields 'MSG' '消息' '' '' '' '' '' ''.
add_fields 'ZKEY ' '分组 ' 'EKPO' 'EBELP' '' '' '' ''.
add_fields 'MBLNR ' '物料凭证编号 ' 'MSEG' 'MBLNR' '' '' '' ''.
add_fields 'MJAHR ' '物料凭证的年份 ' 'MSEG' 'MJAHR' '' '' '' ''.
add_fields 'EBELN ' '内向交货单 ' 'EKPO' 'EBELN' '' '' '' ''.
add_fields 'EBELP ' '内向交货单行项目 ' 'EKPO' 'EBELP' '' '' '' ''.
add_fields 'BLDAT ' '凭证日期 ' 'MKPF' 'BLDAT' '' '' '' ''.
add_fields 'BUDAT ' '过账日期 ' 'MKPF' 'BUDAT' '' '' '' ''.
add_fields 'BWART ' '移动类型 ' 'MSEG' 'BWART' '' '' '' ''.
add_fields 'WERKS ' '工厂' 'MSEG' 'WERKS' '' '' '' ''.
add_fields 'LGORT ' '库存地点 ' 'MSEG' 'LGORT' '' '' '' ''.
add_fields 'MATNR ' '物料编码 ' 'MSEG' 'MATNR' '' '' '' ''.
add_fields 'MATNR_T ' '物料名称 ' '' '' '' '' '' ''.
* ADD_FIELDS 'MEINS ' '单位 ' 'MSEG' 'MEINS' '' '' '' ''.
add_fields 'MENGE ' '数量 ' 'MSEG' 'MENGE' '' '' '' ''.
add_fields 'MEINS ' '单位 ' 'MSEG' 'MEINS' '' '' '' ''.
add_fields 'DMBTR ' '金额 ' 'MSEG' 'DMBTR' '' '' '' ''.
add_fields 'GRUND ' '移动原因 ' 'MSEG' 'GRUND' '' '' '' ''.
add_fields 'SGTXT ' '项目文本 ' 'MSEG' 'SGTXT' '' '' '' ''.
ENDFORM.
FORM set_pf_status USING rt_extab TYPE slis_t_extab."调用SAP标准功能的工具栏图标,例排序、筛选、小计等功能
SET PF-STATUS 'ZMMF025'. "双击单引号里面的,新建一个同名的状态,也可以去在别的reportcopy一个标准的
" "再加上自己定义的按钮。比如program name : RM07MLBS
ENDFORM.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
* DATA: LV_EBELN TYPE EBELN.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = gc_grid.
CALL METHOD gc_grid->check_changed_data.
rs_selfield-refresh = 'X'.
CASE r_ucomm.
WHEN 'UPLOAD'.
IF gv_error EQ 'X'.
MESSAGE '存在错误数据请纠正后再导入' TYPE 'E'.
ELSE.
PERFORM frm_creat_migo.
ENDIF.
* WHEN '&IC1'.
* CASE RS_SELFIELD-FIELDNAME.
* WHEN 'EBELN'.
* LV_EBELN = RS_SELFIELD-VALUE.
* SET PARAMETER ID 'BES' FIELD LV_EBELN.
* CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
*
* ENDCASE.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREAT_MD12
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_creat_migo .
DATA: ls_itab TYPE ty_itab,
ls_itab_1 TYPE ty_itab,
lt_itab TYPE TABLE OF ty_itab.
DATA: ls_goodsmvt_header TYPE bapi2017_gm_head_01,
ls_goodsmvt_code TYPE bapi2017_gm_code,
ls_goodsmvt_headret TYPE bapi2017_gm_head_ret,
lt_goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create INITIAL SIZE 0 WITH HEADER LINE,
lt_return TYPE STANDARD TABLE OF bapiret2 INITIAL SIZE 0 WITH HEADER LINE.
LOOP AT gt_itab INTO ls_itab_1.
CLEAR ls_itab.
MOVE-CORRESPONDING ls_itab_1 TO ls_itab.
AT NEW zkey.
CLEAR ls_goodsmvt_header.
ls_goodsmvt_header-pstng_date = ls_itab-budat. "过账日期
ls_goodsmvt_header-doc_date = ls_itab-bldat. "凭证日期
"与内向交货单相关的入库
ls_goodsmvt_code-gm_code = '01'.
ENDAT.
CLEAR lt_goodsmvt_item.
lt_goodsmvt_item-material_long = ls_itab-matnr. "物料
lt_goodsmvt_item-plant = ls_itab-werks. "工厂
lt_goodsmvt_item-stge_loc = ls_itab-lgort. "库存地点
lt_goodsmvt_item-move_type = ls_itab-bwart. "移动类型
lt_goodsmvt_item-mvt_ind = 'B'.
* LT_GOODSMVT_ITEM-SPEC_STOCK = LS_ITAB-SOBKZ. "特殊库存
lt_goodsmvt_item-entry_qnt = ls_itab-menge. "数量
lt_goodsmvt_item-amount_lc = ls_itab-dmbtr. "金额
lt_goodsmvt_item-DELIV_NUMB_TO_SEARCH = ls_itab-ebeln. "采购订单号
lt_goodsmvt_item-DELIV_ITEM_TO_SEARCH = ls_itab-ebelp. "采购订单行项目
lt_goodsmvt_item-move_reas = ls_itab-grund. "移动原因
* LT_GOODSMVT_ITEM-WITHDRAWN = LS_ZMMS004-KZEAR. "最后
lt_goodsmvt_item-item_text = ls_itab-sgtxt. "项目文本
APPEND lt_goodsmvt_item.
AT END OF zkey.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_goodsmvt_header
goodsmvt_code = ls_goodsmvt_code
IMPORTING
goodsmvt_headret = ls_goodsmvt_headret
TABLES
goodsmvt_item = lt_goodsmvt_item
return = lt_return.
IF ls_goodsmvt_headret-mat_doc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
READ TABLE lt_return WITH KEY type = 'E'.
LOOP AT gt_itab ASSIGNING <fs_itab> WHERE zkey = ls_itab-zkey.
<fs_itab>-statu = 'E'.
<fs_itab>-chk_lights = 1.
<fs_itab>-msg = lt_return-message..
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT gt_itab ASSIGNING <fs_itab> WHERE zkey = ls_itab-zkey.
<fs_itab>-statu = 'S'.
<fs_itab>-chk_lights = 3.
<fs_itab>-msg = '执行成功'.
<fs_itab>-mblnr = ls_goodsmvt_headret-mat_doc.
<fs_itab>-mjahr = ls_goodsmvt_headret-doc_year.
ENDLOOP.
ENDIF.
REFRESH: lt_goodsmvt_item[],
lt_return[].
CLEAR: ls_goodsmvt_header,
ls_goodsmvt_code,
ls_goodsmvt_headret.
ENDAT.
CLEAR ls_itab_1.
ENDLOOP.
* DATA: LT_ROW_INDEX TYPE LVC_T_ROW,
* LT_ROW_NO TYPE LVC_T_ROID,
* LS_ROW_NO TYPE LVC_S_ROID,
* LV_LINES TYPE I.
*
* CALL METHOD GC_GRID->GET_SELECTED_ROWS
* IMPORTING
** ET_INDEX_ROWS = LT_ROW_INDEX
* ET_ROW_NO = LT_ROW_NO.
*
* DESCRIBE TABLE LT_ROW_NO LINES LV_LINES.
* IF LV_LINES EQ 0.
* MESSAGE '请选择需要导入的条目' TYPE 'E'.
* EXIT.
* ENDIF.
*
* LOOP AT LT_ROW_NO INTO LS_ROW_NO.
* READ TABLE GT_ITAB INTO LS_ITAB INDEX LS_ROW_NO-ROW_ID.
* IF SY-SUBRC = 0.
* APPEND LS_ITAB TO LT_ITAB.
* ENDIF.
* ENDLOOP.
*
* LOOP AT LT_ITAB INTO LS_ITAB.
** PERFORM FRM_CALL_VK12 USING LS_ITAB.
* ENDLOOP.
ENDFORM.
标签:itab,DATA,MIGO,过账,lt,ls,交货单,TYPE,goodsmvt 来源: https://blog.csdn.net/qq_37968127/article/details/89632958