View previous topic :: View next topic
|
Author |
Message |
Andi1982
New User
Joined: 27 Mar 2008 Posts: 42 Location: Karlsruhe / Germany
|
|
|
|
Hello,
we have some RPG II program and nobody here know how to solve this problem.
In our input file is a 3-Byte field with unsigned packed decimal value:
12 34 56
We need to bring it into packed format 01 23 45 6C.
Does anybody has an idea how to do this in RPG II ?
Best regards
Andi |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
I can't say I remember much of my small encounter with RPG II from 40 years ago...
Is it possible to append a packed-decimal zero (x'0C' or x'0F') giving x'1234560C' and then divide the lot by ten ? |
|
Back to top |
|
|
Andi1982
New User
Joined: 27 Mar 2008 Posts: 42 Location: Karlsruhe / Germany
|
|
|
|
Marso wrote: |
Is it possible to append a packed-decimal zero (x'0C' or x'0F') giving x'1234560C' and then divide the lot by ten ? |
Yes, in COBOL we are doing like that. PIC X redefined and then divide and multiply by 10.
But we don't know how to do this in RPG II. How to define this work-fields? How to work with them to multiply or divide.
We really don't have this RPG-Skills anymore in Company. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
Back to top |
|
|
Andi1982
New User
Joined: 27 Mar 2008 Posts: 42 Location: Karlsruhe / Germany
|
|
|
|
Thx a lot! I was not able to find that Kind of documentation. We will have a look at it and I will give Response if we were able to solve our Problem. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Good luck. |
|
Back to top |
|
|
ApexNC
New User
Joined: 10 Feb 2006 Posts: 19 Location: USA
|
|
|
|
My RPG experience is likewise very old, but one of the COBOL conversion techniques I know very well should be easily adaptable.
Decimal digits without a sign are called "Binary Coded Decimal" (BCD) and a typical usage for a six-digit BCD value is to hold a Gregorian Date with a two-digit year: MMDDYY.
So, I'll use MMDDYY to explain the technique:
(1) Move the 3-byte BCD field (right justified) to a 4-byte binary field.
==> MMDDYY becomes xxMMDDYY.
(2) Multiply by 16
==> xxMMDDYY becomes xMMDDYY0.
(3) Add 15
==> xMMDDYY0 becomes xMMDDYYF.
(4) Declare the 4-byte binary field as 4-byte packed decimal (7-digits). Does RPG have a "redefines" feature, like COBOL? If so, use it.
(5) Move the 4-byte packed decimal field to a 6-digit zoned-decimal (USAGE DISPLAY) field.
==> xMMDDYYF becomes .M.M.D.D.Y.Y ("." characters represent zone value of "F".
Done. |
|
Back to top |
|
|
|