IBM Mainframes PLI Training Class5 Structures Introduction A
IBM Mainframes PL/I Training Class-5
Structures Introduction A structures is a collection of data items inter related to one another, whose data types can be same or different. Structures are three types: Major Structures: Declared using Level Number 1. Minor Structures: Declared using Level Number 2 - 255. Elementary Items: Declared using Level Number 2 – 255 The only difference between elementary and minor structures is: the minor structures are structures within the major structures just like sub group.
Structures Level Numbers When a data structure is declared the level of each data name is indicated by level number. Level Numbers : To declare structures we use level numbers these level numbers starts with 1 and can go maximum up to 255. Level number 1 is used to indicate the major structures and remaining from 2 – 255 are used for both minor and elementary data names. The elementary data names are the actual data name having a data type. Each name of the deeper level is given a greater number to indicate the level depth. Level number must be followed by a space.
Structures In Detail § DCL 1 EMPLOYEE, 2 NAME CHAR(30), 2 SALARY FIXED DECIMAL(7, 2); Name of the whole structure is EMPLOYEE, and each element in it, has it's own name and it's attributes. During processing elements can be addressed singly or all together using the structure name. A single element can be addressed by it's name. § Name = ‘ANIL KUMAR'; Put list(EMPLOYEE); Put list(NAME, SALARY); § The above two statements have the same meaning.
Structures DCL 1 NEW, 2 NAME, 2 ADDRESS, 2 PAYMENT, 3 GROSS, 3 NET, 2 DEDUCTIONS; § In Detail DCL 1 OLD, 2 NAME, 2 ADDRESS, 2 PAYMENT, 3 GROSS, 3 NET, 2 DEDUCTIONS; Some times two different structures may have the elements which have the same names. At that time we can use BY NAME clause to assign data correspondingly from one structure to another. NEW = OLD, BY NAME; Or we can do it by , NEW. NAME = OLD. NAME; NEW. PAYMENT. GROSS = OLD. PAYMENT. GROSS; NEW. PAYMENT. NET = OLD. PAYMENT. NET;
Structures Program EMPPGM: PROCEDURE OPTIONS(MAIN); DCL 1 EMPREC, 3 EMPID FIXED BINARY(15) INIT(0), 3 EMPNAME CHAR(10) INIT(‘ '), 3 EMPLOC, 5 CITY CHAR(10) INIT(' '), 5 STATE CHAR(10) INIT(' '), 5 PINCODE CHAR(10) INIT(' '), 3 EMPSAL FIXED DECIMAL(7, 2) INIT(0); GET LIST(EMPID, EMPNAME, , STATE, CITY, PINCODE, EMPSAL); PUT LIST(EMPID, EMPNAME, STATE, CITY, PINCODE, EMPSAL); END EMPPGM;
IF-THEN-ELSE
IF-THEN-ELSE Introduction § In programming, Many times a program needs to run one or more sets of statements based on some condition § If the condition is true, one set of statements get executed. If condition is false another set of statements will get executed. § Conditional statements alters' the control flow of the execution based on a condition. § In PLI the Conditional statements are § IF-THEN Statement. § SELECT Statement.
IF-THEN-ELSE Combined conditions contains two or more conditions connected using logical operators AND OR & | Format condition-1 <AND/OR> condition-2 [ <AND/OR> condition-3 ]. . .
IF-THEN-ELSE Combined conditions Below table gives the results of using logical operators AND & OR between two conditions COND 1 & COND 2. COND 1 COND 2 COND 1 & COND 2 COND 1 | COND 2 TRUE TRUE FLASE TRUE FLASE
IF-THEN-ELSE Relation Condition § Relation condition compares two operands either of which can be an identifier, literal, arithmetic expression. Format Operand 1 <relational operator> Operand 2 The Relational operator specifies the type of comparison
IF-THEN-ELSE Relational Operator GREATER THAN NOT GREATER THAN Relational Operator Can be written as > ¬> LESS THAN < NOT LESS THAN ¬< EQUAL TO = (NOT ¬ NOT EQUAL TO ¬= GREATER THAN OR EQUAL >= LESS THAN OR EQUAL TO <= alt-170)
IF-THEN-ELSE Syntax for : Syntax IF THEN , IF-THEN ELSE IF CONDITION THEN STATEMENT; IF CONIDTION THEN STATEMENT; ELSE STATEMENT; § NULL statement : - Null statement consists of ONLY a semicolon. it is used where logically no statement is necessary. IF STATMENT THEN; ELSE STATEMENT;
IF-THEN-ELSE Do BLOCK § Do block is used when a set (more than one) of statements has to be executed when IF condition is true. § § DO in an IF statement indicates start of a DO group block. END in an IF statement indicates end of a DO group block. IF A > B THEN DO; X = 100; Y = 50; END; ELSE DO; X = Y; C = Z + 10; END;
IF-THEN-ELSE EMPGEN: PROC OPTIONS(MAIN); DCL EMP_GENDER CHAR(1) INIT(' '); GET LIST(EMP_GENDER); IF EMP_GENDER = 'M' THEN PUT SKIP LIST(' EMPLOYEE IS MALE'); IF EMP_GENDER = 'F' THEN PUT SKIP LIST(' EMPLOYEE IS FEMALE'); IF EMP_GENDER = 'M' THEN PUT SKIP LIST(' EMPLOYEE IS MALE'); ELSE PUT SKIP LIST(' EMPLOYEE IS FEMALE'); Example
IF-THEN-ELSE Example IF EMP_GENDER = 'M' THEN PUT SKIP LIST(' EMPLOYEE IS MALE'); ELSE; IF EMP_GENDER = 'F' THEN PUT SKIP LIST(' EMPLOYEE IS FEMALE'); ELSE PUT SKIP LIST(' ERROR IN INPUT GENDER VALUE ');
IF-THEN-ELSE Example STUDET: PROCEDURE OPTIONS(MAIN); DCL STUNAME CHAR(10); DCL (SUB 1, SUB 2, SUB 3) FIXED DECIMAL(3) INIT(0); DCL (TOTAL, AVG) FIXED BINARY; GET LIST(STUNAME, SUB 1, SUB 2, SUB 3); PUT LIST(STUNAME, SUB 1, SUB 2, SUB 3); TOTAL = SUB 1 + SUB 2 + SUB 3; PUT SKIP LIST(TOTAL); AVG = TOTAL / 3; IF AVG >= 70 & AVG <= 100 THEN PUT SKIP LIST('PASS WITH FIRST CLASS'); ELSE IF AVG >= 50 & AVG <= 69 THEN PUT SKIP LIST('PASS WITH SECOND CLASS'); ELSE IF AVG >= 35 & AVG <= 49 THEN PUT SKIP LIST('PASS WITH THIRD CLASS'); ELSE PUT SKIP LIST('ERROR IN AVG OR FAIL '); END STUDET;
SELECT statement
SELECT statement Introduction A select-group provides a multiple path conditional branch. A select-group contains a SELECT statement, optionally one or more WHEN statements, optionally an OTHERWISE statement, and an END statement. § The general form of select statement is: SELECT(EXP 1); WHEN(EXP 2) UNIT 1; WHEN(EXP 3) UNIT 2; WHEN(EXP 4) UNIT 3; WHEN(EXP 5) UNIT 4; OTHERWISE UNIT 5; END;
SELECT statement In Detail SELECT (exp 1) The SELECT statement and its corresponding END statement, delimit a group of statements collectively called a select-group. The expression in the SELECT statement is evaluated and its value is saved. WHEN (exp 2, . . . ) unit Specifies one or more expressions that are evaluated and compared with the saved value from the SELECT statement. If an expression is found that is equal to the saved value, the evaluation of expressions in WHEN statements is terminated, and the unit of the associated WHEN statement is executed. If no such expression is found, the unit of the OTHERWISE statement is executed.
SELECT statement In Detail OTHERWISE unit Specifies the unit to be executed when every test of the preceding WHEN statements fails. If the OTHERWISE statement is omitted and execution of the select-group does not result in the selection of a unit, the ERROR condition is raised. Note: Condition are invalid on OTHERWISE statements. Unit: Each unit is either a valid single statement, a group, or a begin block. DECLARE, DEFAULT, END, ENTRY FORMAT, PROCEDURE, and % Reference statements are not valid. SELECT statement can also have DO BLOCK.
SELECT statement § In Detail Select statement without any expression/condition must have a logical expression with the when clause. SELECT; WHEN ( CONDITION) imperative statement; WHEN (CONDITION) imperative statement; OTHERWISE imperative statement; END;
SELECT statement Example SELECT(GENDER); WHEN (‘M’) PUT SKIP LIST(‘CUSTOMER IS MALE’); WHEN (‘F’) PUT SKIP LIST(‘CUSTOMER IS FEMALE); OTHERWISE; PUT SKIP LIST(‘ERROR IN VALUE’); END
Thank You
- Slides: 24