Hi Anagha,
Please find, in the following SAP Help link, all the information to reach your goal:
User-Defined Functions - Variant Configuration (LO-VC) - SAP Library
In detail, with a User-Defined Function you should be able to set characteristic values based on certain conditions, via an ABAP function and an object dependency.
Feel free to come back here in case further info is needed.
Thanks and regards,
Flavio