Mainframe Utility: COPYCOL

Return to Mainframe Utilities Page

Module


ISREDIT MACRO (COL1,COL2,COL3,OPT1,OPT2,OPT3,OPT4)
ISPEXEC CONTROL ERRORS RETURN
ISPEXEC VGET (DBGSWTCH) PROFILE
IF &DBGSWTCH = &STR(ON) THEN +
     CONTROL MSG LIST CONLIST SYMLIST NOFLUSH
ELSE CONTROL NOMSG NOLIST NOFLUSH NOPROMPT
IF &STR(&COL1) = HELP THEN GOTO HELPSEC
/**********************************************************************
/* EDIT MACRO : COPYCOL                                               *
/* AUTHOR     : DAVID LEIGH                                           *
/* FUNCTION   : COPY ONE COLUMN IN A FILE BEING EDITED TO ANOTHER.    *
/**********************************************************************

/**********************************************************************
/* 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 &STR(&OPT4) = STRING AND +
   &STR(&OPT3) ¬= STRING THEN +
    DO
        SET ZEDLMSG = &STR(*** "STRING" CANNOT BE THE LAST OPTION ***)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT CODE(8)
    END

/**********************************************************************
/* PROCESS THE INPUT                                                  *
/**********************************************************************
SELECT
    WHEN (&OPT1 = STRING) +
        DO
            SET STG = &STR(&OPT2)
            SET OPT = &STR(&OPT3 &OPT4)
        END
    WHEN (&OPT2 = STRING) +
        DO
            SET STG = &STR(&OPT3)
            SET OPT = &STR(&OPT1 &OPT4)
        END
    WHEN (&OPT3 = STRING) +
        DO
            SET STG = &STR(&OPT4)
            SET OPT = &STR(&OPT1 &OPT2)
        END
    OTHERWISE +
        DO
            SET STG = &STR(P'=')
            SET OPT = &STR(&OPT1 &OPT2 &OPT3 &OPT4)
        END
END

IF &STR(&OPT) =      THEN +
    DO
        %YOUSURE COLUMN(10) ROW(5) ZWINTTL('PROCESS ALL LINES?!')
        IF &LASTCC > 0 THEN +
            DO
                SET ZEDLMSG = &STR(*** NO "COPYCOL" PROCESSING +
                                   PERFORMED ***)
                ISPEXEC SETMSG MSG(UTLZ001)
                EXIT
            END
    END

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 COUNT = 0
SET LEN = &COL2 - &COL1 + 1

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

ISREDIT FIND FIRST &STR(&STG &OPT)

DO WHILE &LASTCC = 0
    SET COUNT = &COUNT + 1
    ISREDIT CHANGE P'&PIC' '&SPACE' .ZCSR .ZCSR &COL3
    ISREDIT (LINE) = LINE .ZCSR
    SET COL = &SUBSTR(&COL1:&COL2,&NRSTR(&LINE))
    ISREDIT LINE .ZCSR = LINE + <(COL3) (COL)>
    ISREDIT FIND LAST P'=' .ZCSR .ZCSR
    ISREDIT FIND NEXT &STR(&STG &OPT)
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 COPYCOL UTILITY +             02490000
                   *** NO PROCESSING PERFORMED ***)                     02490000
ISPEXEC SETMSG MSG(UTLZ000)                                             02490000
EXIT
            


Documentation


 The COPYCOL utility allow you to copy one column of data/text in a file which
 you are editing to another column next to it.  You simply specify the beginning
 and ending column numbers to be copied, the column number where you want to
 copy the data to 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 a column of data, and some of the rows of data
 contain the value 'xyz' in them.  In these rows, we need the column of data
 repeated next to itself.  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
 000002 asdfghjkl;
 000003  copycol 1 5 20 x                                   SCROLL ===> CSR
 =COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 000001 qwertyuiop
 000002 asdfghjkl;
 000003                                                     SCROLL ===> CSR
 *** 3 LINE(S) PROCESSED ***
 000001 qwertyuiop
 000002 asdfghjkl;
 000003             


Leave a Reply

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