Upload
lagbe666
View
243
Download
0
Embed Size (px)
Citation preview
7/31/2019 3. Language Reference
1/1103
COBOL85
Reference Manual
7/31/2019 3. Language Reference
2/1103
Third Edition: November 1996
The contents of this manu al may be revised w ithout prior notice. No p art of
this docum ent may be reproduced or transmitted in any form or by any
means, electronic or mechanical, for an y p urp ose, without th e express
written permission of Fu jitsu Limited .
1996 Fujitsu Limited . All Rights Reserved .
7/31/2019 3. Language Reference
3/1103
Preface
Purpose
This COBOL85 Reference Manual covers the ru les for w riting
programs in COBOL (COmm on Business Oriented Langu age) using
FUJITSU COBOL85.
Audience
This manual is for u sers who d evelop COBOL program s using
COBOL85. This manual assum es users possess basic programm ing
knowledge.
7/31/2019 3. Language Reference
4/1103
iv COBOL85 Reference Manual
Organization
The table below shows how th is manu al is organized.
Chap ter /Append ix Descrip tion
Ch ap ter 1. G en er al Ru les Co ver s th e g en er al r ules in clu d in g th e lan gu ag e
elements of COBOL, un ique reference, writing of
literals, and reference format
Cha pt er 2. COBOL Modules List s a nd e xp la ins the fa cilit ies of COBOL
Chap ter 3. Identification Division
and End Program Header
Explains the syntax of the id entification d ivision an d
end program header
Chapter 4 . Environment Division Explains the syntax of the environment division
Ch ap ter 5. D ata Division Exp lain s th e syn tax of th e d ata d iv ision
Chapter 6. Procedure Divis ion Expla ins the syntax of the procedure divis ion
Cha pter 7. Sour ce Text
Manipulation
Explains the syntax of statements used in th e source
text manipulation function
Cha pt er 8. Dat abase(SQL) Expla ins t he syn ta x o f t he da ta ba se function(SQL)
Chapter 9. Communication
Database
Explains the syntax of the commu nication d atabase
function
Chap ter 10. Micro Focus Native
Functions
Explains th e syntax of the Micro Focus n ative
functions
App end ix A. List of Reserved
Words
Lists the reserved w ord s in COBOL
App end ix B. System Quan titativeRestrictions Lists the qu antity restrictions of th e system
Ap p en d ix C. Cod e Tables Lists th e ch ar acter sets an d th eir la rg e-to -sm all
sequence
Appendix D. Intermediate Results Explains the attributes and accuracy of intermediate
results
Appendix E. Functional
Differences
Lists the functional d ifferences for each system
Appendix F. Control Record Expla ins t he fo rmat s o f the cont ro l r ecords
7/31/2019 3. Language Reference
5/1103
COBOL85 Reference Manual v
Scope of FUJITSU COBOL85 Functions
The FUJITSU COBOL85 functions consist of JIS standard COBOL
functions (JIS X 8002-1992) and FUJITSU COBOL85 extend ed
functions. The FUJITSU COBOL85 functions are as follows:
FUJITSU
COBOL85
functions
JIS stand ard COBOLfunctions
FUJITSU COBOL85
extend ed functions
Required
functions
Optional
functions
Nu cleus (2, nucleus 1, 2)
Sequential I-O fun ction (2, sequen tial 1, 2)
Relative I-O function (2, relative 0, 2)
Indexed I-O function (2, ind exed 0, 2)
Inter-program commu nication function
(2, comm un ication 1, 2)
Sort-merge function (1, sort 0, 1)
Source test manipulation function(2, sou rce tes t 0, 2)
Presenta tion file functionScreen han dling mod ule
Command line argument and
environment variable operation function
Database function
Comm unication d atabase function
Micro Focus n ative fun ction
Report w riter function (1, report 0, 1)
Built-in function function (1, function 0, 1)
Debu g fun ction (2, debu g 0, 2)*
Segmentation fu nction (2, segmentat ion 0, 2)*
*: The debu g function and segmentat ion function are treated as commen ts wh enthe program is run.
Note: In the above, stand ard m nemonic symbols for each JIS stand ard COBOLfunction is shown in paren theses. From left to right the symbols show theposition of the function in the hierarchy, the function abbreviation, and th emaximum and minimum levels of the function to wh ich th e level belongs.
In th is reference m anual, FUJITSU COBOL85 is called simp ly
COBOL.
7/31/2019 3. Language Reference
6/1103
vi COBOL85 Reference Manual
How to Use this Manual
Users who w ish to gain an un derstanding of the basic concepts of
COBOL and its facilities should first read Chap ters 1 and 2 in that
order. Users wh o already have an und erstanding of COBOL may
skip the first two chapters and read any of the other chapters or
appendixes as required.
The following d iagram show s the sequence in wh ich th e chapters
and app end ixes of this reference manu al shou ld be read.
[Aim of reader]
Understand the basicconcepts of COBOL
Understand the facilities of
COBOL
Understand syntax necessaryfor programming
[Required reading]
Chapter 1 General Rules
Chapter 2 COBOL Facilities
Chapter 3 Identification Division andProgram Header
Chapter 4 Environment Division
Chapter 5 Data Division
Chapter 6 Procedure Division
Chapter 7 Source Text Manipulation
Chapter 8 Database (SQL)
Chapter 9 Communication Database
Chapter 10 Micro Focus Native
Functions
Appendix A List of Reserved Words
Appendix B System Quantitative
Restrictions
Appendix C Code Tables
Appendix D Intermediate Results
Appendix E Functional Differences
Appendix F Control Record
Also see:
:Sequence
7/31/2019 3. Language Reference
7/1103
COBOL85 Reference Manual vii
Conventions Used in This Manual
Symbols Used in [Format]
In each chap ter, [Form at] show s how to w rite COBOL language
elemen ts, such as statements and clauses. The words show n in
[Format] mu st be written in the sequence shown un less otherwise
specified in the syn tax rules or general rules.
The following table lists the meaning of symbols app earing in
[Format].
Example of Convention Description
IF Underlined text indicates that thecharacter string is a keyword andcannot be omitted. Keywords notund erlines can be omitted.
VALUE IS constant-1 Uppercase characters indicate aCOBOL reserved word . These
character strings must be writtenexactly as they app ear in [Format].
{ identifier-1 } Brackets indicate that one of the valuesgiven can be selected.
[ data-name-1 ] Square parenthesis indicate that one of the values can be selected or th e valuecan be omitted.
{| COMMON | } Choice indicators mean that at leastone of the values given can be wr itten.Each character string must be unique.
Ellipses indicate the item immediatelypreceding can be specified rep eatedly.
7/31/2019 3. Language Reference
8/1103
viii COBOL85 Reference Manual
Example of Convention Descrip tion
WORKING-STORAGE SECTION. Periods must be written in the sameposition.
=, -, >, =, Special characters are key words. They
are not underlined, but must not beomitted.
CHECK
WITH PASCAL LINKAGE
ALL
PARAGRAPH-ID
COBOL
Command s, statements, clauses, andoptions you en ter or select app ear inupp ercase. Program section nam es, andsome proper nam es also appear inuppercase.
COBOL85 Users Guide
See Data Division in Chap ter 5.
References to other pu blications orsections with in pu blications are inquotation marks.
Shading
FUJITSU COBOL85 extend ed functions are h ighlighted in th e text by
shad ing. A shad ed section title ind icates that the entire title is a
FUJITSU COBOL85 extended function.
Syntax Rules and General Rules
The explanation of COBOL language elements such as statementsand clauses in each chap ter is arranged into [Format], syntax rules,
and general rules. [Format] shows the arrangem ent of elements
mak ing up a statement or clause. Syntax rules explain the
arran gement of elements in [Format] and restrictions on their
arrangement.
7/31/2019 3. Language Reference
9/1103
COBOL85 Reference Manual ix
General ru les explain the results of execution an d compilation wh ere
a statement or clause was written. They also explain the meaning of
elements in [Format] and the relationship between the elemen ts.
Syntax ru les or general rules are omitted w hen th ere are no ru les
relating to the elemen ts in [Format].
Obsolete Elements
Elemen ts marked "Obsolete elemen ts" in the text are given in the
1985 issue of the AN SI COBOL standard bu t may not be included in
the next ed ition. Fujitsu recomm end s that obsolete elements not be
used w hen creating new programs.
System-specific Functions
Some par ts of the COBOL85 common syn tax described in th is
man ual dep end on system functions, and differ among systems.
Such p arts are indicated by the following system nam es:Indication Corresponding sys tem
DS UXP/ DS COBOL85 V20L1X
HP HP-UX COBOL85 V20L10
Su n Solaris COBOL85 V20L20
Win COBOL85 V30L10 for Windows 95,COBOL85 V30L10 for Windows NT &COBOL85 V20L10 for Windows 3.1
Win32 COBOL85 V30L10 for Windows 95 &COBOL85 V30L10 for Wind ows N T
Win16 COBOL85 V20L10 for Windows 3.1
7/31/2019 3. Language Reference
10/1103
x COBOL85 Reference Manual
The followings are positions of the indications and the area
correspond ed the indications:
Position of in dication Corresp on d area of th e
indication
top of a heading the chapter, the section ,etc.
head of a paragraph the paragraph
in table the row
See Appendix E for a list of functional differences.
7/31/2019 3. Language Reference
11/1103
COBOL85 Reference Manual xi
Acknowledgment
COBOL language specifications are based on the original
specifications developed by the Conference on Data Systems
Langu ages (CODASYL), and specifications in this m anu al are a lso
derived from these specifications. The chap ters listed below were
includ ed on requ est from CODASYL.
COBOL is not own ed by any p articular comp any, organization, or
group ; it has been d esigned for general use in ind ustry. CODASYL
does not guarantee and bears no responsibility in relation to the
programm ing method , the accuracy of langu age, and functions.
The following copyright own ers permitted partial use of thefollowing documents when the original specifications were put
together . This permission also extends to the use of the original
specifications in oth er COBOL specifications.
FLOW-MATIC (trad emark of Sperryland Inc.),"Programm ing for the Univac (R) I and II, Data Autom ation
System s", cop yrigh t Sperry land Inc. 1958, 1959 IBM Commercial Translator, library number F28-8013,
copy righ t IBM Inc. 1959
FACT, library number 27A5260-2760, copyright MinneapolisHoneywell Inc. 1960
7/31/2019 3. Language Reference
12/1103
xii COBOL85 Reference Manual
Trademarks
UNIX is a registered trademark in the United States and other
countries, licensed exclusively through X/ Open Comp any Limited.
Motif is a trad emark of Open Software Found ation, Inc.
MS-DOS is a registered trademark of Microsoft Corporation.
Microsoft is a registered trademark of Microsoft Corporation.
Window s is a registered tradem ark of Microsoft Corporation.
Windows NT is a registered trademark of Microsoft Corporation
HP an d H P-UX are tradem arks of Hew lett-Packard Comp any
Micro Focus is a reg istered trademark of Micro Focus Ltd., U.K.
Sun and Solaris are trademarks of Sun Microsystems, Inc.
7/31/2019 3. Language Reference
13/1103
COBOL85 Reference Manual xiii
Contents
CHAPTER 1. GENERAL RULES...........................................................................................1
CHARACTERS AND
CHARACTER
SETS
.........................................................................................2BASIC OVERVIEW OF LANGUAGE ...............................................................................................5
Separator ........................................................................................................... ..................5
COBOL Word.................................................................................................... ................10
Literal................................................................................................................................23
Figurative Constant............................................................................................................32
Concatenation Expression......................................... .........................................................35
Literal for Special Applications..........................................................................................37
Picture Character-string.....................................................................................................38Comment Entry .................................................................................................................39
CONCEPT OF DATA DESCRIPTION.............................................................................................39
Concept of Levels...............................................................................................................39
Concept of Class ................................................................................................................40
Standard Alignment Rule................................................................................... ................42
Adjustment of Data Boundary............................................................................................43
Example of Insertion of a Slack Byte..................................................................................45
UNIQUENESS OF REFERENCE....................................................................................................51Qualification......................................................................................................................51
Subscripting.......................................................................................................................57
Reference Modification ......................................................................................................60
Pointer...............................................................................................................................64
Identifier............................................................................................................................66
Uniqueness of Reference of Condition-name ......................................................................67
Function-identifier .............................................................................................................68
REFERENCE FORMAT...............................................................................................................69Configuration of a Line......................................................................................................69
Reference Format for Area A and Area B...................................... .....................................72
Blank Line.........................................................................................................................74
Comment Line...................................................................................................................74
Joining Lines .....................................................................................................................75
Debugging Line .................................................................................................................77
In-line Comment................................................................................................................78
Reference Format for Free Format......................................................................................79PROGRAM CONFIGURATION.....................................................................................................82
7/31/2019 3. Language Reference
14/1103
xiv COBOL85 Reference Manual
CHAPTER 2. COBOL MODULES........................................................................................85
NUCLEUS................................................................................................................................86
Transcription of Data.........................................................................................................89
Arithmetic Operation.........................................................................................................90
Optional Processing and Branching ...................................................................................91
Repetition Processing....... ..................................................................................................93
Table Handling ..................................................................................................................95Initialization of Data Items ..............................................................................................102
Character-string Handling ...............................................................................................102
Simple Input-Output ........................................................................................................ 104
Terminating a Program....................................................................................................105
Pointer Handling..............................................................................................................105
INPUT-OUTPUT FACILITY ......................................................................................................110
File Organization.............................................................................................................112
File Connector ................................................................................................................. 115Operation of Input-Output Statement ...............................................................................115
File Position Indicator...... ................................................................................................118
Volume Indicator............................................................................................................. 118
Sharing and Exclusion of Files.........................................................................................118
Locking a Record............................................................................................................. 120
I-O Status .......................................................................................................... ..............122
Record Format ................................................................................................................. 124
Record Area..................................................................................................................... 126Special Register ............................................................................................................... 126
INTER-PROGRAM COMMUNICATION MODULE .........................................................................127
Accessing and Returning to a Program.............................................................................129
Global Name and Local Name .........................................................................................130
External Attribute and Internal Attribute .........................................................................131
Common Attribute in a Program......................................................................................133
Initial State of Program.................................................................................................... 133
Passing a Parameter......................................................................................................... 135
Scope of Names ............................................................................................................... 136
Scope of the Name of a Program-name and Secondary Entry Name .................................139
Special Register ............................................................................................................... 140
SORT-MERGE MODULE .........................................................................................................141
Sorting Methods .............................................................................................................. 143
Merging Methods.............................................................................................................144
Input Procedure................................................................................................................144
Output Procedure............. ................................................................................................145
Sort-merge File................ ................................................................................................145
7/31/2019 3. Language Reference
15/1103
COBOL85 Reference Manual xv
Special Register ............................................................................................................... 146
SOURCE TEXT MANIPULATION MODULE ................................................................................147
Example of COPY Statement ...........................................................................................148
Example of REPLACE Statement ....................................................................................148
PRESENTATION FILE MODULE ...............................................................................................149
Destination Type..............................................................................................................151
Screen Form Descriptor ................................................................................................... 151
File Organization and Access Mode.................................................................................152
Operating Input-Output Statements..................................................................................152
I-O Status .......................................................................................................... ..............153
Special Register ............................................................................................................... 155
BUILT-IN FUNCTION MODULE................................................................................................157
SCREEN HANDLING MODULE.................................................................................................159
Screen and Screen Item...................................................................................... ..............160
Input-Output Handling of the Screen................................................................................163Screen Input Status .......................................................................................................... 163
OPERATION MODULE FOR COMMAND LINE ARGUMENT AND ENVIRONMENT VARIABLE ...........164
Operating a Command Line Argument ............................................................................165
Operating an Environment Variable.................................................................................168
REPORT WRITER MODULE.....................................................................................................170
CHAPTER 3. IDENTIFICATION DIVISION AND END PROGRAM HEADER............. 175
IDENTIFICATION DIVISION.....................................................................................................176Program Name Paragraph................................................................................................177
END PROGRAM HEADER........................................................................................................179
CHAPTER 4. ENVIRONMENT DIVISION ........................................................................181
CONFIGURATION OF ENVIRONMENT DIVISION ........................................................................182
CONFIGURATION SECTION.....................................................................................................182
Source Computer Paragraph.............................................................................................183
Object Computer Paragraph .............................................................................................184Special Names Paragraph................................................................................................. 187
INPUT-OUTPUT SECTION .......................................................................................................213
File Control Paragraph..................................................................................................... 213
I-O-Control Paragraph.....................................................................................................260
CHAPTER 5. DATA DIVISION...........................................................................................269
DATA DIVISION CONFIGURATION...........................................................................................270
Based-storage Section ...................................................................................................... 271File Section...................... ................................................................................................271
7/31/2019 3. Language Reference
16/1103
xvi COBOL85 Reference Manual
Working-storage Section................................................................ ..................................272
Constant Section.............................................................................................................. 272
Linkage Section ............................................................................................................... 273
Report Section ................................................................................................................. 273
Screen Section ................................................................................................................. 274
77-level Description Entry ...............................................................................................274
Record Description Entry................................................................................................. 275
FILE DESCRIPTION ENTRY .....................................................................................................276
BLOCK CONTAINS Clause (Sequential File, Relative File, Indexed File, and Record
Writer Module) ......................................................................................................... 278
CODE-SET Clause (Sequential File and Report Writer Module)......................................279
CONTROL RECORDS Clause (Sequential File)..............................................................280
DATA RECORDS Clause (Sequential File, Relative File, and Indexed File)....................281
EXTERNAL Clause (Sequential File, Relative File, Indexed File, Presentation File, and
Report Writer Module)..............................................................................................282
GLOBAL Clause (Sequential File, Relative File, Indexed File, Presentation File, and Report
Writer Module) ......................................................................................................... 283
LABEL RECORDS Clause (Sequential File, Relative File, Indexed File, and Report Writer
File) ............................................................................................................ ..............284
LINAGE Clause (Sequential File) ....................................................................................285
Record Clause (Sequential File, Relative File, and Indexed File)......................................290
RECORD Clause (Presentation File)................................................................................295
RECORD Clause (Report Writer Module).......................................................... ..............296REPORT Clause (Report Writer Module).........................................................................296
VALUE OF Clause (Sequential File, Relative File, Indexed File, and Report Writer Module)298
SORT-MERGE FILE DESCRIPTION ENTRY................................................................................299
DATA DESCRIPTION ENTRY...................................................................................................300
Notes on Data Description Entries in the Based-storage Section.......................................303
Notes on Record Description Entries in the File Section...................................................304
Notes on Data Description Entries in the Working-storage Section ..................................304
Notes on Data Description Entries in the Constant Section...............................................305Notes on Data Description Entries in the Linkage Section................................................305
BLANK WHEN ZERO Clause.........................................................................................305
CHARACTER TYPE Clause ...........................................................................................307
EXTERNAL Clause.........................................................................................................315
GLOBAL Clause..............................................................................................................317
JUSTIFIED Clause .......................................................................................................... 318
OCCURS Clause..............................................................................................................319
PICTURE Clause............. ................................................................................................325PRINTING POSITION Clause......................................................................................... 346
7/31/2019 3. Language Reference
17/1103
COBOL85 Reference Manual xvii
REDEFINES Clause ........................................................................................................ 348
RENAMES Clause...........................................................................................................351
SIGN Clause.................................................................................................................... 353
SYNCHRONIZED Clause ...............................................................................................356
USAGE Clause................................................................................................................ 358
VALUE Clause................ ................................................................................................368
BASED ON Clause.......................................................................................................... 372
SCREEN DATA DESCRIPTION ENTRY ......................................................................................374
AUTO Clause .................................................................................................................. 379
BACKGROUND-COLOR Clause ....................................................................................380
BELL Clause ................................................................................................................... 381
BLANK LINE Clause ...................................................................................................... 382
BLANK SCREEN Clause ................................................................................................383
BLANK WHEN ZERO Clause.........................................................................................384
BLINK Clause ................................................................................................................. 385
COLUMN NUMBER Clause ...........................................................................................386
ERASE Clause.................................................................................................................388
FOREGROUND-COLOR Clause.....................................................................................389
FULL Clause ................................................................................................................... 391
HIGHLIGHT Clause ........................................................................................................ 393
JUSTIFIED Clause .......................................................................................................... 394
LINE NUMBER Clause................................................................................................... 395
LOWLIGHT Clause...................................................................... ...................................397PICTURE Clause............. ................................................................................................398
REQUIRED Clause..........................................................................................................401
REVERSE-VIDEO Clause................................................................................. ..............402
SECURE Clause .............................................................................................................. 403
SIGN Clause.................................................................................................................... 404
UNDERLINE Clause ....................................................................................................... 405
USAGE Clause................................................................................................................ 405
VALUE Clause................ ................................................................................................407REPORT DESCRIPTION ENTRY................................................................................................408
CODE Clause .................................................................................................................. 411
CONTROL Clause.................................................... .......................................................412
PAGE Clause................................................................................................................... 414
Page Area .......................................................................................................... ..............418
REPORT GROUP DESCRIPTION ENTRY ....................................................................................420
CHARACTER TYPE Clause ...........................................................................................425
COLUMN NUMBER Clause ...........................................................................................427GROUP INDICATE Clause.............................................................................................428
7/31/2019 3. Language Reference
18/1103
xviii COBOL85 Reference Manual
LINE NUMBER Clause................................................................................................... 430
NEXT GROUP Clause..................................................................................................... 432
PRINTING POSITION Clause......................................................................................... 434
SIGN Clause.................................................................................................................... 435
SOURCE Clause.............................................................................................................. 437
SUM Clause.....................................................................................................................438
TYPE Clause ................................................................................................................... 444
USAGE Clause................................................................................................................ 453
VALUE Clause................ ................................................................................................454
REPORT GROUP PRESENTATION RULES ..................................................................................456
How to Use Presentation Rule Tables ...............................................................................456
Reading Applicable Rule Column ....................................................................................457
LINE NUMBER Clause Notation.................................................. ...................................459
NEXT GROUP Clause Notation.......................................................................................460
Integer Saving Item for Next Report Group...................................................................... 460
Report Heading Group Presentation Rules........................................................................461
Page Heading Group Presentation Rules...........................................................................464
Body Group Presentation Rules..................................................... ...................................466
Page Footing Group Presentation Rules............................................................................473
Report Footing Group Presentation Rule ..........................................................................475
CHAPTER 6. PROCEDURE DIVISION..............................................................................479
PROCEDURE DIVISION STRUCTURE ........................................................................................480Section.............................................................................................................................481
Paragraph .......................................................................................................... ..............481
Statement.........................................................................................................................482
Sentence ............................................................................................................ ..............485
Scope of Statements ......................................................................................................... 486
PROCEDURE DIVISION HEADER..............................................................................................488
Syntax Rule ....................................................................................................... ..............488
General Rules .................................................................................................................. 489COMMON STATEMENT RULES ................................................................................................491
Arithmetic Expressions.... ................................................................................................491
Boolean Expression..........................................................................................................495
Conditional Expression.... ................................................................................................498
Comparison Rules............ ................................................................................................515
Rules for Copying ............................................................................................................ 523
Arithmetic Statement....... ................................................................................................529
More Than One Answer of an Arithmetic Statement........................................................530ROUNDED Phrase .......................................................................................................... 531
7/31/2019 3. Language Reference
19/1103
COBOL85 Reference Manual xix
ON SIZE ERROR Phrase................................................................................... ..............532
CORRESPONDING Phrase .............................................................................................534
Overlapping of Operands ................................................................................................. 535
INVALID KEY Phrase .................................................................................................... 536
AT END Phrase...............................................................................................................539
STATEMENTS ........................................................................................................................542
ACCEPT Statement (Nucleus) .........................................................................................542
ACCEPT Statement (Screen Operation)...........................................................................546
ACCEPT Statement (Operation on Command Line Arguments and Environmental
Variables) ................................................................................................................. 549
ADD Statement (Nucleus)................................................................................................552
ALTER Statement (Nucleus)............................................................................................555
CALL Statement (Inter-program Communication)......................... ..................................556
CANCEL Statement (Inter-program Communication)......................................................565
CLOSE Statement (Sequential, Relative, Indexed, and Presentation Files, and Report Writer
Module) .................................................................................................................... 567
COMPUTE Statement (Nucleus).................................................... ..................................574
CONTINUE Statement (Nucleus) ....................................................................................576
DELETE Statement (Relative and Indexed Files).............................................................577
DISPLAY Statement (Nucleus)........................................................................................580
DISPLAY Statement (Screen Operation)..........................................................................584
DISPLAY Statement (Operation on Command Line Arguments and Environmental
Variables) ................................................................................................................. 586DIVIDE Statement (Nucleus)...........................................................................................589
ENTRY Statement (Inter-program Communication) ........................................................594
EVALUATE Statement (Nucleus).................................................................................... 595
EXIT Statement (Nucleus)...............................................................................................604
EXIT PERFORM Statement (Nucleus).............................................................................605
EXIT PROGRAM Statement (Inter-program Communication) ........................................606
GENERATE Statement (Report writing)..........................................................................607
GO TO Statement (Nucleus) ............................................................................................611IF Statement (Nucleus) .................................................................................................... 612
INITIALIZE Statement (Nucleus)......... ...........................................................................617
INITIATE Statement (Report writer) ...............................................................................621
INSPECT Statement ........................................................................................................ 622
MERGE Statement (Sort-merge)........................................................................ ..............638
MOVE Statement (Nucleus).............................................................................................648
MULTIPLY Statement (Nucleus).......... ...........................................................................651
OPEN Statement (Sequential File, Relative File, Indexed File).........................................653OPEN Statement (Presentation File) ................................................................................662
7/31/2019 3. Language Reference
20/1103
xx COBOL85 Reference Manual
OPEN Statement (Report Writer)....................................................................... ..............664
PERFORM Statement (Nucleus) ......................................................................................665
READ Statement (Sequential File, Relative File, Indexed File) ........................................ 682
READ Statement (Presentation File)................................................................................698
RELEASE Statement (Sort-merge) ..................................................................................701
RETURN Statement (Sort-merge)....................................................................................703
REWRITE Statement (Sequential File, Relative File, Indexed File)..................................706
SEARCH Statement (Nucleus).................................. .......................................................714
SET Statement (Nucleus)................................................................................................. 724
SORT Statement (Sort-merge) .........................................................................................728
START Statement (Relative File)................................................... ..................................739
START Statement (Indexed File) .....................................................................................742
STOP Statement (Nucleus)...............................................................................................752
STRING Statement (Nucleus) ..........................................................................................753
SUBTRACT Statement (Nucleus) ....................................................................................760
SUPPRESS Statement (Report Writer).......................................... ...................................763
TERMINATE Statement (Report Writer)........................................................... ..............764
UNLOCK Statement (Sequential File, Relative File, Indexed File)...................................766
UNSTRING Statement (Nucleus).......... ...........................................................................767
USE Statement (Creation of Sequential Files, Relative Files, Indexed Files, Presentation
Files, and Reports) .................................................................................................... 782
USE BEFORE REPORTING Statement (Creation of Reports) .........................................786
USE FOR DEAD-LOCK Statement (Presentation File)....................................................788WRITE Statement (Sequential File).................................................................................790
WRITE Statement (Relative and Indexed Files) ...............................................................803
WRITE Statement (Presentation File) ..............................................................................810
GENERAL RULES FOR FUNCTIONS ..........................................................................................812
Function Call Format ....................................................................................................... 812
Types of Arguments......................................................................................................... 813
Rules Applied for Specifying a Table as Argument ..........................................................814
Function Types ................................................................................................................ 815FUNCTIONS...........................................................................................................................817
ACOS Function ............................................................................................................... 817
ADDR Function............................................................................................................... 818
ANNUITY Function ........................................................................................................ 819
ASIN Function.................................................................................................................820
ATAN Function...............................................................................................................821
CAST-ALPHANUMERIC Function.................................................................................821
CHAR Function............................................................................................................... 822COS Function .................................................................................................................. 823
7/31/2019 3. Language Reference
21/1103
COBOL85 Reference Manual xxi
CURRENT-DATE Function ............................................................................................824
DATE-OF-INTEGER Function........................................................................................825
DAY-OF-INTEGER Function..........................................................................................826
FACTORIAL Function .................................................................................................... 827
INTEGER Function ......................................................................................................... 828
INTEGER-OF-DATE Function........................................................................................829
INTEGER-OF-DAY Function..........................................................................................830
INTEGER-PART Function ..............................................................................................831
LENG Function ............................................................................................................... 832
LENGTH Function .......................................................................................................... 832
LOG Function..................................................................................................................834
LOG10 Function.............................................................................................................. 834
LOWER-CASE Function................................................................................................. 835
MAX Function.................................................................................................................836
MEAN Function .............................................................................................................. 837
MEDIAN Function .......................................................................................................... 837
MIDRANGE Function..................................................................................................... 838
MIN Function .................................................................................................................. 839
MOD Function.................................................................................................................840
NATIONAL Function...................................................................................................... 841
NUMVAL Function......................................................................................................... 842
NUMVAL-C Function ..................................................................................................... 843
ORD Function..................................................................................................................845
ORD-MAX Function ....................................................................................................... 846
PRESENT-VALUE Function...........................................................................................848
RANDOM Function.........................................................................................................848
RANGE Function ............................................................................................................ 850
REM Function ................................................................................................................. 851
REVERSE Function.........................................................................................................852
SIN Function ................................................................................................................... 853
SQRT Function................ ................................................................................................854STANDARD-DEVIATION Function...............................................................................854
SUM Function ................................................................................................................. 855
TAN Function..................................................................................................................856
UPPER-CASE Function................................................................................................... 857
VARIANCE Function...................................................................................................... 858
WHEN-COMPLIED Function..........................................................................................858
CHAPTER 7. SOURCE TEXT MANIPULATION .............................................................861
TEXT....................................................................................................................................862
7/31/2019 3. Language Reference
22/1103
xxii COBOL85 Reference Manual
TEXT WORD .........................................................................................................................862
PSEUDO-TEXT.......................................................................................................................862
COPY STATEMENT ..............................................................................................................863
Syntax Rules.................................................................................................................... 864
General Rules .................................................................................................................. 866
REPLACE STATEMENT........................................................................................................874
Syntax Rules.................................................................................................................... 874
General Rules .................................................................................................................. 875
CHAPTER 8. DATABASE (SQL) .......................................................................................879
DATABASE ...........................................................................................................................880
TABLE..................................................................................................................................880
EMBEDDED SQL...................................................................................................................880
HOST VARIABLE ...................................................................................................................881
REFERENCE FORMAT OF EMBEDDED SQL ..............................................................................881
Overall Rules................................................................................................................... 881
Continuation of Line........................................................................................................ 881
COBOL Comment Line and In-line Comment .................................................................882
DATA DIVISION ....................................................................................................................882
Embedded SQL Declare Section....................................................................................... 882
Host Variable Definitions................................................................................................. 883
Referencing Host Variables..............................................................................................886
SQLSTATE/SQLCODE................................................................................................... 886
SQLMSG.........................................................................................................................887
PROCEDURE DIVISION ...........................................................................................................887
Character.........................................................................................................................888
Literals .............................................................................................................. ..............889
Token ................................................................................................................ ..............893
Names..............................................................................................................................895
Value Specification and Target Specification ...................................................................896
Column Specification.......................................................................................................898Set Function Specification................................................................................................ 899
Value Expression............................................................................................................. 900
Predicate..........................................................................................................................901
Search Condition ............................................................................................................. 906
Table Expression ............................................................................................................. 907
Query Specification............................................................................................ ..............909
Query Expression...................................................... .......................................................910
Subquery..........................................................................................................................910EMBEDDED EXCEPTION DECLARATION ..................................................................................911
7/31/2019 3. Language Reference
23/1103
COBOL85 Reference Manual xxiii
DATA MANIPULATION WITHOUT USING CURSOR ....................................................................912
SELECT Statement..........................................................................................................912
DELETE Statement (Searched)........................................................................................913
INSERT Statement .......................................................................................................... 914
UPDATE Statement (Searched) .......................................................................................915
DATA MANIPULATION USING THE CURSOR.............................................................................918
Declare Cursor................. ................................................................................................918
OPEN Statement.............. ................................................................................................921
CLOSE Statement............................................................................................................921
FETCH Statement............................................................................................................922
DELETE Statement (Positioned)........................................................................ ..............923
UPDATE Statement (Positioned) .....................................................................................924
DYNAMIC SQL....................................................................................................... ..............926
INTO Clause / USING Clause..........................................................................................926
PREPARE Statement ....................................................................................................... 926
EXECUTE Statement ...................................................................................................... 927
EXECUTE IMMEDIATE Statement................................................................................929
Dynamic SELECT Statement................ ...........................................................................930
Dynamic Declare Cursor.................................................................................................. 930
Dynamic OPEN Statement ...............................................................................................931
Dynamic CLOSE Statement.................. ...........................................................................932
Dynamic FETCH Statement.................. ...........................................................................933
Dynamic DELETE Statement (Positioned)......................................................... ..............934
Dynamic UPDATE Statement (Positioned) ......................................................................935
TRANSACTION MANAGEMENT ...............................................................................................936
COMMIT Statement........ ................................................................................................936
ROLLBACK Statement....................................................................................................936
CONNECTION MANAGEMENT.................................................................................................937
CONNECT Statement......................................................................................................937
SET CONNECTION Statement .......................................................................................939
DISCONNECT Statement................................................................................................ 940CHAPTER 9. COMMUNICATION DATABASE ...............................................................943
GENERAL OVERVIEW ............................................................................................................944
Communication Database ................................................................................................945
Services ............................................................................................................. ..............945
Tables..............................................................................................................................945
Embedded DCSQL...........................................................................................................946
Host Variable................... ................................................................................................946BASIC ELEMENTS OF EMBEDDED DCSQL ..............................................................................947
7/31/2019 3. Language Reference
24/1103
xxiv COBOL85 Reference Manual
Available Characters........ ................................................................................................947
Quotation Marks, Key Words, and Separators ..................................................................948
Communication Database Names.....................................................................................949
Service Names ................................................................................................................. 949
Table Names.................................................................................................................... 949
Host Variable Names ....................................................................................................... 950
Literals .............................................................................................................. ..............950
REFERENCE FORMAT OF EMBEDDED DCSQL.........................................................................954
Overall Rules for Description.................................... .......................................................954
Continuation of Line........................................................................................................ 954
COBOL Comment Line and In-line Comment .................................................................954
Comments in Embedded DCSQL..................................................................................... 955
EMBEDDED DCSQL..............................................................................................................955
Data Division................................................................................................................... 955
Procedure Division...........................................................................................................960
CHAPTER 10. MICRO FOCUS NATIVE FUNCTIONS...................................................961
SCREEN FUNCTIONS ..............................................................................................................962
Environment Division...... ................................................................................................962
CONSOLE IS CRT CLAUSE.................................................................................................963
Data Division................................................................................................................... 964
COLUMN NUMBER CLAUSE..............................................................................................968
GRID CLAUSE......................................................................................................................968
LEFTLINE CLAUSE .............................................................................................................969
LINE NUMBER CLAUSE .....................................................................................................970
OCCURS CLAUSE................................................................................................................970
OVERLINE CLAUSE ............................................................................................................971
PROMPT CLAUSE................................................................................................................972
SIZE CLAUSE.......................................................................................................................973
ZERO-FILL CLAUSE............................................................................................................974
Procedure Division...........................................................................................................975NATIONAL FUNCTIONS..........................................................................................................986
Procedure Division...........................................................................................................986
INPUT-OUTPUT STATEMENT ..................................................................................................987
Procedure Division...........................................................................................................987
APPENDIX A. LIST OF RESERVED WORDS.................................................................1001
APPENDIX B. SYSTEM QUANTITATIVE RESTRICTIONS ........................................ 1017
REFERENCE FORMAT...........................................................................................................1017
7/31/2019 3. Language Reference
25/1103
COBOL85 Reference Manual xxv
NUCLEUS DATA DIVISION....................................................................................................1018
NUCLEUS PROCEDURE DIVISION ..........................................................................................1019
SEQUENTIAL FILE ...............................................................................................................1019
RELATIVE FILE ...................................................................................................................1020
INDEXED FILE.....................................................................................................................1020
INTER-PROGRAM COMMUNICATION .....................................................................................1021
SORT AND MERGE...............................................................................................................1021
SOURCE STATEMENT MANIPULATION ..................................................................................1022PRESENTATION FILE............................................................................................................1022
APPENDIX C. CODE TABLES ........................................................................................ 1023
INTERNAL CODES FOR EBCDIC CHARACTERS .....................................................................1024
INTERNAL CODES FOR ASCII CHARACTERS .........................................................................1025
INTERNAL CODES FOR JIS 8-BIT CODE CHARACTERS ...........................................................1026
APPENDIX D. INTERMEDIATE RESULTS................................................................... 1027
ATTRIBUTE AND PRECISION OF THE INTERMEDIATE RESULT..................................................1028
INTERMEDIATE RESULTS OF ARITHMETIC OPERATIONS.........................................................1029
Precision of the Intermediate Results of Arithmetic Operations Having Fixed Point Attribute1029
Determining the Reference Number of Digits in the Decimal-part..................................1030
Determining the Temporary Number of Arithmetic Operation Digits.............................1031
Determining Precision of the Intermediate Result of Arithmetic Operations ...................1036
Intermediate Result in Arithmetic Operations Having the Floating-point Attribute.........1039
INTERMEDIATE RESULT OF THE EXPONENT ..........................................................................1039
Intermediate Result of the Exponent Having Fixed-point Attribute.................................1039
When the Exponent is a Literal..................................................... .................................1040
When the Exponent is a Variable ................................................................................... 1040
Intermediate Result of the Exponent Having Floating-point Attribute.............................1041
ATTRIBUTES AND ACCURACY OF FUNCTION VALUES ............................................................1041
APPENDIX E. FUNCTIONAL DIFFERENCES................................................... ............ 1045
HANDLING OF NUMERIC VALUES .........................................................................................1045
PRESENTATION FILES ..........................................................................................................1045
Destination ........................................................................................................ ............1045
Combining Specifiable Clauses and Destinations ........................................................... 1045
USE FOR DEAD-LOCK Statement ............................................................................... 1046
INTER-PROGRAM COMMUNICATION.....................................................................................1046
STATEMENTS ......................................................................................................................1046
WRITE Statement (Sequential File)............................................................................... 1046DATABASE .........................................................................................................................1047
7/31/2019 3. Language Reference
26/1103
xxvi COBOL85 Reference Manual
COMMUNICATION DATABASE ..............................................................................................1047
QUANTITATIVE SYSTEM LIMITS ...........................................................................................1047
APPENDIX F. CONTROL RECORD FORMATS ........................................................... 1049
I CONTROL RECORD ...........................................................................................................1049
S CONTROL RECORDS .........................................................................................................1057
INDEX ..................................................................................................................... ............1059
7/31/2019 3. Language Reference
27/1103
COBOL85 Reference Manual xxvii
7/31/2019 3. Language Reference
28/1103
7/31/2019 3. Language Reference
29/1103
COBOL85 Reference Manual xiii
7/31/2019 3. Language Reference
30/1103
Chapter 1. General Rules
This chap ter explains the concepts of the COBOL language and
covers the general rules.
2 Chapter 1. General Rules
7/31/2019 3. Language Reference
31/1103
Characters and Character Sets
Though there are several types of character sets that can be used
on a compu ter. COBOL programs use specific character sets for
wr iting. These character sets are called COBOL character sets.
There are four typ es of COBOL character sets:
Alphabetic character set
Numeric character set
Special character set
National character set
Alphabetic Character Set
The alphabetic characters are listed below. Each alphabetic
character uses 1 byte of storage area.
Uppercase letters (26 letters from A to Z)
Lowercase letters (26 letters from a to z)
Space
Except in a n onnumeric literal, lowercase letters are equ ivalent to
their correspond ing upp ercase letters.
Numeric Character Set
There are ten nu meric characters: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Each numeric character uses a 1 byte storage area.
Chapter 1. General Rules 3
7/31/2019 3. Language Reference
32/1103
Special Character Set
The table below lists the special characters. Each special character
uses a 1 byte storage area.
Character Meaning
+ Plus sign
- Minus sign or hyphen
* Asterisk
/ Slash
= Equal sign
$ Dollar sign
, Comma
; Semicolon
. Period or decimal point
Quotation mark
( Left parenthesis
) Right parenthesis
> Greater-than sign
< Less-than sign: Colon
& Ampersand
4 Chapter 1. General Rules
7/31/2019 3. Language Reference
33/1103
National Characters
National characters are contained in the Japanese character set.
Each character in the character set is expressed by a tw o-byte
internal code.
Unless otherwise specified, alphabetic or numer ic characters do
not contain national characters.
Computer Character Set
Character sets used on a compu ter are called comp uter
character sets. The COBOL character sets make up a part of thecomp uter character set.
Characters from COBOL character sets and from other compu ter
character sets can be u sed in the following items:
Nonnu meric literal
National nonnu meric literal
Comment entry
Comm ent line
In-line commen t
Chapter 1. General Rules 5
7/31/2019 3. Language Reference
34/1103
Basic Overview of Language
A COBOL program is mad e up of separators, COBOL word s,
literals, character-strings in PICTURE clauses, comm ent entries,
comment lines, and in-line commen ts. The COBOL character sets
are used for wr iting all program elements except for the literal
values, comment entries, comment lines, and in-line comments.
These elements are written u sing characters from a comp uter
character set.
A COBOL prog ram can also contain a line consisting of all spaces
(blank line).
Separator
A separator is a character delimiting a character-string. Use any
of the following characters as a separator:
A sequence of one or more spaces. This is called a sep aratorspace.
A sequence of one comm a followed by one or m ore spaces.This is called a sep arator comma.
A sequen ce of one semicolon followed by one or m ore spaces.This is called a separator sem icolon.
A sequence of one p eriod followed by one or more sp aces.This is called a sep arator p eriod.
A left parenth esis
A right paren thesis
6 Chapter 1. General Rules
7/31/2019 3. Language Reference
35/1103
A qu otation m ark ind icating the start of a literal value (, X,NC, N, NX or B)
A qu otation m ark ind icating the end of the literal value
The == pseu do-text delimiter
A colon
The -> pointer qu alification sym bol
The & concatenation operator
Separator Space
The separator sp ace delimits a COBOL word , literal, or character
string in a PICTURE clause.
Separator Comma and Separator Semicolon
The separator comm a an d separator semicolon facilitate p rogram
reading. Either one can be used wh erever a separator space can
be used.
A separator sp ace can also be includ ed immed iately before or
after these separators.
Separator Period
A separator period ind icates the end of an identification d ivision
for a d ivision, section, or paragrap h or the end of a division,
section, paragrap h, entry, or sentence. A p eriod can only be
wr itten where indicated by . in [Format].
A separator sp ace can be includ ed imm ediately before or after a
period.
Chapter 1. General Rules 7
7/31/2019 3. Language Reference
36/1103
Left and Right Parentheses
Use left and right p aren theses to enclose a subscript, reference
mod ifier, arithmetic expression, Boolean expression, cond itional
expression, or argu ment list. Parentheses are always used in
pairs.
A separa tor space can be included imm ediately before or after
the left or right parenth esis.
Quotation Mark
Quotation m arks are u sed to enclose a non nu meric literal,
hexadecimal nonnumeric literal, National nonnumeric literal,National hexadecimal nonnu mer ic literal, or a character string
ind icating th e Boolean literal value.
Quotation marks are always u sed in pairs, one mark indicating
the start of a literal value and the other m ark ind icating the end
of the literal value. Rules for d escribing qu otation m arks are th e
following:
1. Enclose a non nu mer ic literal with a pa ir of quotation marks.
2. Enclose a hexadecimal nonnu meric literal with X and a
quotation m ark.
3. Enclose a National nonnu meric literal with NC and a
quotation mark or N and a quotation mark.
4. Enclose a National hexadecimal nonnu mer ic literal with NXand a quotation mark.
5. Enclose a Boolean literal with B and a quota tion mark.
8 Chapter 1. General Rules
7/31/2019 3. Language Reference
37/1103
In all cases a separator space or a left pa renth esis mu st
immed iately precede th e quotation m ark ind icating the start of a
literal value. Also, a separator space, separator comm a, separator
semicolon, separator p eriod , or right paren thesis must
immed iately follow the qu otation m ark ind icating the end of the
literal value.
Pseudo-text Delimiter
Pseud o-text delimiters enclose pseudo-text. They are u sed in
pairs. A separator space must immed iately precede the pseudo-
text delimiter indicating the start of pseud o-text. A separatorspace, separator comma, separator semicolon, or separator
period mu st immed iately follow the p seudo-text d elimiter
indicating the end of pseud o-text.
Colon
A colon is used to write a reference mod ifier. A separator sp acecan be includ ed immed iately before or after the colon.
Pointer Qualification Symbol
A pointer qualification sym bol is used to write a pointer
qualifier. A separator space can be included immed iately before
or after the colon.
Concatenation Operator
A concatenation operator is used to link a literal. A separator
space must be written immediately before and after the
concatenation operator.
Chapter 1. General Rules 9
7/31/2019 3. Language Reference
38/1103
Character-strings Not Regarded as Separators
The rules for separators do not apply to character-strings written
in the locations listed below. A character-string w ritten in any of
the following locations is not regard ed as a separator even if thecharacter-string has the same format as a separator:
Nu meric literal
A p ortion enclosed by a separator indicating the start of aliteral value and a separator ind icating the end of a literal
value in a nonn um eric literal, hexadecimal nonnu meric
literal, National nonnu meric literal, or Boolean literal
A character string in a PICTURE clause
A comm ent entry
A commen t line
An in-line comment
10 Chapter 1. General Rules
7/31/2019 3. Language Reference
39/1103
COBOL Word
A COBOL word is a single character string consisting of COBOL
character set characters. There are four types of COBOL words:
User-defined word s System-name
Reserved word
Function-name
Each COBOL word has its own restrictions in add ition to the
following general restrictions:1. A COBOL word must not exceed 30 characters in length.
2. A COBOL word m ust be made up of alphabetic characters (A
to Z an d a to z), numeric characters (0 to 9), or hyp hens (-). It
mu st not contain any spaces. Lowercase letters are regarded
as being equivalent to their correspond ing upp ercase letters.
A user-defined word may consist of national characters.3. A hyphen mu st not be used as the first or last character of a
COBOL word .
Chapter 1. General Rules 11
7/31/2019 3. Language Reference
40/1103
User-defined Words
A user-defined w ord is any of the following 19 words named by
the user:
Positioning u nit nam e
Print mod e name
Symbolic-constant
Symbolic-character
Text-name
Index-name
Class-name
Condition-name
Section-name
Paragraph-name
Data-name
Library-name
File-name
Alphabet-name
Program-name
Report-name
Mnemonic-name
Record-name
Level-number
12 Chapter 1. General Rules
7/31/2019 3. Language Reference
41/1103
The names of all user-defined w ord s except the level-num ber
mu st be un ique. How ever, the cond ition-name, data-name,
record-nam e, and index-nam e may be the same provided the
qualifiers allow reference un iqueness. The same level-nu mber
can be w ritten m