View previous topic :: View next topic
|
Author |
Message |
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
how to convert X(16) to PIC S9(16) COMP-3 |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
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 |
|
|
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Maybe I missed the memo, but what's "-ve"?
Please advise....
Bill |
|
Back to top |
|
|
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
Bill O'Boyle,
negative sign |
|
Back to top |
|
|
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
Friends, can someone please help me? |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
svsarath
New User
Joined: 30 May 2006 Posts: 16
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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....
Bill |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
sureshmanokar
New User
Joined: 21 Dec 2010 Posts: 11 Location: Bangalore
|
|
|
|
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 |
|
|
sureshmanokar
New User
Joined: 21 Dec 2010 Posts: 11 Location: Bangalore
|
|
|
|
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 |
|
|
|