Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
dharmaraok

New User


Joined: 10 Mar 2011
Posts: 30
Location: india

PostPosted: Mon Feb 24, 2014 5:27 pm    Post subject: Conversion of negative amount (comp3) field to 2's complimen
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: 7904
Location: Bellevue, IA

PostPosted: Mon Feb 24, 2014 8:09 pm    Post subject:
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

Site Director


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

PostPosted: Mon Feb 24, 2014 8:22 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Tue Feb 25, 2014 1:19 am    Post subject:
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 User


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

PostPosted: Tue Feb 25, 2014 7:19 am    Post subject:
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: 30
Location: india

PostPosted: Tue Feb 25, 2014 9:54 am    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 25, 2014 12:29 pm    Post subject: Reply to: Conversion of negative amount (comp3) field to 2's
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: 30
Location: india

PostPosted: Tue Feb 25, 2014 12:36 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 25, 2014 1:38 pm    Post subject: Reply to: Conversion of negative amount (comp3) field to 2's
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

Site Director


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

PostPosted: Tue Feb 25, 2014 7:25 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Conversion of a VB file to FB. isssal DFSORT/ICETOOL 1 Mon Oct 31, 2016 10:23 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us