View previous topic :: View next topic
|
Author |
Message |
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Hi
In a group varibale, how I can find that any elementary numeric data type is having spaces without checking individually all the elementary numeric data types for IS NUMERIC etc.
say in a DCLGEN I have moved a record from a file. After move Numeric data item got spaces in it. How I can replace those spaces to zeros.
for e.g
Code: |
EXEC SQL DECLARE TJAEUNDERREFSTRUCT TABLE
( INSTRUMENTID CHAR(24) NOT NULL,
UNDERBASKETNO DECIMAL(12, 0) NOT NULL,
UNDERREFSTRUCTNO DECIMAL(12, 0) NOT NULL,
UNDERCOMPONENTNO DECIMAL(12, 0) NOT NULL,
PROVIDER1ID CHAR(30) NOT NULL,
PROVIDER2ID CHAR(30) NOT NULL,
PROVIDER3ID CHAR(30) NOT NULL,
CREATETIMESTAMP TIMESTAMP NOT NULL,
UPDATETIMESTAMP TIMESTAMP NOT NULL,
UPDATETIMESTAMPFI TIMESTAMP NOT NULL,
MANDATOR_ID CHAR(3) NOT NULL,
PART_CRIT CHAR(4) NOT NULL
) END-EXEC. |
is table defination.
I make a move from file to dclgen
Code: |
MOVE C0499-DCL-RECORD TO DCLTJAEUNDERREFSTRUCT |
but decimal field got spaces in it.
How I can make these spaces as zeros without checking each elemenatry item.
I hope I am able to state the issue clearly.
Regards |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
A space (X'40') could very well be a valid byte (except for the last byte) in a packed-decimal field. But it would be invalid in a display-numeric field.
Bill |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
thanks for the prompt reply , Bill,
Quote: |
A space (X'40') could very well be a valid byte (except for the last byte) in a packed-decimal field. |
Do you mean to say DB2 can store space in decimal field ?
My requirement is that i do not want space in decimal field, but a zero.
regards |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
OK, let's say you have a 2-Byte packed-decimal field and it contains PL2'400' (X'400C'). So, you have a X'40' in the first-byte, which is legitimate, but it would be in error if it was in the second-byte.
Are you defining "decimal" as packed-decimal or display-numeric (a/k/a zoned-decimal) or both?
If you have a display-numeric field, such as PIC 9(02), with a value of X'40F1', then this would be invalid, because a X'40' in this type of definition (regardless of the byte-location) is invalid.
However, as strange as this may sound, if this value were to be packed, the result would be PL2'001' (either X'001C' or X'001F'), because a PACK instruction discards the zone-portion of each byte, except for the last-byte.
This is also true if the display-numeric field contains x'4040' as it would pack as PL2'000', but will most likely be resolved (by the compiler) to an 'F' sign-nibble.
Bill |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Hi Bill
I am having the decimal field as packed decimal.
regards |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
tomehta,
if your input is garbage you need to validate each field.
if you send garbage to DB2, DB2 will return an error.
and a db2 decimal field is BINARY. |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Hi DBZ
Input is not garbage, but is always spaces for comp-3.
Is there a way I can change these spaces to 0000 without validating each elementary field ?
Thanks |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
Input is not garbage, but is always spaces for comp-3. |
that is a very good example of clausal oxymoron. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
If you're referring to packed-decimal, then finding a X'40' in any byte of the field, except the last-byte (that would be an error), is certainly possible and legitimate.
Example -
Code: |
03 WS-PACKED PIC S9(07) PACKED-DECIMAL.
MOVE 4040400 TO WS-PACKED.
|
Internally, in WS-PACKED, you'll find X'4040400C', with bytes 1-3 equal to X'404040' (SPACES), but are treated as just another number.
If you divide WS-PACKED by 10, your internal result will be X'0404040C', with the previous X'40' byte-values now equal to X'04'.
Bill |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Quote: |
I make a move from file to dclgen
Code:
MOVE C0499-DCL-RECORD TO DCLTJAEUNDERREFSTRUCT
but decimal field got spaces in it.
How I can make these spaces as zeros without checking each elemenatry item.
|
Ignore all the exotic BS so far. Are to fields in C0499-DCL-RECORD defined the the same as the fields in DCLTJAEUNDERREFSTRUCT with the same usage in both definitions in both layouts. A group move is a character move in cobol and will not convert data from display to packed format. This an elementary beginners error in COBOL.
DECIMAL items in DB2 are stored in binary only to the extent that all data on a mainframe is stored in binary, decimal items are stored as packed decimal.
Yes you should always check NUMERIC fields to ensure that they are NUMERIC before using them or adding them to you own system. Anyone that accepts data from an outside souce without editting it is just asking for trouble. |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
For packed I can check for NUMERIC class test, but what I can test for the BINARY data type, SMALLINT of DB2 maps to BINARY in cobol, what data type class test I can run for binary ?
Thanks all for your help. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
A binary field in COBOL is numeric -- always. You cannot do a NUMERIC test on a COMP (binary) field for this reason. |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
but say by mistake the input file had spaces for the comp field , which is a invalid value, but system will take it as valid value. ( binary equivalent of space).
How to handle this condition that the input value for comp field is valid numeric field ? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Validate the input field. . . |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
but say by mistake the input file had spaces for the comp field , which is a invalid value, but system will take it as valid value. ( binary equivalent of space).
How to handle this condition that the input value for comp field is valid numeric field ? |
You do not understand. There is no such thing as an invalid value in a COMP (binary) field. If you think the variable cannot have spaces in it, you will have to compare the variable to x'40404040' and do something if the values are equal -- because x'40404040' is a perfectly valid numeric value of 1,077,952,576 -- and the COMP field will show up as having that value. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Redefine this field as pic x(4) and compare to spaces (or x'40404040'). . .
It is not difficult, but it is not automatic - you have to do a bit of work. |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
thanks Robert , Dick , Bill ....i got the point, bit late but point well taken... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
You're welcome - good luck
Someone will be here if there are other questions later.
d |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Here is another way to look at the problem:
Your DCL contains both CHAR and DECIMAL fields.
If you consider your fields as a group, you won't be able to tell if the space you find belongs to a CHAR field (legal space) or a DECIMAL field (maybe illegal). |
|
Back to top |
|
|
|