SourceForge.net Logo   Cobol To Xml

Batch Scripts
 

Batch Scripts

<p>These are the options you can use when calling <b>Data2Xml</b> and <b>Xml2Data</b> programs to convert Cobol data files to/ from Xml Files:
          -cobol	- Cobol  copybook used to "interpret" the data (you must supply either a cobol or cb2xml copybook  
          -cb2xml	- Cb2xml copybook used to "interpret" the data  
 
          -input	- Input file  
          -output	- Output file  
          -font  	- Characterset used in the Cobol data file (e.g. IBM037 for US-EBCIDIC)  
 
          -dropCopybookName	- (true/false) wether to drop the cobol copybook name from the start of the Xml Tags  
 
          -mainXmlTag     	- The outermost Xml tag to use (default coboldata)  
 
          -tagFormat     	- How Cobol Variable names are reformated to Xml tags:  
               Asis       	- Use the Cobol Variable name  
               Underscore 	- Convert - to _,         COBOL-VAR-NAME ==> COBOL_VAR_NAME  
               CamelCase  	- Convert to Camel Case,  COBOL-VAR-NAME ==> cobolVarName  

          -fileOrganisation	- "file organization" of the Cobol data file  
               Text    		- Standard Windows/Unix text file (single byte character-set)  
               FixedWidth 	- File where lines (records) are the same length no \n  
               Mainframe_VB	- Mainframe VB, file consists of <record-length><record-data>  
               GNUCobol_VB	- GNU Cobol VB, file consists of <record-length><record-data>  
 
          -dialect	- Cobol Dialect  
               Mainframe	- Mainframe cobol  
               Futjitsu 	- Fujitsu PC cobol  
               GNUCobol 	- GNU Cobol (little endian, ie intel)  
               GNUCobolBE	- GNU Cobol (big endian, ie IBM, Sun(oracle))  
 
         -split	- Option for Splitting Copybook into seperate records  
               None      	- No Split  
               01        	- Split on 01  
               Highest	- On Highest Repeating  
 
         -recordSelection	- Record Selection, can be used multiple time,  
                                format: -recordSelection RecordName field=value
 
         -recordParent   	- Record Parent, can be used multiple time,  
                               format: -recordParent    RecordName ParentRecord
 
 

Convert a Simple Single Record Cobol file to Xml

The RecordEditor CodeGen of the RecordEditor will generate bat/shell scripts from a Cobol copybook

  ../lib/Cobol2Xml.bat     -cobol G:/Users/BruceTst01/RecordEditor_HSQL/CopyBook/Cobol/DTAR020.cbl ^
                               -fileOrganisation FixedWidth ^
                               -font cp037 ^
                           -input  G:/Users/BruceTst01/RecordEditor_HSQL/SampleFiles/DTAR020.bin   ^
                           -output out/DTAR020.bin.xml

Xml output:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <CobolData>
 3         <Line>
 4                 <DTAR020-KCODE-STORE-KEY>
 5                         <DTAR020-KEYCODE-NO>69684558</DTAR020-KEYCODE-NO>
 6                         <DTAR020-STORE-NO>20</DTAR020-STORE-NO>
 7                 </DTAR020-KCODE-STORE-KEY>
 8                 <DTAR020-DATE>40118</DTAR020-DATE>
 9                 <DTAR020-DEPT-NO>280</DTAR020-DEPT-NO>
10                 <DTAR020-QTY-SOLD>1</DTAR020-QTY-SOLD>
11                 <DTAR020-SALE-PRICE>19.00</DTAR020-SALE-PRICE>
12         </Line>
13         <Line>
14                 <DTAR020-KCODE-STORE-KEY>
15                         <DTAR020-KEYCODE-NO>69684558</DTAR020-KEYCODE-NO>
16                         <DTAR020-STORE-NO>20</DTAR020-STORE-NO>
17                 </DTAR020-KCODE-STORE-KEY>
18                 <DTAR020-DATE>40118</DTAR020-DATE>
19                 <DTAR020-DEPT-NO>280</DTAR020-DEPT-NO>
20                 <DTAR020-QTY-SOLD>-1</DTAR020-QTY-SOLD>
21                 <DTAR020-SALE-PRICE>-19.00</DTAR020-SALE-PRICE>
22         </Line>
23         <Line>

Convert a Xml file Simple Single Record Cobol file

    ../lib/Xml2Cobol.bat   -cobol G:/Users/Bruce01/RecordEditor_HSQL/CopyBook/Cobol/DTAR020.cbl ^
                               -fileOrganisation FixedWidth ^
                               -font cp037 ^
                           -input  out/DTAR020.bin.xml ^
                           -output out/DTAR020.bat.bin

Convert a Multi Record Cobol file to Xml

This converts a multi record file into Xml. Please note the use of

split

used to define how the Cobol Copybook is split into seperate records.

recordSelection

Defines how to determine one record from another.

   ../lib/Cobol2Xml.bat    -cobol G:/Users/Bruce01/RecordEditor_HSQL/Copybook/Cobol/amsPoDownload.cbl ^
                                 -fileOrganisation Text ^
                                 -split 01 ^
                                 -recordSelection PO-Record  Record-Type=H1 ^
                                 -recordSelection Product-Record  Record-Type=D1 ^
                                 -recordSelection Location-Record  Record-Type=S1 ^
                           -input  G:/Users/Bruce01/RecordEditor_HSQL/SampleFiles/Ams_PODownload_20041231.txt   ^
                           -output out/Ams_PODownload_20041231.txt.xml
 

 2 <CobolData>
 3         <PO-Record>
 4                 <Record-Type>H1</Record-Type>
 5                 <Sequence-Number>45.349</Sequence-Number>
 6                      ...
 7         </PO-Record>
 8         <Product-Record>
 9                 <Record-Type>D1</Record-Type>
10                      ...
11         </Product-Record>
12         <Location-Record>
13                 <Record-Type>S1</Record-Type>
14                 <location>
15                         <DC-Number>5043</DC-Number>
16                         <Pack-Quantity>1</Pack-Quantity>
17                 </location>
18                 <location>
19                         <DC-Number>5045</DC-Number>
20                         <Pack-Quantity>1</Pack-Quantity>
21                 </location>
22                    ...
23         </Location-Record>
24         <Product-Record>
25                 ....
26         </Product-Record>
27         <Location-Record>
28                 ....
29         </Location-Record>

Convert a Multi Record Cobol file to Xml (with heirachy)

Some times with multi-record files there is a Record-Hieracrhy between records, in the above file each Po-Record has one or more Product-Records which intern have one or more Location-Record. This hierarchy can be expressed with the -recordParent option.

   ../lib/Cobol2Xml.bat    -cobol G:/Users/Bruce01/RecordEditor_HSQL/Copybook/Cobol/amsPoDownload.cbl ^
                                 -fileOrganisation Text ^
                                 -split 01 ^
                                 -recordSelection PO-Record  Record-Type=H1 ^
                                 -recordSelection Product-Record  Record-Type=D1 ^
                                 -recordSelection Location-Record  Record-Type=S1 ^
                                   -recordParent Product-Record  PO-Record ^
                                   -recordParent Location-Record Product-Record  ^
                           -input  G:/Users/Bruce01/RecordEditor_HSQL/SampleFiles/Ams_PODownload_20041231.txt   ^
                           -output out/Ams_PODownload_20041231.txt.xml
 

In the output Xml; The PO-Record will have child Product-Records which intern have child Location-Records:

 2 <CobolData>
 3         <PO-Record>
 4                 <Record-Type>H1</Record-Type>
 5                 <Sequence-Number>45.349</Sequence-Number>
 6                      ...
 7                 <Product-Record>
 8                         <Record-Type>D1</Record-Type>
 9                         <Pack-Qty>7.0000</Pack-Qty>
10                             ...
11                         <Location-Record>
12                                 <Record-Type>S1</Record-Type>
13                                   ....
14                         </Location-Record>
15                 </Product-Record>
16                 <Product-Record>
17                            ...
18                         <Location-Record>
19                                    ...
20                         </Location-Record>
21                         <Location-Record>
22                                    ...
23                         </Location-Record>
24                 </Product-Record>
25         </PO-Record>

Convert a Xml file to a Multi Record Cobol file

The following script converts a Xml file into a multi record Cobol file. Please note:

   ../lib/Xml2Cobol.bat    -cobol G:/Users/Bruce01/RecordEditor_HSQL/Copybook/Cobol/amsPoDownload.cbl ^
                                 -fileOrganisation Text ^
                                 -split 01 ^
                           -input  G:/Users/Bruce01/RecordEditor_HSQL/SampleFiles/Ams_PODownload_20041231.txt   ^
                           -output out/Ams_PODownload_20041231.txt.xml
 

 

CobolToCsv at SourceForge Download Page Forums