In my one of the code, I am reading the data from CSV file and assigning to working fields by Unstrung function delimited by ';'.
Issue:
When I am reading the file for the decimal values (like 2.33 / 11.03 .. etc) data is not populating properly if i define working field as 9(2)V9(2)
So i had define as X(5) and doing the data population.
01 CSV-FILE
03 CSV-EE-ST-DATUM PIC X(10).
03 CSV-EE-WRDE PIC X(05). <--- which is decimal like 2.33
03 CSV-KOOPSOM PIC X(13).
Procedure:
UNSTRING CSV-RECORD
DELIMITED BY C-DELIMITER
OR ALL LOW-VALUES
INTO CSV-EE-ST-DATUM,
CSV-EE-WRDE
CSV-KOOPSOM
TALLYING IN H-NO-OF-FIELDS
END-UNSTRING.
But later below steps, i need to insert the data to table field
Code:
Move CSV-EE-WRDE to CSV-EE-WRDE1 <---- move is not populating as expected
Move CSV-EE-WRDE1 to CSV-EE-WRDE2 <---- move is not populating as expected
Table Move
Move SV-EE-ST-DATUM TO EINDLABEL-LABEL
Move CSV-EE-WRDE2 TO CONTRACTValue
Move CSV-KOOPSOM TO RUBRIEK
INSERT INTO Table-Name (field1, field2, field3) from (EINDLABEL-LABEL,CONTRACTValue ,RUBRIEK )
Code:
Table field declaration ( which is already existed, alter not possible )
10 EINDLABEL-LABEL PIC X(10).
10 CONTRACTValue PIC 9(02)V9(02) USAGE PACKED-DECIMAL.
10 RUBRIEK PIC X(13).
Could any one help me getting proper values for the decimal part.
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
You apparently do not understand that a V in a PICTURE clause (like 9(2)V9(2) for example) means that the decimal point does NOT appear -- it is implied. And an actual decimal point in the data will cause problems since it is NOT implied.
If you are sure that your data will ALWAYS be 2 digits followed by a decimal point followed by 2 digits, use PIC 9(2).9(2) so the decimal point is explicit. If there is a chance of the data not being 2 digits followed by a decimal point followed by 2 digits, use the FUNCTION NUMVAL to convert an X(5) into numeric data.
Besides of already mentioned problem with COBOL format including 'V' marker, there is another, more serious problem, particularly with CSV data: the length, and position of each field are not fixed (otherwise it wouldn't be a CSV, but fixed format records).
The TS did not give any example of his input data. For CSV we might assume
Code:
1234 , 56 , 789 , 10 , 5 , .....
or
Code:
1234 ; 56 ; 789 ; 10 ; 5 ; .....
or
Code:
1234 | 56 | 789 | 10 | 5 | .....
or
Code:
"1234";"56";"789";"10";"5"; .....
or
Code:
"1.34";"-5.6";"+78.9";"-1.0";"+.5"; .....
etc, etc, etc.
In general case it might be a sophisticated task, especially in COBOL, to parse free text of any possible CSV version.
If input data was better formalyzed, it would be much easier to process it.
But later below steps, i need to insert the data to table field
Easiest way is to use DB2 DEC (Decimal) function during the INSERT or prior and move the value to corresponding field in DCLGEN. This is code is clean and no convoluted COBOL logic for such numeric conversions.
Code:
03 CSV-EE-WRDE PIC X(05).
changes to
Code:
DEC(:CSV-EE-WRDE,4,2)
If you don't have DB2 then use DFSORT to achieve this.
If you don't have DB2 then use DFSORT to achieve this.
I agree. If the author is not afraid of SORT tools, the easiest way would be: first to convert CSV data to flat file with fixed fields of desired format, and then to read this normalized file without problems straightforward into COBOL variables with matching definition.
It might be much more simple rather than parsing free-text CSV data in COBOL code, unless some ready-to-use service procedure is available for this conversion.