from access+VB 6 to COBOL
does开发者_如何学Python someone know any way to export data from access db to cobol code?
Thanks
Fixed Format is definitely the way to go, any Cobol can read a fixed Format File.
A simple way to create a Fixed Format File in any SQL dialect (oracle, DB2, H2 etc) is to use the SQL String functions to create a single Field and export/write this query to a file
MS Access Example Query:
SELECT Left(Str([TblId])+Space(8),8)
+ Left(Str([tblkey])+Space(20),20)
+ Left([Details]+Space(30),30)
+ "<" AS ExportString
FROM Tbl_TI_IntTbls;
For Cobol it would be best right justify Zero fill and align the decimal points of numeric fields.
Also if this a once off you can run the query in access an copy / paste the output to a Text Editor.
Ms Access also allows you to define Fixed Formats and use these to input ( export ?) but it is a long time since I used them (I was using them to import fixed width data). I will leave discussion of this to an Access Expert.
You could also look at the RecordEditor (http://record-editor.sourceforge.net/Record11.htm) / JRecord (http://jrecord.sourceforge.net/) because
- Both let you View / edit a file using a Cobol Copybooks - useful for checking the export match's the Cobol Definition
- Both have Copybook analysis Option (File Menu) that will calculate the start / length of fields in a Cobol Copybook
- Both have copy function that will copy a Csv File to / from a Cobol File using a Cobol Copybook
Note: This is shameless plug for my software
I would avoid a delimited file (in case the delimiter occurs in a field) but if you must, use an obskure character eg ` or ~ or ^
The easiest way would be to export to a fixed with format from access. That is the native format for Cobol file data descriptions.
However, if access does not support this, you can export to a CSV (Comma Seperated Values) file or a TSV (Tab Seperated Values). Cobol, in its ANSI form, does not support this, but it is very easy to parse with a simple Unstring. For example:
Perform Read-A-Record
Perform until End-Of-File
Unstring Input-Record
delimited by ","
into Column-1-Field
Column-2-Field
...
Column-n-Field
Perform Read-A-Record
End-Perform
Access can export to fixed-field formats via its Export Wizard or a simple VB6 program or a script can do the same thing using the Jet OLEDB Provider and Jet's Text IISAM, with a Schema.ini file that defines the output format.
There are formatting limitations (no signed packed decimal formats or other Cobol exotica) but in general this should suffice for creating files most Cobol variations support. If you truly must have numeric fields left-zero filled you can do that by using the Jet SQL Expression Service which allows inline use of a subset of VBA functions, defining the result field as Text in the Schema.ini file.
If what you really require is export to some sort of ISAM files your best bet is to write an intermediate Cobol program to import the saved field-field text data. Some Cobol products may even include utilities to do this kind of importing.
精彩评论