Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
dharmaraok

New User

Joined: 10 Mar 2011
Posts: 45
Location: india

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

Robert Sample

Global Moderator

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

 Posted: Mon Feb 24, 2014 8:09 pm    Post subject: 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.
dick scherrer

Moderator Emeritus

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

 Posted: Mon Feb 24, 2014 8:22 pm    Post subject: 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?
Rohit Umarjikar

Global Moderator

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

 Posted: Tue Feb 25, 2014 1:19 am    Post subject: You might wants to try converting 2's to Disply first and then Decimal.
steve-myers

Active Member

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

Posted: Tue Feb 25, 2014 7:19 am    Post subject:

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
dharmaraok

New User

Joined: 10 Mar 2011
Posts: 45
Location: india

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

Senior Member

Joined: 14 Mar 2007
Posts: 10700
Location: italy

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

New User

Joined: 10 Mar 2011
Posts: 45
Location: india

 Posted: Tue Feb 25, 2014 12:36 pm    Post subject: enrico, Could you please let me know the cobol logic ; how can it be done
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10700
Location: italy

Posted: Tue Feb 25, 2014 1:38 pm    Post subject: Reply to: Conversion of negative amount (comp3) field to 2's

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

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))
dick scherrer

Moderator Emeritus

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

 Posted: Tue Feb 25, 2014 7:25 pm    Post subject: 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 . . .
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics EBCDIC to ASCII conversion help t_bt2 All Other Mainframe Topics 1 Wed Sep 23, 2020 6:34 pm How do i verify the char field is hav... Raghu M N PL/I & Assembler 1 Tue Sep 22, 2020 9:26 pm RPLDDDD field for extended VSAM - ESDS amitsjcntl JCL & VSAM 0 Tue Sep 22, 2020 1:45 pm CA7 Negative dependency JOB=/ Dave Hinds CA Products 0 Thu Sep 10, 2020 7:36 pm Identify the value if the SUM of the ... PORYES SYNCSORT 4 Sun May 10, 2020 12:46 am

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us