*&---------------------------------------------------------------------* *& Report ZDQFI_904 *& *&---------------------------------------------------------------------* *& 抬头 : POS杂项数据记账程序 * *& 模块 : FI * *& 作者 : * *& 创建日期 : 20180124 * *& 程序类型 : 功能报表 * *& 消息类 : zmg_fi * *& 描述 : 红孩子POS杂项数据记账程序 * *& * *& 修改记录 : * *& 日期 修改人 修改内容 * *& YYYY/MM/DD 修改人员名 说明 * *&---------------------------------------------------------------------* REPORT zdqfi_904 MESSAGE-ID zmg_fi NO STANDARD PAGE HEADING. *&---------------------------------------------------------------------* *& INCLUDE *&---------------------------------------------------------------------* INCLUDE zdqfi_904_top. "Type/Data *INCLUDE zxxxxxxxx_class. "Class INCLUDE zdqfi_904_selscr. "Selection screen INCLUDE zdqfi_904_form. "Form *INCLUDE zxxxxxxxx_module. "Module *&---------------------------------------------------------------------* *& 包括 ZDQFI_904_TOP *&---------------------------------------------------------------------* TABLES:zfit1025,sscrfields. TYPES: BEGIN OF ty_alv."ALV 表格 INCLUDE STRUCTURE zfit1025. TYPES: sel TYPE char01, END OF ty_alv. TYPES: tt_alv TYPE STANDARD TABLE OF ty_alv. DATA: gt_alv TYPE STANDARD TABLE OF ty_alv, gs_alv TYPE ty_alv. DATA: gt_item LIKE TABLE OF zfit1026, gs_item LIKE zfit1026. TYPE-POOLS:slis. DATA: gs_layout TYPE lvc_s_layo, "输出格式 gt_fieldcat TYPE lvc_t_fcat, gv_grid TYPE REF TO cl_gui_alv_grid. *&---------------------------------------------------------------------* *& 包括 ZDQFI_904_SELSCR *&---------------------------------------------------------------------* SELECT-OPTIONS: s_sum_no FOR zfit1025-sum_no, s_saleor FOR zfit1025-saleorg, s_payorg FOR zfit1025-payorg, s_date FOR zfit1025-orderdate OBLIGATORY. PARAMETERS: **如输入日期,过账日期=P_DATE,如为空,过账日期为状态日期 p_pdate TYPE budat, p_ccl AS CHECKBOX. *&---------------------------------------------------------------------* *& 初始化处理 *&---------------------------------------------------------------------* 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_post_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, lt_zfit1025 TYPE STANDARD TABLE OF zfit1025, ls_zfit1025 TYPE zfit1025, lt_zfit1026 TYPE STANDARD TABLE OF zfit1026, ls_zfit1026 TYPE zfit1026. FIELD-SYMBOLS: <ls_alv> TYPE ty_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 zfit1025 WHERE orderdate IN s_date AND sum_no IN s_sum_no AND saleorg IN s_saleor AND payorg IN s_payorg AND status IN lr_status. IF gt_alv[] IS INITIAL. MESSAGE '查询不到符合条件的数据' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. **取项目数据,并通过科目汇总金额 SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_zfit1026 FROM zfit1026 FOR ALL ENTRIES IN gt_alv WHERE sum_no = gt_alv-sum_no. IF lt_zfit1026[] IS NOT INITIAL. LOOP AT lt_zfit1026 INTO ls_zfit1026. MOVE-CORRESPONDING ls_zfit1026 TO gs_item. CLEAR gs_item-sum_item. COLLECT gs_item INTO gt_item. CLEAR: gs_item,ls_zfit1026. ENDLOOP. ENDIF. SORT gt_item BY sum_no. FREE:lt_zfit1026. **不是重处理时,需先设置C状态,然后释放程序锁 IF p_ccl <> 'X'. LOOP AT gt_alv ASSIGNING <ls_alv>. MOVE-CORRESPONDING <ls_alv> TO ls_zfit1025. ls_zfit1025-status = 'C'. APPEND ls_zfit1025 TO lt_zfit1025. ENDLOOP. MODIFY zfit1025 FROM TABLE lt_zfit1025[]. IF sy-subrc = 0. COMMIT WORK AND WAIT. ELSE. ROLLBACK WORK. MESSAGE '更新处理数据C状态到表ZSET417失败' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. ENDIF. PERFORM frm_release_lock. ENDFORM. " frm_get_data *&---------------------------------------------------------------------* *& Form frm_post_doc *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_post_doc . FIELD-SYMBOLS: <lf_alv> TYPE ty_alv. DATA: lt_item TYPE STANDARD TABLE OF zfit1026. **step1.通过pos汇总单号处理 LOOP AT gt_alv ASSIGNING <lf_alv>. lt_item = gt_item. DELETE lt_item WHERE sum_no NE <lf_alv>-sum_no. **业务类型 = 01 ,创建一张 SK 凭证, **业务类型 = 03 ,创建两张 凭证,要求同时成功 CASE <lf_alv>-transtype. WHEN '01'. PERFORM frm_post_doc_01 TABLES lt_item CHANGING <lf_alv>. WHEN '03'. PERFORM frm_post_doc_03 TABLES lt_item CHANGING <lf_alv>. WHEN OTHERS. ENDCASE. **step2.1 抬头赋值 **step2.2 项目赋值 ENDLOOP. ENDFORM. " frm_post_doc *&---------------------------------------------------------------------* *& Form frm_alv_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_alv_data . IF sy-batch = 'X'. RETURN. ENDIF. REFRESH gt_fieldcat. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'ZFIT1025' CHANGING ct_fieldcat = gt_fieldcat. DELETE gt_fieldcat WHERE fieldname = 'MANDT'. 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_fieldcat 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_USER_COMMAND *&---------------------------------------------------------------------* * 命令按钮 *----------------------------------------------------------------------* * -->I_UCOMM 命令按钮 * -->I_SELFIELD 选择值 *----------------------------------------------------------------------* FORM frm_user_command USING pi_ucomm LIKE sy-ucomm pi_selfield TYPE slis_selfield. * DATA: lr_grid TYPE REF TO cl_gui_alv_grid. * CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' * IMPORTING * e_grid = lr_grid. IF gv_grid IS INITIAL. PERFORM frm_get_grid. ENDIF. IF gv_grid IS INITIAL. MESSAGE s208(00) DISPLAY LIKE 'W' WITH '获取ALV对象失败'. RETURN. ENDIF. CALL METHOD gv_grid->check_changed_data. CASE pi_ucomm. WHEN '&IC1'. PERFORM frm_comm_2click USING pi_selfield. WHEN OTHERS. ENDCASE. pi_selfield-refresh = 'X'. pi_selfield-row_stable = 'X'. pi_selfield-col_stable = 'X'. ENDFORM. " FRM_USER_COMMAND *&---------------------------------------------------------------------* *& Form FRM_GET_GRID *&---------------------------------------------------------------------* * 获取 ALV 对象 *----------------------------------------------------------------------* FORM frm_get_grid. IF gv_grid IS INITIAL. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = gv_grid. ENDIF. ENDFORM. "frm_get_grid *&---------------------------------------------------------------------* *& Form FRM_COMM_2click *&---------------------------------------------------------------------* *& 双击ALV的凭证号列时,打开凭证信息 *&---------------------------------------------------------------------* *& --> pi_row 双击的行列信息 *&---------------------------------------------------------------------* FORM frm_comm_2click USING pi_row TYPE slis_selfield. CLEAR: gs_alv. READ TABLE gt_alv INTO gs_alv INDEX pi_row-tabindex. IF sy-subrc EQ 0. CASE pi_row-fieldname. WHEN 'BELNR'. IF gs_alv-belnr IS NOT INITIAL. SET PARAMETER ID 'BLN' FIELD gs_alv-belnr. SET PARAMETER ID 'BUK' FIELD gs_alv-bukrs. SET PARAMETER ID 'GJR' FIELD gs_alv-budat+0(4). CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN. ENDIF. WHEN 'BELNR2'. IF gs_alv-belnr2 IS NOT INITIAL. SET PARAMETER ID 'BLN' FIELD gs_alv-belnr2. SET PARAMETER ID 'BUK' FIELD gs_alv-bukrs2. SET PARAMETER ID 'GJR' FIELD gs_alv-budat2+0(4). CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN. ENDIF. ENDCASE. ENDIF. ENDFORM. "FRM_COMM_2CLICK *&---------------------------------------------------------------------* *& 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 *&---------------------------------------------------------------------* *& Form frm_post_doc_01 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LT_ITEM text * <--P_<LF_ALV> text *----------------------------------------------------------------------* FORM frm_post_doc_01 TABLES pt_item STRUCTURE zfit1026 "插入正确名称 <...> CHANGING pc_alv TYPE ty_alv. DATA: ls_documentheader TYPE bapiache09, lt_accountgl TYPE STANDARD TABLE OF bapiacgl09, lt_accountreceivable TYPE STANDARD TABLE OF bapiacar09, lt_accountpayable TYPE STANDARD TABLE OF bapiacap09, lt_currencyamount TYPE STANDARD TABLE OF bapiaccr09, lt_criteria TYPE STANDARD TABLE OF bapiackec9, lt_return TYPE STANDARD TABLE OF bapiret2, lt_extension2 TYPE STANDARD TABLE OF bapiparex, ls_accountgl TYPE bapiacgl09, ls_accountpayable TYPE bapiacap09, ls_currencyamount TYPE bapiaccr09, ls_return TYPE bapiret2, lv_buzei TYPE buzei, lv_text TYPE sgtxt. **step2.1 抬头赋值 ls_documentheader-doc_type = 'SK'. "凭证类型 ls_documentheader-comp_code = pc_alv-payorg. CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_documentheader-ref_doc_no."参照 ls_documentheader-doc_date = pc_alv-orderdate. "凭证日期 IF p_pdate IS INITIAL. ls_documentheader-pstng_date = pc_alv-orderdate. "记帐日期 ELSE. ls_documentheader-pstng_date = p_pdate. "记帐日期 ENDIF. ls_documentheader-username = sy-uname. ls_documentheader-bus_act = 'RFBU'. "参考过程 * IF ls_documentheader-pstng_date IS INITIAL. * ls_documentheader-pstng_date = sy-datum. * ENDIF. * IF ls_documentheader-doc_date IS INITIAL. * ls_documentheader-doc_date = sy-datum. * ENDIF. CLEAR: lv_buzei,lv_text. **step2.2 项目赋值 LOOP AT pt_item. **若金额为负数,则借贷相反,金额相同 IF pt_item-sum_amount1 = 0. pc_alv-status = 'S'. pc_alv-message = '汇总金额为0,无需创建会计凭证!'. ELSEIF pt_item-sum_amount1 < 0. **借2贷1 **借:预收账款-服务折扣(+) lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr2. "科目 **文本 = orderdate+"POS"+"确认游乐卡充值预收款"+补币"+"赠币 CONCATENATE pc_alv-orderdate 'POS确认游乐卡充值预收款补币赠币' INTO lv_text. ls_accountgl-item_text = lv_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount2 ). APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr1. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 ls_accountpayable-item_text = lv_text."文本 APPEND ls_accountpayable TO lt_accountpayable . CLEAR:ls_accountpayable . "金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. "币种 ls_currencyamount-amt_doccur = pt_item-sum_amount1. APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . ELSE. **借1贷2 **借:预收账款-服务折扣(+) lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr1. "科目 **文本 = orderdate+"POS"+"确认游乐卡充值预收款"+补币"+"赠币 CONCATENATE pc_alv-orderdate 'POS确认游乐卡充值预收款补币赠币' INTO lv_text. ls_accountgl-item_text = lv_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount1 ). APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr2. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 ls_accountpayable-item_text = lv_text."文本 APPEND ls_accountpayable TO lt_accountpayable . CLEAR:ls_accountpayable . "金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = pt_item-sum_amount2 * -1. APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . ENDIF. CLEAR: pt_item. ENDLOOP. **记账 CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = ls_documentheader TABLES accountgl = lt_accountgl accountreceivable = lt_accountreceivable accountpayable = lt_accountpayable currencyamount = lt_currencyamount criteria = lt_criteria extension2 = lt_extension2 return = lt_return. **清空原始变量 CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr. CLEAR: pc_alv-status,pc_alv-message. pc_alv-status = 'S'. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE pc_alv-message ls_return-message INTO pc_alv-message SEPARATED BY ' '."错信息 pc_alv-status = 'E'. ENDLOOP. IF pc_alv-status = 'S'. READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. pc_alv-bukrs = ls_documentheader-comp_code. "公司 pc_alv-budat = ls_documentheader-pstng_date."过账日期 pc_alv-cpudt = ls_documentheader-doc_date. "凭证日期 pc_alv-belnr = ls_return-message_v2+0(10). pc_alv-status = 'S'. pc_alv-message = '凭证生成成功'. ELSE. pc_alv-status = 'E'. pc_alv-message = '获取过账凭证信息失败'. ENDIF. ENDIF. **更新自建表状态 UPDATE zfit1025 SET status = pc_alv-status message = pc_alv-message budat = pc_alv-budat cpudt = pc_alv-cpudt bukrs = pc_alv-bukrs belnr = pc_alv-belnr WHERE sum_no = pc_alv-sum_no. IF sy-subrc <> 0. ROLLBACK WORK. CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr. pc_alv-status = 'E'. CONCATENATE pc_alv-message '过账状态数据更新到ZFIT1025表失败' INTO pc_alv-message SEPARATED BY ' '. ELSE. CLEAR ls_return. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = ls_return. IF ls_return-type = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr. pc_alv-status = 'E'. CONCATENATE pc_alv-message '提交数据失败' INTO pc_alv-message SEPARATED BY ' '. ENDIF. ENDIF. ENDFORM. " frm_post_doc_01 *&---------------------------------------------------------------------* *& Form frm_post_doc_03 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LT_ITEM text * <--P_<LF_ALV> text *----------------------------------------------------------------------* FORM frm_post_doc_03 TABLES pt_item STRUCTURE zfit1026 "插入正确名称 <...> CHANGING pc_alv TYPE ty_alv. DATA: ls_documentheader TYPE bapiache09, lt_accountgl TYPE STANDARD TABLE OF bapiacgl09, lt_accountreceivable TYPE STANDARD TABLE OF bapiacar09, lt_accountpayable TYPE STANDARD TABLE OF bapiacap09, lt_currencyamount TYPE STANDARD TABLE OF bapiaccr09, lt_criteria TYPE STANDARD TABLE OF bapiackec9, lt_return TYPE STANDARD TABLE OF bapiret2, lt_extension2 TYPE STANDARD TABLE OF bapiparex, lt_accountgl_2 TYPE STANDARD TABLE OF bapiacgl09, lt_accountpayable_2 TYPE STANDARD TABLE OF bapiacap09, lt_currencyamount_2 TYPE STANDARD TABLE OF bapiaccr09, ls_return TYPE bapiret2. **step1.创建凭证1 RF **step1.1 抬头赋值 ls_documentheader-doc_type = 'RF'. "凭证类型 ls_documentheader-comp_code = pc_alv-payorg. CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_documentheader-ref_doc_no."参照 ls_documentheader-doc_date = pc_alv-orderdate. "凭证日期 IF p_pdate IS INITIAL. ls_documentheader-pstng_date = pc_alv-orderdate. "记帐日期 ELSE. ls_documentheader-pstng_date = p_pdate. "记帐日期 ENDIF. ls_documentheader-username = sy-uname. ls_documentheader-bus_act = 'RFBU'. "参考过程 * IF ls_documentheader-pstng_date IS INITIAL. * ls_documentheader-pstng_date = sy-datum. * ENDIF. * IF ls_documentheader-doc_date IS INITIAL. * ls_documentheader-doc_date = sy-datum. * ENDIF. **step1.2 项目赋值 PERFORM frm_set_item_1 TABLES pt_item lt_accountgl lt_accountpayable lt_currencyamount CHANGING pc_alv. **凭证1 CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = ls_documentheader TABLES accountgl = lt_accountgl accountreceivable = lt_accountreceivable accountpayable = lt_accountpayable currencyamount = lt_currencyamount criteria = lt_criteria extension2 = lt_extension2 return = lt_return. **清空原始变量 CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr. CLEAR: pc_alv-status,pc_alv-message. pc_alv-status = 'S'. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE pc_alv-message ls_return-message INTO pc_alv-message SEPARATED BY ' '."错信息 pc_alv-status = 'E'. ENDLOOP. IF pc_alv-status = 'S'. READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. pc_alv-bukrs = ls_documentheader-comp_code. "公司 pc_alv-budat = ls_documentheader-pstng_date."过账日期 pc_alv-cpudt = ls_documentheader-doc_date. "凭证日期 pc_alv-belnr = ls_return-message_v2+0(10). * pc_alv-status = 'S'. * pc_alv-message = '凭证生成成功'. PERFORM frm_set_item_2 TABLES pt_item lt_accountgl_2 lt_accountpayable_2 lt_currencyamount_2 CHANGING pc_alv. **更改凭证类型 ls_documentheader-doc_type = 'WX'. "凭证类型 **step2.创建凭证2 WX CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = ls_documentheader TABLES accountgl = lt_accountgl_2 accountreceivable = lt_accountreceivable accountpayable = lt_accountpayable_2 currencyamount = lt_currencyamount_2 criteria = lt_criteria extension2 = lt_extension2 return = lt_return. **凭证2 返回信息 CLEAR: pc_alv-bukrs2,pc_alv-budat2,pc_alv-cpudt2,pc_alv-belnr2. CLEAR: pc_alv-status,pc_alv-message. pc_alv-status = 'S'. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE pc_alv-message ls_return-message INTO pc_alv-message SEPARATED BY ' '."错信息 pc_alv-status = 'E'. ENDLOOP. IF pc_alv-status = 'S'. READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. pc_alv-bukrs2 = ls_documentheader-comp_code. "公司 pc_alv-budat2 = ls_documentheader-pstng_date."过账日期 pc_alv-cpudt2 = ls_documentheader-doc_date. "凭证日期 pc_alv-belnr2 = ls_return-message_v2+0(10). pc_alv-status = 'S'. pc_alv-message = '凭证生成成功'. ELSE. pc_alv-status = 'E'. pc_alv-message = '获取过账凭证信息失败'. ENDIF. ELSE. pc_alv-status = 'E'. pc_alv-message = '获取过账凭证信息失败'. ENDIF. ENDIF. ENDIF. **step2.1 抬头赋值 **step2.2 项目赋值 **step3.更新自建表状态 UPDATE zfit1025 SET status = pc_alv-status message = pc_alv-message budat = pc_alv-budat cpudt = pc_alv-cpudt bukrs = pc_alv-bukrs belnr = pc_alv-belnr budat2 = pc_alv-budat2 cpudt2 = pc_alv-cpudt2 bukrs2 = pc_alv-bukrs2 belnr2 = pc_alv-belnr2 WHERE sum_no = pc_alv-sum_no. IF sy-subrc <> 0. ROLLBACK WORK. CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr. pc_alv-status = 'E'. CONCATENATE pc_alv-message '过账状态数据更新到ZFIT1025表失败' INTO pc_alv-message SEPARATED BY ' '. ELSE. CLEAR ls_return. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = ls_return. IF ls_return-type = 'E'. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CLEAR: pc_alv-bukrs,pc_alv-budat,pc_alv-cpudt,pc_alv-belnr, pc_alv-bukrs2,pc_alv-budat2,pc_alv-cpudt2,pc_alv-belnr2. pc_alv-status = 'E'. CONCATENATE pc_alv-message '提交数据失败' INTO pc_alv-message SEPARATED BY ' '. ENDIF. ENDIF. ENDFORM. " frm_post_doc_03 *&---------------------------------------------------------------------* *& Form frm_set_item *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_PT_ITEM text * -->P_LT_ACCOUNTGL text * -->P_LT_ACCOUNTPAYABLE text * -->P_LT_CURRENCYAMOUNT text *----------------------------------------------------------------------* FORM frm_set_item_1 TABLES pt_item STRUCTURE zfit1026 "插入正确名称 <...> lt_accountgl STRUCTURE bapiacgl09 lt_accountpayable STRUCTURE bapiacap09 lt_currencyamount STRUCTURE bapiaccr09 CHANGING pc_alv TYPE ty_alv. DATA: ls_accountgl TYPE bapiacgl09, ls_accountpayable TYPE bapiacap09, ls_currencyamount TYPE bapiaccr09, lv_buzei TYPE buzei. CLEAR: lv_buzei, lt_accountgl, lt_accountpayable, lt_currencyamount. LOOP AT pt_item. IF pt_item-sum_amount4 = 0. pc_alv-status = 'S'. pc_alv-message = '汇总金额为0,无需创建会计凭证!'. ELSEIF pt_item-sum_amount4 < 0. **若金额为负数,则借贷相反,金额相同 **借3贷4 **借:预收账款-服务折扣(+) * PERFORM frm_set_item USING pt_item CHANGING ls_accountgl ls_accountpayable ls_currencyamount. lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr3. "科目 **文本 = orderdate++" 确认红孩子游乐逾期销户"+ 本币 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户本币' INTO ls_accountgl-item_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount3 ). APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr4. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户利得' INTO ls_accountpayable-item_text."文本 APPEND ls_accountpayable TO lt_accountpayable . CLEAR:ls_accountpayable . **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. "币种 ls_currencyamount-amt_doccur = pt_item-sum_amount4. APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . ELSE. **借4贷3 (fs描述正常业务) **借:预收账款-服务折扣(+) lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr4. "科目 **文本 = orderdate++" 确认红孩子游乐逾期销户"+ 本币” CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户本币' INTO ls_accountgl-item_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount4 ). APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr3. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户利得' INTO ls_accountpayable-item_text."文本 APPEND ls_accountpayable TO lt_accountpayable . CLEAR:ls_accountpayable . **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = pt_item-sum_amount3 * -1. APPEND ls_currencyamount TO lt_currencyamount . CLEAR:ls_currencyamount . ENDIF. CLEAR: pt_item. ENDLOOP. ENDFORM. " frm_set_item *&---------------------------------------------------------------------* *& Form frm_set_item_2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_PT_ITEM text * -->P_LT_ACCOUNTGL_2 text * -->P_LT_ACCOUNTPAYABLE_2 text * -->P_LT_CURRENCYAMOUNT_2 text * <--P_PC_ALV text *----------------------------------------------------------------------* FORM frm_set_item_2 TABLES pt_item STRUCTURE zfit1026 "插入正确名称 <...> lt_accountgl_2 STRUCTURE bapiacgl09 lt_accountpayable_2 STRUCTURE bapiacap09 lt_currencyamount_2 STRUCTURE bapiaccr09 CHANGING pc_alv TYPE ty_alv. DATA: ls_accountgl TYPE bapiacgl09, ls_accountpayable TYPE bapiacap09, ls_currencyamount TYPE bapiaccr09, lv_buzei TYPE buzei. CLEAR: lv_buzei, lt_accountgl_2, lt_accountpayable_2, lt_currencyamount_2. LOOP AT pt_item. IF pt_item-sum_amount2 = 0. pc_alv-status = 'S'. pc_alv-message = '汇总金额为0,无需创建会计凭证!'. ELSEIF pt_item-sum_amount2 < 0. **若金额为负数,则借贷相反,金额相同 **借1贷2 **借:预收账款-服务折扣(+) * PERFORM frm_set_item USING pt_item CHANGING ls_accountgl ls_accountpayable ls_currencyamount. lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr1. "科目 **文本 = orderdate++" 确认红孩子游乐逾期销户赠币 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户赠币' INTO ls_accountgl-item_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl_2. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount1 ). APPEND ls_currencyamount TO lt_currencyamount_2 . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr2. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户赠币' INTO ls_accountpayable-item_text."文本 APPEND ls_accountpayable TO lt_accountpayable_2 . CLEAR:ls_accountpayable . **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. "币种 ls_currencyamount-amt_doccur = pt_item-sum_amount2. APPEND ls_currencyamount TO lt_currencyamount_2 . CLEAR:ls_currencyamount . ELSE. **借2贷1 (fs描述正常业务) **借:预收账款-服务折扣(+) lv_buzei = lv_buzei + 1. ls_accountgl-itemno_acc = lv_buzei. ls_accountgl-gl_account = pt_item-saknr2. "科目 **文本 = orderdate++" 确认红孩子游乐逾期销户赠币 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户赠币' INTO ls_accountgl-item_text."文本 **分配 = PAYoffice付款门店+ SUM_NO收入汇总单号 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountgl-alloc_nmbr."分配 * ls_accountgl-costcenter = '1001AEW'."成本中心 APPEND ls_accountgl TO lt_accountgl_2. CLEAR:ls_accountgl. **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = ABS( pt_item-sum_amount2 ). APPEND ls_currencyamount TO lt_currencyamount_2 . CLEAR:ls_currencyamount . **贷:预收账款-预存款 lv_buzei = lv_buzei + 1. ls_accountpayable-itemno_acc = lv_buzei . * ls_accountpayable-vendor_no = pc_alv-lifnr. ls_accountpayable-gl_account = pt_item-saknr1. "科目 * ls_accountpayable-sp_gl_ind = '-'." 偏移码 CONCATENATE pc_alv-payoffice pc_alv-sum_no INTO ls_accountpayable-alloc_nmbr."分配 CONCATENATE pc_alv-orderdate '确认红孩子游乐逾期销户利得' INTO ls_accountpayable-item_text."文本 APPEND ls_accountpayable TO lt_accountpayable_2 . CLEAR:ls_accountpayable . **金额 ls_currencyamount-itemno_acc = lv_buzei . ls_currencyamount-currency = pc_alv-currencytype. ls_currencyamount-amt_doccur = pt_item-sum_amount1 * -1. APPEND ls_currencyamount TO lt_currencyamount_2 . CLEAR:ls_currencyamount . ENDIF. CLEAR: pt_item. ENDLOOP. ENDFORM. " frm_set_item_2