zOs/REXX/DB2UTIL

/* copy db2Util begin ************************************************/
/--- return (first) list of columns from punch file
     i.e. lines between first pair of ( and ) on a line
     used by abub gbGr ----------------------------------------------*/
loadCols: procedure expose m.
    if (\ in()) | word(m.in, 1) <> 'LOAD' then
       call err 'not load but' m.l1
    do while in() & strip(m.in) \== '('
        end
    if strip(m.in) \== '(' then
        call err '( not found in load:' m.in
    m.in = '-'
    do while in() & strip(m.in) \== ')'
        call out m.in
        end
    if strip(m.in) \== ')' then
        call err ') not found in load:' m.in
    return 1
endProcedure loadCols
/* ???????????? achtung nicht fertig |
          Idee: allgemein Punch Umformungs Utility
              aber man müsste wohl auf scan Util umstellen
                  und abstürzen wenn man etwas nicht versteht
          GrundGerüst von cadb2 umgebaut
????????????????? */

db2UtilPunch: procedure expose m.
parse upper arg args
    call scanSrc scanOpt(s), args
    a.rep = 1
    a.tb = ''
    a.trunc = 0
    a.iDD = ''
    a.iDSN = ''
    do while scanKeyValue(scanSkip(s), 1)
        ky = m.s.key
        say '????ky' ky m.s.val
        if wordPos(ky, 'REP TB TRUNC IDD IDSN') < 1 then
            call scanErr s, 'bad key' ky
        a.ky = m.s.val
        end
    if a.iDSN \== '' then do
        if a.iDD == '' then
            a.iDD = 'IDSN'
        call out '  TEMPLATE' a.iDD 'DSN('a.iDsn')'
        end
    do while in() & word(m.in, 1) <> 'LOAD'
        call out m.in
        end
    ll = space(m.in, 1)
    if \ abbrev(ll, 'LOAD DATA ') then
        call err 'bad load line:' m.in
    call out subword(m.in, 1, 2) 'LOG NO'
    if abbrev(ll, 'LOAD DATA INDDN ') then
        call db2UtilPunchInDDn word(ll, 4)
    else if \ abbrev(ll, 'LOAD DATA LOG ') then
        call err 'bad load line' m.in
    if a.rep then
        call out '    STATISTICS INDEX(ALL) UPDATE ALL'
    call out '    DISCARDS 1'
    call out '    ERRDDN   TERRD'
    call out '    MAPDDN   TMAPD '
    call out '    WORKDDN  (TSYUTD,TSOUTD) '
    call out '  SORTDEVT DISK '
    do in()
        li = m.in
        if pos('CHAR(', li) > 0 then
            call out strip(li, 't') 'TRUNCATE'
        else if word(li, 1) word(li, 3) == 'PART INDDN' then do
            call out li,
            call out '  RESUME NO REPLACE COPYDDN(TCOPYD)' ,
            call out '  DISCARDDN TDISC '
            end
        else
            call out li
        end
    return
endProcedure db2UtilPunch

db2UtilPunchInDDn:
parse arg inDDn
     if a.iDD == '' then
         ll =  '    INDDN' inDDn
     else
         ll =  '    INDDN' a.iDD
     if a.rep then
         call out ll 'RESUME NO REPLACE COPYDDN(TCOPYD)'
     else
         call out ll 'RESUME YES'
     call out  '    DISCARDDN TDISC'
     return
endSubroutine db2UtilPunchInDDn
/* copy db2Util end   ************************************************/