Exercise 3: UNSTRING With Fewer Real Words Than Destination Fields — Possible Solution ==================================================================== WHAT UNSTRING ACTUALLY DOES, STEP BY STEP This chapter's own UNSTRING example scans WS-FULL-NAME left to right, splitting it at each real space it finds and filling the three destination fields - WS-FIRST-NAME, WS-MIDDLE-NAME, WS-LAST-NAME - one at a time, in the order they're listed, as each real split is found. WHAT HAPPENS WITH "JANE DOE" INSTEAD OF THREE WORDS With "JANE DOE," UNSTRING finds exactly one real space, producing exactly two pieces: "JANE" and "DOE." The first piece, "JANE," genuinely goes into WS-FIRST-NAME. The second piece, "DOE," genuinely goes into WS-MIDDLE-NAME - the next destination field in the list - since UNSTRING has no way of knowing that "DOE" was meant to be a last name rather than a middle one; it simply fills destination fields in order as real pieces become available. WHAT HAPPENS TO THE THIRD DESTINATION FIELD, WS-LAST-NAME Once the entire sending field has been examined and no further real splits remain, UNSTRING genuinely stops. WS-LAST-NAME, the third destination field, never receives any real piece of data at all - there simply wasn't a third piece to give it. UNSTRING doesn't clear it, blank it out, or raise any error over the shortfall; it's simply left holding whatever value it already contained before the UNSTRING statement ran. WHY THIS IS GENUINELY WORTH KNOWING This means a real program that assumes UNSTRING will always populate every one of its destination fields is making a genuinely risky assumption. If WS-LAST-NAME happened to hold real, meaningful leftover data from an earlier customer record processed just before this one, that stale value would still be sitting there after this UNSTRING runs - silently mislabeled as belonging to "JANE DOE" - with nothing in the program's own behavior signaling that anything went wrong. ANSWER: With "JANE DOE," UNSTRING finds only one real delimiter (the single space), producing two pieces rather than three. "JANE" goes into WS-FIRST-NAME and "DOE" goes into WS-MIDDLE-NAME, since destination fields are filled strictly in the order given as real pieces become available - not by any real understanding of what a "middle name" or "last name" actually means. WS-LAST-NAME, the third destination field, receives nothing at all once the sending field is exhausted; it's left holding whatever value it already had beforehand, with no error or automatic clearing. A real program should not assume every UNSTRING destination field is genuinely refreshed on every execution - a field left untouched can silently carry stale data forward from an earlier operation. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly traces UNSTRING's real in-order, delimiter-driven filling behavior against a genuinely mismatched two-word input, and identifies the concrete real consequence (an untouched, potentially stale destination field) rather than incorrectly assuming an error or automatic blanking occurs.