View Full Version: Csv File Creation With Space In Field

LawsonTalk > Coding, Program Errors and Bugs > Csv File Creation With Space In Field


Title: Csv File Creation With Space In Field


trezaei - January 23, 2006 09:16 PM (GMT)
Hi everyone,
I finally have a question for the forum :coffee:

I have a program which is creating a CSV output file. The receiving program requires for one of the fields to have a space in it and only a space:

1000,1234, ,8383,,,12.45

as opposed to

1000,1234,,8383,,,12.45

you see the difference? After 1234 there is a , , in the first line and a ,, in the second line. How in the world do you put in just a space between the two commas? I suggested that we do ,' ', but that doesn't work for them :banghead: . If anyone can help ...

Thanks

Tan

Ragu - January 23, 2006 09:22 PM (GMT)
Instead of defining the file as CSV in workdef, defined it as TAPE with enough record length to accomondate all fields. Define the fields in your WS. And then in your PD. use a COBOL STRING statement.
Example

STRING VAR1 DELIMITED BY SIZE, VAR2 DELIMITED BY SPACES, ETC.
INTO WORK-FILE-REC.

Ragu

trezaei - January 23, 2006 09:26 PM (GMT)
Yes I was afraid someone would say that. The thing is the program works perfect otherwise and we were hoping there was a way to do this with the CSV file type. I take it your response means that there is no way to do it unless with a different file type.
IMHO, it doesn't make any sense to ask a CSV file to do this because you'd almost never need it, but here we are.

thanks

Tan

bags - January 23, 2006 09:33 PM (GMT)
Ragu's response is a better solution than mine to keep things clean and easier to upgrade, but you might be able to place something temporary in that field and then replace that temporary character with a space using a script after the program has completed running.

tghost - March 28, 2006 06:03 PM (GMT)
Hi Tan,

Have you tried using the hex equivlent of a space in the field? I've run into cases before where I need to populate a field with what would normally be a reserved character and used the hex equivalent instead with quite a bit of success. What I normally do is to define the field in working storage with the value clause being set as the hex equivalent of the character I want to populate. Then I move that working storage field to the field I want to populate. Not sure if it will work in a CSV field, but it's another thing to try.

Good luck,
Ted

trezaei - March 28, 2006 06:13 PM (GMT)
Thats a great idea. I'll give it a try.

T

LawsonsNbr1Fan - March 28, 2006 09:24 PM (GMT)
Can't you use " " in a CSV to flag something as text and to retain the information within it?

tghost - March 28, 2006 10:27 PM (GMT)
Unfortunately you can't just use a " ". The problem is the way that Lawson (and other products) deal with an alphanumeric field. By default, an alphanumeric field is initialized as a blank (or spaces if you prefer to think of it that way). When writing a value to the field, any time the value is left at a blank, or spaces, the field by default is written as ,, (no space). The trick to the original question is to get the CSV file filled with , , instead of the ,, that is normal during the creation of the field. To do that we have to put some legitimate value in the field.

Ted

Milo - April 3, 2006 06:21 PM (GMT)
We've had the same problem. Lawson's CSV work file routines look at the string ", ," and always change it to ",," with one (or more) spaces always stripped out.

I agree with Bags, using an external script is just about the only way to do it. That's what we had to do.



Hosted for free by InvisionFree