MainframeSupports
tip week 41/2006:

When you code EDIT macroes doing a lot of work they do not always run as fast as you might like them to. Fortunately it is possible to code EDIT macroes in other languages than CLIST and REXX. I will now show you an example in COBOL.

There is an important detail about EDIT macroes coded in COBOL or other compiled languages. They end up as LOAD modules and LOAD modules are not located in the SYSPROC or SYSEXEC concatenation. Therefore you have to tell the ISPF editor that your favourite EDIT macro is a LOAD module. Either you put a !-character in front of the name of the EDIT macro or you code a little REXX (or CLIST) shell program that might look like this:

/* REXX */
ADDRESS ISREDIT
"MACRO"
"DEFINE MYMACRO PGM MACRO"
"MYMACRO"

This REXX EDIT macro starts a LOAD module called MYMACRO. The macro call DEFINE MYMACRO PGM MACRO tells the ISPF editor to look for a macro called MYMACRO using the standard search mechanism for LOAD modules. The macro call MYMACRO simply starts the macro. I strongly recommend this little trick because you might forget to put a ! in front of the macro name. Some emulators might translate ! to another character. The ! character might be another character if you are using another language code as for instance danish where the ! is a ¤ or a €. If you use a shell program like the above you do not need to think about language codes and other strange stuff.

Now all you need is to code MYMACRO as an EDIT macro that will be translated into a LOAD module. Here comes an example on how MYMACRO might look:

...
01  ISPF-COMMAND PIC X(8).
01  ISPF-NAME PIC X(8).
01  ISPF-TYPE PIC X(8).
01  BYTE-COUNT PIC S9(9) COMP.
01  MACRO-COMMAND PIC X(80).
01  MACRO-COMMANDL PIC S9(9) COMP.
01  CSRLINE PIC S9(9) COMP.
...
MOVE 'ISREDIT' TO ISPF-COMMAND
MOVE 5 to MACRO-COMMANDL
MOVE 'MACRO' to MACRO-COMMAND
CALL 'ISPLINK' USING ISPF-COMMAND MACRO-COMMAND MACRO-COMMANDL
...
MOVE 'VDEFINE' TO ISPF-COMMAND
MOVE 'CSRLINE' TO ISPF-NAME
MOVE 'FIXED' TO ISPF-TYPE
MOVE 4 TO BYTE-COUNT
CALL 'ISPLINK' USING ISPF-COMMAND ISPF-NAME CSRLINE ISPF-TYPE BYTE-COUNT
...
MOVE 'ISREDIT' TO ISPF-COMMAND
MOVE 25 to MACRO-COMMANDL
MOVE '(CSRLINE) = LINENUM .ZCSR' to MACRO-COMMAND
CALL 'ISPLINK' USING ISPF-COMMAND MACRO-COMMAND MACRO-COMMANDL
...
DISPLAY 'CURSOR-LINE IS LINE ' CSRLINE
...
MOVE 'VDELETE' TO ISPF-COMMAND
MOVE 'CSRLINE' TO ISPF-NAME
CALL 'ISPLINK' USING ISPF-COMMAND ISPF-NAME

I have skipped a lot of the necessary COBOL stuff in order to get to the point. The first part is the minimum number of declarations in working-storage section. After this follows a call in procedure division to ISPF using ISPLINK. This first call exactly matches a ISREDIT "MACRO" call in REXX. After this call the ISPF editor will treat the program as an EDIT macro. Now you just go ahead, almost. you must remember to VDEFINE all variables that is communicated between EDIT and the program. That is what I do with a line number called CSRLINE. The next call puts the line number of the line where the cursor is located when Enter was pressed into variable CSRLINE. This line number is now displayed just to see if the program works. The last call (VDELETE) cleans up the connection created by VDEFINE between EDIT and the program.

Now it is only your imagination that sets the limits. It is worth mentioning that you can code the ISREDIT calls in another fashion where you do not have to tell the length of the individual MACRO commands. Instead you use the same delimiter at the start and in the end of each MACRO command. You can read all about EDIT macroes in the ISPF manual EDIT and EDIT macroes. If you are not familiar with VDEFINE and VDELETE you can read about these commands in the manual ISPF services guide.

Previous tip in english        Sidste danske tip        Tip list