Step 1:-
Create a message ID via transaction code SE91 for message class /EACC/MSG/ACC_COMP. The message text should be which you want to display to the user.
Step 2:-
Go to transaction GGB0 and create the validation step at line item level in Financial Accounting as below:-
Pre Requisits:-
If Posting Key is '31' or '25'
Check:-
Create a exit code using user exit and check for the account group of the vendor
For this take the help of ABAPer and create a copy of the program RGGBR000 and code your check here and assign to the application area GBLR in view V_T80D via transaction code SM30.
Message:-
Message created in step 1 as error message.
Step 3:-
Please also check that this validation has active status (Status=1) at line item level for your company code in transaction OB28.