Mainframe Utility: SWAPCOL

Return to Mainframe Utilities Page

Module


ISREDIT MACRO (COL1,COL2,COL3,OPT1,OPT2,OPT3,OPT4,OPT5,OPT6,OPT7,OPT8)
ISPEXEC CONTROL ERRORS RETURN
ISPEXEC VGET (DBGSWTCH) PROFILE
IF &DBGSWTCH = &STR(ON) THEN +
     CONTROL MSG LIST CONLIST SYMLIST NOFLUSH ASIS
ELSE  CONTROL NOMSG NOLIST NOFLUSH NOPROMPT ASIS
IF &STR(&COL1) = HELP THEN GOTO HELPSEC
/**********************************************************************
/* EDIT MACRO : SWAPCOL                                               *
/* AUTHOR     : DAVID LEIGH                                           *
/* FUNCTION   : SWAP TWO EQUAL WIDTH COLUMNS IN A FILE WITH EACH OTHER*
/**********************************************************************

/**********************************************************************
/* EDIT THE USER INPUT                                                *
/**********************************************************************
ISREDIT (LN,CL) = CURSOR
ISREDIT (LRECL) = LRECL
ISREDIT (X,Y) = DISPLAY_LINES
IF &LASTCC = 8 THEN +
    DO
        SET ZEDLMSG = &STR(*** NO LINES EXIST TO PROCESS AGAINST ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

IF &DATATYPE(&COL1) ¬= NUM OR +
   &DATATYPE(&COL2) ¬= NUM OR +
   &DATATYPE(&COL3) ¬= NUM THEN +
    DO
        SET ZEDLMSG = &STR(*** 1ST 3 PARAMETERS MUST BE COLUMN NUMBERS +
                           ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT CODE(8)
    END

IF (&COL1 > &LRECL OR &COL1 < 1) OR +
   (&COL2 > &LRECL OR &COL2 < 1) OR +
   (&COL3 > &LRECL OR &COL3 < 1) THEN +
    DO
        SET ZEDLMSG = &STR(*** ALL COLUMNS MUST BE BETWEEN 1 AND +
                           &LRECL ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT CODE(8)
    END

IF &COL1 > &COL2 THEN +
    DO
        SET ZEDLMSG = &STR(*** COLUMN 1 MUST BE LESS THAN COLUMN 2 ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT CODE(8)
    END

IF (&COL3 >= &COL1 AND &COL3 <= &COL2) OR +
   (&EVAL(&COL3 + (&COL2 - &COL1 + 1)) >= &COL1 AND +
    &EVAL(&COL3 + (&COL2 - &COL1 + 1)) <= &COL2) THEN +
    DO
        SET ZEDLMSG = &STR(*** THE TWO COLUMNS MAY NOT OVERLAP ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT CODE(8)
    END

/**********************************************************************
/* PROCESS THE INPUT                                                  *
/**********************************************************************
SET OPTIONS = &SYSCAPS(&OPT1 &OPT2 &OPT3 &OPT4 &OPT5 &OPT6 &OPT7 &OPT8)
IF &STR(&OPTIONS) =      THEN +
    DO
        %YOUSURE COLUMN(10) ROW(5) ZWINTTL('PROCESS ALL LINES?!')
        IF &LASTCC > 0 THEN +
            DO
                SET ZEDLMSG = &STR(*** NO "SWAPCOL" PROCESSING +
                                   PERFORMED ***)
                ISPEXEC SETMSG MSG(UTLZ001)
                EXIT
            END
    END
SET COUNT = 0
ISREDIT (ONOFF,TYPE) = NUMBER
IF &ONOFF = ON AND &SYSINDEX(&STR( COBOL ),&STR(&TYPE)) > 0 THEN +
    DO
        SET COL1 = &COL1 - 6
        SET COL2 = &COL2 - 6
        SET COL3 = &COL3 - 6
    END
SET LEN = &COL2 - &COL1 + 1
SET COL4 = &COL3 + &LEN - 1

SET PIC = &STR(=)
SET SPACE = &STR( )
DO &I = 2 TO &LEN
    SET PIC = &STR(&PIC=)
    SET SPACE = &STR(&SPACE )
END

ISREDIT FIND FIRST P'=' 1 &OPTIONS

DO WHILE &LASTCC = 0
    SET COUNT = &COUNT + 1
    ISREDIT (LINE) = LINE .ZCSR
    ISREDIT CHANGE P'&PIC' '&SPACE' .ZCSR .ZCSR &COL1
    ISREDIT CHANGE P'&PIC' '&SPACE' .ZCSR .ZCSR &COL3
    SET COLA = &SUBSTR(&COL1:&COL2,&NRSTR(&LINE))
    SET COLB = &SUBSTR(&COL3:&COL4,&NRSTR(&LINE))
    ISREDIT LINE .ZCSR = LINE + <(COL3) (COLA) (COL1) (COLB)>
    ISREDIT FIND LAST P'=' .ZCSR .ZCSR
    ISREDIT FIND NEXT P'=' 1 &OPTIONS
END

SET ZEDLMSG = &STR(*** &COUNT LINE(S) PROCESSED ***)
ISPEXEC SETMSG MSG(UTLZ000)

ISREDIT CURSOR = &LN &CL

EXIT

HELPSEC: +                                                              02480000
ISPEXEC SELECT PGM(ISPTUTOR) PARM(HELPSHEL)                             02490000
SET ZEDLMSG = &STR(*** HELP DISPLAYED FOR SWAPCOL UTILITY +             02490000
                   *** NO PROCESSING PERFORMED ***)                     02490000
ISPEXEC SETMSG MSG(UTLZ000)                                             02490000
EXIT
            


Documentation


 The SWAPCOL utility allow you to swap two columns of data/text in a file which
 you are editing.  You simply specify the beginning and ending column numbers of
 the first column, the beginning column number of the column of data which you
 want to swap with, and any limiting qualifiers such as "X", "NX", and edit
 labels (any valid combination of these).  Here's an example:

 Let's assume that we have two columns of data, and some of the rows of data
 contain the value 'xyz' in them.  In these rows, we need to swap the two
 columns of data.  We can do this with two commands.  First we exclude the lines
 containing 'xyz' as follows:

 EDIT ---- JP6409A.PDS.WORKFILE(TESTTEST) - 01.00 -------------- COLUMNS 001 072
 COMMAND ===> x all 'xyz'                                       SCROLL ===> CSR
 =COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001 qwertyuiop         xxxxxxxxxx%%%%%%%%%%
 000002 asdfghjkl;         xxxxxxxxxx%%%%%%%%%%
 000003  SWAPCOL 1 10 20 x                                 SCROLL ===> CSR
 =COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001 qwertyuiop         xxxxxxxxxx%%%%%%%%%%
 000002 asdfghjkl;         xxxxxxxxxx%%%%%%%%%%
 000003                                                    SCROLL ===> CSR
 *** 3 LINE(S) PROCESSED ***
 000001 qwertyuiop         xxxxxxxxxx%%%%%%%%%%
 000002 asdfghjkl;         xxxxxxxxxx%%%%%%%%%%
 000003             


Leave a Reply

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