Previous Topic: CREATE CommandNext Topic: DECREMENT Command


DECODE Command

(Area 3)

The DECODE command translates a specified set of values from a source field into a different set of values in a result field.

The format of the DECODE command is as follows:

►►─┬────────────────┬─ DECODE ─ sourcefield ─ INTO ───────────────────────────►
   └─ label: ───────┘

                            ┌─────────────────────┐
 ►─┬─ resultfield ────────┬─▼─ argument=function ─┴───────────────────────────►
   ├─ resultfield(n1) ────┤
   └─ resultfield(n1.n2) ─┘

 ►─┬────────────────────────────────┬─────────────────────────────────────────►
   └─┬─ OTHERWISE ─┬─ defaultvalue ─┘
     └─ ELSE ──────┘

 ►─┬─────────────────────────────────────────────────┬────────────────────────►◄
   └─┬─ HEADING ─┬─ ' heading 1 ' ─┬───────────────┬─┘
     └─ HDG ─────┘                 └─ 'heading 2' ─┘
label:

Specifies an optional identifying label that allows a GOTO branch to be made to this statement.

sourcefield

Specifies the predefined field whose range of values are to be translated. The field can reside either in the input record area or the GSA, but you must predefine it.

resultfield

Specifies the name of the field into which the translated value is to be placed on completion of the DECODE sequence. When this field has not been predefined, The Reporting Facility generates the field automatically in the GSA.

resultfield(n1)

Specifies implicit definition of the result field as alphanumeric, n1 bytes long. The result field must not be a predefined field. The result field resides on the GSA.

resultfield(n1.n2)

Specifies implicit definition of the result field as numeric, containing n1 integers and n2 decimals. The result field must not be a predefined field and resides in the GSA in packed decimal format.

argument

Specifies the value to be tested against the contents of the source field. Code the value as either a numeric constant or an alphanumeric literal, based on the attributes assigned to the source field.

=function

Specifies the value to be placed in the result field when the contents of the source field match the contents of the corresponding argument. The value must be coded as either a numeric constant or an alphanumeric literal based on the attributes assigned to the result field.

defaultvalue

Specifies the value to be placed in the result field after the system has exhausted the entire list of arguments and found no match. When coded, it must be either a numeric constant or an alphanumeric literal based on the attributes assigned to the result field.

HEADING

Specifies an optional separator used to denote that subsequent literals are to be interpreted as headings. Heading specifications are valid only when you are implicitly defining the result field of the transaction. HDG can be used in place of HEADING.

'heading 1' 'heading 2'

Enables you to assign one or two heading lines to the result field. You implicitly define the field in the DECODE command. Heading lines appear as column headings if the field prints in a report.

If the parameter is omitted and the result field is implicitly defined, the Reporting Facility automatically assigns the field name as heading line 1, with no second heading line.

Note the following:

Example

 DECODE CODE INTO GENDER                        Predefined result field
	 1 EQ 'MALE'
        2 EQ 'FEMALE'
 DECODE TRANSACTION-CODE INTO TCODE(23)         Alphanumeric implicit
        'BF' EQ 'BALANCE BROUGHT FORWARD'         field definition
        'CK' EQ 'CHECK WRITTEN'
        'SC' EQ 'SERVICE CHARGE'
        'DP' EQ 'DEPOSIT'
        ELSE   'UNKNOWN TRANSACTION'
        'TYPE OF'  'TRANSACTION'
DECODE SOMETHING INTO SOMETHING-ELSE(2.3)       Numeric implicit
        'ABCDEF' EQ +12.345                       field definition
        'GHIJKL' EQ  -67.89
        'MNOPQR' EQ      0
        OTHERWISE      9.9