Click here for Mitchell Humphrey & Co. sponsor message

 

Using Control-Y traps

By Shawn M. Gordon

Did you ever notice how you can use the <ctrl>+Y key combination to do interrupt processing in many programs such as Query, MPEX, and Suprtool? Have you ever wondered how they do it? I did, so many years ago I learned just enough SPL to write a <ctrl>+Y trap – because in my ignorance, I didn’t think it could be done in COBOL, and I am embarrassed to say that I never noticed the information in the COBOL manual.

Our tip this month comes by way of Tim Ericson at Denkor Dental Management (the NewsWire hat is in the mail). I would like to thank Tim, and Tim would like to thank the HP COBOL II/XL Programmer’s Guide, pages 4-55 and 4-56. See the figure below for an example of the code that arms and handles the <ctrl>+Y trap.

1 $PAGE
1.1 $CONTROL BOUNDS, DYNAMIC, LIST, POST85, SOURCE
1.2
1.3 ****************************************************************
1.4 * *
1.5 * CONTROLY.SOURCE 11/15/94 T. ERICSON *
1.6 * *
1.7 * THIS SUBPROGRAM ARMS A CONTROL-Y TRAP, AND MUST BE CALLED *
1.8 * FROM A MAIN PROGRAM. THE FOLLOWING CODE MUST BE INCLUDED *
1.9 * IN THE MAIN PROGRAM: *
2 * *
2.1 * . *
2.2 * . *
2.3 * . *
2.4 * WORKING-STORAGE SECTION. *
2.5 * *
2.6 * 01 CONTROL-Y EXTERNAL PIC X. *
2.7 * 88 CONTROL-Y-HIT VALUE "Y". *
2.8 * 88 CONTROL-Y-OFF VALUE "N". *
2.9 * *
3 * . *
3.1 * . *
3.2 * . *
3.3 * PROCEDURE DIVISION. *
3.4 * *
3.5 * CALL "ARM-CONTROL-Y". *
3.6 * *
3.7 * . *
3.8 * . *
3.9 * . *
4 * LOOP-POINT. *
4.1 * *
4.2 * . *
4.3 * . *
4.4 * . *
4.5 * IF CONTROL-Y-HIT *
4.6 * DISPLAY "DO YOU WISH TO CONTINUE? " *
4.7 * WITH NO ADVANCING *
4.8 * ACCEPT ANSWER *
4.9 * IF ANSWER = "N" *
5 * STOP RUN *
5.1 * END-IF *
5.2 * SET CONTROL-Y-OFF TO TRUE. *
5.3 * *
5.4 * GO TO LOOP-POINT. *
5.5 * . *
5.6 * . *
5.7 * . *
5.8 * *
5.9 * COMPILE AND LINK THE TWO SOURCE FILES TOGETHER LIKE THIS: *
6 * *
6.1 * :COB85XL MAINSOURCE, USLMAIN *
6.2 * :COB85XL CONTROLY.SOURCE, USLSUB *
6.3 * :LINK FROM=USLMAIN, USLSUB; TO=PROGRAMFILE *
6.4 * *
6.5 ****************************************************************
6.6
6.7 $PAGE
6.8 IDENTIFICATION DIVISION.
6.9 PROGRAM-ID. ARM-CONTROL-Y.
7
7.1 DATA DIVISION.
7.2 WORKING-STORAGE SECTION.
7.3
7.4 01 PROCNAME PIC X(20) VALUE "!control_y_trap!".
7.5 01 PLABEL PIC S9(09) COMP.
7.6 01 OLDPLABEL PIC S9(09) COMP.
7.7 01 PROGFILE PIC X(40).
7.8
7.9 01 CONTROL-Y EXTERNAL PIC X.
8 88 CONTROL-Y-HIT VALUE "Y".
8.1 88 CONTROL-Y-OFF VALUE "N". 8.2
8.3 PROCEDURE DIVISION.
8.4
8.5 01-START.
8.6
8.7 CALL INTRINSIC "HPMYPROGRAM"
8.8 USING PROGFILE.
8.9 CALL INTRINSIC "HPGETPROCPLABEL"
9 USING PROCNAME PLABEL \\ PROGFILE.
9.1 CALL INTRINSIC "XCONTRAP"
9.2 USING PLABEL OLDPLABEL.
9.3 EXIT PROGRAM.
9.4
9.5 ENTRY "CONTROL-Y-TRAP".
9.6
9.7 DISPLAY "< CONTROL Y >".
9.8 DISPLAY " ".
9.9 SET CONTROL-Y-HIT TO TRUE.
10 CALL INTRINSIC "RESETCONTROL".

 

Ok, let’s go over what is going to happen here. Tim’s comments at the top of the code tell you how to use the program, but let’s talk about what may not be so obvious. First the call to HPMYPROGRAM will return the fully qualified MPE file name of the program that is calling it, which we will need for our next call to HPGETPROCPLABEL. This intrinsic will search for the named procedure label – in our case the entry for “CONTROL-Y-TRAP” to use as the interrupt address. It starts searching from the named program until it finds the procedure label, and returns the address into our variable PLABEL.

We then call XCONTRAP, which is the actual trap handler. Here we pass the PLABEL of our interrupt, and the intrinsic will return the procedure label of the current address in the code.

This subroutine should only have to be called once from your main program. Once the trap is enabled, any time the user hits <ctrl>+Y, you will end up calling the “CONTROL-Y-TRAP” entry point and displaying the information in that routine. It is up to your calling process to decide what to do with this information. The entry point will also re-arm the trap with the call to RESETCONTROL.

One good application of a <ctrl>+Y trap is when you are serially reading large amounts of data from a dataset or flat file. If you are keeping counters, then the user can easily tell what progress has been made, and dump out if desired. This can be a handy debugging tool as well, if you use it correctly.

Well that wraps it up for this month. Next month I am finally going to get to COBOL macros, like I’ve been promising for months. Keep those cards and letters coming, and earn yourself a free 3000 Always Online hat for tips you submit, either to the NewsWire or to me at smga@compuserve.com.


Shawn M. Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.


Copyright 1998, The 3000 NewsWire. All rights reserved.