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 X(16) to PIC S9(16) COMP-3

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

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Tue Feb 22, 2011 11:38 pm    Post subject: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

how to convert X(16) to PIC S9(16) COMP-3
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


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

PostPosted: Tue Feb 22, 2011 11:52 pm    Post subject:
Reply with quote

Are you deliberately attempting to generate S0C7 abends? If the data in the X(16) variable is numeric and appropriately set up, FUNCTION NUMVAL will do it. Otherwise, it could be a difficult process.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Tue Feb 22, 2011 11:54 pm    Post subject:
Reply with quote

If the X(16) data element actually contains a valid display numeric or numeric-edited value, then perhaps NUMVAL or NUMVAL-C will help - see the COBOL Manual.
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 Feb 23, 2011 12:06 am    Post subject: Reply to: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

Providing the X(16) field contains valid display-numerics, you'd be better off converting to S9(17) COMP-3. It's the same number of bytes and the high-order nibble of the first-byte will be addressable.

What version/release of COBOL are you using?

Bill
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 642
Location: Whitby, ON, Canada

PostPosted: Wed Feb 23, 2011 12:48 am    Post subject:
Reply with quote

If the contents of the X(16) are numeric, then REDEFINE it as 9(16) and MOVE it to S9(17) COMP-3.
Back to top
View user's profile Send private message
svsarath

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Wed Feb 23, 2011 1:00 am    Post subject:
Reply with quote

Robert Sample:
I am not deliberately attempting to generate SOC7 abends.
My requirement is listed below:
--I have an input file where each field is delimited by '|'
--Unstring the file and load the data into DB2 table.

The column in DB2 table is declared as Decimal(16,0)

For this reason I need to convert X(16) data to S9(16)V COMP-3.

As you suggested I have used NUMVAL function to covert the X(16) to COMP-3. I am getting -311 SQL CODE while inserting the data into DB2 table. could you please advice?
Back to top
View user's profile Send private message
svsarath

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Wed Feb 23, 2011 1:03 am    Post subject:
Reply with quote

don.leahy
"If the contents of the X(16) are numeric, then REDEFINE it as 9(16) and MOVE it to S9(17) COMP-3"
How to handle -ve sign if the input has -ve values, pls advice
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 Feb 23, 2011 1:07 am    Post subject: Reply to: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

Maybe I missed the memo, but what's "-ve"?

Please advise....

Bill
Back to top
View user's profile Send private message
svsarath

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Wed Feb 23, 2011 1:10 am    Post subject:
Reply with quote

Bill O'Boyle,

negative sign
Back to top
View user's profile Send private message
svsarath

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Wed Feb 23, 2011 1:23 am    Post subject:
Reply with quote

Friends, can someone please help me?
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Wed Feb 23, 2011 1:25 am    Post subject:
Reply with quote

Is this some sort of extreme forum challenge?

Why is everyone but svsarth working blind folded?

Svarath, why don't you show the data you are trying to convert?

Don't you think it will help everyone out?
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Wed Feb 23, 2011 1:28 am    Post subject:
Reply with quote

Man o man!

It was a whole thirteen minutes since your last very vauge response.

There is no worse way to get on the bad side of the experts than to be that impatient.

Good luck.
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 Feb 23, 2011 1:39 am    Post subject:
Reply with quote

Hello,

You have been here nearly 5 years. In that time you should have learned how to present a problem you want help with. . .

Suggest you show some real input (including a negitive number), the cobol definition for this after the unstring, and the host variable being used in the sql statement that returns the -311.

You did refer to the -311 sql code. . .?

Did you read about NUMVAL?

Hopefully, you realize that your way of presenting your question has made this take more replies. . .
Back to top
View user's profile Send private message
svsarath

New User


Joined: 30 May 2006
Posts: 16

PostPosted: Wed Feb 23, 2011 1:40 am    Post subject:
Reply with quote

Input X(16)
Output: S9(16)V COMP-3

some possible Input values are- Zero(0), -1 etc.
As I mentioned in my earlier post, I didn't get any abends after executing the NUMVAL function- I am getting -311 abend while inserting the data into the table.

I had a quick test run:
Input: 0(zero)
Ouput:000000. after the NUMVAL function executes.

could you please advice me? thanks in advance for your help.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Wed Feb 23, 2011 1:46 am    Post subject:
Reply with quote

Your input is 16 bytes, yet your example is one byte.

Is this left justfied padded with spaces?
Is this right justfied padded with spaces?

Your output is comp-3, so the data is packed.

What is the hex display of this data look like?

What does the code in your quick test run look like?

Why do we have to guess at this?
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 Feb 23, 2011 2:03 am    Post subject: Reply to: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

Is the sign associated with this data, a separate byte (a "-" or "+") or is it a zone-overpunch in byte-16, with the zone-nibble equal to a 4-Bit "C" (positive) or a 4-Bit "D" (negative)? If so, this would indicate it was originally signed zoned-decimal or display-numeric signed.

Can you post the actual field value (in hex), as has been suggested?

This would significantly reduce the flame factor.... icon_eek.gif

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

Global Moderator


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

PostPosted: Wed Feb 23, 2011 2:25 pm    Post subject:
Reply with quote

well,
a -311 SQLCODE requires that we see
  • your SQL
  • and the definiton of the HOST-Variable for the DECIMAL(16,0) Column.


then we will beable to tell you why you are receiving the -311.

it has nothing to do with the data contents. it is your host variable definition
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


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

PostPosted: Wed Mar 02, 2011 2:08 pm    Post subject:
Reply with quote

svsarath - And you also seem to totally ignore the replies from Don and Bill about using S9(17) COMP-3 instead of S9(16) COMP-3 - I hope you understand the message of the text they put in here.
Back to top
View user's profile Send private message
sureshmanokar

New User


Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

PostPosted: Fri Mar 04, 2011 4:21 pm    Post subject: Reply to: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

Hi Sarath,

I used this piece of code to convert X(16) to S9(16) comp-3.
Can u try this one.

WORKING-STORAGE SECTION.
01 WS-NUMR-COMP.
02 WS-ALPHA-VAR PIC X(16).
02 WS-NUM-VAR REDEFINES WS-ALPHA-VAR PIC S9(16).
77 WS-COMP-VAR PIC S9(16) COMP-3.
PROCEDURE DIVISION.
PARA-1.
MOVE 1234567891234567 TO WS-ALPHA-VAR.
MOVE WS-NUM-VAR TO WS-COMP-VAR.
DISPLAY 'WS-COMP-VAR:' WS-COMP-VAR.
STOP RUN.

Cheers,
Back to top
View user's profile Send private message
sureshmanokar

New User


Joined: 21 Dec 2010
Posts: 11
Location: Bangalore

PostPosted: Fri Mar 04, 2011 5:08 pm    Post subject: Reply to: how to convert X(16) to PIC S9(16) COMP-3
Reply with quote

In the below pasted program, i'm checking for '+' & '-' sign using reference modification based on the sign i'm moving the input values to numeric item..& so on.. Hope it gives u an idea how to handle this type of situation.

IDENTIFICATION DIVISION.
PROGRAM-ID. DSPCOMP3.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUMR-COMP.
02 WS-ALPHA-VAR PIC X(16).
02 WS-NUM-VAR REDEFINES WS-ALPHA-VAR PIC S9(16).
77 WS-COMP3-VAR PIC S9(16) COMP-3.
77 WS-COMP-VAR PIC S9(16) COMP.
77 IND PIC 9(1) VALUE 0.
77 INP-SIGN PIC X VALUE SPACES.
77 POS-SIGN PIC X VALUE '+'.
77 NEG-SIGN PIC X VALUE '-'.
01 INPUT-SIGN PIC X.
88 POS VALUE 'P'.
88 NEG VALUE 'N'.
***********************************************************
PROCEDURE DIVISION.
PARA-1.
***********************************************************
DISPLAY 'WS-ALPHA-VAR:' WS-ALPHA-VAR.
MOVE '+123456789123456' TO WS-ALPHA-VAR.
DISPLAY 'WS-ALPHA-VAR:' WS-ALPHA-VAR.
DISPLAY 'WS-NUM-VAR:' WS-NUM-VAR.
IF WS-ALPHA-VAR IS NUMERIC
COMPUTE WS-COMP3-VAR = WS-NUM-VAR
COMPUTE WS-COMP-VAR = WS-NUM-VAR
COMPUTE IND = 1
END-IF.
************ IF INPUT HAS NON-NUMERIC VALUES ************
IF IND = 0
* PERFORM VARYING I FROM 1 BY 1 UNTIL I > 16
****** ASSUMING FIRST BYTE HAVING THE SIGN '+VE' OR '-VE' *******
IF WS-NUM-VAR(1:1) NOT NUMERIC
MOVE WS-NUM-VAR(1:1) TO INP-SIGN
IF INP-SIGN = NEG-SIGN
SET NEG TO TRUE
DISPLAY 'NEGATIVE INPUT....!'
MOVE WS-NUM-VAR(2:15) TO WS-COMP3-VAR
COMPUTE WS-COMP3-VAR = WS-COMP3-VAR * (-1)
ELSE
IF INP-SIGN = POS-SIGN
SET POS TO TRUE
DISPLAY 'POSITIVE INPUT....!'
MOVE WS-NUM-VAR(2:15) TO WS-COMP3-VAR
COMPUTE WS-COMP3-VAR = WS-COMP3-VAR * (+1)
ELSE
DISPLAY 'ERROR: SIGN IS NOR +VE, NEITHER -VE...!'
STOP RUN
END-IF
END-IF
* END-PERFORM
END-IF.
************ DISPLAYS THE VALUES ***********************
DISPLAY 'WS-COMP3-VAR:' WS-COMP3-VAR.
DISPLAY 'WS-COMP-VAR:' WS-COMP-VAR.
STOP RUN.
*******************************************************

Cheers,
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 Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm


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