Not certain what you are attempting to do but if what you want is to generate a key for a file knowing the fields then you probably just need to use the KEY function.
For example if you have a multi-segment key of something like productno, ciientno, and date as key number 3, you can generate a key string with:
k$ = KEY(fileno, kno=3, key=productno$:clientno$:date$)
This will insert any required padding and return you a key based on the values you provided.