With a COMPRESS statement the contents of one or more operands (Vari or Const) can be concatenated
into a single target field. Beside some other options, two different clauses are available to determine the value separation behavior.
(1) With LEAVING SPACE (also default), the values in the target field will be separated from each other by a blank.
Ex: COMPRESS ‘ABC’ 1 ‘XYZ’ INTO #T LEAVING SPACE -> WRITE #T shows ‘ABC 1 XYZ’
(2) With LEAVING NO SPACE, the values put into the target are placed directly one after the other, w/o any separation char between.
Ex: COMPRESS ‘ABC’ 1 ‘XYZ’ INTO #T LEAVING NO SPACE -> WRITE #T shows ‘ABC1XYZ’
Problem
Practical examples are showing, in many cases a COMPRESS running with a mix of both modes would be useful. Some field pairs should be generated in a compressed form (no blank between), others should appear separated from each other.
Example: COMPRESS 'Error' #ERR 'came from DB file (' #DBID '/' #FNR ') ..
wanted layout -> Error 1234 came from DB file (10/32)
but with (1) COMPRESS 'Error' #ERR 'came from DB file (' #DBID '/' #FNR ')' INTO #T LEAVING SPACE
the result is -> Error 1234 came from DB file ( 10 / 32 ) <- unwanted blanks in the bracket
but with (2) COMPRESS 'Error' #ERR 'came from DB file (' #DBID '/' #FNR ')' INTO #T LEAVING NO SPACE
the result is -> Error1234came from DB file (10/32) <-first tokens should not be connected
Solution
Introduce a new option to request a blank spacing at any position you like, a SPACER element.
When you use a COMPRESS with LEAVING NO SPACE you can add “1X” elements at any position you like.
The default is to have no blanks between the fields, but the programmer can request space(s) at any place.
Ex: COMPRESS 'Error' 1X #ERR 1X 'came from DB file (' #DBID '/' #FNR ')' INTO #T LEAVING NO SPACE
makes wanted -> Error 1234 came from DB file (10/32)
The spacer element is not limited to a single blank, you can insert up to 40 blanks.
COMPRESS 'A’ 1X ‘B’ 2X ‘C’ 3X ‘D’ INTO #T LEAVING NO SPACE -> WRITE #T shows ‘A B C D’
Risk
Close to nothing, since the usage of a spacer “nX” was not permitted until now and would have caused a syntax error when used.
Chance
With the new spacer option you can generate the wanted layout of the sample above with a single COMPRESS,
whereas w/o the spacer clause two COMPRESS statements are required, such as
COMPRESS '(' #DBID '/' #FNR ')' INTO #HELPER LEAVING NO SPACE
COMPRESS 'Error' #ERR 'came from DB file' #HELPER INTO #T
The new programming default could be to run COMPRESS always with LEAVING NO SPACE and to add the space manually at the wanted places.