DECIDE ON

#### Search Results

Search

# DECIDE ON

`DECIDE ON`
| `FIRST` `EVERY` |  | `[VALUE] [OF]` |  | op1 `SUBSTR` (op3,op5,op6) |  |  |  |  |  |  |  |
| `VALUE` |  | op2 `SUBSTR` (op4,op7,op8) |  |  |  | `:` |  | op2 `SUBSTR` (op4,op7,op8) |  |  | statement |
,
`[ANY` `[VALUE]` statement `]`
`[ALL` `[VALUE]` statement `]`
`NONE` `[VALUE]` statement
`END-DECIDE`

This document covers the following topics:

- Function

- Syntax Description

- Examples

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Related Statements: `DECIDE FOR` | `IF` | `IF SELECTION` | `ON ERROR`

Belongs to Function Group: Processing of Logical Conditions

## Function

The `DECIDE ON` statement is used to specify multiple actions to be performed depending on the value (or values) contained in a variable.

Note
If no action is to be performed under a certain condition, you must specify the statement `IGNORE` in the corresponding clause of the `DECIDE ON` statement.

## Syntax Description

Operand Definition Table:

Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition
--- | --- | --- | --- | ---
`op1` |  | S | A |  | N | A | U | N | P | I | F | B | D | T | L |  | G | O | yes | no
`op2` | C | S | A |  |  | A | U | N | P | I | F | B | D | T | L |  | G | O | yes | no
`op3` |  | S | A |  |  | A | U |  |  |  |  | B |  |  |  |  |  |  | yes | no
`op4` | C | S | A |  |  | A | U |  |  |  |  | B |  |  |  |  |  |  | yes | no
`op5` | C | S |  |  |  |  |  | N | P | I |  | B * |  |  |  |  |  |  | yes | no
`op6` | C | S |  |  |  |  |  | N | P | I |  | B * |  |  |  |  |  |  | yes | no
`op7` | C | S |  |  |  |  |  | N | P | I |  | B * |  |  |  |  |  |  | yes | no
`op8` | C | S |  |  |  |  |  | N | P | I |  | B * |  |  |  |  |  |  | yes | no

* Format B of `op5`, `op6`, `op7` and `op8` may be used only with a length of less than or equal to 4.

Syntax Element Description:

Syntax Element | Description
--- | ---
`FIRST/EVERY` | Processing of Values: With one of these keywords, you indicate whether only the first or every value that is found is to be processed.
`op1` | Selection Field: As `op1` or `op2` you specify the name of the field whose content is to be checked.
`VALUES op2 [[,op2] ... [:op2]statement ...` | VALUES Clause: With this clause, you specify the value (`op2`) of the selection field, as well as the `statement(s)` which are to be executed if the field contains that value. You can specify one value, multiple values, or a range of values optionally preceded by one or more values. Multiple values must be separated from one another either by the input delimiter character (as specified with the session parameter `ID`) or by a comma. A comma must not be used for this purpose, however, if the comma is defined as decimal character (with the session parameter `DC`). For a range of values, you specify the starting value and ending value of the range, separated from each other by a colon.
`SUBSTRING` | SUBSTRING Option: Without the `SUBSTRING` option, the whole content of a field is checked. The `SUBSTRING` option allows you to check only a certain part of an alphanumeric, Unicode or binary field. After the field name (`op3`), you specify first the starting position (`op5`) and then the length (`op6`) of the field portion to be checked.
`SUBSTRING (op4,op7,op8)` | SUBSTRING Option: After the field name (`op4`), you specify first the starting position (`op7`) and then the length (`op8`) of the field portion to be checked.
`ANY statement` | ANY Clause: With `ANY`, you specify the `statement(s)` which are to be executed if any of the values in the `VALUES` clause are found. These statements are to be executed in addition to the statement specified in the `VALUES` clause.
`ALL statement` | ALL Clause: With `ALL`, you specify the `statement(s)` which are to be executed if all of the values in the `VALUES` clause are found. These statements are to be executed in addition to the statement specified in the `VALUES` clause. The `ALL` clause applies only if the keyword `EVERY` is specified.
`NONE statement` | NONE Clause: With `NONE`, you specify the `statement(s)` which are to be executed if none of the specified values are found.
`END-DECIDE` | End of DECIDE ON Statement: The Natural reserved word `END-DECIDE` must be used to end the `DECIDE ON` statement.

## Examples

- Example 1 - DECIDE ON with FIRST Option

- Example 2 - DECIDE ON with EVERY Option

### Example 1 - DECIDE ON with FIRST Option

    ** Example 'DECEX3': DECIDE ON (with FIRST option)
    ************************************************************************
    *
    SET KEY ALL
    INPUT 'Enter any PF key' /
          'and check result' /
    *
    DECIDE ON FIRST VALUE OF *PF-KEY
      VALUE 'PF1'
        WRITE 'PF1 key entered.'
      VALUE 'PF2'
        WRITE 'PF2 key entered.'
      ANY VALUE
        WRITE 'PF1 or PF2 key entered.'
      NONE VALUE
        WRITE 'Neither PF1 nor PF2 key entered.'
    END-DECIDE
    *
    END

#### Output of Program DECEX3:

    Enter any PF key
    and check result

#### Output after pressing PF1:

    Page      1                                                  05-01-11  15:08:50

    PF1 key entered.
    PF1 or PF2 key entered.

### Example 2 - DECIDE ON with EVERY Option

    ** Example 'DECEX4': DECIDE ON (with EVERY option)
    ************************************************************************
    DEFINE DATA LOCAL
    1 #FIELD (N1)
    END-DEFINE
    *
    INPUT 'Enter any value between 1 and 9:' #FIELD (SG=OFF)
    *
    DECIDE ON EVERY VALUE OF #FIELD
      VALUE 1 : 4
        WRITE 'Content of #FIELD is 1-4'
      VALUE 2 : 5
        WRITE 'Content of #FIELD is 2-5'
      ANY VALUE
        WRITE 'Content of #FIELD is 1-5'
      ALL VALUE
        WRITE 'Content of #FIELD is 2-4'
      NONE VALUE
        WRITE 'Content of #FIELD is not 1-5'
        END-DECIDE
    *
    END

#### Output of Program DECEX4:

    ENTER ANY VALUE BETWEEN 1 AND 9: 4

#### After entering and confirming `4`:

    Page      1                                                  05-01-11  15:11:45

    Content of #FIELD is 1-4
    Content of #FIELD is 2-5
    Content of #FIELD is 1-5
    Content of #FIELD is 2-4

### On this page

- Function
- Syntax Description
- Examples