Learn how to add key data to the SWIFT (Society for the Worldwide Interbank Telecommunication) MT101 payment file that is not delivered in SAP standard systems using event-based function modules. Discover how dynamic function calls enable you to create country- or bank-specific logic that allows you one MT101 payment file format with an unlimited number of output format possibilities.
Key Concept
Payment format creation can be event driven based on function modules or an SAP Data Medium Exchange Engine (DMEE) tree.
SAP payments are critical to standard business operations, and the automated reconciliation of payments is key to efficient processing and catching fraudulent payments. When payments are made from an SAP system, a unique identifier to the payment needs to be passed to the bank as the transaction reference with payment. This transaction reference is then passed back to the company in the electronic bank statement, and should be used in the automatic bank reconciliation of payments. This should be done for all payments across banks and countries. The framework mentioned in this article describes where and how changes to the Payment Medium Workbench (PMW) payments can be made.
This article is the third of three that detail enhancing the SAP standard payment processing functionality with custom development. The preceding articles were specific to SAP’s Bank Communication Management module. The enhancement mentioned here is specific to Payment Medium Workbench (PMW) payments and is not dependent on SAP’s Bank Communication Management module.
Note
To add the enhancements mentioned in this article, an ABAP developer is needed. As ABAP code changes are being made, a developer’s key is needed. The ABAP team would normally have a developer’s key.
As mentioned in “SAP Bank Communication Management: What You Need to Know,” the payment methods used for payments routed to SAP Bank Communication Management should be defined as PMW payments. In this article, we assume the format of the payment file is an MT101 file, though the information about events mentioned here applies to other PMW file formats as well. An event is an ABAP function module.
For our example, we add the payment document number in the :21: tag of the MT101 file. The :21: tag in a SWIFT MT101 payment file is the transaction reference. The bank sends the information passed with the payment back to the customer in the electronic bank statement. The document number is then used for electronic bank statement clearing in the SAP system.
The SAP function modules that build the header level, transaction level, and footer or trailer records for an MT101 file are shown in Table 1.
Function module |
Description
|
FI_PAYMEDIUM_MT101_20
|
Creates the header level fields for an MT101 payment file
|
FI_PAYMEDIUM_MT101_30 |
Creates the transaction level fields for an MT101 payment file
|
FI_PAYMEDIUM_MT101_40
|
Creates the footer or trailer level fields for an MT101 payment file
|
Table 1
PMW MT101 events
To insert customer-specific code to make adjustments to the payment file, the associated custom event is used, as shown in Table 2. The custom event is called after the SAP standard function module listed in Table 1. Every SAP standard payment event can be replaced or modified by custom events, as we are doing here.
Function module |
Description
|
FI_PAYMEDIUM_MT101_21
|
Custom changes to the header level fields for an MT101 payment file
|
FI_PAYMEDIUM_MT101_31 |
Custom changes to the transaction level fields for an MT101 payment file
|
FI_PAYMEDIUM_MT101_41
|
Custom changes to the footer or trailer level fields for an MT101 payment file
|
Table 2
PMW MT101 custom events
Because the payment document number is at the transaction level (every payment will have a [unique by company code] payment program document number), we add code to the 31 event. To create the 31 event function module, use transaction code SE37.
In the Function Builder: Initial Screen (Figure 1), enter the value FI_PAYMEDIUM_MT101_30 in the Function Module field and click the copy icon.

Figure 1
Copy from the SAP standard function module
In the Copy Function Module box (Figure 2), enter the value FI_PAYMEDIUM_MT101_31 in the To Function module field. You need a customer-specific function group to put in the Function group field. (The developer should know what function group to use.) Then click the Copy button.

Figure 2
Copy from the SAP standard function module to a new custom function module
The reason for copying from the FI_PAYMEDIUM_MT101_30 function module is to copy the inputs and outputs of the FI_PAYMEDIUM_MT101_30 function module to the Z_FI_PAYMEDIUM_MT101_31 function module.
After you click the Copy button in Figure 2, the system displays a pop-up screen like the one shown in Figure 3. To create or make changes to any ABAP code, an ABAP developer’s key is required. The ABAP developer should enter his or her developer’s key into the Access key fields shown in Figure 3 and then click the Continue button. The system displays the message Function Module FI_PAYMEDIUM_MT101_30 copied.

Figure 3
Enter the developer’s key (aka access key)
In the screen that appears (Figure 4), enter the value Z_FI_PAYMEDIUM_MT101_31 in the Function Module field and click the Change button.

Figure 4
Change the custom function module
After you click the Change button in Figure 4, add the code in Figure 5 into the new function module Z_FI_PAYMEDIUM_MT101_31.
FUNCTION Z_FI_PAYMEDIUM_MT101_31. *"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_FPAYH) LIKE FPAYH STRUCTURE FPAYH
*" VALUE(I_FPAYHX) LIKE FPAYHX STRUCTURE FPAYHX
*" TABLES
*" T_FPAYP STRUCTURE FPAYP
*" T_PAYMENT_DETAILS STRUCTURE FPM_PAYD
*" T_FILE_OUTPUT STRUCTURE FPM_FILE
*" EXCEPTIONS
*" NO_PAYMENT
*"--------------------------------------------------------------------
** This function will be used to edit the detail records
** in the MT101 payment file.
DATA: lr_output TYPE fpm_file.
*
*
* Remove :21: record if found to make sure we return required value.
CLEAR: lr_output.
READ TABLE t_file_output INTO lr_output
WITH KEY line(4) = ':21:'.
IF sy-subrc EQ 0.
DELETE t_file_output INDEX sy-tabix.
ENDIF.
*
* Now we will add the appropriate 21 record at the beginning of the
* table which puts it at the beginning of the repeated items section
* of the MT101 file.
CLEAR: lr_output.
CONCATENATE ':21:' i_fpayhx-ovbln INTO lr_output-line.
*
lr_output-length = strlen( lr_output-line ).
lr_output-x_cr = 'X'.
lr_output-x_lf = 'X'.
*
* Insert 21 record into the output structure.
INSERT lr_output INTO t_file_output INDEX 1.
*
ENDFUNCTION.
Figure 5
Custom code for event 31
Next, click the activate icon
to activate the newly created function module. This action displays the screen shown in Figure 6. Click the enter icon (the green checkmark). The system then displays the message Objects Activated.

Figure 6
Objects being activated
After the custom function module is created, it is assigned to the payment medium in configuration. This is done in the IMG under Financial Accounting (New) > Accounts Receivable and Accounts Payable > Business Transactions > Outgoing Payments > Automatic Outgoing Payments > Payment Media > Make Settings for Payment Medium Formats from Payment Medium Workbench > Adjust Payment Medium Format.
Note
After you create a custom event function module, the SAP system loses its sorting of that format as shown in Figure 7. You need to look toward the bottom of the payment medium formats to find it, as shown in Figure 8.

Figure 7
The SAP system loses the sorting of payment medium formats

Figure 8
Change the MT101 events
Select the MT101 format row and double-click the Event Modules folder on the left. This action displays the screen shown in Figure 8. Click the tab to the left of the MT101 format. This action displays the screen shown in Figure 9.

Figure 9
Insert a custom event
In Figure 9, click the New Entries button. In the Event Modules section of Figure 9 insert 31 and the name of the new function module (e.g., Z_FI_PAYMEDIUM_MT101_31) in the fields under the Event and Function module name columns, respectively, as shown in Figure 10.

Figure 10
Custom event inserted
After you click the display implementation icon
in Figure 10, the system opens a screen that displays the code for the function module (Figure 11).

Figure 11
Drill down to the custom event
By creating and assigning event 31 in configuration, the SAP system first executes the code in the SAP standard function module FI_PAYMEDIUM_MT101_30. Right after that, it executes the code in the Z_FI_PAYMEDIUM_MT101_31 function module. It adds the payment document number to each payment in the MT101 payment file. For example, Table 3 shows the order in which the system calls the function modules to create the payment file.
Function module
|
Description
|
1. FI_PAYMEDIUM_MT101_20 |
Create header record |
2. FI_PAYMEDIUM_MT101_30 |
Create detail records |
3. FI_PAYMEDIUM_MT101_31 |
Modify the detail records with custom code |
4. FI_PAYMEDIUM_MT101_40 |
Create the trailer record |
Table 3
SAP standard function modules to create an MT101 file
You are now ready to generate a few MT101 payment files from SAP and validate that the :21: tag for each payment contains the payment document number for the payment.
Step 1. First, two payment requests are created (not shown).
Step 2. Next, the Treasury payment program (transaction code F111) is run (steps not shown) to pay the two payment requests. The executed payment run is shown in Figure 12.

Figure 12
The Treasury payment program
Step 3. In the executed payment run displayed in Figure 12, click the Payments button to view the document numbers for each payment, as shown in Figure 13.

Figure 13
The payment program log
Note
Making changes to the PMW payment files is independent of using the SAP Bank Communication Management module. In other words, you do not need to use the SAP Bank Communication Management module to make adjustments to the MT101 file. In our example, the SAP system the changes were made on did have the SAP Bank Communication Management module configured, which is why we showed the steps. If the SAP Bank Communication Management module were not configured, to see the payment file, use transaction codes F111 or F110 and select Environment > Payment Medium > DME Administration. In the screen the system displays (not shown) press the execute button and then click the display icon

.
Step 4. The SAP Bank Communication Management merge program (transaction code FBPM1) is then run to create the MT101 payment file. As shown in Figure 14, enter the current date in both Run Date fields, enter the payment method for MT101 in the Payment method field, and then click the execute icon.

Figure 14
The SAP Bank Communication Management merge program
The SAP system then displays the batches created in a pop-up screen (Figure 15).

Figure 15
Merge payments output showing payment batch created
Step 5. To view the payment file created, execute the Batch and Payment Monitor report (transaction code BNK_MONI). To narrow down the payments selected, enter the current date in the Due Date field, as shown in Figure 16. Click the execute icon.

Figure 16
Run the Batch and Payment Monitor report to view payment files
Step 6. The output of running the Batch and Payment Monitor report is displayed in Figure 17. Select the tab to the left of the batch and select the File for this batch option.

Figure 17
View the Data Medium Overview for the payment file
The payment file is then displayed in the screen shown in Figure 18. Note the :21: tag that includes the payment document numbers.

Figure 18
The MT101 file with payment document numbers
In Figure 19, a similar payment file is displayed that does not include the enhancement done in this article. The arrows point to where the tag :21 and payment document number were inserted with the enhancement, as shown in Figure 18.

Figure 19
The MT101 file prior to enhancement
As mentioned above, the information sent to the bank in the transaction reference field, (e.g., tag :21:), with each payment is passed back to the company in the electronic bank statement for that payment. (In other words, the FI payment document number is passed in the electronic bank statement for each payment.)
The FI payment document number should then be used to automatically clear the offsetting payment run posting as the electronic bank statement is imported and posted into the SAP system. This can be done by specifying the Standard Algorithm (key 001) Interpretation Algorithm for the payment External Business Transaction (BAI code) in the Electronic Bank Statement configuration found under IMG > Financial Accounting (New) > Bank Accounting > Business Transactions > Payment Transactions > Electronic Bank Statement > Make Global Settings for Electronic Bank Statement. (Not shown.)
Keep in mind that the steps shown in this section of the article to modify the contents of the MT101 detail records to add the SAP FI payment document number for the payment can be done for any PMW payment file. For example, the same steps could be done to modify the detail records in an ACH file by creating a Z_FI_PAYMEDIUM_ACH_31 function module with the code to enhance the payment file.
Mary Loughran
Mary Loughran has been specializing in the SAP Financials area since 1997 and has worked with numerous clients throughout North America and Europe in the areas of finance and treasury. She was employed as a consultant with SAP America and was a designated expert within SAP America for treasury before she left SAP in 2004. Mary’s expertise is in the areas of SAP Treasury and Risk Management, SAP In-House Cash, Liquidity Planner, Accounts Payable, payments from SAP in general, Cash Management, and Electronic Banking. Mary was an independent consultant from 2004 to 2016.
You may contact the author at loughran@gmail.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.

Brent Olsen
Brent Olsen has been a developer and technical specialist in SAP systems since 1996. He has worked with numerous clients throughout North America. Since 2010 he has worked at e5 Solutions Group, where he has developed more of a focus on the SAP Treasury and Risk Management module.
You may contact the author at brent.olsen@e5solutions.com.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.