This chapter describes creating a function module using Z_ACC_DOCUMENT_POST as an example.
The function module is created in the Object Navigator. More information can be found in the administration manual in the chapter Configuration in SAP.

After saving the input, the Function Builder: Display Z_ACC_DOCUMENT_POST dialog opens.
Properties
Here, the radio button Remote-enable module has to be selected.

Import
Define input parameters that are not assigned to any SAP table here.

Export
Define parameters that are returned by the function module that can be used as output parameter by the JobSAP BAPI module here.

Changing
No entries are necessary here.
Tables
Enter the tables used by the function module BAPI_ACC_DOCUMENT_POST here. Those tables have to be listed in the bapi.xml file of the JobSAP BAPI module as well.
Please note: If a warning is displayed informing that TABLES parameter are obsolete, it can be skipped by pressing enter twice.

Exceptions
No entries are necessary here.
Source text
This text field is used for the ABAP code of the function module.
FUNCTION z_acc_document_post.
*"----------------------------------------------------------------------
*"*"Local interfaces:
*" IMPORTING
*" VALUE(DOCUMENTHEADER) TYPE BAPIACHE09
*" VALUE(CUSTOMERCPD) TYPE BAPIACPA09 OPTIONAL
*" VALUE(CONTRACTHEADER) TYPE BAPIACCAHD OPTIONAL
*" VALUE(LANGUAGE) TYPE CHAR_02 DEFAULT 'DE'
*" VALUE(ONLY_SUCCESS_COMMIT) TYPE CHAR_01 DEFAULT 'X'
*" VALUE(COMMIT_AND_WAIT) TYPE CHAR_01 DEFAULT SPACE
*" EXPORTING
*" VALUE(OBJ_TYPE) TYPE BAPIACHE09-OBJ_TYPE
*" VALUE(OBJ_KEY) TYPE BAPIACHE09-OBJ_KEY
*" VALUE(OBJ_SYS) TYPE BAPIACHE09-OBJ_SYS
*" VALUE(RETURNCODE) TYPE INTEGER
*" VALUE(MESSAGE_TYPE) TYPE CHAR_01
*" VALUE(RETURN_COMMIT) TYPE BAPIRET2
*" TABLES
*" ACCOUNTGL STRUCTURE BAPIACGL09 OPTIONAL
*" ACCOUNTRECEIVABLE STRUCTURE BAPIACAR09 OPTIONAL
*" ACCOUNTPAYABLE STRUCTURE BAPIACAP09 OPTIONAL
*" ACCOUNTTAX STRUCTURE BAPIACTX09 OPTIONAL
*" CURRENCYAMOUNT STRUCTURE BAPIACCR09
*" CRITERIA STRUCTURE BAPIACKEC9 OPTIONAL
*" VALUEFIELD STRUCTURE BAPIACKEV9 OPTIONAL
*" EXTENSION1 STRUCTURE BAPIACEXTC OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*" PAYMENTCARD STRUCTURE BAPIACPC09 OPTIONAL
*" CONTRACTITEM STRUCTURE BAPIACCAIT OPTIONAL
*" EXTENSION2 STRUCTURE BAPIPAREX OPTIONAL
*" REALESTATE STRUCTURE BAPIACRE09 OPTIONAL
*" ACCOUNTWT STRUCTURE BAPIACWT09 OPTIONAL
*"----------------------------------------------------------------------
TYPE-POOLS abap.
CONSTANTS true VALUE abap_true.
CONSTANTS false VALUE abap_false.
* =========================================================
* Definitions & declarations
* =========================================================
* Preassignments
returncode = 0.
message_type = 'S'.
* Reference to the exception class
DATA r_exception TYPE REF TO cx_root.
DATA str_exception TYPE string.
* Local structures & variables
DATA ls_return TYPE bapiret2.
DATA lv_msg TYPE char0128.
* =========================================================
* BAPI
* =========================================================
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader " (obligatory)
customercpd = customercpd
contractheader = contractheader
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = accountgl
accountreceivable = accountreceivable
accountpayable = accountpayable
accounttax = accounttax
currencyamount = currencyamount " Currency items (obligatory)
criteria = criteria
valuefield = valuefield
extension1 = extension1
return = return " Return parameter (obligatory)
paymentcard = paymentcard
contractitem = contractitem
extension2 = extension2
realestate = realestate
accountwt = accountwt
. " Point
* =========================================================
* Error-Checking
* =========================================================
READ TABLE return INTO ls_return WITH KEY type = 'W'.
IF sy-subrc = 0 AND only_success_commit = true.
message_type = 'W'.
returncode = 3.
ENDIF.
READ TABLE return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
message_type = 'E'.
returncode = 2.
ENDIF.
* =========================================================
* Translation Messages (RETURN-TABLE)
* =========================================================
LOOP AT return INTO ls_return.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = return-id
lang = language
no = return-number
v1 = return-message_v1
v2 = return-message_v2
v3 = return-message_v3
v4 = return-message_v4
IMPORTING
msg = lv_msg
EXCEPTIONS
not_found = 1
OTHERS = 2
." Point
" If no translation is possible,
" the default language is kept
IF sy-subrc = 0.
ls_return-message = lv_msg.
MODIFY return FROM ls_return.
ENDIF.
ENDLOOP.
* =========================================================
* COMMIT
* =========================================================
" returncode 0 = BAPI was executed correctly
IF returncode = 0.
TRY.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = commit_and_wait
IMPORTING
return = return_commit
. " Point
CATCH cx_sy_dyn_call_illegal_type INTO r_exception.
ENDTRY.
"-----------------------------------------------------
" COMMIT Error-Checking
"-----------------------------------------------------
IF return_commit-type = 'E'.
message_type = 'E'.
returncode = 4.
ENDIF.
ELSE.
TRY.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
IMPORTING
return = return_commit
. " Point
CATCH cx_sy_dyn_call_illegal_type INTO r_exception.
ENDTRY.
"-----------------------------------------------------
" ROLLBACK Error-Checking
"-----------------------------------------------------
IF return_commit-type = 'E'.
message_type = 'E'.
returncode = 5.
ENDIF.
ENDIF.
" Prepare exception for output
"-----------------------------------
IF r_exception IS NOT INITIAL.
CALL METHOD r_exception->if_message~get_text
RECEIVING
result = str_exception.
MESSAGE str_exception TYPE 'I'.
ENDIF.
"---------------------------------------------------------
" Translation Messages (RETURN-STRUCTURE)
"---------------------------------------------------------
CLEAR lv_msg.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = return_commit-id
lang = language
no = return_commit-number
v1 = return_commit-message_v1
v2 = return_commit-message_v2
v3 = return_commit-message_v3
v4 = return_commit-message_v4
IMPORTING
msg = lv_msg
EXCEPTIONS
not_found = 1
OTHERS = 2
." Point
" If no translation is possible,
" the default language is kept
IF sy-subrc = 0.
return_commit-message = lv_msg.
ENDIF.
ENDFUNCTION.
Activate function module
The function module is activated using the "activate" button (alternatively CTRL+F3).

If the function module was activated, the message "Objects were activated" is displayed in the status bar.