Mainframe Utility: B

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 : B                                                   */
/* DATE WRITTEN : 9-29-88                                             */
/* AUTHOR       : DAVE LEIGH                                          */
/* DESCRIPTION  : INSERT 'STRING 2' BEFORE 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 = 1 TO &NUMZ
                ISREDIT LINE_BEFORE .CURR = (ZLINE&I)
                ISREDIT FIND PREV P'=' 1 .ZCSR .ZCSR
                ISREDIT FIND PREV P'=' 1
                ISREDIT CHANGE 'XCOUNT' '&XCOUNT' .ZCSR .ZCSR ALL
                ISREDIT SEEK FIRST P'=' .CURR .CURR
            END
        END
    ELSE +
        DO
            ISREDIT LINE_BEFORE .ZCSR = (STG2)
            ISREDIT FIND PREV P'=' 1 .ZCSR .ZCSR
            ISREDIT FIND PREV P'=' 1
            ISREDIT CHANGE 'XCOUNT' '&XCOUNT' .ZCSR .ZCSR ALL
            ISREDIT FIND NEXT P'=' 1
        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: +
CLEAR

WRITE *** HELP FOR EDIT MACRO 'B' ***
WRITE
WRITE THE 'B' EDIT MACRO ALLOWS YOU TO INSERT A LINE OF  BEFORE
WRITE EVERY LINE IN WHICH  OCCURS AT LEAST ONCE.
WRITE
WRITE BASIC SYNTAX :
WRITE
WRITE COMMAND ===> B XXXX $$$$
WRITE
WRITE FILE VIEW BEFORE COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE 000300 XXXX
WRITE 000400 CCCC
WRITE 000500 XXXX
WRITE
WRITE FILE VIEW AFTER COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE 000201 $$$$
WRITE 000300 XXXX
WRITE 000400 CCCC
WRITE 000401 $$$$
WRITE 000500 XXXX
WRITE
WRITE TO PROCESS ONLY EXCLUDED LINES :
WRITE
WRITE COMMAND ===> B XXXX $$$$ X
WRITE
WRITE FILE VIEW BEFORE COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE X      XXXX
WRITE 000400 CCCC
WRITE 000500 XXXX
WRITE
WRITE FILE VIEW AFTER COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE 000201 $$$$
WRITE 000300 XXXX
WRITE 000400 CCCC
WRITE 000500 XXXX
WRITE
WRITE TO PROCESS ONLY INCLUDED LINES :
WRITE
WRITE COMMAND ===> B XXXX $$$$ NX
WRITE
WRITE FILE VIEW BEFORE COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE X      XXXX
WRITE 000400 CCCC
WRITE 000500 XXXX
WRITE
WRITE FILE VIEW AFTER COMMAND EXECUTION :
WRITE
WRITE 000100 AAAA
WRITE 000200 BBBB
WRITE X      XXXX
WRITE 000400 CCCC
WRITE 000401 $$$$
WRITE 000500 XXXX
WRITE
WRITE SPECIAL NOTES : IF NEITHER 'X' NOR 'NX' ARE SPECIFIED TO DEAL WITH
WRITE                 EXCLUDED OR INCLUDED LINES, ALL LINES WILL BE
WRITE                 SEARCHED REGARDLESS OF INCLUSION/EXCLUSION STATUS.
WRITE
WRITE                 SINGLE/DOUBLE QUOTE USAGE AROUND THE 2 STRINGS IS
WRITE                 IDENTICAL TO THAT OF THE EDIT 'CHANGE' (OR 'C')
WRITE                 COMMAND.
WRITE
WRITE                 THE NUMBER OF LINES INSERTED WILL BE PLACED IN THE
WRITE                 SHORT MESSAGE FIELD AT THE UPPER RIGHT HAND CORNER
WRITE                 OF YOUR SCREEN.
WRITE
WRITE                 IF YOU SPECIFY 'X' FOR PROCESSING EXCLUDED LINES,
WRITE                 ALL LINES WILL BE RESET AT THE END OF MACRO
WRITE                 EXECUTION.
WRITE
WRITE                 IF YOU DO NOT SPECIFY 'X' OR 'NX', AND EXCLUDED
WRITE                 LINES ARE FOUND WHICH CONTAIN  THEY WILL
WRITE                 BE RESET.

EXIT
            


Documentation


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

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

 In this example, a line with string "@@" was inserted before 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. before 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 "B" 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 ===> b %%% @@ nx                   (processing only non-excluded lines)
 File Before :    File After :
 000100 abcdefg%  000100 abcdefg%
 000200 %%%       000200 @@
 - - -  -  -  -   000300 %%%
 """"""           - - -  -  -  -
 """"""

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

 COMMAND ===> b %%% 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 11
 000600 abcdefg%  000100 22
 000700 %%%       000200 333
 .b0800 rrr%%%    000300 %%% xxx
 """"""           000400 abcdefg%
 """"""           000500 12
                  000100 22
                  000200 333
                  000300 %%%
                  000500 13
                  000100 22
                  000200 333
                  000300 rrr%%%
            


Leave a Reply

Your email address will not be published. Required fields are marked *