This is Tikiwiki v2.2 -Arcturus- © 2002–2008 by the Tiki community 2010/09/07 20:06 PDT

Menu [toggle]

Upcoming events

COBOL

Do you use COBOL?
OpenCOBOL 1.0
OpenCOBOL 1.1
OpenCOBOL Other
Other COBOL
Not Yet

View Results
(Votes: 112)
Print

OcOOForm

Using Open Cobol to Write to Open Document Form

Initially this was going to be just some advise on ways to generate forms using ODS and ODT file; however
I ended up starting to write a set of callable routines for working with forms within either open office
spreadsheet or Koffice's kspread. Even thought the screen shots may be of Openoffice I did use koffice for
this project because that package has quite a few templates documents. In fact the invoice template I use
is from kspread.

Bellow is a view of the invoice form to be updated by the cobol program, using the subroutines within
odfscanner. Odfscanner was also written in cobol. Your program updates the form via the values within
the [] brackets, which you enter yourself.



After you have created all of the bracketed fields you need to extract the contents.xml file from the
spreadsheet file invoices.ods. As in the previous article you can use unzip within back to extract all
the files within the spreadsheet to a directory. Also I'm showing you the test data for the invoice run.

^
extracting all files from invoice.ods into template directory
[john@localhost]$ unzip -d template invoice.ods
Archive:  invoice.ods
 extracting: template/mimetype
   creating: template/Configurations2/statusbar/
  inflating: template/Configurations2/accelerator/current.xml
   creating: template/Configurations2/floater/
   creating: template/Configurations2/popupmenu/
   creating: template/Configurations2/progressbar/
   creating: template/Configurations2/menubar/
   creating: template/Configurations2/toolbar/
   creating: template/Configurations2/images/Bitmaps/
  inflating: template/content.xml
  inflating: template/styles.xml
  inflating: template/meta.xml
  inflating: template/Thumbnails/thumbnail.png
  inflating: template/settings.xml
  inflating: template/META-INF/manifest.xml
[john@localhost]$
^
^
View of the test data in invoice1.csv
[john@localhost]$cat invoice1.csv
"invoiceno","invdate","sonumber","custpo","salesrep","shipvia","terms","name","city","st","zip","quantity","unitprice","description"
1,2009-02-28,10002,"po4040",,"bike","none","test company","jelly","fl",,10,0.75,"white bread"
1,2009-02-28,10002,"po4040",,"bike","none","test company","jelly","fl",,50,1.12,"cheddar"
1,2009-02-28,10002,"po4040",,"bike","none","test company","jelly","fl",,15,2.4,"swiss"
2,2009-03-01,20003,"po4120",,"foot","none","test company","jelly","fl",,20,3.01,"mayo"
[john@localhost]$
^
To keep things simple for this article we're just using a csv file for the invoice data. Also I linked odfscanner.o
directly into the writeinvoice program. In order to use the subroutines you need to first set the system variable
to the xml file your using as a template(usually content.xml from the spreadsheet your using) and you need to set the
system varable odfform for the new xml file(bellow I set this to newcontent.xml). After running the writeinvoice program
you need to load the new content file back into the spreadsheet invoice.ods by using the zip -m command. Then you can
run ooffice to view the newly crated form.
^
Compiling writeinvoice.cob and then running the application
[john@localhost]$cobc -c odfscanner.cob
[john@localhost]$cobc -wx writeinvoice.cob odd
[john@localhost]$cp template/content.xml content.xml
[john@localhost]$odffile=content.xml
[john@localhost]$odfform=newcontent.xml
[john@localhost]$export odffile
[john@localhost]$export odfform
[john@localhost]$./writeinvoice
[john@localhost]$cp newcontent.xml content.xml
[john@localhost]$zip -m invoice.ods content.xml
updating: content.xml (deflated 93%)
[john@localhost]$ooffice invoice.ods
^

Bellow are the working storage fields you need to define in order to use odfscanner. You only supply the values
for fieldname, fieldvalue and sheetname at various points within your application. The other fields are used only
by the odfscanner routines.

Following the working storage section I'm showing you the odfscanner routines you need to use to write the form.

  • First you need to call odfscanner which calculates the startpage, endpage and field locations.
  • For each sheet you put into the spreadsheet form you must call odfstartform.
  • All the fields are written to the form by calling odfsetfield
  • Use the odfwritepage call to actually write the form
  • Finish by call odffinishform
^
working storage needed to run odfscanner
01  startpage			unsigned-int value zero.
 01  endpage			unsigned-int value zero.
 01  fieldname			pic x(18) value spaces.
 01  fieldvalue			pic x(100) value spaces.
 01  retcode			unsigned-int value zero.	
 01  sheetname			pic x(10) value spaces.
^

^
"call to the odfscanner subroutine
*>
 procedure division.
*>
 0000-start.
*>
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*>odfscanner preps the template file 
*>that was set to the system varible $odffile.
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
     call "odfscanner"		using startpage,
				      endpage.
^
^
"call to the odfstartform subroutine
else
            call "odfstartform"	using startpage
        end-if
^
^
"call to the odfsetfield subroutine
*>
 0800-odfsetvalue.
*>
     call "odfsetfield" using fieldName,
			      fieldValue,
			      retcode
     end-call.
     if retcode <> 0
        display "0800-odfsetvalue problem with retcode=" retcode
     end-if.
^
^
"call to the odfwritepage subroutine
call "odfwritepage"	using startpage,
                                      endpage,
                                      sheetname
           end-call
^
^
"call to the odffinishform subroutine
call "odffinishform"   using endpage
^
The writeinvoice source can be downloaded from the archive.
You can also download the invoice form ods file here.

You can download odfscanner here but be aware that
this program is very much in alpha test mode. At the moment it only works with ODS (spreadsheet forms) and there
is very little error checking. I would like to change it to justify numeric data better or have it entered as numeric
data instead of string. Also I would also like to add a cobol generator based on the forms file. I also need to
get it set up to create a library within the configure and make routines.






Created by: jrls. Last Modification: Tuesday March 03, 2009 19:13:06 PST by jrls.