Home The Company Publications Products Links Tips

Tips, Tricks, and Techniques

Last update: 30 April 2004

Pause/Wait for NATURAL Programs


Question

Does anyone have any information about an Assembler program that issues a 'wait' to the operating system??? Is there a pause/wait routine for NATURAL?

1st Answer to 1st Question

If its for a NATURAL application, you could use CMROLL.
Short example program below.
* #CMROLL - NOTE THE PARM MUST BE FORMAT (B2)
RESET #TIME-VAR(B2)
*
MOVE 1 TO #TIME-VAR /* EACH BYTE IS A SECOND.
WRITE '=' *TIMN
CALL 'CMROLL' #TIME-VAR
WRITE '=' *TIMN
END

2nd Answer to 1st Question

Basically, the 'CALL CMROLL' is the best technique.

My experience with this type of thing is with NATURAL under CICS and whilst CMROLL is one of 'those CM' routines it is the best to use in this case.

I know one can code a simple external routine to sleep (perhaps using EXEC CICS WAIT()) but the problem is that using this method a user transaction continues to hold the Thread it is executing in. ie if you have 100+ users sharing, say 16 Threads, and 16 of them are paused then no one else gets a go.

Using CMROLL will roll the user out of the Thread and make it available for other users during the wait.

One still needs to be careful with CMROLL because whilst the Thread is released the paused user still runs as a CICS task. Depending on how many users are in this state at the same time (and pause duration) will guide your tuning of CICS max task and CICS active max task parameters.

One further note is that the increased elapsed time of a transaction with the pause will affect response time statistics.

I once wrote an application that when logged on, would continously update a Help Desk Request list every 10 minutes and then slept with CMROLL. Whilst it had the same efficiency as someone hitting ENTER every 10 minutes for 8 hours (6 times/hour * 8 = 48 transactions) the CICS task/transaction had a response time of 8 hours which kinda skewed the performance figures! You could exclude transactions over a certain elapsed time or in my case exclude times from a specific terminal.

Perhaps one day CMROLL will be callable via a SYSEXT subroutine.

3rd Answer to 1st Qeuestion

Even though CMROLL is one of "those CM" routines, there is an example program, SUSPEND, in the SYSEXTP library provided by Software AG. Here is the program:

***********************************************************************
*                                                                     *
*                   NATURAL 2.2 TELEPROCESSING SAMPLES                *
*                                                                     *
*                      ROLL OUT AND SUSPEND SESSION                   *
*                                                                     *
***********************************************************************
*                                                                     *
* THE CURRENT SESSION IS ROLLED OUT (IN THREAD ENVIRONMENTS ONLY) AND *
* SET IN WAIT STATUS FOR THE SPECIFIED TIME. OPTIONALLY, A REQUEST ID *
* CAN BE SUPPLIED (UNDER CICS ONLY). IT MAY BE USED TO REACTIVATE     *
* THE SUSPENDED SESSION FROM ANOTHER TASK BY 'EXEC CICS CANCEL REQID'.*
*                                                                     *
* IF NO TIME INTERVAL IS SPECIFIED, ROLL OUT IS PERFORMED ONLY IF     *
* ANOTHER SESSION IS WAITING FOR THIS THREAD. THIS CAN BE USED IN     *
* VERY CPU TIME CONSUMING PROGRAMS TO RELEASE THE THREAD FROM TIME    *
* TO TIME.                                                            *
*                                                                     *
* 'CMROLL' IS AVAILABLE IN ALL ENVIRONMENTS, EVEN IN BATCH.           *
*                                                                     *
***********************************************************************
DEFINE DATA LOCAL
  01  INTERVAL (I2) INIT <4>           /* SUSPEND SESSION FOR 4 SECONDS
  01  REQID (A8) INIT <'MYREQID'>      /* CICS REQUEST ID (OPTIONAL)
END-DEFINE
  SET CONTROL 'N'                      /* NEXT WRITE WITHOUT READ
  WRITE NOTITLE 'ABOUT TO WAIT FOR' INTERVAL 'SECONDS AT ' *TIMX
  EJECT                                /* FORCE NEW SCREEN
  CALL  'CMROLL' INTERVAL REQID        /* SUSPEND SESSION
  WRITE NOTITLE 'RETURN FROM WAIT AT ' *TIMX
  END


2nd Question

I am using NATURAL for Windows NT v223 and I am looking for a way for a NATURAL program to efficiently wait for a specified amount of time.

Ideally I would like to wait on a Windows event timer or something. I do not want Natural to spin in a loop; essentially I do not want NATURAL to waste CPU doing nothing. Is there a better way for NATURAL to wait ?

1st Answer to 2nd Question

How about calling a VB program with a timer control for example?

2nd Answer to 2nd Qeustion

Check the dialog timers off the dialog menu in natural. I've seen in NLS, but not sure about Natural NT (don't have a copy in front of me). You'll have to use a dialog object instead of a program...

Top Page


Back to NATURAL Tips, Tricks, Techniques -- Overview