1. Conditional expressions

Conditional expression은 참값에 대한 판별에 의해 프로그램에서 선택적으로 실행 로직을 변경할 수 있도록 한다. Conditional expression은 EVALUATE, IF, PERFORM 그리고 SEARCH statement에 사용될 수 있다.

Conditional expression은 다음의 2가지로 나눌 수 있다.

  • Simple conditions

  • Complex conditions

1.1. Simple conditions

Simple condition은 참 또는 거짓의 값을 가진다.

Simple conditions은 다음 4 종류가 있다.

  • Class condition

  • Condition-name condition

  • Relation condition

    Relation condition은 2개의 오퍼랜드를 비교한다. 비교는 다음으로 정의된다.

    • 두 개의 Alphabetic class operands

    • 두 개의 Alphanumeric class operands

    • 두 개의 DBCS class operands

    • 두 개의 Numeric class operands

    • Alphabetic class operand와 alphanumeric class operand

    • Numeric integer operand와 alphanumeric class operand

    • Index 또는 index data item의 비교

    • 두 개의 data pointer operands

    • 두 개의 procedure pointer operands

    • 두 개의 function pointer operands

    • Alphanumeric group과 DISPLAY 또는 DISPLAY-1 usage를 가지는 operand

    Relation condition에는 다음의 2가지 종류가 있다.

    • General relation conditions

    • Data pointer Relation conditions

  • Sign condition

  • Switch-status condition

Class conditions

데이터 항목의 내용이 alphabetic, alphabetic-lower, alphabetic-upper, numeric, DBCS, KANJI인지 또는 environment division의 SPECIAL-NAMES paragraph에 정의된 CLASS clause에 기술된 문자를 포함하는지를 판별한다.

figure pd class condition
Class conditions Format
  • identifier-1

    • 다음에 기술된 USAGE를 가진 데이터 항목을 참조해야 한다.

      • NUMERIC이 기술된 경우 : DISPLAY, COMPUTATIONAL-3, PACKED-DECIMAL

      • DBCS가 기술된 경우 : DISPLAY-1

      • ALPHABETIC, ALPHABETIC-UPPER 또는 ALPHABETIC-LOWER가 기술되었을 때 : DISPLAY

      • Class-name이 기술된 경우 : DISPLAY

    • identifier-1이 function-identifier이면 반드시 alphanumeric function을 참조해야 한다.

    • 다음 중에 하나를 설정한다.

      항목 설명

      NOT

      참값의 판별을 반대로 한다.

      예를 들면 NOT NUMERIC은 NUMERIC class 판별이 거짓일 때 결과가 참이 된다.

      NUMERIC

      identifier-1이 모두 0 ~ 9의 숫자로 구성되어 있다.

      ALPHABETIC

      identifier-1은 대소문자 구분없이 알파벳 문자 A ~ Z와 공백 문자로 구성되어 있다.

      ALPHABETIC-LOWER

      identifier-1은 소문자 알파벳 a ~ z와 공백 문자로 구성되어 있다.

      ALPHABETIC-UPPER

      identifier-1은 대문자 알파벳 A ~ Z와 공백 문자로 구성되어 있다.

      class-name

      identifier-1은 SPECIAL-NAMES paragraph class-name에 정의된 문자들로 구성되어 있다.

      DBCS

      identifier-1은 DBCS 문자들로 구성되어 있다.

아래 표는 사용 가능한 데이터 항목의 타입과 class condition 사이의 관계를 보여 준다.

Type of data item Reference by identifier-1 Valid forms of the class condition

Alphabetic

ALPHABETIC

ALPHABETIC-LOWER

ALPHABETIC-UPPER

class-name

NOT ALPHABETIC

NOT ALPHABETIC-LOWER

NOT ALPHABETIC-UPPER

NOT class-name

Alphabetic,

Alphabetic-edited,

Numeric-edited

ALPHABETIC

ALPHABETIC-LOWER

ALPHABETIC-UPPER

NUMERIC

class-name

NOT ALPHABETIC

NOT ALPHABETIC-LOWER

NOT ALPHABETIC-UPPER

NOT NUMERIC

NOT class-name

External-decimal,

Internal-decimal

NUMERIC

NOT NUMERIC

DBCS

DBCS

NOT DBCS

Numeric

NUMERIC

class name

NOT NUMERIC

NOT class name

Condition-name conditions

Condition-name은 conditional variable을 검사하여 그 값이 연관된 condition-name의 어떠한 값과 같은지를 판별한다.

figure pd condition name condition
condition-name format
항목 설명

condition-name-1

Relation condition을 약식으로 사용할 때 사용된다. Conditional variable과 condition-name 값과의 비교 규칙은 Relation condition의 규칙과 동일하다.

condition-name-1이 범위를 가진 값이라면, conditional variable은 그 값이 범위에 포함되는지를 판별하여 검사된다. conditional variable의 값이 conditon-name의 값들 중 하나와 같다면 결과는 참이된다.

다음 예제는 conditional variables와 condition-name의 사용법을 보여준다.

01 AGE-GROUP PIC 99.
 88 INFANT VALUE 0.
 88 BABY VALUE 1, 2.
 88 CHILD VALUE 3 THRU 12.
 88 TEENAGER VALUE 13 THRU 19.

AGE-GROUP은 conditional variable이다. INFANT, BABY, CHILD와 TEENAGER는 condition-name이다.

다음의 IF문은 AGE-GROUP의 값을 바탕으로 age group을 결정한다.

IF INFANT... (Tests for value 0)
IF BABY... (Tests for values 1, 2)
IF CHILD... (Tests for values 3 through 12)
IF TEENAGER... (Tests for values 13 through 19)
General relation conditions

General relation condition은 두 개의 오퍼랜드를 비교한다. 오퍼랜드는 identifier, literal, arithmetic expression 또는 index-name이 될 수 있다.

figure pd general relation
General relation condition format
항목 설명

operand-1

Relation condition의 subject이다. Identifier, literal, function-identifier, arithmetic expression 또는 index-name이 될 수 있다.

operand-2

Relation condition의 object이다. Identifier, literal, function-identifier, arithmetic expression 또는 index-name이 될 수 있다.

General Relation condition에서 데이터 항목, 리터럴 그리고 Figurative constants는 다음의 비교 형태에 따라 비교된다.

비교 형태 설명

Alphanumeric

두 오퍼랜드의 Alphanumeric 문자 비교

DBCS

두 오퍼랜드의 DBCS 문자 비교

Numeric

두 오퍼랜드의 대수적인 값 비교

GROUP

한쪽이 Alphanumeric 그룹 항목일 때 두 오퍼랜드의 Alphanumeric 문자 비교

(Int)

정수형 item만 비교(Alph, Num, Group와 같이 사용)

Blank

비교될 수 없음

다음 표들은 다른 종류의 오퍼랜드에 대한 가능한 비교의 짝을 보여준다.

figure pd table24 1
Comparisons involving data items and literals
figure pd table25
general relateion condition format
  • Alphanumeric comparisons

    • 두 오퍼랜드의 single-byte character 비교를 수행한다. 비교는 collating sequence에 정의된 순서에따라 수행된다.

    • 두 오퍼랜드 중 하나가 alphanumeric 혹은 alphabetic이 아닐 경우, 다음의 과정이 수행된다.

      1. Zoned decimal integer operand는 같은 사이즈의 Zoned decimal alphanumeric 아이템으로 취급된다.

      2. display floating-point 아이템은 numeric value가 아니라 alphanumeric 아이템으로 취급된다.

    • 두 오퍼랜드의 size가 같으면, leftmost character에서 rightmost까지 비교해가며, 최초의 서로다른 character가 발견되었을때, 그 character의 collating sequence를 비교하여 우선순위를 정한다.

    • 두 operand의 size가 다르면, 짧은쪽의 operand에 space를 긴 쪽의 오퍼랜드의 size만큼 붙이고, comparision을 진행한다.

  • DBCS comparisions

    Alphanumeric comparision과 비교 과정이 동일하다. binary hexadecimal collating sequence를 사용한다.

  • Numeric comparisions

    두 오퍼랜드의 대수 비교를 수행한다.

  • Group comparisions

    두 오퍼랜드의 Alphanumeric character comparision을 수행한다. Alphanumeric elementary data item 비교와 동일한 취급을 한다.

  • Index comparisions

    두 인덱스 아이템의 비교는 인덱스 아이템이 갖고있는 occurrence number의 비교를 수행하는 것이다. 인덱스와 데이터 항목 또는 literal을 비교한다면 occurrence number와 data, literal 값을 비교하게 된다.

Data pointer Relation conditions

Pointer 데이터 항목에 대해서는 오직 같은지 다른지에 대해서만 비교할 수 있다. Pointer 데이터 항목은 USAGE POINTER로 정의된 데이터 항목이거나 ADDRESS OF 특수 레지스터이다.

Relation condition인 IF, PERFORM, EVALUATE와 SEARCH (format-1) statement에 사용될 수 있다. SEARCH format-2(SEARCH ALL)에는 사용하지 말아야 한다.

figure pd data pointer relation
Data pointer Relation condition Format
항목 설명

identifier-1, identifier-3

level-66, level-88을 제외한 어떠한 데이터 항목도 사용 가능하다.

identifier-2, identifier-4

USAGE POINTER로 정의된 데이터 항목이다.

NULL, NULLS

NULL pointer이다.

Procedure-pointer and function-pointer Relation conditions

같은지, 같지 않은지에 대해 비교만 가능하다.

figure pd procedure function pointer relation
Procedure-pointer and function-pointer relation conditions Format
항목 설명

identifier-1, identifier-3

USAGE PROCEDURE-POINTER 또는 FUNCTION-POINTER여야 한다.

NULL, NULLS

NULL pointer이다.

Sign conditions

Sign condition은 Numeric 오퍼랜드의 값이 0보다 큰지, 작은지, 같은지를 판별한다.

figure pd sign condition
sign condition Format
항목 설명

operand-1

Numeric identifier 또는 Arithmetic expression이어야 한다.

0보다 크면 POSITIVE, 0보다 작으면 NEGATIVE, 0과 같으면 ZERO가 된다.

부호 없는 오퍼랜드는 POSITIVE 또는 ZERO가 될 수 있다.

NOT

참, 거짓의 판별을 바꾼다. 예를 들어 NOT ZERO는 오퍼랜드가 0이 아닌 양수나 음수값을 가질 때 참이 된다.

Switch-status conditions

switch status condition은 UPSI siwitch의 ON 혹은 OFF 상태를 정의한다. UPSI switch의 value 상태에 따라 결과가 결정된다.

figure pd switch condition
Switch-status condition Format
항목 설명

condition-name

special-names paragraph에 정의된 UPSI switch이다.

1.2. Complex conditions

Complex condition은 logical operator를 사용한 simple conditions, combined conditions의 결합이나 logical negation을 사용한 condition의 negating 등으로 만들어진다. 각각의 logical operator은 앞뒤로 공백 문자가 있어야 한다.

괄호를 사용하지 않는다면 다음 순서에 따라 우선순위가 정해진다.

  1. Arithmetic operator

  2. Simple conditions

  3. NOT

  4. AND

  5. OR

Complex condition의 참값은 각각의 simple condition의 참값과 logical operator와의 상호 관계에 따라 판별된다. Complex condition은 다음이 될 수 있다.

  • Negated simple condition

  • Combined conditon(Negated 될 수 있다.)

Nagated simple conditions

Simple conditons은 logical operator NOT을 사용하여 참, 거짓 값을 바꿀 수 있다.

figure pd negated simple conditions
Nagated simple conditions Format
항목 설명

conditions-1

conditions-1의 참, 거짓 판별에 대해 반대의 결과를 내놓는다.

conditions-1이 참이면 전체 결과는 거짓이되고, condition-1 결과가 거짓이면 전체 결과는 참이 된다.

condition-1이 괄호로 묶여 있어도 결과는 같다. 예를 들면 다음 두 문장은 동일하다.

NOT A IS EQUAL TO B
NOT ( A IS EQUAL TO B )
Combined conditions

2개 이상의 conditions들이 logical operator로 연결되어 Combined condition을 만든다.

figure pd combined conditions
Combined condition Format

다음에 열거된 것들이 condition-1이나 condition-2에 올 수 있다.

  • Simple condition

  • Nagated simple condition

  • Combined conditon

  • Nagated combined condition(logical operator NOT 다음에 괄호로 묶여진 combined condition이 오는 경우)

다음 표는 logical operator와 condition C1, C2의 관계이다.

Value for C1 Value for C2 C1 AND C2 C1 OR C2 NOT (C1 AND C2) NOT C1 AND C2 NOT (C1 OR C2) NOT C1 OR C2

True

True

True

True

False

False

False

True

False

True

False

True

True

True

False

True

True

False

False

True

True

False

False

False

False

False

False

False

True

False

True

True

Abbreviated combined Relation conditions

Relation conditions가 연속적으로 쓰여질 때 첫 번째 Relation condition 후의 Relation condition은 다음 2가지 방법 중 하나로 축약될 수 있다.

  • Subjecet의 생략

  • Subjecet와 Relation operator의 생략

figure pd abbreviated combined relation conditions
Abbreviated combined Relation condition Format

연관되는 relation conditon에서 두 가지 형태로 축약될 수 있다. Abbreviated condition은 다음처럼 판별된다.

  • 마지막에 기술된 subject가 생략된 subject이다.

  • 마지막에 기술된 relation operator가 생략된 operator이다.

다음 표는 축약된 condition의 예이다.

Abbreviated combined relation condition Equivalent

A = B AND NOT < C OR D

((A = B) AND (A NOT < C)) OR (A NOT < D)

A NOT > B OR C

(A NOT > B) OR (A NOT > C)

NOT A = B OR C

(NOT (A = B)) OR (A = C)

NOT (A = B OR < C)

NOT ((A = B) OR (A < C))

NOT (A NOT = B AND C AND NOT D)

NOT ((((A NOT = B) AND (A NOT = C)) AND (NOT (A NOT = D))))