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

Synchronized clause in COBOL


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

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Tue Feb 14, 2006 11:32 am
Reply with quote

Hi,

Can someone explain Synchronized clause in COBOL? I would like to have a complete detail to get to know about it.

T & R
Prabs
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Tue Feb 14, 2006 12:33 pm
Reply with quote

I think you can find a very detailed explanation in the fine manual.

O.
Back to top
View user's profile Send private message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Tue Feb 14, 2006 5:20 pm
Reply with quote

Hi,

Thanks for the manual, but still unclear. It would be helpful if it can be explained with some examples as this seems to be a standard Q in cobol for all interviews


T & R
Prabs
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Tue Feb 14, 2006 5:29 pm
Reply with quote

Have u read Computer Organization? Do you know what a bit,byte and memory word means? Is so its a way to make sure that memory allocated to variables start from word boundries. As CPU reads words at a time and not bit or byte.


Hope you got it. If not? Better go to someone personally and ask him to explain it to you.
Back to top
View user's profile Send private message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Fri Feb 17, 2006 9:56 am
Reply with quote

Hi Umesh,

As you suggest, Iam not that naive to not to know about bit/byte/word. There are other intricacies which are involved in Synchronized clause.
Memory allocated to variables start from word boundries is only the outer crux of it.

T & R
Prabs
Back to top
View user's profile Send private message
umeshkmrsh

New User


Joined: 21 Sep 2005
Posts: 79
Location: India

PostPosted: Fri Feb 17, 2006 11:15 am
Reply with quote

prabs2006 wrote:
Hi Umesh,

As you suggest, Iam not that naive to not to know about bit/byte/word. There are other intricacies which are involved in Synchronized clause.
Memory allocated to variables start from word boundries is only the outer crux of it.



So you know now that synchronized clause make memeory allocation to start from word boundries. Can u tell me what is the advantage of doing so? without knowing how CPU works.
Back to top
View user's profile Send private message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Fri Feb 17, 2006 11:56 am
Reply with quote

Advantage: Run time performance will be significantly faster.
But What I need is to be xplained with an example so that the confusion in the total no of bytes alloted will be cleared.

01 ws-example.
05 ws-var1 pic x(3).
05 ws-var2 pic s9(04) comp sync.
05 ws-var3 pic 9(5).

How many bytes this will occupy?


T & R
Prabs
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Feb 19, 2006 5:46 am
Reply with quote

Hi Pras,

Have you tried to compile you example?
Back to top
View user's profile Send private message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Mon Feb 20, 2006 10:01 am
Reply with quote

Hi,

I dont have the luxury of checking and compiling this code as I am in the transition phase. But as per theoretical study of Sync clause, this shud take 11 bytes as there will be a slack byte created by WS-var1
Am I right?

T & R
Prabs
Back to top
View user's profile Send private message
KS

New User


Joined: 28 Feb 2006
Posts: 91
Location: Chennai

PostPosted: Thu Mar 02, 2006 10:47 am
Reply with quote

SYNCHRONIZED clause :

- Sometimes used with USAGE IS COMP or USAGE IS INDEX items.

- It is used to optimize speed of processing but it does so at the expense of increased storage requirements

- Computer memories are organized in such a way that there are natural addressing boundaries - such as word boundaries.

If no special action is taken some data items in memory may straddle theses boundaries.This may cause a processing overhead as the CPU may need two fetch cycles to retrieve the data from memory.

See the following example...declared without SYNC

01 ThreeBytes pic x(3) VALUE "GOD".
01 TwoBytes pic 9(4) COMP.

G O -> Word 1
D Num -> Word 2
ber space -> Word 3

To use the number, the CPU has to execute two fetch cycles -
- one to get the first part of the number in Word2 and the second to get the second part of the number in Word3.
- This double fetch slows down calculations.

declared with SYNC :

01 ThreeBytes pic x(3) VALUE "GOD".
01 TwoBytes pic 9(4) COMP.

G O -> Word 1
D space -> Word 2
Num ber -> Word 3

The number in TwoBytes is now aligned along the word boundary, so the CPU only has to do one fetch cycle to retrieve the number from memory.
This speeds up processing but at the expense of wasting some storage (the second byte of Word2 is no longer used).

Hope this makes it clear..

Thanks,
KS
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