View previous topic :: View next topic
|
Author |
Message |
340662
New User
Joined: 23 Apr 2011 Posts: 5 Location: india
|
|
|
|
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 |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Please look for NUMVAL, NUMVAL-C functions in the manual. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
340662
New User
Joined: 23 Apr 2011 Posts: 5 Location: india
|
|
|
|
@ dbzTHEdinosauer
The similar comments you have recieved as well in the below post
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
340662 wrote: |
@ dbzTHEdinosauer
The similar comments you have recieved as well in the below post
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks Mr Bill. That's the stuff I was thinking of.
So, many more than one way to skin a cat. |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
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 |
|
|
kratos86
Active User
Joined: 17 Mar 2008 Posts: 148 Location: Anna NGR
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
kratos86
Active User
Joined: 17 Mar 2008 Posts: 148 Location: Anna NGR
|
|
|
|
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 |
|
Back to top |
|
|
|