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

Efficient COBOL coding


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kalaignar_S
Warnings : 1

New User


Joined: 06 Jan 2006
Posts: 21

PostPosted: Wed May 10, 2006 4:22 pm
Reply with quote

Which one is the efficient COBOL coding, has been mentioned below??
Why??


MOVE A TO B.

COMPUTE B = A.

If anybodies know this let me know the reason..


Thanks
Kalaignar
Back to top
View user's profile Send private message
ralph_v

New User


Joined: 07 Jul 2005
Posts: 27

PostPosted: Wed May 10, 2006 5:06 pm
Reply with quote

COMPUTE B = A is efficient coding because you can check for truncation using ONSIZE ERROR clause.
Back to top
View user's profile Send private message
parikshit123

Active User


Joined: 01 Jul 2005
Posts: 269
Location: India

PostPosted: Wed May 10, 2006 5:27 pm
Reply with quote

Well,

When you say 'efficient coding', offcourse COMPUTE should be a better choice. You can do more with that. for example you can check for size or even overflow....

But, when it comes to "efficient code", if you ignore exceptions, MOVE is efficient. as it maps to less number of instructions.


I hope the difference between "efficient coding" and "efficient code" is clear.
Back to top
View user's profile Send private message
parikshit123

Active User


Joined: 01 Jul 2005
Posts: 269
Location: India

PostPosted: Wed May 10, 2006 5:28 pm
Reply with quote

Also,
I would suggest you to choose a good title for the topic.

I feel that "Efficient Coding" is too general for this topic.

However, it was really a nice question.

Thanks,
Parikshit
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed May 10, 2006 10:05 pm
Reply with quote

Kalaignar,

It's interesting that in the specific example you give, the compiler generates the exact same code for move and compute.

Code:

WORKING-STORAGE SECTION.                             
01  A                        PIC S9(5)    VALUE 123.
01  B                        PIC S9(5)    VALUE 345.
PROCEDURE DIVISION.   
.000028  MOVE A                      TO B.                                                                       
.   000234  F224 D0E8 8000          PACK  232(3,13),0(5,8)        TS2=0       
.   00023A  F822 D0E8 D0E8          ZAP   232(3,13),232(3,13)     TS2=0       
.   000240  F342 8008 D0E8          UNPK  8(5,8),232(3,13)        B           
.000029  COMPUTE B = A.                                                               
.   000246  F224 D0E8 8000          PACK  232(3,13),0(5,8)        TS2=0       
.   00024C  F822 D0E8 D0E8          ZAP   232(3,13),232(3,13)     TS2=0       
.   000252  F342 8008 D0E8          UNPK  8(5,8),232(3,13)        B           
.000031  GOBACK                                                               
Back to top
View user's profile Send private message
parikshit123

Active User


Joined: 01 Jul 2005
Posts: 269
Location: India

PostPosted: Thu May 11, 2006 4:12 pm
Reply with quote

Hi David,

Thats correct!
the specific example generates the same code.

Now, suppose if you are using ONSIZE ERROR clause then compiler will definitely generate more number of instructions. isn't it?

So, only an assignment is your need, offcourse simple move is a better choice.

Any further ideas.. seems to be a nice topic isn't it?

Thanks,
Parikshit.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top