This document describes how to Post FI document using interface FM 'POSTING_INTERFACE_DOCUMENT' to FB01 using Batch input session. The process involves creating a batch input session and processing the session via SM35 for posting. We should transfer all document header and item data which are needed in the document to internal table T_FTPOST. In this method the screen sequence of the transaction used for posting like "FB01" is not required as opposed to the BDC recording process and so this approach provides a more easy way of posting documents than BDC recording of a transaction. In order to call the above FM, the values of all the fields to be filled in the transaction must be populated to the table T_FTPOST as explained below:
1. To Post FI document, the first step is to call FM for interface start using below minimum parameter :
CALL FUNCTION 'POSTING_INTERFACE_START'
EXPORTING
i_function =‘B’ " For Batch Input.
i_group =‘ZSESSION’ " Name of the session for creation
i_keep =‘X’ " Retain the session
i_user =sy-uname. “ User name
2. Now populate the table T_FTPOST with all the required Header (BKPF) and Item (BSEG) fields for FI document one by one from source data file like given below:
HEADER:
ls_ftpost-stype = ‘K’. “Header indicator
ls_ftpost-count = ‘001’. “First item
ls_ftpost-fnam = 'BKPF-BUKRS'.
ls_ftpost-fval = pa_bukrs.
APPEND ls_ftpost TO p_lt_ftpost.
ls_ftpost-fnam = 'BKPF-BUDAT'.
WRITE pa_budat TO ls_ftpost-fval.
APPEND ls_ftpost TO p_lt_ftpost.
ITEMS:
ls_ftpost-stype = ‘P’. “Item indicator
ls_ftpost-count = ‘001’. “First item
ls_ftpost-fnam = 'RF05A-NEWBS'.
ls_ftpost-fval = lv_bschl.
APPEND ls_ftpost TO p_lt_ftpost.
ls_ftpost-fnam = 'RF05A-NEWKO'.
ls_ftpost-fval = p_lfs_tab-hkont.
APPEND ls_ftpost TO p_lt_ftpost.
................
ls_ftpost-stype = ‘P’. “Item indicator
ls_ftpost-count = ‘002’. “First item
ls_ftpost-fnam = 'RF05A-NEWBS'.
ls_ftpost-fval = lv_bschl.
APPEND ls_ftpost TO p_lt_ftpost.
ls_ftpost-fnam = 'RF05A-NEWKO'.
ls_ftpost-fval = p_lfs_tab-hkont.
APPEND ls_ftpost TO p_lt_ftpost.
The field name (FNAM=‘BKPF-BUKRS’) to be used here must be populated with the correct screen field name in the transaction used for posting. Sometimes the screen field has different names than the database table field names. Here, the screen sequence is not required for posting as opposed to the BDC process but the value of all fields must be populated to the table T_FTPOST in the above format and only if the field appears in the screen for input otherwise the system will raise a message for it. If any field doesnot appear in the screen, the value for that field should not be appended in table T_FTPOST.
Note, here that the header record for FI document is populated with single record in internal table T_FTPOST and multiple records for item level records in internal table T_FTPOST which means there should be a single record of type stype = ‘K’ for header and multiple records of type stype = ‘P’ for items in the internal table T_FTPOST for each posting of FI document. Ideally, the item records should be populated inside a LOOP statement for items and field "ls_ftpost-count" should be incremented for each new item of a FI document and should be re-initialized for fresh FI document while populating table T_FTPOST.
3. Now the next step would be to call the below FM with parameters as indicated
CALL FUNCTION 'POSTING_INTERFACE_DOCUMENT'
EXPORTING
i_tcode = ‘FB01’ “Name of t-code for Posting
i_sgfunct = ‘B’ “Batch input session
IMPORTING
e_subrc = lv_subrc
e_msgid = lv_msg-id “Error handling
e_msgty = lv_msg-type “Error handling
e_msgno = lv_msg-number “Error handling
e_msgv1 = lv_msg-message_v1“Error handling
e_msgv2 = lv_msg-message_v2“Error handling
e_msgv3 = lv_msg-message_v3“Error handling
e_msgv4 = lv_msg-message_v4“Error handling
TABLES
t_ftpost = T_FTPOST “Internal table populated in Step 2
t_fttax = lt_fttax “Relevant for Tax calculation manually
t_blntab = lt_blntab “Relevant only for Call Trans...
EXCEPTIONS
OTHERS = 1.
4. Next issue a COMMIT statement after above FM call and finally call the below FM to end processing of the session.
CALL FUNCTION 'POSTING_INTERFACE_END'.
5. In case of posting multiple documents from flat file source the above steps 2 & 3 should be repeated for each document to post multiple documents which means the internal table T_FTPOST should be populated fresh for each document with header & item records and FM 'POSTING_INTERFACE_DOCUMENT' should be called for each FI document to be posted where as the other FMs 'POSTING_INTERFACE_START' & 'POSTING_INTERFACE_END’ should be called once in the start and in the end of session processing.