One way you can extend cash management with SAP S/4HANA is related to One Exposure from Operations.
These extensions are mostly based on backend BAdIs, which allow you to influence the way the data is collected and integrated into the One Exposure from Operations table FQM_FLOW. In this post, we’ll discuss how default loading classes are used, their purpose, and why you may want to create your own loading classes. Finally, we’ll show you how to implement your own functions for liquidity item derivation to fulfill business requirements that can’t be met with standard tools.
You can implement several BAdIs to influence the backend system logic to provide data for One Exposure from Operations. The following BAdIs allow you to adjust the integration logic for specific source applications, including the Transaction Manager in SAP Treasury and Risk Management, financial accounting, materials management, and electronic bank statements:
SAP Treasury and Risk Management Integration into One Exposure from Operations
With this BAdI, you can introduce additional details to how liquidity items are assigned to forecasted cash flows from financial transactions in the Transaction Manager in SAP Treasury and Risk Management.
SAP standard provides origin X for deriving liquidity items, but the available information for this derivation is limited to only a few fields that are relevant to financial transaction cash flows.
For example, an SAP Treasury and Risk Management money market instrument has several other flows representing several kinds of fees, for example, a bank charge. These flows have different flow types and different update types in SAP Treasury and Risk Management position management. You may want to derive liquidity items of the corresponding flows in One Exposure from Operations based on the update type.
Additionally, you can overwrite the key information flow type for cash flows from SAP Treasury and Risk Management, for instance, a cash forecast flow generated for an SAP Treasury and Risk Management transaction. However, if you don’t want to consider this flow in cash management in SAP S/4HANA, use this BAdI to overwrite the flow type with a flow type that won’t be considered by cash management in SAP S/4HANA.
You can create your own implementations using the following methods:
- DERIVE: Derives liquidity items for SAP Treasury and Risk Management in One Exposure from Operations.
- UPDATE_FLOW_TYPE: Updates the flow type for SAP Treasury and Risk Management in One Exposure from Operations.
Adjustment of Flows in One Exposure from Operations
This BAdI enables you to influence the creation of the flows in One Exposure from Operations (table FQM_FLOW). You can use this BAdI to enhance the system logic for flows in One Exposure from Operations from all source applications other than financial accounting and materials management.
Every time a flow is created in One Exposure from Operations, this BAdI allows you to determine your own parameters for the flows, to change or add account assignments, to add new flows, and even to disregard certain flows. Note, however, that you can’t overwrite the logic to delete flows in One Exposure from Operations. Allowing this personalization would jeopardize the consistency of the data in One Exposure from Operations.
For example, you can integrate cash forecasts from invoices from classic cash management running on a remote system (source application CMDSR). The system doesn’t determine a bank account for these cash forecasts. If, based on some dedicated information, you could determine a bank account, you can adjust the created flows with additional information from the house bank account or the bank account.
You can create your own implementation using the following method:
- ADJUST_FLOWS: Adjusts flows in One Exposure from Operations.
Adjustment of Flows in Bank Statement Adapter
By implementing this BAdI, you can determine how and if bank statement line items are integrated into One Exposure from Operations. This BAdI only works for prior-day bank statements, so you can’t use this BAdI to write intraday bank statement line items into One Exposure from Operations.
By default, only those line items not posted to SAP S/4HANA Finance are integrated into One Exposure from Operations. For those line items for which no posting rule has been found, the system will create a line item in One Exposure from Operations. Equally, statements that you never intended to post are integrated into One Exposure from Operations. Similarly, if a temporary issue with posting a line item arises, you may need time to correct the issue (e.g., complete missing configuration). Until you fix the issue, the cash position is being updated based on bank statement line items that haven’t posted.
You can use this BAdI to disregard flows (the individual line items from bank statements), change the parameters and account assignments made for a line item, or even add flows for specific line items from a bank statement. This BAdI also helps you disregard bank statement flows that the standard posting function won’t process because they are flagged in the statement as invalid.
You can create your own implementation using the following method:
- ADJUST_FLOWS: Adjusts flows created in the bank statement adapter before sending to One Exposure from Operations.
BAdI: Only for Prior-Day Bank Statement Flows Not Posted
This BAdI only adjusts flows from prior-day bank statements that haven’t been posted. Only influencing the integration of these flows into One Exposure from Operations, this BAdI doesn’t influence the posting behavior of flows. After a flow is posted to financial accounting, the bank statement flow in One Exposure from Operations is deleted, and the cash flow is now integrated based on the accounting document line in table BSEG.
AMDP-Based Exit Classes in the Financial Accounting Flow Builder
For the financial accounting Flow Builder to work, the system uses loading classes for financial accounting and materials management. A loading class is an ABAP class built with ABAP-managed database procedures (AMDP) technology. The loading class encapsulates the logic for processing the source documents from a specific source application (currently the system supports integration of financial accounting and materials management) into corresponding flows in table FQM_FLOW. The standard logic of the loading class has been delivered via templates.
You can generate the default loading classes based on these templates and thus use the SAP-provided logic of building the One Exposure from Operations data based on financial accounting and materials management documents. Templates are delivered as standard/default exit classes and are used internally whenever you generate loading classes.
You have three options with respect to loading classes. You can use the default, standard SAP-provided loading classes; generate your own loading class based on a template that you’ll modify using available exit classes; or write your own loading classes. However you decide to generate loading classes, you’ll use them to determine the logic of the integration process from the financial documents in financial accounting and materials management into One Exposure from Operations.
AMDP is part of the ABAP code optimization within the context of ABAP development on SAP HANA. AMDP is only one of the recommended patterns.
AMDPs are implemented as methods of a global ABAP class. The development environment for AMDP is the ABAP class editor. An AMDP is written in languages such as Native SQL or SQLScript, that is, in a database-specific language, and is implemented inside an AMDP method body of an AMDP class. From a developer’s perspective, developing a database procedure is similar to editing ABAP class methods with the same tool environment. For more information, check out the SAP Help on this topic at http://s-prs.co/v516904.
However, editing an AMDP is only possible in the Eclipse-based development environment (ABAP Development Tools) and not in SAP GUI (Class Builder), which is also the case for other ABAP tools for SAP HANA. The ABAP Workbench will reject the editing support in the SAP GUI mode. Nevertheless, you’ll be able to view the code within the AMDP methods using the ABAP Workbench.
You’ll use the Generate Loading Classes option to generate the loading classes based on the exit classes you defined as parameters (see below).
You can generate the loading classes at the beginning of the project or when you need to regenerate the loading classes already defined. You’ll need to regenerate the loading classes, for example, when settings used to generate the loading classes have been changed. For instance, you may have adjusted the query sequences for materials management.
If you want to use the SAP-delivered templates, you can use the SAP-provided sample exit classes, or no exit class at all, when you generate the loading class program. Alternatively, you can make changes to the classes by programming your own logic into the exit classes. You can create your exit classes based on the sample methods provided by SAP, and you can assign exit classes as parameters to the program, as shown in the above figure. When you click Execute, the program will generate the loading classes based on the SAP template, including your customized logic in the exit classes. The program uses the loading class names you’ve used as parameters as the names for the loading classes it creates.
After generating your loading classes, with or without the use of exit classes, you’ll assign the loading classes you generated to the flow assignment logic in Assign Loading Classes.
Instead of using the SAP-generated loading classes, you can also write your own loading classes and assign them using the Assign Loading Classes option. You might have to write your own loading classes if you have very specific requirements or want to exclude some of the assignments made by the default programs. You may also find that you need to modify the auto-generated classes to improve the performance of these programs.
If you assign your own loading classes, you must be careful when you use the Generate Loading Classes option. If you do generate the loading classes using the same name of a loading class you modified and which is currently assigned, you’ll overwrite the custom code with the code generated based on the template and exit classes as described previously. You can still generate loading classes but be sure to use a different name and only assign the loading class if you’re sure the new loading class meets the requirements of your assignment logic.
These considerations explain why SAP doesn’t recommend writing your own loading classes. Depending on how you’ve programmed your loading classes, you may have to manually adjust them each time you make changes to your queries and query sequences in materials management. You’ll also no longer benefit from any changes to the standard logic delivered by SAP through the templates. If you do need to make changes, you should try to implement your changes only through the use of exit classes. By using exit classes, you’ll still benefit from the improvements and adjustments to the loading class templates delivered by SAP.
In short, you have three options to modify the standard logic of the flow assignment to table FQM_FLOW—by implementing your own exit classes, and generating the loading class with exit classes; by programming your own loading classes based on the code generated; or by programming the loading class completely from scratch.
If you need to implement exit classes to meet your requirements, here are the steps to follow:
- Copy the predelivered sample exit class to your own class within the customer namespace in Transaction SE24.
- Implement your logic in the copied class using SAP’s ABAP development tool (Eclipse) and activate the class.
- Regenerate the loading classes and assign the new loading class in Flow Builder: Settings and Tools.
The following list provides all available exit classes that you can use in the Generate Loading Classes function. The list also includes the sample exit classes. A sample exit class is a typical extension scenario for you to use as a template as is, or you can use it as the basis for your own implementation of exit classes. The exit classes are as follows:
Exit Class for Finance
SAP provides a sample exit class CL_FCLM_APAR_HADI_SAMPLE; you’ll need to implement the method IF_FCLM_HADI_APAR~ FLOW_ADJUST for your own logic in the sample class or your own new class.
A typical use scenario for this exit class is to populate bank account information for the flows from accounting components, which is especially useful for legacy accounting documents. In SAP ERP, house bank and house bank account information are not always populated for accounting documents.
After you use cash management in SAP S/4HANA, you’ll want to analyze your cash flows by bank account. For this purpose, you’ll need to rebuild the legacy accounting documents with the bank account information.
SAP provides a standard tool to rebuild legacy documents, but the standard logic can only process transactional data, such as bank statements and payment requests. In some cases, the standard tools can’t populate the required information for all records.
One solution could be implementing a simple logic in the exit class for accounting documents, CL_FCLM_APAR_HADI_SAMPLE. If you’ve already maintained the house bank and house bank account information consistently in the general ledger account master data, you can implement a simple logic in the exit class for accounting to derive the bank account information from the general ledger account master record.
For details on how to implement this logic and the exit class for accounting documents, refer to SAP Note 2461437 – House Bank (HBKID) and Account ID (HKTID) Isn’t Updated in Table FQM_FLOW (One Exposure from Operations), which is an SAP knowledge base article (KBA).
Exit Class for Bank Statement
SAP provides a sample exit class CL_FCLM_BS_DELE_HADI_SAMPLE; you’ll need to implement the method IF_FCLM_BS_DELE_HADI~ DELE_BS_FLOW for your own logic.
The sample exit class provides a default logic to find the corresponding bank statement items for accounting documents. With this information, the exit class identifies flows that have been updated from bank statements to One Exposure from Operations, for which now an accounting entry exists. The logic deletes the posted bank statement flows from One Exposure from Operations. Check the actual ABAP code and logic in the relevant method of the sample exit class.
If you need your own logic to link accounting documents and bank statement items, you can use the exit class for bank statements (CL_FCLM_BS_DELE_HADI_SAMPLE). Be careful that the logic is complete; otherwise, you risk getting duplicate flows in One Exposure from Operations.
Exit Class for Materials Management
SAP provides a sample exit class CL_FCLM_MM_HADI_SAMPLE; you’ll need to implement the following methods in interface IF_FCLM_HADI_MM:
- IF_FCLM_HADI_MM~ FILTER_POITEM: This method allows you to filter out purchase orders (and scheduling agreements). For example, if you don’t want a certain type of purchase order in the liquidity forecast, you can easily exclude them by implementing the required logic in this method.
- IF_FCLM_HADI_MM~ FILTER_PRITEM: Similar to the preceding method, this method allows you to filter out purchase requisitions. For instance, you may want to prevent purchase requisitions without account assignment information from impacting the liquidity forecast and exclude them from integration into One Exposure from Operations. Simply implement your required logic in this method.
- IF_FCLM_HADI_MM~ FLOW_ADJUST: This method is similar to the financial accounting Flow Builder exit class. Allowing you to enrich the information included in flows based on purchase requisitions and purchase orders, this method provides data from the original documents to be used in table FQM_FLOW. Check the default exit classes and sample methods for the information available in the exit class.
Liquidity Item Derivation Extensibility
You can use these function modules to enhance the derivation of liquidity items for different source applications. Instead of assigning query sequences to company codes, you’ll assign these function modules to them, as shown below. If you’re using the derivation function, the queries and query sequences assigned to this company code are no longer relevant.
You have two types of exit functions to extend financial accounting and other source applications integrated to One Exposure from Operations:
Exit Function Module for Accounting
You can copy the sample code from the sample function module FCLM_LQF_DERIVE_LQITEM_SAMPLE for your own function. Use this function to enhance the derivation of liquidity items of origin C and origin D. (Origin C is for accounts receivable/accounts payable open items, and origin D is for general ledger items.)
You can use this function module to use fields that aren’t otherwise available in the source structure of these origins as filter criteria and conditions for the query. For example, you may want to derive the liquidity item from the cost center category. You can only get the cost center ID from an accounting document, and neither origin C nor D can provide the field for cost center category. In this case, you’ll needa to use the exit function to get the cost center category from the cost center ID and derive the required liquidity item.
Exit Function Module for Others
You can copy from the example function module FCLM_LQF_DERIVE_LQITEM_DEFAULT. You can use this exit function to derive liquidity items for cash flows from SAP Treasury and Risk Management as well. Unlike the Adjustment of Flows in the One Exposure from Operations BAdI previously discussed, you can only adjust the field liquidity item in this exit function.
Editor’s note: This post has been adapted from a section of the book Cash Management with SAP S/4HANA by Dirk Neumann and Lawrence Liang.