Hi Karan,
For:
1. Idocs extension: To populate custom fields in extended idoc exits are there. Please search on scn you will find exit names.
2. Masking on sensitive data: why you are developing custom program. Is there any specific needs ?
Hope below links will be useful for you.
Masking sensitive data in ALE transfer - ERP Human Capital Management - SCN Wiki
Encrypting the Display of Sensitive Data - IDoc Interface/ALE - SAP Library