I was trying to write an ad-hoc source conversion tool that would correct EBCDIC->ASCII translation of source files that had binary character data embedded in their string literals (we are using a compiler that is Linux hosted, but targets the original EBCDIC runtime character set.) I was trying to deal with ascii sources that had messed up lines like:
10 FILLER PIC X(03) VALUE '^A^@<97>'.
whereas what was actually desired was
10 FILLER PIC X(03) VALUE X'010008'.
If that tool was fully general, I'd wanted it be able to handle replacement of something like:
10 FILLER PIC X(010) VALUE 'Hi^A^@<97>There'.
With that in mind I was hoping that there was a "V6.2 Enterprise COBOL" compiler compatible syntax (in case back porting to the original system was required) to concatenate multiple string constants into a single VALUE clause, something like the following:
IDENTIFICATION DIVISION.
PROGRAM-ID. FOO.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 my-var PIC X(10) VALUE 'Hi' X'01' X'00' X'08' 'There'.
PROCEDURE DIVISION.
DISPLAY my-var
GOBACK
.
HOWEVER: After cobbling together an initial version of my tool, I found that in the ~150/7000 sources in the project that had binary character literals in them, the literals were uniformly unprintable in all but one single case (which I handled manually). So, the fully general concatenation operation that I thought would be desired was not actually required for this project (although it could be for other future projects.)
I'll leave this question open in case somebody is aware of an Enterprise COBOL compatible way of doing this string literal concatenation.
To concatenate multiple alphanumeric or national literals COBOL provides the concatenation operator &
since COBOL 2002 (support may be missing in your compiler):
01 my-var PIC X(120) VALUE X"F0" & "hi there" & X"F1".
Some dialects (and COBOL2023) also provide an intrinsic function for concatenation of any type:
DISPLAY FUNCTION CONCAT (X"F0" "hi there" X"F1" " FROM " your-name-var).