COBOL

 5 Replies
 1 Subscribed to this topic
 17 Subscribed to this forum
Sort:
Author
Messages
Roger French
Veteran Member Send Private Message
Posts: 549
Veteran Member

It's been a long while since I have posted anything to lawsonguru.

I'm doing a little bit of COBOL development within Lawson v10.

I'm writing a custom program. I have a sort file and a csv file. In the sort file I have defined it in workdef with some fields are of type "Signed" with length 11.2 (for example.

In my custom program data is correctly being written to with the "+" or "-" sign on the fields in the sort file.

If I try to define the CSV file with a signed field, the field actually comes out with something like "303030303.03" for any value in that field. If I define it numeric type, positive numbers are written correctly but negative numbers are missing the "-" sign in the field.

What will actually work in terms of getting a signed field in a CSV file? I've gone through some reviewing COBOL manuals and such but it doesn't seem to work. 

Any tips or advise would be greatly appreciated. I am looking on how to actually get a signed number value correctly defined and working with a CSV work file. I am trying to write a signed numberic value to a CSV work file.

Thanks in advance,

Roger

Sreekanth
Veteran Member Send Private Message
Posts: 477
Veteran Member
I use CSV files all the time. The field is just declared as type = Signed and Size = 11.2 as in any other file. Here is the data in a file created by a dummy custom program: "Text","Amt" "LINE1",100.00 "LINE2",-201.98
Roger French
Veteran Member Send Private Message
Posts: 549
Veteran Member

Yep, I agree, but the CSV values for the negative numbers are still coming out as:

303032323.93 

For any number that is moved there, negative or not.

Example:

MOVE -13.55                  TO     WS-EXAMPLE.

MOVE WS-EXAMPLE    TO     WS-TEMP-EXAMPLE.

...

MOVE WS-TEMP-CSV-REC  TO CSV-ZZ165CSV-REC.

PERFORM 800-WRITECSV-ZZ165CSV.

...

OPEN CSV FILE

DISPLAY CSV-EXAMPLE   ---> 303032323.93 

---------

Working Storage

02 WS-TEMP-CSV-REC

    05  WS-EXAMPLE         PIC S9(09)V99 VALUE ZEROES.

 

In the CSV work file definition I've got:

EXAMPLE                        SIGNED 11.2

 

Sreekanth
Veteran Member Send Private Message
Posts: 477
Veteran Member
The group move of WS-TEMP-CSV-REC to CSV-ZZ165CSV-REC may be the issue. When the COBOL shell is built, the numeric fields in the CSV file are built as COMP-3. In my example 000098 01 CSV-CSVFILE-REC. 000099 02 CSV-TEXT PIC X(70). 000100 02 CSV-AMT PIC S9(9)V9(2) COMP-3. When you move S9(9)v99) to a field that is S9(9)v99 COMP-3, bits get moved in ways you do not expect. Try moving values to the individual fields in the CSV file, for example, -13.65 to CSV-EXAMPLE . Or try doing a bldsh, look at the Cobol code generated and match your WS layout to the CSV file layout you see in the .cbl file
Rajashanmugam
Basic Member Send Private Message
Posts: 18
Basic Member
I was in sam situation. All I did was initialize the fields to zeroes before moving/adding the values to CSV file fields and it worked.
Rajashanmugam
Basic Member Send Private Message
Posts: 18
Basic Member
I have another issue. I am working on a interface file. CSV file. I have to sort the data before I can write it to CSV file. I do it and when I move the sorted dollar amount to CSV file I get the similar numbers as described in the first post. Number 2020681795023.67 is supposed to be -121500.00 I tried everything, initialization of variables, fields just before moving the numbers. I tried moving the number -121500.00 directly to the field and they look fine in CSV file. But when I move the data from sort file, I get those gibberish numbers. I have corrected those error s before by initializing the variables. But the program did not use any sort file in that.