Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

COBOL : datatype alphanumeric input to decimal output

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
340662

New User


Joined: 23 Apr 2011
Posts: 5
Location: india

PostPosted: Wed Oct 12, 2011 3:29 pm    Post subject: COBOL : datatype alphanumeric input to decimal output
Reply with quote

Hi,

Need help in changing an Alphanumeric field to decimal field in COBOL.

I am sequentially reading a file and extracting/processing some fields to write onto another file.
One input field is in PIC x(16) format which is actually a dollar value. I need to format it in displayable numeric decimal format and then further process it to string it with another string.
For example if the current value is 21 then my result should be 21.00 and if the current value is 21.25 then my result will be same i.e. 21.25
Back to top
View user's profile Send private message

Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 785
Location: Chennai, India

PostPosted: Wed Oct 12, 2011 3:34 pm    Post subject:
Reply with quote

Please look for NUMVAL, NUMVAL-C functions in the manual.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Oct 12, 2011 3:36 pm    Post subject: Reply to: COBOL : datatype alphanumeric input to decimal out
Reply with quote

Have a look at intrinsic function NUMVAL in the manual for one solution. Convert the some-edited to numeric, then move the numeric to the numeric-edited format that you want.

If your data has either decimal-point plus two decimal places or no decimal-point and no decimal places and no other combinations then it would also be straightforward with some REDEFINES and MOVEs.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Oct 12, 2011 4:12 pm    Post subject:
Reply with quote

not to mention that there is not such thing as a decimal field in COBOL.

Had the TS understood that from the begining,
he may have understood enough about COBOL to accomplish this on his own instead of needing outside help.
Back to top
View user's profile Send private message
340662

New User


Joined: 23 Apr 2011
Posts: 5
Location: india

PostPosted: Wed Oct 12, 2011 4:49 pm    Post subject:
Reply with quote

@ dbzTHEdinosauer

The similar comments you have recieved as well in the below post

http://ibmmainframes.com/about40254.html

Please stop replying in this manner. You are seniour guy and you should reply only to the technical query.

@ Gnana Sekaran Nallathambi

thx.NUMVAL is what im looking for.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Oct 12, 2011 5:12 pm    Post subject:
Reply with quote

Abhishek Sharma, PLEASE learn how to ask a question. Your "requirements" are as clear as mud. You say you have a 16-byte input variable that contains a numeric value. Is this value left-justified, right-justified, justified to some implied decimal location in the 16 bytes, or occurring randomly in the 16 bytes? What is the minimum number of digits? What is the maximum number of digits? Can there be fill values other than spaces -- and if so, what fill values can occur? Can the values be negative? If they can be negative, how is the sign denoted (part of a value such as occurs with USAGE DISPLAY signed numbers, before the number, after the number, specially coded such as CR or DB)? Do positive numbers have a sign? How many decimal digits can your output variable have -- 2 as in your examples, or more (how many more)? How many digits before the decimal must you allow for -- 16? 14? some other value?

In other words, you BARELY started to pose a question, left us to guess most of what you SHOULD have told us in the first place, didn't bother to look anything up in the manuals which are easily found (hint: there's a link on THIS page to them), and then start whining because YOU are being questioned about your EXTREMELY OBVIOUS lack of knowledge.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Oct 12, 2011 5:30 pm    Post subject:
Reply with quote

340662 wrote:
@ dbzTHEdinosauer

The similar comments you have recieved as well in the below post

http://ibmmainframes.com/about40254.html

Please stop replying in this manner. You are seniour guy and you should reply only to the technical query.



sorry, I am going to reply any way I want to people who make no effort
to learn the fundamentals.
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Wed Oct 12, 2011 7:41 pm    Post subject:
Reply with quote

Hello,

Quote:
Please stop replying in this manner. You are seniour guy and you should reply only to the technical query.
When you start your own forum, you can dictate how people will respond.

There is much more to be learned than just some syntactical information.

One of our objectives (us senior guys) is to help people like you learn how to become proficient/professionsl, not only throw syntax around. . . As you have seen (any maybe now understand) you will get "dinged" for completely careless use of terminology.

When sloppy terminilogy is used, it only leads to confusion and a waste of effort as many who don't know any better will try to answer the wrong question.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Oct 12, 2011 7:56 pm    Post subject:
Reply with quote

340662 wrote:
@ dbzTHEdinosauer

The similar comments you have recieved as well in the below post

http://ibmmainframes.com/about40254.html

[...]


I think you have hugely misunderstood the topic. The comments you have noticed are directed at people who could not even understand the post. Like you. Ironic.

Your question was very simple and lacked any detail which might exhibit knowledge. I think you should look at "how should I have answered that on my own?". Sit down with the manuals, familiarise yourself with the Table of Contents, look through the index. Click around on the internet versions, do some searches. Whilst looking for something specific, make a mental note when you see something you are unfamiliar with, get back to it when you have a chance. You don't have to remember everything, as long as you know "it" is there and how to find it.

After you've done a bit of that, read through some of the posts on the Cobol forum. Try 5-10 a day. You'll learn some stuff and you'll see how to do/not to do things (like questions, whether here or to your colleagues/support people).
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Oct 12, 2011 8:36 pm    Post subject:
Reply with quote

Quote:
21 then my result should be 21.00 and if the current value is 21.25 then my result will be same i.e. 21.25


you are going to have to use NUMVAL with an edit mask to go from
21 to 21.00
and
21.25 to 21.25.

COMPUTE EDIT-MASK = FUNCTION NUMVAL(pic x(16) field) end-compute

STRING EDIT-MASK
, other-stuff
INTO OUTPUT-FIELD
END-STRING
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Oct 13, 2011 3:39 am    Post subject: Reply to: COBOL : datatype alphanumeric input to decimal out
Reply with quote

An alternative.

Code:
01  A-NUM-ED-VALUE-W-OR-WO-DEC-PT PIC X(16).

01  ADD-DEC-PT-ZERO-ZERO.
    05  ADPZZ-INTEGER-PART PIC X(13).
    05  FILLER PIC XXX VALUE ".00".

01  NO-OF-DEC-PTS COMP PIC S9(4).
    88  NO-OF-DEC-PTS-OK VALUE ZERO, +1.
    88  NO-OF-DEC-PTS-ZERO VALUE ZERO.

01  DECIMAL-POINTS PIC X VALUE "."

01  REQUIRED-OUTPUT PIC Z(12)9.99.


Code:
MOVE ZERO TO NO-OF-DEC-PTS

INSPECT A-NUM-ED-VALUE-W-OR-WO-DEC-PT
    TALLYING NO-OF-DEC-PTS
    FOR ALL DECIMAL-POINTS

IF NO-OF-DEC-PTS-OK
    IF NO-OF-DEC-PTS-ZERO
        MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
           TO ADPZZ-INTEGER-PART
        MOVE ADD-DEC-PT-ZERO-ZERO
           TO REQUIRED-OUTPUT
    ELSE
        MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
           TO REQUIRED-OUTPUT
    END-IF
ELSE
    DISPLAY "UP THE SWANEE"
    CALL "FOO"
END-IF


An alternative to this alternative.

Code:
01  A-NUM-ED-VALUE-W-OR-WO-DEC-PT.
    05  FILLER PIC X(13).
    05  ANEV-DECIMAL-POSITION PIC X.
    05  FILLER PIC XX.

01  ADD-DEC-PT-ZERO-ZERO.
    05  ADPZZ-INTEGER-PART PIC X(13).
    05  FILLER PIC XXX VALUE ".00".

01  A-DECIMAL-POINT PIC X VALUE "."

01  REQUIRED-OUTPUT PIC X(16).


Code:

IF ( ANEV-DECIMAL-POSITION EQUAL TO A-DECIMAL-POINT )
    MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
       TO ADPZZ-INTEGER-PART
    MOVE ADD-DEC-PT-ZERO-ZERO
       TO REQUIRED-OUTPUT
ELSE
    MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
       TO REQUIRED-OUTPUT
END-IF


These both rely on the data being "regular", but could be further bullet-proofed.

Another? Same sort of test as the 2nd, but use numeric-edited pictures (two of them, one with, the other without, decimals) and use the "de-editing" available with MOVE. Not done this myself, but search for a posting here by Bill O'Boyle.

Other ways too. UNSTRING, STRING, reference modification, subscripting/indexing, OCCURS DEPENDING ON.

If you knew your way around the manual a bit better, you should have been able to come up with at least one, even one we've not suggested. So, dig in to the manual, try them out, see what you pick up along the way.

All untested, but you should be able to knock off any sharp corners necessary?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Thu Oct 13, 2011 3:51 am    Post subject: Reply to: COBOL : datatype alphanumeric input to decimal out
Reply with quote

Introduced with COBOL/370, you are able to move a de-edited field back to its numeric counterpart.

Example -
Code:

03  WS-NUMERIC-EDITED PIC ZZ9.99 VALUE 1.34.
03  WS-NUMERIC PIC S9(03)V99.

MOVE WS-NUMERIC-EDITED TO WS-NUMERIC.

Internally, WS-NUMERIC contains X'F0F0F1F3C4'. (Last byte has the sign in the zone-portion).

HTH....

Mr. Bill
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Thu Oct 13, 2011 2:09 pm    Post subject: Reply to: COBOL : datatype alphanumeric input to decimal out
Reply with quote

Thanks Mr Bill. That's the stuff I was thinking of.

So, many more than one way to skin a cat.
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Fri Oct 14, 2011 8:42 pm    Post subject:
Reply with quote

Abhishek Sharma, these people are giving you advice and council and are receiving no payment for their time and effort.

dbzTHEdinosauer is absolutely correct, have made NO effort to learn the fundamentals and I assume that you are taking payment from your employer for others efforts.
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Sat Oct 15, 2011 9:27 am    Post subject:
Reply with quote

Hi Bill,

In your second alternative, wondering whether the condition is correct.

It has to be NOT EQUAL instead of EQUAL.
Code:
IF ( ANEV-DECIMAL-POSITION NOT EQUAL TO A-DECIMAL-POINT )
    MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
       TO ADPZZ-INTEGER-PART
    MOVE ADD-DEC-PT-ZERO-ZERO
       TO REQUIRED-OUTPUT
ELSE
    MOVE A-NUM-ED-VALUE-W-OR-WO-DEC-PT
       TO REQUIRED-OUTPUT
END-IF


Correct me if i am wrong.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Sat Oct 15, 2011 12:23 pm    Post subject: Reply to: COBOL : datatype alphanumeric input to decimal out
Reply with quote

Excellent kratos86. At least someone read it.

It was even supposed to be a test on an 88-level. When writing something long, always use an editor not the input box on the site. If something horrible happens there is no way back except re-typing. I always do. Sometimes.

Thanks again.
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Sat Oct 15, 2011 12:33 pm    Post subject:
Reply with quote

Quote:
When writing something long, always use an editor not the input box on the site. If something horrible happens there is no way back except re-typing. I always do.


Even i am used to it icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us