Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Packed decimals

Status
Not open for further replies.

IanWh

Programmer
Jul 12, 2001
13
0
0
GB
Hi.

I have a file (which is supposed to be a text file) which I want to read in a vfp application. It originates from a mainframe system and apparantly contains packed decimals, which, apparantly is why it's gibberish.

Does anybody know anything about packed decimals + even better know of a way to read them in VFP.

Thanks
Ian.
 
Thanks,

Actually I can read the file using various functions, it's converting the packed decimal bits of it that I need to do - foxpro doesn't automatically do that..... any other ideas?

Ian
 
Do you have the formula by which the decimals are packed? I tried doing a search but Alta Vista said there were 75 million hits on "packed Decimals" so I wasn't able to find it. If you once know how they're packed, it shouldn't be too difficult to perform ASC() on each such byte and then convert the grouping into the cooresponding decimal values.

Late breaking news: tried 'packed decimals' AND IBM and got only 20 hits. You might try and see if it has anything of value to you. It seems to talk about the C language doing conversions, so if you have Visual C++ you might try seeing if there's a routine that you could use possibly via a .dll or .com object

Dave Dardinger
 
I don't know if this will help, but someone in our IT department wrote this little function in order to translate a mainframe file that was created with a cobol program. It involves passing a string that contains the number to be converted along with the implied decimal position and it returns the decoded results. I think in our case the numbers had letters or other characters in the rightmost position. Anyway, here is the code.

PARAMETERS m.string, m.decimals

m.string = UPPER(ALLTRIM(m.string))
m.decimals = IIF(EMPTY(m.decimals),0,m.decimals)
m.len = LEN(m.string)
IF m.decimals > 0
m.deci_pos = (m.len - m.decimals) + 1
m.string = STUFF(m.string, m.deci_pos, 0, ".")
ENDIF

m.rightbyte = RIGHT(m.string, 1) && right byte
m.leftbytes = LEFT(m.string, LEN(m.string)-1) && remaining bytes.
m.sign = 1 && 1 = pos, -1 = negative
m.alphabet = 'ABCDEFGHIJKLMNOPQR'
m.position = AT(m.rightbyte, m.alphabet)

IF ISDIGIT(m.rightbyte)
RETURN VAL(m.string)
ENDIF

DO CASE
CASE m.rightbyte = '{'
m.rightbyte = '0'
CASE m.rightbyte $ '^,}'
m.sign = -1
m.rightbyte = '0'
CASE m.position <= 9
m.rightbyte = ALLTRIM(STR(m.position))
CASE m.position > 9
m.sign = -1
m.rightbyte = ALLTRIM(STR(ABS(9 - m.position)))
ENDCASE

RETURN m.sign * VAL(m.leftbytes + m.rightbyte)
 
Thanks for all that guys - I'm going to take a look and I'll let you know the results.

Cheers
Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top