&---------------------------------------------------------------------
*& Report ZMMCP005
&---------------------------------------------------------------------
- 作者: Liv
- 完成日期:
- 描述: 期初库存导入
- 需求简要说明:
&--------------------------------------------------------------------- - 版本号 日期 作者 修改描述 功能更改说明书
&--------------------------------------------------------------------- - 1.0 2021/11/19 Liv 程序创建
*&
&---------------------------------------------------------------------
REPORT zmmcp005 MESSAGE-ID 00.
TABLES:sscrfields.
TYPE-POOLS: slis.
INCLUDE .
DEFINE append_str.
CONCATENATE &1 &2 INTO &1 SEPARATED BY ‘,’.
END-OF-DEFINITION.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
*&For DOC ALV
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_event TYPE slis_t_event,
it_layout TYPE slis_layout_alv,
w_callback_ucomm TYPE slis_formname,
i_list_comments TYPE slis_t_listheader,
w_list_comments LIKE LINE OF i_list_comments,
i_events TYPE slis_t_event,
w_events LIKE LINE OF i_events.
*定义隐藏标准按钮的变量
DATA: wa_excluding TYPE slis_extab,
it_excluding TYPE slis_t_extab.
DEFINE initial_field.
wa_fieldcat-ddictxt = ‘L’.
wa_fieldcat-fieldname = &1 .
wa_fieldcat-seltext_l = &2 .
wa_fieldcat-seltext_m = &2 .
wa_fieldcat-seltext_s = &2 .
wa_fieldcat-reptext_ddic = &2.
wa_fieldcat-no_zero = &3.
wa_fieldcat-key = &4.
wa_fieldcat-just = &5.
wa_fieldcat-ref_fieldname = &6.
wa_fieldcat-ref_tabname = &7.
- IF WA_FIELDCAT-FIELDNAME = ‘Z_KPI’.
-
WA_FIELDCAT-INTLEN = 18.
- ENDIF.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
END-OF-DEFINITION.
*DATA gt_input LIKE TABLE OF zcpfit_0600 WITH HEADER LINE. "久其报表KPI数据源配置表
DATA:BEGIN OF gt_input OCCURS 0,
zlsh TYPE i,
zhxm TYPE i,
zks , " 开始
zjs , " 结束
zmess_h(255) , " 抬头系统消息
zmess_i(255) , " 行项目系统消息
bldat LIKE gohead-bldat , " 凭证日期
budat LIKE gohead-budat , " 过账日期
bwart LIKE godefault_tv-bwart , " 移动类型
bktxt LIKE gohead-bktxt , " 抬头文本
werks LIKE goitem-werks, " 工厂
name1 LIKE t001w-name1 , " 工厂名称
lgobe LIKE goitem-lgobe , " 库存地点
zxh(20) , " 序号
matnr LIKE goitem-matnr , " 物料
maktx LIKE goitem-maktx , " 物料描述
xchar LIKE marc-xchar , " 批次启用标识
charg LIKE goitem-charg , " 批次
erfmg LIKE goitem-erfmg , " 数量
meins LIKE mara-meins , " 计量单位
lifnr LIKE goitem-lifnr , " 供应商
kunnr LIKE goitem-kunnr , " 客户
dmbtr LIKE goitem-dmbtr , " 总金额
sobkz LIKE goitem-sobkz , " 特殊库存标识
kdauf LIKE goitem-kdauf , " 销售订单
kdpos LIKE goitem-kdpos , " 行项目
bklas LIKE mbew-bklas , " 系统评估类
vprsv LIKE mbew-vprsv , " 系统价格控制
stprs LIKE mbew-stprs , " 系统标准单价
zprice LIKE goitem-dmbtr , " 系统计算总价
class LIKE klah-class , " 系统分类代码
-
zflbm(20) , " 分类代码
-
mwert01 LIKE rctms-mwert , " 特性1
-
mwert02 LIKE rctms-mwert , " 特性2
-
mwert03 LIKE rctms-mwert , " 特性3
-
mwert04 LIKE rctms-mwert , " 特性4
-
mwert05 LIKE rctms-mwert , " 特性5
-
mwert06 LIKE rctms-mwert , " 特性6
-
mwert07 LIKE rctms-mwert , " 特性7
-
mwert08 LIKE rctms-mwert , " 特性8
-
mwert09 LIKE rctms-mwert , " 特性9
-
mwert10 LIKE rctms-mwert , " 特性10
-
mwert11 LIKE rctms-mwert , " 特性11
-
mwert12 LIKE rctms-mwert , " 特性12
-
END OF gt_input.mwert13 LIKE rctms-mwert , " 特性13 icon TYPE icon_d, "图标
DATA gt_input_hd LIKE TABLE OF gt_input WITH HEADER LINE.
DATA gt_input_it LIKE TABLE OF gt_input WITH HEADER LINE.
DATA BEGIN OF iexcel OCCURS 0. " excel上载内表
INCLUDE STRUCTURE alsmex_tabline.
DATA END OF iexcel.
DATA: error TYPE REF TO cx_root,
lv_message TYPE string.
DATA: gv_message_h TYPE string,
gv_message_i TYPE string,
gv_msg_h TYPE string,
gv_msg_i TYPE string.
DATA: gv_subrc LIKE sy-subrc.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT ‘’ . "文件目录.
SELECTION-SCREEN SKIP.
*
*PARAMETERS: R1 RADIOBUTTON GROUP RG1,
-
R2 RADIOBUTTON GROUP RG1.
SELECTION-SCREEN: END OF BLOCK b1.
INITIALIZATION.
sscrfields-functxt_01 = ‘模板下载’.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_filename.
** 权限检查
- PERFORM AUTHORITY_CHECK.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm .
WHEN ‘FC01’.
DATA rec_objdata LIKE wwwdatatab.
rec_objdata-relid = ‘MI’.
rec_objdata-objid = ‘ZMMCP005’.
** 下载模版
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT’
EXPORTING
key = rec_objdata
destination = p_file.
WHEN OTHERS.
ENDCASE.
*-----------------------------------------------------------------------
- START-OF-SELECTION
*-----------------------------------------------------------------------
START-OF-SELECTION.
PERFORM read_data .
PERFORM check_data .
PERFORM initialize_fieldcat .
PERFORM build_layout .
PERFORM display_alv TABLES gt_input[].
&---------------------------------------------------------------------
*& Form READ_DATA
&---------------------------------------------------------------------
-
text
----------------------------------------------------------------------
- –> p1 text
- <-- p2 text
----------------------------------------------------------------------
FORM read_data .
FIELD-SYMBOLS <fs_excel> LIKE LINE OF iexcel.
CLEAR: iexcel[],
iexcel.
*上载excel文件
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 3
i_end_col = 50
i_end_row = 5000
TABLES
intern = iexcel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'EXCEL 上载失败 ', p_file, sy-subrc.
STOP.
ELSE.
SORT iexcel BY row col.
ENDIF.
*excel内表中的数据放到内表中
LOOP AT iexcel ASSIGNING <fs_excel> .
- CONDENSE <fs_excel>-value NO-GAPS.
CASE <fs_excel>-col.
WHEN 1. "开始
gt_input-zks = <fs_excel>-value.
WHEN 2. "结束
gt_input-zjs = <fs_excel>-value.
WHEN 4. "凭证日期
gt_input-bldat = <fs_excel>-value.
WHEN 5. "过账日期
gt_input-budat = <fs_excel>-value.
WHEN 6. "移动类型
gt_input-bwart = <fs_excel>-value.
WHEN 7. "抬头文本
gt_input-bktxt = <fs_excel>-value.
WHEN 8. "工厂
gt_input-werks = <fs_excel>-value.
WHEN 9. "库存地点
gt_input-lgobe = <fs_excel>-value.
WHEN 10. "序号
gt_input-zxh = <fs_excel>-value.
WHEN 11. "物料
gt_input-matnr = <fs_excel>-value.
WHEN 12. "物料描述
gt_input-maktx = <fs_excel>-value.
WHEN 13. "批次
gt_input-charg = <fs_excel>-value.
WHEN 14. "数量
gt_input-erfmg = <fs_excel>-value.
WHEN 15. "计量单位
gt_input-meins = <fs_excel>-value.
WHEN 16. "总金额
gt_input-dmbtr = <fs_excel>-value.
WHEN 17. "特殊库存标识
gt_input-sobkz = <fs_excel>-value.
WHEN 18. "销售订单
gt_input-kdauf = <fs_excel>-value.
WHEN 19. "行项目
gt_input-kdpos = <fs_excel>-value.
ENDCASE.
AT END OF row.
APPEND gt_input. CLEAR gt_input.
ENDAT.
ENDLOOP.
ENDFORM. "READ_DATA
FORM check_data .
DATA:l_tabix LIKE sy-tabix.
DATA:l_start_flag,l_end_flag.
DATA:l_lsh TYPE i,l_hxm TYPE i.
LOOP AT gt_input.
IF gt_input-zks = ‘S’.
l_lsh = l_lsh + 1.
l_hxm = 1.
ELSE.
l_hxm = l_hxm + 1.
ENDIF.
gt_input-zlsh = l_lsh.
gt_input-zhxm = l_hxm.
-
zhxm
MODIFY gt_input INDEX sy-tabix.
ENDLOOP.LOOP AT gt_input WHERE zks = ‘S’ .
gt_input_hd = gt_input.
APPEND gt_input_hd.
ENDLOOP.LOOP AT gt_input.
l_tabix = sy-tabix.
READ TABLE gt_input_hd WITH KEY zlsh = gt_input-zlsh.
CLEAR: gt_input-zmess_h,gt_input-zmess_i,gt_input-icon,gv_msg_h,gv_message_h,gv_msg_i,gv_message_i.
IF gt_input-zks = ‘S’ OR gt_input-zks IS INITIAL.
ELSE.
gt_input-icon = icon_led_red.
gv_msg_h = ‘凭证开始标识不为S’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-zjs = ‘E’ OR gt_input-zjs IS INITIAL.
ELSE.
gt_input-icon = icon_led_red.
gv_msg_h = ‘凭证结束标识不为E’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-zks = ‘S’ AND l_end_flag <> ‘E’ AND l_tabix <> 1.
gt_input-icon = icon_led_red.
gv_msg_h = ‘上笔记录缺少凭证结束标识E’.
append_str gv_message_h gv_msg_h.
ENDIF.IF l_end_flag = ‘E’ AND gt_input-zks <> ‘S’ .
gt_input-icon = icon_led_red.
gv_msg_h = ‘凭证开始标识不为S’.
append_str gv_message_h gv_msg_h.
ENDIF.CLEAR l_end_flag.
IF gt_input-zks = ‘S’ AND gt_input-bldat IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_h = ‘凭证日期不能为空’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-bldat IS NOT INITIAL AND gt_input-zks <> ‘S’ .
gt_input-icon = icon_led_red.
gv_msg_h = ‘凭证开始标识不为S’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-zks = ‘S’ AND gt_input-budat IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_h = ‘过账日期不能为空’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-zks = ‘S’ AND gt_input-bwart IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_h = ‘移动类型不能为空’.
append_str gv_message_h gv_msg_h.
ENDIF.IF gt_input-werks IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘工厂不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input-lgobe IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘库存地点不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input-zxh IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘序号不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input-matnr IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘物料不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input-maktx IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘物料描述不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input-erfmg IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘数量不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input_hd-sobkz = ‘K’ AND gt_input-lifnr IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘供应商不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF.IF gt_input_hd-sobkz = ‘W’ AND gt_input-kunnr IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = ‘客户不能为空’.
append_str gv_message_i gv_msg_i.
ENDIF. -
IF gt_input-dmbtr IS INITIAL.
-
gt_input-icon = icon_led_red.
-
gv_msg_i = '总金额不能为空'.
-
append_str gv_message_i gv_msg_i.
-
ENDIF.
IF gt_input-xchar = 'X' AND gt_input-charg IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = '批次不能为空'.
append_str gv_message_i gv_msg_i.
ENDIF.
- IF GT_INPUT-XCHAR = ‘X’ AND GT_INPUT-ZFLBM IS INITIAL .
-
GT_INPUT-ICON = ICON_LED_RED.
-
GV_MSG_I = '分类代码不能为空'.
-
APPEND_STR GV_MESSAGE_I GV_MSG_I.
- ENDIF.
*********系统取值
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' "物料前导零
EXPORTING
input = gt_input-matnr
IMPORTING
output = gt_input-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
*批次启用标识
SELECT SINGLE xchar
INTO gt_input-xchar
FROM marc
WHERE matnr = gt_input-matnr
AND werks = gt_input-werks.
*工厂名称
SELECT SINGLE name1
INTO gt_input-name1
FROM t001w
WHERE werks = gt_input-werks.
*计量单位
SELECT SINGLE meins
INTO gt_input-meins
FROM mara
WHERE matnr = gt_input-matnr.
*系统标准单价
SELECT SINGLE stprs bklas vprsv
INTO ( gt_input-stprs,gt_input-bklas,gt_input-vprsv )
FROM mbewh
WHERE matnr = gt_input-matnr
AND bwkey = gt_input-werks
AND lfgja = ‘2018’
AND lfmon = ‘12’.
-
AND vprsv = 'S'.
*系统计算总价
gt_input-zprice = gt_input-erfmg * gt_input-stprs.
*系统分类代码
IF gt_input-xchar = ‘X’.
SELECT SINGLE klah~class
INTO gt_input-class
FROM inob
INNER JOIN kssk
ON inob~cuobj = kssk~objek
INNER JOIN klah
ON kssk~clint = klah~clint
WHERE inob~obtab = ‘MARA’
AND inob~objek = gt_input-matnr.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gt_input-kdauf
IMPORTING
output = gt_input-kdauf.
IF gt_input-xchar IS NOT INITIAL AND gt_input-charg IS INITIAL.
gt_input-icon = icon_led_red.
gv_msg_i = '批次不能为空'.
append_str gv_message_i gv_msg_i.
ENDIF.
-
IF GT_INPUT-XCHAR IS NOT INITIAL AND GT_INPUT-ZFLBM IS INITIAL AND R2 IS NOT INITIAL.
-
GT_INPUT-ICON = ICON_LED_RED.
-
GV_MSG_I = '分类代码不能为空'.
-
APPEND_STR GV_MESSAGE_I GV_MSG_I.
-
ENDIF.
-
IF GT_INPUT-CLASS <> GT_INPUT-ZFLBM AND R2 IS NOT INITIAL.
-
GT_INPUT-ICON = ICON_LED_RED.
-
GV_MSG_I = '分类代码与系统分类代码不一致'.
-
APPEND_STR GV_MESSAGE_I GV_MSG_I.
-
ENDIF.
IF gv_message_h IS NOT INITIAL.
gt_input-zmess_h = gv_message_h.
ENDIF.
IF gv_message_i IS NOT INITIAL.
gt_input-zmess_i = gv_message_i.
ENDIF.
IF gt_input-zjs = 'E'.
l_end_flag = 'E'.
ENDIF.
MODIFY gt_input INDEX l_tabix.
ENDLOOP.
ENDFORM.
FORM get_filename .
CALL FUNCTION ‘WS_FILENAME_GET’
EXPORTING
def_path = ‘C’
mask = ‘,Excel,.XLSX;.XLS.’
title = ‘选择文件’
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0 AND sy-subrc = 3.
MESSAGE ‘选择文件出错’ TYPE ‘I’ DISPLAY LIKE ‘E’.
STOP.
ENDIF.
ENDFORM. "GET_FILENAME
FORM build_layout .
it_layout-zebra = ‘X’.
it_layout-detail_popup = ‘X’.
it_layout-colwidth_optimize = ‘X’.
ENDFORM.
FORM initialize_fieldcat .
- initial_field ‘ZLSH’ ‘流水号’ ‘’ ‘’ ‘’ ‘’ ‘’.
- initial_field ‘ZHXM’ ‘行项目’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ICON’ ‘状态’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZMESS_H’ ‘抬头消息’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZMESS_I’ ‘行项目消息’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZKS’ ‘开始’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZJS’ ‘结束’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘BLDAT’ ‘凭证日期’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘BUDAT’ ‘过账日期’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘BWART’ ‘移动类型’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘BKTXT’ ‘抬头文本’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZEMNUM’ ‘工号’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZPRJVD’ ‘施工单位’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘WERKS’ ‘工厂’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘NAME1’ ‘工厂名称’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘LGOBE’ ‘库存地点’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZXH’ ‘序号’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘MATNR’ ‘物料’ ‘X’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘MAKTX’ ‘物料描述’ ‘’ ‘’ ‘’ ‘’ ‘’. - INITIAL_FIELD ‘XCHAR’ ‘批次启用标识’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘CHARG’ ‘批次’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ERFMG’ ‘数量’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘MEINS’ ‘计量单位’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘LIFNR’ ‘供应商’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘KUNNR’ ‘客户’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘DMBTR’ ‘总金额’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘SOBKZ’ ‘特殊库存标识’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘KDAUF’ ‘销售订单’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘KDPOS’ ‘行项目’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘BKLAS’ ‘评估类’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘VPRSV’ ‘价格控制’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘STPRS’ ‘标准单价’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘ZPRICE’ ‘系统计算总价’ ‘’ ‘’ ‘’ ‘’ ‘’.
initial_field ‘CLASS’ ‘系统分类代码’ ‘’ ‘’ ‘’ ‘’ ‘’. - INITIAL_FIELD ‘ZFLBM’ ‘分类代码’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT01’ ‘特性1’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT02’ ‘特性2’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT03’ ‘特性3’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT04’ ‘特性4’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT05’ ‘特性5’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT06’ ‘特性6’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT07’ ‘特性7’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT08’ ‘特性8’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT09’ ‘特性9’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT10’ ‘特性10’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT11’ ‘特性11’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT12’ ‘特性12’ ‘’ ‘’ ‘’ ‘’ ‘’.
- INITIAL_FIELD ‘MWERT13’ ‘特性13’ ‘’ ‘’ ‘’ ‘’ ‘’.
ENDFORM. " INITIALIZE_FIELDCAT
&---------------------------------------------------------------------
*& Form WRITE_BAPILOG_ALV
&---------------------------------------------------------------------
-
text
----------------------------------------------------------------------
-
-->P_IT_DOC_RETURN text
----------------------------------------------------------------------
FORM display_alv TABLES p_table STRUCTURE gt_input.
CLEAR:wa_excluding,it_excluding.
*设置要隐藏的FCODE
- wa_excluding-fcode = ‘SAV_DATA’.
- APPEND wa_excluding TO it_excluding.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = sy-repid
is_layout = it_layout
it_fieldcat = it_fieldcat
-
TABLESIT_EVENTS = I_EVENTS i_callback_pf_status_set = 'SET_PF_STATUS' i_callback_user_command = 'USER_COMMAND' i_default = 'X' i_save = 'A'
t_outtab = p_table
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ‘显示错误.’ TYPE ‘W’.
STOP.
ENDIF.
ENDFORM. " WRITE_BAPILOG_ALV
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
rt_extab = it_excluding.
- IF R1 = ‘X’.
SET PF-STATUS ‘STANDARD’. "EXCLUDING rt_extab. - ELSE.
- SET PF-STATUS ‘ST200’. "EXCLUDING rt_extab.
- SET TITLEBAR ‘TIT100’ WITH ‘批次库存特性信息补导入’.
- ENDIF.
ENDFORM. "SET_PF_STATUS
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lt_params LIKE rsparams OCCURS 0 WITH HEADER LINE.
DATA:l_index TYPE i.
DATA: l_varid TYPE varid.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid,
is_stable TYPE lvc_s_stbl.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CASE r_ucomm.
WHEN ‘TEST’.
PERFORM frm_imp_data_test.
CALL METHOD lr_grid->refresh_table_display
EXPORTING
is_stable = is_stable.
WHEN 'IMPORT'.
PERFORM frm_imp_data.
-
CLEAR: gt_input,gt_input[]. CALL METHOD lr_grid->refresh_table_display EXPORTING is_stable = is_stable.
WHEN ‘IMPORT1’.
PERFORM frm_imp_data_1. CALL METHOD lr_grid->refresh_table_display EXPORTING is_stable = is_stable.
-
WHEN ‘EXIT’.
-
LEAVE PROGRAM.
-
WHEN ‘BACK’.
-
LEAVE TO SCREEN 0.
-
WHEN ‘CANC’.
-
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDFORM. "user_command
DATA:g_header LIKE bapi2017_gm_head_01.
DATA:g_mat LIKE bapi2017_gm_head_ret-mat_doc.
DATA:gt_item LIKE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.
DATA:gt_ret LIKE TABLE OF bapiret2 WITH HEADER LINE.
DATA gs_bapi_te_xmkpf TYPE bapi_te_xmkpf.
DATA: gt_ext LIKE TABLE OF bapiparex WITH HEADER LINE.
DATA:txt(255) TYPE c.
DATA:code TYPE bapi2017_gm_code.
FORM frm_imp_data_test.
DATA:l_answer TYPE c.
DATA:l_subrc TYPE sy-subrc.
CLEAR: g_header,g_mat,gt_item,gt_item[],gt_ret,gt_ret[],txt,code.
IF gt_input[] IS INITIAL.
MESSAGE e001(00) WITH ‘无批导数据’.
ENDIF.
READ TABLE gt_input WITH KEY icon = icon_led_red.
IF sy-subrc = 0.
MESSAGE e001(00) WITH ‘导入数据存在错误’.
ENDIF.
READ TABLE gt_input INDEX 1.
IF gt_input-zmess_i IS NOT INITIAL.
MESSAGE e001(00) WITH ‘已生成物料凭证’.
ENDIF.
-
CALL FUNCTION ‘POPUP_TO_CONFIRM’
-
EXPORTING
-
titlebar = '提示'
-
text_question = '是否确认导入期初库存'
-
text_button_1 = '确认'
-
text_button_2 = '取消'
-
default_button = '2'
-
display_cancel_button = ' '
-
popup_type = 'ICON_MESSAGE_WARNING'
-
IMPORTING
-
answer = l_answer
-
EXCEPTIONS
-
text_not_found = 1
-
OTHERS = 2.
-
CHECK l_answer = ‘1’.
REFRESH gt_ext.
LOOP AT gt_input_hd.CLEAR:gt_input_it,gt_input_it[].
LOOP AT gt_input WHERE zlsh = gt_input_hd-zlsh.
gt_input_it = gt_input.
APPEND gt_input_it.
ENDLOOP.
SORT gt_input_it BY zlsh zhxm.
BAPI*************
CLEAR: g_header,gt_item,gt_item[].
g_header-pstng_date = gt_input_hd-budat. " 凭证日期
g_header-doc_date = gt_input_hd-bldat. " 过账日期
g_header-header_txt = gt_input_hd-bktxt. " 抬头文本
- "* header增强字段
- gs_bapi_te_xmkpf-zemnum = gt_input_hd-zemnum.
- gs_bapi_te_xmkpf-zprjvd = gt_input_hd-zprjvd.
- gt_ext-structure = ‘BAPI_TE_XMKPF’.
- gt_ext-valuepart1 = gs_bapi_te_xmkpf.
- APPEND gt_ext.
- CLEAR gt_ext.
- CLEAR gs_bapi_te_xmkpf.
" 移动类型
IF gt_input_hd-bwart = '201' OR gt_input_hd-bwart = '202' OR gt_input_hd-bwart = '551'
OR gt_input_hd-bwart = '552' OR gt_input_hd-bwart = '261' OR gt_input_hd-bwart = '262'.
code = '03'.
ELSEIF gt_input_hd-bwart = '701' OR gt_input_hd-bwart = '702' OR gt_input_hd-bwart = '561' OR gt_input_hd-bwart = '562' .
code = '05'.
ELSE.
code = '04'.
ENDIF.
LOOP AT gt_input_it .
gt_item-batch = gt_input_it-charg . " 批次
gt_item-material = gt_input_it-matnr. " 物料
gt_item-plant = gt_input_it-werks. " 工厂
gt_item-stge_loc = gt_input_it-lgobe. " 库存地点
gt_item-move_type = gt_input_hd-bwart. " 移动类型
gt_item-entry_qnt = gt_input_it-erfmg. " 数量
gt_item-entry_uom = gt_input_it-meins. " 计量单位
gt_item-spec_stock = gt_input_it-sobkz. "特殊库存标识
gt_item-val_sales_ord = gt_input_it-kdauf. "销售订单
gt_item-val_s_ord_item = gt_input_it-kdpos. "销售订单行项目
-
gt_item-vendor = gt_input_hd-lifnr. "供应商
-
gt_item-customer = gt_input_hd-kunnr. "客户
-
gt_item-amount_lc = gt_input_hd-zprice. " 总金额 zprice gt_item-amount_lc = gt_input_it-dmbtr. " 金额 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "供应商 EXPORTING input = gt_input_it-lifnr IMPORTING output = gt_item-vendor. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "客户 EXPORTING input = gt_input_it-kunnr IMPORTING output = gt_item-customer.
-
IF gt_input_hd-sobkz = 'W'.
-
gt_item-customer = gt_input_hd-lifnr.
-
ELSE.
-
gt_item-vendor = gt_input_hd-lifnr.
-
ENDIF. APPEND gt_item. CLEAR gt_item.
-
stprs LIKE mbew-stprs , " 系统标准单价
-
zprice LIKE goitem-dmbtr , " 系统计算总价
ENDLOOP.
IF gt_item[] IS NOT INITIAL.
PERFORM exec_bapi USING ‘X’
CHANGING gt_input_hd-zmess_h
l_subrc.
ENDIF.gt_input-zmess_h = gt_input_hd-zmess_h.
IF l_subrc = 0.
gt_input-icon = icon_led_green.
ELSE.
gt_input-icon = icon_led_red.
ENDIF.MODIFY gt_input TRANSPORTING zmess_h icon WHERE zlsh = gt_input_hd-zlsh
AND zhxm = 1.ENDLOOP.
ENDFORM.
FORM frm_imp_data.
DATA:l_answer TYPE c.
DATA:l_subrc TYPE sy-subrc.
CLEAR: g_header,g_mat,gt_item,gt_item[],gt_ret,gt_ret[],txt,code.
IF gt_input[] IS INITIAL.
MESSAGE e001(00) WITH ‘无批导数据’.
ENDIF.
READ TABLE gt_input WITH KEY icon = icon_led_red.
IF sy-subrc = 0.
MESSAGE e001(00) WITH ‘导入数据存在错误’.
ENDIF.
READ TABLE gt_input WITH KEY icon = icon_led_green.
IF sy-subrc <> 0.
MESSAGE e001(00) WITH ‘未运行导入检查’.
ENDIF.
READ TABLE gt_input INDEX 1.
IF gt_input-zmess_i IS NOT INITIAL.
MESSAGE e001(00) WITH ‘已生成物料凭证’.
ENDIF.
CALL FUNCTION ‘POPUP_TO_CONFIRM’
EXPORTING
titlebar = ‘提示’
text_question = ‘是否确认导入期初库存’
text_button_1 = ‘确认’
text_button_2 = ‘取消’
default_button = ‘2’
display_cancel_button = ’ ’
popup_type = ‘ICON_MESSAGE_WARNING’
IMPORTING
answer = l_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
CHECK l_answer = ‘1’.
REFRESH gt_ext.
LOOP AT gt_input_hd.
CLEAR:gt_input_it,gt_input_it[].
LOOP AT gt_input WHERE zlsh = gt_input_hd-zlsh.
gt_input_it = gt_input.
APPEND gt_input_it.
ENDLOOP.
SORT gt_input_it BY zlsh zhxm.
BAPI*************
CLEAR: g_header,gt_item,gt_item[].
g_header-pstng_date = gt_input_hd-budat. " 凭证日期
g_header-doc_date = gt_input_hd-bldat. " 过账日期
g_header-header_txt = gt_input_hd-bktxt. " 抬头文本
-
"* header增强字段
-
gs_bapi_te_xmkpf-zemnum = gt_input_hd-zemnum.
-
gs_bapi_te_xmkpf-zprjvd = gt_input_hd-zprjvd.
-
gt_ext-structure = ‘BAPI_TE_XMKPF’.
-
gt_ext-valuepart1 = gs_bapi_te_xmkpf.
-
APPEND gt_ext.
-
CLEAR gt_ext.
-
CLEAR gs_bapi_te_xmkpf.
-
G_HEADER-ZEMNUM = GT_INPUT_HD-ZEMNUM. " 工号
-
G_HEADER-ZPRJVD = GT_INPUT_HD-ZPRJVD. " 施工单位
" 移动类型
IF gt_input_hd-bwart = ‘201’ OR gt_input_hd-bwart = ‘202’ OR gt_input_hd-bwart = ‘551’
OR gt_input_hd-bwart = ‘552’ OR gt_input_hd-bwart = ‘261’ OR gt_input_hd-bwart = ‘262’.
code = ‘03’.
ELSEIF gt_input_hd-bwart = ‘701’ OR gt_input_hd-bwart = ‘702’ OR gt_input_hd-bwart = ‘561’ OR gt_input_hd-bwart = ‘562’ .
code = ‘05’.
ELSE.
code = ‘04’.
ENDIF.LOOP AT gt_input_it .
gt_item-batch = gt_input_it-charg . " 批次 gt_item-material = gt_input_it-matnr. " 物料 gt_item-plant = gt_input_it-werks. " 工厂 gt_item-stge_loc = gt_input_it-lgobe. " 库存地点 gt_item-move_type = gt_input_hd-bwart. " 移动类型 gt_item-entry_qnt = gt_input_it-erfmg. " 数量 gt_item-entry_uom = gt_input_it-meins. " 计量单位 gt_item-spec_stock = gt_input_it-sobkz. "特殊库存标识 gt_item-val_sales_ord = gt_input_it-kdauf. "销售订单 gt_item-val_s_ord_item = gt_input_it-kdpos. "销售订单行项目
-
gt_item-vendor = gt_input_hd-lifnr. "供应商
-
gt_item-customer = gt_input_hd-kunnr. "客户
-
gt_item-amount_lc = gt_input_hd-zprice. " 总金额 zprice gt_item-amount_lc = gt_input_it-dmbtr. " 金额 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "供应商 EXPORTING input = gt_input_it-lifnr IMPORTING output = gt_item-vendor. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "客户 EXPORTING input = gt_input_it-kunnr IMPORTING output = gt_item-customer.
-
IF gt_input_hd-sobkz = 'W'.
-
gt_item-customer = gt_item-vendor.
-
ELSE.
-
gt_item-vendor = gt_item-customer.
-
ENDIF. APPEND gt_item. CLEAR gt_item.
-
stprs LIKE mbew-stprs , " 系统标准单价
-
zprice LIKE goitem-dmbtr , " 系统计算总价
ENDLOOP.
IF gt_item[] IS NOT INITIAL.
PERFORM exec_bapi USING ‘’
CHANGING gt_input_hd-zmess_i
l_subrc.
ENDIF.gt_input-zmess_h = ‘生成物料凭证’.
gt_input-zmess_i = gt_input_hd-zmess_i.IF l_subrc = 0.
gt_input-icon = icon_led_green.
ELSE.
gt_input-icon = icon_led_red.
ENDIF.MODIFY gt_input TRANSPORTING zmess_h zmess_i icon WHERE zlsh = gt_input_hd-zlsh
AND zhxm = 1.ENDLOOP.
ENDFORM.
更改物料特性BAPI变量******BEGIN
DATA: g_objek TYPE cuobn.
DATA: g_obtab TYPE tabelle.
DATA: g_klart TYPE klassenart.
DATA: g_class TYPE klasse_d.
DATA:g_objectkey LIKE bapi1003_key-object.
DATA:g_objecttable LIKE bapi1003_key-objecttable.
DATA:g_classnum LIKE bapi1003_key-classnum.
DATA:g_classtype LIKE bapi1003_key-classtype.
DATA:g_objectkey_long LIKE bapi1003_key-object_long.
DATA:gt_allocvaluesnumnew LIKE TABLE OF bapi1003_alloc_values_num WITH HEADER LINE.
DATA:gt_allocvaluescharnew LIKE TABLE OF bapi1003_alloc_values_char WITH HEADER LINE.
DATA:gt_allocvaluescurrnew LIKE TABLE OF bapi1003_alloc_values_curr WITH HEADER LINE.
DATA:gt_return LIKE TABLE OF bapiret2 WITH HEADER LINE.
更改物料特性BAPI变量******END
DATA:g_no(2) TYPE n . "当前字段
DATA g_field(50).
FIELD-SYMBOLS <fs_m>.
DATA: g_index TYPE i.
DATA g_msg TYPE string.
*特性值内表
DATA g_clint LIKE klah-clint.
DATA gt_ksml LIKE TABLE OF ksml WITH HEADER LINE.
DATA gs_cabn LIKE cabn.
FORM frm_imp_data_1 .
DATA:l_answer TYPE c.
DATA:l_subrc TYPE sy-subrc.
CLEAR: g_header,g_mat,gt_item,gt_item[],gt_ret,gt_ret[],txt,code.
IF gt_input[] IS INITIAL.
MESSAGE e001(00) WITH ‘无批导数据’.
ENDIF.
READ TABLE gt_input WITH KEY icon = icon_led_red.
IF sy-subrc = 0.
MESSAGE e001(00) WITH ‘导入数据存在错误’.
ENDIF.
CLEAR:gt_input_it,gt_input_it[].
LOOP AT gt_input WHERE class IS NOT INITIAL.
gt_input_it = gt_input.
APPEND gt_input_it.
ENDLOOP.
SORT gt_input_it BY zlsh zhxm.
*******更改物料特性BAPIBEGIN
LOOP AT gt_input_it.
CALL FUNCTION 'VB_BATCH_2_CLASS_OBJECT'
EXPORTING
i_matnr = gt_input_it-matnr "物料编号
i_charg = gt_input_it-charg "批次
i_werks = gt_input_it-werks "工厂
IMPORTING
e_objek = g_objek "对象名 (物料 + 批次) '000000101110001013 Y121710003'
e_obtab = g_obtab "'MCH1'
e_klart = g_klart "类别种类 '023'
e_class = g_class. "类别 'Z_101306_001'.
*特性类别
g_objectkey = g_objek. "对象名 (物料 + 批次)
g_objecttable = g_obtab. "'MCH1'
g_classnum = g_class. ""类别
g_classtype = g_klart. "类别种类
g_objectkey_long = g_objek."对象名 (物料 + 批次)
SELECT SINGLE clint
INTO g_clint
FROM klah
WHERE klart = g_classtype
AND class = g_classnum.
IF sy-subrc = 0.
SELECT *
INTO TABLE gt_ksml
FROM ksml
WHERE clint = g_clint.
ENDIF.
SORT gt_ksml BY clint posnr.
LOOP AT gt_ksml WHERE posnr <= 13.
SELECT SINGLE *
INTO gs_cabn
FROM cabn
WHERE atinn = gt_ksml-imerk.
g_index = sy-tabix.
g_no = g_index.
CONCATENATE 'GT_INPUT_IT-MWERT' g_no INTO g_field.
ASSIGN (g_field) TO <fs_m>.
IF gs_cabn-atfor = 'NUM'.
IF <fs_m> IS ASSIGNED.
gt_allocvaluesnumnew-charact = gs_cabn-atnam. "'ZDY_YJ_SI'
gt_allocvaluesnumnew-value_from = <fs_m>.
APPEND gt_allocvaluesnumnew.
ENDIF.
ELSEIF gs_cabn-atfor = 'CHAR'.
gt_allocvaluescharnew-charact = gs_cabn-atnam. "'ZDY_YJ_SI'
gt_allocvaluescharnew-value_char = <fs_m>.
gt_allocvaluescharnew-value_neutral = <fs_m>.
gt_allocvaluescharnew-value_char_long = <fs_m>.
gt_allocvaluescharnew-value_neutral_long = <fs_m>.
APPEND gt_allocvaluescharnew.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = g_objectkey
objecttable = g_objecttable
classnum = g_classnum
classtype = g_classtype
-
STATUS = '1'
-
STANDARDCLASS =
-
CHANGENUMBER =
-
KEYDATE = SY-DATUM
-
NO_DEFAULT_VALUES = ' '
-
KEEP_SAME_DEFAULTS = ' ' objectkey_long = g_objectkey_long
-
IMPORTING
-
CLASSIF_STATUS = TABLES allocvaluesnumnew = gt_allocvaluesnumnew[] allocvaluescharnew = gt_allocvaluescharnew[] allocvaluescurrnew = gt_allocvaluescurrnew[] return = gt_return[].
READ TABLE gt_return WITH KEY type = ‘E’.
IF sy-subrc = 0.
CLEAR g_msg. LOOP AT gt_return. CONCATENATE g_msg gt_return-id gt_return-message_v1 gt_return-message_v2 gt_return-message_v3 gt_return-message_v4 gt_return-message INTO g_msg SEPARATED BY ','. CONDENSE g_msg NO-GAPS. ENDLOOP. gt_input-zmess_h = '错误'. gt_input-zmess_i = g_msg. gt_input-icon = icon_led_red.
ELSE .
gt_input-icon = icon_led_green. gt_input-zmess_h = '成功'. COMMIT WORK AND WAIT.
ENDIF.
MODIFY gt_input TRANSPORTING zmess_h zmess_i icon WHERE zlsh = gt_input_it-zlsh
AND zhxm = gt_input_it-zhxm.
*******更改物料特性BAPIEND
ENDLOOP.
ENDFORM.
&---------------------------------------------------------------------
*& Form EXEC_BAPI
&---------------------------------------------------------------------
-
text
----------------------------------------------------------------------
FORM exec_bapi USING p_test
CHANGING p_msg
p_subrc.
CALL FUNCTION ‘BAPI_GOODSMVT_CREATE’
EXPORTING
goodsmvt_header = g_header
goodsmvt_code = code
testrun = p_test
-
GOODSMVT_REF_EWM =
IMPORTING
-
GOODSMVT_HEADRET = materialdocument = g_mat
-
MATDOCUMENTYEAR =
TABLES
goodsmvt_item = gt_item[] -
GOODSMVT_SERIALNUMBER = return = gt_ret[]
-
GOODSMVT_SERV_PART_DATA = extensionin = gt_ext.
READ TABLE gt_ret WITH KEY type = ‘E’.
IF sy-subrc = 0.
LOOP AT gt_ret.
CONCATENATE p_msg
gt_ret-id
gt_ret-message_v1
gt_ret-message_v2
gt_ret-message_v3
gt_ret-message_v4
gt_ret-message
INTO p_msg SEPARATED BY ‘,’.
ENDLOOP.p_subrc = 1.
ELSE .
IF p_test = ‘X’.
p_msg = ‘测试成功’.
ELSE.
p_msg = g_mat.
COMMIT WORK AND WAIT.
ENDIF.
p_subrc = 0.
ENDIF.文章来源:https://www.toymoban.com/news/detail-651308.html
ENDFORM . "EXEC_BAPI文章来源地址https://www.toymoban.com/news/detail-651308.html
到了这里,关于ABAP 期初库存批量导入 demo1的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!