Problem:
Can you create a screenset that has a Cancel button that will terminate some processing code?
Some of this text refers to the accompanying demo.
There may be times when your Dialog System application has to execute
some process that you may want to cancel at some point. If your
processing is done in a long-running loop in the COBOL program, then any
button that you may have on a window cannot respond to click events
during that processing.
If you want to have a Cancel button to stop processing, you will need to
break up your long-running process into small units of work, where at the
end of each unit, you will call Dialog System. When you call Dialog
System at each interval, you do not want to explicitely execute any
Dialog code (for instance, using ds-procedure), instead, you will allow
Dialog to execute a procedure via the TIMEOUT function.
You can use the TIMEOUT function to cause a procedure to be executed
after a specified amount of time if no event has occurred. This means
that we can use the TIMEOUT function to execute a Dialog procedure that
will return to COBOL via RETC or CALLOUT (if using a subprogram) to
continue processing and it will allow us to handle a button click event
when returning back to Dialog where we could cancel the processing by
setting the TIMEOUT to 0 which cancels it. The first parameter to
TIMEOUT is the amount of time in 1/100ths of a second to elapse before
executing a procedure in your Dialog code. The second parameter is the
name of the procedure to be branched to. You will have to experiment with
the TIMEOUT time and the unit of work to see what amounts work best for
the situation. Smaller TIMEOUT times will work better for faster
processing.
Because use of the TIMEOUT function allows events to occur, you should
use a dialog box to contain the Cancel button. You can set the properties
of the dialog box so that there is nothing other than the Cancel button
to click during processing. Be sure to turn off the System menu in the
properties. If you don't use a dialog box, then the user could
potentially click other buttons and select menus or the menu bar/System
menu which could stop or hold-up processing. Set the Type property of the
dialog box to "Parent modal" or "Application modal" so that the user
cannot select anything other than what's on the dialog box. If the dialog
box has a titlebar, the user can click and hold or drag it, which will
pause processing, so this is not a perfect scenario. Another problem is
that the user could click and drag in the dialog box window area which
will also pause or slow down processing.
When you click the "Read Records" button, it shows the dialog box (select
the View menu, Windows..., DBOX-READING) with the cancel button on it.
The TIMEOUT function is executed in the WINDOW-SHOWN event of
DBOX-READING. Be sure not to enable the Cancel button until the
appropriate time so that the user can't select it before processing has
started. The TIMEOUT executes the READ-SOME-RECORDS procedure of the
DBOX-READING dialog box. A RETC is done to the COBOL program so that a
unit of processing can be done. When that unit of processing is done,
Dialog System is called and the TIMEOUT executes the READ-SOME-RECORDS
procedure again. The TIMEOUT allows the Cancel button to be clicked,
which cancels the TIMEOUT and unshows the dialog box.
Resolution:
There may be times when your Dialog System application has to execute
some process that you may want to cancel at some point. If your
processing is done in a long-running loop in the COBOL program, then any
button that you may have on a window cannot respond to click events
during that processing.
If you want to have a Cancel button to stop processing, you will need to
break up your long-running process into small units of work, where at the
end of each unit, you will call Dialog System. When you call Dialog
System at each interval, you do not want to explicitely execute any
Dialog code (for instance, using ds-procedure), instead, you will allow
Dialog to execute a procedure via the TIMEOUT function.
You can use the TIMEOUT function to cause a procedure to be executed
after a specified amount of time if no event has occurred. This means
that we can use the TIMEOUT function to execute a Dialog procedure that
will return to COBOL via RETC or CALLOUT (if using a subprogram) to
continue processing and it will allow us to handle a button click event
when returning back to Dialog where we could cancel the processing by
setting the TIMEOUT to 0 which cancels it. The first parameter to
TIMEOUT is the amount of time in 1/100ths of a second to elapse before
executing a procedure in your Dialog code. The second parameter is the
name of the procedure to be branched to. You will have to experiment with
the TIMEOUT time and the unit of work to see what amounts work best for
the situation. Smaller TIMEOUT times will work better for faster
processing.
Because use of the TIMEOUT function allows events to occur, you should
use a dialog box to contain the Cancel button. You can set the properties
of the dialog box so that there is nothing other than the Cancel button
to click during processing. Be sure to turn off the System menu in the
properties. If you don't use a dialog box, then the user could
potentially click other buttons and select menus or the menu bar/System
menu which could stop or hold-up processing. Set the Type property of the
dialog box to "Parent modal" or "Application modal" so that the user
cannot select anything other than what's on the dialog box. If the dialog
box has a titlebar, the user can click and hold or drag it, which will
pause processing, so this is not a perfect scenario. Another problem is
that the user could click and drag in the dialog box window area which
will also pause or slow down processing.
When you click the "Read Records" button, it shows the dialog box (select
the View menu, Windows..., DBOX-READING) with the cancel button on it.
The TIMEOUT function is executed in the WINDOW-SHOWN event of
DBOX-READING. Be sure not to enable the Cancel button until the
appropriate time so that the user can't select it before processing has
started. The TIMEOUT executes the READ-SOME-RECORDS procedure of the
DBOX-READING dialog box. A RETC is done to the COBOL program so that a
unit of processing can be done. When that unit of processing is done,
Dialog System is called and the TIMEOUT executes the READ-SOME-RECORDS
procedure again. The TIMEOUT allows the Cancel button to be clicked,
which cancels the TIMEOUT and unshows the dialog box.