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

Convert a Numeric-Edited value to Numeric value


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Raghuraman_New

New User


Joined: 03 Oct 2008
Posts: 43
Location: Chennai,India.

PostPosted: Wed Apr 29, 2009 7:09 pm
Reply with quote

Hi
Need to convert a Numeric_edited value to numeric value

EX.

A pic --,---,---,---,---,--9.99.
B pic S9(16)V9(2).

Need to move A to B.

Thanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 29, 2009 7:12 pm
Reply with quote

look at NUMVAL - it is a COBOL instruction.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Apr 29, 2009 7:32 pm
Reply with quote

Depending on your version of COBOL you could just use a MOVE.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 29, 2009 7:40 pm
Reply with quote

Which version of COBOL? What have you tried and what results have you gotten?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Apr 29, 2009 8:11 pm
Reply with quote

Robert Sample wrote:
Which version of COBOL? What have you tried and what results have you gotten?


Code:
PP 5655-G53 IBM Enterprise COBOL for z/OS  3.4.1 

77  WS-NUMERIC                  PIC  S9(16)V9(2) VALUE ZERO.   
77  WS-NUMERIC2                 PIC  S9(16)V9(2) VALUE ZERO.   
77  WS-NUMERIC-EDITTED          PIC  --,---,---,---,---,--9.99.

    MOVE 123456789.12 TO WS-NUMERIC.                 
    MOVE WS-NUMERIC TO WS-NUMERIC-EDITTED.           
    MOVE WS-NUMERIC-EDITTED TO WS-NUMERIC2.           
    DISPLAY 'WS-NUMERIC ' WS-NUMERIC.                 
    DISPLAY 'WS-NUMERIC-EDITTED ' WS-NUMERIC-EDITTED.
    DISPLAY 'WS-NUMERIC2 ' WS-NUMERIC2.               
    MOVE -9876543.22 TO WS-NUMERIC.                   
    MOVE WS-NUMERIC TO WS-NUMERIC-EDITTED.           
    MOVE WS-NUMERIC-EDITTED TO WS-NUMERIC2.           
    DISPLAY 'WS-NUMERIC ' WS-NUMERIC.                 
    DISPLAY 'WS-NUMERIC-EDITTED ' WS-NUMERIC-EDITTED.
    DISPLAY 'WS-NUMERIC2 ' WS-NUMERIC2.

The results
Code:
WS-NUMERIC 00000001234567891B                 
WS-NUMERIC-EDITTED            123,456,789.12 
WS-NUMERIC2 00000001234567891B               

WS-NUMERIC 00000000098765432K                 
WS-NUMERIC-EDITTED             -9,876,543.22 
WS-NUMERIC2 00000000098765432K               
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Apr 30, 2009 10:57 pm
Reply with quote

So Enterprise COBOL can now do automatic "de-editing"? Amazing!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 01, 2009 12:42 am
Reply with quote

Hello,

I'd suggest only using this when the same program created the "edited" value in the field (rather than if this edited value came from some external input). . .

NUMVAL and NUMVAL-C work quite nicely with variably formatted, edited data from some trusted external source. If the input is from some direct user screen input or some kind of "heads-down" data entry, the data needs to be validated before any movement is attempted. . .

fwiw.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri May 01, 2009 2:36 am
Reply with quote

Terry Heinze wrote:
So Enterprise COBOL can now do automatic "de-editing"? Amazing!
Yes, just used this some days back and it worked nicely. I believe, if you're using COBOLII or later, just move ws-a to ws-b. Mine is Enterprise COBOL.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri May 01, 2009 3:20 am
Reply with quote

No, COBOL II requires the NUMVAL.

My personal opinion:
I believe that Enterprise COBOL, in addition to the multi-thread capability that it now offers - or Object Oriented as the phrase goes,
COBOL 3 was written for coders that do not have the bits&bytes - near assembler background - that many of us 'legacy programmers' (read: dinosauers) have. Like Java or C, if you manage to define the data properly, you can have 'generic' commands (MOVE in this case) that will tailor the extended code based on the attributes of the defined data.

Confusing the newbees with extra (or special) instructions, such as NUMVAL, was something to be avoided.
End personal opinion:
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri May 01, 2009 5:59 am
Reply with quote

dbzTHEdinosauer wrote:
Confusing the newbees with extra (or special) instructions, such as NUMVAL, was something to be avoided.
No! I disagree, tools have a purpose, and properly used, are of value.
The move of an edited numeric is well documented but crap coming from the "user" does need editing...and NUMVAL and the NUMVALC are very handy....
Heck, when the macro de-edit got downsized, I wrote my own.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun May 03, 2009 8:21 pm
Reply with quote

Quote:
If it works for MOVE, I wonder if it will work for ADD or COMPUTE....
Numeric edited fields can only be used as receiving fields in arith stmts (e.g COMPUTE NUM-ED = A * B).

You'll have to move the N/E field 1st to a numeric field, before executing the arith stmt.

Update - It looks like the orig poster deleted the quoted remarks, but the point is still valid.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue May 05, 2009 2:35 am
Reply with quote

Out of curiosity, I checked an old (VS COBOL II) manual and apparently this de-editing MOVE has been valid since at least Rel. 3.2. That is, moving a numeric-edited field to a numeric field.
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: Tue May 05, 2009 3:00 am
Reply with quote

Terry,

I had also pointed out this concept back in late July 2008, but I couldn't recall whether it was introduced with VS/COBOL II, Version 3 or COBOL/370.

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

Regards.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue May 05, 2009 4:46 am
Reply with quote

How embarrasing. I even responded during that thread. icon_redface.gif
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue May 05, 2009 5:45 pm
Reply with quote

Terry Heinze wrote:
I checked an old (VS COBOL II) manual and apparently this de-editing MOVE has been valid since at least Rel. 3.2. That is, moving a numeric-edited field to a numeric field.
ah... I was having sleepless nights in search of "that" Manual . . . can you please point me to the URL?

Regards,
Anuj
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue May 05, 2009 10:36 pm
Reply with quote

Sorry, the manual I have is a hard copy acquired in the late 80s.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 05, 2009 11:31 pm
Reply with quote

Hello,

VS COBOL II is available via the "IBM Manuals" link at the top of the page.

And from that manual:
Quote:

° De-editing allows moving a numeric-edited data item into a numeric or
numeric-edited receiver. The compiler accomplishes this by first
establishing the unedited value of the numeric-edited item (this value
can be signed), then moving the unedited numeric value to the
receiving numeric or numeric-edited data item.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts convert file from VB to FB and use tr... DFSORT/ICETOOL 8
No new posts Convert HEX to Numeric DB2 3
Search our Forums:

Back to Top