Page 1 of 1

Using OConv with MP tag

Posted: Fri Nov 02, 2007 12:14 am
by vinodlakshmanan
Hi,

Can we use OCONV with MP tag to write packed decimal data to the output? The help says that the MP tag also unpacks the data for output, so I got confused.

Thanks,
Vinod

Posted: Fri Nov 02, 2007 2:21 am
by ray.wurlod
Curiously this works the other way around to what you might expect from the other conversions.

Oconv(42,"MP") returns the characters of 42 (that is, "4" and "2") represented as byte values in hexadecimal, namely "34" and "32" (the ASCII code for "4" is 52 and the ASCII code for "2" is 50).

Iconv(3432, "MP") would therefore return "42".

Iconv(42, "MP") will return "B", since the ASCII code for "B" is 66, which is 42 in hexadecimal.

Hope this makes things clearer.

Posted: Fri Nov 02, 2007 5:01 am
by vinodlakshmanan
Hi Ray,

I am not able to view the rest of your post as it is premium content :)
Could you please tell me some way in which we can pack a decimal field?

Regds,
Vinod

Posted: Fri Nov 02, 2007 3:57 pm
by ArndW
Vinod - the non-premium part is enough; have you actually gone and tried the MP conversion with ICONV and OCONV? All you need to do is create a test routine in the Manager; shouldn't take more than 60 seconds including compile and run. You can try both OCONV and ICONV and actually see what the output is.

Posted: Fri Nov 02, 2007 8:35 pm
by ray.wurlod
Take a look at the SDK routines for converting COMP data types, then try to reverse their logic. It will be slightly different depending on whether you are processing signed values and on the number of decimal places.

Posted: Sat Nov 03, 2007 6:44 am
by vinodlakshmanan
I have tried using OCONV with MP tag, but it converts it to hex. For e.g. if I give OCONV(1234,"MP"), I get "31323334" in my output file (hex values of 1234).
I havent tried ICONV, as the help says it converts data into internal format. I will try it.
As for the routines, there is a DataComp3Unsigned (or a routine of a similar name) to convert packed decimal into integer. It uses OCONV with the MP tag.