1.用到的函数
'POSTING_INTERFACE_START'
'POSTING_INTERFACE_CLEARING'
'POSTING_INTERFACE_END'
这几个函数主要模拟FB05事务码清账。
代码如下
*--------------------------------------------------------------------*
* INTERNAL TABLE DECLARATION
*--------------------------------------------------------------------*
DATA: it_blntab TYPE TABLE OF blntab WITH HEADER LINE,
it_ftclear TYPE TABLE OF ftclear WITH HEADER LINE,
it_ftpost TYPE TABLE OF ftpost WITH HEADER LINE,
it_fttax TYPE TABLE OF fttax WITH HEADER LINE.
*--------------------------------------------------------------------*
* START-OF-SELECTION
*--------------------------------------------------------------------*
START-OF-SELECTION.
DEFINE populate_ftpost.
it_ftpost-stype = &1. "用于内部过帐接口的记录类型 K是抬头 P是行项目
it_ftpost-count = &2. "对于凭证抬头或行项目的计数器(记帐界面) 比如1代表第一个行项目,2 代表第二个行项目
it_ftpost-fnam = &3. "BDC 字段名
it_ftpost-fval = &4. "BDC 字段值
append it_ftpost.
END-OF-DEFINITION.
DEFINE populate_ftclear.
it_ftclear-agkoa = 'D'. "科目类型 A是资产 D是客户 K是供应商 M是物料 S是总账科目
it_ftclear-agbuk = 'XXXX'. "公司代码
it_ftclear-selfd = 'BELNR'. "凭证索引中的字段名
it_ftclear-xnops = 'X'.
append it_ftclear.
END-OF-DEFINITION.
CALL FUNCTION 'POSTING_INTERFACE_START'
EXPORTING
i_function = 'C'
i_keep = 'X'
i_mode = 'A'
EXCEPTIONS
client_incorrect = 1
function_invalid = 2
group_name_missing = 3
mode_invalid = 4
update_invalid = 5
OTHERS = 6.
populate_ftpost: 'K' 1 'BKPF-BUKRS' 'BUKRS', "Company code
'K' 1 'BKPF-BLART' 'DA',
'K' 1 'BKPF-BLDAT' '16.09.2010',
'K' 1 'BKPF-BUDAT' '16.09.2010',
'K' 1 'BKPF-WAERS' 'RMB',
'K' 1 'BKPF-XBLNR' 'Test',
'P' 1 'RF05A-NEWBS' '11',
'P' 1 'BSEG-HKONT' '0090000052',
'P' 1 'BSEG-SGTXT' '20100916-01',
'P' 1 'BSEG-WRBTR' '52'.
populate_ftclear '78000020772018001'. " 连接 凭证号(7800002077)+凭证年度(2018)+凭证行(清账行001)
CALL FUNCTION 'POSTING_INTERFACE_CLEARING'
EXPORTING
i_auglv = 'UMBUCHNG' "具体选择参见上述参数说明
i_tcode = 'FB05'
i_sgfunct = 'C'
IMPORTING
e_msgid = sy-msgid
e_msgno = sy-msgno
e_msgty = sy-msgty
e_msgv1 = sy-msgv1
e_msgv2 = sy-msgv2
e_msgv3 = sy-msgv3
e_msgv4 = sy-msgv4
E_SUBRC = SY-SUBRC
TABLES
t_blntab = it_blntab
t_ftclear = it_ftclear
t_ftpost = it_ftpost
t_fttax = it_fttax
EXCEPTIONS
clearing_procedure_invalid = 1
clearing_procedure_missing = 2
table_t041a_empty = 3
transaction_code_invalid = 4
amount_format_error = 5
too_many_line_items = 6
company_code_invalid = 7
screen_not_found = 8
no_authorization = 9
OTHERS = 10.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'POSTING_INTERFACE_END'
EXCEPTIONS
session_not_processable = 1
OTHERS = 2.
网友评论