现有一个需求,需要同时生成两张不同的凭证,如果其中有一条是错误的,那么其他的已生成凭证,则需冲销,并报错
接口如下:
import:
BUKRS TYPE BUKRS 公司代码
KUNNR TYPE KUNNR 客户编号1
ZUONR TYPE ZDE_ZUONR1 BPM单号
BKTXT TYPE BKTXT 凭证抬头文本
table:
GT_FIGXT024 LIKE ZFIGXT024 财务共享_客户入金凭证传入
GT_FIGXT024_DOC LIKE ZFIS003 财务凭证信息
ZFIGXT024:
ZXH CHAR 4 0 序号
ZCFLB CHAR 10 0 转出方款项类别
ZCKKB CHAR 4 0 转出信贷范围
ZCKMC CHAR 20 0 转出方专款号
ZCAUF CHAR 20 0 转出方订单
ZRFLB CHAR 10 0 转入方款项类别
ZRKKB CHAR 4 0 转入信贷范围
ZRKMC CHAR 20 0 转入方专款号
ZRAUF CHAR 20 0 转入方订单
ZZKJE CURR 25 2 转款金额
SGTXT SGTXT CHAR 50 0 项目文本
ZFIS003:
ZMSGTY SYMSGTY CHAR 1 0 消息,消息类型
ZBUKRS BUKRS CHAR 4 0 公司代码
ZBELNR BELNR_D CHAR 10 0 会计凭证编号
ZGJAHR GJAHR NUMC 4 0 会计年度
ZMSGTXT CHAR200 CHAR 200 0 文本字段长度 200
FUNCTION zrfcfi015.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(BUKRS) TYPE BUKRS OPTIONAL
*" VALUE(KUNNR) TYPE KUNNR OPTIONAL
*" VALUE(ZUONR) TYPE ZDE_ZUONR1 OPTIONAL
*" VALUE(BKTXT) TYPE BKTXT OPTIONAL
*" TABLES
*" GT_FIGXT024 STRUCTURE ZFIGXT024 OPTIONAL
*" GT_FIGXT024_DOC STRUCTURE ZFIS003 OPTIONAL
*"----------------------------------------------------------------------
DATA: lw_error TYPE char1.
DATA l_itemno TYPE posnr_acc.
DATA: ls_figxt024 TYPE zfigxt024,
gs_figxt024 TYPE zfigxt024.
DATA: l_type TYPE bapiache09-obj_type,
l_key TYPE bapiache09-obj_key,
l_sys TYPE bapiache09-obj_sys.
DATA l_index type sy-tabix.
PERFORM clear_globa_data.
g_bukrs = bukrs.
g_kunnr = kunnr.
g_zuonr = zuonr.
g_bktxt = bktxt.
* LOOP AT gt_figxt024 INTO ls_figxt024.
*客户编号转换
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = g_kunnr
IMPORTING
output = g_kunnr.
"BPM单号转焕
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = g_zuonr
IMPORTING
output = g_zuonr.
* PERFORM frm_check_obligatory USING ls_figxt024-burks
* '公司代码'
* CHANGING lw_error.
* MODIFY gt_figxt024 FROM ls_figxt024.
* ENDLOOP.
SORT gt_figxt024.
LOOP AT gt_figxt024 INTO ls_figxt024.
IF ls_figxt024-zcflb EQ '宝旺保险款'
OR ls_figxt024-zcflb EQ '其他款项'
OR ls_figxt024-zrflb EQ '宝旺保险款'
OR ls_figxt024-zrflb EQ '其他款项'.
APPEND ls_figxt024 TO gt_figsxt_sa.
ELSEIF
ls_figxt024-zcflb EQ '保证金'
or ls_figxt024-zcflb EQ '常态金额'
or ls_figxt024-zcflb EQ '专款金额'
or ls_figxt024-zcflb EQ '刻章款'
or ls_figxt024-zcflb EQ '月饼款'
or ls_figxt024-zrflb EQ '保证金'
or ls_figxt024-zrflb EQ '常态金额'
or ls_figxt024-zrflb EQ '专款金额'
or ls_figxt024-zrflb EQ '刻章款'
or ls_figxt024-zrflb EQ '月饼款'.
APPEND ls_figxt024 TO gt_figsxt_da.
ELSE.
CLEAR: ls_zfigxt024_doc.
ls_zfigxt024_doc-zmsgty = 'E'.
ls_zfigxt024_doc-zmsgtxt = '错误的类型'.
APPEND ls_zfigxt024_doc TO GT_FIGXT024_DOC .
ENDIF.
ENDLOOP.
CHECK GT_FIGXT024_DOC is INITIAL.
IF gt_figsxt_da IS NOT INITIAL .
PERFORM create_doucument TABLES gt_figsxt_da USING 'DA'.
ENDIF.
IF g_error_flag NE 'X'.
IF gt_figsxt_sa IS NOT INITIAL .
PERFORM clear_data.
PERFORM create_doucument TABLES gt_figsxt_sa USING 'SA'.
ENDIF.
ENDIF.
if g_error_flag ne 'X'.
"如果有错,则把已生成的凭证 冲销。
LOOP at lt_zfigxt024_doc INTO ls_zfigxt024_doc WHERE zmsgty = 'S'.
l_index = sy-tabix.
PERFORM reback_document CHANGING ls_zfigxt024_doc.
MODIFY lt_zfigxt024_doc FROM ls_zfigxt024_doc INDEX l_index.
ENDLOOP.
* DELETE gt_figxt024_doc WHERE zmsgty = 'S'.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
endif.
IF lt_zfigxt024_doc IS NOT INITIAL .
APPEND LINES OF lt_zfigxt024_doc TO gt_figxt024_doc.
ENDIF.
* IF gt_figsxt_sa IS NOT INITIAL .
* PERFORM post_sa_doucument .
* ENDIF.
ENDFUNCTION.
TOP(全局变量)
FUNCTION-POOL zfg_figx15. "MESSAGE-ID ..
DATA:
gs_header TYPE bapiache09,
gt_accountgl TYPE TABLE OF bapiacgl09 ,
gt_customer TYPE TABLE OF bapiacar09,
gt_vendor TYPE TABLE OF bapiacap09,
gt_tax TYPE TABLE OF bapiactx09,
gt_curr TYPE TABLE OF bapiaccr09,
gt_ext2 TYPE TABLE OF bapiparex,
gs_accountgl TYPE bapiacgl09,
gs_customer TYPE bapiacar09,
gs_vendor TYPE bapiacap09,
gs_tax TYPE bapiactx09,
gs_curr TYPE bapiaccr09,
gs_ext2 TYPE bapiparex,
gt_return TYPE TABLE OF bapiret2,
gs_return TYPE bapiret2.
DATA:
g_itemno TYPE bapiacgl09-itemno_acc.
DATA: g_bukrs TYPE bukrs,
g_kunnr TYPE kunnr,
g_zuonr TYPE zde_zuonr1,
g_bktxt TYPE bktxt.
DATA:
lt_zfigxt024_doc TYPE TABLE OF zfis003, "保存错误消息
ls_zfigxt024_doc TYPE zfis003.
DATA: gt_figsxt_sa TYPE STANDARD TABLE OF zfigxt024,
gs_figsxt_sa TYPE zfigxt024.
DATA: gt_figsxt_da TYPE STANDARD TABLE OF zfigxt024,
gs_figsxt_da TYPE zfigxt024.
data: g_error_flag TYPE char1.
FORMS:
*----------------------------------------------------------------------*
***INCLUDE LZFG_FIGX15F01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_OBLIGATORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ZBUKRS1 text
* -->P_0087 text
* <--P_LW_ERROR text
*----------------------------------------------------------------------*
FORM frm_check_obligatory USING up_imp_val TYPE any
up_imp_txt TYPE any
CHANGING cp_error.
DATA:
lw_msg TYPE string.
CLEAR: cp_error.
IF up_imp_val IS INITIAL.
CLEAR: ls_zfigxt024_doc.
ls_zfigxt024_doc-zmsgty = 'E'.
CONCATENATE '请输入'
up_imp_txt
'!'
INTO lw_msg.
ls_zfigxt024_doc-zmsgtxt = lw_msg.
APPEND ls_zfigxt024_doc TO lt_zfigxt024_doc .
CLEAR: ls_zfigxt024_doc.
cp_error = 'X'.
ENDIF.
ENDFORM. " FRM_CHECK_OBLIGATORY
*&---------------------------------------------------------------------*
*& Form frm_save_msg
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_save_msg.
DATA:
lw_msg TYPE string.
DELETE gt_return WHERE type = 'E'
AND id = 'RW'
AND number = '609'.
LOOP AT gt_return INTO gs_return WHERE type = 'E'.
CLEAR: lw_msg.
MESSAGE ID gs_return-id
TYPE gs_return-type
NUMBER gs_return-number
WITH gs_return-message_v1
gs_return-message_v2
gs_return-message_v3
gs_return-message_v4
INTO lw_msg.
CLEAR: ls_zfigxt024_doc.
ls_zfigxt024_doc-zmsgty = 'E'.
ls_zfigxt024_doc-zmsgtxt = lw_msg.
APPEND ls_zfigxt024_doc TO lt_zfigxt024_doc .
CLEAR: ls_zfigxt024_doc.
ENDLOOP.
ENDFORM. "frm_save_msg
*&---------------------------------------------------------------------*
*& Form CLEAR_GLOBA_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM clear_globa_data .
CLEAR :
gs_header,
gt_accountgl,
gt_customer,
gt_vendor,
gt_tax ,
gt_curr ,
gt_ext2 ,
gs_accountgl ,
gs_customer,
gs_vendor ,
gs_tax ,
gs_curr ,
gs_ext2,
gt_return,
gs_return,
g_itemno,
lt_zfigxt024_doc,
ls_zfigxt024_doc,
g_bukrs,
g_kunnr,
g_zuonr,
g_bktxt,
g_error_flag,
gt_figsxt_da,
gt_figsxt_sa.
ENDFORM. " CLEAR_GLOBA_DATA
*&---------------------------------------------------------------------*
*& Form clear_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM clear_data .
CLEAR :
gs_header,
gt_accountgl,
gt_customer,
gt_vendor,
gt_tax ,
gt_curr ,
gt_ext2 ,
gs_accountgl ,
gs_customer,
gs_vendor ,
gs_tax ,
gs_curr ,
gs_ext2,
gt_return,
gs_return,
g_itemno.
ENDFORM. "clear_data
*&---------------------------------------------------------------------*
*& Form GET_HEADER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_header_data USING p_doc_type TYPE bapiache09-doc_type.
"抬头信息
CLEAR gs_header.
gs_header-comp_code = g_bukrs.
gs_header-header_txt = g_bktxt.
gs_header-doc_date = sy-datum.
gs_header-pstng_date = sy-datum.
gs_header-doc_type = p_doc_type.
gs_header-username = sy-uname.
gs_header-bus_act = 'RFBU'.
ENDFORM. " GET_HEADER_DATA
*&---------------------------------------------------------------------*
*& Form GET_ACCOUNTRECEIVABLE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_customer_s USING p_figxt024 TYPE zfigxt024.
CLEAR gs_customer.
*客户类
gs_customer-itemno_acc = g_itemno. "会计凭证行项目编号
gs_customer-customer = g_kunnr. "客户编号1
IF p_figxt024-zcflb = '保证金'.
gs_customer-sp_gl_ind = 'N'.
gs_customer-gl_account = '2241020009'.
ELSEIF p_figxt024-zcflb = '常态金额'.
gs_customer-gl_account = '2205020001'.
gs_customer-c_ctr_area = p_figxt024-zckkb.
gs_customer-pmnttrms = '0001'.
ELSEIF p_figxt024-zcflb = '专款金额'.
gs_customer-sp_gl_ind = 'I'.
gs_customer-gl_account = '2205020002'.
gs_customer-c_ctr_area = p_figxt024-zckkb.
"add by damon at 20150915
ELSEIF p_figxt024-zcflb = '刻章款'.
gs_customer-sp_gl_ind = '4'. "总账标识
gs_customer-gl_account = '1231080008'.
ENDIF.
gs_customer-comp_code = g_bukrs. "公司代码
gs_customer-alloc_nmbr = g_zuonr. "分配号 = BPM单号
gs_customer-bline_date = sy-datum. "到期日计算的基限日期
* gs_customer-item_text = p_figxt024-sgtxt.
PERFORM get_item_text USING g_kunnr p_figxt024-zcflb CHANGING gs_customer-item_text. "add by damon at 20150915
APPEND gs_customer TO gt_customer.
ENDFORM. " GET_ACCOUNTRECEIVABLE_DATA
*&---------------------------------------------------------------------*
*& Form GET_CUSTOMER_H
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_L_ITEMNO text
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_customer_h USING p_figxt024 TYPE zfigxt024.
CLEAR gs_customer.
*客户类
gs_customer-itemno_acc = g_itemno. "会计凭证行项目编号
gs_customer-customer = g_kunnr. "客户编号1
IF p_figxt024-zrflb = '保证金'.
gs_customer-sp_gl_ind = 'N'.
gs_customer-gl_account = '2241020009'.
ELSEIF p_figxt024-zrflb = '常态金额'.
gs_customer-gl_account = '2205020001'.
gs_customer-c_ctr_area = p_figxt024-zrkkb.
ELSEIF p_figxt024-zrflb = '专款金额'.
gs_customer-sp_gl_ind = 'I'.
gs_customer-gl_account = '2205020002'.
gs_customer-c_ctr_area = p_figxt024-zrkkb.
ELSEIF p_figxt024-zrflb = '刻章款'.
gs_customer-sp_gl_ind = '4'. "总账标识
gs_customer-gl_account = '1231080008'.
ENDIF.
gs_customer-comp_code = g_bukrs.
gs_customer-alloc_nmbr = g_zuonr.
gs_customer-bline_date = sy-datum.
* gs_customer-item_text = p_figxt024-sgtxt.
PERFORM get_item_text USING g_kunnr p_figxt024-zrflb CHANGING gs_customer-item_text. "add by damon at 20150915
APPEND gs_customer TO gt_customer.
ENDFORM. " GET_CUSTOMER_H
*&---------------------------------------------------------------------*
*& Form GET_CURR_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
* -->P_G_ITEMNO text
* -->P_= text
* -->P_G_ITEMNO text
* -->P_+ text
* -->P_1 text
*----------------------------------------------------------------------*
FORM get_curr_data_s USING p_figxt024 TYPE zfigxt024.
CLEAR gs_curr.
gs_curr-itemno_acc = g_itemno.
gs_curr-currency = 'CNY'.
gs_curr-amt_doccur = p_figxt024-zzkje.
APPEND gs_curr TO gt_curr.
ENDFORM. " GET_CURR_DATA\
*&---------------------------------------------------------------------*
*& Form get_curr_data_h
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_curr_data_h USING p_figxt024 TYPE zfigxt024.
CLEAR gs_curr.
gs_curr-itemno_acc = g_itemno.
gs_curr-currency = 'CNY'.
gs_curr-amt_doccur = p_figxt024-zzkje * -1.
APPEND gs_curr TO gt_curr.
ENDFORM. "get_curr_data_h
*&---------------------------------------------------------------------*
*& Form GET_EXT2_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_ext2_data_s USING p_figxt024 TYPE zfigxt024.
DATA ls_zfis008 TYPE zfis008.
IF p_figxt024-zcflb = '保证金'.
CLEAR gs_ext2.
ls_zfis008-posnr = g_itemno.
ls_zfis008-aufnr = p_figxt024-zcauf.
gs_ext2-structure = 'ZFIS008'.
gs_ext2-valuepart1 = ls_zfis008.
APPEND gs_ext2 TO gt_ext2.
ENDIF.
ENDFORM. " GET_EXT2_DATA
*&---------------------------------------------------------------------*
*& Form get_ext2_data_h
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_ext2_data_h USING p_figxt024 TYPE zfigxt024.
DATA ls_zfis008 TYPE zfis008.
IF p_figxt024-zrflb = '保证金'.
CLEAR gs_ext2.
ls_zfis008-posnr = g_itemno.
ls_zfis008-aufnr = p_figxt024-zrauf.
gs_ext2-structure = 'ZFIS008'.
gs_ext2-valuepart1 = ls_zfis008.
APPEND gs_ext2 TO gt_ext2.
ENDIF.
ENDFORM. "get_ext2_data_h
*&---------------------------------------------------------------------*
*& Form GET_ITEM_TEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_G_KUNNR text
* -->P_P_FIGXT024_ZCFLB text
* <--P_GS_CUSTOMER_ITEM_TEXT text
*----------------------------------------------------------------------*
FORM get_item_text USING p_kunnr TYPE kunnr
p_flb TYPE char10
CHANGING p_text TYPE sgtxt .
CONCATENATE '收' p_kunnr p_flb '款' INTO p_text.
ENDFORM. " GET_ITEM_TEXT
*&---------------------------------------------------------------------*
*& Form GET_GLACCOUNT_S
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_glaccount_s USING p_figxt024 TYPE zfigxt024.
CLEAR gs_accountgl.
gs_accountgl-itemno_acc = g_itemno.
gs_accountgl-gl_account = '2241170001'.
gs_accountgl-part_acct = g_kunnr.
gs_accountgl-ref_key_2 = g_kunnr.
* gs_accountgl-ref_key_3 = p_figxt024.
gs_accountgl-alloc_nmbr = g_zuonr.
PERFORM get_item_text USING g_kunnr p_figxt024-zcflb CHANGING gs_accountgl-item_text. "add by damon at 20150915
APPEND gs_accountgl TO gt_accountgl.
ENDFORM. " GET_GLACCOUNT_S
*&---------------------------------------------------------------------*
*& Form get_glaccount_h
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_glaccount_h USING p_figxt024 TYPE zfigxt024.
CLEAR gs_accountgl.
gs_accountgl-itemno_acc = g_itemno.
gs_accountgl-gl_account = '2241170001'.
gs_accountgl-part_acct = g_kunnr.
gs_accountgl-ref_key_2 = g_kunnr.
* gs_accountgl-ref_key_3 = p_figxt024.
gs_accountgl-alloc_nmbr = g_zuonr.
PERFORM get_item_text USING g_kunnr p_figxt024-zrflb CHANGING gs_accountgl-item_text. "add by damon at 20150915
APPEND gs_accountgl TO gt_accountgl.
ENDFORM. "get_glaccount_h
*&---------------------------------------------------------------------*
*& Form GET_VENDOR_S
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_vendor_s USING p_figxt024 TYPE zfigxt024.
CLEAR gs_vendor.
*客户类
gs_vendor-itemno_acc = g_itemno. "会计凭证行项目编号
gs_vendor-sp_gl_ind = 'Q'.
gs_vendor-gl_account = '2241110002'.
IF p_figxt024-zcflb = '宝旺保险款'.
gs_vendor-vendor_no = '0061021511'. "供应商编号
ELSEIF p_figxt024-zcflb = '其他款项'.
gs_vendor-vendor_no = '0061002344'. "供应商编号
* gs_vendor-gl_account = '2205020001'.
* gs_vendor-c_ctr_area = p_figxt024-zrkkb.
ENDIF.
gs_vendor-comp_code = g_bukrs.
gs_vendor-alloc_nmbr = g_zuonr.
gs_vendor-bline_date = sy-datum.
* gs_customer-item_text = p_figxt024-sgtxt.
PERFORM get_item_text USING g_kunnr p_figxt024-zcflb CHANGING gs_vendor-item_text. "add by damon at 20150915
APPEND gs_vendor TO gt_vendor.
ENDFORM. " GET_VENDOR_S
*&---------------------------------------------------------------------*
*& Form get_vendor_h
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIGXT024 text
*----------------------------------------------------------------------*
FORM get_vendor_h USING p_figxt024 TYPE zfigxt024.
CLEAR gs_vendor.
*客户类
gs_vendor-itemno_acc = g_itemno. "会计凭证行项目编号
gs_vendor-sp_gl_ind = 'Q'.
gs_vendor-gl_account = '2241110002'.
IF p_figxt024-zrflb = '宝旺保险款'.
gs_vendor-vendor_no = '0061021511'. "供应商编号
ELSEIF p_figxt024-zrflb = '其他款项'.
gs_vendor-vendor_no = '0061002344'. "供应商编号
* gs_vendor-gl_account = '2205020001'.
* gs_vendor-c_ctr_area = p_figxt024-zrkkb.
ENDIF.
gs_vendor-comp_code = g_bukrs.
gs_vendor-alloc_nmbr = g_zuonr.
gs_vendor-bline_date = sy-datum.
* gs_customer-item_text = p_figxt024-sgtxt.
PERFORM get_item_text USING g_kunnr p_figxt024-zrflb CHANGING gs_vendor-item_text. "add by damon at 20150915
APPEND gs_vendor TO gt_vendor.
ENDFORM. " GET_VENDOR_S
*&---------------------------------------------------------------------*
*& Form CREATE_DOUCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_doucument TABLES pt_figxt024 STRUCTURE zfigxt024
USING p_doc_type TYPE bapiache09-doc_type..
DATA: ls_figxt024 TYPE zfigxt024
.
DATA: l_type TYPE bapiache09-obj_type,
l_key TYPE bapiache09-obj_key,
l_sys TYPE bapiache09-obj_sys.
CLEAR g_itemno.
PERFORM get_header_data USING p_doc_type.
LOOP AT pt_figxt024 INTO ls_figxt024.
* ls_figxt024 = gs_figxt024.
* AT NEW zuonr.
* CLEAR g_itemno.
* PERFORM get_header_data USING ls_figxt024.
* ENDAT.
g_itemno = g_itemno + 1.
"借方
CASE ls_figxt024-zcflb.
WHEN '保证金'OR '常态金额' OR '专款金额' OR '刻章款'.
PERFORM get_customer_s USING ls_figxt024. " 客户行
WHEN '月饼款'.
PERFORM get_glaccount_s USING ls_figxt024. "总账行项目
WHEN '宝旺保险款' OR '其他款项'.
PERFORM get_vendor_s USING ls_figxt024. "供应商行项目
WHEN OTHERS.
CONTINUE.
ENDCASE.
PERFORM get_curr_data_s USING ls_figxt024. "金额行
PERFORM get_ext2_data_s USING ls_figxt024.
"贷方
g_itemno = g_itemno + 1.
CASE ls_figxt024-zrflb.
WHEN '保证金'OR '常态金额' OR '专款金额' OR '刻章款'.
PERFORM get_customer_h USING ls_figxt024. " 客户行
WHEN '月饼款'.
PERFORM get_glaccount_h USING ls_figxt024. "总账行项目
WHEN '宝旺保险款' OR '其他款项'.
PERFORM get_vendor_h USING ls_figxt024. "供应商行项目
WHEN OTHERS.
CONTINUE.
ENDCASE.
* PERFORM get_customer_h USING ls_figxt024.
PERFORM get_curr_data_h USING ls_figxt024. "金额行
PERFORM get_ext2_data_h USING ls_figxt024.
ENDLOOP.
*生产会计凭证
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = gs_header
IMPORTING
obj_type = l_type
obj_key = l_key
obj_sys = l_sys
TABLES
accountgl = gt_accountgl
accountreceivable = gt_customer
accountpayable = gt_vendor
currencyamount = gt_curr
return = gt_return
extension2 = gt_ext2.
IF l_key IS NOT INITIAL AND l_key <> '$'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ls_zfigxt024_doc-zmsgty = 'S'.
ls_zfigxt024_doc-zbukrs = g_bukrs.
ls_zfigxt024_doc-zbelnr = l_key+0(10).
ls_zfigxt024_doc-zgjahr = sy-datum+0(4).
APPEND ls_zfigxt024_doc TO lt_zfigxt024_doc.
CLEAR: ls_zfigxt024_doc.
ELSE.
PERFORM frm_save_msg.
g_error_flag = 'X'.
ENDIF.
ENDFORM. " CREATE_DOUCUMENT
*&---------------------------------------------------------------------*
*& Form CREATE_SD_DOUCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIGXT024 text
*----------------------------------------------------------------------*
" CREATE_SD_DOUCUMENT
*&---------------------------------------------------------------------*
*& Form POST_SA_DOUCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM post_sa_doucument .
* g_itemno = g_itemno + 1.
*
* "借方
*
* CASE ls_figxt024-zcflb.
* WHEN '保证金'OR '常态金额' OR '专款金额' OR '刻章款'.
* PERFORM get_customer_s USING ls_figxt024. " 客户行
* WHEN '月饼款'.
* PERFORM get_glaccount_s USING ls_figxt024. "总账行项目
* WHEN '宝旺保险款' OR '其他款项'.
** PERFORM get_vendor_s USING ls_figxt024. "供应商行项目
*
* WHEN OTHERS.
* ENDCASE.
*
* PERFORM get_curr_data_s USING ls_figxt024. "金额行
* PERFORM get_ext2_data_s USING ls_figxt024.
* "贷方
* g_itemno = g_itemno + 1.
* CASE ls_figxt024-zrflb.
* WHEN '保证金'OR '常态金额' OR '专款金额' OR '刻章款'.
* PERFORM get_customer_h USING ls_figxt024. " 客户行
* WHEN '月饼款'.
* PERFORM get_glaccount_h USING ls_figxt024. "总账行项目
* WHEN '宝旺保险款' OR '其他款项'.
** PERFORM get_vendor_h USING ls_figxt024. "供应商行项目
* WHEN OTHERS.
* ENDCASE.
** PERFORM get_customer_h USING ls_figxt024.
* PERFORM get_curr_data_h USING ls_figxt024. "金额行
* PERFORM get_ext2_data_h USING ls_figxt024.
*
* ENDLOOP.
ENDFORM. " POST_SA_DOUCUMENT
*&---------------------------------------------------------------------*
*& Form REBACK_DOCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_ZFIGXT024_DOC text
*----------------------------------------------------------------------*
FORM reback_document CHANGING p_doc TYPE zfis003.
TABLES: bkpf.
DATA p_bukrs TYPE bukrs VALUE '9900'.
DATA p_belnr TYPE bseg-belnr VALUE '0100000335'.
DATA p_gjahr TYPE bseg-gjahr VALUE '2011'.
DATA p_budat TYPE bkpf-budat VALUE '20110126'.
DATA p_awkey TYPE awkey.
DATA p_subrc TYPE sy-subrc.
DATA: w_belnr TYPE belnr_d,
w_reversal TYPE bapiacrev,
wt_return TYPE STANDARD TABLE OF bapiret2,
wa_return TYPE bapiret2.
CLEAR p_subrc.
SELECT SINGLE * FROM bkpf
WHERE bukrs EQ p_doc-zbukrs
AND belnr EQ p_doc-zbelnr
AND gjahr EQ p_doc-zgjahr.
*
* CHECK bkpf-blart = 'SA'.
sy-uname = bkpf-usnam.
* CONCATENATE W_BELNR P_BUKRS P_GJAHR INTO W_REVERSAL-OBJ_KEY.
w_reversal-obj_type = bkpf-awtyp.
w_reversal-obj_key_r = bkpf-awkey.
* CONCATENATE p_doc-zbelnr p_doc-zbukrs p_doc-zgjahr INTO w_reversal-obj_key_r.
w_reversal-obj_key = w_reversal-obj_key_r.
* w_reversal-obj_key = '$'.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
own_logical_system = w_reversal-obj_sys
EXCEPTIONS
own_logical_system_not_defined = 1
OTHERS = 2.
w_reversal-reason_rev = '01'.
w_reversal-pstng_date = bkpf-budat.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
EXPORTING
reversal = w_reversal
bus_act = 'RFBU'
TABLES
return = wt_return.
LOOP AT wt_return INTO wa_return WHERE type NE 'S'.
p_subrc = 4.
p_doc-ZMSGTY = 'E'.
p_doc-ZMSGTXT = '生成的凭证冲销失败,请手动冲销'.
EXIT.
ENDLOOP.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
EXPORTING
reversal = w_reversal
bus_act = 'RFBU'
IMPORTING
* OBJ_TYPE =
obj_key = p_awkey
* OBJ_SYS =
TABLES return = wt_return.
LOOP AT wt_return INTO wa_return WHERE type EQ 'S'.
p_doc-ZMSGTY = 'E'.
p_doc-ZMSGTXT = '生成的凭证已冲销'.
EXIT.
* p_subrc = 4.
* EXIT.
ENDLOOP.
ENDFORM. " REBACK_DOCUMENT