Joined: 16 May 2006 Posts: 3 Location: Johannesburg
The UNSTRING verb is a nice way of coding fewer lines. But in terms of efficiency, the compiler is going intepret the UNSTRING verb and generate more code than what you would have coded if you were to code/unstring the field with your own code. The difference in performance is negligible. I would a sacrifice a small increase in performance for readability by using the UNSTRING verb as you have done.
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix
UNSTRING is fine for breaking up the component fields, but it will not provide the requirement to "shift" the lines up so that the content is filled from the top with the lower entries containing spaces.
One question i had is what should happen if the person who enters the data keys in line2 and line4 and leaves 1 & 3 blank or for whatever reason only enters data in line3? Etc. . . .
After the UNSTRING you could try to STRING delim by " " (space) into an "WS-ALL-STRINGS field. This will eliminate the "empty" fields.
Spaces embedded in each field can be a problem. I don't remember and haven't checked how UNSTRING places the string into each receiving field, but initing them with X'FF' and STRINGing delimed by X'FF' may solve that problem (8/13 - I tried the X'FF' - it didn't work. I was hoping that UNSTRING did a Ref/Mod MOVE of the string sements to the receiving field, but no such luck.)
But you can delim the STRING w/multiple spaces if you know what the maximum spaces in each string might possibly be.