View previous topic :: View next topic
|
Author |
Message |
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
Hi All,
I was trying to read the CSV file format in Cobol , by unstringing the data which comes with a comma delimited .
In the input data i get the numeric data like 99.90. So after i do unstring to write to a output file i want in the format 999{ which is hex for ebcdic.
Hoe we can convert the data from decimal to a non decimal format
Please let me know |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
It would be nice to know: what is “non decimal format”?
As well as: which one is “decimal”?
PIC 99999
PIC 99999 COMP-3
PIC 99999 COMP
PIC 99999 COMP-n
PIC XXXXX
. . . etc . . . |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
@Sergeyken
The Data comes from a SQL Server download thru a CSV File to mainframe.
So in the Data base it will be like Dec(7,2)
and in mainframe copybook we unstring this to S9(07)V99 |
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
We were actually trying to make it like if the input comes
input file >> 18.50
output file should write it like 185}
which means it should be hex at the end |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
vibi wrote: |
@Sergeyken
The Data comes from a SQL Server download thru a CSV File to mainframe.
So in the Data base it will be like Dec(7,2)
and in mainframe copybook we unstring this to S9(07)V99 |
All fields in a CSV file are strictly in character format. That is, PIC X(nnn) in COBOL.
After your DB field DEC(7,2) has been unloaded from a database to CSV format, is is expected to be in PIC X(9) format; please, verify your real unloaded data to be sure, before trying any conversion.
For instance, the following values are expected to be unloaded as follows
Code: |
-123.45 ===> " -123.45" (with two spaces in front of the field)
+123.45 ===> " 123.45" (with three spaces in front of the field) |
Using the link given above, please find out: how to convert in COBOL
PIC X(nnn) ===> PIC S9(07)V99
This must be one of your basic knowledge before starting any coding.
All such very fundamental knowledge is expected to come from technical manuals, rather than from forums. |
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
Thank you Sergeyken
I want the decimal value on the CSV data ( for example 12.20) stored as 122{ in the output file...right now it is stored as 12.20
Usually it will be like that , but not sure why it was not writing as 122{ after the unstring |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
Does your source data have a positive/negative sign?
1220 is neither positive or negative and is generally treated as positive.
122{ is positive while 122} is negative.
Garry. |
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
hi Gary,
data from the csv will come like decimal 10.20...
but when we unstring it it is coming as same thought we unstring this to 9(02)v99
I want the output file to like 102{ to match an existing format |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
Have you tried unstring to a field with the (optional) sign specified ( e.g. PIC S9(02)V99 ) ?
Garry |
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
Yes Gary , I am unstringing to a variable S9(02) V99
I was expecting to come in the format i expected.. like 102{
My understanding is when we unstring it to S99v99 then the decimal portion wont come in the output file...
But right now it is coming like 10.20 itself |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
I'm GaRRy.
It would seem that the values from the .csv file are all unsigned and you want to consider as signed positive. You might try adding +0 to the field to get the sign set to what you want.
Garry. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
Garry Carroll wrote: |
Does your source data have a positive/negative sign?
1220 is neither positive or negative and is generally treated as positive.
122{ is positive while 122} is negative.
Garry. |
Any field unloaded as CSV has mandatory the sign-character as part of it (while for positive values it may be either blank, or '+'). The position of the sign within this field is varying. It is almost free-text format.
There is no such problem when DB records unloaded in flat-file format.
I asked the TS about his actual format, and what are his intentions on handling varying positions of the sign, and leading blanks? My questions were simply ignored.
Conversion of free-text numbers to decimal unpacked numerics requires either a conversion function (if available), or coding a mini text analyzer inside of COBOL code. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
vibi wrote: |
Thank you Sergeyken
I want the decimal value on the CSV data ( for example 12.20) stored as 122{ in the output file...right now it is stored as 12.20
Usually it will be like that , but not sure why it was not writing as 122{ after the unstring |
I know what you mean, but please keep in mind that CSV-formatted numerics (e.g. DEC(7,2) ) do have non-fixed positions of the sign character, as well as leading blanks in front of the numeric value. This is your original problem: free-text parsing. How do you plan to detect negative values in your CSV? You need also to ignore decimal point character somehow, etc.
Code: |
-12345.67
12345.67
123.45
-123.45
0.12
-0.12
. . . etc ... |
|
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
Thank You ,
What i was able to do is unstring the decimal numerics into alphanumeric and then later move the alpha to the S9(07)V99 and then pass it thru a NUMVAL Function where i am able to get the unpacked decimal properly ..
Regarding the negative i am still looking that options.
We are actually creating a file which needs to be passed to downstream application. Earlier there was stored procedure in SQL server which was sending the data to mainframe but now as the DB is moved to cloud they are going to send the data in the CSV format. SO the main intention is to create a flat file similar to the Stored procedure created by SQL server. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
Off-topic.
Has this COBOL program any other purpose except this conversion of CSV format(s) to regular tabulated numeric formats?
If not, the best solution would be - using any of SORT utilities for any desired conversion, including full free-text analysis. |
|
Back to top |
|
|
vibi
New User
Joined: 02 Jan 2022 Posts: 8 Location: India
|
|
|
|
Yes.. first i tried JCl sort to parse but there more than 1000+ in table.. which i think SORT has limitation ..
COBOl module is just to parse and write to a output file |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
vibi wrote: |
Yes.. first i tried JCl sort to parse but there more than 1000+ in table.. which i think SORT has limitation ..
COBOl module is just to parse and write to a output file |
More than 1000+ of what??? Characters? Fields? Records? Datasets? Volumes?
SORT utilities do have much less limitations, and much better performance compared to almost any COBOL code.
In many cases the size of code for SORT utility is 50-100 times less than equivalent COBOL code. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2139 Location: USA
|
|
|
|
Code: |
//CONVERT EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD * - unloaded DEC(7,2) as CSV
. . . . , " -123.45", . . . .
. . . . . . . . . . , " +98765.12", . . . .
. . , " 67123.45", . . . .
//*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC PARSE=(%=(STARTAFT=C','),
%1=(STARTAFT=C'"',ENDBEFR=C'"',
FIXLEN=10)),
BUILD=(%1,SFF,TO=ZDC,LENGTH=7) as if PIC S9(5)V99
SORT FIELDS=COPY
END
//* |
|
|
Back to top |
|
|
|