To realise intercompany transactions in SAP you need to specify a trading partner for each transaction. This trading partner represents a company that is doing the transaction with your company code. Intercompany transactions can be done at either the general ledger level or the sub-ledger level. Since invoices are often needed for some intercompany transactions many companies do most of their intercompany transactions at the sub-ledger level.
Trading partners can be maintained in transaction OX15.
In this example we want to make sure that postings that are using G/L account 449010 „Intercompany Labor“ always have the trading partner information filled by using a valdidation rule and an User Exit routine.
In SAP the validation rule function (transaction GGB0) is used to define a set of conditions that must be met in order for a particular action or process to be completed. These rules can be applied to various aspects of the SAP system such as data entry transactions or reports. Validation rules are used to ensure the accuracy and consistency of data in the SAP system and can help prevent errors or incorrect information from being entered or processed.
SAP offers two programs that can be used to implement user exits: RGGBS000 and RGGBR000. These programs are used for substitutions and validation rules, respectively. To implement user exits you should create a copy of the relevant program and give it a name that begins with „Z“ (for example, ZRGGBR000). This allows you to customize the program without modifying the original SAP version.
Futhermore its necessary to fill the Z report into transaction GCX2 to ensure that the new Userexit will be present and selectable in the standard transaction GGB0.
While this looks like an unusual approach it is mentioned on the offical saphelp website. Normaly this is done by using enhancement points. In SAP an enhancement point is a specific location within the SAP software where users can insert their own custom code or functionality. This allows users to add new features or functionality to the SAP system without modifying the core SAP code.
First of all we need to define a new exit in the report. This needs to be done in the form GET_EXIT_TITLES.
Here we need to set a NAME field that contains the user exit name. The field PARAM defines the parameter type. This parameter has three possible values that are defined as constants:
C_EXIT_PARAM_NONE constant specifies that no parameters are defined for a user exit. However there is actually one parameter defined which is a boolean flag that indicates whether there is an error in the data. A value of false means that the data is valid and a value of true means that there is an error. This parameter can be used with rules, validations, and substitutions.
The C_EXIT_PARAM_FIELD constant is only valid for substitutions and it means that one parameter can be defined for the user exit, which is the field to be substituted.
The C_EXIT_PARAM_CLASS constant is valid for rules, validations, and substitutions. It signifies that all the data (BKPF and BSEG data) will be passed as one parameter to the user exit. You will be given a table containing all the relevant information and you can refer to the routine U101 to see how to access this data.
We will using the C_EXIT_PARAM_CLASS parameter for this example.
Now we need to create the coding for the userexit. Therefor i added another include on the end of the report. (Same approach than the given example in the standard sap report. (EXAMPLES FROM Argentina Legal Change))
The exit is returning a boolean value for the valdiation rule useage. If the b_result value is F than the message in the validation rule (GGB0) will triggered. The exit parameter BOOL_DATA TYPE gb002_015 will lead to both BSEG line items and the BKPF header information. If the value is T the message will not be triggered.
In this example (Validation for Intercompany postings) it is required to use a complete document validation rule because the trading partner is not available on document header and line item level validation. (depending on the fieldstatus group of the account)
The new validation rule needs to be assigned to the company code and set to activation level 2 by using transaction OB28. The Callpoint is the same as the defined rule level (complete document). (Note: If you change the coding of the userexit like the parameter you need to reactivate the validation rule again and set the table entry otherwise it will lead to runtime errors (inconsistencies)). By activating the validation rule there is a abap runtime generation in the background.
If we set a debugger breakpoint on the userexit we can analyse what information will be present on runtime. Now we want to simulate an intercompany posting by running transaction FB50. If the trading partner is empty the userexit should trigger the message.
As mentioned the exit parameter BOOL_DATA TYPE gb002_015 will lead to both BSEG line items and the BKPF header information. Without the parameter we only have the last entered BSEG line available in the runtime of the userexit.
So in this example on the first run of the BSEG loop we got the combination that the trading partner field is empty for the intercompany account 449010. The second run of the loop using the bank account 113200 wouldn’t trigger the validation rule message.
The validation rule message (Type E) appears and the user cant post the document without entering the trading partner first.
After entering the trading partner the userexit doesn`t lead to the combination of b_result = F anymore and the posting can be processed.
The trading partner information can be found on the BSEG line of the intercompany expense account. (FB03).