COBOL workshop memo

The screens, the file calls, the function cycle and the control breaks: enough to get your 2005 reflexes back, or to pick them up. It is a reference, not an answer key.

The screens

A program is described, not written. Each screen holds part of the model; the COBOL source is generated from the whole, then compiled and run in the browser. The workshop and the terminal share the same model.

WorkshopTerminalWhat you describe there
DictionaryRThe data elements, once: code, label, type X or 9, length, decimals, sign. Their format is used everywhere.
RecordsEThe elements of a file line, in the order they follow each other. The positions come from it.
FilesCThe file calls: code, usage, record, name, argument (control break or matching).
ProcessingTThe program name, the title, and for a listing without a report: filters, columns, detail, totals. The output files.
ReportsKA report described the way the manual does: labels, structures, layout.
(at the terminal)OEntry screens that read and update the tables: description, Segments, mock-up, run.
Structured languagePYour procedures, in functions and sub-functions.
DataDThe content of the input files, typed column by column.
DatabaseB, QDB2-style tables, and an SQL console to query them.
Source, RunG, XThe generated source, then the SYSOUT and the files produced.

File calls

Each file of the program is called with a two-character code, which prefixes its fields, and a usage:

CConsulted: read in sequence. In a listing program, it is the one that gets printed.
PPrincipal: the file being updated. Sorted on its argument, no duplicates.
MTransactions: they update the principal file. Same argument, sorted, several transactions per key allowed. A one-character element gives the transaction code (create, modify, delete).
RResult: the principal file after the update, with the same record.
IPrint: a report is written to it. Its argument is the report letter.

Two kinds of program: the listing (a C file, a report) and the update (P + M give R, with a log). The argument of a C file declares its control breaks; that of P and M, the matching.

The fields of a file

For a file with code FA and an element CUSTNM:

FA00-CUSTNMThe field read. When the file has control breaks or holds transactions, it is the next record, read ahead.
1-FA00-CUSTNMThe record being processed (file with control breaks, transactions, principal file read).
2-FA00-CUSTNMThe updated principal record, before the result is written.
FA-FTEnd of work for the file.
FA-PEn, FA-DEnFirst, last record at level n.
FA-CFn, FA-OCnMatching: the record takes part in the cycle, exists.
W-CUSTNMA working field, declared with the element's format.
D-CUSTNMThe element on the detail line of the simple listing.

The function cycle

The generated program is cut into two-character functions, run in the order of their code. The program loops from F05 to F90, once per record, until the end of the files.

F01Initialization: opening the files, once.
F05Start of iteration.
F10Read (with control break or matching).
F20End of processing: once every file is read, your F20 sub-functions, closing the files, stop.
F22Last-record computation: which record is the last of its group, at each level.
F24 to F39Update: configuration and occurrence (24), total breaks (26), control variables (30), transaction code (33), presence of elements (39).
F70 to F76Update: matching check (70), update (73), error storage (76).
F8E, F8ePrinting: F8E for the simple listing, F8e for the report with letter e.
F90Writes, then back to F05.

Placing your functions

Your sub-functions add to the generated functions (for example 8E 10, 20 10), or form your own functions, placed according to their code. The order is EBCDIC: letters come before digits, so 0A before 00 and 8E before 80.

  • Before F01: once, before initialization. Between F01 and F05: once, after it.
  • Between F05 and F20: on every cycle, after the read, including the last pass.
  • Between F20 and F90: for every record, before or after printing depending on the code.
  • After F90: never on its own, only performed by the P operator.

Control breaks

Control breaks are declared in the call of the consulted file: up to three argument elements, from the broadest to the finest. The program sorts the file on this argument, then reads it one record ahead to know, before processing a record, whether a group starts or ends.

RTPn = 1The record being processed is the first of its group at level n.
RTDn = 1It is the last one: time for the subtotals.
FA-FI = 1Nothing left to read ahead: the record being processed is the last of the file.

A level 1 break triggers those of the finer levels. In the simple listing, each level prints its subtotal; in a report, these are the categories of type 1 to 3, and the grand total is type 0.

Reminder: the field read (FA00-) is the next record, the record being processed is 1-FA00-. Mixing them up shifts everything by one line.

The simple listing

A listing program without a report prints on the SYSOUT a listing set up in the Processing tab:

  • Filters: records that do not pass every filter are skipped (counted as read, not as kept).
  • Columns: the elements of the detail line, and the “print the detail” box.
  • Totals: the numeric elements to total, at each break and in the grand total; “count the lines” adds the number of records.
  • Output files: written from the structured language, with M then ECR.

The structured language

A sub-function starts with an N line: title, level (05, 10…), type and condition. The types: BL block, IT if, EL else, DW while. A sub-function with a higher level nests in the previous one.

M a bMove a to b.
A a b, S a bAdd a to b, subtract a from b.
C W-X = A + BCompute.
P ffPerform function ff.
MES …Display on the SYSOUT.
ECR ddWrite a record of output file dd.
SQL tb aaAccess a table (see the database).
SCO, SROCommit, roll back.
COB …A line of COBOL as is.
*A comment.

Conditions: = # (not equal) > < >= <=, joined by AND and OR.

Reports

A report is printed to a print file (usage I). Its code is the file code followed by its letter: file ET with letter 1 gives report ET1 and function F81. It is described on three screens.

Labels (-L)

The fixed lines, numbered from 01 with no gap, at the report's length.

Structures (-CE)

The elements to place on a line: structure (01, 02…), element, start column, mode, source and condition.

  • Mode: M move, T to total, + or R compute (R rounded), U by you.
  • Source field type: blank for the field read, 1 processing, 2 update, 5 counters, * free expression.
  • Source: FFNNELEMNT (file, segment, element; FA00 alone takes the element of the same name) or a quoted literal.
  • A continuation line (*) holds a + - * / operation on another source, or the rest of the condition.

Layout (-D)

The characteristics (line length, lines per page, items) then the categories: lines printed under the same condition, in code order. Each line: number, type, structure, label, skip before the line, function to run first, condition.

(blank)Ordinary line.
A, ZPage header and footer.
IIterative line, repeated.
*Detail line, totaled.
TDetail never printed, only totaled.
0, 1 to 3Grand total, break total of the level.

Skip 00: overprint; absolute skip * to 01: new page. Items at 0: each line is printed right away, without being stored. The counters 5-dd00-eCL (line in the page), CLM (lines per page), CP (page) and CE (lines written) are used in conditions and sources; CATX is the current category.

Entry screens

A screen has a six-character code, the first two being the Dialogue code (CL0010). It is described at the terminal (option O); the generated program is a pseudo-conversational transaction: each Enter or PF key receives the screen, checks it, updates the database and sends back the next screen.

Description (-CE)

One line per element, in line-number order. View C1: position and presentation; view C2 (PF11): update and source.

  • Positioning: A absolute (line, column), blank relative to the previous field (lines below, or columns after).
  • Nature: V entered, F protected but received, P shown only, O label of the element only, L fixed label (no element), R start of the repetitive part (RV lines, H lines per instance), Z start of the bottom part.
  • Label presentation: L M long on 36, left or right, N useful long, S T U the same with the short label on 18, F element alone, 1 column header.
  • R: required entry. Processing I: transaction code of the category (C create, M modify, D delete); with no transaction code, the update is implicit.
  • Update M: the element updates the given Segment; V: allowed value, one per continuation line. Source: the displayed Segment that feeds the element.
  • LIERR (nature P) receives the error message. PFKEY describes the keys: G or S calls another screen (blank: end of the conversation), V operation code of the key (S next page of the list…).

Segments (-CS)

The tables read or updated: Segment code (table code and two digits), category, reception usage (N L read E existence M modify X create and modify T all three), display usage (A), and the screen field that gives the key (0010-CUSTNO; blank: start of the table).

Mock-up and run

-SIM shows the screen as it will be, keys G and S chain the mock-ups; Clear goes back. -TP runs the transaction on the database; Clear leaves. -G shows the generated source. On an error, the faulty field is flagged, the cursor goes there and nothing is written.

The database

A database runs in the browser, the DB2 way. Each table has a two-letter code: its columns are used as CL-CUSTNM. The SQL operator takes the table code and the access type:

R, RURead by key, read for update.
W, RW, DInsert, update by key, delete by key.
P, RN, CLOpen the cursor (the whole table, in key order), next row, close.

SQLCODE gives the result: 0 found, 100 not found or end of cursor, -803 duplicate key. The database keeps its rows from one run to the next.

The terminal

The same screens on 24 lines of 80 columns. A code on the OPTION line, then Enter: R E C T P D K (then -D, -L, -CE) O (then -CE, -CS, -SIM, -TP, -G) S B Q G X.

  • Tab and Shift+Tab from field to field, Enter sends the screen, F1 to F12 for PF1 to PF12.
  • PF3 back, PF7 and PF8 pages, PF10 and PF11 left and right, PF12 menu.
  • In column A: an action code, S delete, D duplicate, I insert, depending on the screen. An empty line at the bottom is for creating.
  • END, END UPD, END REPORT load the examples; SHARE gives the program's link.