S-COBOL Structures

An AppMaster Builder program can be coded in AMB Structured COBOL (S-COBOL) language structures, either in combination with or instead of COBOL statements. S-COBOL structures are procedural, and extend the power of native COBOL, yet simplify and shorten the amount of code you must write.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

You can write a complete AMB program in S-COBOL. There are no differences between S-COBOL and batch COBOL in the Identification, Environment, and Data Divisions. The major differences exist in the Procedure Division.

Reserved Words:

S-COBOL reserved words are the same as ANSI COBOL, plus the following. For a complete list of all AMB reserved words and symbols, see the Help topic Reserved Words.

  • ALWAYS
  • ELSE-IF
  • ESCAPE
  • EVALUATE
  • FALSE
  • FALSX
  • NEVER
  • REPEAT
  • SAGE-TRACE-FLAG
  • TRUE
  • TRUX
  • UNTIL
  • USERNAME (IMS only)
  • WHILE

S-COBOL Structures:

  • You code the S-COBOL structures in paragraphs and statement blocks. A paragraph is denoted by the keyword PARA and a paragraph name, followed by clauses or a statement block. Within a paragraph, indentation determines the exact positioning of statements. A paragraph ends with the next appearance of any Procedure Division keyword.
  • Indentation determines how the statements execute. For example, when you indent a statement under a conditional statement, the indentation tells AMB that this statement is subordinate to the condition.
  • AMB reads an S-COBOL program from top to bottom. The first paragraph performs all other paragraphs. Within paragraphs and statement blocks, statements execute sequentially until conditional statements, PERFORMs, or CALLs modify the sequence of operations. Indentation controls the logical sequence in which lines of source code execute.
  • Code S-COBOL structures in the Program Painter for batch, report, or complex online programs, or in the Program Painter for a simple program.

List of Structures:

The following are the S-COBOL structures.

Verbs
ENTRY

Establish entry point for subprogram.

ESCAPE

Exit from the current paragraph.

EVALUATE

Evaluate conditions; program a decision table.

EXIT PROGRAM

End the execution sequence.

PERFORM

Execute a particular paragraph or section, with or without arguments.

REPEAT

Establish a loop for testing.

SEARCH

Establish looping or conditionals for each WHEN.

STOP RUN

Return control to the operating system.

TRUE/FALSE

Establish true and false flags; test the flags.

UNTIL/WHILE

Form a loop with a test.

USERNAME

Title a procedure generated by the Precompiler.

Conditionals
AT END/INVALID KEY

Test for end-of-file or invalid key condition.

EVALUATE

Evaluate one or more conditions; program a decision table.

IF/ELSE-IF/ELSE

Evaluate one or more conditions.

SEARCH

Establish looping or conditionals for each WHEN condition.

TRUE/FALSE

Establish true and false flags; test the flags.

Error Handling
AT END/INVALID KEY

Test for end-of-file or invalid key condition.

TRUE, FALSE, ALWAYS, NEVER

Use these AMB-supplied flags for testing.

TRUE/FALSE

Establish true and false flags; test the flags.

Flags
TRUE, FALSE, ALWAYS, NEVER

Use these AMB-supplied flags for testing.

Looping
REPEAT

Establish a loop for testing.

UNTIL/WHILE

Form a loop with a test.

Transferring Program Control
ENTRY

Establish entry point for subprogram.

ESCAPE

Exit from the current paragraph.

EXIT PROGRAM

End the execution sequence.

STOP RUN

Return control to the operating system.

General Rules:

  1. When coding paragraph names, at least one character within the first 24 characters must be unique for each paragraph in the program.
  2. Code only one verb per source code line.
  3. Do not code punctuation in the Procedure Division. It is unnecessary and therefore disregarded.
  4. Code punctuation within the Identification, Environment, and Data Divisions that conforms to COBOL rules.
  5. Code structures with consistent indentation. The level of indentation can vary with each new statement block; however, it cannot vary within a statement block of code. We recommend using four additional spaces for each new level of indentation.
  6. Do not code the following structures.
    • PERFORM ... THRU statement
    • GO TO statement
    • SORT|MERGE THRU ... sectionname with INPUT PROCEDURE or OUTPUT PROCEDURE
    • NEXT SENTENCE
  7. Avoid using the double-hyphen (--). The S-COBOL translator frequently creates procedures and flags required for generating ANSI COBOL that are unnecessary and sometimes invalid in S-COBOL. Generated names for these procedures or flags always contain a double-hyphen to avoid conflict with programmed names. Under IMS, the USERNAME parameter can change double hyphens to single hyphens at S-COBOL processing time.
  8. Continue a structure on subsequent lines by coding an ellipsis followed by a space (... ).
  9. Continue a non-numeric literal by splitting the literal and concatenating the parts, which AMB then treats as separate literals. Concatenate non-numeric literals by separating them with an ellipsis, space, two ampersands, and space (... && ), for example,
               REGISTER = " THIS IS A VERY,"
               ... && "VERY LONG LITERAL"
    
  10. Enclose literals with quotation marks. S-COBOL allows both single and double quotation marks within the same program.
  11. Use any of the following relational operators to make comparisons.
    Type of Comparison Relational Operator

    Greater than

    IS GREATER THAN
    IS >
    

    Not greater than

    IS NOT GREATER 
    THAN
    IS NOT >
    IS <=
    

    Less than

    IS LESS THAN
    IS <
    

    Not less than

    IS NOT LESS THAN
    IS NOT <
    IS >=
    

    Equal to

    IS EQUAL TO
    IS =
    

    Not equal to

    IS NOT EQUAL TO
    IS NOT =
    

    Greater than or equal to

    >=
    

    Less than or equal to

    <=
    
  12. Create compound conditions by using ANDs or ORs.
  13. Optionally, use a simplified syntax:
    Abbreviated Syntax S-COBOL/COBOL Equivalent
    A = B
    MOVE B TO A
    A B = C
    MOVE C TO A B
    A = B + C
    COMPUTE A = B + C
    B = B + C
    COMPUTE B = B + C
    A = B - C
    COMPUTE A = B - C
    A = B * C
    COMPUTE A = B * C
    A = B / C
    COMPUTE A = B / C
    A = B + (C * D)
    COMPUTE A = B + (C * D)
    A <+ B
    COMPUTE A = A + B
    A </ B
    COMPUTE A = A / B
    A << B
    MOVE B TO A
    A <* B
    COMPUTE A = A * B
  14. Use the above simplified syntax with any of these verbs: ADD, COMPUTE, DIVIDE, MOVE, MULTIPLY, SUBTRACT

Example:

The following example demonstrates control logic without interrupting the flow or readability of the program with a GO TO. Program control is handled entirely by S-COBOL indentation.
001030  PARA   PAYROLL-CALCULATION  /*PARAGRAPH NAME
001040         IF EMPLOYEE-TYPE = 'HRLY'
001050             IF HOURS-WORKED > 40
001060                 HOURS-BASE = HOURS-WORKED * 2
001070                 HOURS-BASE = HOURS-BASE - 40
001080             ELSE
001090                 HOURS-BASE = HOURS-WORKED
001100                 GROSS-PAY = HOURS-BASE * HOURS-RATE
001110         ELSE
001120             GROSS-PAY = EMPLOYEE-SALARY

Because IF conditions generally require an alternative action, you generally code an ELSE-IF or ELSE statement at the same level of indentation as the IF.

Line: 1040

001040         IF EMPLOYEE-TYPE = 'HRLY'

If EMPLOYEE-TYPE is not equal to HRLY, control passes to the corresponding ELSE statement on line 1110. On the other hand, if EMPLOYEE-TYPE is equal to HRLY, lines 1050-1100 execute.

Lines: 1050 - 1120

001050             IF HOURS-WORKED > 40
001060                 HOURS-BASE = HOURS-WORKED * 2
001070                 HOURS-BASE = HOURS-BASE - 40
001080             ELSE
001090                 HOURS-BASE = HOURS-WORKED
001100                 GROSS-PAY = HOURS-BASE * HOURS-RATE

If EMPLOYEE-TYPE is equal to HRLY, lines 1050-1100 execute. In this case, if HOURS-WORKED is not greater than 40, control passes to the ELSE statement at the same indentation (line 1080). Thus, lines 1060-1070 execute only for hourly employees who have worked over 40 hours, while line 1090 executes for hourly employees who have worked 40 hours or less.

Line:

001110         ELSE
001120             GROSS-PAY = EMPLOYEE-SALARY

Executes for employees who are not hourly.