View previous topic :: View next topic
|
Author |
Message |
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
Hi All,
I want to move char to COmp-3. Could you please help me out.
Example:
01 X PIC X(17).
X = 99.6084135397392
I have to move Value in X to comp-3 variable.
01 PERCENT PIC S9(3)V9(14) COMP-3.
I tried to move using NUMVAL function but didn't work. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Hi...
Since you have joined forum in 2006.. I will definately ask..
What have you tried and what is issue you are facing... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I tried to move using NUMVAL function but didn't work. |
After this many years on the forum, you should know that posting "it didn't work" is useless. Do you mean:
- the code you wrote generated a compile error?
- the code you wrote compiled cleanly but generated an abend?
- the code you wrote compile and ran but did not produce the expected results? If so, what did you get?
- something else you need to explain? |
|
Back to top |
|
|
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
I tried to move the value in X to comp-3. I tried using NUMVAl but didn't work. I tried in so many other ways but didn't suceed. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Code: |
01 X PIC X(17) VALUE
'99.6084135397392'.
01 X-PERCENT PIC S9(3)V9(14) COMP-3.
PROCEDURE DIVISION .
PARA-1.
COMPUTE X-PERCENT = FUNCTION NUMVAL (X).
DISPLAY 'X >' X '<'.
DISPLAY 'X-PERCENT >' X-PERCENT '<'.
|
produces output of
Code: |
X >99.6084135397392 <
X-PERCENT >09960841353973920< |
so your sttatement about the NUMVAL function not working is not supported by the compiler. |
|
Back to top |
|
|
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
This is first time i am posting an issue in forum..so I didn't know what exactly to put.
When i tried to move char values in to comp-3 using NUMVAL i am getting the below error message.
IGZ0152S Invalid character . was found in column 3 in argument-1 for function NUMVAL in program SIBGLC02 at displacement '08BE'.
From compile unit SIBGLC02 at entry point SIBGLC02 at compile unit offset +000008BE at entry offset +000008BE at address 1FA008BE. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Did you try a COMPUTE statement as my example shows? |
|
Back to top |
|
|
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
Below is my code.
01 WS-LOAD-REC.
05 WS-LOAD_MONTH PIC X(3).
05 WS-LOAD_PERCENT PIC X(17).
01 LOAD-REC.
05 LOAD_MONTH PIC X(3).
05 LOAD_PERCENT PIC S9(3)V9(14) COMP-3.
UNSTRING INPUT-REC
DELIMITED BY C-DELIM
INTO WS-LOAD_MONTH
WS-LOAD_PERCENT
END-UNSTRING.
MOVE WS-LOAD_MONTH TO LOAD_MONTH.
COMPUTE LOAD_PERCENT = FUNCTION NUMVAL (WS-LOAD_PERCENT).
Input dataset
****** ************************
000001 002|99.6084135397392|
****** ************************ |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Have you displayed WS-LOAD_MONTH and WS-LOAD_PERCENT to see what values were created by the UNSTRING? |
|
Back to top |
|
|
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
Below are the 2 values in WS-LOAD_MONTH and WS-LOAD_PERCENT.
WS LOAD MONTH=002
WS LOAD PERCENT=99.6084135397392 |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Code: |
01 X PIC X(17) VALUE '99.6084135397392'
01 X-NUM PIC 9(17).
01 X-NUM-V914 REDEFINES X-NUM PIC 9(3)V9(14).
MOVE ZERO TO TALLY.
INSPECT X TALLYING TALLY FOR CHARACTERS BEFORE INITIAL '.'.
IF TALLY > ZERO
MOVE ZERO TO X-NUM
MOVE X (TALLY + 1:) TO X-NUM
MOVE X (1:) TO X-NUM (2:2)
MOVE X-NUM-V914 TO X-PERCENT
ELSE
MOVE ZERO TO X-PERCENT.
|
HTH....
Bill |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Since your code has underscores instead of dashes in the variable names, you obviously did not cut and paste your code. hence there is no way we can evaluate it.
I modified your code to actually compile under COBOL and set it up to generate output:
Code: |
77 C-DELIM PIC X(01) VALUE '|'.
77 INPUT-REC PIC X(80) VALUE
'002|99.6084135397392| ' .
01 WS-LOAD-REC.
05 WS-LOAD-MONTH PIC X(3).
05 WS-LOAD-PERCENT PIC X(17).
01 LOAD-REC.
05 LOAD-MONTH PIC X(3).
05 LOAD-PERCENT PIC S9(3)V9(14) COMP-3.
PROCEDURE DIVISION .
PARA-1.
UNSTRING INPUT-REC
DELIMITED BY C-DELIM
INTO WS-LOAD-MONTH
WS-LOAD-PERCENT
END-UNSTRING.
DISPLAY 'WS LOAD MONTH >' WS-LOAD-MONTH '<'.
DISPLAY 'WS LOAD PERCENT >' WS-LOAD-PERCENT '<'.
MOVE WS-LOAD-MONTH TO LOAD-MONTH.
COMPUTE LOAD-PERCENT =
FUNCTION NUMVAL (WS-LOAD-PERCENT).
DISPLAY ' LOAD MONTH >' LOAD-MONTH '<'.
DISPLAY ' LOAD PERCENT >' LOAD-PERCENT '<'. |
produces output of
Code: |
WS LOAD MONTH >002<
WS LOAD PERCENT >99.6084135397392 <
LOAD MONTH >002<
LOAD PERCENT >09960841353973920< |
so you need to go back to your site and figure out what you are doing wrong. The code you posted, adjusted for the syntactic problems, does not produce the output you claim it does. Since I trust the computer to be consistent, it appears you are not telling us everything, or you are not posting exactly what it going on.
There is a beginner's and students forum that might be more suited for you, based on your inability to recognize valid COBOL syntax, inability to paste actual code, and demonstrated lack of skills: Beginner's and Students Forum |
|
Back to top |
|
|
sandybadam
New User
Joined: 09 Oct 2006 Posts: 14
|
|
|
|
Hi,
Thanks for your suggestion.
It worked now. The issue is not because of underscores its because of the below statement in configuration section.
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.
Thanks |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Quote: |
This is first time i am posting an issue in forum..so I didn't know what exactly to put. |
But have you not read others posts here to see how to do it? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Yeah, changing the decimal point to a comma would cause the input decimal point to become a character that caused NUMVAL to fail. If you want to go that route, you need to change all decimal points in your input to commas BEFORE doing the NUMVAL conversion. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you need all that precision, check the Cobol manual. With 15 digits, it is happy, otherwise there is advice for you to consider. |
|
Back to top |
|
|
|