DATA DIVISION - IBM Mainframe

In the Data Division, you define the characteristics of your data. To save processing time:

  • Place the most frequently referenced data items close together in the Working-Storage Section.
  • Group data definitions of constants together
  • Group data definitions of variables together, separately from the constants
  • Define data in a way that avoids unnecessary conversions

To save yourself time, use the COPY statement in the Data Division. Three types of data are defined in the Data Division:

  • Data used in input/output operations (File Section)
  • Data developed for internal processing (Working-Storage Section)
  • Data from another program (Linkage Section)

Data Used in Input/Output Operations (File Section)

The data you use in input and output operations are defined in the File Section. Naming and describing the input and output files is the File Section's primary function. Data items defined in the File Section are never available to Procedure Division statements until the file has been successfully opened.

The FD file-name is the name used in the Procedure Division when you OPEN and CLOSE files and READ records from them. (For VSAM files, the file-name in the FD entry is also used for a START or DELETE request.) The record description following the FD entry describes the records in the file. You can code this as a level-01 description of the entire record. Then in the Working-Storage Section, you can code a "working copy" that describes the fields of the record.

The record-name established is the object of WRITE and REWRITE statements. For QSAM files only, you can specify one of the following:

  • The record format in the RECORDING MODE clause. Without this specification, the compiler determines the record format based on the RECORD clause and on the level-01 record descriptions.
  • A blocking factor for the file in the BLOCK CONTAINS clause, if the BLOCK CONTAINS clause is omitted, the file will be unblocked. For VSAM files, the BLOCK,CONTAINS clause is treated as comments.

The record description following the FD file-name describes the logical records in the file, following the COBOL rules for data description (level numbers, picture clause, and so forth). A common programming practice is to keep the FD input and? output record descriptions at the 01 level and code more detailed data descriptions (with the fields used in processing) in the Working-Storage Section. READ INTO is used to bring the records into WORKING-STORAGE. Processing occurs on the copy of data in WORKING-STORAGE. A WRITE FROM statement then writes processed data into the record area defined in the File Section.

Data DevelopedforInternalProcessing(WORKING-STORAGE Section)

You can write a program that processes data without performing any input/output operations. In such a program, all the data is defined in the Working-Storage Section. Most programs, however, have a combination of input and output file processing and internal data manipulation; the data files are defined in the File Section, and the data developed by the program is defined in the Working-Storage Section.

Initialize all the data in the Working-Storage Section before you use it. Data read from input files is quite often copied into the Working-Storage Section before processing begins (using the READ INTO statement). A CALL statement with the USING option is more efficient when a single item is passed than when many level-01 items are passed.

Several other techniques that help to make working with Working-Storage data in your program easier and passing this data to subprograms more efficient are to:

  • Keep indentation consistent. The key purpose of indentation is to help the reader understand program relationships and functions. Conventions vary from one programming organization to another. You should follow the standards in effect for your organization. Some ways to do this in the Data Division are:
  • Begin all PICTURE clauses in the same column. The choice of column depends on the length of the longest data-name and on the depth of the level structure. Starting all PICTURE clauses somewhere between columns 32 through 45 is reasonable.
  • Indent continuation lines. This makes it clear that they are part of the same entry. Use a consistent number of spaces, such as 4.
  • Highlight record structure by indenting each successive level by 2 to 4 spaces.
  • Croup individual data items (items that are not part of records) under a higher level.

For example, group individual items that are not part of other records under level-01 entries with descriptive names, such as FLAGS or ERROR-MESSAGES.

  • In addition to indentation, use blank lines to make record groupings clearer.
  • Croup data entries. Group entries under one or only a few level-01 data-names. Then use level-05 and greater to describe logical record areas. Use widely incremented level numbers like 01, 05, 10,15, instead of 01, 02, 03, 04, to allow room for future insertions of group levels. Use level-88 condition-names. Then, if the conditional values must be changed, the Procedure Division coding for conditional tests does not need to be changed.
  • Use standard data-item names. Some general rules to follow in naming your data items are:
  • Conform to internal standards.
  • Do not use reserved words.
  • Select meaningful names.
  • Use meaningful prefixes and suffixes. Careful use of prefixes and suffixes helps to:
  • Make groups and subordination clear. Assign a prefix or suffix for each group item. Use this prefix or suffix on every subordinate item (except FILLER) to associate a file with its records and work areas. This technique makes it easier for a person unfamiliar with the program to find fields in the program listing and to determine which fields are logically parts of the same record or area. For example:

DATA DIVISION

  • Distinguish between similar record fields. For example, if three files all have a date field, use MASTER-DATE, DETAIL-DATE, and REPORT-DATE instead of DATE1, DATE2, and DATE3.
  • Make record and field names meaningful. One convention for making data-names meaningful is prefixing. For example, you can prefix all file names with FILE and all record names with REC, etc. Rising such conventions consistently throughout your program helps readers understand the program's structure and function.
  • Eliminate excessive qualifying. When you use the MOVE statement with the CORRESPONDING option, redefine or rename 'corresponding' names with prefixed unique names.
  • Use the EXTERNAL clause. The EXTERNAL clause allows a data item to be accessed by any program in the run unit that includes a declaration for it. Only level-01 items can be specified as EXTERNAL.
  • Use the GLOBAL clause. The GLOBAL clause allows a data item to be accessed by any subprogram contained within the program that declares it; the contained subprogram cannot itself have a declaration for the data item. Only level-01 items can be specified as GLOBAL.

Data from Another Program (Linkage Section)

Many times an application's solution consists of many, separately compiled programs that call and pass data to one another. A run unit includes one or more object programs and can include object programs from languages other than COBOL. The Linkage Section in a called COBOL program describes the data that is passed from another program. The VS COBOL 11 compiler limits the maximum size of data division elements.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics