COMPRESS [NUMERIC] [FULL]
|
|||||
|
|
operand1 [(parameter)] |
|
|||
SUBSTRING (operand1,operand3,operand4)
[(parameter)]
|
|||||
INTO
|
|
operand2 |
|
||
SUBSTRING
(operand2,operand5,operand6)
|
|||||
|
|
LEAVING [SPACE]
|
|
|||
LEAVING NO [SPACE]
|
|||||
WITH [ALL] [DELIMITERS] [operand7]
|
|||||
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statements: ASSIGN | COMPUTE | EXAMINE | MOVE | MOVE
ALL | SEPARATE
Belongs to Function Group: Arithmetic and Data Movement Operations
The COMPRESS statement is used to transfer (combine) the contents of one or
more operands into a single field.
Operand Definition Table:
| Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1
|
C | S | A | G | N | A | U | N | P | I | F | B | D | T | L | G | O | yes | no | |
operand2
|
S | A | U | B | yes | yes | ||||||||||||||
operand3
|
C | S | N | P | I | B* | yes | no | ||||||||||||
operand4
|
C | S | N | P | I | B* | yes | no | ||||||||||||
operand5
|
C | S | N | P | I | B* | yes | no | ||||||||||||
operand6
|
C | S | N | P | I | B* | yes | no | ||||||||||||
operand7
|
C | S | A | U | B | yes | no | |||||||||||||
* Format B of operand3,
operand4,
operand5 and
operand6 may be used only with a length of
less than or equal to 4.
Syntax Element Description:
| Syntax Element | Description | |
|---|---|---|
NUMERIC |
Handling of Sign Characters:
This option determines how sign characters and decimal characters are to be handled: Without COMPRESS -123 1.23 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: 123*123 With For floating point source values, decimal points and signs are transferred,
regardless of whether Example 1:
COMPRESS NUMERIC -123 1.23 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: -123*1.23 Example 2:
COMPRESS NUMERIC 'ABC' -0056.00 -0056.10 -0056.01 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: ABC*-56*-56.1*-56.01 Example 3:
COMPRESS NUMERIC FULL 'ABC' -0056.00 -0056.10 -0056.01 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: ABC*-0056.00*-0056.10*-0056.01 |
|
FULL
|
Handling of Source Field Values:
Without
For a numeric source field containing all zeros, one zero will be transferred. For example: COMPRESS 'ABC ' 001 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: ABC*1 With
are displayed as entered. For example: COMPRESS FULL 'ABC ' 001 INTO #TARGET WITH DELIMITER '*' Content of #TARGET is: ABC *001 |
|
operand1
|
Source Fields:
As Note Using
- Time variable (format T) is transferred only with the time component,
not the date component. |
|
operand2
|
Target Field:
As If the target field is of format U (Unicode) and if a source field of format B is involved, the length of the sending binary field must be even. |
|
LEAVING SPACE
|
Values in Target Field Separated by a Blank: If
you use the COMPRESS statement without any further options, or if you
specify LEAVING SPACE (which also applies by default), the values in
the target field will be separated from one another by a blank.
|
|
LEAVING NO SPACE
|
Values in Target Field Not Separated: If you
specify LEAVING NO SPACE, the values in the target field will not be
separated from one another by a blank or any other character.
|
|
parameter
|
Print Mode/Date Format/Edit Mask Parameters: As
parameter, you can specify the session
parameters PM, DF, EM, or EMU:
|
|
PM=I |
In order to support languages whose writing direction is from right to left,
you can specify MOVE 'XYZ' TO #A COMPRESS #A (PM=I) 'ABC' INTO #B LEAVING NO SPACE Any trailing blanks in |
|
DF |
If operand1 is a date
variable, you can specify the session parameter DF as
parameter for this variable.
|
|
EM= |
Edit Mask: For details on edit masks, see the
session parameter EM in the Parameter Reference. The
EM parameter cannot be applied for group operands or when
the SUBSTRING option is used.
|
|
EMU= |
Unicode Edit Mask: For details on Unicode edit
masks, see the session parameter EMU in the Parameter Reference. The
EMU parameter cannot be applied for group operands or
when the SUBSTRING option is used.
|
|
SUBSTRING
(operand1, operand3, operand4)
|
SUBSTRING Option: If
operand1 is of alphanumeric (A),
Unicode (U) or binary (B) format, you can use the SUBSTRING option to
transfer only a certain part of a source field. After the field name
(operand1) you
specify first the starting position
(operand3) and then the length
(operand4) of the field portion to be
transferred.
|
|
INTO
SUBSTRING (operand2,
operand5, operand6)
|
INTO Clause:
Also, you can use the In both cases, the use of the |
|
WITH DELIMITERS
|
Input Delimiter Character:
If you wish the values in the target field to be separated from one another by
a specific character, you use the If you specify |
|
WITH DELIMITERS
operand7
|
Specific Delimiter Character: If you specify
WITH DELIMITERS operand7, the values
will be separated by the character specified with
operand7.
operand7 must be a single character.
If operand7 is a variable, it must be of
format/length (A1) or (B1).
If the target field is of format A or B, the format/length of the delimiter has to be (A1), (B1) or (U1). If the target field is of format U (Unicode), the format/length of the delimiter has to be (A1), (B2) or (U1). |
|
WITH ALL
|
Handling of Delimiters:
Without COMPRESS 'A' ' ' 'C' ' ' INTO #TARGET WITH DELIMITERS '*' Content of #TARGET is: A*C With COMPRESS 'A' ' ' 'C' ' ' INTO #TARGET WITH ALL DELIMITERS '*' Content of #TARGET is: A**C* |
|
A destination field of format B is handled like a destination field of format A.
The COMPRESS operation terminates when either all operands have been
processed or the target field (operand2) is filled.
If the target field contains more positions than all operands combined, all remaining
positions of operand2 will be filled with blanks.
If the target field is shorter, the value will be truncated.
If operand2 is a dynamic variable, the
COMPRESS operation terminates when all source operands have been processed.
No truncation will be performed. The length of
operand2 after the COMPRESS
operation will correspond to the combined length of the source operands. The current
length of a dynamic variable can be ascertained by using the system variable *LENGTH.
This section covers the following topics:
** Example 'CMPEX1': COMPRESS
************************************************************************
DEFINE DATA LOCAL
1 EMPLOY-VIEW VIEW OF EMPLOYEES
2 NAME
2 FIRST-NAME
2 MIDDLE-I
*
1 #COMPRESSED-NAME (A20)
END-DEFINE
*
LIMIT 4
READ EMPLOY-VIEW BY NAME
COMPRESS FIRST-NAME MIDDLE-I NAME INTO #COMPRESSED-NAME
DISPLAY NOTITLE
FIRST-NAME MIDDLE-I NAME 5X #COMPRESSED-NAME
END-READ
*
END
FIRST-NAME MIDDLE-I NAME #COMPRESSED-NAME
-------------------- -------- -------------------- --------------------
KEPA ABELLAN KEPA ABELLAN
ROBERT W ACHIESON ROBERT W ACHIESON
SIMONE ADAM SIMONE ADAM
JEFF H ADKINSON JEFF H ADKINSON
** Example 'CMPEX2': COMPRESS (with LEAVING NO SPACE)
************************************************************************
DEFINE DATA LOCAL
1 EMPL-VIEW VIEW OF EMPLOYEES
2 NAME
2 CURR-CODE (1)
2 SALARY (1)
*
1 #CCSALARY (A20)
END-DEFINE
*
LIMIT 4
READ EMPL-VIEW BY NAME
COMPRESS CURR-CODE (1) SALARY (1) INTO #CCSALARY
LEAVING NO SPACE
DISPLAY NOTITLE
NAME CURR-CODE (1) SALARY (1) 5X #CCSALARY
END-READ
*
END
NAME CURRENCY ANNUAL #CCSALARY
CODE SALARY
-------------------- -------- ---------- --------------------
ABELLAN PTA 1450000 PTA1450000
ACHIESON UKL 11300 UKL11300
ADAM FRA 159980 FRA159980
ADKINSON USD 34500 USD34500
** Example 'CMPEX3': COMPRESS (with delimiter)
************************************************************************
DEFINE DATA LOCAL
1 EMPL-VIEW VIEW OF EMPLOYEES
2 NAME
2 CURR-CODE (1)
2 SALARY (1)
*
1 #CCSALARY (A20)
END-DEFINE
*
LIMIT 4
READ EMPL-VIEW BY NAME
COMPRESS CURR-CODE (1) SALARY (1) INTO #CCSALARY
WITH DELIMITER '*'
DISPLAY NOTITLE NAME CURR-CODE (1) SALARY (1) 5X #CCSALARY
END-READ
*
END
NAME CURRENCY ANNUAL #CCSALARY
CODE SALARY
-------------------- -------- ---------- --------------------
ABELLAN PTA 1450000 PTA*1450000
ACHIESON UKL 11300 UKL*11300
ADAM FRA 159980 FRA*159980
ADKINSON USD 34500 USD*34500
** Example 'CMPEX4': COMPRESS (with edit mask EM)
************************************************************************
DEFINE DATA LOCAL
1 #A10 (A10) INIT <'ABCDEF'>
1 #I4 (I4) INIT <-123>
1 #T (T) INIT <E'2021-11-22 10:24:36'>
1 #L (L) INIT <TRUE>
1 #RESULT (A70)
END-DEFINE
*
COMPRESS '#A:' #A10 (EM=X_X_X)
'#I4:' #I4 (EM=-999Z)
'#T:' #T (EM=YYYY-MM-DD_HH:II)
'#L:' #L (EM=FALSE/TRUE) INTO #RESULT
PRINT #RESULT
END
#A: A_B_C #I4: -0123 #T: 2021-11-22_10:24 #L: TRUE