IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Converting FLOAT to Readable format


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Jul 27, 2011 6:26 pm
Reply with quote

In DSNTIAUL, I am trying to unload a float value. When i open the SYSREC file I see values in packed format. I want to know is there any why I can convert the FLOAT values to a readable format while unloading data from the table?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 6:50 pm
Reply with quote

A visit to the film director's couch? Launching fly, hook and line into the water to try to catch a fish?

Or some other sort of "casting"?
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Jul 27, 2011 6:55 pm
Reply with quote

I tried using Cast function --

When I try to cast it to DECIMAL --> Decimal sign was getting lost.
Also when I am trying to cast it as DECIMAL(10,3) then the decimal part was retained but hardcoding 10,3 will not work for all the cases.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Jul 27, 2011 7:17 pm
Reply with quote

I'm not DB2 literate (and maybe I misunderstood your question), but perhaps (assuming this is COBOL) the following could be adapted for converting Floating Point data to displayable (readable) format?

www.ibmmainframes.com/viewtopic.php?p=115071&highlight=#115071

Bill
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Jul 27, 2011 7:21 pm
Reply with quote

COBOL equivalent for FLOAT is COMP-2 .
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Jul 27, 2011 8:22 pm
Reply with quote

For COMP-2 (long Floating Point) fields, if it is redefined as a PIC X(08) and moved to WS-PACKED-X (1:8) it should successfully unpack and be readable in WS-DISPLAY-X (1:16).

The same would apply to COMP-1 (short Floating Point), if redefined as PIC X(04) and moved to WS-PACKED-X (1:4).

In an UNPK instruction (MOVE WS-PACKED-V9 TO WS-DISPLAY-V9), each 4-Bit value unpacks with a high-order 'F' zone.

In the link-solution posted, (after the MOVE statement), WS-DISPLAY-X is always left-justified with low-order ZEROS.

Give it a try (although, no guarantees).... icon_wink.gif

Bill
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Jul 27, 2011 9:02 pm
Reply with quote

char(floatcol) will return the scientific notation : 1.57658E-2
it depends on what you call "readable"
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jul 28, 2011 12:00 pm
Reply with quote

Thanks GuyC... I tried this already... But i want to display it as 0.0157658
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jul 28, 2011 12:33 pm
Reply with quote

Hi All,

I tried the below code....

Code:

SELECT
DECIMAL(SUBSTR(CHAR(1.023E02),1,LOCATE('E',CHAR(1.023E02))-1),31,18)*POWER(10,INTEGER(SUBSTR(CHAR(1.023E02),LOCATE('E',CHAR(1.023E02))+1,LENGTH(STRIP(CHAR(1.023E02))))))
FROM SYSIBM.SYSDUMMY1 ;


Is there any better way to do this? Also will there be any data problem if I use this?
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Jul 28, 2011 4:48 pm
Reply with quote

that is exactly the same as casting it to DECIMAL(31,18)
and it will have the same (or worse) problem with numbers outside 1E-15 or 1E+12
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jul 28, 2011 6:58 pm
Reply with quote

Thanks GuyC
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts InfoSphere OPTIM CSV ouput vs DSNTIUA... IBM Tools 3
Search our Forums:

Back to Top