View previous topic :: View next topic
|
Author |
Message |
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi All,
I am trying to read a file in rexx and trying to convert the data if fields are comp or comp-3.I have seen some of the thread for conversion.
I have the variables starting position and length but dont have type of the fields.I done substring on the record with start position and length and then did DATATYPE check.but always it will return type as CHAR.Is any way in rexx that can identify a field is comp or comp-3 field after reading from file.
Regards,
Bipin Peter |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 712 Location: Denmark
|
|
|
|
Hi, I'm not a COBOL person, but I understand that a comp-3 field is what in assembler is a packed decimal field.
A packed decimal field has the hex format X'nnnnns' where n must be a number and s is the sign C,D or F.
You can then identify a field to be comp-3 using something like the following:
u=c2x(substr(p,1,2)) /* pick field from record, convert to readable hex */
/* test for comp-3 */
if verify(left(u,3),'0123456789','N')=0,
& pos(right(u,1),'CDF')>0 then do /* comp-3 */
end
else do /* not comp-3 */
end
Willy |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Willy Jensen wrote: |
You can then identify a field to be comp-3 ...
|
As enrico has indicated, it is not possible to do. X'0C' may be the last byte of a packed-decimal, but it can equally be a value in a binary field, a floating-point field, or some value even in a PIC X field (all bit patterns are valid).
Unless you know the start, length and type, you can only guess. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
especially because the TS has asked
Quote: |
if fields are comp or comp-3 |
|
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
You can do a bit of educated guesswork, but not much more, using:
length = 1: packed decimal or char
length = 2: all bets are off
length = 3: packed decimal or char
length = 4: all bets are off
length = 5/6/7/8: packed decimal or char
length > 8: most likely char
Of course if you use 64-bit comp-whatever binaries and 31 digit fixed decimals even more bets are off... |
|
Back to top |
|
|
Willy Jensen
Active Member
Joined: 01 Sep 2015 Posts: 712 Location: Denmark
|
|
|
|
well, he did say 'I have the variables starting position and length' so I took it that he needed a test for comp3 or not comp3 (which is a 2-byte field as I understand). I agree that there could be something entire different in that area. |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi All,
I managed to get the type of data from the layout.
Now i am trying to convert the comp & comp-3 data to readable form.
One of my comp fields definition is PIC s9(07) comp.
Using substring I have taken the data and used C2X and X2D functions.
for this particular field, when i am viewing the data with fileaid I can see data as 1077990645.
After C2X function the compressed data got converted to 4040D4F5 but its giving error in X2D function.
Do you have any idea why this error happened and how we can do conversion?
Bipin Peter |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
PIC S9(07) COMP will be a 4-byte hexadecimal value. X'4040D4F5' is 1077990645 in decimal. If you are seeing 1077990645 in File Aid, then the value is not being converted by your routines -- and I would suspect a problem with your layout since X'4040D4F5' is space space M 5 as zoned decimal DATA. |
|
Back to top |
|
|
|