Dave Higgins Consulting Strategic Technology Consulting and Enterprise Architecture |
Home | What's New | What's Old | Articles | Associates | Interesting Links | Cool Stuff |
Section 6: Generating COBOL Programs from Brackets
Note: This section was originally written under the assumption that the reader would be using an older version of Brackets. Users of the current version (Version 4 for Windows) may still find the information useful, although it has a few different options, including the ability to generate COBOL-85 with nested paragraphs and true generation of DoUntil loops with "Perform ... Until ... With Test After". I'll be glad to update this section if there is sufficient interest from current Brackets users. Just drop me an email.
The
Procedure Division
Introduction
Brackets diagrams can be converted to COBOL format by choosing
the menu options File, Export, Cobol, Go. If you so choose, you
can have Brackets number the generated paragraphs by choosing the
ParaNum=Y option on export. The Topcards option is explained
later.
Although Brackets is not a COBOL compiler, it does have the ability to translate diagrams into COBOL format. Thus, it can be used as a kind of "structured editor" for creating COBOL programs. When using Brackets to create a program design which will be translated to COBOL, there are several conventions to keep in mind. These conventions are discussed in detail in the following sections.
Notice one thing with respect to using the Export COBOL feature of Brackets: although Brackets will create an ASCII text file containing the generated COBOL program, you cannot VIEW the generated COBOL program from Brackets. You can, however, use the main menu of Brackets to drop to DOS (select the DOS option from the Options sub-menu) and use the DOS command "type <cobolfile name> ¦ more" to scan the generated code. Return to Brackets by entering "exit" at the DOS prompt.
The generated ASCII COBOL file can be read into most any other word processor or text editor, and can be compiled by any COBOL compiler.
General
Comments
When creating Brackets diagrams which will be generated as COBOL
code, there are a few general things to keep in mind. The
following comments have little to do with Brackets; they are
simply good programming techniques.
Generating
Paragraphs
Each set (bracket) present in the Procedure Division portion of
the program (more about that in a minute) will be translated into
one paragraph in the generated program. Thus the diagram...
will result in the following COBOL being generated...
PROCEDURE DIVISION.
COMPANY.
____PERFORM COMPANY-BEGIN.
____PERFORM COMPANY-MIDDLE.
____PERFORM COMPANY-END.COMPANY-BEGIN.
____...company begin statements...COMPANY-MIDDLE.
____...company middle statements...COMPANY-END.
____...company end statements...
Notice that Brackets will generate the "PROCEDURE DIVISION." line, and will follow it with the name of the highest level (leftmost) bracket as the first paragraph (there is a way to override this that will be discussed later during the part of the tutorial on the upper divisions). Each subset is translated into a performed paragraph (as are sub-subsets, and so on). Notice that Brackets always capitalizes all letters in the set names and inserts hyphens in all the blanks. It also indents the line correctly and generates the period at the end of each sentence.
Therefore keep in mind that your set names should be shorter than the maximum length for paragraph names in the version of COBOL you will be using, and that your set names will not be translated into reserved words (such as "Working Storage" or "Division"). Brackets DOES NOT check for either of these conditions.
Also notice that you will have to add a "Stop Run" or "GoBack" to the end of your program (generally as the last statement in the highest level).
If you wish to include "Copy" statements in the generated code for library procedures, place them AFTER the "stop run".
Performing Paragraphs If you wish to perform a paragraph from an included copy library, you must enter the word "perform" on the Brackets statement, such as...
perform Included-Subroutine
Otherwise, Brackets will generate all necessary "perform" statements.
Conversely, if an included procedure is to perform a paragraph generated from your Brackets diagram, place the Brackets code definition AFTER the "stop run" as follows...
This may cause a compilation warning on some compilers, since Brackets will generate a "perform" of the module after the "stop run". If so, use a text editor to remove the "perform" statement after the code has been generated.
If you wish to perform the same paragraph from multiple locations, use the "DUP" feature of Brackets to make a duplicate of the paragraph to be performed in each place you wish the code to be executed. Thus this diagram...
will generate the following...
COMPANY.
____PERFORM COMPANY-BEGIN.
____PERFORM COMPANY-END.COMPANY-BEGIN.
____PERFORM COMMON-ROUTINE.COMMON-ROUTINE.
____...common routine statements...COMPANY-END.
____PERFORM COMMON-ROUTINE.
Generating
Statements
Any feature present on your diagram which is NOT a set will be
translated as follows: all letters will be capitalized and a
period will be added at the end. Further, each statement will
begin in column 12 of the generated line.
Brackets will also break apart long statements into multiple lines. This is done at word boundaries, and only a single period will be placed at the end of the last line generated by the long statement.
If you want Brackets to generate something like the following...
COMPUTE COMPLEX-NUMBER =
____(FIRST-NUMBER * SECOND-NUMBER)
____/ (THIRD-NUMBER).
use the "full screen edit" mode (press F2) to create the lines as you wish them to be generated. Begin the first line in column 1, and press Enter at the end of each line EXCEPT THE LAST. Include any intervening spaces you wish for indentation, and DO NOT put a period at the end of the last line.
DO NOT create three separate Brackets entries for the above...Brackets will treat them as three individual statements and place a period at the end of each line.
DO NOT code multiple sentences into a single full-screen element. Each different generated sentence should come from one and only one Brackets element.
Comments may be generated by placing the asterisk "*" in the first position of a Brackets element. Comments may be as long as you like...if Brackets has to break them into multiple lines it will place the asterisk in column 7 of each generated comment line.
The page break character "/" is also generated in column 7 if it is found as the first character in a Brackets element. The trick is to use the "full screen edit" mode (press F2) to get Brackets to accept the "/" as a character (normally when you press the "/" key Brackets gives you the main menu...this is disabled when you are in full screen mode; you can enter the "/" just like any other character).
By the way if you are in full screen mode DO NOT enter a "#" or "?" character with one or more spaces immediately beforehand: even though they appear normally on the screen Brackets will try to interpret the text following them as a "number of times" and "conditional expression" when you return to "normal" mode. This will cause unpredictable problems when you generate code.
Generating
Loops
Brackets can generate two kinds of loops: the DoUntil (which will
repeat a loop one to many times) and the DoWhile (which will
repeat a loop zero to many times).
The Brackets entry...
Employee `#0,n `?No-More-Employees
will generate the following...
PERFORM EMPLOYEE UNTIL NO-MORE-EMPLOYEES.
If you wish, you may include the word "until" in the conditional phrase following the question mark. Although both the "`#" and "`?" require at least one intervening space before them, there must be no spaces immediately afterwards.
The Brackets entry...
Employee `#1,n `?No-More-Employees
will generate the following...
PERFORM EMPLOYEE. PERFORM EMPLOYEE UNTIL NO-MORE-EMPLOYEES.
Since earlier versions of COBOL do not have a true "DoUntil" construct, this is Brackets way of generating code that is consistent with the design. Although it looks strange, the generated code does work (as long as the design is correct). As before, you may include the word "until" in the conditional phrase following the question mark. Although both the "`#" and "`?" require at least one intervening space before them, there must be no spaces immediately afterwards.
You may optionally use the "varying" clause in the conditional statement. But if you do so you must place the word "varying" immediately after the question mark, and code the entire clause; Brackets will not generate an "until" if the varying option is used. For example...
Vendor `#0,v ?`Varying Vendor-Number from 1 by 1 Until No-More-Vendors
will generate...
PERFORM VENDOR VARYING VENDOR-NUMBER FROM 1 BY 1 UNTIL NO-MORE-VENDORS.
Note that "0,n" or "1,n" (where "n" is any letter or combination of letters) is the only syntax recognized by Brackets for generating loops. The Brackets feature...
Month `#12
will specifically NOT generate the following...
PERFORM MONTH 12 TIMES.
nor will
Month `#1,12
Generating
IF Statements
Simple Alternatives
The following Brackets diagram...
Generates the following code...
INVOICE.
____...INVOICE BEGIN STATEMENTS...
____IF DUE-DATE < TODAYS-DATE
________PERFORM OVERDUE. ...INVOICE END STATEMENTS...OVERDUE.
____...OVERDUE INVOICE STATEMENTS...
Complimentary
Alternatives
The following Brackets diagram...
Generates the following code...
INVOICE.
____...INVOICE BEGIN STATEMENTS...
____IF DUE-DATE < TODAYS-DATE
________PERFORM OVERDUE
____ELSE
________PERFORM NOT-OVERDUE.
____...INVOICE END STATEMENTS...OVERDUE.
____...OVERDUE INVOICE STATEMENTS...NOT-OVERDUE.
____...NON OVERDUE INVOICE STATEMENTS...
Multiple
Alternatives
The following Brackets diagram...
Generates the following code...
INVOICE.
____...INVOICE BEGIN STATEMENTS...
____IF DUE-DATE > TODAYS-DATE
________PERFORM CURRENT
____ELSE IF DUE-DATE < (TODAYS-DATE - 30)
________PERFORM OVERDUE-1-30
____ELSE
________PERFORM OVER-30-DAYS-OVERDUE.
____...INVOICE END STATEMENTS...CURRENT.
____...CURRENT INVOICE STATEMENTS...OVERDUE-1-30.
____...OVERDUE 1-30 INVOICE STATEMENTS...OVER-30-DAYS-OVERDUE.
____...OVER 30 OVERDUE STATEMENTS...
Notice in all cases where there is more than one alternative, the final alternative does not need the conditional clause (the test following the question mark).
The reserved word "if" may optionally be added to the conditional clause in the Brackets statement, providing that it immediately follows the question mark with no intervening spaces.
Notice also that the Brackets statement...
Add A to B `#0,1 `?if x > y
WILL NOT generate the following...
IF X > Y ADD A TO B.
Generating
Sections
You can't.
Generating
Perform-Thru's and Go To's
See "Generating Sections"
The
Upper Divisions
There are two ways to include upper division code
The
TopCards Option
If your upper division entries are contained in a separate ASCII
file created with a text editor, Brackets will "glue"
the upper divisions to the generated Procedure Division if you
specify the file name containing the upper divisions when you
export your COBOL file.
The upper division entries will not be changed by Brackets, and must be syntactically correct.
The $Top Set If you wish to code the upper three divisions on your Brackets diagram, create a set names "$Top" (either upper or lowercase letters in any combination will work) and place it at the very beginning of your highest level as follows...
In the $Top set, you may code the following...
Notice that Brackets does only limited formatting in the upper divisions. It will capitalize all entries, and it will indent data definitions when appropriate, but otherwise your entries have to be syntactically valid COBOL statements INCLUDING PERIODS WHERE APPROPRIATE.
Reserved
Characters
Take care to remember that both the pound sign "#" and
the question mark "?" are reserved characters in
Brackets when preceeded by one or more spaces. Therefore when
coding literals in the Data Division of your COBOL program, you
must break up the literal so that some other character than a
space preceedes either of the reserved characters. This can
easily be done by breaking up the literal so that the pound sign
or the question mark is the first character in some portion of
the literal as follows:
____05 Filler
Pic X(9) Value "Customer ".
____05 Filler Pic X(16) Value "# Customer
Name".
Fixed
Entries in the Procedure Division
If you must have entries in the Procedure Division which come
BEFORE the first paragraph, you must do it in the following
way...
This will cause Brackets to generate the "Company" paragraph after the statements which must be first in the Procedure Division.
Special
Cases
The $Work Set
If you wish, you can place a set called "$Work" at the
beginning of any set that would normally be considered a
"procedure division" set. In the $Work set you may
place working-storage section entries as you would in the $Top
set--at code generation time Brackets will "harvest"
all of the $Work paragraphs and place their entries in the
Working-Storage Section of the generated program.
Previous Section | Next Section |
Home | What's New | What's Old | Articles | Associates | Interesting Links | Cool Stuff |
This web site and all
material contained herein is Copyright ©2002-2009 Dave
Higgins. All Rights Reserved. For additional information,
please contact me at: |