View previous topic :: View next topic |
Author |
Message |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Sat Jun 11, 2011 1:24 pm Post subject: Handling Float through Easytrieve |
|
|
Hi all,
I have this requirement of loading 20 byte data in the form of
(-123.456988231876000) from PS file into DB2 column which is defined as FLOAT datatype.(Double Precision occupies 8 bytes)
I tried various possibilities listed as below:
1. Loaded the data as is W 20 A. Failed with S0C7.
2. Conver the data from W 20 A to another variable of W 18 N/W 18 N 15, and then load that data to DB2. But easytrieve thrown error "B204 SQL-INVALID HOSTVAR DATATYPE 836"
3. Tried to move the data W 20 A to packed variable W 9 P 14/ W 10 P 16 and then load that data to DB2. Getting error "B055 INVALID LENGTH, TYPE OR DECIMAL PLACES.
4. Tried to move the data from W 20 A to numeric variable W 18 N 14; which in turn has been moved to another variable of W 10 P 14. Failing with S0C7.
5. Tried to use DB2 CAST scalar function with W 20 A variable. Fetch worked fine with (CAST AS CHAR(20)) but while updating the (CAST AS DOUBLE) failing with -301 SQLCODE.
Is there any way to accomplish this task? Am I missing something in this entire process??
===============================================
Then, I edited my input file to remove decimal point '.' Data in the form of
(-123456988231876000) from PS file into DB2 column which is defined as FLOAT datatype. Now data only 19 bytes.
I had defined MASK while loading the data to numeric variable as
'ZZZ.99999999999999-'. Still unable to load the data as is. Getting S0C7.
===============================================
Then, I edited my input file to remove -ve sign. This time I was able to load the data into table. DB2 assumed my decimal point correctly but it couldn't recognize the -ve sign. So my entire file was loaded to DB as +VE floating point numbers which I don't want.
So to summarize is it that only +ve Float numbers can be handled through Easytrive to load to DB2?
Is there anyway we can load Float data to DB2 at all?
Please let me know if you need any additional info. I have been trying numerous possibilities but couldn't crack it. so thought of taking big brains help!!
-Akella |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sat Jun 11, 2011 2:05 pm Post subject: |
|
|
atakella,
Define the Easytrieve variable as
W 22 A
and move the value as -123.45678901234567890
and in the load card assuming that float data starts at position 35 , use the following control card. External function makes DB2 to take it in numeric format and convert it into float format
Code: |
..
Float_col POSITION(35) FLOAT EXTERNAL(22),
next_col POSITION(57) CHAR(3))
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Sun Jun 12, 2011 11:10 am Post subject: Handling Float through Easytrieve |
|
|
I am sorry if I carried the impression of loading data to DB2 through easy trieve using LOAD CARD. It's basically updation of couple of fields on existing DB2 record. And those two fields are Float data types. And I am facing this problem while updating the record. I get the data through PS, after initial validations and compares, I will try to update these fields to DB2.
So guess, I might not be able to use LOAD CARD as such. I am not quite well into easytrieve, correct me if I am mistaken.
Thanks and awaiting your response. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Sun Jun 12, 2011 3:03 pm Post subject: |
|
|
atakella,
try this (untested)
Code: |
Float_dec W 10 P 15
Float_DEC = -123.456988231876000
|
and use Float_dec to update your db2 table
Kolusu |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Sun Jun 12, 2011 11:55 pm Post subject: Handling Float through Easytrieve |
|
|
Tried....
Code: |
.........
.........
IP-DATA1-ALPHA 155 20 A
IP-DATA2-ALPHA 175 20 A
........
........
WS-DATA1-DEC W 10 P 15
WS-DATA2-DEC W 10 P 15
........
........
JOB
......
......
WS-DATA1-DEC = IP-DATA1-ALPHA
WS-DATA2-DEC = IP-DATA12-ALPHA |
Code: | "B055 INVALID LENGTH, TYPE OR DECIMAL PLACES." |
So, instead I tried to below way....
Code: | .........
.........
IP-DATA1-ALPHA 155 20 A
IP-DATA2-ALPHA 175 20 A
........
........
WS-DATA1-ALPHA W 18 A
WS-DATA1-NUM WS-DATA1-ALPHA 18 N 15
WS-DATA1-ALPHA W 18 A
WS-DATA1-NUM WS-DATA1-ALPHA 18 N 15
WS-DATA1-DEC W 10 P 15
WS-DATA2-DEC W 10 P 15
........
........
JOB
......
......
WS-DATA1-ALPHA = IP-DATA1-ALPHA
WS-DATA2-ALPHA = IP-DATA12-ALPHA
WS-DATA1-DEC = WS-DATA1-NUM
WS-DATA2-DEC = WS-DATA2-NUM |
Got S0C7 at WS-DATA1-DEC = WS-DATA1-NUM instruction. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Jun 13, 2011 11:19 am Post subject: |
|
|
atakella,
You cannot move a alpha-numeric variable directly into a packed decimal field. You need to redefine it and move it.
Take a look at the example here
http://mvsforums.com/helpboards/viewtopic.php?p=24520#24520
You have the data in similar format. First move that value to a zoned decimal format removing the decimal and sign as shown in the example and then move that value to packed decimal field.
Kolusu |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Tue Jun 14, 2011 12:39 am Post subject: Handling Float through Easytrieve |
|
|
Thanks a lot. With the link given, I was able to transform string expression of float value to numeric and then to Packed Decimal and finally to DB2 table as FLOAT(Double Precision).
However, one thing I observed was...
Code: | PS data (String Expression) DB2 data
039.595159999900000 3.9595159999900002E+01
038.601990000030000 3.8601990000299999E+01
044.475806214400000 4.4475806214399999E+01
-076.424460000300000 -7.6424460000300002E+01 |
That means, the last decimal point(15th position) is off by either adding 1 or 2 points OR subtracting 1 or 2 points.
Is this how system behaves? Is there any way to rectify it or just live with it?
Please advice. Once again thanks a ton for your help and time.
-Akella |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Jun 14, 2011 10:30 am Post subject: |
|
|
atakella,
Hmm I think you made a mistake of defining the fields as it increased the decimals to 16 instead of 15. How did you define your Numeric and Packed decimal fields? You need to define the numeric variable as 20 bytes and the packed decimal as 10 bytes.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Tue Jun 14, 2011 9:17 pm Post subject: Handling Float through Easytrieve |
|
|
Please find the declaration I have used.
Code: | WS-DATA1-ALP W 20 A
WS-DATA1-ALP-SIGN WS-DATA1-ALP 1 A 0
WS-DATA1-ALP-WHOLE WS-DATA1-ALP +1 3 N
WS-DATA1-ALP-POINT WS-DATA1-ALP +4 1 A
WS-DATA1-ALP-FRAC WS-DATA1-ALP +5 15 N
...........
...........
WS-DATA1-NUM W 18 N 15 MASK 'ZZZ.999999999999999-'
WS-DATA1-NR-WHOLE WS-DATA1-NUM 3 N 0
WS-DATA1-NR-FRAC WS-DATA1-NUM +3 15 N 0
...........
...........
WS-DATA1-PACKED W 10 P 15
.............
JOB INPUT NULL
............
WS-DATA1-NR-WHOLE = WS-DATA1-ALP-WHOLE
WS-DATA1-NR-FRAC = WS-DATA1-ALP-FRAC
IF WS-DATA1-ALP-SIGN = '-1'
WS-DATA1-NUM = WS-DATA1-NUM * (-1)
END-IF
WS-DATA1-PACKED = WS-DATA1-NUM |
One other thing is though DB2 has last decimal point slightly above 1 or 2 digits, Upon unload the data is rounded off and I am getting exactly the same data I intended to put into DB2. So upon extract of the records, my PS has same data without change in fraction part. May be becuase I have only 15 decimal places defined on my work variable(exactly the same way defined above) but used the oppoiste way....
movement from numeric to alpha.
Request you help if there is anything wrong in the declaration part.
-Akella |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Tue Jun 14, 2011 9:22 pm Post subject: Handling Float through Easytrieve |
|
|
Just to add above, I couldn't define numeric as 20 bytes. The max I could define for numeric is 18 bytes
System throws error for Code: | WS-DATA1-NUM W 20 N |
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Jun 15, 2011 10:58 am Post subject: |
|
|
atakella,
Did you get the right values for negative float values? You defined the sign field as 1 byte field and you are checking for 2 bytes? why are you even checking for -1 ? when you just need to check if it is just a minus symbol?
Why do you have a MASK on a working storage field? Unless you are writing a report that mask does nothing.
You cannot define a 20 byte numeric field however you only have 18 byte of data after the removal of decimal point and the sign.
Also learn to initialize the working storage fields to zero before you manipulate them.
So try this piece of code(untested)
Code: |
WS-DATA1-NUM W 18 N 15
WS-DATA1-NR-WHOLE WS-DATA1-NUM 03 N 0
WS-DATA1-NR-FRAC WS-DATA1-NUM +3 15 N 15
WS-DATA1-PACKED W 10 P 15
WS-DATA1-BYTE1 WS-DATA1-PACKED 01 P 0
WS-DATA1-BYTEN WS-DATA1-PACKED +1 09 P 15
JOB INPUT NULL
WS-DATA1-NUM = 0
WS-DATA1-NR-WHOLE = WS-DATA1-ALP-WHOLE
WS-DATA1-NR-FRAC = WS-DATA1-ALP-FRAC
IF WS-DATA1-ALP-SIGN = '-'
WS-DATA1-NUM = WS-DATA1-NUM * -1
END-IF
WS-DATA1-PACKED = 0
WS-DATA1-BYTE1 = X'00'
WS-DATA1-BYTEN = WS-DATA1-NUM
|
|
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Tue Jun 28, 2011 5:23 am Post subject: Handling Float through Easytrieve |
|
|
Apologies for late reply. I was on vacation.
1. It was my typo error. I did check for minus symbol"-" only in the actual piece of code
2. I masked the working storage field because I am printing the values to SYSOUT for testing purpose. Will remove once I am through successful load/update of float data
3. Agree. 18 byte of data after removal of decimal point and the sign.
4. I did initialize the working storage fields to ZERO, just that I din't paste it over here bcoz I wanted only the declaration and manipulation with them.
5. Tried your piece of code, and
Code: | WS-DATA1-BYTE1 = X'00' | and got error
Code: | B055 INVALID LENGTH, TYPE OR DECIMAL PLACES |
Then, commented that line(for testing) and proceeded with
Code: | WS-DATA1-BYTEN = WS-DATA1-NUM |
However, the data resulted in truncation of highest significant bit(Leftmost bit). Kindly note that I still have the declaration for WS-DATA1-BYTE1
Code: | -176.424460000300000 became 76.424460000300000- |
Anything that I am missing? Please advice. Thanks for your help and time. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Jun 28, 2011 10:25 am Post subject: Re: Handling Float through Easytrieve |
|
|
atakella wrote: |
Then, commented that line(for testing) and proceeded with
Code: | WS-DATA1-BYTEN = WS-DATA1-NUM |
However, the data resulted in truncation of highest significant bit(Leftmost bit). Kindly note that I still have the declaration for WS-DATA1-BYTE1
Code: | -176.424460000300000 became 76.424460000300000- |
Anything that I am missing? Please advice. Thanks for your help and time. |
atakella,
You just can't comment the first byte and expect correct results.
Remove the redefine of the packed decimal field and move it directly
Code: |
WS-DATA1-NUM W 18 N 15
WS-DATA1-NR-WHOLE WS-DATA1-NUM 03 N 0
WS-DATA1-NR-FRAC WS-DATA1-NUM +3 15 N 15
WS-DATA1-PACKED W 10 P 15
WS-DATA1-NUM = 0
WS-DATA1-NR-WHOLE = WS-DATA1-ALP-WHOLE
WS-DATA1-NR-FRAC = WS-DATA1-ALP-FRAC
IF WS-DATA1-ALP-SIGN = '-'
WS-DATA1-NUM = WS-DATA1-NUM * -1
END-IF
WS-DATA1-PACKED = 0
WS-DATA1-BYTEN = WS-DATA1-NUM
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
atakella Beginner
Joined: 07 Jun 2011 Posts: 11 Topics: 2
|
Posted: Tue Jun 28, 2011 11:35 am Post subject: Handling Float through Easytrieve |
|
|
But that is what I tested initially(see my code snippet posted on (14th June).
And I was getting 16 digits after decimal point. And 16th digit is either 1 or 2 numbers added or substracted.
Quote: | ...........
...........
WS-DATA1-PACKED W 10 P 15
.............
JOB INPUT NULL
............
WS-DATA1-NR-WHOLE = WS-DATA1-ALP-WHOLE
WS-DATA1-NR-FRAC = WS-DATA1-ALP-FRAC
IF WS-DATA1-ALP-SIGN = '-1'
WS-DATA1-NUM = WS-DATA1-NUM * (-1)
END-IF
WS-DATA1-PACKED = WS-DATA1-NUM
One other thing is though DB2 has last decimal point slightly above 1 or 2 digits, |
|
|
Back to top |
|
 |
|
|