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

Compare PIC S9(9) COMP with PIC 9(9) variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
siddhartha biswas
Currently Banned

New User


Joined: 04 May 2008
Posts: 15
Location: india

PostPosted: Wed Sep 15, 2010 3:12 pm
Reply with quote

I need to compare PIC S9(9) COMP variable with PIC 9(9) variable and write in output file if they match.

Is it possible to compare them directly or I need to move PIC S9(9) COMP to a PIC 9(9) variable before the comparison ?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Sep 15, 2010 4:27 pm
Reply with quote

Why did you not research this in the COBOL manual (link at the top of the page)? If you do the research, you will find that numeric variables can be compared with an IF statement with no problems -- and so can alphanumeric variables. I'll leave it up to you to determine if both of your variables are numeric.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Sep 15, 2010 5:16 pm
Reply with quote

Then there's ... drum roll ...





testing.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Sep 15, 2010 5:20 pm
Reply with quote

I think "testing" is becoming the four-letter word of IT, even though it can be a lot of fun.
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: Wed Sep 15, 2010 7:16 pm
Reply with quote

Testing. . . We don' need no steenkin' testing. . .

If it clean compiles, it is ready for production. . . icon_rolleyes.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Wed Sep 15, 2010 7:52 pm
Reply with quote

Dick, you may say this ...
Quote:
If it clean compiles, it is ready for production.
but when I was in the Old Country (working for a previous employer), one of the programmers there told me a clean compile meant the program was tested. Sadly enough, the quality of the code reflected this attitude pretty much throughout. I had to tell the U.S. programmers that they were not allowed to ask "Why?" when working on the source for that system.
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: Wed Sep 15, 2010 8:25 pm
Reply with quote

Hi Robert,

Quote:
but when I was in the Old Country (working for a previous employer), one of the programmers there told me a clean compile meant the program was tested.
A couple of places i supported (ya get to see a bunch of strange things in 3 decades of being a migrant data worker) had it as policy that when the programmer got a clean compile, the programmer was done.

Fortunately, the next step was the "formal unit testing" with an analyst/programmer. Unfortunately, they wasted so much time that nothing moved forward - which was how i was invited to participate. Told them that immediately, the programmer would at least make sure that screens were displayed properly and reports had basically correct content. This alone saved more than 80% of the trips back for re-work. Testing stopped at the first error and continued when that particular error had been "fixed". Mercy. . .

One of the nicest "perks" about being the new crisis intervention guru is that when you provide direction, you tend to get your way icon_smile.gif The newcomer can get "things" implemented about which people already on staff are told no.

d
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: Wed Sep 15, 2010 9:08 pm
Reply with quote

I'm thinking out loud here and was pondering the fact that a false positive could be raised in the program which has the PIC 9(09) COMP field and the value exceeds the Picture Clause size of 999999999, due to the use of the TRUNC(BIN) compiler option?

It really depends on how the compiler builds both fields for comparison?

Does it convert them both to packed-dblwords or converts only the display-numeric field to a fullword?

But then again, maybe I'm completely off on a tanget and there's nothing to worry about? icon_eek.gif

Just thought I'd raised this as a potential pitfall....

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

Global Moderator


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

PostPosted: Wed Sep 15, 2010 10:46 pm
Reply with quote

Bill: this code
Code:
       01  WS-COMP-VAR           PIC S9(09) COMP VALUE  123456789.
       01  WS-DISP-VAR           PIC S9(09)      VALUE  234567890.

       PROCEDURE DIVISION.
       MAIN-PARA.
           COMPUTE WS-COMP-VAR = WS-COMP-VAR * 10 .
           DISPLAY 'COMP    ' WS-COMP-VAR.
           DISPLAY 'DISPLAY ' WS-DISP-VAR.
           IF  WS-COMP-VAR = WS-DISP-VAR
               DISPLAY 'MATCHED'
           ELSE
               DISPLAY 'UNMATCHED'
           END-IF.
translates the IF to
Code:
 000021  IF
    000408  5840 8000               L     4,0(0,8)                WS-COMP-VAR
    00040C  8E40 0020               SRDA  4,32(0)
    000410  5D40 C000               D     4,0(0,12)               SYSLIT AT +0
    000414  4E50 D118               CVD   5,280(0,13)             TS2=24
    000418  F154 D100 D11B          MVO   256(6,13),283(5,13)     TS2=0
    00041E  4E40 D118               CVD   4,280(0,13)             TS2=24
    000422  9110 D105               TM    261(13),X'10'           TS2=5
    000426  D204 D105 D11B          MVC   261(5,13),283(13)       TS2=5
    00042C  4780 B1E4               BC    8,484(0,11)             GN=20(000434)
    000430  9601 D109               OI    265(13),X'01'           TS2=9
    000434                 GN=20    EQU   *
    000434  F258 D110 8008          PACK  272(6,13),8(9,8)        TS2=16
    00043A  F844 D111 D111          ZAP   273(5,13),273(5,13)     TS2=17
    000440  D505 D104 D110          CLC   260(6,13),272(13)       TS2=4
    000446  4770 B208               BC    7,520(0,11)             GN=5(000458)
 000022  DISPLAY
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: Fri Sep 17, 2010 6:26 am
Reply with quote

Robert,

Had to take a mind break about this, but now I know what I was trying to say.

Let's say program "A" created the binary-fullword (non COMP-5) and it was compiled with TRUNC(BIN) and the value was F'1987675321', a perfectly legitimate value for a fullword. Now, this fullword is passed to program "B", but this program was compiled with TRUNC(OPT) and the fullword is defined as non COMP-5 as well. So, because of TRUNC(OPT), only F'987654321' is addressable and the high-order digit is truncated, due to the picture clause number of digits. Plus, the 9-byte display-numeric field in program "B" just so happens to equal C'987654321'. When both of these fields are converted to a "like" format by the compiler for comparison, they will be equal, raising the false positive.

Although the likelihood of this false positive occurring is remote, it can't be ruled out.

Such are the dangers of having programs, which are compiled using different TRUNC options and they deal with non COMP-5 binary-data. icon_eek.gif

COMP-5 (as you know) treats binary-fields as if the program had been compiled using TRUNC(BIN) and COMP-5 overrides all TRUNC options, regardless.

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

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Sep 17, 2010 6:27 pm
Reply with quote

As Artie Johnson once said:

In America, children should be seen but not heard.
In the Old Country, if you were heard, then you were never seen.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Sep 17, 2010 6:32 pm
Reply with quote


On a More Serious Note

For any Newbies still watching


The only way to really learn any of this stuff is to run your own tests - good data and bad - normal and screwy parms - trying different values just for the hell of it.
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: Fri Sep 17, 2010 7:17 pm
Reply with quote

Hello,

Quote:
. . . run your own tests - good data and bad - normal and screwy parms - trying different values . . .
And save these test processes. They will be most handy when verifying that some upgrade has not changed the way they work.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Sep 18, 2010 8:15 pm
Reply with quote

Hi Sid,

My concern about your problem is that one field is signed and the other isn't. Is the intent to only accept positive number matches, or is PIC 9(9) a typo?
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Compare two files with a key and writ... SYNCSORT 3
Search our Forums:

Back to Top