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
 

 

How to convert char to COMP-3

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

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 8:41 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed May 11, 2011 8:44 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 8:50 pm    Post subject:
Reply with quote

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
View user's profile Send private message
sandybadam

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 8:50 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 8:55 pm    Post subject:
Reply with quote

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
View user's profile Send private message
sandybadam

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 8:56 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 8:57 pm    Post subject:
Reply with quote

Did you try a COMPUTE statement as my example shows?
Back to top
View user's profile Send private message
sandybadam

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 9:03 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 9:06 pm    Post subject:
Reply with quote

Have you displayed WS-LOAD_MONTH and WS-LOAD_PERCENT to see what values were created by the UNSTRING?
Back to top
View user's profile Send private message
sandybadam

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 9:10 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Wed May 11, 2011 9:10 pm    Post subject: Reply to: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 9:26 pm    Post subject:
Reply with quote

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
View user's profile Send private message
sandybadam

New User


Joined: 09 Oct 2006
Posts: 14

PostPosted: Wed May 11, 2011 9:58 pm    Post subject: How to convert char to COMP-3
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed May 11, 2011 10:33 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed May 11, 2011 10:43 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7230

PostPosted: Thu May 12, 2011 3:18 am    Post subject: Reply to: How to convert char to COMP-3
Reply with quote

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
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 How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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