SiouxCityElvis
Programmer
I am Reading in a sequential file:
TestDataFile.csv
SELECT TESTDATA-FILE ASSIGN TO "TestDataFile.csv"
ORGANIZATION IS LINE SEQUENTIAL
ACCESS IS SEQUENTIAL.
FD TESTDATA-FILE.
01 TESTDATA-FILE-RECORD PIC X(16).
I unstring it into Working Storage fields.
WORKING STORAGE.
01 WS-MSG-RECORD.
02 WS-MSG-FIELDS.
03 WS-MSG-FIELD-1 PIC X(4).
03 WS-MSG-FIELD-2 PIC X(4).
03 WS-MSG-FIELD-3 PIC X(4).
03 WS-MSG-FIELD-4 PIC 9(4).
My UNSTRING Statement is as follows:
UNSTRING-TEST-DATA.
READ TESTDATA-FILE NEXT RECORD
AT END DISPLAY "DONE READING"
NOT AT END
UNSTRING TESTDATA-FILE-RECORD DELIMITED BY ","
INTO
WS-MSG-FIELD-1
WS-MSG-FIELD-2
WS-MSG-FIELD-3
WS-MSG-FIELD-4
END-UNSTRING
END-READ.
Okay. So, when I look at my sequential file it looks like:
abcd,dcba,cbda,4444
But, later in my code after I UNSTRING into my WS fields and do a DISPLAY of my WS-MSG-FIELD-4 it always has 0000 as its value. I find that if I make my TestDataFile.csv record with a trailing comma afer the 4444 i.e.
abcd,dcba,cbda,4444,
My 4444 will show up instead of 0000.
Also, if I don't put a comma after 4444 in my comma-delimited record in TestDataFile.csv, but change my WS-MSG-FIELD-4 to PIC X(4), it shows up on the DISPLAY statement, but is useless when comparing it to a numeric defined value off of another field in a different datafile.
Any suggestions as to how to fix this?
The reason I ask, is because when I load my .csv file into the environment, I don't think I will be expecting to have a "," after the last field(numeric field) on each record. So, I want to be able to handle this properly through my code and by not manually putting a comma after the last field on each record in my sequential .csv file.
Thanks in advance.
-David
TestDataFile.csv
SELECT TESTDATA-FILE ASSIGN TO "TestDataFile.csv"
ORGANIZATION IS LINE SEQUENTIAL
ACCESS IS SEQUENTIAL.
FD TESTDATA-FILE.
01 TESTDATA-FILE-RECORD PIC X(16).
I unstring it into Working Storage fields.
WORKING STORAGE.
01 WS-MSG-RECORD.
02 WS-MSG-FIELDS.
03 WS-MSG-FIELD-1 PIC X(4).
03 WS-MSG-FIELD-2 PIC X(4).
03 WS-MSG-FIELD-3 PIC X(4).
03 WS-MSG-FIELD-4 PIC 9(4).
My UNSTRING Statement is as follows:
UNSTRING-TEST-DATA.
READ TESTDATA-FILE NEXT RECORD
AT END DISPLAY "DONE READING"
NOT AT END
UNSTRING TESTDATA-FILE-RECORD DELIMITED BY ","
INTO
WS-MSG-FIELD-1
WS-MSG-FIELD-2
WS-MSG-FIELD-3
WS-MSG-FIELD-4
END-UNSTRING
END-READ.
Okay. So, when I look at my sequential file it looks like:
abcd,dcba,cbda,4444
But, later in my code after I UNSTRING into my WS fields and do a DISPLAY of my WS-MSG-FIELD-4 it always has 0000 as its value. I find that if I make my TestDataFile.csv record with a trailing comma afer the 4444 i.e.
abcd,dcba,cbda,4444,
My 4444 will show up instead of 0000.
Also, if I don't put a comma after 4444 in my comma-delimited record in TestDataFile.csv, but change my WS-MSG-FIELD-4 to PIC X(4), it shows up on the DISPLAY statement, but is useless when comparing it to a numeric defined value off of another field in a different datafile.
Any suggestions as to how to fix this?
The reason I ask, is because when I load my .csv file into the environment, I don't think I will be expecting to have a "," after the last field(numeric field) on each record. So, I want to be able to handle this properly through my code and by not manually putting a comma after the last field on each record in my sequential .csv file.
Thanks in advance.
-David