*&---------------------------------------------------------------------* *& 程序名: ZDQFI_925 *& *&---------------------------------------------------------------------* *& 抬头 : 生鲜项目原料消耗发货功能 * *& 模块 : FI * *& 作者 : * *& 创建日期 : 20180301 * *& 程序类型 : 功能报表 * *& 消息类 : zmg_fi * *& 描述 : 生鲜项目原料消耗发货功能 * *& * *& 修改记录 : * *& 日期 修改人 修改内容 * *& YYYY/MM/DD 修改人员名 说明 * *&---------------------------------------------------------------------* REPORT zdqfi_925 MESSAGE-ID 00. *&---------------------------------------------------------------------* *& INCLUDE *&---------------------------------------------------------------------* INCLUDE zdqfi_925_top. "Type/Data *INCLUDE zxxxxxxxx_class. "Class INCLUDE zdqfi_925_selscr. "Selection screen INCLUDE zdqfi_925_form. "Form *INCLUDE zxxxxxxxx_module. "Module *&---------------------------------------------------------------------* *& 初始化处理 *&---------------------------------------------------------------------* INITIALIZATION. * PERFORM xxxxxxx. *&---------------------------------------------------------------------* *& 选择屏幕控制 *&---------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. * PERFORM xxxxxxx. *&---------------------------------------------------------------------* *& 参数输入检查 *&---------------------------------------------------------------------* AT SELECTION-SCREEN. * PERFORM xxxxxxx. *&---------------------------------------------------------------------* *& 程序开始处理 *&---------------------------------------------------------------------* START-OF-SELECTION. PERFORM frm_check_run. PERFORM frm_get_data. "取数,过滤数据 逻辑 PERFORM frm_pro_doc. "处理数据 *&---------------------------------------------------------------------* *& 程序结束处理 *&---------------------------------------------------------------------* END-OF-SELECTION. PERFORM frm_alv_data. "alv显示数据 *&---------------------------------------------------------------------* *& Form frm_check_run *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_check_run . DATA:ls_zfit1004 TYPE zfit1004. "加锁配置表. DATA:ls_zruning_lock TYPE zruning_lock. "加锁配置表. IF p_ccl = ‘X‘. IF sy-batch = ‘X‘. MESSAGE ‘重处理只能前台手工处理!‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. SELECT SINGLE * FROM zfit1004 INTO ls_zfit1004 WHERE usnam = sy-uname. IF sy-subrc <> 0. MESSAGE ‘请联系产品维护权限!‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. ENDIF. SELECT SINGLE * FROM zruning_lock INTO ls_zruning_lock WHERE zprogram = sy- repid AND flag = ‘X‘. IF sy-subrc EQ 0. DO. *加锁 CALL FUNCTION ‘ENQUEUE_EZ_ZRUNING_LOCK‘ EXPORTING mode_zruning_lock = ‘X‘ mandt = sy-mandt zprogram = sy-repid _scope = ‘1‘ EXCEPTIONS foreign_lock = 1 system_failure = 2 OTHERS = 3. IF sy-subrc = 0. EXIT. ELSE. IF sy-batch = ‘X‘. WAIT UP TO 10 SECONDS. ELSE. MESSAGE ‘该程序已有其他用户在运行,请稍候再试!‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. ENDIF. ENDDO. ELSE. MESSAGE ‘请维护加锁配置表ZRUNING_LOCK!‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. " frm_check_run *&---------------------------------------------------------------------* *& Form frm_get_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_data . DATA: lr_status TYPE RANGE OF zdestatus01, ls_status LIKE LINE OF lr_status. DATA: lt_zfit1048 LIKE TABLE OF zfit1048, ls_zfit1048 LIKE zfit1048. FIELD-SYMBOLS: <lf_alv> LIKE LINE OF gt_alv. ls_status(3) = ‘IEQ‘. IF p_ccl = ‘X‘. ls_status-low = ‘C‘. APPEND ls_status TO lr_status. ELSE. ls_status-low = ‘E‘. APPEND ls_status TO lr_status. ls_status-low = ‘‘. APPEND ls_status TO lr_status. ENDIF. **取主数据 SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_alv FROM zfit1048 WHERE zdate_js IN s_zdate AND ajust_date IN s_adate AND mblnr IN s_mblnr AND iblnr IN s_iblnr AND status IN lr_status. SORT gt_alv BY iblnr mblnr. IF gt_alv[] IS INITIAL. MESSAGE ‘查询不到符合条件的数据‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. **不是重处理时,需先设置C状态,然后释放程序锁 IF p_ccl <> ‘X‘. LOOP AT gt_alv ASSIGNING <lf_alv>. MOVE-CORRESPONDING <lf_alv> TO ls_zfit1048. ls_zfit1048-status = ‘C‘. APPEND ls_zfit1048 TO lt_zfit1048. ENDLOOP. MODIFY zfit1048 FROM TABLE lt_zfit1048. IF sy-subrc = 0. COMMIT WORK AND WAIT. ELSE. ROLLBACK WORK. MESSAGE ‘更新处理数据C状态到表ZFIT1048失败‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. LEAVE LIST-PROCESSING. ENDIF. ENDIF. PERFORM frm_release_lock. ENDFORM. " frm_get_data *&---------------------------------------------------------------------* *& Form frm_pro_doc *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_pro_doc . FIELD-SYMBOLS: <lf_alv> LIKE LINE OF gt_alv. **定义货物移动(MB11)收货过账的结构和变量 DATA: ls_heade LIKE bapi2017_gm_head_01. DATA: ls_code LIKE bapi2017_gm_code. * DATA: ls_testrun LIKE bapi2017_gm_gen-testrun. DATA: ls_goodsmvt_headret LIKE bapi2017_gm_head_ret. DATA: ls_materialdocument LIKE bapi2017_gm_head_ret-mat_doc. DATA: ls_matdocumentyear LIKE bapi2017_gm_head_ret-doc_year. DATA: ls_goodsmvt_item LIKE bapi2017_gm_item_create, lt_goodsmvt_item LIKE TABLE OF bapi2017_gm_item_create, ls_goodsmvt_serialnumber LIKE bapi2017_gm_serialnumber, lt_goodsmvt_serialnumber LIKE TABLE OF bapi2017_gm_serialnumber, ls_return LIKE bapiret2 , lt_return LIKE TABLE OF bapiret2 . DATA: lv_xblnr LIKE bkpf-xblnr, lv_zuonr LIKE bseg-zuonr. DATA: l_error TYPE c, l_msg TYPE string. DATA: ls_bkpf LIKE bkpf, ls_bseg LIKE bseg, lv_awkey LIKE bkpf-awkey. **处理数据 LOOP AT gt_alv ASSIGNING <lf_alv>. CLEAR: ls_heade, ls_goodsmvt_headret,ls_materialdocument, ls_matdocumentyear, lt_goodsmvt_item, lt_goodsmvt_serialnumber,lt_return. **s1.抬头赋值: *凭证日期:调整日期AJUST_DATE *记账日期:当屏幕输入的BUDAT为空,则取调整日期AJUST_DATE,否则取屏幕输入BUDAT ls_code-gm_code = ‘06‘. "MB11执行货物移 动收货,标准收货 ls_heade-doc_date = <lf_alv>-ajust_date. "凭证日期 IF p_budat IS INITIAL. ls_heade-pstng_date = <lf_alv>-ajust_date. "记账日期 ELSE. ls_heade-pstng_date = p_budat. ENDIF. ls_heade-pr_uname = sy-uname. "用户名 **is_heade-header_txt = ‘[ERP2.0]自营库存平台一期‘. "抬头文本 **s2.项目赋值: *商品:取数为存表中的MATNR; *数量:取数为存表中的DIFMG; *批次:取数为存表中的CHARG; *移动类型:需根据DIFMG差异数量判断: *当DIFMG差异数量不存在‘-’是,R3调用MB11增加库存,移动类型默认为Y52; *当DIFMG差异数量存在‘-’是,R3调用MB11减少库存,移动类型默认为Y51; *地点:WERKS 工厂 *库存地点:LGORT 库存地点 ls_goodsmvt_item-material = <lf_alv>-matnr. "商品号 ls_goodsmvt_item-sales_ord = <lf_alv>-difmg. "数量 ls_goodsmvt_item-plant = <lf_alv>-werks. "工厂 ls_goodsmvt_item-move_plant = <lf_alv>-werks. "工厂11/18 ls_goodsmvt_item-stge_loc = <lf_alv>-lgort. "库存地点 ls_goodsmvt_item-move_stloc = <lf_alv>-lgort. "库存地点 11/18 ls_goodsmvt_item-batch = <lf_alv>-charg. "批号 IF <lf_alv>-difmg > 0. ls_goodsmvt_item-move_type = ‘Y52‘. "移动类型 ELSE. ls_goodsmvt_item-move_type = ‘Y51‘. ENDIF. **s3.细节赋值 *仓储类型:默认为999; *仓位:默认为999; *分配:输入MBLNR SIMS MD 单号; *文本:输入JUST_DATE 调整日期+ ‘确认销售发货成本(盘点)’ *参照:输入IBLNR SIMS MD 单号 ls_goodsmvt_item-entry_uom = <lf_alv>-meins. "单位 ls_goodsmvt_item-stge_type = ‘999‘. "仓储类型 ls_goodsmvt_item-stge_bin = ‘999‘. "仓位 CONCATENATE <lf_alv>-ajust_date ‘确认销售发货成本(盘点)‘ INTO ls_goodsmvt_item-item_text. APPEND ls_goodsmvt_item TO lt_goodsmvt_item. CLEAR: ls_goodsmvt_item. ***Export分配和参照,在ZGGBS002替代程序里Import ***去替代商品凭证对应会计凭证分配和参照 MOVE <lf_alv>-iblnr TO lv_xblnr. MOVE <lf_alv>-mblnr TO lv_zuonr. EXPORT lv_xblnr TO MEMORY ID ‘LV_XBLNR‘."抬头参照 EXPORT lv_zuonr TO MEMORY ID ‘LV_ZUONR‘."行分配 break 88392028. **GR CREATE CALL FUNCTION ‘BAPI_GOODSMVT_CREATE‘ EXPORTING goodsmvt_header = ls_heade goodsmvt_code = ls_code IMPORTING goodsmvt_headret = ls_goodsmvt_headret materialdocument = ls_materialdocument matdocumentyear = ls_matdocumentyear TABLES goodsmvt_item = lt_goodsmvt_item goodsmvt_serialnumber = lt_goodsmvt_serialnumber return = lt_return. LOOP AT lt_return INTO ls_return WHERE type = ‘E‘ OR type = ‘A‘. CONCATENATE l_msg ls_return-message INTO l_msg. l_error = ‘X‘. ENDLOOP. IF l_error = ‘X‘. CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. <lf_alv>-status_fh = ‘E‘. CONCATENATE ‘生成商品凭证失败!‘ l_msg INTO <lf_alv>-message_fh. ELSE. * 返回商品凭证号,提交 CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘ EXPORTING wait = ‘X‘. <lf_alv>-status_fh = ‘S‘. <lf_alv>-mblnr_fh = ls_materialdocument. <lf_alv>-message_fh = ‘生成商品凭证成功!‘. **商品凭证成功,通过MBLNR_FH+年度 取会计凭证 CLEAR: ls_bkpf, ls_bseg, lv_awkey. CONCATENATE ls_materialdocument ls_matdocumentyear INTO lv_awkey. SELECT SINGLE * INTO ls_bkpf FROM bkpf WHERE awkey = lv_awkey AND awtyp = ‘MKPF‘. IF sy-subrc EQ 0. SELECT SINGLE * INTO ls_bseg FROM bseg WHERE bukrs = ls_bkpf-bukrs AND belnr = ls_bkpf-belnr AND gjahr = ls_bkpf-gjahr AND hkont = ‘1243999994‘. **会计凭证回写 <lf_alv>-belnr_fh = ls_bkpf-belnr. <lf_alv>-mjahr = ls_bkpf-gjahr. <lf_alv>-bukrs3 = ls_bkpf-bukrs. <lf_alv>-budat_fh = ls_bkpf-budat. <lf_alv>-cpudt_fh = ls_bkpf-cpudt. <lf_alv>-dmbtr3 = ls_bseg-dmbtr. ENDIF. ENDIF. **数据回写zfit1048 UPDATE zfit1048 SET status_fh = <lf_alv>-status_fh message_fh = <lf_alv>-message_fh mblnr_fh = <lf_alv>-mblnr_fh belnr_fh = <lf_alv>-belnr_fh bukrs3 = <lf_alv>-bukrs3 dmbtr3 = <lf_alv>-dmbtr3 mjahr = <lf_alv>-mjahr budat_fh = <lf_alv>-budat_fh cpudt_fh = <lf_alv>-cpudt_fh * STATUS WHERE iblnr = <lf_alv>-iblnr AND gjahr = <lf_alv>-gjahr AND serialno = <lf_alv>-serialno AND mblnr = <lf_alv>-mblnr AND uuid = <lf_alv>-uuid. IF sy-subrc EQ 0. COMMIT WORK AND WAIT. ELSE. ROLLBACK WORK. <lf_alv>-status_fh = ‘E‘. <lf_alv>-message_fh = ‘商品凭证记账状态更新zfit1048表失败!‘. ENDIF. ENDLOOP. ENDFORM. " frm_pro_doc *&---------------------------------------------------------------------* *& Form frm_alv_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_alv_data . IF sy-batch = ‘X‘. RETURN. ENDIF. DEFINE lm_fieldcat. clear:gs_fcat. gs_fcat-tabname = ‘GT_ALV‘. gs_fcat-fieldname = &1. gs_fcat-scrtext_l = &2. gs_fcat-scrtext_m = &2. gs_fcat-scrtext_s = &2. gs_fcat-no_out = &3. gs_fcat-outputlen = &4. gs_fcat-do_sum = &5. gs_fcat-hotspot = &6. gs_fcat-ref_table = &7. gs_fcat-ref_field = &8. append gs_fcat to gt_fcat. END-OF-DEFINITION. REFRESH: gt_fcat. lm_fieldcat: ‘IBLNR ‘ ‘库存盘点凭证‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MBLNR ‘ ‘SIMS MD单号‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘, ‘WERKS ‘ ‘工厂 ‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘LGORT ‘ ‘库存地点‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MATNR ‘ ‘商品编码‘ ‘‘ ‘18‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MEINS ‘ ‘单位‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘CHARG ‘ ‘批次‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘DIFMG ‘ ‘差异数量 ‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘AJUST_DATE‘ ‘调整日期 ‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘STATUS_FH ‘ ‘商品凭证记账状态‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MESSAGE_FH‘ ‘消息 ‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MBLNR_FH ‘ ‘商品凭证‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ , ‘MJAHR ‘ ‘凭证年度‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘, ‘BELNR_FH ‘ ‘会计凭证‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ . gs_layout-zebra = ‘X‘. gs_layout-cwidth_opt = ‘X‘. * gs_layout-box_fname = ‘SEL‘. "可放出最前的选择中方块" CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘ EXPORTING i_callback_program = sy-repid i_callback_user_command = ‘FRM_USER_COMMAND‘ is_layout_lvc = gs_layout it_fieldcat_lvc = gt_fcat i_save = ‘A‘ TABLES t_outtab = gt_alv EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " frm_alv_data *&---------------------------------------------------------------------* *& Form frm_release_lock *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_release_lock . CALL FUNCTION ‘DEQUEUE_EZ_ZRUNING_LOCK‘ EXPORTING mode_zruning_lock = ‘X‘ mandt = sy-mandt zprogram = sy-repid. ENDFORM. " frm_release_lock
原文地址:https://www.cnblogs.com/rainysblog/p/8494864.html
时间: 2024-11-08 14:15:08