PLI Day2

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Logical Testing

Logical testing
It is used when a test or decision is to be made between alternatives.
SIMPLE IF : A single statement will appear as the action to be taken if the condition tested

is TRUE. If the condition tested is false, the THEN keyword is ignored and the program continues immediately with the next sequential statement. IF cond THEN stmt; COMPOUND IF: If the condition tested is true the statement following the then clause is executed otherwise the statement following the ELSE clause is executed. IF cond THEN stmt1; ELSE stmt2; DO grooup in an IF statement: When it is logically necessary to execute more than one statement following the THEN or ELSE the DO group is used. DO; X = 1; Y = 2; END;

Logical testing
Nested IF statement:
IF A = B THEN IF A = C THEN X = 1; ELSE X = 2; ELSE X = 3;

NULL ELSE: It is a non-operative statement. It gives no direction to the computer.


IF A = B THEN IF A = C THEN X = 1; ELSE; ELSE X = 3;

PROGRAM SWITCHES :Program switches can be tested by using the indicator name e.g.
IF MORE_RECORDS THEN ELSE

Logical testing
SELECT (optional expression here); WHEN(expression1) ACTION1; WHEN(expression2) ACTION2; WHEN(expression3) ACTION3; OTHERWISE ACTION4; END; Following keyword SELECT an expression or even nothing may be specified. Program action after WHEN can be a DO group or another SELECT group. Max. permissible nesting of SELECT is 49, but there is not limit to the number of WHEN clause in a SELECT. Logical operators can be used in IF stmt

& |

NOT AND OR

Ex. IF A = B & C = D THEN X = 1;

Logical testing
CONDITIONS AND ON UNITS
A CONDITION is the occurrence within a PL/I program that causes a program

interrupt. In the absence of a program specifying an action, for most conditions the standard system action is to print a message, raise the ERROR condition and the terminate the PL/I program and return control to the OS. In PL/I the ON statement is used to specify action to be taken when any subsequent occurrence of a specified condition causes a program interrupt. Ex. ON ENDFILE(SYSIN) BEGIN; PUT SKIP(3) LIST(TOTAL); PUT PAGE LIST(NO OF RECORDS PROCESSED,COUNT) END_OF_FILE = YES; END;

Logical testing
The ENDFILE condition:

This condition is raised during a GET or READ operation. It is caused by an attempt to read past the last record for the file named in the GET or READ statement. After ENDFILE is raised no further GETs or READs should be executed for that file. This condition is raised when a PUT statement results in an attempt to start a new line beyond the limit specified by PAGESIZE.ENDPAGE is raised only once per page. When it is raised standard system action is to skip to a new page and continue execution with the PUT statement, which caused the ENDPAGE condition to occur.

The ENDPAGE condition:

Logical testing
The CONVERSION condition:

Occurs whenever a conversion is attempted on character data containing characters that are invalid for the conversion being performed. e.g DCL X BIT(4); X = 10A1; It occurs when the precision of the result of a fixed point arithmetic operation exceeds N digits. For most PL/I implementations, N is 15 for decimal fixed point values and 31 for binary fixed point values. DCL (A , B, C) FIXED DEC (15); A = 40000000; B = 80000000;

The FIXEDOVERFLOW condition:

Logical testing
The OVERFLOW condition:

It Occurs when the magnitude of a floating point number exceeds the permitted maximum. (For most cases it must not be greater than 1075 or 2252 . e.g. A = 55E71; B = 23E11; C = A * B; /* RESULTING EXPONENT IS LARGER HAN 10**75 It occurs when the magnitude of a floating point number is smaller than the permitted minimum. For most cases value may not be less than 10-78 or 2-260 A = 23E-71; B = 3E-9; C =A*B; /* Resulting exponent is smaller than 10**-78 */

The UNDERFLOW condition:

The ZERODIVIDE condition:

Logical testing
The Size Condition:

It occurs when high order ( leftmost non zero binary or decimal digits) are lost in an assignment operation. The size condition differs from FIXEDOVERFLOW condition in the sense , FIXEDOVERFLOW occurs when the calculated precision exceeds the maximum allowed, where as SIZE condition occurs when data item size exceeds the declared size. DCL V1 fixed dec(4); DCL V2 FIXED DEC(5) init(12345); V1 = V2; /* size condition */ The identifiers V1 and V2 require 3 bytes of storage even though their precision differs. However V1 must always have a 0 in its leftmost position of the leftmost byte. 09 99 9 Physically space is there to contain an additional digit; logically however the space is not available. Hence the size condition;

File Declarations and STREAM I/O

Subroutines and Functions


DECLARATION
File name can be of 1 to 7 characters long. File attributes include

Type of transmission. (STREAM or RECORD) Direction of transmission. (INPUT, OUTPUT or UPDATE) Physical environment of the file. (Record size, blksize etc..) Ex.DCL INVEN FILE INPUT STREAM ENV (options). FILE attribute It specifies that the identifier being declared is a file. It can be implied if other file attributes are present in the DECLARE that enable the compiler to deduce the file attribute. e,g, DCL BILLING INPUT STREAM ENV(F BLKSIZE(150));

You might also like