Sie sind auf Seite 1von 748

Enterprise COBOL for z/OS and OS/390

Programming Guide

Version 3 Release 1

SC27-1412-00

Enterprise COBOL for z/OS and OS/390

Programming Guide

Version 3 Release 1

SC27-1412-00

Note! Before using this information and the product it supports, be sure to read the

Note! Before using this information and the product it supports, be sure to read the general information under “Notices” on page 679.

this information and the product it supports, be sure to read the general information under “Notices”

First Edition (November 2001)

This edition applies to Version 3 Release 1 of IBM Enterprise COBOL for z/OS and OS/390 (program number 5655-G53) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure that you are using the correct edition for the level of the product.

You can order publications online at www.ibm.com/shop/publications/order, or order by phone or fax. IBM Software Manufacturing Solutions takes publication orders between 8:30 a.m. and 7:00 p.m. Eastern Standard Time (EST). The phone number is (800)879-2755. The fax number is (800)445-9269.

You can also order publications through your IBM representative or the IBM branch office serving your locality.

© Copyright International Business Machines Corporation 1991, 2001. All rights reserved. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

Contents

About this book .

.

.

.

.

.

.

.

.

.

.

xi

How this book will help you.

.

.

.

.

.

.

.

.

xi

Abbreviated terms

.

.

.

.

.

.

.

.

.

.

.

.

xi

Comparison of commonly used terms

.

.

.

.

.

xii

How to read syntax diagrams .

.

.

.

.

.

.

.

xiii

How examples are shown Summary of changes .

. How to send your comments

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

xiv

.

.

.

.

.

.

.

.

.

.

xiv

xv

Part 1. Coding your program

 

.

.

.

.1

Chapter 1. Structuring your program

Identifying a program

.

.

.

.

.

.

.

.

.

.

.

5

.5

. Identifying a program as recursive .

.

.

.

.

.6

Marking a program as callable by containing .

programs

. Changing the header of a source listing

. Setting a program to an initial state.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.6

.6

6

Describing the computing environment Example: FILE-CONTROL entries .

 

.

.

.

.

.7

.

.

.

.

.7

Specifying the collating sequence

.

.

.

.

.

.8

Defining symbolic characters . Defining a user-defined class .

.

.

.

.

 

.

.

.

.

.9

.

.

.

.

.9

Defining files to the operating system

 

.

.

.

.

10

Describing the data .

.

.

.

.

.

.

.

.

.

.

.

12

Using data in input and output operations . Comparison of WORKING-STORAGE and

 

.

.

12

LOCAL-STORAGE .

.

.

.

.

.

.

.

.

.

.

14

Using data from another program .

.

.

.

.

.

16

Processing the data .

.

.

.

.

.

.

.

.

.

.

.

17

How logic is divided in the PROCEDURE

 

DIVISION

.

.

.

.

.

.

.

.

.

.

.

.

18

Declaratives .

.

.

.

.

.

.

.

.

.

.

.

.

21

Chapter 2. Using data

.

.

.

.

.

.

.

.

23

Using variables, structures, literals, and constants

 

.

23

Variables

.

.

.

.

.

.

.

.

.

.

.

.

.

.

23

Data structure: data items and group items .

 

.

.

23

Literals .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

24

.

.

. Examples: initializing variables .

Constants .

. Figurative constants

.

. Assigning values to data items .

.

.

.

.

. Initializing a structure (INITIALIZE) .

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

24

24

25

25

27

Assigning values to variables or structures

 

(MOVE)

.

.

.

.

.

.

.

.

.

.

.

.

.

.

27

Assigning arithmetic results (MOVE or

 

. Assigning input from a screen or file (ACCEPT)

COMPUTE) .

.

.

.

.

.

.

.

.

.

.

 

.

28

29

Displaying values on a screen or in a file (DISPLAY) 30 Displaying data on the system logical output

30

31

32

. Using intrinsic functions (built-in functions)

device .

. Using WITH NO ADVANCING

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Types of intrinsic functions

.

.

.

.

.

.

.

.

32

Nesting functions .

.

.

.

.

.

.

.

.

.

.

33

Using tables (arrays) and pointers .

.

.

.

.

.

.

33

Storage and its addressability

.

.

.

.

.

.

.

.

33

Settings for RMODE

.

.

.

.

.

.

.

.

.

.

.

34

Storage restrictions for passing data

.

.

.

.

.

34

Location of data areas

. Storage for external data .

.

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.

.

35

35

Storage for QSAM input-output buffers .

.

.

.

35

Chapter 3. Working with numbers and

 

arithmetic

.

.

.

.

.

.

.

.

.

.

.

.

.

37

Defining numeric data.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

37

Displaying numeric data .

.

.

.

.

.

38

Controlling how numeric data is stored .

.

.

.

.

39

Formats for numeric data.

. External decimal (DISPLAY) items .

.

.

.

.

.

.

.

.

.

.

.

.

.

40

40

External floating-point (DISPLAY) items .

 

.

.

.

40

Binary (COMP) items .

.

.

.

.

.

.

.

.

.

41

.

.

.

.

.

.

41

Native binary (COMP-5) items . Packed-decimal (COMP-3) items

. Floating-point (COMP-1 and COMP-2) items

.

.

.

.

.

.

.

42

42

Examples: numeric data and internal representation

42

Data format conversions .

.

.

.

.

.

.

.

.

.

.

.

.

43

Conversions and precision

.

.

.

.

.

44

Sign representation and processing

.

.

.

.

.

.

45

NUMPROC(PFD) .

.

.

.

.

.

.

.

.

.

.

45

.

.

.

.

.

.

.

.

.

45

NUMPROC(NOPFD) . NUMPROC(MIG) .

. Checking for incompatible data (numeric class test)

.

.

.

.

.

.

.

.

.

45

46

Performing arithmetic .

.

.

.

.

.

.

.

.

.

.

47

COMPUTE and other arithmetic statements

Arithmetic expressions

.

.

.

.

.

.

.

.

.

.

47

47

. Numeric intrinsic functions .

.

.

.

.

.

.

.

48

Nesting functions and arithmetic expressions .

 

.

49

ALL subscripting and special registers

.

.

.

.

49

Math and date Language Environment services

 

49

Examples: numeric intrinsic functions

.

.

.

.

.

51

General number handling

.

.

.

.

.

.

.

.

51

Date and time

.

.

.

.

.

.

.

.

.

.

.

.

51

Finance .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

52

Mathematics .

.

.

.

.

.

.

.

.

.

.

.

.

52

Statistics .

.

.

.

.

.

.

.

.

.

.

.

.

.

52

Fixed-point versus floating-point arithmetic

 

.

.

.

53

Floating-point evaluations

.

.

.

.

.

.

.

.

53

Fixed-point evaluations

.

.

.

.

.

.

.

.

.

53

Arithmetic comparisons (relation conditions) Examples: fixed-point and floating-point

evaluations

. Using currency signs

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

54

54

55

. Example: multiple currency signs .

.

.

.

.

.

56

Chapter 4. Handling tables .

.

.

.

.

.

57

Defining a table (OCCURS) .

.

.

.

.

.

.

.

.

57

Nesting tables

.

.

.

.

.

.

.

.

.

.

.

.

.

58

Subscripting .

.

.

.

.

.

.

.

.

.

.

.

.

58

Indexing

.

.

.

.

.

.

.

.

.

.

.

59

Referring to an item in a table .

.

.

.

.

.

.

.

59

Subscripting

.

.

.

.

.

.

.

.

.

.

.

.

.

60

Indexing .

. Loading a table dynamically.

. Initializing a table (INITIALIZE)

. Putting values into a table

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

61

62

62

62

Assigning values when you define a table

(VALUE) .

.

.

.

.

.

.

.

.

.

.

.

.

.

63

.

.

.

.

64

Example: PERFORM and subscripting Example: PERFORM and indexing.

. Creating variable-length tables (DEPENDING ON)

.

.

.

 

.

65

66

Loading a variable-length table .

.

.

.

.

.

.

67

Assigning values to a variable-length table .

. Doing a serial search (SEARCH)

.

.

Searching a table

.

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.

.

68

69

69

. Doing a binary search (SEARCH ALL)

.

.

.

.

70

Processing table items using intrinsic functions

 

.

.

71

Example: intrinsic functions .

.

.

.

.

.

.

.

71

Chapter 5. Selecting and repeating

program actions

.

.

.

.

.

.

.

.

.

.

73

Selecting program actions

. Coding a choice of actions

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

73

73

Coding conditional expressions .

.

.

.

77

Repeating program actions

.

.

.

.

.

.

.

.

.

80

Choosing inline or out-of-line PERFORM

.

.

.

81

. Coding a loop through a table .

Coding a loop

.

. Executing multiple paragraphs or sections .

.

.

.

.

.

.

.

.

.

.

.

 

.

.

.

.

.

.

82

83

83

Chapter 6. Handling strings .

.

.

.

.

.

85

Joining data items (STRING) Example: STRING statement.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

85

85

Splitting data items (UNSTRING) .

.

.

.

87

Example: UNSTRING statement

Manipulating null-terminated strings .

.

.

.

.

.

.

87

89

Example: null-terminated strings

Referring to substrings of data items .

.

.

.

.

.

.

90

90

Reference modifiers.

.

.

.

.

.

.

.

.

.

.

91

Example: arithmetic expressions as reference

 

modifiers .

.

.

.

.

.

.

.

.

.

.

.

.

.

92

Example: intrinsic functions as reference

modifiers .

.

.

.

.

.

.

.

.

.

.

.

.

.

93

Tallying and replacing data items (INSPECT) .

 

.

.

93

Examples: INSPECT statement .

.

.

.

.

.

.

93

Converting data items (intrinsic functions) . Converting to uppercase or lowercase

.

.

.

94

. Converting to reverse order (REVERSE) .

(UPPER-CASE, LOWER-CASE) .

.

.

.

.

.

.

.

.

95

95

Converting to numbers (NUMVAL, NUMVAL-C)

95

Evaluating data items (intrinsic functions) Evaluating single characters for collating .

.

.

sequence .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

96

97

Finding the largest or smallest data item

.

.

.

97

Finding the length of data items

.

.

.

.

.

.

.

.

.

98

Finding the date of compilation

.

.

.

99

Chapter 7. Coding for run-time use of

national languages .

.

.

.

.

.

.

.

.

101

Unicode and encoding of language characters

 

.

.

103

Using national data (Unicode) in COBOL .

 

.

.

.

103

National data items .

.

.

.

.

.

.

.

.

.

103

National literals

.

.

.

.

.

.

.

.

.

.

.

104

National characters as figurative constants

 

.

.

104

Storage of national data .

.

.

.

.

.

.

.

.

104

Converting national data

.

.

.

.

.

.

.

.

.

105

Converting alphanumeric and integer to

 

national data (MOVE)

.

.

.

.

.

.

.

.

.

105

Converting alphanumeric to national data

 

(NATIONAL-OF)

.

.

.

.

.

.

.

.

.

105

Converting national to alphanumeric data

(DISPLAY-OF) .

.

.

.

.

.

.

.

.

 

.

.

106

. Conversion exceptions .

.

.

.

.

.

.

.

.

106

Example: converting national data

 

.

.

.

.

.

106

Processing UTF-8 data .

.

.

.

.

.

.

.

.

.

107

Processing Chinese GB 18030 data

.

.

.

.

.

.

107

Comparing national data items

.

.

.

.

.

.

.

108

Comparing national operands .

.

.

.

.

.

.

109

Comparing national and numeric operands Comparing national and alphabetic or

 

.

.

109

. Comparing national and group operands .

alphanumeric operands .

.

.

.

.

.

.

.

.

.

109

109

Processing alphanumeric data items that contain

 

DBCS data

.

.

.

.

.

.

.

.

.

.

.

.

.

.

109

Chapter 8. Processing files

.

.

.

.

.

111

File organization and input-output devices

.

.

.

111

Choosing file organization and access mode

.

.

.

113

Format for coding input and output .

.

 

.

.

.

114

. Checking for input or output errors .

Allocating files .

.

.

.

.

.

.

 

.

.

.

.

.

.

.

.

.

.

115

116

Chapter 9. Processing QSAM files

 

.

.

117

Defining QSAM files and records in COBOL .

 

.

.

117

Establishing record formats .

.

.

.

.

.

.

.

118

Setting block sizes .

.

.

.

.

.

.

.

.

.

.

125

Coding input and output statements for QSAM

files

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

127

. Opening QSAM files .

.

.

.

.

.

.

.

.

.

128

Dynamically creating QSAM files with

 

CBLQDA .

.

.

.

.

.

.

.

.

.

.

.

.

.

128

Adding records to QSAM files.

.

.

.

.

.

.

129

Updating QSAM files

.

.

.

.

.

.

.

.

.

129

Writing QSAM files to a printer or spooled data

set .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

129

. Closing QSAM files .

.

.

.

.

.

.

.

.

.

130

Handling errors in QSAM files

.

.

.

.

.

.

.

131

Working with QSAM files

. Defining and allocating QSAM files .

.

.

.

.

.

.

 

.

.

.

.

.

.

131

131

. Ensuring file attributes match your program

Retrieving QSAM files

.

.

.

.

.

.

.

.

134

135

Using striped extended-format QSAM data sets

137

Accessing HFS files using QSAM .

.

.

.

.

.

.

138

Labels for QSAM files

.

.

.

.

.

.

.

.

.

.

139

Using trailer and header labels

.

.

.

.

.

.

139

Format of standard labels

. Processing QSAM ASCII files on tape

.

.

 

.

.

.

.

.

.

.

.

.

.

141

141

Requesting the ASCII alphabet

.

.

.

.

.

.

142

Defining the record formats Defining the ddname .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

142

142

Processing ASCII file labels .

.

.

.

.

.

143

Chapter 10. Processing VSAM files

 

145

VSAM files .

.

.

.

.

.

.

.

.

.

.

.

.

.

146

Defining VSAM file organization and records Specifying sequential organization for VSAM

.

.

147

. Specifying indexed organization for VSAM files

files

.

.

.

.

.

.

.

.

.

.

.

.

.

.

148

148

Specifying relative organization for VSAM files

149

Specifying access modes for VSAM files

 

.

.

.

151

Defining record lengths for VSAM files.

.

.

.

152

Coding input and output statements for VSAM

files

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

153

. File position indicator

.

.

.

.

.

.

.

.

.

155

Opening a file (ESDS, KSDS, or RRDS) .

 

.

.

.

155

Reading records from a VSAM file

.

.

.

.

.

157

Updating records in a VSAM file .

.

.

.

.

.

158

Adding records to a VSAM file

.

.

.

.

.

.

159

Replacing records in a VSAM file.

.

.

.

.

.

160

Deleting records from a VSAM file

.

.

.

.

.

160

Closing VSAM files .

. Handling errors in VSAM files

. Protecting VSAM files with a password

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

160

161

162

Example: password protection for a VSAM

 

indexed file .

.

.

.

.

.

.

.

.

.

.

.

.

162