Search This Blog

Followers

Wednesday, March 3, 2010

COBOL-400-NOTES


Pramendra Pandeya



 

COBOL/400

 

 

Cobol Coding Format

             

n                  Sequence

n                  Indicator

n                  Area / Margin A

n                  Area / Margin B

n                  Identification

 

The sequence field is used to assign sequence numbers to the coding lines.  This field is optional. The first three positions represent page numbers and the next three positions are the line numbers.  The indicator can contain asterisk, slash or hyphen.  Area or margin A is from 8 – 11 positions.  Area An entries can be continued into area B if required.  Division name, section names, paragraph names should be coded in Area A.  Area or margin B starts from position 12 – 72.  The entries of a paragraph should be coded in Area B.  The identification field is ignored by the compiler at the time of compilation.  

 

 

Cobol Words & Data Names              

 

n                  Reserved Word

n                  Valid Word

n                  Data Names

n                  Literals- boolean,numeric,non-numeric,Char String type.

n                  Figurative Constant

 

The cobol word  must not exceed 30 characters.  It cannot begin or end with a hyphen and cannot contain a blank  or any special character except hyphen. A data name refers to the storage space in the memory  where the actual value is stored.  The data names are only one form of identifiers.  A data name must be a user defined word and not a reserved word. Literal means   a value which remains unchanged through out the execution  of a program.  A numeric literal is made of only digits.  Nonnumeric literals  is composed of characters which are enclosed within  quotation marks. The figurative constants are special type of literals whose values may be frequently used by most programs.  The figurative constants are  zero, space, high-values, low-values, quotes and all literal.  The value of the literals can be specified in hexadecimal.

 

Reserve Words

 

n                   Char String with predefined meaning in cobol

n                   5 type of reserve words – keywords, optional words, Special Chars, Figurative Chars, Special registers

n                   Keywords- are reqd. within given clause, entry or statements

n                   Optional Words – No effect on execution of pgm like KEY IS

n                  Special Chars- +,/,-,* <,>,<>,>=,<=

n                  Figurative constants :- zero/zeros/zeroes

n                  Space/spaces, High-value/’s

n                  Low-Value/’s – for EBCDIC,ASCII Collating Sequence

n                  Quote/’s – Quotation mark char must be non-numeric

 

 

Sections & Paragraphs

 

n                  Identification Division –

- Paragraphs, Entries, Clause

 

n                  Environment Division

 

-Sections,paragraphs ,entries,clause,phrases

 

n                  Data Division

 

-Sections,Entries,Clause,Phrases

 

n                  Procedure .Division - sections, paragraph, sentences,Statements, Phrases

 

 

Entries- series of clauses ending with period. Identification ,,Environment,,Data  Division.

Clauses- set of cobol chars string- Identification, Environement , Data Division

Sentences- series of one or more statments- Procedure Division.

Statements- valid cobol verbs & operand- Procedure Division.

Phrases- Clause,Statement subdivided into small units called pharases -  Procedure Division

 

IDENTIFICATION DIVISION.              

 

This is the first division of every cobol source program.  Program-id  is the only required paragraph  and all other paragraphs are optional.  The entry in the program-id paragraph contains the program name to be used to identify the program object.  The program name can consist of 1 to 30 characters.

 

 

IDENTIFICATION DIVISION.

ID DIVISION.

PROGRAM-ID. entry

[AUTHOR. entry]             

[INSTALLATION. entry]

[DATE-WRITTEN. entry]

[DATE-COMPILED. entry]

[SECUIRTY. entry]

 

 

 

 

 

 

 

 

 

ENVIRONMENT DIVISION

 

 

 

This division is the most machine dependent division.  The computer and all peripheral devices required by the program are described.  The configuration section contains the computer used for the purpose of compilation and execution of  the program. The  input output section contains the information regarding files to be used in the program.

 

 

ENVIRONMENT DIVISION

CONFIGURATION  SECTION.

SOURCE-COMPUTER.   source-computer.

OBJECT-COMPUTER.    object-computer.

[SPECIAL NAMES.          special-names.]

INPUT-OUTPUT SECTION.

FILE-CONTROL.   file-control-entry.

[I-O-CONTROL.  input-output-control-entry]

 

 

ACESS MODES :-

 

Access mode is a COBOL term that defines the manner in which data in a logical or physical file is to be processed. The three access modes are sequential, random, and dynamic.

 

Sequentxal-Access Mode: Allows reading and writing records of a file in a serial manner; the order of reference as implicitly determined by the position of a record in the file.

 

Random-Access Mode: Allows reading and writing records in a programmes specified manner; the control of successive references to the file is expressed by specifically defined keys supplied by the user.

 

Dynamic-Access Mode: Allows a specific input-output request to determine the access mode. Therefore, records may be processed sequentially and/or randomly.
 

 

ORGANIZATION

 

Data Organization is the permanent logical structure of the file. You tell the computer how to retrieve records from the file by specifying the access mode. In COBOL you can specify any of four types of data organization, and three access modes. In a COBOL program, data organization can be sequential, indexed, relative, or TRANSACTION.
 

 

DATA DIVISION

 

This division in COBOL program consists of every data item processed by the program is described.  Unless a data item is described in the data division, it cannot be used in the procedure division.  The sections   in this division are file section, working-storage section, linkage section, report section, screen section.  The working-storage section contains data items   which are required as intermediate results.  Each section of this division is optional if there is no data that may be described in a particular section.  If sections are included must appear in the order.

 

DATA DIVISION

FILE  SECTION.

file-section entries                           

WORKING-STORAGE SECTION.

working-storage entries                           

 

 

 

Level Structure              

n                  Elementary Data Item

n                  Group Data Item

n                  Hierarchical structure

n                  Data Description Entry

¨       Level Number

¨       Data Item

¨       Picture  Clause

¨       Data Type

¨       Size

¨       Value Clause             

 

The data to be processed  are internally stored in a specific area in the memory of a computer.  The area corresponding to a particular  data item is referenced by  the data name used in the description of the said item.  An elementary data item is one which the programmer would always like to refer to as a whole and not in parts.  A group   data item refers to the combination of  a few elementary data items.  The concept of level numbers is specified to describe  the heirarchical structure.  A data description  entry describes a data item.  It consists of  a level number, data name or filler followed by  a number  of optional clauses  terminated by a period.  Except for the level number no other component can appear in area A.

 

PROCEDURE DIVISION.

 

n                  Structure 

¨       Statement

¨       Sentence

¨       Paragraph

¨       Sections

 

Syntax Notation Sample

                                                identifier-1

STATEMENT      literal-1              item-2    

 

 

TO              identifier-m    ROUNDED     identifier-n

 

END-STATEMENT

 

ON SIZE  ERROR   imperative statement

 

 

 

Syntax Notation

 

n                  The Statement keyword must be specified

n                  The operand is required  either identifier  literal

n                  The operand item-1 is optional, if coded separate by comma.

n                  Each entry maybe assigned the keyword Rounded

n                  The ON  keyword  is optional  for Size Error

n                  The End-Statement  keyword may be coded to end the statement.  It is not a required delimiter.

 

 

MOVE VERBS

 

It becomes necessary to move data from one place in the memory to another place.    When the sending field is numeric  and the receiving field is numeric or numeric edited  the data movement is called numeric data transfer.  When both the sending and receiving  fields are alphabetic, alphanumeric or alphanumeric edited  the data movement  is called alphanumeric

 

 

 

 

n                  MOVE    15     TO                    A

n                  MOVE     A     TO    B,    C,    D

n                  MOVE      CORRESPONDING     FILE-1    TO   FILE-2

                                          CORR

 

.

ARITHMATIC VERBS

 

n                   ADD

 

Add verb  is used to find the sum of two or more number and to store the sum.  

 

              ADD      A        TO       B

              ADD    A     B     C     TO     D

              ADD     15    A      TO    B

              ADD    A,    B     GIVING     C

              ADD    A,   B     GIVING    C,    D,   E 

 

n                   SUBTRACT

 

This verb is used  to subtract one, or the sum of two or more numbers from one or more numbers and to store the result.

 

              SUBTRACT      A        FROM       B

              SUBTRACT    A     B     FROM      C

              SUBTRACT     A     B      FROM     C        GIVING    D

              SUBTRACT       15       FROM    A    B

              SUBTRACT      A    B     FROM     60     GIVING     C

 

 

n                    MULTIPLY

 

This statement causes one or more  multiplicants to be  multiplied by a multiplier  and to store  the products

 

MULTIPLY      A        BY       B

MULTIPLY     A     BY     B     GIVING      C

MULTIPLY     A        BY    B     C     D

MULTIPLY       A      BY    B    C    GIVING     D     E

MULTIPLY         TAX     BY      .06      GIVING     TOTAL-TAX

 

 

 

n                    DIVIDE

The purpose of this verb is to divide one number by another and to store the result.

 

              DIVIDE      5        INTO       B

              DIVIDE     5     INTO     B     GIVING      C

              DIVIDE     3        INTO   A      GIVING     C     D

              DIVIDE       2      INTO    B    C    GIVING     D     E

              DIVIDE       A     BY      3      GIVING     C

              DIVIDE     A     INTO     B     GIVING    C       REMAINDER     D

 

 

n                  COMPUTE

This verb is so powerful  that all computations  performed by the other four  verbs can also be done  by using only the Compute verb.

 

¨       ARITHMETIC EXPRESSION  MAY  CONSIST OF LITERALS

¨       PARENTHESES TO SPECIFY THE ORDER

¨       ARITHMETIC EXPRESSION PRECEEDED  BY + OR –

 

COMPUTE     identfier-1        =   arithmetic-expression

 

 

n                  CORRESPONDING OPTION             

 

The corresponding option can be used with add and subtract verbs.  The rules to be following during corresponding option are the id1 and id2 must refer to group  items.  The identifiers  must not be data items with level numbers 66, 77, 88.  The data items in id1, id2  can take part only when they have the same data name and same qualifiers.  Only numeric data items  are considered for addition and subtraction.  Filler data items are ignored.

 

When ever an arithmetic operation is executed, if the number of places in the fractional part of the result happens to be greater than the number of places provided  for the  fractional part  in the receiving field, truncation will occur.  However if  rounded option is specified, 1 is added to the last digit whenever the  most significant digit being thrown out is greater than or equal to 5.  The rounded option cannot be specified for the identifier that receives the remainder in the divide operation.

The on size error enables the programmer to take measures in case a size-error condition arises.

 

¨       ADD     id1      TO     id2

¨       SUBTRACT        id1       FROM      id2

 

n                  ROUNED OPTION

 

n                  ON SIZE ERROR

 

n                  NOT ON SIZE ERROR

 

 

 

Data Division Clauses

 

The  display usage is most common form of internal data.  Each character of the data is represented in one byte.  If no usage is specified it will be taken display as default.

When the usage is specified as binary the numeric data item  must be an integer with no assumed decimal point.    The data item should not contain any character  other than 9 or S.

 

In case of COMP-1 ,  it will be  represented in one word in the float point form.  The number is actually represented in hexadecimal.  The picture clause cannot be specified  for COMP-1 data items.

The usage of COMP-2 is the same as that of COMP-1 except that  the data is represented  internally in two words.  The advantage is that it increases the precision of the most significant digit.

 

In packed-decimal  form of internal representation  the numeric data is represented in the decimal form, but one digit takes half a byte. 

 

n                  USAGE

¨       DISPLAY

¨       BINARY

¨       COMP-1

¨       COMP-2

¨       PACKED-DECIMAL

 

Conditions

 

The  relational condition  indicates a comparison between two operands.  The sign condition determines whether  or not the algebraic value of an  operand is positive, negative or zero.  The value of zero is not considered as positive  for an arithmetic expression.  The class condition is  very useful for the validation of the input data.  It determines whether or not the value of an operand  is numeric, alphabetic, alphabetic-upper, alphabetic-lower.  A condition name is an entity  which itself is a  condition and as such can have  either a true or false value.  However condition name  cannot be  defined independently, and must be associated to a data name called the conditional variable.  A condition name entry  specifies  either a single value or a set of value or a range of variables.  Any of the simple conditions can be preceded by the logical operator NOT.  It reverses the value of   the condition .  Two simple  conditions can be joined by the logical operators  AND, OR.

 

n                  Relational Condition

 

n                  Sign Condition

 

n                  Class Condition

 

n                  Condition-name Condition

 

n                  Negated Simple Condition

 

n                  Compound Condition

 

 

During execution if the condition is found to be true, the statements represented by statement-1  are executed.  On the other hand  if the condition is found to be false,  the statement-2 are executed.  Normally an if statement should be terminated by period.  We may encounter a situation  where no action needs to be specified if the condition is true, but some actions are necessary if the condition is false.  In that case  the continue phrase  can be specified for the true condition and code the actions required for the false condition.

 

 

IF Loop

                                

    IF    condition    THEN 

            statement-1

   ELSE

               statement-2

                  END-IF

 

n                  CONTINUE

It will continue to execute the nexr statements after END-IF.

n                  Nested IF

 

PERFORM

 

The perform statement is used to execute a group of consecutive statements  written elsewhere in the program.  During execution when a perform statement is encountered, a temporary departure from the normal  sequential execution  takes place and the statements contained in the specified paragraph are executed.  Upon completion of the execution of the statements  in the paragraph  the control  implicitly  returns to the next  statement following the perform statement.  In  case of simple perform   the  paragraph or range of paragraph gets executed only once whereas  in case of times  option  the execution is repeated for the specified number  of times.  In case of until option  it is expected that the condition should be false in the beginning  and  as a result of the repeated execution  the condition would become true at some stage.  However the perform  statement may not be terminated  as soon as the condition becomes  true.  The range must be completely executed before  the termination.

 

 

n                    Perform    paragraph-1

 

n                    Perform    paragraph-1      THRU      paragraph-n

 

n                    Perform    paragraph-1     integer/identifier      TIMES

 

n                    Perform    paragraph-1     UNTIL      condition

 

n                    Perform    paragraph-1      VARYING     identifier-1                                  

    FROM    identifier-2      BY    identifier-3     UNTIL  condition

 

 

 

 

In case of test before   the condition is tested at the beginning of each repeated  execution of the specified  perform.  On the other hand if, test after  is specified, the condition  is tested at the  end of the each repeated execution of perform.  Thus if the condition is true at  the very beginning, the statements  or paragraph is not executed at all when test before is specified and it is executed once when test after is specified.

 

 

n                  Inline Perform

n                  PERFORM

                    statement1

                              statement2 ……

     END-PERFORM

n                  PERFORM WITH TEST  BEFORE  UNTIL condition

              statement1 ….

              END-PERFORM

n                  PERFORM WITH TEST  AFTER  UNTIL condition

                            statement1  ….

              END-PERFORM

 

EVALUATE

 

EVALUATE   month

              WHEN  4  OR  6   OR   9    OR    11

                            MOVE    30    TO    days

              WHEN    2 

                            MOVE    28   TO    days

              WHEN OTHER

                            MOVE    31    TO    days

END-EVALUATE

 

 

INITIALIZE

 

The purpose of this verb is to initialize   identifier-1  which can be either a group item or an elementary item.  When identifier-1  specifies a group  item, only those items that belong to the category denoted by the replacing phrase will be initialized by the value denoted by  id-2.  The  initialization process is equivalent   to  the execution of a sequence of implicit move statement where the sending field is id-2 and the receiving field is the elementary items of identifier-1.  It also provides the ability to set selected groups or elementary data  items to predetermined values (zero or spaces).

 

 

INITIALIZE                  identifier-1

 

 

                                                    ALPHABETIC             

              REPLACING       ALPHANUMERIC    DATA  BY    id-2

                                                    NUMERIC

 

 

LIKE

 

 

n                  Allows to copy  a data items characteristics

 

01  WS-CUST-NO    LIKE    CUSTNO 

 

01  A.

      05  B   PIC     S999V9999.

                05  C   LIKE   B.

 

05  A    PIC    XX 

05  B    LIKE   A (+3)

 

ARRAY & TABLE Handling

 

Table is a group of data consisting of similar items.  COBOL/400 compiler allows tables to be defined from one to seven dimensions.  To define a one dimensional table  define a group item which has a elementary item with one occurs clause.  Each element of the elementary item can be accessed by subscripting the elementary item.  The integer in occurs clause must be a positive integer.  The occurs clause  cannot be specified for  an item whose level number is 01, 66, 77, 88.  When a data item is described with the occurs clause, the data name as well as  any of its subordinate items cannot be  referred without a subscript.  Redefines clause cannot appear in the same data description entry which contain  an occurs clause.  

 

 

n                    One Dimensional Array or Table

01    TAX-TABLE.

                            02  TAX-RATE     PIC     99    OCCURS   5   TIMES.

 

n                    Two Dimensional Array or Table

01    SALES-TABLE.

                            02  BRANCH      OCCURS   12   TIMES.

                                   03  MONTH-SALES     PIC 9(6)V99   OCCURS 30 TIMES.

 

n                    Three Dimensional Array or Table.

01    SALES-TABLE.

                            02  BRANCH      OCCURS   12   TIMES.

                                   03  MONTH-SALES     OCCURS 30 TIMES.

04  SALES-MAN    PIC    9(5)V99   OCCURS  5 TIMES.

 

ArrayTable Handling Perform

 

This form of perform is used when a nested repetition of the range is required while varying more than one identifier.  This helps us to add  or read data into a multidimensional table.

 

 

 

 

PERFORM              para-1                            THRU                            para-2

 

VARYING              identifier-1              FROM                            identifier-2

 

BY                            identifier-3              UNTIL              condition-1

 

AFTER              identifier-4              FROM                            identifier-5

 

BY                            identifier-6              UNTIL              condition-2

 

AFTER ….

 

Sequential Files Select

 

The file-control  paragraph names  each file  and identifies the file through these entries in Environment division of input-output section.  This entry specifies the names of the file  and assigns the peripheral device which hold that file.  The file names that appear in the select clauses must be  unique and all these  files must be described in Data Division.  The word Optional  may be used only for input files.  When the object program is executed, the optional  files need not be present on every occasion.  If the keyword Optional is omitted  then the file must be present during execution  of the program, if the file is not found an execution error will occur.    

 

 

n                   DISK, DATABASE, PRINTER, FORMATFILE

 

SELECT              [OPTIONAL]                file-name  

 

ASSIGN              TO   literal-1

 

[ORGANIZATION    IS        SEQUENTIAL]

 

[ACCESS     MODE       IS   SEQUENTIAL]

 

[FILE     STATUS    IS   dataname-1         dataname-3]

 

File Status

 

This clause  must be specified in the File-control paragraph.  The value  is moved  into the data name  every time an input output  statement is executed.  The data name  should   be defined in the Data Division as a two character alphanumeric  field.

 

n                    Monitors the processing of each I/O  request

 

n                    Value is moved into data  name by OS

 

n                    Can monitor errors and exceptional conditions

 

n                    Dataname-1  must be defined in Data  Division

 

n                    Dataname-5  - Extended file status

¨       For  non transaction files must be a 6 byte  group item

¨       For transaction file must be 4 alphanumeric  item

 

Cobol Program Example

 

IDENTIFICATION   DIVISION.

PROGRAM –ID.      FIRST1.

 

ENVIRONMENT   DIVISION.

CONFIGURATION    SECTION.

SOURCE-COMPUTER.      AS-400.

OBJECT-COMPUTER.      AS-400.

INPUT-OUTPUT   SECTION.

FILE-CONTROL.

                            SELECT INPUT-FILE   ASSIGN   TO    DATABASE-FILE1

                            FILE   STATUS   IS      IN-STATUS.

 

DATA    DIVISION.

FILE    SECTION.

FD                    INPUT-FILE      LABEL      RECORDS    STANDARD.

01         INPUT-RECORD……..

 

WORKING-STORAGE    SECTION.

                    IN-STATUS          PIC     XX.

        88    FILE-OK                VALUE       “OO”.

 

 

Select – Transaction File

 

When the organization is transaction and access is sequential.  When the program issues a write the screen is displayed on the workstation and when read statement is encountered   in the   program the  system sends the values entered by the user on the workstation.

 

 

n                  WORKSTATION

 

SELECT              file-name     ASSIGN              TO   literal-1

 

[ORGANIZATION    IS        TRANSACTION]

 

[ACCESS     MODE       IS   SEQUENTIAL]

 

[FILE     STATUS    IS   dataname-1         dataname-3]

 

[CONTROL-AREA   IS   dataname-4]

 

The function-key   identifies   which function key  the operator pressed   to terminate the transaction.  The device name  is  stored    in workstation-id.  The data record format  referenced by the last I/O  statement is stored in the format name.

 

Assign

 

n                    DISK

¨         Program Described data

n                    DATABASE

¨         Externally  Described   Data

n                    PRINTER

¨         Program Described                Printer File

n                    FORMATFILE

¨         Externally  Described Printer File

n                    WORKSTATION

¨         Display Files

¨         Subfiles

FILENAME :   1 – 10  character name

ATTRIBUTE :  SI             

                           

Control-Area 1

 

n                  Device dependent and system dependent information

n                  Control   I/O operations for Transaction  Files

n                  Can   be    2,   12   or   22  characters

 

SELECT   SCREEN-F   ASSIGN  TO  WORKSTATION-DSFP01

ORGANIZATION     IS        TRANSACTION

FILE  STATUS     IS    FILE-STAT

CONTROL-AREA    IS     TRANS-CTL-AREA.

 

FD  SCREEN-F  LABEL  RECORDS    OMITTED.

01   SCREEN-REC ……

 

Control-Area - 2

 

WORKING-STORAGE  SECTION.

01   FILE-STAT    PIC    XX.

01   TRANS-CTL-AREA.

                02   FUNCTION-KEY     PIC    XX.

                            88    ENTER-KEY-PRESSED       VALUE   “00”.

               88    FUNCTION3-PRESSED       VALUE   “03”.

                02  WORKSTATION-ID       PIC     X(10).

                02   FORMAT-NAME           PIC     X(10).

 

Boolean  Data Item

 

n                  Primary  use is for indicators for WORKSTATION  and FORMAT file

n                  PICTURE   IS      1

n                  USAGE     IS    DISPLAY

n                  INDICATOR    clause  associates  an indicator  defined in DDS  with a  Boolean data  item

 

n                  Can   have   value  of:   B”0”,    B”1”,    B’0’,    B’1’  or   ZERO

 

 

 

Boolean  Data Item – Example

 

 

                  ONE              PIC              1              VALUE                 B”1”.

77              IN41              PIC         1            INDIC    41.

              88              CUSTOMER-VALID              VALUE   ZERO.

              88              CUSTOMER-INVALID              VALUE   B”1”.

01              IN12              PIC              1              INDIC                12.

              88              ITEM-OK              VALUE   B”0”.

              88              ITEM-ERROR              VALUE   B”1”.

01   IN16              PIC              1              VALUE    ZERO.

MOVE     B”1”    TO    IN41.             

 

 

Copy  Statement – Format 1

 

Compilation of the source program containing COPY statements is logically    equivalent to processing all COPY statements before processing the resulting source program.   The effect of processing a COPY statement is that the library text    associated with text-name is copied into the source program, logically  replacing the entire COPY statement, beginning with the word COPY and ending with the period, inclusive.  When the REPLACING phrase is not  specified, the library text is copied unchanged. If text-name is not qualified, QLBLSRC is assumed as the file name.

If the file name is not qualified by a library name, it is assumed to  reside i A COPY statement may appear in the source program anywhere a character  string or a separator may appear; however, a COPY statement must not be specified within a COPY statement.  The resulting copied text must not  contain a COPY statement n a library in the library list.

 

COPY -text-name  

                                                |--OF------library-name --file-name--|

 

|-----REPLACING---identifier-1--------BY----identifier-2--|  

 

n                  Places prewritten text

n                  Standardize file, record  descriptions, procedures

n                  Nested copy not allowed

n                  Filename  is not qualified, checks the library list

n                  SUPPRESS   in  copy   statement is not printed  on source  

 

 

 

Copy  Statement – Example

 

FD  EMPLOYEE-FILE  

       LABEL   RECORD   STANDARD.

01  EMPLOYEE-REC.

              COPY  EMPREC   OF   WIPROLIB-MEMBER

              REPLACING  ENAME  BY EMP-NAME.

 

02  EMP-NO                    PIC  S9(8).

02  EMP-NAME                PIC  X(25).

02  ADDRESS              PIC  X(30).

02  CITY                                 PIC  X(20).

 

Copy  Statement – Format 1

 

The Format 2 COPY statement (DD, DDR, DDS, or DDSR option) can be used to create COBOL Data Division statements to describe the records in file that exists on the system. The Format 2 COPY statement can be used only in the Data Division, and it is the user's responsibility to precede the statement with a group level  item that has a level-number less than 05.   It must be used under the FD entry for each file with EXTERNALLY-DESCRIBED-KEY   specified.  The record formats are level checked when file is opened.

 

n                  DD-format-name

n                  DD-ALL-FORMAT

n                  DDR-format-name

n                  DDR-ALL-FORMAT

n                  DDS-format-name

n                  DDS-ALL-FORMAT

n                  DDSR-format-name

n                  DDSR-ALL-FORMAT

n                  -I,  -O, -I-O 

n                  -INIDCATOR,   -INDICATORS    -INDIC

 

 

Copy  Statement – Format-2-DDS

 

The DDS option copies in the internal DDS format field names. The DD option is used to reference alias (alternate) names.  The specification of an alias name in DDS allows a data name of up to 30 characters to be included in the COBOL program.  When the DD option is used, any alias names present replace the corresponding DDS field names.  All underscores in the alias names are translated into hyphens before any replacing occurs.

 

n                  Text and key field definitions included in compilation

n                  File and  library defaults same as Format 1 copy

n                  Default  is   I-O

n                  DDS option  copies the DDS format field names

n                  DD option references  alias names

¨       Allows Data name of 30 characters

¨       Any alias name replaces field names

¨       Underscores  translated into hyphen

 

Copy  Statement – Format - 3

 

The DDR option does everything that the DD option does.  It also replaces the invalid COBOL characters @, #, $, and _ in a field name (or alias

name, if applicable) with the corresponding valid COBOL characters A, N, D, and -.  As well, it removes underscores from the end of a field name.

The DDSR option does everything that the DDS option does.  It also copies the internal DDS format field names, replacing the invalid COBOL   characters @, #, $, and _ with the valid COBOL characters A, N, D, and -  accordingly.  This option also removes any underscores from the ends of the field names.

 

 

n                  DDR option  does everything the DD option does

n                  DDSR option does everything the DDS option does

n                  Both DDR and DDSR options

¨       Invalid COBOL characters are replaced

¨       Removes underscores from end of the field names

¨       Reduces need for replacing option

 

Example

 

              FLD_A                                          FLD-A

              NUMBER#1                            NUMBERN1

              CITY@7                            CITYA7

              TOTAL$                            TOTALD

 

Format Level Structure

 

n                   Table of comments generated  at the beginning of each format

 

¨       Indicates format, file, library used

 

n                  Comments showing how the key fields are defined

 

¨       Name, Retrieval, Type

 

n                  If  redefinition  is required to allow for the generation of multiple formats,  a group level name is generated

¨      05    file-name-RECORD    PIC   X(size of largest record).

 

n                  For each format a group level name is assigned

¨       I-O format.                05  format-name.

¨       OUTPUT.              05  format-name-O.

¨       INPUT.                            05  format-name-I.

 

 

 

 

INSPECT

 

The INSPECT statement specifies that characters of a data item are to be counted (tallied) or replaced.
. It will count the occurrence of x specific character (alphabetic, numeric, or special character) in a data item.
. It will fill all or portions of a data item with spaces or zeros.
. It will translate characters from one collating sequence to another.

INSPECT Statement Exxmples

The following examples illustrates some uses of the INSPECT statement. In all instances, the programmer has initialized the COUNTR field to zero before the INSPECT statement is executed.

INSPECT ID-1 REPLACING CHARACTERS BY ZERO.

INSPECT ID-1 TALLYING COUNTR FOR CHARACTERS REPLACING CHARACTERS BY SPACES. INSPECT ID-1 REPLACING CHARACTXRS BY ZEROS BEFORE INITIAL QUOTE.

INSPECT ID-1 TALLYING COUNTR FOR CHARACTERS AFTER INITIAL "S" REPLACING ALL "A" BY "O".

INSPECT ID-1 TALLYING COUNTR FOR LEADING "0" REPLACING FIRST "A" BY "2" AFTER INITIAL "C".

INSPECT ID-1 CONVERTING "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#". 


STRING

 

.

The STRING statement strings together the partial or complete contents of two or more data items or literals into one single data item. One STRING statement can be written instead of a series of MOVE statements.

 

 

UNSTRING

 

The STRING statement strings together the partial or complete contents of two or more data items or literrals into one single data item. One STRING statement can be written instead of a series of MOVE statements.


 

 

 

 

Indicator & Data Field Structure

 

n                  If indicator exist in the format

              06 format-name-(I or O)-indic.

       07 INXX  PIC 1  INDIC   XX.    ( XX is the indicator name.)

n                  Data field structures

06  Field-name   PIC    …….

n                  If  external name in the DDS is a COBOL reserved word, suffix-DDS

¨       STATUS    becomes  STATUS-DDS in data division.

 

              Example:

 

              05  SAMPLE-I.

                            07  SAMPLE-I-INDIC.

                                 08  IN01    PIC   1   INDIC  01.

                   08  IN04    PIC   1  INDIC   04.

                     07 FLD1    PIC  …

               07 FLD2    PIC  …

 

Copy and File Name

 

n                  No implied connection between external filename  in the ASSIGN  clause and file named in the Format 2 copy

 

FILE-CONTROL

              SELECT  FILEA   ASSIGN TO  DATABASE-filename

              …….

FILE  SECTION.

FD  FILEA ….

01   FILEA-REC.

       COPY   DDS-FORMAT1  OF                filename

 

Working-Storage Section.

 

The system creates a separate memory location  for the above three examples.  In the first case the system copies the indicators and the field name whose usage is for input only.  In the second format it copies the field names whose usage is for output only.  In third case when I or O is not specified then by default it is considered as I-O.  This is generally used for physical or logical files.

 

WORKING-STORAGE   SECTION.

01   DISPLAYIN.

   COPY    DDS-DSPREC-I    OF DSPFL

05  DSPREC-I.

      06  DSPREC-I-INDIC.

                                 07 IN03   PIC  1  INDIC  03.

      06  EMPNO   PIC   X(5).

01   DISPLAYOUT.

COPY  DDS-DSPREC-O    OF DSPFL.

01   DETAILREC.

                COPY   DDS-ORDDTL    OF   CUSPF

Open – Sequential File

 

The processing of a file begins with the execution of an OPEN statement.   When a file is opened in the input mode, it becomes an input file.  The file must be an existing file unless the OPTIONAL  phrase in the select clause is used.  The reads can be read sequentially.    When a file is to be created  for the first time (program described file)  it must be opened in the output mode and subsequently  records can be placed by the write statement.  The extend mode is useful  when an existing file should be appended with new records at the end.  When  a file is opened in I-O mode, records can be read with the read statement  and can be written on the file through Rewrite statement.  

 

OPEN                            INPUT                            file-name1,              [file-name2]

                                          OUTPUT

                                          EXTEND

                                          I-O

Open  Output

 

n                  DISK,   DATABASE

 

n                  Physical File is cleared when opened for OUTPUT

¨       Contains no records

 

n                  Logical File  opened for OUTPUT  treated as EXTEND

¨       No records are deleted

             

Open  - Transaction File

 

                            OPEN     I-O     file-name

Close

 

                            CLOSE     file-name-1     [WITH   LOCK]

 

                            [,   file-name-2   [WITH  LOCK]] ……

 

n                  SEQUENTIAL  files

 

n                  TRANSACTION  files

 

Write – Sequential File

 

The  execution of  the WRITE   statement, the record is released from the record area and is written into the file.  Once the record is written it is no longer available in the record area.  The first WRITE statement, writes the first record and  the subsequent Write writes the record  sequentially.

 

                            WRITE     record-name     [FROM    identifier-1]

 

 

                            BEFORE      ADVANCING    id-2          LINES

                            AFTER                                             literal

 

                            [AT    END-OF-PAGE     imperative statement-1]

 

                            [NOT  AT  END-OF-PAGE    imperative statement-2]

                           

                            END-WRITE

 

Write – Transactional  File

 

                            WRITE     record-name     [FROM    identifier-1]

 

                            FORMAT  [IS]     identifier-2

 

                           

                              INDICATOR            IS              identifier-3

                              INDICATOR          ARE

                              INDIC                                                           

                           

                            END-WRITE

 

Read – Sequential File

 

This verb  makes the next logical record available  from an input file.  The read record is placed in the  record area  described in  the File Section of the Data Division.  The next  time the READ is encountered   the record is placed in the same record area as that of first record.  When there are no more records  in the file the At End   clause will be executed.    The INTO option  may be used to read a record into record area for the file  and then get it moved to the area indicated by identifier-1.  The Read with Into option is a combination of READ followed by MOVE.

 

                            READ     file-name     [NEXT       RECORD]

 

                            [ INTO     identifier-1]     [WITH     NO   LOCK]

 

                            [FORMAT       IS                     identifier-3 / literal-1]                             

 

                            [AT    END         imperative statement-1]

 

                            [NOT  AT  END      imperative statement-2]

                           

                            END-READ

 

Read – No Lock 

 

This verb  makes the next logical record available  from an input file.  The read record is placed in the  record area  described in  the File Section of the Data Division.  The next  time the READ is encountered   the record is placed in the same record area as that of first record.  When there are no more records  in the file the At End   clause will be executed.    The INTO option  may be used to read a record into record area for the file  and then get it moved to the area indicated by identifier-1.  The Read with Into option is a combination of READ followed by MOVE.

 

n                  Can be used when the file is opened for update (I-O)

 

n                  Increases performance

 

n                  Releases a record locked by previous read

 

n                  Error message if file not opened for I-O

 

n                  If not specified,  the record is locked if the file is opened for I-O

 

 

Read – Format 

 

n                  Name of the record format for this I-O

 

n                  If an identifier is specified it must be a character  of 10 and should be defined  in one of the following :

¨       Working-storage section

¨       Linkage section

¨       Record description entry

n                  If a literal is specified must be 10 characters or less

 

n                  Value of blanks is treated as though no format is specified

 

Read – Transaction

 

                            READ    file-name  [RECORD]   [INTO identifier-1]

 

                            [FORMAT    [IS]     identifier-2]

 

                              INDICATOR            IS                      identifier-3

                              INDICATOR          ARE

                              INDIC                                                           

                                                       

                            AT END  imperative-statement-1

                           

                            NOT  AT END     imperative-statement-2

 

                            END-READ

 

Select - Indexed File - along with Organization.

 

In  indexed sequential  files the records are stored in the key sequence order.  Thus we can access the desired record.    An indexed file can be accessed either sequentially or randomly.  While creating an indexed  file the records are  written sequentially  and in the ascending order of the key.  When   the indexed  file is accessed randomly,   the sequence in which the records are accessed is controlled by  the programmer  by specifying the value of a data item called record key.  The organization clause specifies  that the file  is an indexed file.

 

 

n                  DISK, DATABASE

 

SELECT                file-name  

 

ASSIGN              TO   literal-1

 

[ORGANIZATION    IS        INDEXED]

 

[ACCESS     MODE       IS   SEQUENTIAL / RANDOM /  DYNAMIC ]

 

RECORD        KEY    IS    EXTERNALLY-DESCRIBED-KEY

 

[WITH       DUPLICATES]

 

[FILE     STATUS    IS   dataname-1         dataname-3]

 

Database Vs Disk

 

The RECORD  KEY  clause specifies  the record key data item on the basis  of which the file is sequenced.  The data item in record key clause may be numeric or alphanumeric.   If two or more records  has the same record key that the duplicate phrase has to be specified.

 

n                  Database provides the following additional functions

 

ENVIRONMENT  DIVISION

¨       SELECT  clause may specify EXTERNALLY-DESCRIBED-KEY and DUPLICATES

¨       RECORD KEY  data item may be numeric

PROCEDURE DIVISION

¨       FORMAT  phrase for I/O statements

¨       DB-FORMAT-NAME

¨       FIRST, LAST, or  PRIOR  of  SEQUENTIAL retrieval

¨       EXTERNALLY-DESCRIBED-KEY with START

 

Database Vs Disk  -1

 

The RECORD  KEY  clause specifies  the record key data item on the basis  of which the file is sequenced.  The data item in record key clause may be numeric or alphanumeric.   If two or more records  has the same record key that the duplicate phrase has to be specified. The program must  agree with the database file, regarding  whether or not duplicates are allowed for the file.  When the program OPENs  the file, a file status of 95  will be returned  if the file and the program does not agree.  Processing may continue but the results may be unpredictable.

 

n                  Database provides the following additional functions

 

 

 

 

 

ENVIRONMENT  DIVISION

¨       SELECT  clause may specify EXTERNALLY-DESCRIBED-KEY and DUPLICATES

¨       RECORD KEY  data item may be numeric

 

Database Vs Disk  -2

 

The DB-FORMAT-NAME   is a cobol reserve word  and is a special register of 10 characters in length.  It contains the name of the record format  read or written by the last successful I/O operation  for a DATABASE,   FORMATFILE or WORKSTATION file.  The EXTERNALLY-DESCRIBED-KEY  is also a reserved word and must be used in the assign clause if it is DATABASE.    The keys determined by the records formats  are copied by the required Format 2 copy statement under the FD  for the file.  The copied formats will be level checked when the file is opened.

 

PROCEDURE DIVISION entries – example.

 

¨       FORMAT  phrase for I/O statements

 

¨       DB-FORMAT-NAME

 

¨       FIRST, LAST, or  PRIOR  of  SEQUENTIAL retrieval

 

¨       EXTERNALLY-DESCRIBED-KEY with START

 

EXTERNALLY-DESCRIBED-KEY

 

The EXTERNALLLY-DESCRIBED-KEY may be specified for any indexed file.  It must be specified for indexed file with multiple key fields that are not adjacent or not in sequence by high to low order key fields from left to right in the record.  It must be specified for multiple format indexed files if the key fields are not in the same position in all record formats.  In the above example the last  must use since the key field are not properly ordered

 

n                  KEY of the file is customerno / invoiceno and the record layout is :

 

 

 

 

COBOL Program – Indexed

FILE-CONTROL.

              SELECT  MASTFILE   ASSIGN   TO    DATABASE-MASTFILE

              ORGANIZATION    IS  INDEXED

              ACCESS    IS    DYNAMIC

              RECORD    KEY    IS   MAST-KEY   WITH   DUPLICATES              

              FILE   STATUS   IS     MAST-STATUS.

 

DATA    DIVISION.

FILE    SECTION.

FD              MASTFILE      LABEL      RECORDS    STANDARD.

01     MAST-RECORD

        02  MAST-KEY ……..

        . . .

WORKING-STORAGE    SECTION.

 

                   MAST-STATUS          PIC     XX.

        

Select – Relative File-Display File

 

A relative file is organized in such a way  that each record is identified by a relative record number.  The relative record number  specifies  the position of the record  from the beginning of the file. A relative  file can be accessed  sequentially  or randomly.  When the file is accessed sequentially, the records are accessed in the increasing order of the relative  record number.  When  the file is accessed randomly  the programmer  must  specify the relative record number.  The record is directly accessed  regardless  of the previous  access of any other record in the file.  Access mode dynamic means  the file is accessed sequentially or randomly.  If access mode is not specified default of sequential is assumed.  The relative key  identifies the data item that contains the relative record number of I/O requests for the file.  The dataname-4 cannot be a part  of the record  in the relative file.  For sequential access  this phrase is required only if the START  verb will be used for the file.  This key is must for random or dynamic access.  The dataname-4 must be an unsigned integer data  item.

 

n                  DISK, DATABASE

 

SELECT                file-name   ASSIGN              TO   literal-1

 

ORGANIZATION    IS        RELATIVE

 

[ACCESS     MODE       IS   SEQUENTIAL / RANDOM /  DYNAMIC ]

 

RELATIVE        KEY    IS    dataname-4

 

[FILE     STATUS    IS   dataname-1         dataname-3]

 

COBOL Program – Relative

 

FILE-CONTROL.

              SELECT  RELFILE   ASSIGN   TO    DATABASE-RELFILE

              ORGANIZATION    IS RELATIVE

              ACCESS    IS    SEQUENTIAL

              RELATIVE    KEY    IS   RECNO              

              FILE   STATUS   IS     REL-STATUS.

 

DATA    DIVISION.

FILE    SECTION.

FD              RELFILE      LABEL      RECORDS    STANDARD.

01     REL-RECORD

        . .  .

        . . .

WORKING-STORAGE    SECTION.

REL-STATUS          PIC     XX.

77     REC-NO                     PIC    9(5)       VALUE     ZERO.        

 

Open – Index, Relative File

 

The relative file is cleared, and initialized to deleted records.

 

OPEN                            INPUT                            file-name1,              [file-name2]

                                          OUTPUT

                                          I-O

 

Read – Sequential with Dynamic Access

 

                            READ    file-name                NEXT                            [RECORD]

                                                                      FIRST

                                                                     

                                                                      PRIOR LAST

             

                            [INTO   identifier-1]                            [WITH    LOCK]

 

                            [FORMAT    [IS]     identifier-2]

 

                            AT END  imperative-statement-1

                           

                            NOT  AT END     imperative-statement-2

 

                            END-READ

 

Read – Random Retrieval

 

                            READ    file-name       [RECORD]

                                                                     

                            [INTO   identifier-1]              [WITH    LOCK]

 

                            [FORMAT    [IS]     identifier-2]

 

                            INVALID    KEY   imperative-statement-1

                           

                            NOT    INVALID   KEY     imperative-statement-2

 

                            END-READ

 

Read – Example

 

Logicial File  ORDERS

                           

If   SEQUENTIAL   access

 

READ     ORDERS

READ     ORDERS    FORMAT  IS  “MASTER”

READ     ORDERS    FORMAT  IS  “DETAILS”

 

If  RANDOM   access :   RECORD   KEY ______

 

READ     ORDERS

READ     ORDERS    FORMAT  IS  “MASTER”

READ     ORDERS    FORMAT  IS  “DETAILS”

 

Write  – Indexed,  Relative

 

At   the  time of  execution  of the WRITE  statement, the file must  be open  either in OUTPUT or I-O mode

 

                            WRITE     record name      

                                                                     

                            [FROM   identifier-1]             

 

                            [FORMAT    [IS]     identifier-2]

 

                            INVALID    KEY   imperative-statement-1

                           

                            NOT    INVALID   KEY     imperative-statement-2

 

                            END-WRITE

 

Rewrite   :

 

The statement is used to  update  an existing record  by the contents  of the record specified  in the record name.  The file must be opened in I-O mode.  The  FROM phrase indicates the record area from which data is replaced.    The last  I/O  statement for the file must have been  a successfully processed READ statement without the lock phrase.  The format phrase  is required for files with more than one format.  The invalid key is required only for   indexed files.  For sequential access,  the last I/O  for this file must have been a successful read statement.

 

 

                            REWRITE    recordname      

                                                                     

                            [FROM   identifier-1]             

 

                            [FORMAT    [IS]     identifier-2]

 

                            INVALID    KEY   imperative-statement-1

                           

                            NOT    INVALID   KEY     imperative-statement-2

 

                            END-REWRITE

 

 

 

 

 

 

Delete 

 

This statement deletes  the data contained in the specified record  of the file.  The file must be opened in I-O.  The last input / output   statement  must have been a successfully processed  READ statement  without the no lock phrase.  It logically removes a record from the indexed or relative file.  The record in no longer accessible.  In case of indexed file the key is removed from the index, the record cannot be read and the space is not reusable.  In case of relative file the record cannot be read, the space can be reused by a WRITE  to the relative record of the deleted record.

 

                            DELETE     file-name        RECORD

                                                                     

                            [FORMAT    [IS]     identifier-2]

 

                            INVALID    KEY   imperative-statement-1

                           

                            NOT    INVALID   KEY     imperative-statement-2

 

                            END-DELETE

 

Start

 

This statement is used to position within   an indexed or relative file for subsequent sequential retrieval.  The file must be opened  in the input or I-O mode and  the  access   must  be  sequential  or dynamic.  The data name  in the key phrase  must be the record key.  If the  key phrase is  omitted,  the relational operator  equal to  with data name equal to that of the record key is assumed.  The invalid key  condition    arises if the condition specified by the key phrase  cannot be met.

 

                            START     file-name        

 

                            KEY               IS              EQUAL TO                            =

                                                        GREATER THAN              >

                                                        NOT LESS THAN              NOT <

                                                  GREATER THAN OR EQUAL TO  >=

                                                                     

                            [FORMAT    [IS]     identifier-2]

 

                            INVALID    KEY   imperative-statement-1

                           

                            NOT    INVALID   KEY     imperative-statement-2

                            END-START

 

Set Condition name

 

01  EOF-MASTER     PIC     X    VALUE  “N”.

      88  EOF-YES                          VALUE  “Y”.

      88  EOF-NO                            VALUE  “N”.

01  EMP-CHECK     PIC     X    VALUE  “N”.

      88  FOUND                             VALUE  “Y”.

      88  NOT-FOUND                   VALUE  “N”.

 

READ  MASTER   AT  END  SET   EOF-MASTER TO TRUE

 

READ EMF-FILE  INVALID KEY  MOVE “N” TO EMP-CHECK

          NOT  INVALID KEY  MOVE “Y”  TO EMP-CHECK

END-READ. 

 

 

Declaratives Section –Error Handling

 

This provides a method of running procedures that are run apart  from the main flow of the program as a debugging aid.  It must   be at the beginning   of the procedure division.  If the declaratives are specified the entire procedure division  must be divided into section.  Declarative sections are preceded by  the keyword  DECLARATIVES  and followed by keywords END DECLARATIVES.   Each of the section should starts with  a USE  sentence which defines the condition  that execute the following procedural   paragraphs.  These procedural paragraphs specify the action to be taken.  After the procedure is executed, control is returned  to the routine that activated it.  Exception and Error have the same meaning and can be used interchangeably.

 

n                  Debugging Aid

 

DECLARATIVES

 

USE   AFTER    STANDARD   {EXCEPTION/ERROR }

 

PROCEDURE    ON                filename1, filename2 ..

                                                        INPUT

                                                        OUTPUT

                                                        EXTEND

                                                        I-O

END-DECLARATIVES

 

Declaratives Section – Example 1

 

01  END-INPUT               PIC    X   VALUE   SPACE.

      88  END-OF-INPUT             VALUE “E”.

01  ERROR-FLAG               PIC    X   VALUE   SPACE.

      88  ERROR-TRUE             VALUE “1”.

01  ERROR-DATA.

      05  FILLER     PIC  X(21)  VALUE “STATEMENT FAILING  IS”.

      05 OP-NAME   PIC   X(9).

      05  FILLER   PIC  X(16)   VALUE “FILE STATUS  IS”

      05  STATUS-VALUE    PIC XX.

01  INPUT-MSG.

      05 FILLER   PIC  X(30)  VALUE “ERROR   ON INPUT FILE”.

01  I0-MSG.

      05 FILLER   PIC  X(30)  VALUE “ERROR ON MASTER  FILE”.

01  OUTPUT-MSG.

      05 FILLER   PIC  X(30)  VALUE “ERROR ON OUTPUT FILE”.

 

 

 

Declaratives Section – Example 2

 

PROCEDURE DIVISION.

DECLARATIVES.

INPUT-ERROR SECTION.

              USE AFTER STANDARD ERROR PROCEDURE ON INPUT

INPUT-ERROR-PARA.

                 DISPLAY INPUT-MSG.

              MOVE  INPUT-STATUS TO STATUS-VALUE.

              DISPLAY ERROR-DATA.

              SET ERROR-TRUE  TO  TRUE.

I-O-ERROR SECTION.

              USE AFTER STANDARD ERROR PROCEDURE ON I-O.

I-O-ERROR-PARA.

              DISPLAY  IO-MSG.

OUTPUT-ERROR SECTION.

              USE AFTER STANDARD ERROR PROCEDURE ON OUTPUT.

OUTPUT-ERROR-PARA.

              DISPLAY  OUTPUT-MSG.

END DECLARATIVES.

MAIN-PROCESSING  SECTION.

 

 

Inter Program Communication

 

The  inter program communication   facility provides  the capability of transfer of control from one program to another and the capability of accessing  same data items  by two or more programs.   The calling program  contains the CALL  statement  and the called program  is the sub program.    The using phrase  makes the referenced  data items in the calling program available to the called subprogram.   These referenced data items must be defined in the Linkage Section.  The number of operands  in each using phrase must be identical.  The on exception  handles exceptions that result from  program existence, authority and storage.

 

 

Cancel

 

The memory space  occupied  by the program  is released to  the operating system after its cancellation.  The next time the referenced  subprogram is called, it will   be in its initial state, rather than    “last used state”.  A program that has been called  but has not yet executed  its EXIT PROGRAM  statement cannot be cancelled.  If the cancel statement specifies a program  that has not yet been called or that has already been cancelled, no  action takes place for that program. 

 

 

 

 

 

 

 

COPY  - Database File

 

COPY  - Transaction File 1/2

 

COPY  - Transaction File 2/2

 

Call - Example

 

RUN UNIT

 

A run time  is  a set of one or more object programs  which functions as a unit during program execution.  One member  of this set must  be a main program which is not called by any program in the run unit.

 

Program Termination

 

Termination

Main Program

Sub Program

EXIT PROGRAM

Nonoperational

Return to calling program

STOP RUN

Return  to calling  program

Return directly to the program  that called the main program

GOBACK

Return  to calling  program

Return to calling program

 

 

Subfile

 

Select – Transaction File

 

The access mode for  workstation file  which has subfile  keywords specified must be dynamic and relative key clause.  IF the access mode is sequential then relative key clause must not be coded.

 

 

 

 

 

 

              SELECT   DISPLAY-FILE              ASSIGN               TO               WORKSTATION-DSP01

              ORGANIZATION IS TRANSACTION

              ACCESS  IS  DYNAMIC

              RELATIVE  KEY IS   REC-NUM

              FILE STATUS   IS DSP-STAT

              CONTROL-AREA  IS  DSP-AREA.

 

 

 

Write – Transaction (Subfile)

 

This statement  is used to write a subfile record.  The relative record number is specified by the relative key field. 

 

                            WRITE  SUBFILE  record-name [FROM   identifier-1]

                                                                     

                            FORMAT    [IS]     identifier-2

 

                            [{INDICATOR / INDIC}    {IS/ARE}     identifier-3]

 

                            [INVALID    KEY   imperative-statement-1]

                           

                            [NOT    INVALID   KEY     imperative-statement-2]

 

                            [END-WRITE]

 

Subfile Inquiry Tasks

n                  Load Subfile

¨       Write subfile records

 

n                  Display subfile

¨       Write subfile control record

 

n                  Processing

¨       Read subfile control record

 

 

Subfile Phrase I/O

 

n                  If SUBFILE  phrase is specified

¨       Indicates that all formats referred  to by the statement are subfile records (i.e. data records)

 

n                  If  SUBFILE  phrase is not specified

¨       Indicates that none of the formats referred  to by the statement are subfile records

 

n                  Not verified at compile time.

 

n                  If specified incorrectly, file status value will be 92

 

 

SFLPAG = SFLSIZ

 

n                  Useful when

¨       Total number of subfile records to be displayed  will fit on one page   or

¨       Number  of  records to be placed in the  subfile is unknown  and could be  large

 

n                  Program writes one  page of subfile  records  at a  time

 

n                  Subfile will not be extended

 

n                  No automatic support for ROLLUP ROLLDOWN  keys

 

SFLPAG    Not  = SFLSIZ

 

n                  Program writes one page of subfile records at a  time

 

n                  Subfile will  be extended

 

n                  ROLLUP  and SFLRCDNBR  keywords required

 

n                  Automatic support for ROLLUP ROLLDOWN  keys

 

Update Using Subfile

 

n                  Program loads the subfile

 

n                  Program displays the subfile

 

n                  User modifies the displayed records

 

n                  Program reads the subfile and updates the file

 

Read – Transaction File Subfile – NEXT MODIFIED

 

This statement   is used only to read a format that is a subfile record.    The next modified reads  the next changed  record in the subfile and the  AT END phrase  is used only   with Next Modified.   

 

              READ  SUBFILE   file-name [NEXT   MODIFIED RECORD]

 

              [INTO identifier-1] [FORMAT  IS identifier-3 / literal-1]                             

              [{INDICATORS/INDIC}     {IS/ARE}    identifier-4]

 

              [ INVALID  KEY         imperative statement-1]

              [NOT  INVALID KEY      imperative statement-2]

             

              [AT END  imperative statement-3]

              [NOT AT END  imperative-statement-4]

              END-READ

 

 

REWRITE – Transaction File Subfile

 

The relative key field determines  which record is updated.

 

 

                            REWRITE  SUBFILE  record-name 

                           

                            [FROM   identifier-1]   

                           

                            [FORMAT  IS   identifier-3 / literal-1]                             

                           

                            [{INDICATORS/INDIC}     {IS/ARE}    identifier-4]

 

                            [ INVALID  KEY         imperative statement-1]

 

                            [NOT  INVALID KEY      imperative statement-2]

                           

                            END-REWRITE

 

To Access Records - Subfile

 

The relative key field determines  which record is updated.

 

n                  WRITE  SUBFILE

 

n                  READ  SUBFILE

 

n                  READ SUBFILE  NEXT MODIFIED

 

n                  REWRITE   SUBFILE

 

Random Read  of Subfile  - Example

The relative key field determines  which record is  read.

 

MOVE   5  TO REC-NO.

 

READ  SUBFILE DISPLAY-FILE

INTO DSP-SUBF-INPUT-REC

FORMAT IS “ORDERL”

INVALID KEY  SET  NO-SF-REC TO TRUE

END-READ.

 

 

Sequential Retrieval  of Subfile  - Example

 

 

 

 

 

 

 

DATA  DIVISION.

                   EOF-FLAG              PIC              1              VALUE  ZERO.

              88  NO-RECORDS                            VALUE  B”1”.

              88  MORE-RECORDS                            VALUE  B”0”.

                   REC-NUM              PIC              999              VALUE  ZERO.

PROCEDURE  DIVISION.

              PERFORM  PARA10   UNTIL   NO-RECORDS.

PARA10.

              ADD   1   TO REC-NUM.

              READ  SUBFILE   DISPLAY-FILE  RECORD

              INTO DSP-SUBF-INPUT-REC  FORMAT  IS “ORDERL”

              INVALID KEY SET NO-RECORDS TO TRUE

              NOT INVALID KEY SET MORE-RECORD TO TRUE

              END-READ.

              IF MORE-RECORDS

              ***PROCESS SUBFILE

 

 

Next Modified   - Example 1

 

The first read  statement  read the data from the display screen into the subfile.  The second read retrieves    the first changed record in the subfile.  The subsequent reads retrieve the next changed records.  The relative key field is updated automatically.

 

READ  SUBFILE   DISPLAY-FILE  RECORD

              INTO DSP-CTL-INPUT-REC 

              FORMAT  IS “CONTROLREC”

END-READ.

 

READ  SUBFILE   DISPLAY-FILE 

              NEXT MODIFIED  RECORD

              INTO DSP-SUBFL-INPUT-REC 

              FORMAT  IS “ORDERL”

              AT  END SET  NO-RECORDS TO TRUE

END-READ.

 

 

Next Modified   - Example 2

 

The  records that are changed by the user  have  the  “MODFLG”   is turned  on by  “MDT” returned from the display or a WRITE or REWRITE  of  a subfile record with SFLNXTCHG activated.

 

              PERFORM  PARA-LOOP  UNTIL    NO-RECORDS.

 

PARA-LOOP.

              READ  SUBFILE   DISPLAY-FILE 

              NEXT MODIFIED  RECORD

              INTO DSP-SUBFL-INPUT-REC 

              FORMAT  IS “ORDERL”

              AT  END SET  NO-RECORDS TO TRUE

              END-READ.

 

IF MORE-RECORDS

***PROCESS  THE RECORD  RETRIEVED**********

 

 

SFLNXTCHG

n                    If a subfile record is written (WRITE  or REWRITE) with SFLNXTCHG  active :

¨         The MODFLG  for that record is turned on

¨         The record will be retrieved from   the subfile by a READ SUBFILE NEXT MODIFIED after the next read of the display, even if the user  did not modify any field in that record on the display

 

n                    READ SUBFILE  NEXT MODIFIED  retrieves  records in the subfile with the MODFLG  on.

 

n                    MODFLG is set off when the changed record is retrieved

 

 

SFLCLR

n                  All  records are cleared from the file, but the file still exists

 

n                  There are no active records in the subfile

 

n                  Use  WRITE SUBFILE  to add records to the subfile

 

   

SFLINZ

n                  All  records  in the subfile are initialized

¨       Numeric fields  -  zeros

¨       Character  fields  - blanks

¨       DFT  value for input fields only 

 

n                  All records in the subfile are considered active

¨      To modify these records, you must READ, REWRITE

 

n                  If the subfile is displayed  without editing, the fields will contain their initial values

 

n                  Input capable fields  are underlined on the display

 

  SFLINZ with SFLRNA

n                  All  records  in the subfile are initialized

 

n                  All records in the subfile are considered inactive

¨       To add records, you must   WRITE   SUBFILE

 

n                  The records cannot be read unless written to

 

n                  The display is the same as with SFLINZ without   SFLRNA

 

   

 

 

Indicators  Example 1/2

 

01  SCREEN-IN.

       COPY   DDS-FORMAT1-I  OF   DSPFILE.

       05   FORMAT1-I.

              06  FORMAT1-I-INDIC.

                                       07  IN91      PIC   1   INDIC  91.

              06  PORNBR      PIC S9(6).

01  SCREEN-OUT.

       COPY   DDS-FORMAT1-O  OF   DSPFILE.

       05   FORMAT1-O.

              06  FORMAT1-O-INDIC.

                                 07  IN11      PIC   1   INDIC  11.

                       07   IN12     PIC   1   INDIC  12.

              06  PORNBR      PIC S9(6).

01  WORK-INDICATORS.

              05  IN11           PIC  1.

              05  IN12           PIC  1.              

              05  IN91           PIC  1.

 

Indicators Example  2/2

 

……….

……….

READ   DISPLAY-FILE   INTO   SCREEN-IN

              FORMAT  IS  “FORMAT1”.

MOVE CORRESPONDING  FORMAT1-I-INDIC  TO  WORK-INDICATORS.

…………………

………………

MOVE CORRESPONDING  WORK-INDICATORS.

TO FORMAT1-O-INDIC

WRITE  DISPLAY-REC   FROM   SCREEN-OUT

              FORMAT  IS  “FORMAT”.

 

 

Indicators  Example 

 

The contents  of IND-IN  / IND-out  are copied from/to  the beginning of the record, on a byte  by  byte basis(group  move).  The indicator numbers are ignored.

 

01  IND-IN.

       COPY   DDS-FORMAT1-I-INDIC  OF   DSPFILE.

       05   FORMAT1-I.

              06  FORMAT1-I-INDIC.

                                       07  IN91      PIC   1   INDIC  91.

01  IND-OUT.

       COPY   DDS-FORMAT1-O-INDIC  OF   DSPFILE.

       05   FORMAT1-O.

              06  FORMAT1-O-INDIC.

                           07  IN11      PIC   1   INDIC  11.

                       07   IN12     PIC   1   INDIC  12.

              06  PORNBR      PIC S9(6).

 

READ   DISPLAY-FILE   INTO   SCREEN-IN

              FORMAT  IS  “FORMAT1”      INDICATORS  ARE        IND-IN.

 

WRITE  DISPLAY-REC   FROM   SCREEN-OUT

              FORMAT  IS  “FORMAT”       INDICAOTRS     ARE    IND-OUT.

 

Local  Data Area 

 

n                  1024   bytes of character   data

n                  Automatically created by the system for each job

n                  Pass information between programs in a job

n                  Initialized to blanks

n                  One per job

n                  SBMJOB takes a copy

n                  Defined in the SPEC IAL-NAMES  paragraph

n                  Access with ACCEPT and DISPLAY  statements

 

Special-Names 

 

Accept transfers data to the identifier from the LDA and Display transfer’s data into the LDA.

 

 

ENVIRONMENT  DIVISION.

CONFIGURATION  SECTION.

SPECIAL-NAMES.

              LOCAL-DATA   IS   LDA..

 

ACCEPT   identifier-1        FROM      mnemonic-name.

 

DISPLAY     identifier-1     UPON    mnemonic-name.

LDA Example -1 

CONFIGURATION  SECTION.

SPECIAL-NAMES.

              LOCAL-DATA   IS   LOCAL-DATA-AREA.

. . .

01  LDA-FIELDS.

       02 NO-REC    PIC  S9(3)      VALUE   ZERO.

       02 TOT-ORD  PIC S9(5)V99  VALUE  ZERO.

       02 FILLER      PIC X(1014).

. . .

DISPLAY   LDA-FIELDS      UPON   LOCAL-DATA-AREA.

 

LDA Example -2 

CONFIGURATION  SECTION.

SPECIAL-NAMES.

              LOCAL-DATA   IS   LDA.

. . .

01  LOCAL-FIELDS.

       02 NUM-REC    PIC  S9(3).

       02 TOT-ORDER  PIC S9(5)V99.

       02 FILLER      PIC X(1014).

. . .

 

ACCEPT   LOCAL-FIELDS      FROM  LDA.

 

Externally  Described  Printer File 

 

n                  Less   Coding   -  Describe  once

 

n                  Less Maintenance  -  Change  one place

 

n                  Improved  Documentation  -  Standardize  names

 

n                  Better Performance  -  Less system  overhead

Write  - Format File 

                            WRITE  record-name      [FROM   identifier-1]

                                                                     

                            FORMAT    [IS]     identifier-2

 

                            [{INDICATOR / INDIC}    {IS/ARE}     identifier-3]

 

                            [AT    END-OF-PAGE   imperative-statement-1]

                           

                            [NOT AT    END-OF-PAGE    imperative-statement-2]

 

                            [END-WRITE]

 

Printer File Example  ½

 

ENVIRONMENT  DIVISION.

INPUT-OUTPUT   SECTION.

FILE  CONTROL.

              SELECT  PRINT-FILE                

                            ASSIGN TO FORMATFILE-PRTF01.

 

DATA DIVISION.

FD  PRINT-FILE   LABEL RECORD IS STANDARD.

01   PRINT-REC  PIC   X(132).

 

Printer File Example  2/2

 

WORKING-STORAGE   SECTION.

01  HEADING-REC.

       COPY  DDS-HEADING   OF PRTF01.

01  DETAIL-REC.

              COPY   DDS-DETAIL OF   PRTF01.               

 

PROCEDURE       DIVISION.

PARA01.

              OPEN OUTPUT PRINT-FILE.

PRINT-HEADING

              WRITE  PRINT-REC    FROM    HEADING

                            FORMAT  IS “HEADING”   .

 

PRINT-DETAIL.

              WRITE  PRINT-REC FROM DETAIL-REC 

                            FORMAT IS “DETAIL”  

                            AT   END-OF-PAGE  PERFROM  PRINT-HEADING.

 

 

 

***********************************************************************

 


No comments:

Post a Comment