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

To Identify the Packed decimal, Binary value


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Thu Mar 28, 2013 7:02 pm
Reply with quote

Hi All,
I am writing a REXX program for my requirement and in one part, I will refer the copybook for a starting position, length and datatype of 'some' fields and I need to check in the file whether in the specified position, the value is of the specified datatype. I have no problems in finding out the starting position, length and datatype in copybook. But I am wondering how I can check whether the same is there in file.

This might sound as a strange requirement. But I have started with DATATYPE built in function, later to realize that won't work.

Ex:
01 A
03 A1 PIC X(5).
03 A2 PIC S9(5).
03 A3 PIC S9(3) COMP-3.

In this case, I will have to check whether the 6th position - 10th Position contains only numeric values and 11th position to 12 th position contains valid packed decimal number.

Any guidance on the same is appreciated.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Mar 28, 2013 7:38 pm
Reply with quote

search the forum for my PACK/UNPACK snippets
Back to top
View user's profile Send private message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Mon Apr 01, 2013 5:01 pm
Reply with quote

Thanks Enrico,

I got your post, I can now handle PACKed values. But I am thinking how can I handle the other two cases

a) PIC S999
b) PIC S9(4) COMP.

In case a), I will get 12E in sequential file for +125 value (which is a valid value), I will have to check whether a similar Builtin function (of C2X) will help to identify this as correct value.
In case b), I will check how I can validate the value in this case.

I can connect to my machine tomorrow and will try.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon Apr 01, 2013 7:19 pm
Reply with quote

senjay wrote:
But I am thinking how can I handle the other two cases

a) PIC S999
b) PIC S9(4) COMP.

In case a), I will get 12E in sequential file for +125 value (which is a valid value), I will have to check whether a similar Builtin function (of C2X) will help to identify this as correct value.

There is no such function, in part because there are too many possible output formats.
Quote:
In case b), I will check how I can validate the value in this case.

Look at the C2D function.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Apr 01, 2013 7:33 pm
Reply with quote

if You had looked better at my unpack function here
ibmmainframes.com/viewtopic.php?t=27921&highlight=rexx+pack+unpack

You would have seen that it shows also the way of verifying if a string is a proper zoned decimal number

hint

Code:
    numb = left( thevar, length(thevar)-1 )
    sign = right( thevar, 1 )

    /* Check sign and numeric sections */
    if  verify(sign, "ABCDEF" ) > 0 then do
        ....
    end
    if  verify( numb, "0123456789" ) > 0 then ,
        ....
    end


the above works for any length
noo way to check anything for a COMP
a binary is ALWAYS a valid number
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Apr 01, 2013 8:00 pm
Reply with quote

disregard the last snippet,
will post later the good one !
Back to top
View user's profile Send private message
senjay

Active User


Joined: 10 May 2007
Posts: 147
Location: India

PostPosted: Mon Apr 01, 2013 10:55 pm
Reply with quote

Enrico said:
Quote:
noo way to check anything for a COMP
a binary is ALWAYS a valid number


Er, Let me explain the full scenario.

Assume that the current layout for a sequential file which is an input to a COBOL program is of LRECL 300. The previous layout of the input file, for ex, could be any of the below cases.

a) LRECL 270
b) LRECL 300 (270 + FILLER X(30)), whereas the current layout is 300 (an ex can be 270 + PIC S9(4) COMP + PIC S9(8) + PIC X(20), or can be any other combination.

Now, we can expect any of the files mentioned in the above cases, can be passed as input to the current version of the program. I will not know the old copybook. The new fields will always get added at last. I need to modify the incoming file to the new layout, for ex, in case b), the last 30 bytes of old file, which has 30 space, should be replaced with zeroes for comp field + zeroes for Zoned decimal field + 20 spaces for alphanumeric field. By this, the program will run successfully.

What I have planned is,
a) determine the layout of the new copybook using FILEAID RLPRINT in batch mode.
b) Determine the LRECL of the incoming file by LISTDSI, check whether the last Numeric (can be Zoned decimal, Binary, Packed decimal) field of the file as per the current layout contains only numeric values(can be Zoned decimal, Binary, Packed decimal), If not, then it is evident that the input file is not the latest one. I will create a SORT control card to insert zeroes of the corresponding data type. I will perform this check (from last field to first field) until the numeric field in the file matches with the Numeric field position mentioned in the layout.

Note:
I know this is a weird requirement and I know some of you experts will advice me to check the source of the input file and correct it there. This requirement is for one of my colleague. Since I know Rexx (to some extent), I jumped in for help. The first question I asked him is: "Can't you correct the input file" and it seems they can't. And now I am stuck in how to validate whether a value specified in the file in a particular position of specified length is a valid binary or zoned decimal number.

@Akatsukami, Thanks, I will try out what you suggested.

And sorry for the long post. Any suggestion in alternate approach is also welcome.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Apr 01, 2013 11:07 pm
Reply with quote

A binary field will be 2, 4, or 8 bytes. There is no such thing as an invalid numeric value for a binary field, as you were told earlier, as every bit combination is a valid bit combination and hence represents a valid binary number. For example, X'F7F7' is a 2-byte binary value of 63479 -- but it also could be a 2-digit zoned decimal number with a value of 77.

In fact, if you check the COBOL Language Reference manual, you will find that IF NUMERIC is not valid for binary data -- because the test cannot fail.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 01, 2013 11:15 pm
Reply with quote

Just looking quickly, what compiler sub-option do you have for TRUNC for the program which reads the file?

Can you be more clear about your input file, like "any combination"? If there is data which is not identifiable from "something" on the record, then how is it ever going to be processed? As a once-off you might be able to "guess", but not day-in-day-out.
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
No new posts How to identify the transaction categ... IMS DB/DC 3
No new posts Identify Program Insert DB2 7
Search our Forums:

Back to Top