Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixed Length to CSV Using COBOL LE

Status
Not open for further replies.

ceh4702

Programmer
Jul 25, 2001
2,065
US
I want to take a fixed length file and convert it to a csv file on an IBM mainframe (VSE/ESA) using COBOL LE for export only. Does anyone have a simple example for a very short file?

I would assume I need variable length records, but I have never used them.

Any links or references would be helpful. If you do not like my post feel free to point out your opinion or my errors.
 
I describe the fixed lenght file, and an second line sequential file with one Element. The length is depending on the delimiter I use in the string command. I use Fujitsu Cobolon windows NT I doesn#t know if it works for you. Sorry for my English but i am from Germany and my English is not so good.



 
Hi,

A CSV file is nothing more than that the elements of you record are separated by a comma. So if you define something like:

01 OUTPUT-RECORD.
03 FIRST-ELEMENT PIC ....
03 COMMA-1 PIC X.
03 SECOND-ELEMENT PIC ...
03 COMMA-2 PIC ...


So you fill the records the usual way and fill the comma-fields with comma's or you can use a pre-defined working-storage record where the comma's have a value ',' already.


An other way to build the file is to string them together like:

STRING FIRST-ELEMENT DELIMITED BY <space or size or so>
',' DELIMITED BY SIZE
SECOND-ELEMENT DELIMITED BY .....

etc. The last element doesn't get a comma.

You can test your output by letting excel reading it.

But, if you are on the mainframe and you have a fixed record, you can also convert it using an IEBGENER utility, which allows you copy the input into an other record and fill in the comma's.

Regards,

Crox
 
Hi All,

I've never used CSV files, though I THINK I've heard some things about them. I'm not sure if I have it right.

Ceh4702 mentions VB recs on O/P. Does that pre-suppose that the A/N fields defined in the I/P rec have trailing blanks that aren't to be moved to the O/P? That raises another question. If the field contains embedded blanks, does the O/P field require quotes or aposts?

RE. numeric fields. Should leading zeros be dropped on O/P?
I'd assume that a numeric I/P field defined as 9V99 must be redefined or moved to a 9.99 field before being moved to O/P. Does it matter to the receiving APP if the numeric field has leading spaces, e.g., ZZ9.99?

If I've got it even half right, ODO has to play a big part in defining the O/P file and the STRING stmt would have to keep track of the rec len.

I'd appreciate comments from anyone who knows the ins and outs.

Thanx, Jack.

 
Well, I'm not an expert on CSV files, but I've done some work on them. One of the problems is that there is NO standard. Different programs interpret/produce CSV files in different ways.

1. If alphanumeric fields may contain a comma, they'll need to be surrounded by quotes. If they then might contain a quote, you have to insert two quotes at that spot. You may also be able to use something other than comma as a field separator; I generally use the bar (&quot;|&quot;).

2. Numeric fields must include the decimal point. Leading/trailing zeros are optional.

3. Dates go in fine as mm/dd/yyyy.

4. I typically use STRING with the POINTER clause to construct the output record. You can use a fixed length record on the mainframe if you want to (the excess trailing spaces will be ignored by the recipient of the file).

5. Successive commas generally will indicate that the missing field is NULL. Depending on the program, you may wish to indicate a missing field by outputing a single space. (Probably only an issue if the CSV file is being imported into a database.)

Good luck

Glenn
 
Thanks for your replies. I may end up using an application to do this type of work. The application is called Decision Analyzer, it is made by a company near Princeton, NJ. If you do not like my post feel free to point out your opinion or my errors.
 
hello
what's a csv file ? i couldn't guess from the answers.
Thanks
 
Hi Claude,

As I said before, I'm no CSV expert. I THINK it stands for:
C omma
S eparated
V ariables

Meaning that a CSV file might look something like this:
&quot;jack sleight&quot;,1234,&quot;my my&quot;,&quot;etc.&quot;

As stated by others, quotes and commas as part of the text in the file, is problematic. There are methods to do this, but I'm not sure of them. Double or triple quotes/commas or some such.

HTH, Jack.
 
Thank you.
Crox said it but i missed it :A CSV file is nothing more than that the elements of you record are separated by a comma.
How about using a JCL to do that ?
OUTREC FIELDS=(field-1,X'4F',field-2,X'4F'.....) ?



 
Claude,

If I'm not mistaken, the trailing blanks are usually squeezed out of the field before the comma is placed. That's why STRING or ref mod is used (I think).

Jack
 
Hello Claude,

in Europe you often use instead of coma a semikolon to separate the fields. The reason that in Germany and other European countrys decimal point is a coma and not a point like in the USA. So you doesn't need the quotation mark at all, so done in the Grman &quot;Datanorm&quot; Version 4 or 5.

It is easy to use string and to seperate the fields to use unstring with an delimiter.

Sorry for my english but i am from Germany.

Goetz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top