IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Finding spaces in numeric elementary item in a group variabl


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Thu Oct 15, 2009 9:28 pm
Reply with quote

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

CICS Moderator


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

PostPosted: Thu Oct 15, 2009 9:41 pm
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Thu Oct 15, 2009 9:50 pm
Reply with quote

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

CICS Moderator


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

PostPosted: Thu Oct 15, 2009 10:06 pm
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Oct 16, 2009 1:27 am
Reply with quote

Hi Bill
I am having the decimal field as packed decimal.

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

Global Moderator


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

PostPosted: Fri Oct 16, 2009 2:30 am
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Oct 16, 2009 2:38 am
Reply with quote

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

Global Moderator


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

PostPosted: Fri Oct 16, 2009 2:46 am
Reply with quote

Quote:
Input is not garbage, but is always spaces for comp-3.


that is a very good example of clausal oxymoron.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Oct 16, 2009 3:32 am
Reply with quote

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

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Oct 16, 2009 5:51 am
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Oct 16, 2009 8:07 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Fri Oct 16, 2009 8:09 pm
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Oct 16, 2009 8:55 pm
Reply with 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 ?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Oct 16, 2009 8:58 pm
Reply with quote

Hello,

Validate the input field. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Fri Oct 16, 2009 9:14 pm
Reply with quote

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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Oct 16, 2009 9:23 pm
Reply with quote

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

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Fri Oct 16, 2009 9:49 pm
Reply with quote

thanks Robert , Dick , Bill ....i got the point, bit late but point well taken... icon_smile.gif icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Fri Oct 16, 2009 10:05 pm
Reply with quote

You're welcome - good luck icon_smile.gif

Someone will be here if there are other questions later.

d
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun Oct 18, 2009 9:33 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts how to complete the end of a record w... DFSORT/ICETOOL 2
No new posts BPXBATCH SFTP to remote path having s... All Other Mainframe Topics 6
No new posts Finding and researching jobs All Other Mainframe Topics 0
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts VB to FB - Finding LRECL SYNCSORT 4
Search our Forums:

Back to Top