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

Extracting a packed decimal data from Alphanumeric field


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

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Tue Jan 29, 2008 11:34 pm
Reply with quote

In my program I am recieving an ALPHANUMERIC field which may contain a proper numeric value, a character value or a packed numeric value(COMP-3).
I know before hand that the field is going to be one of the three with the help of an indicator.

Now I dont have problem to read the numeric and character.

But how to extract the COMP-3 from the alphanumeric, as it could be any non-display junk the program abends around that area if I am use NUMVAL.

Is there anyway I can extract the numeric data from the Alphanumeric field?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1050
Location: Richmond, Virginia

PostPosted: Wed Jan 30, 2008 2:26 am
Reply with quote

If its the full length, can't you just REDEFINE a varname which has a packed-dec PIC?
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: Wed Jan 30, 2008 3:05 am
Reply with quote

Hello,

If it is not the full length, please post a few examples showing the various data the field might contain. It would be best to post these values in hex and explain what part of the content should be the comp-3 output.
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: Wed Jan 30, 2008 6:10 pm
Reply with quote

Are the indicators unique in the ALPHANUMERIC field?

Is their a length associated with the data?

You could search for the target indicator and when you find it (and depending on the data-type), move the sending data (via reference modification) to the proper WS field, redefined as PIC X.

Then, perform the test (using the proper WS field) as to whether the data is numeric or not.

For example, if the sending data is X'01234C' (3-bytes packed-decimal signed/COMP-3), then move it to a redefined PIC X equivilent of a PIC S9(05) COMP-3 field and perform a NUMERIC test on the COMP-3 field.

HTH....

Regards,

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

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Tue Feb 12, 2008 3:11 pm
Reply with quote

The problem is that the length of the field is variable, I am reading a file using the starting point and length field. like
MOVE FILE(X:Y) TO TEMP-FIELD

Now that field could be a COMP3, FILE(X:Y) always bring in as a alphanumeric field so I am not able to use a NUMVAL also.

Currently I am going to try out the INSPECT option, will this work?
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: Tue Feb 12, 2008 8:49 pm
Reply with quote

Hello,

If you will post several examples of the data you are working with (and maybe explain how you knew the reference modification values), we should be able to offer suggestions.

Quote:
For example, if the sending data is X'01234C' (3-bytes packed-decimal signed/COMP-3), then move it to a redefined PIC X equivilent of a PIC S9(05) COMP-3 field and perform a NUMERIC test on the COMP-3 field.
If the field is verified to contain x'01234C', it is already "proved" to be numeric and no further test would be necessary.

Quote:
Currently I am going to try out the INSPECT option, will this work?
I do not believe inspect will provide the functionality you want.

Once we better understand the requirement, we can better think about how to implement.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue Feb 12, 2008 8:54 pm
Reply with quote

One thing I have used to prevent NUMVAL from erroring is to mone the field to a subfield next to a predefined subfield with a numeric zero in it ant then NUMVAL the combined fields, then if there was no valid numerics in the moved field, the value would be zero.....
Also look at NUMVAL-C......
Back to top
View user's profile Send private message
aravindunlimited

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Mon Feb 25, 2008 2:55 pm
Reply with quote

e.g

in my file position 5->12 is always COMP-3 variable. I have another field as well starting from 16->20 which is also COMP-3

Reference data:
SALARY
FIELD-START = 5
LENGTH = 8
TYPE = PD

INTEREST
FIELD-START = 16
LENGTH = 5
TYPE = PD

I am reading the file in this manner.

EVALUATE TRUE

WHEN PACK-DECIMAL
WHEN BIN-DECIMAL
COMPUTE WS-FIELD-VAL-NUM = FUNCTION
NUMVAL(WS-RECORD(WS-FIELD-START:
WS-FLENGTH(WX-FIELD-INDEX)))
MOVE WS-FIELD-VAL-NUM
TO WS-FIELD-VALUE

WHEN OTHER
MOVE WS-RECORD(WS-FIELD-START:
WS-FLENGTH(WX-FIELD- INDEX))
TO WS-FIELD-VALUE


But this one doesnt work as the NUMVAL is not able to identify whether it is a COMP-3 data or some genuine junk data.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Feb 25, 2008 5:23 pm
Reply with quote

aravindunlimited wrote:
But this one doesnt work as the NUMVAL is not able to identify whether it is a COMP-3 data or some genuine junk data.
If you are expecting 'junk'. then only you can define just what 'junk' is and only you can validate the input data for it and avoid it....
You define 'junk' , you avoid it....
Back to top
View user's profile Send private message
aravindunlimited

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Thu Mar 06, 2008 1:53 pm
Reply with quote

I am not defining junk, I am just unable to read that field as comp-3 copied to a generic variable.

either I have to have a COMP-3 redefine of each and every length or any other better generic solution
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Thu Mar 06, 2008 6:41 pm
Reply with quote

There is a similar discussion going on in FAQ. I wonder if it is the same project? It can be done but I won't be a party to such a mess. I feel sorry for the customers.
Back to top
View user's profile Send private message
aravindunlimited

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Mon Mar 10, 2008 2:30 pm
Reply with quote

It is something like this, out a 1000 fields in a file on day 1. I have to identify which ones have changed on day 2. and only pick them.
I am able to pick the changed values if it is char or num, but for comp and comp-3 I am not able to read the value(But I am able to understand that this has changed).
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: Tue Mar 11, 2008 8:42 am
Reply with quote

Hello,

If your only concern is whether the field changed or not just compare the fields as PIC X. . .

If they are the same, no change occurred. If the pic x values are not the same, something changed between day1 and day2. Do whatever you need with the "changes".

Remember - this will only work testing for equal/not equal.
Back to top
View user's profile Send private message
aravindunlimited

New User


Joined: 08 May 2006
Posts: 16

PostPosted: Thu Mar 27, 2008 7:39 pm
Reply with quote

That is the problem I want the change. and the info I have is

position: x
lenght: y
type: BI

Now how will I extract it. Is there any concept of variable length field like VARCHAR
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: Thu Mar 27, 2008 9:40 pm
Reply with quote

Hello,

It would be fairly simple to identify individual bytes that were different. If you want to identify entire fields that are different, you would need to create an array which is an index/glossary/directory (whatever term you prefer) of the length and displacement of each field. It would also be good to include the field-name in this array.

Quote:
Is there any concept of variable length field like VARCHAR
Once you have this index of the field length/displ, you could use "reference modification" to compare the individual fields of "changed" records and show the differences in hex.

Once you find a "change" comparing the entire record, you could use a loop to show the individual field name(s) and content of fields that were different.
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 Mar 27, 2008 9:54 pm
Reply with quote

Is this a Bit-Map formatted message-area, such as a Visa, MasterCard, JCB, etc Authorisation request and you're trying to extract (parse) this data?

Just curious....

Regards,

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Mar 27, 2008 10:32 pm
Reply with quote

From what I understood, in the MOVE FILE(X:Y) TO TEMP-FIELD,
the part FILE(X:Y) contains exactly the comp-3 value.
If we define TEMP-FIELD-R PIC X(8) JUST RIGHT,
then we may be able to get somewhere.
After MOVE FILE(X:Y) TO TEMP-FIELD-R,
we can calculate the length of the left part (Z = 8 - Y)
and MOVE LOW-VALUES TO TEMP-FIELD-R (1:Z)
Then use a REDEFINES to have a working COMP-3 field.

Does it work? Anybody tempted to write down some code?
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: Thu Mar 27, 2008 11:23 pm
Reply with quote

Hello,

If i understand correctly (and i may not icon_smile.gif ), comparing the characters in the fields and reporting the differences (in hex) will provide the required output with no need to find a way to work with comp-3 data.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Mar 30, 2008 6:00 am
Reply with quote

Here's something that might work. The PD pseudo code looks OK (haven't tested). The BI section needs more definition by the OP.

Eg. Do the BI fld lengths limit themselves to 2, 4, 8 or can they be any lengths within the 8 byte COMP limit. If so, that raises the ques of negative binary number represtntation (hi order bits of 1).

PS. I used pic s9(18) as the limit. If arith extend is used that would change.

What say you Arav?
Code:
01  wrk-area.
    05  wrk-numeric-grp.
        wrk-pd        pic s9(18) comp-3
        wrk-bi-x      pic  x(8).
        wrk-bi        redefines
        wrk-bi-x      pic s9(18) comp.


move lo-vals to wrk-numeric-grp
eval type
when 'pd'
     compute wrk-strt = (length of wrk-pd - orig-len) + 1
     move orig-rec(orig-strt:orig-len) to wrk-pd(wrk-strt:)
       
when 'bi'
     if orig-fld is neg
        move hi-vals to bi-wrk-x
     end-if
     compute wrk-strt = (length of wrk-bi - orig-len) + 1
     move orig-rec(orig-strt:orig-len) to wrk-bi(wrk-strt:)
when 'an'
     do the easy part
end-eval
.
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 Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts Unable to interpret a hex value to De... COBOL Programming 7
No new posts db2 vs static data COBOL Programming 1
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts External data queue (changes?) CLIST & REXX 0
Search our Forums:

Back to Top