Posting the whole code and just asking "tell me what is wrong" without mentioning what the actual issue is seems rather ineffective. Besides, we are all supposed to troubleshoot the program ourselves before posting on SCN.
There are BAPIs available for customer master and in the migration context most frequently LSMW is used and not the custom programs. Also, as Juergen correctly pointed out, we just don't use XD99 in such way, it makes no sense.
You might want to go back to the specification and get better understanding of what the actual requirement is. It seems the design has not been thought through here. If there is a specific technical challenge then kindly share more details.