Validation: Prevent GL Account Sets from Posting to Cost Centers
There’s always an issue that SAP users by mistake post production consumption to cost centers through MIGO or manually although production consumption accounts should only be posted to production orders.
The best way to prevent this mistake is to use Validation Rules (Trx GGB0) and specify the GL accounts that are not allowed on a cost center so the user gets an error whenever SAP is posting these GLs to a Cost Center.
Since validation rules are part of system config, it’s a lot of headache to change the GLs in the rule later in case a new GL is created or an exception is needed.
To be able to edit the rule’s GLs without doing any configuration, we can maintain an Account Set in the validation rule instead of specific GL accounts, in this case the Set can be edited freely in Production environment (by authorized users).
This will involve creating a user exit and editing a copy of a standard SAP program
1) Trx GS01 > Create the Account set
2) Trx SE38 > Copy program RGGBR000 to ZRGGBR000 and add the below code at the end of the standard code
exits-name = ‘ZCC’.
exits-param = c_exit_param_none.
exits-title = text-103.
FORM ZCC USING b_result.
RANGES: GLS FOR BSEG–HKONT.
Select VALSIGN AS SIGN VALOPTION AS OPTION
VALFROM AS LOW VALTO AS HIGH
FROM SETLEAF INTO CORRESPONDING FIELDS OF TABLE GLS
WHERE SETNAME = ‘GL_CC_BLOCK‘.
if SY–SUBRC = 0.
IF BSEG–HKONT IN GLS.
b_result = b_true.
b_result = b_false.
GL_CC_BLOCK is the name of the Account Set
3) Trx GCX2 >> Assign program ZRGGBR000 to Validation Rule Exits
4)Trx GGB0 >> Create Validation
5) Trx OB28 >> Activate Validation on the company code level
Now test the validation using any transaction, try FB50
Thank you for reading.