This tutorial will help you
to understand:
1.
Follow one of the tutorials up to the Generation
dialog. For Instance, on the "Creating an XML Handler using an XML
Schema" tutorial this is up to step 13.
2.
Check the IDS (Interface Data Structure)
option on Generation dialog.
3.
Press the More Options... button.
The IDS
Generation Options dialog will be shown. Set the Prefix
to XD-, the Suffix
to None
and check the Convert
all names to upper case option. Press OK.

4.
Back on Generation dialog, adjust settings to generate
a Writer,
set the Program
ID / Source Name to BAXSDUW,
set the destination folder, check the Generate IDS
and change its name to BAXSDUWC option, check
the Unbounded
Style option and Generate
.

5.
Upon normal completion, adjust settings to generate a Reader,
set the Program
ID / Source Name to BAXSDUR,
change the IDS
name to BAXSDURC
option and click Generate
.
6.
At the destination folder, you should now have BAXSDUW.cbl,
BAXSDUR.cbl,
BAXSDUWC.cpy
and BAXSDURC.cpy
files, the XML Writer, Reader, Reader IDS and Writer IDS respectively. Main
test programs BAXSDUW_test.cbl
and BAXSDUR_test.cbl (located at Installation Folder/TutorTX/Main
Test Programs) calls BAXSDUW and BAXSDUR to
demonstrate how an Unbounded XML Writer and Reader can be used within a COBOL
main program.
7.
Copy the following files to a temp folder:
BAXSDUW_test.cbl
BAXSDUR_test.cbl
BAXSDUW.cbl
BAXSDUR.cbl
BAXSDUWC.cpy
BAXSDURC.cpy
8.
Launch your favorite COBOL IDE and load these files.
Compile them and run BAXSDUW_test.cbl. It should produce BAXSDU.XML
file using BAXSDUW.cbl.
Let's analyze the most important section of the BAXSDUW_test.cbl
program.
|
*
<ACCOUNT> * * setting number of occurrences to write * | For the
repeating element ACCOUNT we need to keep XC-ACCOUNT-COUNT > 1 * | until we send all occurrences to the writer.
The writer will keep the * | parent element BANK open, until
XC-ACCOUNT-COUNT = 1 * | The writer decrements XC-ACCOUNT-COUNT by 1 at
the end of each call. MOVE 50 TO XC-ACCOUNT-COUNT. PERFORM VARYING WS-II FROM 1 BY 1 UNTIL WS-II > 50 * | Dummy data. ADD 1000, WS-II TO WS-AUX STRING WS-AUX INTO XC-ACCOUNT-NUMBER MOVE 15 TO XC-ACCOUNT-NAME-LEN STRING "ACC-NAME-" WS-II INTO
XC-ACCOUNT-NAME MOVE 15 TO XC-ACCOUNT-OWNER-LEN STRING "ACC-OWNER-" WS-II INTO
XC-ACCOUNT-OWNER MOVE "20041207" TO
XC-ACCOUNT-OPENING-DATE MOVE "152514" TO
XC-ACCOUNT-OPENING-TIME COMPUTE XC-ACCOUNT-BALANCE = 238.35 * WS-II MOVE 1 TO XC-ACCOUNT-COMMENT-FLAG MOVE 15 TO XC-ACCOUNT-COMMENT-LEN STRING "ACC-COMMENT-" WS-II
INTO XC-ACCOUNT-COMMENT MOVE 1 TO XC-ACCOUNT-ADDRESS-FLAG STRING "STREET-" WS-II INTO
XC-STREET-ADDRESS STRING "CITY-" WS-II INTO
XC-CITY STRING "ST-" WS-II INTO
XC-STATE-PROVINCE STRING "COUNTRY-" WS-II INTO
XC-COUNTRY * | Here, we call the writer with command = NEXT
to enable it to check the PERFORM PARA-XML-WRITE-NEXT THRU PARA-XML-WRITE-NEXT-EXIT END-PERFORM. * | We need to call the writer one more time with
command = SPACE, to let * | it close open
elements. * Last Write PERFORM PARA-XML-WRITE-CLOSE THRU PARA-XML-WRITE-CLOSE-EXIT * Write XML document to a file PERFORM PARA-XML-DOC-APPEND THRU PARA-XML-DOC-APPEND-EXIT * Close XML file and log PERFORM PARA-TIMESTAMP-LOG THRU PARA-TIMESTAMP-LOG-EXIT CLOSE DATA-FILE CLOSE XML-FILE |
9.
Run BAXSDUR_test.cbl. It will read back the
XML file.
Let's take a look at the main section of this program.
|
* | The
first read must be done with XML-COMMAND-CODE = SPACE * | The
Reader will go through the entire document. * * First read * PERFORM PARA-XML-READ THRU PARA-XML-READ-EXIT * |
After the first read, * |
first occurrences of data will be populated. * |
XML-REMAIN-... will have number of * |
elements remaining * | The
reader will return XML-RETURN-CODE-OK if there is * | no
more data, XML-RETURN-CODE-MD if there is more. * | The
reader may also report errors on first read * | If
there are mandatory nodes missing or there * | are
foreign elements within non-extensible elements. * *
Continue reading until there is no more data * <ACCOUNT> * PERFORM UNTIL WS-XML-PROCESSING-ERROR OR XD-XML-REMAIN-ACCOUNT <
1 MOVE SPACES TO WS-LINE STRING "ACCOUNT" "--"
XD-XML-MORE-ACCOUNT DELIMITED BY SIZE INTO WS-LINE PERFORM PARA-PROCESS-LOG THRU PARA-PROCESS-LOG-EXIT * | In order to process remaining <ACCOUNT> elements * |
corresponding XC-XML-MORE-ACCOUNT field must be set * | to
"X" before calling the reader with command "NEXT" MOVE "X" TO
XC-XML-MORE-ACCOUNT PERFORM PARA-XML-READ-NEXT THRU PARA-XML-READ-NEXT-EXIT END-PERFORM * * </ACCOUNT> |