Of course, I've complained incessantly about the unpredictable behavior of certain COBOL verbs (namely STRING, UNSTRING, INSPECT, SEARCH, and SEARCH ALL for those of you who are wondering) in various forums and I've encountered another example of having to do this again.
I am trying to do something where I repeatedly concatenate string values together using STRING. As an example, if I set up a loop whereby I concatenate values in a table, say:
Now to use my loop to turn this into a proper sentence, I would need to string these values together using a temporary value as shown in my code above. One rather unpredictable thing I already encountered and solved is that I must move my current formed sentence to a temp-value before I string it back...now if we look at our code:
The problem here is that I have to use the double spaces as delimiters to preserve my spaces in my text. Yet I get unpredictable results when I run this. Depending on the lengths of my values I place in my data table, I might get no spaces, I might get one, I might get two as part of the table value.
So how do I counter this unpredictable behavior of STRING?
I am trying to do something where I repeatedly concatenate string values together using STRING. As an example, if I set up a loop whereby I concatenate values in a table, say:
Code:
01 MY-TABLE-DATA.
04 TABLE-VALUES.
08 pic x(09) value "MY".
08 PIC X(09) VALUE "BROWN".
08 PIC X(09) VALUE "DOG".
08 PIC X(09) VALUE "POSSESSES".
08 PIC X(09) VALUE "MANY".
08 PIC X(09) VALUE "FLEAS".
04 WORDS-TABLE REDEFINES TABLE-VALUES PIC X(09) OCCURS 6.
01 concat-data.
04 concat-value pic x(80).
04 concat-temp-value pic x(80).
Now to use my loop to turn this into a proper sentence, I would need to string these values together using a temporary value as shown in my code above. One rather unpredictable thing I already encountered and solved is that I must move my current formed sentence to a temp-value before I string it back...now if we look at our code:
Code:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 6
MOVE CONCAT-VALUE TO CONCAT-TEMP-VALUE
STRING WORDS-VALUE (I) DELIMITED BY ' '
SPACE DELIMITED BY SIZE
CONCAT-TEMP-VALUE DELIMITED BY ' '
INTO CONCAT-VALUE
END-PERFORM.
MOVE CONCAT-VALUE TO CONCAT-TEMP-VALUE.
STRING CONCAT-TEMP-VALUE DELIMITED BY ' '
'.' DELIMITED BY SIZE
INTO CONCAT-VALUE.
The problem here is that I have to use the double spaces as delimiters to preserve my spaces in my text. Yet I get unpredictable results when I run this. Depending on the lengths of my values I place in my data table, I might get no spaces, I might get one, I might get two as part of the table value.
So how do I counter this unpredictable behavior of STRING?