Program structure for example 6

The following tables show COBOL statements that relate to performing XML Extensions statements. Some COBOL statements (mostly the DISPLAY statements) have been omitted. The source of this example is in the file, example06.cbl.

Initialization

COBOL Statement

Description

XML INITIALIZE.

Execute the XML INITIALIZE statement (no parameters).

If Not XML-OK Go To Z.

If the statement terminates unsuccessfully, go to the termination logic.

COBOL Statement

Description

Perform 5 Times
 XML GET UNIQUEID
 Unique-Name
 If Not XML-OK Go To Z.

Iterate to export 5 files. Generate a unique identifier. If the statement terminates unsuccessfully, go to the termination logic.

Move Spaces to Unique-File-Name
 String "stamp/a" delimited by size
 Unique-Name delimited by SPACE
 ".xml" delimited by size
 into Unique-File-Name.

Convert the unique identifier into a path name.

Move … To Time-Stamp.

Populate the Time-Stamp field.

XML EXPORT FILE
 Time-Stamp
 Unique-File-Name
 "Time-Stamp".

Execute the XML EXPORT FILE statement specifying: the data item address, the XML document filename, and the ModelFileName#DataName parameter value.

If Not XML-OK Go To Z.
 End-Perform.

If the statement terminates unsuccessfully, go to the termination logic.

COBOL Statement

Description

Perform Until 0 > 1

Outer perform loop. Iterate until Exit Perform.

Perform Compute-Curr-Time
 Compute Stop-Time
 = Curr-Time + 100

The paragraph Compute-Curr-Time ACCEPTs the current time and converts it to an integer value. Compute Stop-Time to be 1 second after current time.

Perform Until 0 > 1
 XML FIND FILE
 "stamp"
 Unique-File-Name
If XML-IsSuccess
 Exit Perform
End-If
If XML-IsDirectoryEmpty
 Perform Compute-Curr-Time
If Curr-Time > Stop-Time
 Exit Perform
End-If
 Call "CBL_THREAD_SLEEP" …
End-If
If Not XML-OK
 Go To Z
End-If
End-Perform

Inner perform loop. Iterate until Exit Perform. Execute XML FIND FILE parameters: directory name and filename. If the statement returned success, exit the paragraph. If the statement returns directory empty, compute new current time, and if the current time is greater than the stop time, exit the perform. Otherwise, do a short time delay. If the statement terminates unsuccessfully, go to the termination logic. The end of the inner perform loop.

If Curr-Time > Stop-Time
 Exit Perform
End-If

Check to see if the outer perform loop should terminate.

XML IMPORT FILE
 Time-Stamp
 Unique-File-Name
 "Time-Stamp"
 If Not XML-OK Go To Z
 End-If

Import the file that was found using: the data item, the filename, and the ModelFileName#DataName parameter value. If the statement terminates unsuccessfully, go to the termination logic.

XML REMOVE FILE
 Unique-File-Name
 If Not XML-OK Go To Z
 End-If

Remove the file that has just been processed; otherwise, find it again. If the statement terminates unsuccessfully, go to the termination logic.

End-Perform

The end of the outer perform loop.

COBOL Statement

Description

Z.

Paragraph-name that is a target of error condition GO TO statements.

Copy "lixmltrm.cpy".

Copy in the termination test logic (see the Termination Test Logic table).

Stop Run.

Terminate the COBOL program.

Copy "lixmldsp.cpy".

Copy in the status display logic (see the Status Display Logic table).

This code is found in the copybook, lixmltrm.cpy.

This code occurs after the paragraph named Z, so that any error condition is obtained here via a GO TO Z statement. If there are no errors, execution "falls through" to these statements.

COBOL Statement

Description

Display "Status: " XML-Status.

Display the most recent return status value (if there are no errors, this should display zero).

Perform Display-Status.

Perform the Display-Status paragraph to display any error messages.

XML TERMINATE.

Terminate the XML interface.

Perform Display-Status.

Perform the Display-Status paragraph again to display any error encountered by the XML TERMINATE statement.

This code is found in the copybook, lixmldsp.cpy.

This code is called twice by the termination test logic: the first time to report any error condition that exists, and the second time to report an error (if one occurs) from the XML TERMINATE statement. If there are no errors (the condition XML-IsSuccess is true), this paragraph displays no information.

COBOL Statement

Description

Display-Status.

This is the paragraph-name.

If Not XML-IsSuccess

Do nothing if XML-IsSuccess is true.

 Perform With Test After
         Until XML-NoMore

Perform as long as there are status lines available to be displayed (until XML-NoMore is true).

  XML GET STATUS-TEXT

Get the next line of status information from the XML interface.

  Display XML-StatusText

Display the line that was just obtained.

 End-Perform

End of the perform loop.

End-If.

End of the IF statement and the paragraph.