ISPEDIT Macro - Create sub-sums on some columns

Sample
ISPF Edit Macro - Sample

Beispiel:                                 

/* REXX YTSUM Copyright YCOS Yves Colliard Software 1990-2009 */
/* TRACE ?R  */
  /* einschalten des interaktiven Trace Modus */
  /* */
/***  REXX  **********************************************************/
/*  Funktion:  teil-summieren von Columns im editierten Source       */
/*  Aufruf:    YTSUM whatscol whatendcol Startcol Endcol             */
/*  Input Beispiel:                                                  */
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----*/
/*        same    1                                                  */
/*        same    6                                                  */
/*        same   12                                                  */
/*        same   25                                                  */
/*        other   8                                                  */
/*        other  22                                                  */
/*  Aufruf:    YTSUM 11 15 16 19                                     */
/*  Output Beispiel:                                                 */
/*        same    1                                                  */
/*        same    6                                                  */
/*        same   12                                                  */
/*        same   25                                                  */
/*---> Sum: same        44 Numb:      4                              */
/*        other   8                                                  */
/*        other  22                                                  */
/*---> Sum: other       30 Numb:      2                              */
/* Die Zeile kann als "richtige" oder als "Info" Zeile eingefuegt    */
/* werden - siehe UNTEN!                                             */
/*********************************************************************/
/* */
numeric digits 20
/* */
Address ISREDIT "MACRO (wscol,wecol,scol,ecol)"
Address ISPEXEC "CONTROL ERRORS RETURN"
Address ISREDIT "(TLINE) = LINENUM .ZLAST"
if scol > ecol ,
! ecol = "" ,
  then do
    zedsmsg = "invalid column range"
    zedlmsg = "End column for SUM must not be lower than start column"
    Address ISPEXEC "SETMSG MSG(ISRZ001)"
    exit
  end
if wscol > wecol,
  then do
    zedsmsg = "invalid column range"
    zedlmsg = "End column for COMP must not be lower than start column"
    Address ISPEXEC "SETMSG MSG(ISRZ001)"
    exit
  end
l = ecol-scol+1
lw = wecol-wscol+1
totnum = 0
totanz = 0
gtotanz = 0
gtotnum = 0
last=""
i=1
do until i>tline
  Address ISREDIT "(xstat) = XSTATUS "i
  if xstat = "NX" ,
    then do
      Address ISREDIT "(tl) = line "i
      num = substr(tl,scol,l)
      what = substr(tl,wscol,lw)
      if what<>last & last<>"" then do
         call doit
         totanz=0
         totnum=0
         i=i+1
         tline=tline+1
      end
      if datatype(num) = "NUM" then do
         totnum = totnum + num
         totanz = totanz + 1
         gtotnum = gtotnum + num
         gtotanz = gtotanz + 1
      end
      last=what
    end
    i=i+1
end
Address ISREDIT "(TLINE) = LINENUM .ZLAST"
i=tline+1
call doit
gtotanz=max(gtotanz,1)
zedsmsg = ""
zedlmsg = "Grand Total value "gtotnum" Avg "format(gtotnum/gtotanz,,2),
"Anz "gtotanz "(columns "scol" to "ecol")"
Address ISPEXEC "SETMSG MSG(ISRZ001)"
exit
doit:
   outit="' ---> Sum:" last format(totnum,8,0),
         "Numb:" format(totanz,6,0)"'"
   Address ISREDIT "LINE_AFTER" i-1 "= DATALINE" outit
   /* Comment Start
   Address ISREDIT "LINE_AFTER" i-1 "= INFOLINE" outit
      Comment End */
return