POS杂项数据SAP记账程序
*&---------------------------------------------------------------------*
*& 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 <> .
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 .
DO.
*加锁
CALL FUNCTION 'ENQUEUE_EZ_ZRUNING_LOCK'
EXPORTING
mode_zruning_lock = 'X'
mandt = sy-mandt
zprogram = sy-repid
_scope = ''
EXCEPTIONS
foreign_lock =
system_failure =
OTHERS = .
IF sy-subrc = .
EXIT.
ELSE.
IF sy-batch = 'X'.
WAIT UP TO 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() = '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 = .
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 ''.
PERFORM frm_post_doc_01 TABLES lt_item CHANGING <lf_alv>.
WHEN ''.
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 =
OTHERS = .
IF sy-subrc <> .
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() 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 .
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+().
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+().
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 = .
pc_alv-status = 'S'.
pc_alv-message = '汇总金额为0,无需创建会计凭证!'.
ELSEIF pt_item-sum_amount1 < .
**借2贷1
**借:预收账款-服务折扣(+)
lv_buzei = lv_buzei + .
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 + .
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 + .
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 + .
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 * -.
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 = .
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+().
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 <> .
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 = .
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+().
* 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 = .
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+().
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 <> .
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 = .
pc_alv-status = 'S'.
pc_alv-message = '汇总金额为0,无需创建会计凭证!'.
ELSEIF pt_item-sum_amount4 < .
**若金额为负数,则借贷相反,金额相同
**借3贷4
**借:预收账款-服务折扣(+)
* PERFORM frm_set_item USING pt_item CHANGING ls_accountgl ls_accountpayable ls_currencyamount.
lv_buzei = lv_buzei + .
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 + .
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 + .
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 + .
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 * -.
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 = .
pc_alv-status = 'S'.
pc_alv-message = '汇总金额为0,无需创建会计凭证!'.
ELSEIF pt_item-sum_amount2 < .
**若金额为负数,则借贷相反,金额相同
**借1贷2
**借:预收账款-服务折扣(+)
* PERFORM frm_set_item USING pt_item CHANGING ls_accountgl ls_accountpayable ls_currencyamount.
lv_buzei = lv_buzei + .
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 + .
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 + .
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 + .
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 * -.
APPEND ls_currencyamount TO lt_currencyamount_2 .
CLEAR:ls_currencyamount . ENDIF.
CLEAR: pt_item.
ENDLOOP. ENDFORM. " frm_set_item_2
POS杂项数据SAP记账程序的更多相关文章
- 在微软平台上运行 SAP 应用程序
本博客介绍了在微软平台上运行 SAP 应用程序的相关信息,作者在基于微软平台使用 SAP 方面有着数十年经验. 发布关于 Azure 的 SAP 说明 几个月前,SAP 针对适用于 SAP 软件 ...
- Salesforce Apex 使用JSON数据的示例程序
本文介绍了一个在Salesforce Apex中使用JSON数据的示例程序, 该示例程序由以下几部分组成: 1) Album.cls, 定了了封装相关字段的数据Model类 2) RestClient ...
- Mysql 大数据量导入程序
Mysql 大数据量导入程序<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" ...
- 关于leetcode中链表中两数据相加的程序说明
* Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ ...
- Microsoft Azure News(2) 在Microsoft Azure上运行SAP应用程序
<Windows Azure Platform 系列文章目录> 2014年6月27日消息,在 Microsoft Azure 上提供 SAP Business Suite 软件.All-I ...
- 基于Hbase数据的Mapreduce程序环境开发
一.实验目标 编写Mapreduce程序,以Hbase表数据为Map输入源,计算结果输出到HDFS或者Hbase表中. 在非CDH5的Hadoop集群环境中,将编写好的Mapreduce程序整个工程打 ...
- 项目mysql数据导入数据的Java程序
最近写的一个数据库导入数据的程序,有兴趣的同学可以参考一下: 这个程序是针对mysql数据库的,在本地或服务器上运行,主要的需求还是,针对项目的某些bug修复 后,客户的数据要搬到新表上来,避免新版本 ...
- 用saxon框架对xml数据进行过滤 - 程序员的天堂 - ITeye技术网站
用saxon框架对xml数据进行过滤 博客分类: Java Saxon 是一个 XSLT 和XQuery处理器.它是使用 XML 文档和样式表作为输入,然后生成结果文档作为输出的程序,它还包括了一 ...
- PL/SQL修改数据之后,程序查到的还是原来的数据怎么办?
我们在开发的过程中,可能需要手动删除或者修改数据库数据,但是在update之后,程序还是查到的是原始的数据.而我们自己在pl/sql中查到的确实修改之后的数据,通常情况下这个是因为我们在修改之后没有c ...
随机推荐
- 轻量级UML工具-UMLet
免费.开源,而且灰常好用的工具,这里就当加一个备注.免得忘了 如何在UMLet中表示static和final? UMLet中表示static用下划线(对于method.function或者operat ...
- binutils工具集之---objdump
在嵌入式软件开发中,有时需要知道所生成的程序文件中的段信息以分析问题,或者需要查看c语言对应的汇编代码,此时,objdump工具就可以帮大忙了.obj——object dump:转储. #inclu ...
- oracle9i 精简版客户端界面没有显示实例名
1.右击"我的电脑",选择"属性"菜单项 2.在弹出的窗口中,点击"高级系统设置" 3.在弹出的窗口中,选择"环境变量" ...
- PHP学习笔记(3)GD库画图
<?php //加header头,不然浏览器乱码 header("content-type: image/png"); //创建画布资源 $img = imagecreate ...
- [转]用了docker是否还有必要使用openstack?
从一项颠覆性的技术成果转化并衍生出一整套社区体系,Docker在发展速度上打破了一个又一个历史纪录.然而,Docker项目在采纳与普及方面表现出惊人态势的同时,也给我们带来了一系列疑问与困惑. 在今天 ...
- website 合集
1. oracle http://asktom.oracle.com ( 英文 ) http://itpub.net ( 中文 ) https://www.oracle.com/communitie ...
- iframe宽高百分百显示
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 安装Node.js以及Hexo
安装前提 安装 Hexo 相当简单.然而在安装前,您必须检查电脑中是否已安装下列应用程序: Node.js 如何在Ubuntu上安装最新版本的Node.js https://hexo.io/zh-cn ...
- C++学习之拷贝构造函数篇
一.拷贝构造函数的声明 Array(const Array & arr); 二.拷贝构造函数的实现分为两种,即是深拷贝和浅拷贝. 1.浅拷贝 代码例如以下: class Array { pub ...
- Revit 2017 编程须要用Visual Studio2015 +.NET Framework 4.52
一年一度的Revit产品公布时刻,我们抢先想各位介绍下Revit 2017的变化和新功能 Major changes and renovations to the Revit API API chan ...