forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading an Cobol "PIC S9(n)" field using Struct.

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Thu Apr 10, 2014 1:33 pm    Post subject: Reading an Cobol "PIC S9(n)" field using Struct. Reply with quote

Hi.
I'm trying to read from an RMS file where some Cobol app writes data.
The Data Definitin contains PIC lines like:
Code:

...
        05 PATYP                PIC 9.
        05 PABEANT              PIC S9(7).
        05 PALEVDAT             PIC 9(5).
        05 PATRIGGANT           PIC S9(4).
        05 PASTATUS             PIC X.
...

When typing the RMS file it looks like (for the part from the definition above):
Code:

...2000002D13222000{I...
...2000001F13222000{I...
...1000012{13232000{I...
...1000006{13232000{I...
...1000003{13232000{I...
...1000003{13232000{I...
...1000001{13232000{I...
...1000006{13232000{I...

The first "2" or "1" is the PATYP fields.
The next 7 chars is the PABEANT field
A PABEANT field like "000002D" should read 24 (numeric) in Python.
And "000001F" = 16, "000012{" = 120 and so on.

All of the PATRIGGANT fields in the example data are 0 ("000{").

If I create the Struct using "String(name, size) I get the "{" in the string (or the other characters, of course).
If I try with UBint.. I get other errors. (I do not think they are correct for character numeric formats anyway).

All non-singed numeric fields (like "PALEVDAT" in the example above reads just fine as strings.

This is a "load" routine to load RMS data into Rdb and I use Python as the "glue" beetween RMS and Rdb.
Works just fine, apart from these signed S9(x) fields.
Back to top
View user's profile Send private message
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Sun Apr 13, 2014 12:36 pm    Post subject: Reply with quote

Followup...
I think I will "solve" it by some string handling.
The numeric value is read to a string anyway, and this page shows how to evaluate the last character of the value:
http://www.3480-3590-data-conversion.com/article-signed-fields.html
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Mon Apr 14, 2014 8:02 am    Post subject: Reply with quote

Thanks for the tips.

JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jescab



Joined: 28 Jan 2008
Posts: 252

PostPosted: Mon Apr 14, 2014 12:36 pm    Post subject: Reply with quote

No problem... Smile

That page at least verified the coding of the "sign".
I'm not an expert in Python, so it is now 10 if's like:

if last char is "{", set last char to "0"
if last char is "A", set last char to "1"

and so on for each variable using "singed character numeric"... Smile
Back to top
View user's profile Send private message
jfp



Joined: 12 Jul 2004
Posts: 618

PostPosted: Tue Apr 15, 2014 9:01 am    Post subject: Reply with quote

May be something like this:
Code:

if c in ('{', '}'):
    sign = ' '
    c = '0'
else:
    if c <= 'I':
        sign = '+'
        c = chr(ord('1') + ord(c) - ord('A'))
    else:
        sign = '-'
        c =  chr(ord('1') + ord(c) - ord('J'))


or just use a dictionnary:
Code:

dct = {'{' : (' ', '0'),
          'A' : ('+', '1'),
          ...
        }
sign, c = dct(c)


JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group