5 ENVIRONMENT DIVISION
ENVIRONMENT DIVISION Syntax
ENVIRONMENT DIVISION.
~~~~~~~~~~~ ~~~~~~~~
[ CONFIGURATION SECTION. ]
~~~~~~~~~~~~~ ~~~~~~~~
[ SOURCE-COMPUTER. Compilation-Computer-Specification . ]
~~~~~~~~~~~~~~~
[ OBJECT-COMPUTER. Execution-Computer-Specification . ]
~~~~~~~~~~~~~~~
[ SPECIAL-NAMES. Program-Configuration-Specification . ]
~~~~~~~~~~~~~
[ REPOSITORY. Function-Specification... . ]
~~~~~~~~~~
[ INPUT-OUTPUT SECTION. ]
~~~~~~~~~~~~ ~~~~~~~
[ FILE-CONTROL. General-File-Description... . ]
~~~~~~~~~~~~
[ I-O-CONTROL. File-Buffering Specification... . ]
~~~~~~~~~~~
This division defines the external computer environment in which the program will be operating. This includes defining any files that the program may be .
If both optional sections of this division are coded, they must be coded in the sequence shown.
The paragraphs within the sections may be coded in any order.
These sections consist of a series of specific, pre-defined, paragraphs (
SOURCE-COMPUTERandOBJECT-COMPUTER, for example), each of which serves a specific purpose. If no code is required for the purpose one of the paragraphs serves, the entire paragraph may be omitted.If any of the paragraphs within one of the sections are coded, the section header itself must be coded.
If none of the paragraphs within one of the sections are coded, the section header itself may be omitted.
If none of the sections within the environment division are coded, the
ENVIRONMENT DIVISION.header itself may be omitted.
5.1 CONFIGURATION SECTION
CONFIGURATION SECTION Syntax
CONFIGURATION SECTION.
~~~~~~~~~~~~~ ~~~~~~~
[ SOURCE-COMPUTER. Compilation-Computer-Specification . ]
~~~~~~~~~~~~~~~
[ OBJECT-COMPUTER. Execution-Computer-Specification . ]
~~~~~~~~~~~~~~~
[ SPECIAL-NAMES. Program-Configuration-Specification . ]
~~~~~~~~~~~~~
[ REPOSITORY. Function-Specification... . ]
~~~~~~~~~~
This section defines the computer system upon which the program is being compiled and executed and also specifies any special environmental configuration or compatibility characteristics.
The four paragraphs in this section may be specified in any order but if not in this order, a warning will be issued.
The configuration section is not allowed in a nested subprogram. A nested program inherits the configuration section settings of its parent program.
If none of the features provided by the configuration section are required by a program, the entire
CONFIGURATION SECTION.header may be omitted from the program.
5.1.1 SOURCE-COMPUTER
SOURCE-COMPUTER Syntax
SOURCE-COMPUTER. computer-name [ WITH DEBUGGING MODE ] .
~~~~~~~~~~~~~~~ ~~~~~~~~~ ~~~~
This paragraph defines the computer upon which the program is being compiled and provides one way in which debugging code embedded within the program may be activated.
The reserved word
WITHis optional and may be omitted. The presence or absence of this word has no effect upon the program.This paragraph is not allowed in a nested subprogram. A nested program inherits the
SOURCE-COMPUTERsettings of its parent program.The value specified for <computer-name> is irrelevant, provided it is a valid COBOL word that does not match any GnuCOBOL reserved word. The <computer-name> value may include spaces. This need not match the <computer-name> used with the
OBJECT-COMPUTERparagraph, if any.The
DEBUGGING MODEclause, if present, will inform the compiler that debugging lines (those with a ‘D‘ in column 7 if Fixed Source Mode is in effect, or those prefixed with a>>Dif Free Source Mode is in effect) — normally treated as comments — are to be compiled.Even without the
DEBUGGING MODEclause, it is still possible to compile debugging lines. Debugging lines may also be compiled by specifying the-fdebugging-lineswitch to the GnuCOBOL compiler.
5.1.2 OBJECT-COMPUTER
OBJECT-COMPUTER Syntax
OBJECT-COMPUTER. [ computer-name ]
~~~~~~~~~~~~~~~
[ MEMORY SIZE IS integer-1 WORDS|CHARACTERS ]
~~~~~~ ~~~~ ~~~~~ ~~~~~~~~~~
[ PROGRAM COLLATING SEQUENCE IS alphabet-name-1 ]
~~~~~~~~~
[ SEGMENT-LIMIT IS integer-2 ]
~~~~~~~~~~~~~
[ CHARACTER CLASSIFICATION IS { locale-name-1 } ]
~~~~~~~~~~~~~~ { LOCALE }
{ ~~~~~~ }
{ USER-DEFAULT }
{ ~~~~~~~~~~~~ }
{ SYSTEM-DEFAULT }
~~~~~~~~~~~~~~
.
The
MEMORY SIZE and
SEGMENT-LIMITclauses are syntactically recognized but are otherwise non-functional.
This paragraph describes the computer upon which the program will execute.
The <computer-name>, if specified, must immediately follow the
OBJECT-COMPUTERparagraph name. The remaining clauses may be coded in any sequence.The reserved words
CHARACTER,IS,PROGRAMandSEQUENCEare optional and may be omitted. The presence or absence of these words has no effect on the program.The value specified for <computer-name>, if any, is irrelevant provided it is a valid COBOL word that does not match any GnuCOBOL reserved word. The <computer-name> may include spaces. This need not match the <computer-name> used with the
SOURCE-COMPUTERparagraph, if any.The
OBJECT-COMPUTERparagraph is not allowed in a nested subprogram. A nested program inherits theOBJECT-COMPUTERsettings of its parent program.The
COLLATING SEQUENCEclause allows you to specify a customized character collating sequence to be used when alphanumeric values are compared to one another. Data will still be stored in the character set native to the computer, but the logical sequence in which characters are ordered for comparison purposes can be altered from that defined by the computer’s native character set. The <alphabet-name-1> you specify needs to be defined in theSPECIAL-NAMES( 5.1.3 SPECIAL-NAMES) paragraph.If no
COLLATING SEQUENCEclause is specified, the collating sequence implied by the character set native to the computer (usually ASCII) will be used.The optional
CLASSIFICATIONclause may be used to specify a locale for the environment in which the program will execute, for the purpose of influencing the upper-case and lower-case mappings of characters for theUPPER-CASE( 8.1.101 UPPER-CASE) andLOWER-CASE( 8.1.51 LOWER-CASE) intrinsic functions and the classification of characters for theALPHABETIC,ALPHABETIC-LOWERandALPHABETIC-UPPERclass tests. The definitions of these classes is taken from the cultural convention specification (LC_CTYPE) from the specified locale.The meanings of the four locale specifications are as follows:
<locale-name-1> references a
LOCALE( 5.1.3 SPECIAL-NAMES) definition.The keyword
LOCALErefers to the current locale (in effect at the time the program is executed)The keyword
USER-DEFAULTreferences the default locale specified for the user currently executing this program.The keyword
SYSTEM-DEFAULTdenotes the default locale specified for the computer upon which the program is executing.
Absence of a
CLASSIFICATIONclause will cause character classification to occur according to the rules for the computer’s native character set (ASCII, EBCDIC, etc.).
5.1.3 SPECIAL-NAMES
SPECIAL-NAMES Syntax
SPECIAL-NAMES.
~~~~~~~~~~~~~
[ CALL-CONVENTION integer-1 IS mnemonic-name-1 ]
~~~~~~~~~~~~~~~
[ CONSOLE IS CRT ]
~~~~~~~ ~~~
[ CRT STATUS IS identifier-1 ]
~~~ ~~~~~~
[ CURRENCY SIGN IS literal-1 ]
~~~~~~~~ ~~~~
[ CURSOR IS identifier-2 ]
~~~~~~
[ DECIMAL-POINT IS COMMA ]
~~~~~~~~~~~~~ ~~~~~
[ EVENT STATUS IS identifier-3 ]
~~~~~ ~~~~~~
[ LOCALE locale-name-1 IS literal-2 ]...
~~~~~~
[ NUMERIC SIGN IS TRAILING SEPARATE ]
~~~~~~~ ~~~~ ~~~~~~~~ ~~~~~~~~
[ SCREEN CONTROL IS identifier-4 ]
~~~~~~ ~~~~~~~
[ device-name-1 IS mnemonic-name-2 ]...
[ feature-name-1 IS mnemonic-name-3 ]...
[ Alphabet-Clause ]...
[ Class-Definition-Clause ]...
[ Switch-Definition-Clause ]...
[ Symbolic-Characters-Clause ]...
.
The
EVENT STATUS and
SCREEN CONTROLclauses are syntactically recognized but are otherwise non-functional.
<Alphabet-Name-Clause>, <Class-Definition-Clause>,
<Switch-Definition-Clause> and <Symbolic-Characters-Clause>
are discussed in detail in the next four sections.
The SPECIAL-NAMES paragraph provides a means for specifying various program and operating environment configuration options.
The various clauses that may be specified within the
SPECIAL-NAMESparagraph may be coded in any order.The reserved word
ISis optional and may be omitted. The presence or absence of this word has no effect upon the program.The
SPECIAL-NAMESparagraph is not allowed in a nested subprogram. A nested program inherits theSPECIAL-NAMESsettings of its parent program.Only the final clause specified within this paragraph should be terminated with a period.
The
CALL-CONVENTIONclause allows a decimal integer, representing a series of ON/OFF switch settings, to be associated with a mnemonic name which may then be coded on aCALLstatement ( 7.8.5 CALL). The switch settings defined by this mnemonic will then control how the linkage to a subroutine invoked by theCALLstatement that references <mnemonic-name-1> will be handled.The
CONSOLE IS CRTclause, if specified, will cause aDISPLAYstatement lacking an explicitUPONclause to be treated as aDISPLAY data-itemstatement ( 7.8.12.4 DISPLAY data-item), and anyACCEPTstatement lacking aFROMclause to be treated as aACCEPT data-itemstatement ( 7.8.1.4 ACCEPT data-item).If the
CRT STATUSclause is not specified, an implicitCOB-CRT-STATUSidentifier (with aPICTURE 9(4)) will be allocated for the purpose of receiving screenACCEPTstatuses. IfCRT STATUSis specified, then <identifier-1> must be defined in the program as aPICTURE 9(4)field.The
CURRENCY SIGNclause may be used to redefine the character to be used as a currency sign in aPICTURE( 6.9.37 PICTURE) clause. The default currency sign is a dollar-sign (’$‘). You may specify any character except0-9,A-Z,a-z,+,-,,,.,*,/,;,(,),=,\, quote (’"‘) or space.The
CURSOR ISclause allows you to specify a 4- or 6-character data item into which the cursor screen location at the time a screenACCEPTis satisfied. The value will be returned as rrcc or rrrccc, depending upon the length of the specified <identifier-2>, where rr and rrr represent the row number (starting at zero) and cc and ccc represent the column number (also starting at zero). There is no default data item allocated for this data if theCURSOR ISclause is not specified, and it is the programmer’s responsibility to define <identifier-2> if the clause is specified.The
DECIMAL POINT IS COMMAclause reverses the definition of the ‘,‘ and ‘.‘ characters when they are used asPICTUREediting symbols and within numeric literals. This can have unwanted side-effects - see 2.1.20 Punctuation.The
LOCALEclause may be used to associate external OS-defined locale names (<literal-2>) with an internal name (<locale-name-1>) that may then be referenced within the program. Locale names are defined by the Operating System and/or C compiler GnuCOBOL will be utilizing on your computer.The following is the list of possible locale codes, for example, that would be available on a Windows computer running a GnuCOBOL version that was built utilizing the MinGW Unix-emulator and the GNU C compiler (gcc):
A
af_ZA, am_ET, ar_AE, ar_BH, ar_DZ, ar_EG, ar_IQ, ar_JO, ar_KW, ar_LB, ar_LY, ar_MA, ar_OM, ar_QA, ar_SA, ar_SY, ar_TN, ar_YE, arn_CL, as_IN, az_Cyrl_AZ, az_Latn_AZ
B
ba_R, be_BY, bg_BG, bn_IN bo_BT, bo_CN, br_FR, bs_Cyrl_BA, bs_Latn_BA
C
ca_ES, cs_CZ, cy_GB
D
da_DK, de_AT, de_CH, de_DE, de_LI, de_LU, dsb_DE, dv_MV
E
el_GR, en_029, en_AU, en_BZ, en_CA, en_GB, en_IE, en_IN, en_JM, en_MY en_NZ, en_PH, en_SG, en_TT, en_US, en_ZA, en_ZW, es_AR, es_BO, es_CL, es_CO, es_CR, es_DO, es_EC, es_ES, es_GT, es_HN, es_MX, es_NI, es_PA, es_PE, es_PR, es_PY, es_SV, es_US, es_UY es_VE, et_EE, eu_ES
F
fa_IR, fi_FI, fil_PH, fo_FO, fr_BE, fr_CA, fr_CH, fr_FR, fr_LU, fr_MC, fy_NL
G
ga_IE, gbz_AF, gl_ES, gsw_FR, gu_IN
H
ha_Latn_NG, he_IL, hi_IN, hr_BA, hr_HR, hu_HU, hy_AM
I
id_ID, ig_NG, ii_CN, is_IS, it_CH, it_IT, iu_Cans_CA, iu_Latn_CA
J
ja_JP
K
ka_GE, kh_KH, kk_KZ, kl_GL, kn_IN, ko_KR, kok_IN, ky_KG
L
lb_LU, lo_LA, lt_LT, lv_LV
M
mi_NZ, mk_MK, ml_IN, mn_Cyrl_MN, mn_Mong_CN moh_CA, mr_IN, ms_BN, ms_MY, mt_MT
N
nb_NO, ne_NP, nl_BE, nl_NL, nn_NO, ns_ZA
O
oc_FR, or_IN
P
pa_IN, pl_PL, ps_AF, pt_BR, pt_PT
Q
qut_GT, quz_BO, quz_EC, quz_PE
R
rm_CH, ro_RO, ru_RU, rw_RW
S
sa_IN, sah_RU, se_FI, se_NO se_SE, si_LK, sk_SK, sl_SI, sma_NO, sma_SE, smj_NO, smj_SE, smn_FI, sms_FI, sq_AL, sr_Cyrl_BA, sr_Cyrl_CS, sr_Latn_BA, sr_Latn_CS, sv_FI, sv_SE, sw_KE syr_SY
T
ta_IN, te_IN, tg_Cyrl_TJ, th_TH tk_TM, tmz_Latn_DZ, tn_ZA, tr_IN, tr_TR, tt_RU
U
ug_CN, uk_UA, ur_PK, uz_Cyrl_UZ, uz_Latn_UZ
V
vi_VN
W
wen_DE, wo_SN
X
xh_ZA
Y
yo_NG
Z
zh_CN, zh_HK, zh_MO, zh_SG, zh_TW, zu_ZA
The
NUMERIC SIGN TRAILING SEPARATEspecification causes all signed numericUSAGE DISPLAYdata items to be created as if theSIGN IS TRAILING SEPARATE CHARACTERclause was included in their definitions.The
<device-name-1> IS <mnemonic-name-2>clause allows you to specify an alternate name (<device-name-1>) for one of the built-in GnuCOBOL device name <mnemonic-name-2>. The list of device names built-into GnuCOBOL, and the physical device associated with that name, are as follows:CONSOLEThis is the (screen-mode) display of the PC or Unix system.
STDINSYSINSYSIPTThese devices (they are all synonymous) represent standard system input (pipe 0). On a PC or UNIX system, this is typically the keyboard. The contents of a file may be delivered to a GnuCOBOL program for access via one of these device names by adding the sequence ‘
0< filename‘ to the end of the programs execution command.PRINTERSTDOUTSYSLISTSYSLSTSYSOUTThese devices (they are all synonymous) represent standard system output (pipe 1). On a PC or UNIX system, this is typically the display. Output sent to one of these devices by a GnuCOBOL program can be sent to a file by adding the sequence ‘
1> filename‘ to the end of the programs execution command.STDERRSYSERRThese devices (they are synonymous) represent standard system error output (pipe 2). On a PC or UNIX system, this is typically the display. Output sent to one of these devices by a GnuCOBOL program can be sent to a file by adding the sequence ‘
2> filename‘ to the end of the programs execution command.
The
<feature-name-1> IS <mnemonic-name-3>clause allow for mnemonic names to be assigned to up to the 13 printer channel (i.e. vertical page positioning) position feature namesC<nn>(<nn>=01-12) andCSP. Once a channel position has been assigned a mnemonic name, statements of the formWRITE <record-name> AFTER ADVANCING <mnemonic-name-3>may be coded to write the specified print record at the channel position assigned to <mnemonic-name-3>.Printers supporting channel positioning are generally mainframe-type line printers. When writing to printers that do not support channel positioning, a formfeed will be issued to the printer.
The
CSPpositioning option stands for “No Spacing”. Testing on a MinGW build of GnuCOBOL shows that this too results in a formfeed being issued.
5.1.3.1 Alphabet-Name-Clause
SPECIAL-NAMES Alphabet-Clause Syntax
ALPHABET alphabet-name-1 IS { ASCII }
~~~~~~~~ { ~~~~~ }
{ EBCDIC }
{ ~~~~~~ }
{ NATIVE }
{ ~~~~~~ }
{ STANDARD-1 }
{ ~~~~~~~~~~ }
{ STANDARD-2 }
{ ~~~~~~~~~~ }
{ Literal-Clause... }
SPECIAL-NAMES ALPHABET Literal-Clause Syntax
literal-1 [ { THRU|THROUGH literal-2 } ]
{ ~~~~ ~~~~~~~ }
{ {ALSO literal-3}... }
~~~~
The
ALPHABET clause relates <alphabet-name-1> to a specified character code set or collating sequence, including one you define yourself using the <literal-1> option.
The reserved word
ISis optional and may be omitted. The presence or absence of this word has no effect upon the program.The reserved words
THRUandTHROUGHare interchangeable.GnuCOBOL considers
ASCII,STANDARD-1andSTANDARD-2to be interchangeable.NATIVEspecifies the system default character set.The following points apply to using the <literal-n> specifications to compose a custom character set:
The <literal-n> values are either integers or alphanumeric quoted characters. These represent a single character in the
NATIVEcharacter set, either by its actual text value (alphanumeric quoted character) or by ordinal position in theNATIVEcharacter set (integer),The sequence in which characters are defined in this clause specifies the relative order those characters should have when comparisons are made using this alphabet.
Character positions in this list do not affect the actual binary storage values used for the characters. Binary values will still be those of the
NATIVEcharacter set.You may specify any of the figurative constants
SPACE,SPACES,ZERO,ZEROS,ZEROES,QUOTE,QUOTES,HIGH-VALUE,HIGH-VALUES,LOW-VALUEorLOW-VALUESfor any of the <literal-1>, <literal-2> or <literal-3> specifications.
Once you have defined an alphabet name, that alphabet name may be used on specifications in
CODE-SET,COLLATING SEQUENCE, orSYMBOLIC CHARACTERSclauses elsewhere in the program.
5.1.3.2 Class-Definition-Clause
SPECIAL-NAMES Class-Definition-Clause Syntax
CLASS class-name-1 IS { literal-1 [ THRU|THROUGH literal-2 ] }...
~~~~~ ~~~~ ~~~~~~~
The reserved word
ISis optional and may be omitted. The presence or absence of this word has no effect upon the program.The reserved words
THRUandTHROUGHare interchangeable.Both <literal-1> and <literal-2> must be alphanumeric literals of length 1.
The literal(s) specified on this clause define the possible characters that may be found in a data item’s value in order to be considered part of the class.
For example, the following defines a class called
Hexadecimal, the definition of which specifies the only characters that may be present in an alphanumeric data item if that data item is to be part of theHexadecimalclass:CLASS Hexadecimal IS '0' THRU '9' 'A' THRU 'F' 'a' THRU 'f'
Once class
Hexadecimalhas been defined, program code could then use a statement such asIF input-item IS Hexadecimalto determine if the value of characters in a data item are valid according to that class.
5.1.3.3 Switch-Definition-Clause
SPECIAL-NAMES Switch-Definition-Clause Syntax
switch-name-1 [ IS mnemonic-name-1 ]
[ ON STATUS IS condition-name-1 ]
~~
[ OFF STATUS IS condition-name-2 ]
~~~
The switch-definition clause associates a condition-name with a run-time execution switch so that the status of that switch may be tested from within a program.
The reserved words
ISandSTATUSare optional and may be omitted. The presence or absence of these words has no effect upon the program.The valid <switch-name-1> names are
SWITCH-n(<n>= 0-36).If the program is compiled with the
-fsyntax-extensionswitch, the switch namesSWn(<n>= 0-15) are also valid; they correspond toSWITCH-0throughSWITCH-15, respectively as well asSWITCH-16throughSWITCH-36,SWITCH 0throughSWITCH 26andSWITCH AthroughSWITCH Z.At execution time, each switch will be associated with a run-time environment variable, where
<n>will have the value ‘0‘ through ‘15‘. Any of these sixteen environment variables that have the valueON(regardless of upper- or lower-case value) will be considered to be set “on”. Any of these sixteen environment variables having no value at all or a value other thanONwill be consideredOFF.Each specified switch must have at least one of a
IS <mnemonic-name-1>,ON STATUSor anOFF STATUSoption defined for it, otherwise there will be no way to reference the switch from within a GnuCOBOL program.The
IS <mnemonic-name-1>syntax provides a means for setting the switch to either anONorOFFvalue via theSETstatement ( 7.8.41 SET).The
ON STATUSandOFF STATUSsyntax provides a way of associating a condition-name with either the on or off status of the switch, so that status may be tested at execution time via theIFstatement ( 7.8.23 IF).
5.1.3.4 Symbolic-Characters-Clause
SPECIAL-NAMES-Symbolic-Characters-Clause Syntax
SYMBOLIC CHARACTERS
~~~~~~~~
{ symbolic-character-1... IS|ARE integer-1... }...
[ IN alphabet-name-1 ]
~~
This clause may be used to define your own figurative constants.
The reserved words
ARE,CHARACTERSandISare optional and may be omitted. The presence or absence of these words has no effect upon the program.
ERROR: uninterpreted block “raggedright”
There must be exactly as many <integer-1> values specified as there are | | <symbolic-character-1> names.
Each symbolic character name will be associated with the corresponding <integer-1>th character in the alphabet named in the
INclause. The integer values are selecting characters from the alphabet by their ordinal position and not by their numeric value; thus, an integer of 15 will select the 15th character in the specified alphabet, regardless of the actual numeric value of the bit pattern that constitutes that character.If no <alphabet-name-1> is specified, the systems native character set will be assumed.
The following two code examples define the same set of figurative constant names for five ASCII control characters (assuming that ASCII is the system’s native character set). The two examples are identical in their effects, even though the way the figurative constants are defined is different.
Individually
SYMBOLIC CHARACTERS NUL IS 1 SOH IS 2 BEL IS 8 DC1 IS 18 DC2 IS 19
Respectively
SYMBOLIC CHARACTERS NUL SOH BEL DC1 DC2 ARE 1 2 8 18 19
5.1.4 REPOSITORY
REPOSITORY Syntax
REPOSITORY.
~~~~~~~~~~
FUNCTION { function-prototype-name-1 [ AS literal-1 ] }...
~~~~~~~~ { ~~ }
{ intrinsic-function-name-1 [ AS literal-2 ] }
{ ~~ }
{ intrinsic-function-name-2 INTRINSIC }
{ ALL INTRINSIC ~~~~~~~~~ }
~~~ ~~~~~~~~~
The REPOSITORY paragraph provides a way to control access to the various built-in intrinsic functions and any user defined functions that your program will be using.
The
REPOSITORYparagraph is not allowed in a nested subprogram. A nested program inherits theREPOSITORYsettings of its parent program.The
INTRINSICclause allows you to flag one or more (orALL) built-in intrinsic functions as being usable without the need to code the keywordFUNCTIONin front of the function names.As an alternative to using the
ALL INTRINSICclause, you may instead compile your GnuCOBOL programs using the-fintrinsics=ALLswitch.The <function-prototype-name-1> option is required to specify the name of a user-defined function your program will be using. Optionally, should you desire, you may specify an alias name by which you will reference that user-defined function. Should you wish, you may also use the
ASclause to provide an alias name for a built-in intrinsic function.The following example
enables all intrinsic functions to be specified without the use of the
FUNCTIONkeyword,names two user-defined functions named
MY-FUNCTION-1andMY-FUNCTION-2that will be used by the program andspecifies the alias names
SIGMAfor the intrinsic functionSTANDARD-DEVIATIONandMF2forMY-FUNCTION-2.
REPOSITORY. FUNCTION ALL INTRINSIC FUNCTION MY-FUNCTION-1 FUNCTION MY-FUNCTION-2 AS "MF2" FUNCTION STANDARD-DEVIATION AS "SIGMA".
A special note about user-defined functions — because you must name a user-defined function that your program will be using in the REPOSITORY paragraph, you may always reference that function from your program’s procedure division without needing to use the FUNCTION keyword.
5.2 INPUT-OUTPUT SECTION
INPUT-OUTPUT SECTION Syntax
[ INPUT-OUTPUT SECTION. ]
~~~~~~~~~~~~ ~~~~~~~
[ FILE-CONTROL. ]
~~~~~~~~~~~~
[ SELECT-Statement... ]
[ I-O-CONTROL. ]
~~~~~~~~~~~
[ MULTIPLE-FILE-Statement ]
[ SAME-RECORD-Statement ]
The INPUT-OUTPUT section provides for the definition of any files the program will be accessing as well as control of the I/O buffering process against those files through the FILE-CONTROL and I-O-CONTROL paragraphs, respectively.
As the diagram shows, there are three types of statements that may occur in the two paragraphs of this section. If none of the statements are coded in a particular paragraph, the paragraph itself may be omitted, otherwise it is required.
If neither paragraph is coded, the
INPUT-OUTPUT SECTION.header itself may be omitted, otherwise it is normally required.If the compiler configuration file ( 10.1.7 Compiler Configuration Files) you are using has
relaxed-syntax-checkset to ‘yes‘, theFILE-CONTROLandI-O-CONTROLparagraphs may be specified without theINPUT-OUTPUT SECTIONheader having been coded.If both statement types are coded in the
I-O-CONTROLparagraph, the order in which those statements are coded is irrelevant.
5.2.1 SELECT
SELECT Statement Syntax
SELECT [ [ NOT ] OPTIONAL ] file-name-1
~~~~~~ ~~~ ~~~~~~~~
[ ASSIGN { TO } [{ EXTERNAL }] [{ DISC|DISK }] [{ identifier-1 }] ]
~~~~~~ { USING } { ~~~~~~~~ } { ~~~~ ~~~~ } { word-1 }
{ DYNAMIC } { DISPLAY } { literal-1 }
~~~~~~~ { ~~~~~~~ }
{ KEYBOARD }
{ ~~~~~~~~ }
{ LINE ADVANCING }
{ ~~~~ ~~~~~~~~~ }
{ PRINTER }
{ ~~~~~~~ }
{ RANDOM }
{ ~~~~~~ }
{ TAPE }
~~~~
[ COLLATING SEQUENCE IS alphabet-name-1 ]
~~~~~~~~~
[ FILE|SORT ] STATUS IS identifier-2 [ identifier-3 ] ]
~~~~ ~~~~ ~~~~~~
[ LOCK MODE IS { MANUAL|AUTOMATIC } ]
~~~~ { ~~~~~~ ~~~~~~~~~ }
{ EXCLUSIVE [ WITH { LOCK ON MULTIPLE RECORDS } ] }
~~~~~~~~~ { ~~~~ ~~ ~~~~~~~~ ~~~~~~~ }
{ LOCK ON RECORD }
{ ~~~~ ~~ ~~~~~~ }
{ ROLLBACK }
{ ~~~~~~~~ }
[ ORGANIZATION Clause ]
~~~~~~~~~~~~
[ ORGANISATION Clause ]
~~~~~~~~~~~~
[ RECORD DELIMITER IS STANDARD-1 ]
~~~~~~ ~~~~~~~~~ ~~~~~~~~~~
[ RESERVE integer-1 AREAS ]
~~~~~~~
[ SHARING WITH { ALL OTHER } ]
~~~~~~~ { ~~~ }
{ NO OTHER }
{ ~~ }
{ READ ONLY }
~~~~ ~~~~
The
COLLATING SEQUENCE,
RECORD DELIMITER,
RESERVE and
ALL OTHER clauses are syntactically recognized but are otherwise non-functional.
The SELECT statement creates a definition of a file and links that COBOL definition to the external operating system environment.
The reserved words
AREAS,IS,MODE,OTHER,SEQUENCE,TO,USINGandWITHare optional and may be omitted. The presence or absence of these words has no effect upon the program.After <file-name-1>, the various clauses may be coded in any sequence.
A period must follow the last coded clause.
The
OPTIONALclause, to be used only for files that will be used to provide input data to the program, indicates the file may or may not actually be available at run-time. Attempts toOPENanOPTIONALfile when the file does not exist will receive a special non-fatal file status value (see status 05 in the list of file status values below) indicating the file is not available; a subsequent attempt toREADthat file will return anAT END(end-of-file) condition. Optionally, files may be designated asNOT OPTIONAL, if desired. This is useful when specifying the compiler’s-foptional-fileswitch, which automatically makes all filesOPTIONALexcept for those explicitly declared asNOT OPTIONAL.The <file-name-1> value that you specify will be the name by which you will reference the file within your program. This name should be formed according to the rules for user-defined names ( 2.1.2 User-Defined Words).
The optional
ASSIGNclause specifies how — at runtime, when <file-name-1> is opened — either a logical device (STDIN,STDOUT) or a file anywhere in one of the currently-mounted file systems will be associated with <file-name-1>, as follows:There are three components to the
ASSIGNclause:<Type>EXTERNAL,DYNAMICor neither<Device>the list of device choices
<Locator>shown as a choice between <identifier-1>, <word-1> and <literal-1>.
ASSIGN TO DISC <file-name-1>will be assumed if there is noASSIGNclause on aSELECT.If an
ASSIGNclause is coded without a <Device>, the deviceDISCwill be assumed.If a <Locator> clause is coded, the COBOL file <file-name-1> will be attached to a data file within any file system that is mounted and available to the executing program at the time <file-name-1> is opened. How that file is identified varies, depending upon the specified <Locator>, as follows:
If <literal-1> is coded, the value of the literal will serve as the File Location String that will identify the data file.
If <identifier-1> is coded, the value of the identifier will serve as the File Location String that will identify the data file.
If <word-1> (a syntactically valid word not duplicating a reserved or user-defined word) is coded, and a <Type> is
EXTERNAL, then <word-1> itself will serve as the File Location String that will identify the data file. If, however, a <Type> ofEXTERNALwas not specified, the compiler will create aPIC X(1024)data item named <word-1> within the program; the contents of that data item at the time the program opens <file-name-1> will then serve as the File Location String that will identify the data file.File Location Strings will be discussed shortly.
If no <Locator> is coded, <file-name-1> will be attached to a logical device or a file based upon the specified (or implied) <Device>, as follows:
DISCorDISKwill assume an attachment to a file named <file-name-1> in whatever directory is current at the time the file is opened.DISPLAYwill assume an attachment to theSTDOUTlogical device; these files should only be used for output.KEYBOARDwill assume an attachment to theSTDINlogical device; these files should only be used for input.PRINTERwill assume an attachment to theLPT1logical device/port; these files should only be used for output.RANDOMorTAPEwill behave exactly asDISCdoes. These two additional <Device>s are provided to facilitate the compilation of COBOL source from other COBOL implementations.
The
LINE ADVANCINGdevice requires that a <Locator> be specified; these files should only be used for output. A COBOL Line Advancing file will allow carriage-control characters such as line-feeds and form-feeds to be written to the attached operating system file, via theADVANCINGclause of theWRITEstatement ( 7.8.52 WRITE).File Location Strings are used (at runtime) to identify the path and filename to the data file that must be attached to <file-name-1> when that file is opened.
If the compiler configuration file ( 10.1.7 Compiler Configuration Files) you used to compile the program with had a
filename-mappingvalue ofyes, the GnuCOBOL runtime system will first attempt to identify a currently-defined environment variable whose value will serve as the data file’s path and filename, as follows:If the compiler configuration file ( 10.1.7 Compiler Configuration Files) ( 10.1.7 Compiler Configuration Files) you used to compile the program specified
mfas theassign-clausevalue, then the File Locator String will be interpreted according to Microfocus COBOL rules — namely, everything before the last ‘-‘ in the File Locator String will be ignored; the characters after the last ‘-‘ will be treated as the base of an environment variable name. If there is no ‘-‘ character in the File Locator String then the entire File Locator String will serve as the base of an environment variable name. This is the default behaviour for every config file exceptibm.If, on the other hand, the compiler configuration file ( 10.1.7 Compiler Configuration Files) you used to compile the program specified
mfas theassign-clausevalue, then the File Locator String will be interpreted according to according to IBM COBOL rules — namely, the File Locator String is expected to be of the formS-<xxx>orAS-<xxx>, in which case the <xxx> will be treated as the base of an environment variable name. If there is no ‘-‘ character in the File Locator String then the entire File Locator String will serve as the base of an environment variable name.Once an environment variable name base (let’s refer to it as
<bbbb>) has been determined, the runtime system will look for the first one of the following environment variables that exists, in this sequence:DD_<bbbb> dd_<bbbb> <bbbb>
Windows systems are case-insensitive with regard to environment variables, so there is no difference between the first two when using a GnuCOBOL implementation built for either Windows/MinGW or native Windows.
If an environment variable was found, its value will serve as the path and filename to the data file.
If no environment variable was found, or the configuration file ( 10.1.7 Compiler Configuration Files) used to compile the program had a
filename-mappingvalue ofNO, then the File Locator String value will serve as the path and filename to the data file.Paths and file names may be specified on an absolute (
C:\Data\datafile.dat,/Data/datafile.dat, …) or relative to the current directory (Data\datafile.dat,Data/datafile.dat, …) basis. If no directory name is included (datafile.dat), the file must be in the current directory.
The
FILE STATUSorSORT STATUSclause (they are both equivalent and only one or the other, if any, should be specified) is used to specify the name of a two-digit numeric data item into which an I/O status code will be saved after every I/O verb that is executed against the file. This does not actually allocate the data item — you must define the item yourself somewhere in the data division. Note that the following list is complete as of v3.2: but more can be added and any tests should include one for non zeros as a catch all. See the copy book file filestat.cpy (which may not include all of these listed status codes). See sample version lower down. Possible status codes that can be returned to aFILE STATUSdata item are as follows:00Success
02Success (Duplicate Record Key Written)
04Success (Incomplete)
05Success (Optional File Not Found)
06Multiple records (in LS)
07Success (No Unit)
09Success LS Bad Data
10End of file reached if reading forward or beginning-of-file reached if reading backward
14Out of key range
21Key invalid
22Key already exists
23Key not found
24Key boundary violation
30Permanent I/O error
31Inconsistent filename
34Boundary violation
35File not found
37Permission denied
38Closed with lock
39Conflicting attribute
41File already open
42File not open
43Read not done
44Record overflow
46Read error
47OPEN INPUTdenied (insufficient permissions to read file)48OPEN OUTPUTdenied (insufficient permissions to write to file)49OPEN I-Odenied (insufficient permissions to read and/or write file)51Record locked
52End of page
57LINAGEbad specification (I-O linage)61File sharing failure
71Bad character
91File not available
Sample copy book member, suggest that you copy this content to say FileStat-Msgs.cpy and save in your copy book folder.
*>************************************************************ *> Author: Gary L. Cutler CutlerGL@gmail.com * *> * *> This copybook defines an EVALUATE statement capable of * *> translating two-digit FILE-STATUS codes to a message. * *> * *> Use the REPLACING option to COPY to change the names of * *> the MSG and STATUS identifiers to * *> the names your program needs. * *> chg 09/08/23 vbc for missing statuses * *> Chg 11/12/23 vbc for missing statuses, amended note above * *> to allow for copybook expansion. * *>************************************************************ EVALUATE STATUS WHEN 00 MOVE 'Success ' TO MSG WHEN 02 MOVE 'Success Duplicate ' TO MSG WHEN 04 MOVE 'Success Incomplete ' TO MSG WHEN 05 MOVE 'Success Optional, Missing' TO MSG when 06 move "Multiple Records LS" to msg WHEN 07 MOVE 'Success No Unit ' TO MSG when 09 move "Success LS Bad Data" to msg WHEN 10 MOVE 'End Of File ' TO MSG WHEN 14 MOVE 'Out Of Key Range ' TO MSG WHEN 21 MOVE 'Key Invalid ' TO MSG WHEN 22 MOVE 'Key Exists ' TO MSG WHEN 23 MOVE 'Key Not Exists ' TO MSG WHEN 24 MOVE 'Key Boundary violation ' TO MSG WHEN 30 MOVE 'Permanent Error ' TO MSG WHEN 31 MOVE 'Inconsistent Filename ' TO MSG WHEN 34 MOVE 'Boundary Violation ' TO MSG WHEN 35 MOVE 'File Not Found ' TO MSG WHEN 37 MOVE 'Permission Denied ' TO MSG WHEN 38 MOVE 'Closed With Lock ' TO MSG WHEN 39 MOVE 'Conflict Attribute ' TO MSG WHEN 41 MOVE 'Already Open ' TO MSG WHEN 42 MOVE 'Not Open ' TO MSG WHEN 43 MOVE 'Read Not Done ' TO MSG WHEN 44 MOVE 'Record Overflow ' TO MSG WHEN 46 MOVE 'Read Error ' TO MSG WHEN 47 MOVE 'Input Denied ' TO MSG WHEN 48 MOVE 'Output Denied ' TO MSG WHEN 49 MOVE 'I/O Denied ' TO MSG WHEN 51 MOVE 'Record Locked ' TO MSG WHEN 52 MOVE 'End-Of-Page ' TO MSG WHEN 57 MOVE 'I/O Linage ' TO MSG WHEN 61 MOVE 'File Sharing Failure ' TO MSG WHEN 71 MOVE 'Bad Character ' TO MSG WHEN 91 MOVE 'File Not Available ' TO MSG WHEN OTHER MOVE "Unknown File Status " TO MSG END-EVALUATE.
One sample code defining and using this copy book in a free format program source.
In Working-Storage section : 01 WS-Wor-Areas. 03 WS-Eval-Msg pic x(25) value spaces. 03 Fs-Reply pic xx. 03 WS-No-Care pic x. ..... 01 Error-Messages. *> System Wide 03 SL002 pic x(31) value "SL002 Note error and hit return". In Procedure Division : rewrite CUSTOMER-Record invalid key display "Rewrite Customer Rec " at line ws-23-lines col 1 display CUSTOMER-FILE-STATUS at line WS-23-Lines col 22 move CUSTOMER-FILE-STATUS to FS-Reply perform evaluate-message display ws-Eval-Msg at line ws-23-lines col 25 beep display SL002 at line ws-lines col 1 accept WS-No-Care at line ws-lines col 33 display space at line ws-23-lines col 1 with erase eos end-rewrite *> Evaluate-Message Section. *>============================== *> copy "FileStat-Msgs.cpy" replacing MSG by ws-Eval-Msg STATUS by fs-reply. *> Eval-Msg-Exit. exit section. *>************ ************ *>
The
SHARINGclause defines the conditions under which the program will be willing (or not) to allow other programs executing at the same time to access the file. 2.2.15 File Sharing, for the details.The
LOCKclause defines how concurrent access to the file will be managed on a record-by-record basis. 2.2.16 Record Locking, for the details.For syntax details for the
ORGANIZATIONclause, see next group of paragraphs.A
SELECTstatement without anORGANIZATIONexplicitly coded will be handled as if the following ORGANIZATION clause had been specified:ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL
5.2.1.1 ORGANIZATION SEQUENTIAL
ORGANIZATION SEQUENTIAL Clause Syntax
[ ORGANIZATION|ORGANISATION IS ] RECORD BINARY SEQUENTIAL
~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~
[ ACCESS MODE IS SEQUENTIAL ]
~~~~~~ ~~~~~~~~~~
Files declared as ORGANIZATION SEQUENTIAL will consist of records with no explicit end-of-record delimiter character sequences; records in such files are “delineated” by a calculated byte-offset (based on the maximum record length) into the file.
The reserved words
BINARY,IS,MODEandRECORDare optional and may be omitted. The presence or absence of these words has no effect upon the program.The reserved words
ORGANIZATIONandORGANISATIONare interchangeable.The phrase
ORGANIZATION IS(and its internationalized alternative,ORGANISATION IS) is optional to provide compatibility with those (few) COBOL implementations that considerORGANIZATIONto be optional. Most COBOL implementations do require the wordORGANIZATION, so it should be used in new programs.These files cannot be prepared with any standard text-editing or word processing software as all such programs will embed delimiter characters at the end of records (use
ORGANIZATION IS LINE SEQUENTIALinstead).These files may contain either
USAGE DISPLAYorUSAGE COMPUTATIONAL(of any variety) data since no binary data sequence can be accidentally interpreted as an end-of-record delimiter.While records in a
ORGANIZATION SEQUENTIALfile may be defined as having variable-length records, the file will be structured in such a manner as to reserve space for each record equal to the size of the largest possible record, based on the file’s description in theFILE SECTION.The
ACCESS MODE SEQUENTIALclause is optional because, if absent, it will be assumed anyway for this type of file. The internal structure of these files is such that they can only be processed in a sequential manner; in order to read the 100th record in such a file, for example, you first must read records 1 through 99.Sequential files are processed using the following statements:
CLOSE( 7.8.7 CLOSE)COMMIT( 7.8.8 COMMIT)DELETE( 7.8.11 DELETE)MERGE( 7.8.27 MERGE)OPEN( 7.8.30 OPEN)READ( 7.8.32 READ)REWRITE( 7.8.37 REWRITE)SORT( 7.8.42 SORT)UNLOCK( 7.8.50 UNLOCK)WRITE( 7.8.52 WRITE)
5.2.1.2 ORGANIZATION LINE SEQUENTIAL
ORGANIZATION LINE SEQUENTIAL Clause Syntax
[ ORGANIZATION|ORGANISATION IS ] LINE SEQUENTIAL
~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~ ~~~~~~~~~~
[ ACCESS MODE IS SEQUENTIAL ]
~~~~~~ ~~~~~~~~~~
[ PADDING CHARACTER IS literal-1 | identifier-1 ]
~~~~~~~
The PADDING CHARACTER clause is syntactically recognized but is otherwise non-functional.
Files declared as ORGANIZATION LINE SEQUENTIAL will consist of records terminated by an end-of-record delimiter character or character sequence.
The reserved words
CHARACTER,ISandMODEare optional and may be omitted. The presence or absence of these words has no effect upon the program.The reserved words
ORGANIZATIONandORGANISATIONare interchangeable.The phrase
ORGANIZATION IS(and its internationalized alternative,ORGANISATION IS) is optional to provide compatibility with those (few) COBOL implementations that consider that word to be optional. Most COBOL implementations do require the wordORGANIZATION, so it should be used in new programs.This is the only
ORGANIZATIONvalid for files that are assigned to thePRINTERdevice.These files may be created with any standard text-editing or word processing software capable of writing text files. Such files MUST NOT contain any
USAGE COMPUTATIONALorBINARY(of any variety) data since such fields could accidentally contain byte sequences that could be interpreted as an end-of-record delimiter.Both fixed- and variable-length record formats are supported.
The end-of-record delimiter sequence will be
X'0A'(an ASCII line-feed character) or aX'0D0A'(an ASCII carriage-return + line-feed sequence). The former is used on Unix implementations of GnuCOBOL (including Windows/MinGW, Windows/Cygwin and OSX implementations) while the latter would be used with native Windows implementations.When reading a
LINE SEQUENTIALfile, records in excess of the size implied by the file’s description in theFILE SECTIONwill be truncated while records shorter than that size will be padded to the right withSPACES.The
ACCESS MODE SEQUENTIALclause is optional because, if absent, it will be assumed anyway for this type of file. The internal structure of these files is such that the data can only be processed in a sequential manner; in order to read the 100th record in such a file, for example, you first must read records 1 through 99.Files assigned to
PRINTERorCONSOLEshould be specified asORGANIZATION LINE SEQUENTIAL.Line Sequential files are processed using the following statements:
CLOSE( 7.8.7 CLOSE)COMMIT( 7.8.8 COMMIT)DELETE( 7.8.11 DELETE)MERGE( 7.8.27 MERGE)OPEN( 7.8.30 OPEN)READ( 7.8.32 READ)REWRITE( 7.8.37 REWRITE)SORT( 7.8.42 SORT)UNLOCK( 7.8.50 UNLOCK)WRITE( 7.8.52 WRITE)
5.2.1.3 ORGANIZATION RELATIVE
ORGANIZATION RELATIVE Clause Syntax
[ ORGANIZATION|ORGANISATION IS ] RELATIVE
~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~
[ ACCESS MODE IS { SEQUENTIAL } ]
~~~~~~ { ~~~~~~~~~~ }
{ DYNAMIC }
{ ~~~~~~~ }
{ RANDOM }
~~~~~~
[ RELATIVE KEY IS identifier-1 ]
~~~~~~~~
These files are files with an internal organization such that records may be processed in a sequential manner based upon their physical location in the file or in a random manner by allowing records to be read, written or updated by specifying the relative record number in the file.
The reserved words
IS,KEYandMODEare optional and may be omitted. The presence or absence of these words has no effect upon the program.The reserved words
ORGANIZATIONandORGANISATIONare interchangeable.The phrase
ORGANIZATION IS(and its internationalized alternative,ORGANISATION IS) is optional to provide compatibility with those (few) COBOL implementations that consider that word to be optional. Most COBOL implementations do require the wordORGANIZATION, so it should be used in new programs.ORGANIZATION RELATIVEfiles cannot be assigned to theCONSOLE,DISPLAY,LINE ADVANCINGorPRINTERdevices.The
RELATIVE KEYclause is optional only ifACCESS MODE SEQUENTIALis specified.While an
ORGANIZATION RELATIVEfile may be defined as having variable-length records, the file will be structured in such a manner as to reserve space for each record equal to the size of the largest possible record as defined by the file’s description in theFILE SECTION.ACCESS MODE SEQUENTIAL, the defaultACCESS MODEif none is specified, indicates that the records of the file will be processed in a sequential manner, according to their physical sequence in the file.ACCESS MODE RANDOMmeans that records will be processed in random sequence by specifying their record number in the file every time the file is read or written.ACCESS MODE DYNAMICindicates the program may switch back and forth betweenSEQUENTIALandRANDOMmode during execution. The file starts out initially inSEQUENTIALmode when first opened but the program may use theSTARTstatement ( 7.8.43 START) to switch between sequential and random access.The
RELATIVE KEYdata item is a numeric data item that cannot be defined as a field within records of this file. Its purpose is to return the current relative record number of a relative file that is being processed inSEQUENTIALaccess mode and to serve as a key that specifies the relative record number to be read or written when processing a relative file inRANDOMaccess mode.Relative files are processed using the following statements:
CLOSE( 7.8.7 CLOSE)COMMIT( 7.8.8 COMMIT)DELETE( 7.8.11 DELETE)MERGE( 7.8.27 MERGE),ACCESS MODE RANDOMnot allowedOPEN( 7.8.30 OPEN)READ( 7.8.32 READ)REWRITE( 7.8.37 REWRITE)SORT( 7.8.42 SORT),ACCESS MODE RANDOMnot allowedSTART( 7.8.43 START)UNLOCK( 7.8.50 UNLOCK)WRITE( 7.8.52 WRITE)
5.2.1.4 ORGANIZATION INDEXED
ORGANIZATION INDEXED Clause Syntax
[ ORGANIZATION|ORGANISATION IS ] INDEXED
~~~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~
[ ACCESS MODE IS { SEQUENTIAL } ]
~~~~~~ { ~~~~~~~~~ }
{ DYNAMIC }
{ ~~~~~~~ }
{ RANDOM }
~~~~~~
[ RECORD KEY IS { [ data-name-1 ]
~~~~~~
{ [ record-key-name-1 ]
[ =|{SOURCE IS} data-name-2 ] ... ] }
~~~~~~
[ ALTERNATE RECORD KEY IS { [ data-name-3 ]
~~~~~~~~~ ~~~~~~
{ [ record-key-name-2 ]
[ =|{SOURCE IS} data-name-4 ] ... ] }
~~~~~~
[ WITH DUPLICATES ] ]...
~~~~~~~~~~
[ SUPPRESS WHEN ALL literal ]
~~~~~~~~~~~~~~~~~
[ SUPPRESS WHEN SPACES | ZEROES ]
~~~~~~~~~~~~~~~~~~~~ ~~~~~~
Indexed files, like relative files, may have their records processed in either a sequential or random manner. Unlike relative files, however, the actual location of a record in an indexed file is calculated automatically based upon the value(s) of one or more alphanumeric fields within records of the file. For example, an indexed file containing product data might use the product identification code as a record key. This means you may read, write or update the A6G4328th record or the Z8X7723th record directly, based upon the product id value of those records!
The reserved words
IS,KEYandMODEare optional and may be omitted. The presence or absence of these words has no effect upon the program.The reserved words
ORGANIZATIONandORGANISATIONare interchangeable.The phrase
ORGANIZATION IS(and its internationalized alternative,ORGANISATION IS) is optional to provide compatibility with those (few) COBOL implementations that consider that word to be optional. Most COBOL implementations do require the wordORGANIZATION, so it should be used in new programs.ORGANIZATION INDEXEDfiles cannot be assigned toCONSOLE,DISPLAY,KEYBOARD,LINE ADVANCINGorPRINTER.ACCESS MODE SEQUENTIAL, the defaultACCESS MODEif none is specified, indicates that the records of the file will be processed in a sequential manner with respect to the values of theRECORD KEYor theALTERNATE RECORD KEYmost-recently referenced on aSTARTstatement ( 7.8.43 START).ACCESS MODE RANDOMmeans that records will be processed in random sequence by accessing the record with specific record key or alternate record key values.ACCESS MODE DYNAMICallows the file will be processed either inRANDOMorSEQUENTIALmode; the program may switch between the two modes as needed. TheSTARTstatement is used to make the switch between modes.The
RECORD KEYclause defines the field within the record used to provide the primary access to records within the file. No two records in the file will be allowed to have the samePRIMARY KEYfield value. TheSOURCE ISclause is for use withSplit Keys.The
ALTERNATE RECORD KEYclause, if used, defines an additional field within the record that provides an alternate means of directly accessing records or an additional field by which the file’s contents may be processed sequentially. You have the choice of allowing records to have duplicate alternate key values, if necessary.There may be multiple
ALTERNATE RECORD KEYclauses, each defining an additional alternate key for the file.Usage of the
SUPPRESS WHENclause is used whenSparse Keysare required which may take the form for a literal or spaces or zeroes.Indexed files are processed using the following statements:
CLOSE( 7.8.7 CLOSE)COMMIT( 7.8.8 COMMIT)DELETE( 7.8.11 DELETE)MERGE( 7.8.27 MERGE),ACCESS MODE RANDOMnot allowedOPEN( 7.8.30 OPEN)READ( 7.8.32 READ)REWRITE( 7.8.37 REWRITE)SORT( 7.8.42 SORT),ACCESS MODE RANDOMnot allowedSTART( 7.8.43 START)UNLOCK( 7.8.50 UNLOCK)WRITE( 7.8.52 WRITE)
5.2.2 SAME RECORD AREA
I-O-CONTROL SAME AREA Syntax
SAME { SORT-MERGE } AREA FOR file-name-1... .
~~~~ { ~~~~~~~~~~ }
{ SORT }
{ ~~~~ }
{ RECORD }
~~~~~~
The
SAME SORT-MERGE and
SAME SORTclauses are syntactically recognized but are otherwise non-functional.
The SAME RECORD AREA clause allows you to specify that multiple files should share the same input and output memory buffers.
The reserved words
AREAandFORare optional and may be omitted. The presence or absence of these words has no effect upon the program.This statement must be terminated with a period.
While coding only a single file name (the repeated <file-name-1> item) is syntactically valid, this statement will have no effect upon the program unless at least two files are specified.
The effect of this statement will be to cause the specified files to share the same I/O buffer in memory. These buffers can sometimes get quite large, and by having multiple files share the same buffer memory you may significantly cut down the amount of memory the program is using (thus making “room” for more procedural code or data). If you do use this feature, take care to ensure that no more than one of the specified files are ever OPEN simultaneously.
5.2.3 MULTIPLE FILE
I-O-CONTROL MULTIPLE FILE Syntax
MULTIPLE FILE TAPE CONTAINS
~~~~~~~~
{ file-name-1 [ POSITION integer-1 ] }...
~~~~~~~~
.
The MULTIPLE FILE TAPE clause is obsolete and is therefore recognized but not functional.