IBM Global Services

A Short Course in PL/I

Programming Language 1

© Copyright IBM Corporation 2004

IBM Global Services

AGENDA 
Introduction to PL/I  Data Types and Data Manipulation.  Subroutines and Functions  Dos and arrays  File declarations and Stream I/O  Record I/O, Structures, Pictures  Storage classes and List processing

2

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

ELEMENTS Of a PL/I program 
Form :  E.G.:LABEL : PROCEDURE OPTIONS(MAIN); AVERAGE : PROCEDURE OPTIONS(MAIN);

Must Specify for Main Program May be abbreviated as PROC

Programmer Selects this name(label)

3

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

µ % .$) .* / ( ) . .#. They include: ..Ten Decimal Digits (0.Z.29 Characters (A . 4 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services Character Sets  There are 60 characters in PL/I Language.. @.9) . : ¬ & | > < _ ?  A special 48 character set is also available as an alternative to the 60 character set.21 Special Characters (Blank = + .

Names of DATA ( 1 to 31 alphabetic characters A.LABLES of PL/I statements . . .g GET . ‡ Internal Procedures: Nested within an external procedure.IBM Global Services IDENTIFIERS  The general term IDENTIFIERS is given to: .KEYWORDS (e. PUT ) 5 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .g.e.Names of PROCEDURES ( Seven or eight characters for external procedures) ‡ External Procedures: Name must be know to the operating system.. Main Procedure.#..Names of FILES ( Seven or eight characters) .9 and break _ ) . Subprograms.Z @.$ numeric digits 0.

READ_STMT: GET LIST(A. Consists of KEYWORDS and programmer defined Identifiers and /or Constants Selected by the Programmer Selected from the PL/I Language Selected from the PL/I language and identifies the type of PL/I statement Selected by the Programmer.g. © Copyright IBM Corporation 2004 6 Presentation Title | Confidential | 30-Nov-10 .IBM Global Services Statement Format  LABEL : KEYWORD STATEMENT OPTIONS. most statements are not labeled e.C).B.

.A statement may be continued across several lines. .One line may contain several PL/I statements.Position1 : Reserved for use by the operating system. 7 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .Position 73-80:May contain program identification name and/or a sequence number. the compiler however does not check for consecutive order of the sequence numbers.  Accepted IBM standard for typing PL/I programs: . .IBM Global Services PL/I Language Characteristics  PL/I is free form i.e. . .Position 2-72: May Contain one or more PL/I statements or part of statements.A statement may contain blanks as needed to improve readability of the source program.

78.g.Bit String Constants: These constants are written in a program as a series of binary digits enclosed in single quote marks and followed by the letter B.¶ . Examples are: 8 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . which specifies a power of two. and q is the number of binary digits specified to the right of the binary point. 2. e.g.1234. The mantissa is a binary fixed-point constant.g. a decimal point. followed immediately by the letter B. 180. .q) where p is the total number of binary digits. These constants are written using exponential notation.Decimal Fixed point constants: These consists of one or more decimal digits and.Binary Fixed Point Constants: It consists of one or more binary digits with an optional binary point.g. 0. . µ1010101¶B.Decimal Floating Point: e. +56. .Character String Constants: These constants are alpha numeric data items that may include any of the up to 256 characters recognized by the computer. They have a precision (p. The exponent is the letter E. e.00009 .IBM Global Services PL/I Constants  A constant is a data item that does not have a name and whose value cannot change in a program. 1. optionally.Binary Floating Point Constants: A binary floating-point constant is a mantissa followed by an exponent and the letter B. followed by an optionally signed decimal integer. Binary floating-point constants have a precision (p) where p is the number of binary digits of the mantissa.g. e. 10110B . e.30000E+01. µTHIS IS A PL/1 CHARACTER CONSTANT.

IBM Global Services DECIMAL Arithmetic Data Items  e.g. e.168325E20 = 168325 * (10**20) 9 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .102.g.30 125. :.3E5 decimal fixed point decimal floating point  A floating point number consists of 2 parts fraction and exponent. :.

IBM Global Services LIST DIRECTED I/O  Useful for debugging and not used in production type jobs. 10 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

.g.A Null field is indicated by the first non blank character or by two commas separated by an arbitrary number of blanks. If the statement is GET LIST (A. the values keyed could be 100 90 80 70 90.IBM Global Services LIST DIRECTED I/O  GET LIST (List directed input) .E).B.e. .D.For this type of input each data value in the stream must separated either by a blank or a comma. 11 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .C.

.e. ‡ e.g. PUT SKIP LIST(123).Use SKIP(n) option to move the line feed to the nth line after the current line. ‡ e.Values of the data list items are converted to character representations and transmitted to the data stream. . ‡ Tab position 1 ‡ 1st Line ‡ 2nd Line 25 50 86 49 ABC 87 73 123 97 127 121 23 . PUT LINE(10) LIST (A.B).IBM Global Services LIST DIRECTED I/O  PUT LIST (List directed output) .Use PAGE option causes the data to be printed on the top of a new page. Lets consider the following: ‡ PUT LIST (50.g.¶ABC¶.87).g. .g. PUT PAGE LIST(µIGSI¶). ‡ PUT LIST(23. 12 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .A blank separates successive data values transmitted.123. ‡ e.127).Use LINE option to print the data on a specific line number. .86.

IBM Global Services Data types and Data Manipulation © Copyright IBM Corporation 2004 .

DECLARE  Mode: real. The syntax for the DECLARE statement. Default is It is either Fixed or Float. It is either Decimal or Binary. the minimum of valid digits to be regarded as significant.IBM Global Services DECLARE statement  The DECLARE statement specifies attributes of a name and its position determines the scope of the declaration of the name. 14 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .  Precision: Precision means number of figures that a fixed point data item can hold or in case of floating point.  Scale:  Base: variable_name mode scale base precision  Abbreviation: DCL Mode of an arithmetic item is either real or complex.

IBM Global Services DECLARE statement  Implicit Declaration: . is invalid ‡ DCL PI FLOAT DECIMAL(6. It must follow either (or both) base or scale in the declaration. ‡ DECLARE QUANTITY(5. Note: Do not specify fractions in the precision attribute for floating point data.It specifies the number of significant digits of data and/or the decimal or binary point alignment. the implied attribute for the variable will be FIXED BINARY (15).0). 15 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .  Precision Attribute: .An identifier beginning with any alphabetic letter other than I through N and not described in a DECLARE statement. It is never specified alone. DECLARE QUANTITY FIXED DECIMAL(5. is invalid. has the implied attributes of FLOAT DECIMAL(6). ‡ e.When a variable name begins with the letter I through N and is simply used in a program without appearing in a DECLARE statement. Precision is either attributed by default or along with base and /or scale.5).g.0).

If the mode is not declared. 7. REAL is assumed.g. 8 + 2I where I is ¥-1.14E10I 16 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services DECLARE statement  Mode Attribute: It specifies whether a variable has the REAL or COMPLEX attribute. e.

2). It is possible to make a partial DECIMAL FLOAT declaration of a variable. - BINARY FLOAT DECIMAL BINARY FIXED The following table summarizes the defaults FLOAT that are taken for partially declared None ± initial variables. @.0) DECIMAL(5. DCL DD FLOAT(16). DCL D FLOAT. The Scale and he Precision: DCL CC FIXED(9. 2.$ 17 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 3.0) BINARY FIXED (15) Ideally arithmetic data are described with DECIMAL FIXED three basic attributes: base. To declare partially a variable name is to specify one of BINARY FIXED the following: 1. O-Z.0) (6) (15. The Base and Precision: DCL AA DECIMAL(16).0) (21) FLOAT(6) FLOAT(21) DECIMAL(5. scale and precision. DCL BB BINARY(53). The Scale: DCL C FIXED. DCL B BINARY. The Base : DCL A DECIMAL. 4.#.IBM Global Services DECLARE statement  - Partially Declared Identifiers: Declared Attributes Default attributes (5. character I-N None Initial character DECIMAL FLOAT (6) A-H.

Length attribute of 1 bit for the identifier PL/I keyword for declaring bit-string data Programmer specified identifier  Bits are used for switches. 18 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .g..e. indicators etc. .IBM Global Services Declare Statement (String Data Attribute)  String Data Attributes: . DECLARE MORE_RECORDS BIT(1).A String is a sequence of characters or bits that is treated as a single data item.

It causes the length specification of the identifier to be affectively adjusted to describe the length of each data item assigned to it. NAME = µIBM GLOBAL SERVICES¶. DCL NAME CHAR(20) VARYING. NAME = µ ¶. NAME = µMOHAN¶ 4. because no character string is assigned to it. 19 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . /* NULL STRING */ ‡ ‡ ‡ ‡ In stmt 1 NAME has a length of zero. In stmt 2 NAME will have a length of 19 In stmt 3 NAME will have a length of 5 In stmt 4 length become zero again. e.IBM Global Services Declare Statement (Varying Attribute)  VARYING attribute: It is used when padding of blanks to the right is not desired. 2. 3.g. Consider the following examples 1.

.X = µ11001¶B. /* X = µ1100¶B */ 20 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL X BIT(4) VARYING. .Varying attribute may be specified for identifiers that have character or bit attribute.g.e.IBM Global Services Declare Statement .Truncation occurs if the length of an assigned string exceeds the maximum declared for the varying length string variable: .

In addition one of the name being declared may represent either all or part of the same storage as that assigned to the other. e. DCL NAME CHAR(20) INITIAL (µIBM GLOBAL SERVICES¶). More than one item may be overlay defined. The base identifier cannot have the DEFINED attribute. 1. Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL FIRST CHAR(3) DEFINED NAME. 2.g. Identifier NAME is called the base identifier This process is called overlay defining.       21 In stmt1 NAME has the value µIBM GLOBAL SERVICES¶.IBM Global Services Declare Statement (Defined Attribute)  DEFINED attribute: It allows you to equate two or more different names to the same storage area. In stmt2 identifier FIRST has the value IBM.

g. POS(11). LIST LIST POS(21). 22 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . A_LIST B_LIST C_LIST In this example A_LIST refers to the first 10 characters of the identifier LIST. CHAR(10) CHAR(20) CHAR(10) DEF DEF DEF LIST.IBM Global Services Declare Statement (Position Attribute)  POSITION attribute. B_LIST refers to the 21st through 40th characters of LIST.  It may be specified in overlay defining of bit and character strings. C_LIST refers to the 11th through 20th characters of LIST. DECLARE LIST CHAR(40). e.

Only one value can be specified for an element variable.An INITIAL attribute specifies an initial value or values to a variable at the time storage is allocated to it.g. DCL PAGE_CT FIXED BINARY (15) INITIAL(0).2) INITIAL (24.  Good programming practice: . E. . use meaningful data names and INIT them in DCL stmt. DCL HEADING CHAR(22) INIT(µWEEKLY ACTIVITY REPORT¶). DCL AMT FIXED DECIMAL (7. identifier may be set to an initial value by adding INITIAL attribute to the DECLARE statement.IBM Global Services Declare Statement (Initial Attribute)  INITIAL attribute: .For program constants. more than one can be used for array attribute.For program variables and indicators DCL them but initialize them using assignment statements.50). DECLARE DATA_ERROR BIT(1) INIT(µ0¶B). 23 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

6000 00042 24 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . Decimal fixedpoint data is stored two digits to the byte.4) (5.6 042. with a sign indication in the rightmost 4 bits of the rightmost byte. DCL HOUR_1 FIXED DEC(P. even though the declaration of the variable can specify the number of digits.0).60 042. . as an even number.2) (7.1) (5.IBM Global Services Declare Statement (PL/I DATA Attribute)  FIXED DECIMAL: . the point is assumed to be immediately to the right of the rightmost digit.6 2. p.60 .A decimal fixed-point constant consists of one or more decimal digits with an optional decimal point. Consequently.The default precision is (5. If no decimal point appears.0) 42.6) (3.q). a decimal fixed-point data item is always stored as an odd number of digits.2) (1. Decimal fixedpoint constants have a precision (p. where p is the total number of digits in the constant and q is the number of digits specified to the right of the decimal point.Q) INIT(42.1) (3.

is stored as a fullword. two of which are fractional.(A halfword is 15 bits plus a sign bit. where p is the total number of binary digits in the constant.IBM Global Services Declare Statement (PL/I DATA Attribute)  FIXED BINARY: . .The default precision is (15.DECLARE FACTOR BINARY FIXED (20. followed immediately by the letter B. Binary fixed-point constants have a precision (p. and q is the number of binary digits specified to the right of the binary point.A binary fixed-point constant consists of one or more binary digits with an optional binary point. .2).0). A binary fixed-point data item with: ‡ 15 digits or less is stored as a fixed-point binary halfword ‡ More than 15 digits. and a fullword is 31 bits plus a sign bit). ‡ FACTOR is declared a variable that can represent binary fixed-point data items of 20 digits. up to 31. Examples are: .q). 25 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

Constant Precision 15E-23 (2) 15E23 (2) 4E-3 (1) 1.IBM Global Services Declare Statement (PL/I DATA Attribute)  FLOAT DECIMAL: . short floatingpoint form is used. Decimal floating-point data is stored as normalized hexadecimal floating-point. If the declared precision is less than or equal to (6). . If the declared precision is greater than (16). Decimal floating-point constants have a precision (p). where p is the number of digits of the mantissa.decimal floating-point constant is a mantissa followed by an exponent. which specifies a power of ten.96E+07 (3) 438E0 (3) 3141593E-6 (7) . long floating-point form is used. extended floating-point form is used. If the declared precision is greater than (6) and less than or equal to (16).003141593E3 (9) The last two examples represent the same value (although with different precisions). Examples are: .Suitable for working with very large or very small numbers. 26 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . with the hexadecimal point assumed to the left of the first hexadecimal digit.The default precision is (6). . The exponent is the letter E followed by an optionally signed integer. The mantissa is a decimal fixed-point constant.

Binary floating-point constants have a precision (p) where p is the number of binary digits of the mantissa.Constant Precision 101101E5B (6) 101. The exponent cannot exceed three decimal digits. The mantissa is a binary fixed-point constant. long floating-point form is used. If the declared precision is less than or equal to (21). which specifies a power of two.01E+42B (4) . 27 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . Binary floating-point data is stored as normalized hexadecimal floating-point. extended floating-point form is used. followed by an optionally signed decimal integer. If the declared precision is greater than (53). If the declared precision is greater than (21) and less than or equal to (53). short floating-point form is used. .A binary floating-point constant is a mantissa followed by an exponent and the letter B.101E2B (6) 11101E-28B (5) 11. The exponent is the letter E. Examples are: .IBM Global Services Declare Statement (PL/I DATA Attribute)  FLOAT BINARY: .No diff between FLOAT DEC and FLOAT BIN in main storage.The default precision is (21).

‡ Maximum length is 8000 bits for constants and 32767 bits for variables.The CHARACTER or CHAR attribute specifies a character variable.IBM Global Services Declare Statement (PL/I DATA Attribute)  BIT and CHARACTER: . . ‡ If BIT string is larger than the assigned field only leftmost bits are assigned. ‡ Padding takes place with blanks instead of zeros as in bits. rest are similar. 28 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . Character strings can also be declared using the PICTURE attribute ‡ Maximum length 1000 characters for constants and 32767 characters for variables.The BIT attribute specifies a bit variable.

B. array. or pseudovariables.  TOTAL_COST = COST*QUANTITY.g.IBM Global Services The ASSIGNMENT Statement  The assignment statement evaluates an expression and assigns its value to one or more target variables. e. The target variables can be element. as well as for specifying computations. 29 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . C = D*E.  A. or structure variables.  The assignment statement is used for internal data movement.

EXPONENTIATION (Symbol: **): Moving from right to left in an expression .IBM Global Services ARITHMETIC Operations  The order in which Arithmetic operation is performed is: .  When Parenthesis are specified elements within the parenthesis will be evaluated first.ADDITION (SYMBOL +) OR subtraction (Symbol -) whichever appears first moving from left to right in an expression. .MULTIPLICATION (Symbol: *) or Division (Symbol /) whichever appears first moving from left to right. starting with the innermost pair of parenthesis. 30 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

+ . . Y = X ** -A is equivalent to Y = X**(-A) 31 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .e. ¬) are performed before Infix operations.g.IBM Global Services ARITHMETIC Operations  Prefix operations( ..

Negation .g ±A**2 ‡ The order is .Negation .-A**-Y ‡ The order is . (X+5)**3.e.IBM Global Services ARITHMETIC Operations  Any expression or element may be raised to a power and the power may have either a positive or negative value.e. the order of priority of those operators is from right to left .Exponentiation . X**(J*2).g. X**-A  If two or more operators of highest priority appear in the same expression. .Exponentiation .Negation 32 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

IBM Global Services CONCATENATION FULL_NAME2 = LAST_NAME || µ . ¶ || FIRST_NAME . PATTERN = (08)¶1¶B || (8)¶0¶B. /* 1111111100000000 */ 33 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . /* MOHAN . PERI */ DCL PATTERN BIT(32).

/* MOHAN PERI */ 34 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . and whose type (that is. bit. or graphic) is the same as that of the two operands. or graphic  The result of a concatenation operation is a string whose length is equal to the sum of the lengths of the two operands. FULL_NAME1 = FIRST_NAME || LAST_NAME. bit. LAST_NAME = µPERI¶.IBM Global Services CONCATENATION  Concatenation operation is specified by combining operands with the concatenation infix operator: ||  Concatenation can be performed only upon strings--either character. character.  It means ³Join Together´  Examples: FIRST_NAME = µMOHAN¶.

IBM Global Services

BUILT IN FUNCTIONS 
They are the subprograms supplied as a part of PL/I.  Have the attribute BUILTIN.  Produces a new value for each value or set of values it recieves.  Always produces a single value regardless of input values or arguments.  Arithmetic Functions:
- ABS: Finds the absolute value of a given quantity. ‡ e.g. X = -3.714; Y = ABS(X); X = +7.47; Y = ABS(X); ‡ e.g. - FLOOR ‡ e.g. X = 3.32; Y = CEIL(X); X = -3.32; /* Y = 4.00 */ Finds the largest integer that does not exceed the argument. /* Y = 7.47 */ - CEIL:Finds the smallest integer greater than or equal to argument. /* Y = 3.714 */

35

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

BUILT IN FUNCTIONS
Y = CEIL(X); Y = FLOOR(X); - MIN: - MAX: ‡ e.g. /* Y = -3.00 */ /* Y = -4.00 */

Finds the smallest value from 2 or more arguments. Finds the largest value for 2 or more arguments. X = 100; Y = 32.76 ; Z = -6; W = MIN(X,Y,Z); W = MAX(X,Y,Z); /* W = -6 */ /* W = 100 */

- TRUNC: ‡ e.g.

Changes the fractional part of an argument to zero. DCL (X,Y) DECIMAL FIXED(3,2); X = 3.32; Y = TRUNC(X); X = - 3.32; Y = TRUNC(X); /* Y = -3.00 */ /* Y = 3.00 */

36

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

BUILT IN FUNCTIONS
- SIGN: Determines the sign of a value and returns a FIXED BINARY(15), 1 for positive argument, 0 for zero argument, and -1 for negative argument. ‡ e.g. X = 123; I = SIGN(X) ; X = -175; I = SIGN(X); X = 0; I = SIGN(X); /* I = 1 */ /* I = -1 */ /* I = 0 */

It rounds a given value at a specified digit and pads spare digit - ROUND: positions with zeros. ‡ e.g. - MOD: DCL X FIXED DEC(5,4) INIT(6.6666); Y = ROUND(X,2); /* Y = 6.67 */ It returns the smallest non negative value, R, such that:

(X - R)/Y = N, where N is an integer value.i.e R is the smallest nonnegative value that must be subtracted from x to make it divisible by Y. ‡ e.g. MOD(10,8) = 2;

37

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

«. . . 38 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . . expression or array name.IBM Global Services BUILT in FUNCTIONS .MATHEMATICAL FUNTIONS: ‡ These functions operate on arguments in floating point scale. error message with proper identification code will be printed along with program termination.ACOS9X).DATE & TIME . ‡ For invalid arg.ATAN(X). ‡ Arguments may be single value.

of x. The STRINGRANGE condition is raised if z is negative or if the values of y and z are such that the substring does not lie entirely within the current length of x. .SUBSTR(EDIT_DATE. specified by y and z. . . the substring returned is position y in x to the end of x. If z is omitted.e. .g.String handling Functions: ‡ SUBSTR: Returns a substring .13. . If z is zero.g.IBM Global Services BUILT IN FUNCTIONS .0) value specifying the starting position of the substring in x.y Expression that can be converted to a FIXED BINARY (15. YEAR = SUBSTR(DATE. . a null string is returned.z Expression that can be converted to a value specifying the length of the substring in x.1.2).x String-expression from which the substring is to be extracted. /* CHANGES year to 88 */ 39 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .DCL EDIT_DATE CHAR(14) INIT(µDATE: 10/03/97¶).2) = µ88¶.Substr can be used as pseudovariable e.

/* LTH = 12 */ . .DCL NAME CHAR(30) VARYING INIT(µMOHAN PERI¶). . e.15).DCL A FIXED DEC(5) INIT(175). .Note: If the arg has a decimal base. .LTH = LENGTH (NAME). /* C = µ 175¶ */ /* C = µ16500¶ */ Converts a given value to a character string.C = CHAR(A).IBM Global Services BUILT IN FUNCTIONS ‡ BIT: Converts a coded arithmetic data item or char string to BIT string argument. . . ‡ LENGTH: Finds the length of a given BIT or CHAR string and returns a result with attribute FIXED BINARY (15).e. . Argument can be a single value an expression or an array.NO_BITS = BIT(NUM).NO_BITS = BIT(NUM. 40 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .DCL B FIXED BIN (15) INIT(16500).g. /* NO_BITS = bit-string of length 32 */ /* NO_BITS = bit string of length 15 */ . . DCL NUM FIXED BIN(31).e.DCL C CHAR(5). it is converted to a char string before the function is invoked and to a bit string if arg has a BINARY base. .C = CHAR(B).g. ‡ CHAR: .g.

SENTENCE = µVALUE JAM¶. If the configuration is found. START = INDEX(SENTENCE. both are conveted to char string. If neither or one argument is a bit string. No conversion is performed.START.3) = µPBC¶. Result has the attribute BIN FIXED(15). character string. SENTENCE = µWIN TEAM EXECUTE PCB.g. decimal picture. binary coded arithmetic.P).DCL SENTENCE CHAR(40). The arguments may be bit string.IBM Global Services BUILT IN FUNCTIONS ‡ INDEX: Searches a string for a specified bit or character configuration. or array names. START = INDEX(SENTENCE. /* START = 3 */ /* START = 0 */ /* pbc spelling is now corrected /* 41 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . If both arg are bit strings. Binary coded arithmetic arg are converted to bit string. SUBSTR(SENTENCE. Decimal args are converted to char string before the above conversion.¶L¶). .¶PCB¶). e. START = INDEX(SENTENCE. the starting location of the leftmost configuration within the string is returned .

REPEAT ( M . N ) May be a Decimal integer constant or variable greater than zero representing the number of times the first argument is to be concatenated to itself Represents a character or bit string from which the new string will be formed.IBM Global Services BUILT IN FUNCTIONS ‡ REPEAT: It takes a given string value and forms a new string consisting of the string value concatenated with itself a specified number of times: e.g. Concatenate the first argument with itself n number of times 42 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

3).g.IBM Global Services BUILT IN FUNCTIONS e.2). SPIDER_BIT = REPEAT(ITSY_BIT. CITY = REPEAT(µAGRA¶. DCL ITSY_BIT BIT(3) INIT(µ101¶B). CITY = (2) µDELHI¶. /* SPIDER BIT = µ101101101¶b */ /* CITY = µDELHI DELHI¶ */ /* CITY = µAGRA AGRA¶ */ 43 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL CITY CHAR(12). DCL SPIDER_BIT BIT(15).

X = MARTYS Y = DEOLGNQZ Z = TYARMSBE If we execute TRANSLATE(X.Z) The for each character in X a search of Z is made. TRANSLATE(X.Z) . e.g.Y. If a match is found the corresponding positional character in Y is returned.X is the Source string .g.IBM Global Services BUILT IN FUNCTIONS ‡ TRANSLATE: It substitutes one character with another or one bit with another bit.Z is the position string e.Y.Y is the replacement string . In the above example result is GOLDEN M D T A E Y R O A T L R Y G M S N S Q B Z E 44 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

Z) will return zero. If all the characters or bits in X do appear in Y. a value of zero is returned. a value of zero is returned. N = VERIFY(Y. If X is the null string.0) value indicating the position in X of the leftmost character or bit that is not in Y. VERIFY (X.IBM Global Services BUILT IN FUNCTIONS ‡ VERIFY: It lets you examine a target string so that you can be assured that all the characters in that string belong to a certain set of characters in another string. If X is not the null string and Y is the null string. X Y Z = = = A A B B C L C H E E E A S C H 45 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . a value of one is returned.Z) will return 5.Y) Returns a FIXED DECIMAL (15. N = VERIFY(X.

. DECIMAL is converted to BINARY. Any decimal point. . .BIT to CHAR: Bit 1 becomes CHAR 1 and BIT 0 becomes CHAR 0. . then BIT is converted to CHAR.Arithmetic to BIT: The absolute arithmetic value is converted to a binary integer with the length of the target bit-string.If the CHAR & BIT are specified. The binary integer without the sign is then treated as a BIT string.BIT to Arithmetic: Bit string is interpreted as unsigned binary integer. ) is converted to char string. the length of which depends on the precision of the arithmetic data.IBM Global Services BUILT IN FUNCTIONS  DATA CONVERSION .If the scale differs then FIXED is converted to FLOAT.CHAR to Arithmetic: The CHAR string must contain only valid numeric characters i. digits.  Conversion Rules: . . negative sign or decimal fraction in the source appears in the char string. . 46 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . optionally a decimal point and a sign. .Arithmetic to CHAR: Value of the internal coded arithmetic data item (FIXED.CHAR to BIT: Char string should contain the Characters 0 and 1 only.If the base differs.e. BINARY ETC. FLOAT.

IBM Global Services Subroutines and Functions © Copyright IBM Corporation 2004 .

MAIN Procedure . .Improves program reliability.Facilitates program maintenance 48 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services SUBROUTINES and PROCEDURES  Used to increase MODULARITY.  One of them must be designated as MAIN procedure.  The advantages are: .Reduces total programming time .FUNCTION procedure.  There are 3 types of PL/I procedures: .SUBROUTINE procedure .  An EXTERNAL procedure is a separate compilation.Saves Coding effort .

It is invoked by a CALL. 49 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .A STOP or EXIT statement abnormally terminates execution of that subroutine and the program associated with it.  ARGUMENTS and PARAMETERS.It is the value passed to the invoked procedure.IBM Global Services PROCEDURES  SUBROUTINE PROCEDURES . . .IINITIAL Attribute cannot be used on parameters.The attributes of the parameter and its argument must be same. . .For arguments that are bit or character string the corresponding parameters can be expressed as asterisks.

2).Y. « « END SUBPR.IBM Global Services PROCEDURES MAINPR : PROC OPTIONS (MAIN). DCL (X. SUBPR : PROC(A.B. DCL C FIXED DEC(8. «. DCL (A. END MAINPR. 50 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .2). DCL Z FIXED DEC(8.Z). CALL SUBPR(X.B) CHAR(10).C).Y) CHAR(10). «.

IBM Global Services PROCEDURES . ‡ BUILIN functions without arguments are passed as names unless the function itself is enclosed in parenthesis.DUMMY Arguments.5.g. CALL SUBRT(A.CALL SUBRT(A.(DATE).Z).Y are replaced with compiler generated DUMMY names. .g.SQRT(X).C) will pass the function name DATE. These arguments are not accessible to the programmer. 51 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .e. .X-Y. .CALL SUBRT(A.C).BUILTIN functions can be specified as arguments.DATE. ‡ If the argument has no names e. CALL SUBRT(7.e. DCL DATE BUILTIN. In this the values 7. .g. ‡ Name of an argument not its value is passed to a subroutine or function. . when constants are passed. ‡ BUILIN functions with arguments are invoked before subroutine is called .g. compiler inserts a DUMMY name (also called Internal argument) in its place before processing.5 and X .e.C) will pass the value of the date.

B.2).B) DCL C C = A + B. ‡ It allows you to direct the compiler to generate coding to convert one or more arguments to conform to the attribute pf the corresponding parameters. FIXED DEC(8.FIXED(7. Explicit of SUBRT as ENTRY solves this Problem: DCL SUBRT ENTRY (FIXED(7. e.FIXED(8.2).Y) DCL Z FLOAT DEC(6).2). DCL (X. FIXED DEC(7. GET LIST(X. SUBRT: PROC(A.g. This will cause error because X and Y do not have the same attributes as their corresponding parameters. 52 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .2). FLOAT DEC(8.Y.C). The main proc is like this: MAINPR: PROC OPTIONS(MAIN). END SUBRT.Y).2)). CALL SUBRT(X.IBM Global Services PROCEDURES .ENTRY attribute. DCL (A.2).Z). END MAINPR.

g. Z= CALC(A.Attributes of returned value may be declared in 2 ways: ‡ They may be declared by default according to the first letter of the function e.RETURN statement is used to terminate a function. ‡ Using RETURNS keyword e. .B). in the following stmt CALC is DECIMAL FLOAT(6) because it starts with C.Invoked by a typing the name and parameters it requires e. like PUT LIST or IF.It could appear in other PL/I statements..g. CALC: PROC(A. . . RETURN A+B+C.g. .IBM Global Services PROCEDURES  Function Procedures: .B. .C) RETURNS(FIXED DECIMAL(7)). 53 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . ‡ The invoking procedure must also specify that CALC is returning a FIXED DEC value of the same precision.Attributes of the value returned should be same as those expected by the invoking procedure. e. END CALC.It returns a single value to the invoking procedure.g.

. it is called a recursive procedure.  RECURSIVE PROCEDURES: . RESULT = FACTORIAL_N(I).X n . SUM = CALC(A.IBM Global Services PROCEDURES MAINPR : PROC OPTIONS (MAIN).B. END MAINPR.When a procedure invokes itself.. « 54 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL SUM FIXED DEC (7). GET LIST(A. e.C). Consider the computation of factorial.Method 1: I = 4.B. n! = 1 X 2 X 3 X 4 X «.g.C).. DCL CALC ENTRY RETURNS(FIXED DEC(7)).

IBM Global Services

PROCEDURES
- FACTORIAL_N : PROC(N); K=I; DO I = 1 TO N; K = K * I; END; RETURN(K); END FACTORIAL_N; - Method 2: FACTORIAL_N: PROC(N) RECURSIVE; K = N ± 1; IF K = 1 THEN I = N; ELSE I = N* FACTORIAL_N(K); RETURN(I); END FACTORIAL_N;

55

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

PROCEDURES
E.G. I = 4; Then Cycle 1 Cycle 2 Cycle 3 K 3 2 1 N 4
K= 3

Return 4*K! 3*K! 2 =24 =6

3 2

K=2

56

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

PROCEDURES 
Scope of Identifiers:
- One way looking glass: Inner glass can see out, but outer glass cannot see in. e.g P1 : PROC (MAIN); DCL DATE FIXED DEC(3); DCL TODAY CHAR(6); DATE = 302; CALL P2; P2 : PROC; DCL DATE BUILTIN; TODAY = DATE; END P2; END P1;

57

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

P1: PROC. 58 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .g.IBM Global Services PROCEDURES  Scope of EXPLICIT DECLARATION: The scope of an explicit declaration of a name is that block to which the declaration is internal. DCL B FIXED DEC (6). e. This includes all nested blocks except those blocks to which another explicit declaration of the same identifier is internal. END P2. DCL C FIXED BIN(15). DCL D = FIXED BIN(15). DCL B CHAR(8). P2 : PROC. DCL C CHAR(8). X = C * D. DCL A FIXED DEC(6). END P1. P3 : PROC. « END P3.

IBM Global Services Logical Testing © Copyright IBM Corporation 2004 .

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. . e. END.IBM Global Services THE IF STATEMENT  It is used when a test or decision is to be made between alternatives.g. Y = 2. DO. . X = 1.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.SIMPLE IF: A single statement will appear as the action to be taken if the condition tested is TRUE. If th condition tested is false. . ‡ IF cond THEN stmt1. ‡ IF cond THEN stmt. 60 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . ELSE stmt2. the THEN keyword is ignored and the program continues immedietly wit the next sequential statement.

. ELSE X = 3. IF A = B THEN IF A = C THEN X = 1. It gives no direction to the computer. ELSE X = 2. ELSE X = 3.Nested IF statement: IF A = B THEN IF A = C THEN X = 1. ELSE.NULL ELSE: It is a non-operative statement.IBM Global Services THE IF STATEMENT . 61 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

Program switches can be tested by using the indicator name e. IF MORE_RECORDS THEN « ELSE « 62 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services THE IF STATEMENT ‡ PROGRAM SWITCHES in the IF STMT.g. .

WHEN(expression2) ACTION2. . END.Following keyword SELECT an expression or even nothing may be specified. permissible nesting of SELECT is 49. . but there is not limit to the number of WHEN clause in a SELECT.Max.  It takes the general form: SELECT (optional expression here). WHEN(expression3) ACTION3. OTHERWISE ACTION4.Program action after WHEN can be a DO group or another SELECT group. 63 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services The SELECT STATEMENT. WHEN(expression1) ACTION1. .

64 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .¬ .| NOT AND OR ‡ They are used in the IF statements.& . . ‡ They are used to manipulate BIT strings. ‡ They are used occasionally in the assignment statements.IBM Global Services LOGICAL OPERATORS.IF A = B & C = D THEN X = 1.  Three logical operators are provided in PL/I .

raise the ERROR condition and the terminate the PL/I program and return control to the OS.COUNT) END_OF_FILE = µYES¶. for most conditions the standard system action is to print a message.  In the absence of a program specifying an action. e. 65 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . PUT SKIP(3) LIST(TOTAL). END.g. ON ENDFILE(SYSIN) BEGIN. PUT PAGE LIST(µNO OF RECORDS PROCESSED¶.  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.IBM Global Services CONDITIONS AND ON UNITS  A CONDITION is the occurrence within a PL/I program that causes a program interrupt.

. When it is raised standard system action is to skip to a new page and continue execution with the PUT statement. 66 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . After ENDFILE is raised no further GETs or READs should be executed for that file. which caused the ENDPAGE condition to occur. .IBM Global Services CONDITIONS AND ON UNITS  TYPES OF CONDITIONS: .The ENDPAGE condition: ‡ This condition is raised when a PUT statement results in an attempt to start a new line beyond the limit specified by PAGESIZE. It is caused by an attempt to read past the last record for the file named in the GET or READ statement.The ENDFILE condition: ‡ This condition is raised during a GET or READ operation.ENDPAGE is raised only once per page.

TODAY = DATE. 67 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . MORE_DATA = YES. PAGE_NUMBER = PAGE_NUMBER + 1.2) || µ/¶ || SUBSTR(TODAY.2). CALL PROCESS_DATA. END.1. ON ENDPAGE(PRINTR) BEGIN. µPAGE¶||PAGE_NUMBER ). GET LIST(DATA). SIGNAL ENDPAGE(PRINTR).2) || µ/¶ || SUBSTR(TODAY. PUT PAGE LIST(µ¶. DO WHILE (MORE_DATA).IBM Global Services CONDITIONS AND ON UNITS ON ENDFILE(SYSIN) MORE_DATA = µNO¶.5. GET LIST(DATA). CALL PRINT_DATA. µWeekly status report¶. SUBSTR(TODAY. PAGE_NUMBER = 1.3. END. OPEN FILE(PRINTR) PAGESIZE(45).

. 68 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .A = 40000000.The CONVERSION condition: ‡ Occurs whenever a conversion is attempted on character data containing characters that are invalid for the conversion being performed.B = 80000000.C=A*B. N is 15 for decimal fixed point values and 31 for binary fixed point values.X = ¶10A1¶. .DCL (A . B. e.IBM Global Services CONDITIONS AND ON UNITS .DCL X BIT(4). .The FIXEDOVERFLOW condition: ‡ It occurs when the precision of the result of a fixed point arithmetic operation exceeds N digits. . . C) FIXED DEC (15).g . For most PL/I implementations.

e.A = 23E-71. A = 55E71. C = A/B. . . For most cases value may not be less than 10-78 or 2-260 .IBM Global Services CONDITIONS AND ON UNITS . B = 3E-9.B = 23E11. /* RESULTING EXPONENT IS LARGER HAN 10**75 . /* ZERO DIVIDE CONDITION */ C =A*B.A = 15. .g.C = A * B. /* Resulting exponent is smaller than 10**-78 */ 69 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . . B = 0.The UNDERFLOW condition: ‡ It occurs when the magnitude of a floating point number is smaller than the permitted minimum.The ZERODIVIDE condition: ‡ It occurs when an attempt is made to divide by zero.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 . .

IBM Global Services

CONDITIONS AND ON UNITS
- 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;

70

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

CONDITIONS AND ON UNITS
DCL V3 FIXED BIN(5); DCL V4 FIXED BIN(15) INIT(3000); V3 = V4; /* SIZE CONDITION */ V3 requires 2 bytes of storage, but the program contains instructions to ensure that all binary digit of positions beyond five in the preceding example will be zero.  Status of conditions:
- Some conditions are always enabled unless explicitly disabled others are disabled unless explicitly enabled. - When a condition is enabled: ‡ Programmer defined action takes place ‡ System defined action takes place. - The following conditions are always enabled: CONVERSION, FIXEDOVERFLOW, OVERFLOW, UNDERFLOW, ZERODIVIDE. - The SIZE condition is disabled unless enabled by the programmer.
71

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

CONDITIONS AND ON UNITS 
Conditions are enabled or disabled by a condition prefix. e.g.
(NOFIXEDOVERFLOW):CALC:SUM = A + B + C; - Fixedoverflow condition is disabled. - CALC is the label name. - If it is desired to enable or disable condition execution in the entire program then specify the CONDITION prefix in the procedure statement. e.g. (SIZE,NOFIXEDOVERFLOW):PROG1 : PROC OPTIONS(MAIN); 

Changing the ACTION taken.
- It is possible to specify more than one ON statements for the same condition in a program. ON ENDFILE(SYSIN) .. .. ON ENDFILE(SYSIN) CALL NORMAL_END_OF_JOB;
72

CALL ERROR_RT;

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

73 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . simply specify another ON statement with the keyword SYSTEM. Since this is at the expense of considerable programming overhead.  Simulating conditions .g. it should be used only for debugging. .If after having supplied your own ON-unit for a condition. you wish to return to the standard system action for that on unit.Execution of the signal statement has the same affect as if the condition has actually occurred.PUT DATA: It causes all the variables known to the program at the point of the PUT statement to be outputed in the form of assignment statements.The programmer can simulate the occurrence of a condition through the use of the SIGNAL statement.IBM Global Services CONDITIONS AND ON UNITS . e. .  Some useful Debugging tools: .If the signaled condition is not enabled the SIGNAL statement is treated as a NULL statement.

‡ This code defines the type of interrupt. ON ERROR SYSTEM . .IBM Global Services CONDITIONS AND ON UNITS ON ERROR BEGIN.ONLOC ‡ This ma be used in any on unit to determine the entry point of the procedure in which that condition was raised. 74 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .  Built in functions for ON Units: . ‡ See the manuals for the complete list. END. PUT DATA.ONCODE ‡ This function may be used in any on unit to determine the type of interrupt that caused the on-unit to become active.

This condition is raised whenever the lengths of the arguments to the SUBSTR builtin function reference a non-exitant part of the string data.ONCHAR and ONSOURCE ‡ They can used as pseudovariables and builtin functions. DCL LAST CHAR(16).20). CHAR = ONCHAR. ‡ As builtin functions. DCL NAME char(20).5.IBM Global Services CONDITIONS AND ON UNITS . ‡ When used out of context they return a blank or null string e. SOURCE = ONSOURCE.  The STRINGRANGE condition: . Value returned is a char string of length 1 containing the culprit char.g. LAST = SUBSTR(NAME. /* STRINGRANGE ERROR */ 75 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . they return the character and source fields respectively containing the character that caused the conversion condition to be raised. Value returned is a varying length character string giving the contents of the field being processed when conversion was raised.

/* STRINGSIZE ERROR */ 76 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . e. DCL SEND CHAR(12). .g. DCL RECEIVE CHAR(5). RECEIVE = SEND.IBM Global Services CONDITIONS AND ON UNITS  The STRINGSIZE condition: .This condition is raised when a string is about to be assigned to a shorter string.Standard system action is to print a message and continue execution from the point of interrupt.

IBM Global Services DO statements and ARRAYS © Copyright IBM Corporation 2004 .

Thus the contained statement will be executed at least once.The test for loop execution is done after the statements within the range of the DO. . ON ENDFILE(SYSIN) EOF = YES. GET FILE(SYSIN) LIST(DATA). END.. 78 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . IF EOF THEN CALL NO_RECORDS_IN_FILE.It is terminated when the condition tested is true( DO-WHILE is terminated when the condition tested is false. .) DO UNTIL (EXPRESSION) .IBM Global Services DO UNTIL STRUCTURE  Essentially the same capability as the DO-WHILE except for the following: . ELSE DO UNTIL(EOF) CALL PROCESS_DATA. END.. GET FILE(SYSIN) LIST(DATA).

. . .I is the control variable. (greater program efficiency is reached is this is FIXED BIN) .IBM Global Services ITERATIVE DO  J = 10.K is the modification value.The above statement performs the following steps: ‡ Initialize the control variable. ‡ Modify the control variable. ‡ Return to step2.1 is the initial value . ‡ Test control variable.J is the limit value. 79 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . K = 2 DO I = 1 TO J BY K . ‡ Execute statements following the DO.

8.025.13.6. (Is valid but termination should be done by other coding) DO J = 1.5 TO 10 BY 0. DO K = 1 TO 10 WHILE(X>100). DO B = 1.50 TO 55. DO K = 1 TO 5. 40 TO 44. DO I = K*2 TO K*5 BY J-4.IBM Global Services ITERATIVE DO Examples: DO K = 5 TO -5 BY -1. 8 TO 18 BY 2.11. DO I = 1 BY 1. DO I = 1 TO 100.9. 80 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

DO I = 1 TO 50. IF A < 0 THEN I = 50. Leaving the DO group: Set the index variable to the maximum value e. END. DO J = 1 TO 100. 81 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . Note: It is possible to transfer out of a DO Group before the maximum number of iterations has been performed. GET LIST(A. However it is not permitted to transfer to a statement in an iterative DO GROUP. « « END. ELSE CALL PROCESS_DATA. END.DATA).IBM Global Services NESTED DO GROUP DO I = 1 TO 99.g.

1). . ‡ FIXED is the scale attribute for all the elements in the array.In the above example 365 is the UPPER BOUND of the array . ‡ (4.The LOWER BOUND is 1. DCL DAYS(365) FIXED DEC(4. e. ‡ In the above example the extent is 12. ‡ DAYS is the name of the array ‡ DECIMAL is the base attribute for all elements in the array.1) is the precision attribute for all the elements in the array. ‡ Array has 365 elements.g.g.1). 82 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . (bound)  BOUNDS .IBM Global Services ARRAYS  An ARRAY is a table of data items in which each item has the same attribute as every other item in the array. It has storage reserved for it by the declare statement.We can specify both the upper and the lower bounds e. ‡ DCL TABLE(0:11) FIXED DEC(4.

( Generally the max # of dimensions is 15) 83 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .50.  DIMENSIONS: The number of sets of upper and lower bounds specifies the dimensions in an array.g. ‡ Bounds that are variables or expressions are determined when the storage is allocated for the array.2) FIXED DEC(5).10) FLOAT DEC(6). or asterisks. variables.Bounds may be constants. expressions.DCL AXIS(-3:3. e.-4:4) FLOAT DEC(6) INIT(63(0)).IBM Global Services ARRAYS . . .DCL POPULATION(2. .DCL TABLE(6. ‡ An asterisk means the bounds are defined later either in an ALLOCATE statement or via an argument to a subroutine or function procedure.

0) INIT(3.Subscripts may be constants .50).Subscript expressions may include subscripted items. AMOUNT = PRICE * QTY * COMMISSION(3.1). I = 3.2. variables.30. or expressions.1). T = TEMP(J-I+K).40.An element of an array is referred by means of a subscript. DCL Y(3) FIXED BIN(15.0) INIT(10. Range of subscripts is determined by the bounds of the array.IBM Global Services ARRAYS  SUBSCRIPTS: . Z = X(Y(I)).g. . DCL X(5) FIXED BIN(15. e. .20. 84 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

LBOUND: ‡ It finds the current lower boundary for a specified dimension of a given array. DCL GRADE(5) FIXED DEC(3) INIT(10.SUM: ‡ It finds the sum of all elements in an array. AVERAGE = SUM(GRADE)/5.30. . .20. /* AVERAGE = 30 */ © Copyright IBM Corporation 2004 85 Presentation Title | Confidential | 30-Nov-10 . I = HBOUND(ARRAY_NAME. I = LBOUND(ARRAY_NAME.HBOUND: ‡ It finds the current UPPER bound for a specified dimension of a given array. DCL AVERAGE FIXED DEC(3).N). .IBM Global Services ARRAYS  ARRAY MANIPULATION BUILTIN FUNCTIONS: .N).DIM: ‡ It provides the current extent for a specified dimension in a given array I = DIM(ARRAY_NAME.N).50).40.

If any bit in the same position of the elements of the array is µ1¶B . PRODUCT = PROD(ALIST).40.'1111').2. /* ANSWER = 1290 */ Result would be (10X0 + 20X1 + 30X2 + 40X3 + 50X4) .'0111'. DCL ALIST(5) FLOAT DEC(6) INIT(1.3.X)). /* bit2 = µ1111¶B */ 86 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL X FIXED DEC(6) INIT(2).5). DCL GRADE(5) FIXED DEC(3) INIT(10.4.50). DCL ANSWER FIXED DEC(6) INIT(POLY(GRADE.PROD: ‡ Finds the product of all the elements of the array.'0011'.20.IBM Global Services ARRAYS .20000E+02 */ .ANY: ‡ Used to test the bits of a given bit-string array. ‡ DCL BIT1(4) BIT(4) INIT('0001'.30. /* PRODUCT = 1. then the result is µ1¶B otherwise the result is µ0¶B.POLY: ‡ Forms a polynomial expansion in float point format. ‡ DCL bit2 BIT(4) INIT(ANY(BIT1)).

DCL BIT3 BIT(4) INIT(ALL(BIT1)).'0011'.ALL: ‡ Used to test all bits of a given bit string array.'0111'. /* BIT3 = µ0001¶B */ 87 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL BIT1(4) BIT(4) INIT('0001'.IBM Global Services ARRAYS . If all bits in the same position within each element of an array are µ1¶B then result is µ1¶B otherwise the result is µ0¶B.'1111').

DATA_SUM).IBM Global Services ARRAYS  VARIABLE ARRAY BOUNDS HELLO3 : PROC OPTIONS(MAIN). END.SUM). DCL LOW FIXED BIN(15). HIGH = HBOUND(ARRAY. DCL SAMPLE_ARRAY(500) FIXED BIN(31) INIT((500)7). DCL DATA_SUM FIXED BIN(31) INIT(0). LOW = LBOUND(ARRAY. DCL SUM FIXED BIN(31). END ODDSUM. 88 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . IF MOD(LOW.1). DO INDEX = LOW TO HIGH BY 2. DCL ARRAY(*) FIXED BIN(31). SUM = SUM + ARRAY(INDEX).LBOUND. END HELLO3.1). DCL (HBOUND. PUT SKIP LIST('SUM IS'.2) = 0 THEN LOW = LOW + 1. CALL ODDSUM(SAMPLE_ARRAY. ODDSUM : PROC(ARRAY. SUM = 0.DATA_SUM).MOD) BUILTIN. DCL INDEX FIXED BIN(15). DCL HIGH FIXED BIN(15).

END.J) DO I = 1 TO 5) DO J = 3 TO 7)). is equivalent to DO J = 3 TO 7.If a multi dimensional array is specified then the right-hand subscript varies most rapidly.IBM Global Services ARRAYS  I/O Operations & ARRAYS . 89 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .J)). data items are read into arrays starting with the lowest numbered subscripted element and finishing with the highest subscripted element. DO I = 1 TO 5. END. GET LIST (((A(I. .In the absence of explicit element specifications. GET LIST(A(I.  Repetitive Specification of DATA item.

.2. will result in ‡ A(1. ‡ DCL A(2. If two appear. an iteration specification.2) = 2.2) = 4.IBM Global Services ARRAYS  INITIAL ATTRIBUTE: .1.If only one parenthesized decimal integer constant precedes a string initial value. A(2. ‡ ((iteration factor)item. remainder of the array is not initialized.1) = 3.If too many INITIAL values are specified then the excess values are ignored.) /* DCL A(25) FIXED DEC(6) INIT((25)0) */ /* DCL B(10) FIXED DEC(6) INIT((7)0. . the first is taken as the initialization iteration factor and the second a string repetition factor. A(1.2) FIXED DEC (6) INIT(1. ‡ ((Iteration factor)constant).Initial values specified for an array are assigned to successive elements of the array in he order where right hand subscript varies most rapidly. where as if not enough values are specified . ‡ DCL TABLE(1) CHAR(10) INIT((2)¶A¶). A(2. ‡ DCL TABLE(2) CHAR(10) INIT((2)(2)¶A¶).2. It has one of the following general forms.item«. it is interpreted as a repetition factor for the string.3.4).Each item in the INITIAL value may be a constant.3) */ . or a repetition factor.1) = 1. 90 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

g. 91 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .1). MONTHS = 0.One array can be moved to another array (provided the arrays have identical dimensions and bounds) DCL A(5. DCL B(5.An entire array is assigned to a single (scalar) value.IBM Global Services ARRAYS  ARRAY ASSIGNMENT: .5) FLOAT DEC(6). A = B. DCL MONTHS(12) FIXED DEC(4. ‡ Array to array.5) FLOAT DEC(6).e.Two types of move types may be specified for arrays: ‡ Scalar to scalar .

B = A * 5. e. .Infix operators.g.g. A = -A. . ‡ Result is an array of identical bounds in which each element is the result of the infix operation having been performed. e.IBM Global Services ARRAYS  ARRAY EXPRESSIONS: .PREFIX Operators: ‡ Result is an array of identical bounds in in which each element is the result of the operation performed.It is an expression whose evaluation yields an array result. 1 4 6 3 -2 12 A -5 -7 -13 -1 -4 -6 -3 2 -12 -A 5 7 -13 5 20 10 10 25 20 A 15 30 30 25 100 50 50 125 100 B 75 150 150 92 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

IBM Global Services ARRAYS  CROSS SECTION of ARRAYS .6. e. TOTALS will have the values 20.An array subscript may also be an asterisk.1.3. in which case it specifies the entire extent of the dimension.4.4) FIXED DEC(3.2. 24 and 28 respectively.1) INIT(1.2.4)*PRICE.g. 93 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .4.4). DCL PRICE(3) DCL TOTALS (3) FIXED DEC(3. FIXED DEC(3.2.1.1) INIT(5.3. DCL PERCENT (3.1).3. TOTALS = PERCENT(*. This extent across the cross section of an array.7).

AGGREGATE compiler option. . This table will specify the amount of storage required (length) for all arrays.SUBSCRIPTRANGE condition. .IBM Global Services ARRAYS  DEBUGING TIPS. DCL ARRAY(10) FLOAT DEC(6). ‡ It specifies that the compiler to include the aggregate length table. ‡ It can raised whenever there is a reference to an element outside the boundaries of an array. /* IF K is > 10 condition is raised */ 94 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . ARAY(K) = J. GET LIST(K).

IBM Global Services File Declarations and STREAM I/O © Copyright IBM Corporation 2004 .

(STREAM or RECORD) ‡ Direction of transmission. DCL BILLING INPUT STREAM ENV(F BLKSIZE(150)). (INPUT.IBM Global Services FILES  DECLARATION ..File name can be from 1 to 7 characters long. 96 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .File attributes include ‡ Type of transmission. .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.  FILE attribute . e. OUTPUT or UPDATE) ‡ Physical environment of the file.(Record size.g.) DCL INVEN FILE INPUT STREAM ENV (options). blksize etc.

‡ LIST Directed GET LIST.IBM Global Services FILES  INPUT/OUTPUT attribute . If neither is not specified STREAM is assumed. 97 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .  STREAM Attribute . PUT DATA . There are three forms of stream.It specifies that data items are accessed by GET or PUT statements that they are continuous stream. . PUT LIST ‡ EDIT Directed GET EDIT.Opposite of stream is record.INPUT is the default attribute unless the file has the PRINT attribute.One of these attributes must be specified either in the declare statement or in the open statement. PUT EDIT ‡ DATA directed GET DATA.

It can be omitted if equivalent information is given in the JCL. .IBM Global Services FILES  ENVIRONMENT Attribute. .Applies only to files with STREAM and OUTPUT attributes.It causes the initial byte of each record of the associated data set to be reserved for printer control character (which does not appear in the printout) through the use of PAGE. SKIP. 98 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .The options applicable to STREAM files are ‡ Record form ‡ Record size. ENV(F BLKSIZE(80)) Specifies Record type is fixed Each record is 80 byte long  PRINT Attribute .Added for stream files associated with a printer. LINE. .

99 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL AREA CHAR(132). In the above example if the area size is 130.IBM Global Services FILES DCL PRINTR FILE OUTPUT STREAM PRINT ENV(F BLKSIZE(133)). PUT FILE (PRINTR) PAGE LIST(AREA). ‡ If the PRINT attribute is removed form the declare. ‡ Quote marks are supplied by list directed output routines around character strings output to non-PRINT files. we can have a blocksize of 132 instead of 133. I = LINENO(PRINTR).g. the record length will still be 132. ‡ Builtin function LINENO finds the current line number for a file having the PRINT attribute and returns that number to the point of invocation. e.

.IBM Global Services FILES  DEFAULT or PREDEFINED FILES .SYSIN is the default standard input file.B) is equal to GET FILE(SYSIN) LIST(A.B) is equal to PUT FILE(SYSPRINT) LIST(A.B) ‡ PUT LIST(A. ‡ GET LIST(A.SYSIN and SYSPRINT file names and their attributes need not be declared for IBM implementations.SYSPRINT is the default standard output file. The default attributes are: ‡ SYSIN FILE STREAM INPUT ENV(F BLKSIZE(80)) ‡ SYSPRINT FILE STREAM OUTPUT PRINT ENV(V BLKSIZE(129)) 100 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .B) .

OPEN FILE(KEYBD).FILE(PRINTR). . 101 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .Stream files are automatically opened when the first GET or PUT is issued.It is specified to include additional file attributes or options. OPEN FILE (PRINTR) PAGESIZE(50). Note: If LINESIZE is used we need not specify the BLKSIZE in the declare stmt. At OPEN time attributes from these three sources are combined to form the description of the file which the program is going to communicate. OPEN FILE(SYSPRINT) LINESIZE(133). Pagesize and Linesize cant be used in the declare statement. .Several files may be opened with one OPEN statement.Some attributes of the file may be specified in the JCL.Opening of the file is automatic. some (but not conflicting ones ) in the Declare and the remaining in the OPEN statement. .IBM Global Services FILES  OPEN STATEMENT . .

‡ If an I/O devise is not ready at open time. 102 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .Device readiness is checked. .IBM Global Services FILES OPEN FILE(DATAIN) TITLE(FILENAME).  When the files are opened: . error message is displayed at the operator¶s console.Attributes are merged. . ‡ FILENAME is the name of the file or devise associated with the logical file DATAIN. ‡ When communicating with disk or tape datasets dataset labels are also checked at OPEN time.Labels are checked.

103 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . e. the problem should be rectified and the job has to be run one more time. .CLOSE is optional. . /* READ RECORDS */ Note: If a job is terminated abnormally during a transaction then the end-of-file labels are not written to the disk. OPEN FILE(WORK) OUTPUT /* WRITE RECORDS */ CLOSE FILE(WORK).IBM Global Services FILES  CLOSE STATEMENT CLOSE FILE(PAYROLL). .In case of output files written to magnetic disk or tapes the end of file mark is written to the device to signal the physical end of the dataset.When files are closed FILENAME is disassociated from the dataset.g.If a files is open and its attributes are to be changed then the file must be closed first and opened again. OPEN FILE(WORK) INPUT. .

IBM Global Services FILES  Advantages of LIST directed I/O . and therefore more space is required to represent the input data.In PUT LIST. 104 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . data is presented at predefined tab positions . and so we cannot format it to provide a more meaningful and pleasing report. .In GET LIST the data needs to be separated by space or comma.It is easy to code and is a useful debugging tool  Disadvantages of LIST directed I/O .

(items describing page control.21 Only 36 positions are needed if edit directed input as compared to 47 positions for list directed input.1).IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  ADVANTAGES . line control.HOURS. GET EDIT (data list) (format list) PUT EDIT (data list) (format list) .) ‡ REMOTE format item (it indicates one or more format items are located remotely from the GET or PUT.DEDUCTIONS)(R(RFMT)). Example: If we have to supply the following stream input: µ435928¶ µDAVID P.RATE.2)).F(4. RFMT:FORMAT(COLUMN(1).Format items may be divided into 3 categories: ‡ DATA FORMAT ITEMS. 105 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .55 41.No punctuation marks are needed to indicate the type of input data.A(20). (e. e.A(6).NAME. GET EDIT(EMP#. character.F(5.g. Take this general format.3 103. space etc.g.F(3. fixed point or float point) ‡ CONTROL format items. EDIT I/O stmts.No Blanks are needed to separate the data items in the input stream . GOLDSMITH¶ 10.2).

I.B)(COLUMN(1).A(40)). 4.B)(A(70). 3. GET EDIT(A. e. 2. F(5) describes B.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  Rules for I/O. DCL B CHAR(40). there¶s a return to the beginning of the format list. GET EDIT(INPUT_DATA)(COLUMN(1).O continues until the data list is exhausted.g. Data list item need not have the same width specification as the corresponding DATA item.DCL A CHAR(70). and F(4) describes C.B. All data lists must have corresponding format items. If there are more format items than data items extra format items are ignored.A(40)).A(40). DO I = 1 TO 10.GET EDIT(A. If there are less format items than data items.B)(A(70). .A(70).A(40)). . PUT EDIT(INPUT_DATA)(COLUMN(1).F(5)).X(10). 1. GET EDIT(A.COLUMN(1). END. F(4) describes A. 5. . DCL NAME CHAR(15).A(40)) .C)(F(4).GET EDIT(A. GET EDIT (NAME)(A(20)). 106 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .DCL INPUT_DATA CHAR(40).

DCL TT(81.F(4. 107 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . GET EDIT (TABLE)(COLUMN(1).2)).8))(A(8)).F(6. GET EDIT(TT)(F(10)). DCL TABLE(100) FLOAT DEC(6).(X(I) DO I = 1 TO N))(COLUMN(1). 8. DATA list items may be names of data aggregates.2)). GET EDIT(((TT(I. GET EDIT(TABLE)(50F(3).2)).5.5.50F(4)). DCL NAME_FIELD CHAR(35). GET EDIT(N. Output data items may be built functions. Input DATA items may be pseudo-variables. GET EDIT(TABLE(K) DO K = 1 TO 50)(COLUMN(1).9) FLOAT DEC(6).IBM Global Services EDIT DIRECTED INPUT AND OUTPUT 6. 7. PUT EDIT(SUBSTR(NAME_FIELD.J) DO J = 1 TO 9) DO I = 1 TO 89))(F(10)).20))(A(20)). GET EDIT(SUBSTR(NAME_FIELD.F(6.

F)(B(10).A(7)) (G.A(22)). Output DATA items may be PL/I constants.COLUMN(60).C)(F(12).F(5.E.2)).3)F(5)) (D. 10. More than one data list and corresponding format list can be specified.F(8.B. PUT EDIT(A*3.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT 9.B+C/D)(F(10). Data items may consist of element expressions. PUT EDIT (A.H)(F(8). PUT EDIT(µWEEKLY REPORT¶)(COLUMN(40). 108 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .F(15. 11.2).A(22)).

OTHERWISE CALL ERROR_IN_INPUT. .It can be used to effect character to arithmetic and arithmetic to character string conversion.X(3). GET STRING(NAME) EDIT(FIRST.F(7.LAST)(A(15).Instead of getting data form an external device(a file) the data can also be read from a character string.Sometimes records of different formats appear in the same file where each record contains a code that identifies the particular format. 109 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .A(20)). SELECT(SUBSTR(INFO.AMT)(X(1). END.2).A(8)).1.X(1).1)).X(1).1).MIDDLE. PUT STRING (RECORD) EDIT(NAME.2).EMP#.2)).A(6).e. GET EDIT (INFO)(A(80).INVOICE#)(X(1). DCL RECORD CHAR(80).IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  STRING OPTION .A(7).HOURS*RATE)(A(20).AMT.X(1).DATE.2)). DCL EMP# CHAR(70). WHEN(µ1¶) GET STRING(INFO) EDIT(CUST#.A(6). WHEN(µ2¶) GET STRING(INFO) EDIT(CUST#.A(6).F(7.A(1). DCL RATE FIXED DEC(4.F(7. DCL NAME CHAR(20). DCL HOURS FIXED DEC(3.g.

.An E or F format may be specified which may be used for both real and imaginary part of the comlex number.B ‡ Allowed for output only. Normal truncation rules apply.B(w) ‡ On input a string of length w characters is read into a variable having BIT attribute. Normal truncation rules apply. . .IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  DATA FORMAT ITEMS . .real format2) . valid for char-string variables. ‡ C(real format1. Valid for BIT string variables.Fifferent E or F format may be specified for the real as well as imaginary parts.A ‡ Allowed for output only.C ‡ It can be either C(real format) . 110 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .A(w) ‡ On Input a string of length w characters is read into a variable.

e.17536E+08 respectively if the following format specifications are used.d) .d. E(12.s) . 175. s gives the number of significant digits.Contains w character containing fixed point data.2. E(11.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT ‡ E(w.d contians the number of decimal points e. The character w represents the total number of characters including decimal point.5). .3) is given to 123.5.W and d are same as above.45 it will result in 123.36E+05 will result into bb175.0.5). ‡ F(w. if F(7. bb.450 111 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . bb17536E+03.g.Input stream contains data in floating point format. ‡ F(w) .d) .5). ‡ E(w. signs and the designation E. E(12.36e+05.

‡ P . Character $+-S Z 9 V /.B Purpose static or drifting characters inserted where specified. digit characters or zero suppress(insert blanks) Digit character(0-9) decimal point alignment insertion character (B = insert blank) 112 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . The result is a character string whose form is determined by the picture specification as shown below..Picture specification is used to edit numeric data in fixed point decimal form. and on output w blanks are inserted.On input w characters are ignored.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT ‡ X(w) .

GET EDIT(HOURS) (A(3)). DCL HOURS FIXED DEC(3). /* provided HOURS contain only the digits 0 through 9 */ 113 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .g.Arithmetic data items have the format F (fixed point) or E (floating point). ‡ FIXED BINARY ‡ FIXED DECIMAL ‡ FLOAT BINARY ‡ FLOAT DECIMAL e. E or P format items.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  Conversion of external data to internal data format . Following data types may be input or output using the F.

‡ Specifies that the next data item is to be printed on the nth line.F(5).F(7.F(7.B)(F(5).2)) ‡ PUT EDIT(A. ‡ On output: positions the output stream to the nth byte of the record or the nth print position on the line printer.B)(F(5).PAGE.COLUMN: ‡ On input: positions the input stream to the nth byte or the position of the record.2)). ‡ PUT PAGE EDIT(A. .F(7.LINE: ‡ Used for printed output only.2)).When a control item appears inside the format list they are called control format items and when they appear outside the format list they are called control options. ‡ PUT PAGE EDIT(A.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT  Control Items .B)(PAGE(. . Control format items and control options are performed in the order in which they appear in a get or put statement. 114 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

.PAGE: ‡ Can be specified only for the stream files that have the PRINT attribute. ‡ Causes a skip to the first print line of the next page. Suppress the line feed. ‡ For Printer output: . 115 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .SKIP: ‡ On Input: .SKIP or SKIP(1): Starts printing on the next line.SKIP(expression): Causes the expression minus 1 lines to be left blank before printing the next line.IBM Global Services EDIT DIRECTED INPUT AND OUTPUT . .SKIP(0): Start or continue reading at the beginning of the next logical record.

Each item in the input is in the form of an assignment statement that specifies both the value and the variable to which it is to be assigned. DCL TABEL(50) FIXED DEC(5.If the data list is an array. .D=µ1110¶B.43.D). . TABLE(4)=8.C=µABCDEF¶.Statements are separated by blanks or commas.95.3. .B. | Presentation Title | Confidential 30-Nov-10 © Copyright IBM Corporation 2004 . but the vice versa is not true. .Maximum number of elements permitted in a list = 320.C. A= 12. e.Data list may include the name that do not appear in the list. GET DATA (TABLE).TABLE(7) = 50.Semicolon ends each group of items to be accessed by a single GET statement.B=57. GET DATA(A.IBM Global Services DATA DIRECTED INPUT AND OUTPUT  Data directed input: . Input stream could be: 116 TABLE(3)=7.g.g. subscripted references to that array may appear in the stream. e.2). .

. . Tab position Output would look like: 1 A=0 25 B=0 49 C=175.IBM Global Services DATA DIRECTED INPUT AND OUTPUT  DATA DIRECTED OUTPUT: . DCL C FIXED BIN(15) INIT(175). PUT DATA(A.C).Last item output is followed by a semicolon.Each data item is placed in the stream in the form of assignment statements.Leading zeros of arithmetic data are suppressed.g. DCL A FIXED DEC(5) INIT(0).B. e. DCL B FIXED DEC(5) INIT(0). 117 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

118 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .  CONVERSION: .A condition indicating that the end of a page of printed output has been completed.  SIZE: .  RECORD: .  ENDPAGE: .IBM Global Services STREAM FILE CONDITIONS  ENDFILE: .A condition indicating that an input or output device did not transmit data correctly.A condition indicating that the size of record in a given file does not match the record size declared in a PL/I program.A condition indicating that the number of significant digits in a coded arithmetic data item exceeds the declared or default size of the identifier.  TRANSMIT: .A condition indicating that the data includes illegal characters for the type of data item declared.A condition indicating the end of file has been reached.

Structures.IBM Global Services Record I/O. Pictures © Copyright IBM Corporation 2004 .

. DCL PRINTR FILE OUTPUT RECORD ENV(F RECSIZE(80)). READ FILE(DATA) INTO(DATA_AREA). . DO WHILE(MORE_RECORDS). ON ENDFILE(DATA) MORE_RECORDS = µ0¶B. 120 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . READ FILE(DATA) INTO(DATA_AREA).IBM Global Services RECORD I/O Consider a simple program: DCL DATA FILE INPUT RECORD ENV(F RECSIZE(80)).WRITE Specifies the OUTPUT operation. END. DCL DATA_AREA CHAR(80). WRITE FILE(PRINTR) FROM(DATA_AREA).READ specifies the INPUT operation. MORE_RECORD = µ1¶B.

which helps the printer to determine the appropriate action.A keyword must be added to the environment section of the file declaration to notify PL/I that these carriage control statements are being used.IBM Global Services RECORD I/O  Carriage Control in record output: . . . . . skip to the next page. 121 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .There are 2 general choices for this: CTLASA and CTL360 respectively. when this count reaches a specified limit.CTL360 causes the carriage control operation after the print operation.Increment a program count by 1 each time a write is issued. .CTLASA causes the carriage control operation before print operation. .To achieve this an extra character is added at the beginning of every record.Is required to control page overflow.

DCL DATAIN FILE INPUT ENV( F RECSIZE(80)). DCL MORE_RECORDS BIT(1) INIT('1'B). LINE_COUNT = 55. DCL PRINT_AREA CHAR(81).FILE(PRINTR). READ FILE(DATAIN) INTO (DATA_AREA).IBM Global Services RECORD I/O TSTPLI1: PROC OPTIONS(MAIN). PRINT_AREA = '1'||DATA_AREA. DCL NO BIT(1) INIT('0'B). LINE_COUNT = 0. DCL LINE_COUNT FIXED DEC(3). WRITE FILE(PRINTR) FROM (PRINT_AREA). ON ENDFILE(DATAIN) MORE_RECORDS = NO. 122 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . END TSTPLI1. END. IF LINE_COUNT > 55 THEN DO. DCL DATA_AREA CHAR(80). OPEN FILE(DATAIN). END. ELSE PRINT_AREA = ' '||DATA_AREA. READ FILE(DATAIN) INTO (DATA_AREA). DCL PRINTR FILE OUTPUT RECORD ENV(F RECSIZE(81) CTLASA). DO WHILE(MORE_RECORDS). LINE_COUNT = LINE_COUNT + 1.

Character Code Blank 0 + 1 2 3 4 5 Resulting carriage control operation Space 1 line Space 2 lines Space 3 lines Suppress space Skip 1o channel1 Skip to channel2 Skip to channel3 Skip to channel4 Skip to channel5 Character Code 6 7 8 9 A B C V W Resulting carriage control operation Skip to channel6 Skip to channel7 Skip to channel8 Skip to channel9 Skip to channel10 Skip to channel11 Skip to channel12 Select stacker 1 Select stacker2 123 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services RECORD I/O  Carriage Control characters that can be used with CTLASA option.

. 124 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services RECORD I/O  Record I/O statements: . and so on.Position 1 through 4 will be placed in TABLE(1).READ FILE(DATA) INTO(DATA_AREA).DCL TABLE(20) CHAR(4). . position 5 through 9 in TABLE(2).WRITE FILE(PRINTR) FROM(PRINT_AREA).READ FILE (DATA) INTO (TABLE). . .

Keywords: GET. . PUT .Outputs data in exactly the same form as internally stored.Respects physical record boundaries . READ.Converts and edits internally stored data to character format.IBM Global Services RECORD I/O  Record . . . I/O is considered to be a continuous stream .Converts character data in input stream to the attributes of the declared identifiers.Ignores physical boundaries.Stores data in exactly the same form as input. direct)  Stream .May be used with any data set organization (sequential.May only be used for sequential datasets. no conversion or validity checks.Input and output are a stream of characters. VSAM. WRITE . fixed point binary. indexed sequential.Input and output may be any data type (packed decimal. .) . 125 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .Keywords. etc. .

126 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .g. CHAR(25).  Fillers used in a structure should have UNIQUE names. DCL 1 NAME_AND_ADDR. CHAR(25).IBM Global Services STRUCTURES  A Structure is a collection of data items whose locations relative to one another are critical. e. 2 NAME 2 STREET 2 CITY_STATE 2 ZIP 2 REST_OF_RECORD CHAR(20).  Each element has a level number and several elements are grouped under a single structure name.  Usually the data items that appear in a structure have a logical relationship to each other. CHAR(1). CHAR(9).

/* ILLEGAL MOVE */ /* Legal move */ 127 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . DCL ITEM CHAR(15).IBM Global Services STRUCTURES  STRING function: . 2 ELEMENT3 CHAR(7) INIT(µXYZXYZX¶). 2 ELEMENT1 CHAR(5) INIT(µABCDE¶). DCL 1 STRUCTURE. 2 ELEMENT2 CHAR(3) INIT(µ123¶).Concatenates all the elements in a structure into a single character or bit string. ITEM = STRING(STRUCTURE). ITEM = STRUCTURE.

S indiactes that the sign of the value is to appear in a separate byte position in the variable. insertion character and sign occupies one byte. DCL B PIC µ(5)9V(2)9¶. . DCL A PIC µ9999V99¶. . 128 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . .The base and scale are implicitly DECIMAL and FIXED. .e.  Decimal Pictures .Validate data.Treat arithmetic quantities as character strings (record output) . + Indicates that a plus sign is to appear in the character representation of the variable if the value is greater than or equal to zero and a blank if it is less than zero.IBM Global Services PICTURES  Pictures are used to .Each digit .Precision is determined by number of µ9¶s or µZ¶s and the location of the µV¶ picture character.Treat character-strings as arithmetic quantities( record input) .g.Edit data($) .

/* 012.If V is to the right of the decimal point in PIC and leading 0¶s are to be suppressed..Indiactes that a minus sign is to appear in the character representation of the variable of the value is less than zero and a blank if it is greater than equal to zero.99¶ INIT(12.05).12 IS PRINTED */ .99¶ INIT(12. PUT LIST(PRICE).99¶ INIT(.e. DCL PRICE PIC¶999V.  Decimal point. e. DCL VALUE PIC¶999.34). .IBM Global Services PICTURES .g.35).g.05). B PIC µZZZ. e. 129 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .34 */ If the picture is specified without the decimal point the output will be 01234 The decimal point however does not cause alignment.g DCL A PIC µZZZV. decimal point will be replaced by a blank whenever the integer portion of the number is 0. PUT LIST (VALUE).Z is used to suppress the leading zeroes. . /* 000.V99¶ INIT(.It is an insertion character and will be inserted output field in the position it appears in the picture specification. .

99(7)B¶. It will be inserted in the output field in the position corresponding to its location in the picture.99¶ INIT(104056.ZZZV.98 is the output */  The Blank(B) .It is another insertion character.  The Slash(/) .056.98).It is another insertion character. It will insert a blank to the right of a value on output. /* 104. DCL BIG_VALUE PIC¶999.999V.) . IS INVALID 130 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . Note: DCL EDITED_RUN_DATE PIC¶Z9/Z9/99¶ . DCL B PIC µZ. DCL EDITED_RUN_DATE PIC µZ9/99/99/.It is an insertion character used to insert / at the specified position in the picture. PUT LIST(BIG_VALUE).IBM Global Services PICTURES  The Comma(. DCL RUN_DATE CHAR(6). DCL A PIC¶999V99BBB¶.

/* $012.50). PUT LIST (A). PUT LIST(B). .**¶ INIT(843.99¶ INIT(12. PUT LIST(AMT_PAID).In static form it implies that currency symbol will always appear in the position fixed by its location in the picture. /* **843.Specifies the currency symbol in the character representation of numeric data.IBM Global Services PICTURES  Dollar sign . DCL AMT_PAID PIC µ*****V. .  The ASTERISK (*) .It is a fill character and is used much the same way as Z.50 IS THE OUTPUT */ 131 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .34 IS THE OUTPUT */ DCL B PIC µ$$$$V.34).In drifting it specifies that the leading zeros are to be suppressed and that the rightmost suppressed will be replaced with the $ symbol DCL A PIC µ$999V.99¶ INIT(12.34).34 IS THE OUTPUT */ /( $12.

99CR¶ INIT(-12. DCL D PIC ¶99V.If the value of the data is negative associated positions will contain CR or DB when specified in the picture clause. /* 12. PUT LIST(E). 132 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . PUT LIST(D).IBM Global Services PICTURES  Credit (CR) and Debit (DB) characters: .34).34).34cr IS THE OUTPUT */ /( 12.99DBBBBB¶ INIT(-12.34Dbbbb IS THE OUTPUT */ DCL E PIC¶99V. If the value is positive it will contain 2 blanks.

Picture Specification A X 9 Action Performed Associated position may contains alphabets from A to Z Associated position may contain any character. . .X and 9.String built-in functions can be used.Characters that make up the picture specification are A.IBM Global Services PICTURES  Character String Pictures: . Associated position ma contain digits 0 through 9. rather they have the character string length attribute.Data items do not have the arithmetic attributes of base scale and precision. 133 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

C.P¶AA999¶.D)(COL(1). GET EDIT(A.B.IBM Global Services PICTURES  Pictures in String I/O: . VALUE = A*B.99CR¶. Ex: DCL VALUE FIXED DEC(8.P¶ZZZ9¶.$$$V.P¶99V99¶. EDIT_VALUE = VALUE . 134 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .P¶(5)9¶). DCL EDIT_VALUE PIC µ$$$$.Data editing is possible also in list directed I/O and edit directed I/O. PUT LIST(EDIT_VALUE).2).

it may contain the INITIAL attribute. level number that may be specified is 255. e.  Elementary items contained in a minor structure must be declared with a greater level number than that of the minor structure.C) CHAR(3).  Max.B.IBM Global Services STRUCTURES  The major structure name is declared first.  Factored attribute in a structure. DCL (A. character string or other data item.g.Elementary items in a structure may be initialized using the INITIAL attribute.  INITIAL attribute in Structures. 135 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . as long as the structure is not overlay defined on another structure. . As long as the structure is the base identifier.  The elementary items in each minor structure are completely declared before the next minor structure is declared. .Factoring identifiers together for the the purpose of giving them a common attribute.

3 WAGES. ¶99¶.g. but within structures . 5 5 REGULAR OVERTIME PIC PIC PIC PIC ¶99¶. it is often desirable to be able to use the same identifier for related names and yet retain the uniqueness. 136 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . ¶99V99¶.REGULAR*WAGES.REGULAR. ¶99V99¶. RGULAR_PAY = HOURS. All names within a single procedure must be unique. 3 HOURS.IBM Global Services STRUCTURES  Qualified attributes. 5 REGULAR 6 OVERTIME We can have the following statements.e.

1). 2 TEMPERATURE. 2 2 2 PART_NO CHAR(8). QTY_ON_HAND PIC¶9999¶. FIXED DEC(3. PIC¶9999¶. FIXED DEC(2).IBM Global Services STRUCTURES  Arrays in structures: DCL 1 INVERTORY_ITEM. FIXED DEC(3).1). 3 3 2 3 3 HIGH LOW HIGH LOW FIXED DEC(4. 137 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . SALES_HISTORY(12)  Arrays of structures: DCL 1 WHETHER(12). WIND_VELOCITY.

3 PRODUCE 2 TRANSPORTATION FIXED DEC(7. DCL 1 BUDGET. 2 ENTETAINMENT FIXED DEC(5.It is used to indicate that the name being declared is to be given the same structure as the major structure name following the attribute LIKE.Minor structure name can be declared like a major structure or another minor structure. .e. FIXED DEC(5. DCL COST_OF_LIVING LIKE BUDGET. 2 RENT 2 FOOD. 138 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . FIXED DEC(5. FIXED DEC(4. .2).2).IBM Global Services STRUCTURES  Like Attribute: .2).2). 3 MEAT 3 DAIRY FIXED DEC(5.2).No dimensionality of the specified name is copied.g.2).

2 E FIXED BIN(15). 2 B FIXED DEC(5). 2 D CHAR(20).Both the structures should have the same relative structuring.Same number of elementary items within the minor/major structure . A = AA. 2 F FLOAT DEC(5).The attributes of the elementary items can be different and conversion occurs in such cases. . 2 CC FIXED DEC(5).  DCL 1 AA. .The sizes of the receiving and sending fields may differ.  DCL 1 A. . 2 DD CHAR(10). 2 EE FIXED DEC(4). 2 C FIXED BIN(31).If arrays are present the same bounds should have the same values.IBM Global Services STRUCTURES  Structure assignment. 2 BB FIXED BIN(15). . .Must have the same minor structures. 139 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 2 FF FIXED DEC(6).Elementary items are moved to corresponding elementary items. .

PIC µ$999V.IBM Global Services STRUCTURES  Structure assignment by name. 2 CARRIAGE_CNTL CHAR(1). 2 EMP_NUMBER CHAR(6). Is allowed. 2 EMP_NAME 2 GROSS_PAY CHAR(250. 3 REGULAR PIC ¶99¶. . 140 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 3 OVERTIME PIC ¶99¶. 2 EMP_NAME CHAR(20). .  DCL 1 INPUT.99¶. BY NAME. 2 EMP_NUMBER CHAR(12). DCL 1 OUTPUT.Allows structures with different relative structuring to assign values. 2 GROSS_PAY PIC µ999V99¶. 2 HOURS.In the example OUTPUT = INPUT .

2 ACCOUNT-NO CHAR(7). 141 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 3 CITY_STATE CHAR(25). 2 ADDRESS. DCL 1 CUSTOMER. 2 NAME CHAR920).IBM Global Services STRUCTURES  Scalar to structure assignment. 3 STREET CHAR(25). 3 ZIP_CODE CHAR(5). CUSTOMER = µ ¶.

CHAR(7).  Overlay defining ± Structure on a structure . although CUST and CUSTOMER are different variables they refer to the same storage.e. CHAR(61).Here. DCL 1 ISSUES. CHAR(3). .In the previous example we could have initialized the structure in a different way. PIC¶9999¶. CUST = µ ¶. CHAR(4).Need arises when we are dealing with 2 or more data formats for records read from the same input. 2 CODE 2 QTY 2 JOB_NO 2 PART_NO 2 DEPT 2 REST_OF_RECORD CHAR(1).We could have declared a variable: DCL CUST CHAR(81) DEF CUSTOMER.IBM Global Services STRUCTURES  Overlay defining on a structure . .g. 142 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .

WHEN(µ1¶) CALL PROCESS_ISSUES. WHEN(µ2¶) CALL PROCESS_RECEIPTS. OTHERWISE CALL ERROR. 143 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . CHAR(6). SELECT (ISSUES. PIC¶9999¶. END. 2 CODE 2 QTY 2 PART_NO 2 SUPPLIER READ FILE(INPUT) INTO(ISSUES).IBM Global Services STRUCTURES DCL 1 RECEIPTS DEFINED ISSUES. CHAR(7).CODE). CHAR(1). Note: Overlay defined structures do not have to define an area as large as the base identifier.

A(3).IBM Global Services STRUCTURES  STRUCTURES in Stream I/O . .REORDER_QTY)(A(2).Name of structures can also be specified in edit directed and list directed I/O. type and code Two format items are required 144 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 3 TYPE 3 CODE CHAR(2). DCL 1 INVENTORY.Names may be major level or intermediate level structure names.F(9)). REORDER_QTY is printed in form of bbbbbxxxx. where x is any decimal digit. Represents two elementary items. PUT EDIT (PART_NO. CHAR(3). 2 PART_NO. 2 REORDER_QTY PIC¶(4)9¶.

IBM Global Services STORAGE CLASSES © Copyright IBM Corporation 2004 .

IBM Global Services STORAGE CLASSES  Data names actually represent locations in main storage where data items are recorded. the storage is said to be allocated.  The time at which the storage is to be allocated depends on the storage class of the data. 146 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .  When the location in main storage is associated with data name.

DCL 1 STRUCTURE.IBM Global Services AUTOMATIC STORAGE  Unless declared to have another storage class most variables have the AUTOMATIC attribute. MAIN : PROC OPTIONS (MAIN). «. « END P2. 147 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .2). «. PROC. P1 : PROC. 2D FIXED(5). END MAIN. END. DCL LIST(500) FIXED.C) FIXED(5. P2 . 2 (A. DCL TABLE(100) CHAR(10).B. END P1. DO WHILE(MORE_DATA). «.

 When main calls P2.It performs the allocation of dynamic allocation.Storage for LIST is allocated. . Compiler controls this routine by executing it as the first step in the routine. 148 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .Storage for TABLE is activated.  Epilogue: .  This process is called dynamic allocation.IBM Global Services AUTOMATIC STORAGE  When main calls P1 . .The release of main storage that has been allocated to automatic variables is handled by a routine called epilogue.  Prologue: .Storage for TABLE is released prior to this call. . It is executed as the final step before the termination of the block.Storage for STRUCTURE stays allocated.

Static variables however are initialized once and Dynamic variables are initialized in each and every invocation of the block. if we wanted to store the value of TABLE before P1 is called 2nd time.IBM Global Services STATIC STORAGE  In the previous example. 149 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . so that the value of LIST does not overlay it. then we need to allocate the storage for table STATICALLY.  Here the storage is allocated before the execution of the program and remains allocated throughput the execution of the program. File names default to EXTERNAL and thus info related to a file is stored in static storage area.  Static and Dynamic variables can be initialized using the INIT attribute.  Program constants and variables declared with EXTERNAL attribute have STATIC storage class attribute.

DCL A(100) FIXED DEC(5) BASED(P). DCL P POINTER.IBM Global Services BASED STORAGE  With AUTOMATIC storage address of storage is determined upon entry into the block  With STATIC storage address of storage is determined when the program is loaded in the main storage. Indicates that the address of the array A is determined by te contents of P.  With BASED storage the address is contained in a pointer variable. 150 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . The contents of P have not been established yet.

151 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .By assignment of the value of another pointer. DCL (P. DCL VALUE2 FLOAT(6).Q) POINTER. Q = P.  This can be done in one of the following ways: . .By assignment of the value returned by the ADDR built in function.IBM Global Services BASED STORAGE  A pointer variable is a special type of variable used to point to data in main storage. DCL VALUE1 BIT(32) BASED (P).  Before a reference can be made to a based variable a value must be given to the pointer. P = ADDR(VALUE2). P = ADDR(AREA).

IBM Global Services

BASED STORAGE
- With the SET option of a READ or LOCATE statement. READ FILE(INPUT) SET(P); LOCATE FILE(OUTPUT) SET(Q); - By an ALLOCATE statement. DCL (P,Q) PTR; DCL AREA CHAR(100) BASED(P); ALLOCATE (AREA); ALLOCATE(AREA) SET (Q);

152

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

BASED STORAGE 
Simulating overlay defining.
DCL A(100) FIXED BIN(31); DCL B(50) FLOAT DEC(6) BASED(P); DCL P POINTER; P = ADDR(A); Here B is overlay defined on A although A and B have different base, scale and precision.( not possible with DEF attribute.) - A based variable is a description of data i.e. a pattern for which no storage space is reserved but that will be overlaid on data in storage pointed to by an associated pointer variable. - If A is itself a based variable , the returned value is determined from the pointer variable declared within A( If this pointer variable contains no value, the value returned by ADDR is undefined.)

153

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

IBM Global Services

BASED STORAGE 
It is also possible to have more than one variable based on contents of same ptr.
DCL 1 A , 2 B PIC µ9999¶, 2 C FIXED DEC(13,2), 2 D CHAR(21); DCL 1 J BASED(PTR), 2 X FIXED BIN(15), 2 Y FLOAT DEC(6), 2 Z BIT(7); DCL 1 W BASED(PTR), 2 K FIXED BIN(15), 2 L FIXED BIN(15); DCL PTR PTR; PTR = ADDR(A); Note: A Based variable shouldn¶t describe more storage than the identifier on which it is based uses.

154

Presentation Title | Confidential

|

30-Nov-10

© Copyright IBM Corporation 2004

.The Length field must be specified in the structure to accommodate the two-byte field that always preceds a variable length character string. DCL 1 STRUCTURE BASED(ADDR(FIELD)). 2 LENGTH FIXED BIN(15. 2 DATA CHAR(100).0). 155 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 .IBM Global Services BASED STORAGE  Special consideration for character strings with varying clause. DCL FIELD CHAR(100) VAR.

It then Sets the pointer variable named in the set option to point to the location (starting address) of the next record. Causes a block of data to be read from the file named TAPEIN to an input buffer.2). READ FILE(TAPEIN) SET(P). DCL 1 IN_REC BASED(P). 2 C FIXED DEC(7.The read stmt. 156 Presentation Title | Confidential | 30-Nov-10 © Copyright IBM Corporation 2004 . 2 A PIC ¶99¶.IBM Global Services BASED STORAGE DCL P PTR. 2 B CHAR(8). . . 2 REST_OF_RECORD CHAR(66).

IBM Global Services Thank You © Copyright IBM Corporation 2004 .

Sign up to vote on this title
UsefulNot useful