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

Can we add comp-3 vairable with Comp-5 variable


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

New User


Joined: 21 Jan 2006
Posts: 48
Location: india

PostPosted: Mon Aug 20, 2007 10:23 am
Reply with quote

Hi All,
Can we add comp-3 vairable with Comp-5 variable without getting any compile/run time error.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Aug 20, 2007 12:05 pm
Reply with quote

What was the result when you tried it..?
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Mon Aug 20, 2007 2:06 pm
Reply with quote

YES! That's the beauty of COBOL.
Back to top
View user's profile Send private message
noorkh

New User


Joined: 06 Mar 2006
Posts: 76
Location: Chennai

PostPosted: Mon Aug 20, 2007 6:04 pm
Reply with quote

Hopefully you can do. Because as a storage both works in Hexadecimal.
Back to top
View user's profile Send private message
kanak

Moderator


Joined: 12 Mar 2005
Posts: 252
Location: India

PostPosted: Wed Aug 22, 2007 2:32 pm
Reply with quote

I guess COMP-5 is same as comp-2 and adding comp-2 and comp-3...
Might can give some issuee under certain circumstance
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Wed Aug 22, 2007 3:59 pm
Reply with quote

kanak wrote:
I guess COMP-5 is same as comp-2
Wrong guess.

COMP-5 stands for "binary native". On the mainframe this is not really an issue. On ohter platforms, however, there are processor architectures representing integers in a different way (http://en.wikipedia.org/wiki/Endianness). All those computers can run COBOL so sometimes the cobol compilers forces those binary-integers to behave in a standard way (comp-4). This might be sub-optimal for calculations. Specifiying COMP-5 allows native represention and optimal performance for calculations (comp-3 does not perform at all outside the mainframe!) .

So, when you want to produce portable code, always use comp-5 for your calculations.

I've also used this in the past to test at execution time to determine on which machine the program ran:
Code:
       01  Machinetest.
           03 binair-0000-0100-pic-X   pic X(2)  value X'0004'.
           03 which-endian             redefines
              binair-0000-0100-pic-X   pic S9(4) comp-5.

           03 B-I-G-endian value +0004 pic S9(4) comp-5.
           03 litle-endian value +1024 pic S9(4) comp-5.
       PROCEDURE DIVISION.
      ********************
       000-MAIN Section.
       000-010.
            evaluate which-endian
               when B-I-G-endian
                   display "this is the AIX (powerPC)"
               when litle-endian
                   display "this is a PC (intel inside!)"
               when other
                   display "how the *beep* do you run this program?"
            end-evaluate.

Those days I was coding & testing on windows (Micro Focus NetExpress) and the target machine was a R6000 (Micro Focus ServerExpress).
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 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 Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top