Making a program skeleton

Step 1 started with just a fragment of the program in order to show the COBOL data structure.

The interface to the XML Extensions library, a COBOL-callable subprogram, is simplified by using some COBOL copybooks that perform source text replacement. This means that the developer may use XML Extensions statements, which are much like COBOL statements, rather than writing CALL statements that directly access entry points in the XML Extensions library. The COBOL copybooks also define program variables that are used in conjunction with the XML Extensions statements. The copybook, lixmlall.cpy (or at least the copybooks referenced by lixmlall.cpy), must be copied in the Working-Storage Section of the program in order to use XML Extensions. For more information, see copybooks.

To call the XML Extensions library, add the following lines (shown in bold) to the COBOL program fragment from step 1:

Identification Division.
Program-Id. Getting-Started.
Data Division.
Working-Storage Section.
01  Customer-Address.
    02  Cust-Name     Pic X(128).
    02  Address-1     Pic X(128).
    02  Address-2     Pic X(128).
    02  Address-3.
        03  City      Pic X(64).
        03  State     Pic X(2).
        03  Zip       Pic 9(5) Binary.
Copy "lixmlall.cpy".
Procedure Division.
A.
    XML INITIALIZE.
    If Not XML-OK Go To Z.

< insert COBOL PROCEDURE DIVISION logic here >

Z.
Copy "lixmltrm.cpy".
    GoBack.
Copy "lixmldsp.cpy".
End Program  Getting-Started.

The COPY statement is placed in the Working-Storage Section after the data structure.

The Procedure Division header is entered, followed by the paragraph-name, A.

The XML INITIALIZE statement produces a call to the XML Extensions library. The XML INITIALIZE statement may be thought of as similar to a COBOL OPEN statement.

Termination logic is placed at the end of the program. The paragraph-name, Z. , is used as a GO TO target for error or other termination conditions.

The copybook, lixmltrm.cpy, is used to generate a correct termination sequence. A call to XML TERMINATE (similar to a COBOL CLOSE statement) is in this copybook. If errors are present, the logic in this copybook will perform a procedure defined in the copybook, lixmldsp.cpy, which will display any error messages.

The original program fragment is now a working COBOL program that calls the XML Extension library. Its only function is to open and close the interface to the library.

Compile and run the program from the command line as follows:

Windows:

cobol getstarted.cbl xmlgen(ws) noobj; run getstarted

The first parameter of the run command is the name of the COBOL object file.

UNIX:

cob -i -C 'xmlgen(ws)' -P getstarted.cbl; cobrun getstarted.int