PP:COR6N: 批量报工程序

1 篇文章 0 订阅

PP: COR6N :批量报工程序

REPORT ZCOR6N.
&---------------------------------------------------------------------
*& 包含 ZCOR6N
&---------------------------------------------------------------------

TYPE-POOLS:slis,icon.
TABLES : sscrfields,afru.
TYPES : BEGIN OF ty_alv,
box TYPE char1, "选择框
icon TYPE char4, "状态
msg TYPE string, "消息文本
rueck TYPE afru-rueck, "确认编号
rmzhl TYPE afru-rmzhl, "确认计数器
aufnr TYPE afru-aufnr, "订单号
vornr TYPE afru-vornr, "操作/活动
gmnga TYPE afru-gmnga, "产量
ism01 TYPE afru-ism01, "直接人工
ism02 TYPE afru-ism02, "折旧
ism03 TYPE afru-ism03, "动力
ism04 TYPE afru-ism04, "物料消耗
ism05 TYPE afru-ism05, "其他制造费用
ism06 TYPE afru-ism06, "间接费用
budat TYPE afru-budat, "过账日期
eline TYPE char1, "错误行标识
END OF ty_alv.

TYPES : BEGIN OF ty_data,
aufnr TYPE afru-aufnr, "订单号
vornr TYPE afru-vornr, "操作/活动
gmnga TYPE afru-gmnga, "产量
ism01 TYPE afru-ism01, "直接人工
ism02 TYPE afru-ism02, "折旧
ism03 TYPE afru-ism03, "动力
ism04 TYPE afru-ism04, "物料消耗
ism05 TYPE afru-ism05, "其他制造费用
ism06 TYPE afru-ism06, "间接费用
budat TYPE afru-budat, "过账日期
END OF ty_data.

DATA : gt_alv TYPE TABLE OF ty_alv WITH HEADER LINE .
DATA : gt_data TYPE TABLE OF ty_data WITH HEADER LINE .

DATA:
gs_fieldcat TYPE lvc_s_fcat, "字段工作区
gt_fieldcat TYPE lvc_t_fcat,
gt_event TYPE slis_t_event WITH HEADER LINE,
gs_layout TYPE lvc_s_layo. "ALV布局工作区

DATA:gr_grid TYPE REF TO cl_gui_alv_grid.
DATA:functxt TYPE smp_dyntxt.
DATA:gv_zflag .

SELECTION-SCREEN: FUNCTION KEY 1. "在选择屏幕的应用工具条上创建第一个按钮,最多创建5个.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-t02.
PARAMETERS: p_file TYPE rlgrap-filename .
SELECTION-SCREEN END OF BLOCK b2.

INITIALIZATION.
functxt-icon_text = ‘下载模板’ .
functxt-icon_id = icon_import .
sscrfields-functxt_01 = functxt.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .
PERFORM frm_file_path. "路径

AT SELECTION-SCREEN .

CASE sscrfields-ucomm.
WHEN ‘FC01’.
PERFORM frm_download_templte.
ENDCASE.

START-OF-SELECTION.

  • PERFORM frm_auth_check. “”"权限检查
    PERFORM frm_import_data. "导入数据
    PERFORM frm_deal_data. "处理数据
    PERFORM frm_alv_show. "ALV展示

FORM frm_file_path .
DATA: lv_rc TYPE i,
lt_table TYPE filetable.

DATA : lv_initname TYPE string .

FIELD-SYMBOLS: TYPE file_table .

CLEAR: lt_table,lv_rc,lv_initname.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = ‘选择文件’
default_filename = lv_initname
file_filter = ‘Excel文件(.XLS,.XLSX)|.XLS;.XLSX|全部文件 (.)|.|’
initial_directory = ‘C:’
multiselection = ’ ’
CHANGING
file_table = lt_table
rc = lv_rc
EXCEPTIONS
cntl_error = 1
file_open_dialog_failed = 2
error_no_gui = 3.

CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.

CLEAR: p_file .

READ TABLE lt_table ASSIGNING INDEX 1.

IF sy-subrc EQ 0.
p_file = -filename.
ENDIF.

ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_DOWNLOAD_TEMPLTE
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_download_templte .

DATA: lv_objdata LIKE wwwdatatab,
lv_filename TYPE string,
lv_fullpath TYPE string VALUE ‘D:’,
lv_path TYPE string VALUE ‘D:’,
lv_destination LIKE rlgrap-filename,
lv_rc LIKE sy-subrc,
lv_errtxt TYPE string,
lv_dest LIKE sapb-sappfad,
lv_name TYPE char10 VALUE ‘ZPPF0009’.

lv_filename = ‘批量报工模板’ && sy-datum.

*-调用保存对话框
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = ‘XLSX’
default_file_name = lv_filename
*** initial_directory = ‘D:’
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
*-下载模板
IF sy-subrc = 0 AND lv_fullpath IS NOT INITIAL.
SELECT SINGLE relid
objid
FROM wwwdata
INTO CORRESPONDING FIELDS OF lv_objdata
WHERE srtf2 = 0
AND relid = ‘MI’
AND objid = lv_name.

lv_destination = lv_fullpath.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT’
EXPORTING
key = lv_objdata
destination = lv_destination
IMPORTING
rc = lv_rc
CHANGING
temp = lv_dest.
IF lv_rc <> 0.
CONCATENATE ‘模板文件:’ lv_objdata+2(13) ‘下载失败’ INTO lv_errtxt.
MESSAGE lv_errtxt TYPE ‘E’.
ENDIF.
ENDIF.
ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_IMPORT_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_import_data .
DATA:batch_data LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA:l_row TYPE i,
l_col TYPE i.
FIELD-SYMBOLS: .
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’ “读取EXCEL fuction
EXPORTING
filename = p_file
i_begin_col = 1 “””
i_begin_row = 4 “”" "读取开始行:
i_end_col = 10
i_end_row = 65535
TABLES
intern = batch_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.

IF sy-subrc <> 0.
MESSAGE ‘读取数据错误 !’ TYPE ‘S’ DISPLAY LIKE ‘E’ .
RETURN .
ELSE .

CLEAR:gt_data[],gt_data,l_row .
LOOP AT batch_data . "将读取出的数据整合到内表
l_col = batch_data-col .
ASSIGN COMPONENT l_col OF STRUCTURE gt_data TO .
IF sy-subrc = 0 AND IS ASSIGNED .
= batch_data-value .
ENDIF .
AT END OF row .
APPEND gt_data.
CLEAR: gt_data .
ENDAT .
ENDLOOP .
ENDIF.

ENDFORM.

&---------------------------------------------------------------------
*& Form FRM_DEAL_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_deal_data .
REFRESH : gt_alv.
DATA : ls_order_objects LIKE bapi_pi_order_objects.
DATA : lt_phase LIKE TABLE OF bapi_order_phase.
DATA : lt_header LIKE TABLE OF bapi_order_header1.
DATA : ls_return LIKE bapiret2.

LOOP AT gt_data .
CLEAR : gt_alv,ls_order_objects.
REFRESH : lt_phase,lt_header.

MOVE-CORRESPONDING gt_data TO gt_alv.
gt_alv-box = ‘X’.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = gt_alv-aufnr
IMPORTING
output = gt_alv-aufnr.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = gt_alv-vornr
IMPORTING
output = gt_alv-vornr.
""检查操作/活动是否存在
ls_order_objects-phases = ‘X’.
CALL FUNCTION ‘BAPI_PROCORD_GET_DETAIL’
EXPORTING
number = gt_alv-aufnr
order_objects = ls_order_objects
IMPORTING
return = ls_return
TABLES
phase = lt_phase.

LOOP AT lt_phase INTO DATA(ls_phase) WHERE superior_operation <> ‘’ AND operation_number = gt_alv-vornr.
ENDLOOP.
IF sy-subrc <> 0.
gt_alv-icon = icon_red_light.
gt_alv-msg = ‘操作/活动不存在,请检查模板数据’.
ENDIF.

ls_order_objects-header = ‘X’.
CALL FUNCTION ‘BAPI_PROCORD_GET_DETAIL’
EXPORTING
number = gt_alv-aufnr
order_objects = ls_order_objects
IMPORTING
return = ls_return
TABLES
header = lt_header.
READ TABLE lt_header INTO DATA(ls_header) INDEX 1.
FIND ‘CNF’ IN ls_header-system_status .
IF sy-subrc = 0 .
gt_alv-icon = icon_yellow_light.
gt_alv-msg = ‘已报工,是否进行多次报工’.
ELSE .
FIND ‘PCNF’ IN ls_header-system_status .
IF sy-subrc = 0 .
gt_alv-icon = icon_yellow_light.
gt_alv-msg = ‘已报工,是否进行多次报工’.
ELSE .
gt_alv-icon = icon_green_light.
gt_alv-msg = ‘检查通过,可以导入。’.
ENDIF.
ENDIF.

APPEND gt_alv.
CLEAR gt_alv.
ENDLOOP.

ENDFORM.

&---------------------------------------------------------------------
*& Form FRM_ALV_SHOW2
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_alv_show .
PERFORM field_cat USING ‘BOX’ ‘选择框’ ‘’ ‘’ ‘’ ‘X’ ‘X’ .
PERFORM field_cat USING ‘ICON’ ‘状态’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘MSG’ ‘消息’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘RUECK’ ‘确认编号’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘RMZHL’ ‘确认计数器’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘AUFNR’ ‘订单号’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘VORNR’ ‘操作/活动’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘GMNGA’ ‘产量’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM01’ ‘直接人工’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM02’ ‘折旧’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM03’ ‘动力’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM04’ ‘物料消耗’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM05’ ‘其他制造费用’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘ISM06’ ‘间接费用’ ‘’ ‘’ ‘’ ‘’ ‘’.
PERFORM field_cat USING ‘BUDAT’ ‘过账日期’ ‘’ ‘’ ‘’ ‘’ ‘’.

gs_layout-cwidth_opt = ‘X’.
gs_layout-zebra = ‘X’.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = ‘SUB_STATUS_SET’
i_callback_user_command = ‘SUB_USER_COMMAND’
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
i_save = ‘A’
TABLES
t_outtab = gt_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDFORM.
FORM field_cat USING i_fieldname i_coltext i_outputlen i_re_field i_ref_table i_checkbox i_edit .
gs_fieldcat-fieldname = i_fieldname. " 1
gs_fieldcat-coltext = i_coltext. "2
gs_fieldcat-outputlen = i_outputlen. "3
gs_fieldcat-edit = i_edit. "4
gs_fieldcat-lowercase = ‘X’.
gs_fieldcat-ref_table = i_re_field."6
gs_fieldcat-ref_field = i_ref_table."7
gs_fieldcat-checkbox = i_checkbox. "9
gs_fieldcat-no_zero = ‘X’.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDFORM.
FORM sub_status_set USING rt_extab TYPE slis_t_extab.
DATA fcode TYPE TABLE OF sy-ucomm.
SET PF-STATUS ‘ZF1000’ EXCLUDING fcode .
ENDFORM.
FORM sub_user_command USING s_ucomm TYPE sy-ucomm
re_selfield TYPE slis_selfield.

CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = gr_grid.

CALL METHOD gr_grid->check_changed_data. “触发数据变更
CASE s_ucomm.
WHEN ‘ALL’.”“全选
LOOP AT gt_alv .
gt_alv-box = ‘X’.
MODIFY gt_alv .
CLEAR gt_alv.
ENDLOOP.
WHEN ‘DALL’.”“取消全选
LOOP AT gt_alv .
gt_alv-box = ‘’.
MODIFY gt_alv .
CLEAR :gt_alv.
ENDLOOP.
WHEN ‘ANSEL’.”"反选
LOOP AT gt_alv .
IF gt_alv-box = ‘’.
gt_alv-box = ‘X’.
ELSE .
gt_alv-box = ’ '.
ENDIF.
MODIFY gt_alv .
CLEAR :gt_alv.
ENDLOOP.

WHEN ‘ZDR’.
IF gv_zflag = ’ '.
READ TABLE gt_alv TRANSPORTING NO FIELDS WITH KEY icon = icon_red_light.
IF sy-subrc = 0.
MESSAGE ‘存在错误数据不可导入!请检查数据!’ TYPE ‘E’.
ELSE .
PERFORM frm_data_dr.
gv_zflag = ‘X’.
ENDIF.
ELSE .
MESSAGE ‘不可重复导入数据!’ TYPE ‘S’ DISPLAY LIKE ‘E’.
EXIT.
ENDIF.
WHEN OTHERS .

ENDCASE.

re_selfield-refresh = ‘X’.
re_selfield-col_stable = ‘X’.
re_selfield-row_stable = ‘X’.

ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_DATA_DR
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM frm_data_dr .
DATA : ls_ret1 LIKE bapiret1.
DATA : lt_conf LIKE TABLE OF bapi_pi_timeticket1 .
DATA : ls_conf LIKE bapi_pi_timeticket1 .
DATA : lt_return LIKE TABLE OF bapi_coru_return.
DATA : ls_return LIKE bapi_coru_return.

LOOP AT gt_alv WHERE box = ‘X’ .
ls_conf-orderid = gt_alv-aufnr ."“订单
ls_conf-phase = gt_alv-vornr .”"操作/活动
ls_conf-fin_conf = ‘1’. ""确认类型
ls_conf-postg_date = gt_alv-budat. ""过账日期
ls_conf-yield = gt_alv-gmnga . ""产量

IF gt_alv-ism01 IS NOT INITIAL .
ls_conf-conf_activity1 = gt_alv-ism01 . "作业1
ENDIF.

IF gt_alv-ism02 IS NOT INITIAL .
ls_conf-conf_activity2 = gt_alv-ism02 . "作业2
ENDIF.

IF gt_alv-ism03 IS NOT INITIAL .
ls_conf-conf_activity3 = gt_alv-ism03 . "作业3
ENDIF.

IF gt_alv-ism04 IS NOT INITIAL .
ls_conf-conf_activity4 = gt_alv-ism04 . "作业4
ENDIF.

IF gt_alv-ism05 IS NOT INITIAL .
ls_conf-conf_activity5 = gt_alv-ism05. "作业5
ENDIF.

IF gt_alv-ism06 IS NOT INITIAL .
ls_conf-conf_activity6 = gt_alv-ism06. "作业6
ENDIF.

APPEND ls_conf TO lt_conf.
CLEAR ls_conf.

CALL FUNCTION ‘BAPI_PROCORDCONF_CREATE_TT’
EXPORTING
post_wrong_entries = space
testrun = space
IMPORTING
return = ls_ret1
TABLES
timetickets = lt_conf
detail_return = lt_return.

READ TABLE lt_return INTO ls_return WITH KEY type = ‘E’.
IF sy-subrc EQ 0.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’ .
gt_alv-icon = ‘@5C@’.
gt_alv-msg = ls_return-message.
MODIFY gt_alv .
CLEAR :ls_return,gt_alv.
ELSE.

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.

READ TABLE lt_return INTO ls_return WITH KEY type = ‘I’.
IF sy-subrc = 0.
gt_alv-rueck = ls_return-conf_no.
gt_alv-rmzhl = ls_return-conf_cnt.
gt_alv-icon = ‘@5B@’.
gt_alv-msg = ‘导入成功。’.
MODIFY gt_alv .
CLEAR :ls_return,gt_alv.
ENDIF.
ENDIF.

REFRESH : lt_conf ,lt_return.
ENDLOOP.

ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值