Hi Mahesh,
Now I know what your issue is for the numbering. Since the array for contract numbers only has two elements that is why you get the index of 2 instead of 3 on the last reference segment. In order to adjust for that you would need to make sure you use "mapWithDefault" on the UDF input for the contract number values and that would mean that ze1ekpd1 and ContNo arrays would both have the same number of elements - thus allowing you to remove the try/catch block that was inserted previously.
Regards,
Ryan Crosby