3. Embedded SQL for COBOL : Preprocessor Operation : Coding Requirements for Embedded SQL Programs : COBOL Periods and Embedded SQL Statements
 
Share this page                  
COBOL Periods and Embedded SQL Statements
You can place a period following the END-EXEC statement terminator (for more information, see Embedded SQL Statement Syntax for COBOL (see page Embedded SQL Statement Syntax for COBOL) in this chapter), although the preprocessor does not require this. If you do include a period at the end of an embedded SQL statement, the preprocessor places a period at the end of the last COBOL statement generated by that embedded SQL statement. Therefore, when you include periods in embedded SQL statements, be careful to follow the same guidelines that you use for placing periods in COBOL statements. For example, do not add a period at the end of an embedded SQL statement occurring in the middle of the scope of a COBOL IF or PERFORM statement. If you include the separator period in such a case, you will prematurely end the scope of the COBOL statement.
Similarly, when an embedded SQL statement is the last statement in the scope of a COBOL IF, you must follow it with a period (or, alternatively, an END-IF) to terminate the scope of the IF. For example:
    IF ERR-NO > 0 THEN
* Do not use a separating period in the middle
* of an IF statement.
        EXEC FRS MESSAGE 'You cannot update the database'
END-EXEC
* Be sure to use a separating period at the
* end of an IF statement.
        EXEC FRS SLEEP 2 END-EXEC.
In the example above, the absence of the period after the first end‑exec causes the preprocessor to generate code without the separator period, thus preserving the scope of the IF statement. The period following the second end‑exec causes the preprocessor to generate code with a final separator period, terminating the scope of the IF.
The embedded SQL preprocessor always generates necessary separator periods when translating embedded SQL block structured statements, such as a select or unloadtable loop, into COBOL paragraphs. The end‑exec statement terminator associated with these statements and with their begin clauses cannot be followed by a period. A period will cause a preprocessor syntax error on the subsequent components of the block structured statement.
In a display loop, periods are allowed in the statement blocks of initialize and activate statements and following the finalize statement.
The following example shows the use of the period in block‑structured statements and display loops.
EXEC FRS FORMS END-EXEC. -- Period allowed

EXEC FRS DISPLAY empform END-EXEC -- No period
EXEC FRS INITIALIZE END-EXEC -- No period
EXEC FRS BEGIN END-EXEC -- No period
    ESQL, COBOL statements -- Periods allowed
    EXEC SQL SELECT * INTO :emp_rec
           FROM employee END-EXEC -- No period
    EXEC SQL BEGIN END-EXEC -- No period
    ESQL, COBOL statements. -- Periods allowed
    EXEC SQL END END-EXEC. -- Period allowed
EXEC FRS END END-EXEC -- No period

EXEC FRS ACTIVATE FIELD emp_name END-EXE -- No period
EXEC FRS BEGIN END-EXEC -- No period
    EXEC FRS SUBMENU END-EXEC -- No period
    EXEC FRS ACTIVATE frskey3 END-EXEC -- No period
    EXEC FRS BEGIN END-EXEC -- No period
        ESQL, COBOL statements. -- Periods allowed
        IF condition THEN
            ESQL, COBOL statements -- No periods
        ELSE
            ESQL, COBOL statements -- No periods
        END-IF. -- Period optional
                                            (COBOL rules)
        PERFORM UNTIL condition
            ESQL, COBOL statements -- No periods
        END-PERFORM. -- Period optional
                                            (COBOL rules)
     EXEC FRS END END-EXEC -- No period

EXEC FRS END END-EXEC -- No period

EXEC FRS ACTIVATE MENUITEM 'Save' END-EXE-- No period
EXEC FRS BEGIN END-EXEC -- No period
  EXEC FRS UNLOADTABLE empform employee END-EXEC -- No period
  EXEC FRS BEGIN END-EXEC -- No period
        ESQL, COBOL statements. -- Periods allowed
    EXEC FRS END END-EXEC. -- Period allowed

EXEC FRS END END-EXEC -- No period

EXEC FRS FINALIZE END-EXEC. -- Period allowed
A period after the END-EXEC terminator of any of the following statements will cause a preprocessor error:
display
initialize
activate
submenu
formdata
unloadtable
end, (except when used as the final statement of display, unloadtable, formdata, and select loops)
select, when opening a select loop
For more information on COBOL paragraphs and embedded SQL structured statements, see the preceding section.