Skip to main content

Dear Community,

has someone an example of a simple invoice generated using xml and the cobol copybooks created using the cbl2xml utility ?

I do not see any difficulty in creating an xml with

<invoice> <supplier> <supplierName>My Name</supplierName> <supplierAddess>My Address</supplierAddress> </supplier> <client> <clientName>My Client Name</clientName> <clientAddess>My Address</clientAddress> </client> <invoiceDate>14/07/2020</invoiceDate> <invoiceId>123456</invoiceId> <invoiceLines> <invoiceLine> <item>Item 1</item> <price>100 €</price> </invoiceLine> <invoiceLine> <item>Item 2</item> <price>200 €</price> </invoiceLine> </invoiceLines> <invoice>

A cpy definition could be the following, then converted with cbl2xml in order to create an xml file from a cobol program. But my concern is : how do I manage the <invoiceLines> section as I have no idea in advance of the number of items per invoice ? Or do I have to split in two cpy files : one for the "fixed" part of the invoice (client name etc.) and another one for the item list ? But then, how to create a single xml file with my final invoice ?

01 invoice. 02 supplier. 03 supplierName pic x(50). 03 supplierAddess pic x(50). 02 client. 03 clientName pic x(50). 03 clientAddess pic x(50). 02 invoiceDate pic 9(8). 02 invoiceId pic 9(6). 02 invoiceLines. 03 invoiceLine occurs ???. 04 item pic x(20). 04 price pic 99999.

Eventually, does anyone know how to link Factur-x ( http://fnfe-mpe.org/factur-x/factur-x_en/ ) to cobol?

Best regards,

Alain

Dear Community,

has someone an example of a simple invoice generated using xml and the cobol copybooks created using the cbl2xml utility ?

I do not see any difficulty in creating an xml with

<invoice> <supplier> <supplierName>My Name</supplierName> <supplierAddess>My Address</supplierAddress> </supplier> <client> <clientName>My Client Name</clientName> <clientAddess>My Address</clientAddress> </client> <invoiceDate>14/07/2020</invoiceDate> <invoiceId>123456</invoiceId> <invoiceLines> <invoiceLine> <item>Item 1</item> <price>100 €</price> </invoiceLine> <invoiceLine> <item>Item 2</item> <price>200 €</price> </invoiceLine> </invoiceLines> <invoice>

A cpy definition could be the following, then converted with cbl2xml in order to create an xml file from a cobol program. But my concern is : how do I manage the <invoiceLines> section as I have no idea in advance of the number of items per invoice ? Or do I have to split in two cpy files : one for the "fixed" part of the invoice (client name etc.) and another one for the item list ? But then, how to create a single xml file with my final invoice ?

01 invoice. 02 supplier. 03 supplierName pic x(50). 03 supplierAddess pic x(50). 02 client. 03 clientName pic x(50). 03 clientAddess pic x(50). 02 invoiceDate pic 9(8). 02 invoiceId pic 9(6). 02 invoiceLines. 03 invoiceLine occurs ???. 04 item pic x(20). 04 price pic 99999.

Eventually, does anyone know how to link Factur-x ( http://fnfe-mpe.org/factur-x/factur-x_en/ ) to cobol?

Best regards,

Alain

To handle an unknown number of occurrences you can use the COUNT IN phrase in conjunction with the OCCURS clause. You would set the OCCURS to the maximum possible number and then on input the COUNT-IN variable would contain the actual number of elements read and on output it would write the number of elements that are specified in the COUNT IN variable. See the documentation here:

If the maximum number of OCCURS items is unknown or is unlimited then there is a method that you can use using dynamic tags to read these in or create files with these constructs. See the example here:


To handle an unknown number of occurrences you can use the COUNT IN phrase in conjunction with the OCCURS clause. You would set the OCCURS to the maximum possible number and then on input the COUNT-IN variable would contain the actual number of elements read and on output it would write the number of elements that are specified in the COUNT IN variable. See the documentation here:

If the maximum number of OCCURS items is unknown or is unlimited then there is a method that you can use using dynamic tags to read these in or create files with these constructs. See the example here:

Dear Chris,

 

I thank you for the prompt answer. I was asking the question because using the occurs/count in clause reserves a huge amount of potentially useless bytes in memory (if occurs is high).

I'll examine the dynamic tags.

Is there somewhere in the whole MF documentation a good and complete cobol program illustrating the possibilities of xml and cobol together ? The documentation is one thing but a real life example facilitates the comprehension of the concepts.

Regards,

Alain 


To handle an unknown number of occurrences you can use the COUNT IN phrase in conjunction with the OCCURS clause. You would set the OCCURS to the maximum possible number and then on input the COUNT-IN variable would contain the actual number of elements read and on output it would write the number of elements that are specified in the COUNT IN variable. See the documentation here:

If the maximum number of OCCURS items is unknown or is unlimited then there is a method that you can use using dynamic tags to read these in or create files with these constructs. See the example here:

Dear Chris,

I had a look at the link here :

"If the maximum number of OCCURS items is unknown or is unlimited then there is a method that you can use using dynamic tags to read these in or create files with these constructs. See the example here:"

The example is given for a read statement. I could find an example on how to organize things when writing an xml file with an unknown or unlimited number of occurs. Do you have one somewhere ?

Best regards,

Alain


Dear Chris,

I had a look at the link here :

"If the maximum number of OCCURS items is unknown or is unlimited then there is a method that you can use using dynamic tags to read these in or create files with these constructs. See the example here:"

The example is given for a read statement. I could find an example on how to organize things when writing an xml file with an unknown or unlimited number of occurs. Do you have one somewhere ?

Best regards,

Alain

The following is an example that shows how you can write and read back multiple elements within an xml document by using the WRITE KEY is data-name and READ NEXT KEY IS data-name statements.

$set preprocess(prexml) warn endp id division. program-id. testxml. environment division. select invoice-file assign "invoice.xml" organization is xml file status is inv-status. data division. file section. xd invoice-file. 01 invoice identified by "invoice". 05 cust-data identified by "custdata". 10 inv-num pic 9(5) identified by "invnum". 10 cust-name pic x(80) identified by "custname" 10 cust-address pic x(80) identified by "address". 05 line-items identified by "detail". 10 product pic x(80) identified by "product". 10 quantity pic 9(5) identified by "quantity". 10 amount pic 9(5).99 identified by "amount". 05 instructions pic x(80) identified by "instructs". working-storage section. 01 inv-status pic s9(3) value zeroes. procedure division. open output invoice-file display "open output = " inv-status move 1 to inv-num move "Micro Focus" to cust-name move "Newbury" to cust-address *> The following will add the first part of the record to the xml document in memory write invoice key is all cust-data display "write = " inv-status *> Add multiple line items to the xml document move "Laptop" to product move 10 to quantity move 5000.00 to amount write invoice key is all line-items move "Desks" to product move 5 to quantity move 2500.00 to amount write invoice key is all line-items *> Add the last element to the xml document move "Free shipping" to instructions write invoice key is instructions *> The write statement without the key is phrase will write the document to disk. write invoice close invoice-file *> Now read it back and display open i-o invoice-file display "open i-o =" inv-status *> read statement without key is phrase populates the xml document in memory read invoice-file display cust-name display cust-address display instructions display product display quantity display amount *> The first read populates the first line item only. *> We can read next thru the key to get the other ones. perform until exit read invoice-file next key is line-items if inv-status not = 0 exit perform end-if display product display quantity display amount end-perform close invoice-file stop run.

The following is an example that shows how you can write and read back multiple elements within an xml document by using the WRITE KEY is data-name and READ NEXT KEY IS data-name statements.

$set preprocess(prexml) warn endp id division. program-id. testxml. environment division. select invoice-file assign "invoice.xml" organization is xml file status is inv-status. data division. file section. xd invoice-file. 01 invoice identified by "invoice". 05 cust-data identified by "custdata". 10 inv-num pic 9(5) identified by "invnum". 10 cust-name pic x(80) identified by "custname" 10 cust-address pic x(80) identified by "address". 05 line-items identified by "detail". 10 product pic x(80) identified by "product". 10 quantity pic 9(5) identified by "quantity". 10 amount pic 9(5).99 identified by "amount". 05 instructions pic x(80) identified by "instructs". working-storage section. 01 inv-status pic s9(3) value zeroes. procedure division. open output invoice-file display "open output = " inv-status move 1 to inv-num move "Micro Focus" to cust-name move "Newbury" to cust-address *> The following will add the first part of the record to the xml document in memory write invoice key is all cust-data display "write = " inv-status *> Add multiple line items to the xml document move "Laptop" to product move 10 to quantity move 5000.00 to amount write invoice key is all line-items move "Desks" to product move 5 to quantity move 2500.00 to amount write invoice key is all line-items *> Add the last element to the xml document move "Free shipping" to instructions write invoice key is instructions *> The write statement without the key is phrase will write the document to disk. write invoice close invoice-file *> Now read it back and display open i-o invoice-file display "open i-o =" inv-status *> read statement without key is phrase populates the xml document in memory read invoice-file display cust-name display cust-address display instructions display product display quantity display amount *> The first read populates the first line item only. *> We can read next thru the key to get the other ones. perform until exit read invoice-file next key is line-items if inv-status not = 0 exit perform end-if display product display quantity display amount end-perform close invoice-file stop run.

Dear Chris,

Thank you so much. This little example has unblocked the situation ! Very useful.

Regards,

Alain


The following is an example that shows how you can write and read back multiple elements within an xml document by using the WRITE KEY is data-name and READ NEXT KEY IS data-name statements.

$set preprocess(prexml) warn endp id division. program-id. testxml. environment division. select invoice-file assign "invoice.xml" organization is xml file status is inv-status. data division. file section. xd invoice-file. 01 invoice identified by "invoice". 05 cust-data identified by "custdata". 10 inv-num pic 9(5) identified by "invnum". 10 cust-name pic x(80) identified by "custname" 10 cust-address pic x(80) identified by "address". 05 line-items identified by "detail". 10 product pic x(80) identified by "product". 10 quantity pic 9(5) identified by "quantity". 10 amount pic 9(5).99 identified by "amount". 05 instructions pic x(80) identified by "instructs". working-storage section. 01 inv-status pic s9(3) value zeroes. procedure division. open output invoice-file display "open output = " inv-status move 1 to inv-num move "Micro Focus" to cust-name move "Newbury" to cust-address *> The following will add the first part of the record to the xml document in memory write invoice key is all cust-data display "write = " inv-status *> Add multiple line items to the xml document move "Laptop" to product move 10 to quantity move 5000.00 to amount write invoice key is all line-items move "Desks" to product move 5 to quantity move 2500.00 to amount write invoice key is all line-items *> Add the last element to the xml document move "Free shipping" to instructions write invoice key is instructions *> The write statement without the key is phrase will write the document to disk. write invoice close invoice-file *> Now read it back and display open i-o invoice-file display "open i-o =" inv-status *> read statement without key is phrase populates the xml document in memory read invoice-file display cust-name display cust-address display instructions display product display quantity display amount *> The first read populates the first line item only. *> We can read next thru the key to get the other ones. perform until exit read invoice-file next key is line-items if inv-status not = 0 exit perform end-if display product display quantity display amount end-perform close invoice-file stop run.
Chris!
Who works today with display commands?