Mainframe Utility: A

Return to Mainframe Utilities Page

Module


ISREDIT MACRO NOPROCESS (STG1,STG2,OPT1,OPT2,OPT3,OPT4,OPT5,OPT6,OPT7)
ISPEXEC CONTROL ERRORS RETURN
/**** SET MESSAGE DISPLAY ON/OFF BASED ON THE DEBUG SWITCH ***/
ISPEXEC VGET (DBGSWTCH) PROFILE
IF &DBGSWTCH = &STR(ON) THEN CONTROL MSG LIST CONLIST SYMLIST NOFLUSH
ELSE CONTROL NOMSG NOLIST NOFLUSH NOPROMPT
/**********************************************************************/
/* UTILITY NAME : A                                                   */
/* DATE WRITTEN : 9-29-88                                             */
/* AUTHOR       : DAVE LEIGH                                          */
/* DESCRIPTION  : INSERT 'STRING 2' AFTER LINE WITH (AN) OCCURANCE(S) */
/*              : OF 'STRING 1'                                       */
/*========================== MODIFICATIONS ===========================*/
/* WHO         |WHEN     |WHY                                         */
/* ---         |----     |---                                         */
/* DAVE LEIGH  |8-11-89  |TOOK OFF THE 'CODE(&MAXCC)' PORTION OF THE  */
/*             |         |EXIT STATEMENT SINCE A CODE OF > 0 WOULD    */
/*             |         |CAUSE THE INVOCATION COMMAND ON THE COMMAND */
/*             |         |TO REMAIN AFTER IT WAS COMPLETE, AND HITTING*/
/*             |         |THE LAST LINE OF THE FILE WOULD ALWAYS CAUSE*/
/*             |         |THE RETURN CODE TO BE > 0.                  */
/* DAVE LEIGH  |8-17-89  |CHANGED &STRING_ TO &NRSTR(&STRING_) TO TAKE*/
/*             |         |CARE OF STRINGS WITH '&' IN THEM.           */
/**********************************************************************/

IF &NRSTR(&STG2) =         THEN +
    IF &NRSTR(&STG1) = &STR(HELP) THEN GOTO HELPSEC
    ELSE +
        DO
            SET ZEDSMSG = &STR(2ND STRING MISSING)
            ISPEXEC SETMSG MSG(UTLZ001)
            EXIT CODE(8)
        END

IF &SYSNSUB(1,&STG2) = ZLINE OR +
   &SYSNSUB(1,&STG2) = &SYSNSUB(0,&ZLINE) THEN +
    DO
        ISREDIT PROCESS RANGE Z
        IF &LASTCC ¬= 0 THEN +
            DO
                SET ZEDLMSG = &STR(*** NO LINE MARKED "Z" TO INSERT ***)
                ISPEXEC SETMSG MSG(UTLZ001)
                EXIT
            END
        ELSE +
            DO
                SET I = 0
                ISREDIT FIND FIRST P'=' 1 .ZFRANGE .ZLRANGE
                DO WHILE &LASTCC = 0
                    SET I = &I + 1
                    ISREDIT (ZLINE&I) = LINE .ZCSR
                    ISREDIT FIND NEXT P'=' 1 .ZFRANGE .ZLRANGE
                END
                SET NUMZ = &I
            END
    END
ELSE +
    IF &SUBSTR(1:1,&STR(&SYSNSUB(1,&STG2))) = &STR(') OR +
       &SUBSTR(1:1,&STR(&SYSNSUB(1,&STG2))) = &STR(") THEN +
        DO
            SET X = &LENGTH(&SYSNSUB(1,&STG2))
            SET STG2 = &SUBSTR(2:&X-1,&SYSNSUB(1,&STG2))
        END

SET OPTIONS = &SYSCAPS(&OPT1 &OPT2 &OPT3 &OPT4 &OPT5 &OPT6 &OPT7)
ISREDIT (SLINE,SCOL) = CURSOR
SET XCOUNT = 0

ISREDIT FIND FIRST &NRSTR(&STG1) &OPTIONS

DO WHILE &LASTCC = 0
    SET XCOUNT = &XCOUNT + 1
    IF &SYSNSUB(1,&STG2) = ZLINE OR +
       &SYSNSUB(1,&STG2) = &SYSNSUB(0,&ZLINE) THEN +
        DO
            ISREDIT LABEL .ZCSR = .CURR
            DO &I = &NUMZ TO 1 BY -1
                ISREDIT LINE_AFTER .CURR = (ZLINE&I)
                ISREDIT FIND NEXT P'=' 1
                ISREDIT CHANGE 'XCOUNT' +
                               '&XCOUNT' .ZCSR .ZCSR ALL
                IF &I = &NUMZ THEN ISREDIT LABEL .ZCSR = .NEXT
                ISREDIT SEEK FIRST P'=' .CURR .CURR
            END
            ISREDIT FIND FIRST P'=' .NEXT .NEXT
        END
    ELSE +
        DO
            ISREDIT LINE_AFTER .ZCSR = (STG2)
            ISREDIT FIND NEXT P'=' 1
            ISREDIT CHANGE 'XCOUNT' '&XCOUNT' .ZCSR .ZCSR ALL
        END
    ISREDIT SEEK LAST P'=' .ZCSR .ZCSR
    ISREDIT FIND NEXT &NRSTR(&STG1) &OPTIONS
END

ISREDIT CURSOR = &SLINE &SCOL
IF &STR(&NUMZ) > 1 THEN SET XCOUNT = &XCOUNT * &NUMZ
SET ZEDSMSG = &STR(&XCOUNT LINES INSERTED)
ISPEXEC SETMSG MSG(UTLZ000)

EXIT

HELPSEC: +
ISPEXEC SELECT PGM(ISPTUTOR) PARM(UTILH010)
SET ZEDLMSG = &STR(*** HELP DISPLAYED FOR "A" EDIT MACRO +
                   *** NO PROCESSING PERFORMED ***)
ISPEXEC SETMSG MSG(UTLZ000)
EXIT
            


Documentation


 This is an edit macro which allows the user to insert a line containing a given
 string (e.g. "XXX") after every line in which another (or the same) given
 string (e.g. "ZZZ") already exists.  An example follows :

 COMMAND ===> a %%% @@
 File Before :    File After :
 000100 abcdefg%  000100 abcdefg%
 000200 %%%       000200 %%%
 000300 rrr%%%    000300 @@
 """"""           000400 rrr%%%
 """"""           000500 @@

 In this example, a line with string "@@" was inserted after each line
 containing "%%%".  If either string contains special characters (space, etc.)
 it should be enclosed in quotes.

 It is possible to add additional ISPF edit parameters that you might find using
 a FIND or CHANGE command.  These parameters serve to limit the scope of lines
 which the edit macro operates against to find lines which match the "string1"
 criteria.  These can include any valid combination of : "X/NX", column ranges,
 and edit labels (system or user defined, e.g. ".abc", ".zcsr", etc.)  These
 additional parameters must be specified after "string2" and are "space
 delimited".

 "String2" may also be specified as a line or block of lines already in the
 file; i.e. after every line with an occurance of "string1", you may insert a
 line or block of lines in the file.  To accomplish this, you must mark the
 lines with a line command of "Z" or a block line command pair of "ZZ" and "ZZ"
 on the first and last lines of the block of lines.  You then specify the
 reserved string "ZLINE" instead of a "string2".

 The "A" edit macro also can make use of a special "counter" variable in
 "string2" or a marked "zline".  This variable is called "XCOUNT".  If the
 string XCOUNT is found anywhere in "string2" or a marked "zline", it will be
 replaced with the current incremental count of "string1" lines which have been
 found.

 Let's look at some examples of these additional features:

 COMMAND ===> a %%% @@ nx                   (processing only non-excluded lines)
 File Before :    File After :
 000100 abcdefg%  000100 abcdefg%
 000200 %%%       000200 %%%
 - - -  -  -  -   000300 @@
 """"""           000400 rrr%%%
 """"""

 COMMAND ===> a %%% @xcount@                (using XCOUNT in "string2")
 File Before :    File After :
 000100 abcdefg%  000100 abcdefg%
 000200 %%%       000200 %%%
 000300 rrr%%%    000300 @1@
 """"""           000400 rrr%%%
 """"""           000500 @2@

 COMMAND ===> a %%% zline .a .b             (using XCOUNT, blocked zlines,
 File Before :    File After :               edit labels)
 zz0100 1xcount   000100 1xcount
 000200 22        000200 22
 zz0300 333       000300 333
 .a0400 wwwds     000400 wwwds
 000500 %%% xxx   000500 %%% xxx
 000600 abcdefg%  000100 11
 000700 %%%       000200 22
 .b0800 rrr%%%    000300 333
 """"""           000400 abcdefg%
 """"""           000500 %%%
                  000100 12
                  000200 22
                  000300 333
                  000500 rrr%%%
                  000100 13
                  000200 22
                  000300 333
            


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.