Mainframe Utility: ADDCOL

Return to Mainframe Utilities Page

Module


ISREDIT MACRO (COLUMN1,COLUMN2,COLUMN3)
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 : ADDCOL                                              */
/* DATE WRITTEN : 4-19-89                                             */
/* AUTHOR       : DAVE LEIGH                                          */
/* DESCRIPTION  : ADD UP THE NUMBERS IN A COLUMN OF NUMBERS WITHIN A  */
/*              : FILE BEING EDITED IN ISPF                           */
/*========================== MODIFICATIONS ===========================*/
/* WHO         ¦WHEN     ¦WHY                                         */
/* ---         ¦----     ¦---                                         */
/* DAVE LEIGH  ¦3-26-90  ¦ADDED CODE TO DETERMINE THE NUMBERING MODE  */
/*             ¦         ¦TO SEE IF IT'S COBOL OR NOT BECAUSE THIS    */
/*             ¦         ¦AFFECTS THE COLUMNS THAT ARE RETURNED TO    */
/*             ¦         ¦THE MACRO FOR COMPUTATION.                  */
/**********************************************************************/

IF &LENGTH(&STR(&COLUMN2)) = 0 THEN +
    IF &STR(&COLUMN1) = &STR(HELP) THEN GOTO HELPSEC
    ELSE +
        DO
            SET ZEDSMSG = &STR(2ND COLUMN MISSING)
            SET ZEDLMSG = &STR(YOU MUST PASS A BEGINNING AND ENDING +
                               COLUMN # TO THE ADDCOL MACRO (E.G. " +
                               ADDCOL 35 40"))
            ISPEXEC SETMSG MSG(UTLZ001)
            EXIT
        END

IF &LENGTH(&STR(&COLUMN3)) > 0 AND +
   &COLUMN1 > &COLUMN3 AND +
   &COLUMN3 > &COLUMN2 THEN +
    DO
        SET ZEDLMSG = &STR(THE DECIMAL POINT COLUMN MUST BE > THE 1ST +
                           COLUMN AND < THE 2ND COLUMN)
        ISPEXEC SETMSG MSG(UTLZ001)
        EXIT
    END

ISREDIT (NUMVAR1,NUMVAR2) = NUMBER

IF &NUMVAR2 = &STR(NOSTD   COBOL   NODISPL) THEN +
    DO
        SET COLUMN1 = &COLUMN1 - 6
        SET COLUMN2 = &COLUMN2 - 6
        IF &STR(&COLUMN3) >   THEN SET COLUMN3 = &COLUMN3 - 6
    END

ISREDIT (SLINE,SCOL) = CURSOR

SET COUNT = 0
SET NUMCOUNT = 0
SET CHARCOUNT = 0
SET AMOUNT = 0
ISREDIT CURSOR = 1 0
SET SAVECC = 0
ISREDIT FIND NEXT P'=' 1 X
SET SAVECC = &LASTCC
SET XCOLUMN1 = 1
SET XCOLUMN2 = &COLUMN2 - &COLUMN1 + 1
SET XCOLUMN3 = &COLUMN3 - &COLUMN1 + 1
SET LENDATA = &COLUMN2 - &COLUMN1 + 1

DO WHILE &SAVECC = 0
    ISREDIT (DATA) = LINE .ZCSR
    SET XDATA = &SUBSTR(&COLUMN1:&COLUMN2,&STR(&SYSNSUB(1,&DATA)))
    SET NDX = 1
    DO WHILE &NDX <= &LENDATA
        IF &SYSINDEX(&STR( ),&STR(&SYSNSUB(1,&XDATA))) = &NDX THEN +
            DO
                SET A = &NDX - 1
                SET B = &NDX + 1
                SET XDATA1 =
                SET XDATA2 =
                IF &A > 0 THEN +
                    SET XDATA1 = &SUBSTR(1:&A,&STR(&SYSNSUB(1,&XDATA)))
                IF &B <= &LENDATA THEN +
                    SET XDATA2 = &SUBSTR(&B:&LENDATA,+
                                 &STR(&SYSNSUB(1,&XDATA)))
                SET XDATA = &STR(&SYSNSUB(1,&XDATA1))+
                            &STR(0)+
                            &STR(&SYSNSUB(1,&XDATA2))
            END
        SET NDX = &NDX + 1
    END
    IF &LENGTH(&STR(&COLUMN3)) > 0 THEN +
        DO
            SET A = &XCOLUMN3 - 1
            SET B = &XCOLUMN3 + 1
            SET XDATA1 = &SUBSTR(&XCOLUMN1:&A,&STR(&XDATA))
            SET XDATA2 = &SUBSTR(&B:&XCOLUMN2,&STR(&XDATA))
            SET XDATA = &STR(&XDATA1)&STR(&XDATA2)
        END
    ELSE SET XDATA = &SUBSTR(&XCOLUMN1:&XCOLUMN2,&STR(&XDATA))
    IF &DATATYPE(&STR(&XDATA)) = CHAR THEN +
        SET CHARCOUNT = &CHARCOUNT + 1
    ELSE +
        DO
            SET NUMCOUNT = &NUMCOUNT + 1
            SET AMOUNT = &AMOUNT + &XDATA
        END
    SET COUNT = &COUNT + 1
    ISREDIT FIND NEXT P'=' 1 X
    SET SAVECC = &LASTCC
END

ISREDIT CURSOR = &SLINE &SCOL

IF &COUNT = 0 THEN +
    DO
        SET ZEDLMSG = &STR(LINES TO BE ACCUMULATED MUST BE "EXCLUDED" +
                           WITH AN "X" IN THE LINE NUMBER)
        ISPEXEC SETMSG MSG(UTLZ001)
    END
ELSE +
    DO
        IF &LENGTH(&STR(&COLUMN3)) > 0 THEN +
            DO
                SET POINT = &COLUMN2 - &COLUMN3
                SET LENAMT = &LENGTH(&STR(&AMOUNT))
                SET POINT = &LENAMT - &POINT
                SET AMT1 = &SUBSTR(1:&POINT,&STR(&AMOUNT))
                SET POINT = &POINT + 1
                SET AMT2 = &SUBSTR(&POINT:&LENAMT,&STR(&AMOUNT))
                SET AMOUNT = &STR(&AMT1).&STR(&AMT2)
            END
        SET ZEDSMSG = &STR(TOTAL AMT = &AMOUNT)
        SET ZEDLMSG = &STR(TOTAL LINES READ = &COUNT  NON-NUMERIC +
                           = &CHARCOUNT  NUMERIC = &NUMCOUNT +
                           TOTAL AMOUNT = &AMOUNT)
        ISPEXEC SETMSG MSG(UTLZ000)
        ISPEXEC VGET ADDCOL SHARED
        IF &STR(&ADDCOL) = BATCH THEN +
            DO
                SET ADDCOL = &STR(&AMOUNT)
                ISPEXEC VPUT ADDCOL SHARED
            END

    END

EXIT CODE(&MAXCC)

HELPSEC: +
WRITE *** HELP FOR EDIT MACRO 'ADDCOL' ***
WRITE
WRITE THE 'ADDCOL' EDIT MACRO WILL AUTOMATICALLY ADD UP A COLUMN OF
WRITE NUMBERS IN A BLOCK OF LINES IN A COLUMN THAT YOU ARE EDITING.
WRITE THE EDIT MACRO WILL TAKE INTO ACCOUNT ZERO-FILLING WHERE NECESSARY
WRITE AND ANY NON-NUMERIC LINES THAT MAY FALL INTO THE SELECTED BLOCK OF
WRITE LINES.  IF THERE ARE DECIMAL POINTS, AN ADDITIONAL PARAMETER MAY
WRITE BE PASSED TO THE MACRO TO TAKE THEM INTO ACCOUNT.  POSSIBLE USES
WRITE FOR THIS MACRO INCLUDE ADDING UP A COLUMN OF NUMBERS IN A REPORT
WRITE OR EXTRACT FILE, OR ADDING UP FILE OR PRINT LINE LAYOUTS IN A
WRITE PROGRAM.  THE BASIC METHOD OF USING IT IS TO DETERMIN THE COLUMNS
WRITE IN THE FILE THAT BEGIN AND END THE NUMERIC AREA TO ACCUMULATE
WRITE (THIS CAN BE ACCOMPLISED VIA THE "COLS" EDIT LINE COMMAND).  THEN
WRITE "EXCLUDE" THE BLOCK OF LINES TO BE ACCUMULATED.  (THIS CAN BE
WRITE ACCOMPLISHED VIA THE "X" OR "XX" EDIT LINE COMMANDS).  THEN INVOKE
WRITE THE MACRO AS FOLLOWS:  (THE OUTPUT IS AN ISPF MESSAGE LINE).
WRITE
WRITE BASIC SYNTAX :
WRITE
WRITE COMMAND ===> ADDCOL 1 3 2
WRITE (WHERE "1" = BEGINNING COLUMN OF NUMERIC AREA TO ACCUMULATE)
WRITE (WHERE "3" = ENDING COLUMN OF NUMERIC AREA TO ACCUMULATE)
WRITE (WHERE "2" IS AN OPTIONAL PARAMETER INDICATING THE COLUMN POSITION
WRITE  OF THE DECIMAL POINT IN THIS NUMERIC AREA...IF THERE IS ONE)
WRITE
WRITE EXAMPLE #1
WRITE
WRITE COMMAND ===> ADDCOL 10 12
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE XX0100          111
WRITE 000200          111
WRITE 000300          111
WRITE 000400          111
WRITE XX0500          111
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE MESSAGE AFTER COMMAND EXECUTION :
WRITE
WRITE COMMAND ===>
WRITE TOTAL LINES READ = 5  NON-NUM = 0  NUM = 5 TOTAL AMOUNT = 555
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100          111
WRITE 000200          111
WRITE 000300          111
WRITE 000400          111
WRITE 000500          111
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE EXAMPLE #2 - NUMBERS WITH DECIMAL POINTS
WRITE
WRITE COMMAND ===> ADDCOL 10 15 13
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE XX0100          111.11
WRITE 000200          111.11
WRITE 000300          111.11
WRITE 000400          111.11
WRITE XX0500          111.11
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE MESSAGE AFTER COMMAND EXECUTION :
WRITE
WRITE COMMAND ===>
WRITE TOTAL LINES READ = 5  NON-NUM = 0  NUM = 5 TOTAL AMOUNT = 555.55
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100          111.11
WRITE 000200          111.11
WRITE 000300          111.11
WRITE 000400          111.11
WRITE 000500          111.11
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE EXAMPLE #3 - NUMBERS WITH DECIMAL POINTS AND LETTING THE "ADDCOL"
WRITE              MACRO "ZERO FILL" SPACES WHERE NECESSARY.
WRITE
WRITE COMMAND ===> ADDCOL 10 15 13
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE XX0100          111.1
WRITE 000200          111.
WRITE 000300          111
WRITE 000400           11.11
WRITE XX0500            1
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE MESSAGE AFTER COMMAND EXECUTION :
WRITE
WRITE COMMAND ===>
WRITE TOTAL LINES READ = 5  NON-NUM = 0  NUM = 5 TOTAL AMOUNT = 345.21
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100          111.1
WRITE 000200          111.
WRITE 000300          111
WRITE 000400           11.11
WRITE 000500            1
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE EXAMPLE #4 - NUMBERS WITH DECIMAL POINTS AND LETTING THE "ADDCOL"
WRITE              MACRO "ZERO FILL" SPACES WHERE NECESSARY AND INTER-
WRITE              SPERSING NON-NUMERIC DATA LINES WITHIN THE BLOCK OF
WRITE              NUMERIC DATA LINES.
WRITE
WRITE COMMAND ===> ADDCOL 10 15 13
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE XX0100          111.11
WRITE 000200        XXXXXXXXXX
WRITE 000300          111
WRITE 000400        XXXXXXXXXXX
WRITE XX0500            1
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE MESSAGE AFTER COMMAND EXECUTION : (NOTICE DIFFERENCE IN COUNTS OF
WRITE                                    NUMERIC AND NON-NUMERIC LINES.)
WRITE
WRITE COMMAND ===>
WRITE TOTAL LINES READ = 5  NON-NUM = 2  NUM = 3 TOTAL AMOUNT = 223.11
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100          111.11
WRITE 000200        XXXXXXXXXX
WRITE 000300          111
WRITE 000400        XXXXXXXXXXX
WRITE 000500            1
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE EXAMPLE #5 - PRACTICAL USE FOR ADDING UP RECORD LAYOUTS.
WRITE
WRITE COMMAND ===> ADDCOL 44 45
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100        01  PRINT-LINE-1.
WRITE XX0200            05  PRINT-DATE            PIC 9(06)
WRITE 000300                VALUE ZEROS.
WRITE 000200            05  FILLER                PIC X(20)
WRITE 000300                VALUE SPACES.
WRITE 000200            05  FILLER                PIC X(29)
WRITE 000300                VALUE 'THIS IS THE LONG REPORT TITLE'.
WRITE 000200            05  FILLER                PIC X(21)
WRITE 000300                VALUE '     PAGE '.
WRITE XX0200            05  PRINT-PAGE            PIC 9(04)
WRITE 000300                VALUE ZEROS.
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE MESSAGE AFTER COMMAND EXECUTION : (NOTICE THAT ONLY THE REPORT
WRITE                                    TITLE IS CONSIDERED NON-NUMERIC
WRITE                                    IN THIS GROUP OF LINES.  THAT
WRITE                                    IS BECAUSE THE LINES IN WHICH
WRITE                                    COLUMNS 44 AND 45 BOTH CONTAIN
WRITE                                    SPACES ARE "ZERO-FILLED" AND
WRITE                                    AND THUS BECOME THE NUMERIC
WRITE                                    VALUE '00'.
WRITE
WRITE COMMAND ===>
WRITE TOTAL LINES READ = 9  NON-NUM = 1  NUM = 8 TOTAL AMOUNT = 80
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE 000100        01  PRINT-LINE-1.
WRITE XX0200            05  PRINT-DATE            PIC 9(06)
WRITE 000300                VALUE ZEROS.
WRITE 000400            05  FILLER                PIC X(20)
WRITE 000500                VALUE SPACES.
WRITE 000600            05  FILLER                PIC X(29)
WRITE 000700                VALUE 'THIS IS THE LONG REPORT TITLE'.
WRITE 000800            05  FILLER                PIC X(21)
WRITE 000900                VALUE '     PAGE '.
WRITE XX1000            05  PRINT-PAGE            PIC 9(04)
WRITE 001100                VALUE ZEROS.
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE SPECIAL NOTES : MORE INFORMATION ON "EXCLUDING" LINES CAN BE FOUND
WRITE                 BY TYPING "HELP" FROM ANY ISPF "EDIT" SESSION AND
WRITE                 CHOOSING OPTION "11 EDIT LINE COMMANDS".
WRITE
WRITE                 ADDCOL WILL ONLY ZERO-FILL "SPACES" IN THE
WRITE                 SPECIFIED COLUMNS.  THEREFORE, THE FOLLOWING
WRITE                 NUMBERS WOULD NOT BE ADDED CORRECTLY :
WRITE
WRITE COMMAND ===> ADDCOL 10 15 13
WRITE ****** ***************************** TOP OF DATA *****************
WRITE =COLS> ....+....1....+....2....+....3....+....4....+....5....+....
WRITE XX0100         $111.11
WRITE 000200          $11.11
WRITE 000300           $1.11
WRITE 000400          111.1X
WRITE XX0500            1
WRITE ****** **************************** BOTTOM OF DATA ***************
WRITE
WRITE        ONLY LINES 000100, AND 000500 ABOVE WOULD BE CONSIDERED
WRITE        NUMERIC AND WOULD BE ADDED.
WRITE
WRITE *** END OF HELP *** NO PROCESSING PERFORMED ***
EXIT
            


Documentation

 This is an edit macro which will add up a column of numbers in a file you're
 editing.  You must exclude the lines you wish to tally, and specify which
 columns are to be included in the operation.  In the columns selected, spaces
 will be converted to zeros, but any other non-numeric character will cause the
 line to be identified as non-numeric and not counted.  Example follows :
&nbsp;
 COMMAND ===> addcol 58 61  <== This example would add up the excluded numeric
 lines between columns 58 and 61 inclusive.  Notes : trailing spaces will be
 made zeros as well as leading spaces, so your numbers should be right
 justified.  If the numbers contain decimal points,specifiy the column of the
 decimal point as a 3rd parameter.            


Leave a Reply

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