Hi Murthy,
I request you to go through the below blog,
Partner Functions Validations on sales and service order documents
Also am not sure whether you can code inside the function module. Go through the above blog and check whether it helps, please try the user exits that has been used in the blog to achieve your requirement.
Hope this helps
Regards,
Satish