Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
"It's all coming back to me now." Here goes:
01 EXTRACT-REC-IN. 03 KEY-DATA. 05 FIELD1 PIC 9(5) VALUE 0 BINARY. 05 FIELD2 PIC 9(4) VALUE 0 BINARY. 05 FIELD3 PIC 9(4) VALUE 0 BINARY. 05 FIELD4 PIC 9(8) VALUE 0 BINARY. 05 FIELD5 PIC 9(4) VALUE 0 BINARY. 03 DATA. 05 FIELD6 PIC S9(04) VALUE 0 COMP. 05 FILED7 PIC S9(15)V99 VALUE 0 COMP-3. 05 FIELD8 PIC S9(15)V99 VALUE 0 COMP-3.
Your data should consist of big-endian data as follows:
  1. FIELD1, FIELD4 four unsigned bytes, binary.
  2. FIELD2, FIELD3, FIELD5 two unsigned bytes each, binary.
  3. DATA.FIELD6 two bytes, binary, but two's complement signed.
  4. DATA.FIELD7-FIELD8 nine-byte fields consisting of seventeen binary-coded-decimal (BCD) digits (four bits = "one nybble" each) followed by a sign-indicator in the rightmost "nybble" as described above. The rightmost two digits are implicitly understood to be right of the decimal point.

I am not immediately aware of any Perl package which will directly handle "BCD representation." Although I do, of course, expect that Many Monks will promptly correct me on this point! Because, "this being Perl, surely it must be there."

Edited:   Thanks for pointing out what I originally had missed that FIELD4 requires to be a four-byte field.


In reply to Re: Perl Unpack Cobol Binary File and Fields by sundialsvc4
in thread Perl Unpack Cobol Binary File and Fields by dbarkho14

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-10-28 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (96 votes). Check out past polls.

    Notices?