For Programmers: Free Programming Magazines  


Home > Archive > Cobol > June 2007 > Identifting sign in COMP data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Identifting sign in COMP data
kimi

2007-06-28, 6:55 pm

Hi ppl,
Can anyone tell me how to recognize whether the COMP
variables are negative or positive.
For instance in COMP-3 data , if the last nibble is 'C' then we say it
is positive and if it is 'D' or 'F' we say it is negative.

Similarly how can we recognize whether the number is positive or
negative in COMP , COMP-1 and COMP-2 data.

Rick Smith

2007-06-28, 6:55 pm


"kimi" <mraghu83@gmail.com> wrote in message
news:1183006609.523437.181340@e9g2000prf.googlegroups.com...
> Hi ppl,
> Can anyone tell me how to recognize whether the COMP
> variables are negative or positive.
> For instance in COMP-3 data , if the last nibble is 'C' then we say it
> is positive and if it is 'D' or 'F' we say it is negative.


Actually 'F' is unsigned, assumed positive.

> Similarly how can we recognize whether the number is positive or
> negative in COMP , COMP-1 and COMP-2 data.


For IBM mainframe and Micro Focus, COMP is
the same as BINARY. The most significant bit of
the most significant byte is the sign.

For IBM mainframe, COMP-1 and COMP-2
floating-point items, the most significant bit of
the most significant byte is the sign.

For Micro Focus, COMP-1 and COMP-2
floating-point items in IEEE format on Intel-type
processors, the most significant bit of the least
significant byte is the sign.

For COBOL, "we" use a conditon, such as,
IF ITEM IS NEGATIVE
...
END-IF
..



Louis Krupp

2007-06-28, 6:55 pm

kimi wrote:
> Hi ppl,
> Can anyone tell me how to recognize whether the COMP
> variables are negative or positive.
> For instance in COMP-3 data , if the last nibble is 'C' then we say it
> is positive and if it is 'D' or 'F' we say it is negative.
>
> Similarly how can we recognize whether the number is positive or
> negative in COMP , COMP-1 and COMP-2 data.
>


Hi, Kimi!

Do you actually have COMP-3 data in which the last nibble is 'F' and
this indicates a negative number? This ... surprises me.

For COMP data, it's probably safe to assume (someone correct me if I'm
wrong) that the high-order bit indicates the sign; if the bit is on,
the number is negative. The value as a whole is *probably*
twos-complement, but I've worked on systems that used sign-magnitude.

For COMP-1 and COMP-2, the high-order bit *probably* indicates the sign
(just like with COMP), but it depends on the floating-point format, and
you'll have to know what format you're using before you can get anything
else out of the data.

Is this part of your project to read COMP-1 and COMP-2 data from your
mainframe? Out of curiosity, how's that going? And which mainframe is it?

Louis
kimi

2007-06-28, 6:55 pm

On Jun 28, 1:36 pm, Louis Krupp <lkr...@pssw.nospam.com.invalid>
wrote:
> kimi wrote:
>
>
> Hi, Kimi!
>
> Do you actually have COMP-3 data in which the last nibble is 'F' and
> this indicates a negative number? This ... surprises me.
>
> For COMP data, it's probably safe to assume (someone correct me if I'm
> wrong) that the high-order bit indicates the sign; if the bit is on,
> the number is negative. The value as a whole is *probably*
> twos-complement, but I've worked on systems that used sign-magnitude.
>
> For COMP-1 and COMP-2, the high-order bit *probably* indicates the sign
> (just like with COMP), but it depends on the floating-point format, and
> you'll have to know what format you're using before you can get anything
> else out of the data.
>
> Is this part of your project to read COMP-1 and COMP-2 data from your
> mainframe? Out of curiosity, how's that going? And which mainframe is it?
>
> Louis


tnx for that guys..!!
No louis this isnt a part of that project...
Well,i am moving the COMP-1 and COMP-2 data to COMP-3 as we discussed
in the other thread..
I did try out setting the environment variables and all that... but
doesnt work..
Probably need to know the right way to set it..

Charles Hottel

2007-06-28, 6:55 pm


"kimi" <mraghu83@gmail.com> wrote in message
news:1183029576.961432.41730@i38g2000prf.googlegroups.com...
> On Jun 28, 1:36 pm, Louis Krupp <lkr...@pssw.nospam.com.invalid>
> wrote:
>
> tnx for that guys..!!
> No louis this isnt a part of that project...
> Well,i am moving the COMP-1 and COMP-2 data to COMP-3 as we discussed
> in the other thread..
> I did try out setting the environment variables and all that... but
> doesnt work..
> Probably need to know the right way to set it..
>


Have you considered using SIGN SEPARATE?


Doug Miller

2007-06-28, 6:55 pm

In article <XCNgi.1824$zA4.1630@newsread3.news.pas.earthlink.net>, "Charles Hottel" <chottel@earthlink.net> wrote:
>
>"kimi" <mraghu83@gmail.com> wrote in message
>news:1183029576.961432.41730@i38g2000prf.googlegroups.com...


>
>Have you considered using SIGN SEPARATE?


On a COMP field?

--
Regards,
Doug Miller (alphag at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Howard Brazee

2007-06-28, 6:55 pm

On Thu, 28 Jun 2007 04:32:05 -0400, "Rick Smith" <ricksmith@mfi.net>
wrote:

>
>Actually 'F' is unsigned, assumed positive.


In 1980 I worked in a shop that moved from IBM Mainframe DOS to IBM
Mainframe OS. One thing we had to do was change many programs to
move old data from unsigned to signed and back again before
comparisons. That was because the way they stored unsigned numbers
changed with the operating system. Same CoBOL, but the operating
system changed how the numbers were stored.
Michael Mattias

2007-06-28, 6:55 pm

"Howard Brazee" <howard@brazee.net> wrote in message
news:rfg783p44bhf4hq5iuscr3r865vl7438qc@
4ax.com...
> On Thu, 28 Jun 2007 04:32:05 -0400, "Rick Smith" <ricksmith@mfi.net>
> wrote:
>
[color=darkred]
> That was because the way they stored unsigned numbers
> changed with the operating system. Same CoBOL, but the operating
> system changed how the numbers were stored.


IIRC, "COMP" or "COMP-[anything'"] is always "implementor-defined" and the
only COBOL-defined storage you can absolutely assume will be the same across
platforms/operating systems are USAGE PACKED-DECIMAL (BCD) and USAGE BINARY.

In practice of course, compiler publishers will never change the storage for
"COMP[-anything]" data in their products, but as Mr. Brazee's example
demonstrates, the operating system may have an impact on it.

--
Michael C. Mattias
Tal Systems Inc.
Racine WI
mmattias@talsystems.com
>



Louis Krupp

2007-06-28, 6:55 pm

kimi wrote:
> On Jun 28, 1:36 pm, Louis Krupp <lkr...@pssw.nospam.com.invalid>
> wrote:
>
> tnx for that guys..!!
> No louis this isnt a part of that project...
> Well,i am moving the COMP-1 and COMP-2 data to COMP-3 as we discussed
> in the other thread..
> I did try out setting the environment variables and all that... but
> doesnt work..
> Probably need to know the right way to set it..
>


Sounds like this *is* part of the same effort, and now you need to know
how to interpret COMP-3 data that comes from the mainframe. You haven't
mentioned *which* mainframe...

A couple of ideas:

1. What Michael said -- use "PACKED DECIMAL" instead of "COMP-3"; it
sounds like that should be portable. Just move the floating point
fields to packed fields (be sure to give them a picture S9x.y); the
system will take care of the sign.

2. If you run into range issues with your COMP-1 (or, more likely,
COMP-2) data, go with one of my earlier suggestions about splitting the
floating point value into an exponent and a mantissa. Store those as
COMP, move the data to your UNIX system, and then put it all back
together into floating point.

Louis
William M. Klein

2007-06-29, 7:55 am

Follow up on this and your previous note.

You really are going about this entire process "backwards" (and the hardest way
possible).

If you move your COMP, COMP-3, COMP-4, Binary, and Packed-Decimal fields (on the
mainframe) to
Usage Display - Sign is Separate - fields
and
Move your COMP-1 and COMP-2 fields to "external floating point" i.e.
PIC +9.9(15)E+99
fields

BEFORE you down-load your files (using EBCDIC/ASCII conversion) then you won't
have any of these problems/questions. If you want them in COMP-xxx format on
the Workstation, then simply reverse the MOVE statements of the mainframe
program.

P.S. On the mainframe, A, B, and E *are* valid sign-nibbles for packed fields,
they are just never produced by COBOL - but COBOL can handle them.

P.P.S. On the mainframe, there is a difference between "unsigned" and
"signed-positive" nibbles, this doesn't exist on the workstation.

P.P.P.S. You can only use the "most-significant" bit for deterring the sign of
a Binary fields, if the COBOL program defines it with a "S". If the PICTURE is
unsigned, then that bit is part of the number/data.

--
Bill Klein
wmklein <at> ix.netcom.com
"kimi" <mraghu83@gmail.com> wrote in message
news:1183006609.523437.181340@e9g2000prf.googlegroups.com...
> Hi ppl,
> Can anyone tell me how to recognize whether the COMP
> variables are negative or positive.
> For instance in COMP-3 data , if the last nibble is 'C' then we say it
> is positive and if it is 'D' or 'F' we say it is negative.
>
> Similarly how can we recognize whether the number is positive or
> negative in COMP , COMP-1 and COMP-2 data.
>



kimi

2007-06-29, 7:55 am

On Jun 28, 10:14 pm, Louis Krupp <lkr...@pssw.nospam.com.invalid>
wrote:
> kimi wrote:
>
>
>
>
>
>
>
> Sounds like this *is* part of the same effort, and now you need to know
> how to interpret COMP-3 data that comes from the mainframe. You haven't
> mentioned *which* mainframe...
>
> A couple of ideas:
>
> 1. What Michael said -- use "PACKED DECIMAL" instead of "COMP-3"; it
> sounds like that should be portable. Just move the floating point
> fields to packed fields (be sure to give them a picture S9x.y); the
> system will take care of the sign.
>
> 2. If you run into range issues with your COMP-1 (or, more likely,
> COMP-2) data, go with one of my earlier suggestions about splitting the
> floating point value into an exponent and a mantissa. Store those as
> COMP, move the data to your UNIX system, and then put it all back
> together into floating point.
>
> Louis- Hide quoted text -
>
> - Show quoted text -


This is not a part of that effort...
I wanted the information on sign of packed variables for something
else which i am coding in REXX..

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com