Dealing with Packed Numbers

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-04-17
I have a file that was extracted from IBM mainframe using COBOL program. The file contains Packed Numbers.

The packed numbers are numbers stored by COBOL in a kind of compressed format to save space. For an example if we have the below row format in COBOL:

01 row01.
     03 std-name           X(10).
     03 std-age            9(8) COMP-3.

This means that, if we have a record with std-name = “Robert Lee” and std-age=6 the row will appear in the extracted file as

Robert Lee0006

Instead of

Robert Lee00000006

My problem is that, I need to read this file using VB code and convert all the numbers into normal numbers so I can store them in SQL server.

Thanks in advance

M. Fraij
Question by:mfraij
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

billious earned 200 total points
ID: 8083855
COMP-3 format is each digit is represented as a nybble, hence hex'37' represents 37.

Take each byte in turn, and the value represented is

10*(byte div 16) + (byte modulo 16)

EXCEPT that IF THE COMP-3 is a SIGNED field.

In this case, the last nybble may be C,D or F (byte modulo 16 = 12, 13 or 15.)

Here, C or F means POSITIVE, and D means NEGATIVE.




Expert Comment

ID: 9447309
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Simple Linear Regression
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question