MainframeSupports
tip week 25/2012:

This week I will reveal to you how you can read the screen buffer from any ISPF screen. For many years ISPF has given you access to four variables which makes it possible for you to acces the ISPF screen buffer including the cursor position. The four variables are: ZSCREENI which contains the image of the screen as one long string of characters, ZSCREENC which contains the position of the cursor within ZSCREENI where 0 is the first position and so forth, ZSCREEND which contains the number of lines on the screen and ZSCREENW which contains the width of the screen in characters.

Using this information I have made the following small and useful REXX which I will call SCRNSHOT:

/* REXX */
ARG LINECNT COLCNT REUSE
ADDRESS ISPEXEC "VGET (ZSCREENI ZSCREENW ZSCREEND ZSCREENC)"
ADDRESS TSO "ALLOC FI(SCRNSHOT) DA(SCRNSHOT) MOD CATALOG",
            " SPACE(1 1) TRACKS RECFM(F B) LRECL("ZSCREENW") REUSE"
DROP SCRNSHOT.
IF DATATYPE(LINECNT, 'W') = 0
THEN
  LINECNT = 1
IF DATATYPE(COLCNT, 'W') = 0
THEN
  COLCNT = 8
STARTPOS = ZSCREENC + 1
IF REUSE = ''
THEN DO
  SCRNSHOT = STARTPOS
  ADDRESS ISPEXEC "VPUT SCRNSHOT"
END
ELSE DO
  ADDRESS ISPEXEC "VGET SCRNSHOT"
  STARTPOS = SCRNSHOT
END
DO LINENO = 1 TO LINECNT
  SCRNSHOT.LINENO = SUBSTR(ZSCREENI, STARTPOS, COLCNT)
  STARTPOS = STARTPOS + ZSCREENW
END
SCRNSHOT.0 = LINECNT
ADDRESS TSO "EXECIO * DISKW SCRNSHOT (STEM SCRNSHOT. OPEN FINIS)"
ADDRESS TSO "FREE FI(SCRNSHOT)"
ADDRESS ISPEXEC "EDIT DATASET(SCRNSHOT)"
EXIT

If you use the command TSO SCRNSHOT the first time you execute this REXX, you will probably be a little disappointed. It just copies the first 8 characters starting at the cursor position when you pressed Enter to the dataset userid.SCRNSHOT and displays it in an EDIT session. The cursor was most likely positioned in the command area one position to the right of the T in SCRNSHOT. The first 8 characters starting at this cursor position are most likely all blanks. Consequently userid.SCRNSHOT will contain a blank line which is pretty boring.

Your next attempt should rather be something like the command TSO SCRNSHOT 10 70 and before you press Enter you should place the cursor in the upper right corner of the screen. Now the EDIT session will display the first 70 characters in the first 10 lines of the panel as it looked when you pressed Enter. A blank line will still be present in the first record of userid.SCRNSHOT as SCRNSHOT appends the newest screen area to the data already present in userid.SCRNSHOT. It is up to you to manage the contents of userid.SCRNSHOT using the EDIT session. SCRNSHOT accepts a third parameter which contents does not matter. The presence of this third parameter instructs SCRNSHOT to use the same cursor position as in the previous invocation of SCRNSHOT.

I hope this REXX and my description of how it works will make you able to develop new fancy REXX programs where the cursor position in different panels controls what is going to happen. I will be happy to hear about your ideas or even better: share them using the MainframeSupport LinkedIn user group.

Previous tip in english        Forrige danske tip        Tip list