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

Conversion of negative amount (comp3) field to 2's complimen


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 45
Location: india

PostPosted: Mon Feb 24, 2014 5:27 pm
Reply with quote

I have an amount field having below value.

00211
0011D

I need to convert this amount field into 2'c ompliment in the below way.

FFF2
FFFB

after converting into 2's compliment . how to convert into comp-3 format again.

Could you please let me know how can we achieve through COBOL pgm.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Feb 24, 2014 8:09 pm
Reply with quote

What you want cannot be done -- PERIOD. COMP-3 data is numbers (as in digits zero through nine) and a sign nubble exclusively. You may convert your value to 2's complement, or you may have your value in COMP-3 -- you CANNOT have both.
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: Mon Feb 24, 2014 8:22 pm
Reply with quote

Hello,

How will these flip-flopped values intended to be used?

If you explain what the usage will be someone may have an alternate suggestion.

You could define another field and keep both?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Tue Feb 25, 2014 1:19 am
Reply with quote

You might wants to try converting 2's to Disply first and then Decimal.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Tue Feb 25, 2014 7:19 am
Reply with quote

When Cobol converts data in packed decimal to "2s complement," which most of us call binary, it uses the hardware CVB (Convert to Binary) instruction, either inline or in a subroutine. CVB automatically creates the proper 2s complement value.

I wrote up the following sample Assembler program to show the steps that Cobol performs.
Code:
CVBNEG   CSECT
         USING *,12
         SAVE  (14,12),,*
         LR    12,15
         ZAP   DWORK,SOURCE
         CVB   0,DWORK
         ST    0,RESULT
         UNPK  MSG1VAL(L'MSG1VAL+1),SOURCE(L'SOURCE+1)
         NC    MSG1VAL,=16X'0F'
         TR    MSG1VAL,HEXTAB
         UNPK  MSG2VAL(9),DWORK(5)
         UNPK  MSG2VAL+8(L'MSG2VAL-8+1),DWORK+4(L'DWORK-4+1)
         NC    MSG2VAL,=16X'0F'
         TR    MSG2VAL,HEXTAB
         UNPK  MSG3VAL(L'MSG3VAL+1),RESULT(L'RESULT+1)
         NC    MSG3VAL,=16X'0F'
         TR    MSG3VAL,HEXTAB
         LA    0,L'MSG1
         LA    1,MSG1
         TPUT  (1),(0),R
         LA    0,L'MSG2
         LA    1,MSG2
         TPUT  (1),(0),R
         LA    0,L'MSG3
         LA    1,MSG3
         TPUT  (1),(0),R
         RETURN (14,12),T,RC=0
DWORK    DC    D'0'
HEXTAB   DC    C'0123456789ABCDEF'
RESULT   DC    F'0'
SOURCE   DC    X'000021111D'
MSG1     DC    0C'SOURCE = 000021111D'
         DC    C'SOURCE = '
MSG1VAL  DC    CL(L'SOURCE*2)' ',C' '
MSG2     DC    0C'DWORK = 0123456789ABCDEF'
         DC    C'DWORK = '
MSG2VAL  DC    CL(L'DWORK*2)' ',C' '
MSG3     DC    0C'RESULT = 01234567'
         DC    C'RESULT = '
MSG3VAL  DC    CL(L'RESULT*2)' ',C' '
         END   CVBNEG
The CVB instruction uses an 8 byte packed decimal data area, so the ZAP (Zero and Add Decimal) instruction expands the source to 8 bytes. The output from CVB is in a register, so the program stores the 32-bit register value. The remainder of the program translates the data areas to hexadecimal data for display purposes. TPUT is a macro to display a message at a TSO user's workstation, and is much easier than more traditional mechanisms for a simple program like this.

The output as displayed on my TSO workstation is
Code:
SOURCE = 000021111D     
DWORK = 000000000021111D
RESULT = FFFFAD89       
Back to top
View user's profile Send private message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 45
Location: india

PostPosted: Tue Feb 25, 2014 9:54 am
Reply with quote

Robert,

I need only one conversion from - neg comp-3 to 2's compliment.

Could you please let me know the logic in cobol.

I have an amount field having below value.

00211
0011D

I need to convert this amount field into 2'c ompliment in the below way.

FFF2
FFFB

Thanks,
Dharma Rao
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Feb 25, 2014 12:29 pm
Reply with quote

read the COBOL manual about the definition of a BINARY number
and after that a plain good old assignment statement will do!

in every computer/hardware binary negative numbers are stored in the two complement representation

but still the question does not make any sense
Back to top
View user's profile Send private message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 45
Location: india

PostPosted: Tue Feb 25, 2014 12:36 pm
Reply with quote

enrico,

Could you please let me know the cobol logic ; how can it be done
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Feb 25, 2014 1:38 pm
Reply with quote

we are going into a loop here ...

start by reading the IBM pronicple of operations ably the number reprentation in IBM z architecture machines ,

here anyway a short resume of it

using the number 100 as an example

Code:
zoned positive
x'F1F0C0'
zoned negative
x'F1F0D0'

packed positive
x'100c'
packed negative
x'100d'

binary positive
x'00000064'
binary negative ( 2's complement notation )
x'FFFFFF9C'



the transformation from one format to the other is done
using the proper COBOL declarations
and the move instruction

anyway Your math is just wrong

the binary representation of -21111 is x'FFFFAD89'

what you posted is the representation of a -213

so... reset Your neurons and start over from scratch
icon_biggrin.gif

You can test everything with a simple rexx snippet ...

Code:
say c2x(D2C(-21111, 4))
say c2d("FFFFFF2b"x,4)

say c2x(D2C(100, 4))
say c2x(D2C(-100, 4))
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: Tue Feb 25, 2014 7:25 pm
Reply with quote

Hello,

Unless i misunderstand, can you not simply MOVE the value frm one field type to the other?

Then wriote bpth fields into a file and view the file in hex.

As i mentioned before, if you explain how this will be used, we can provide more useful replies . . .
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:

Back to Top