IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Converting BIGINT value to unpacked data and vice-versa


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
girish.shekki

New User


Joined: 25 Nov 2007
Posts: 3
Location: chennai, india

PostPosted: Sat Feb 05, 2011 11:19 pm
Reply with quote

Hi,

I need to convert a 8 byte binary number (SQL Data type BIGINT) to its equivalent Packed Decimal Number, and this decimal number is to be unpacked.

Similarly i should also need to do the reverse of above- pack the data, and convert it to 8 byte binary number. How can i do that? CVD, CVB work only on 4 byte numbers. My module is 31 bit module. Can anyone help me out here?

Thanks.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Feb 06, 2011 12:12 am
Reply with quote

Hello and welcome to the forum,

Which language are you using?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Feb 06, 2011 12:18 am
Reply with quote

(I'm assuming Assembler) icon_wink.gif

Use "Load Grande" to load your doubleword binary value into a 64-Bit register and use a "Convert to Decimal Grande" to convert the 64-Bit doubleword into a 16-Byte Packed-Decimal/Quadword. Using 64-Bit R15 as an example, which should be OK -

Code:

QWORD    DS   L            ALIGNED 16-BYTE QUADWORD
DWORD    DS   D            ALIGNED 8-BYTE DOUBLEWORD
         LG   R15,DWORD    LOAD INTO 64-BIT REGISTER
         CVDG R15,QWORD    MAKE IT 16-BYTE PACKED-DECIMAL


This can be done in COBOL, using the ARITH(EXTEND) compiler option.

I'm unsure about PL/I.... icon_sad.gif

Bill
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Sun Feb 06, 2011 3:57 am
Reply with quote

Bill O'Boyle wrote:
(I'm assuming Assembler) icon_wink.gif

Use "Load Grande" to load your doubleword binary value into a 64-Bit register and use a "Convert to Decimal Grande" to convert the 64-Bit doubleword into a 16-Byte Packed-Decimal/Quadword. Using 64-Bit R15 as an example, which should be OK -

Code:

QWORD    DS   L            ALIGNED 16-BYTE QUADWORD
DWORD    DS   D            ALIGNED 8-BYTE DOUBLEWORD
         LG   R15,DWORD    LOAD INTO 64-BIT REGISTER
         CVDG R15,QWORD    MAKE IT 16-BYTE PACKED-DECIMAL


This can be done in COBOL, using the ARITH(EXTEND) compiler option.

I'm unsure about PL/I.... icon_sad.gif


PL/I can also handle it, compiler option

Code:
*process limits(fixeddec(15,31) fixedbin(31,63));
which lets you use:

Code:
 DCL BIGDEC FIXED (31); /* and */
 DCL BIGBIN FIXED BIN (63);


It was introduced in Enterprise PL/I V3.5, and possibly even earlier, but I don't have older manuals available.
Back to top
View user's profile Send private message
girish.shekki

New User


Joined: 25 Nov 2007
Posts: 3
Location: chennai, india

PostPosted: Sun Feb 06, 2011 9:58 am
Reply with quote

Yes i am writing in Assembler.
I am aware of grand instructions CVDG and CVBG which can be used to convert 8 byte data to binary and vice-versa. But once i convert binary to decimal using CVDG, i need to unpack the decimal value. As far as i know, using UNPK i can only get unpacked value of 16 bytes. In 8 byte data, the unpacked data can go beyond 8 bytes(i am thinking that for maximum allowed BIGINT value, unpacked data can be upto 19 digits.) I don think there is UNPK grand instr. icon_smile.gif do i need to use TR and a table with appropriate values to translate? Any other way?

Thanks,
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Feb 06, 2011 1:47 pm
Reply with quote

The following has only been desk-checked -

Code:

UNPKAREA DS    CL31
DBLWORD  DS    D
         DS    XL1
DWORD    DS    D
QWORD    DS    L
         LG    R15,DWORD                         PREPARE FOR 'CVDG'
         CVDG  R15,QWORD                         MAKE IT QUADWORD-DECIMAL
         MVC   DBLWORD,QWORD+8                   MOVE LOW 8-BYTES
         OI    DBLWORD+L'DBLWORD-1,X'0F'         ENSURE 'F' SIGN-NIBBLE
         UNPK  UNPKAREA+16(15),DBLWORD           UNPK AS CL15
         MVC   DBLWORD,QWORD                     MOVE HIGH 8-BYTES
         MVI   DBLWORD+L'DBLWORD,X'0F'           ENSURE X'0F' SIGN-BYTE
         MVO   DBLWORD(L'DBLWORD+1),DBLWORD      SHIFT-RIGHT 4-BITS
         UNPK  UNPKAREA(16),DBLWORD(L'DBLWORD+1) UNPK AS CL16

Bill
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Sun Feb 06, 2011 8:45 pm
Reply with quote

The following (untested) should also accomplish your goal:
Code:
MASK     DC    X'21',30X'20'
UNPKAREA DS    CL31
DWORD    DS    D
QWORD    DS    L

         LG    R15,DWORD                         R15 = BINARY VALUE
UNPKQWD  CVDG  R15,QWORD                         MAKE IT QUADWORD-DECIMAL
         MVC   UNPKAREA,MASK                     MOVE EDIT MASK TO UNPKAREA
         ED    UNPKAREA(31),QWORD                UNPACK QUADWORD USING MASK
         BNL   NOTNEG                            TEST SIGN - IF NOT NEG, CONT
         NI    UNPKAREA+L'UNPKAREA-1,X'DF'       MAKE NEGATIVE - SIGN = X'D'
NOTNEG   EQU   *
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Feb 06, 2011 11:12 pm
Reply with quote

Ron,

Yes, ED is one of the SS instructions with a 1-Byte length (max=X'FF'/256), is a lot less code and I didn't think of it at O'Dark Thirty (was up doing maintenance, not by choice). icon_sad.gif

But, the reverse UNPACKED CL31 <---> DBLWORD-BINARY will be an exercise for the OP as a PACK has a 4-Bit max-length for Operand2 of X'F'/16.

The MVO was included as a possible alternative in the reverse process, by showing the OP how it can be used during the UNPK.

Instead of an MVO, an SRP would work just as well, but that's a more expensive instruction, plus, if you're ultimately unpacking the data, you'd have to reset the sign-nibble after the SRP or the zone-nibble after the UNPK and OR with a X'F'. icon_wink.gif

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top