|
| 1 | +/* REXX */ |
| 2 | + |
| 3 | + TRACE Off |
| 4 | + WhatDDName = 'DB2MASK$' |
| 5 | +/* If DB2MASK$ is allocated? If yes, then turn on Trace */ |
| 6 | + isItThere = , |
| 7 | + BPXWDYN("INFO FI(EDCHKDD) INRTDSN(DSNVAR) INRDSNT(myDSNT)") |
| 8 | + If isItThere = 0 then Trace r |
| 9 | + |
| 10 | + MY_RC = 0 |
| 11 | + |
| 12 | + /* DB2 Masking routine for processors */ |
| 13 | + |
| 14 | + Mask. = '' |
| 15 | + /* Capture Mask names ane values */ |
| 16 | + /* Read Endevor's Masking rules in the MASKING data */ |
| 17 | + "EXECIO * DISKR MASKING (STEM mask. FINIS " |
| 18 | + |
| 19 | + Do m# = 1 to mask.0 |
| 20 | + msk = Strip(mask.m#) |
| 21 | + posEqual = Pos('=',msk) |
| 22 | + if posEqual = 0 then iterate ; |
| 23 | + msk = overlay(' ',msk,posEqual) |
| 24 | + text = Substr(msk,1,(posEqual-1)) |
| 25 | + if Words(text)/= 1 then iterate |
| 26 | + MaskWord = Word(msk,1) |
| 27 | + posValue = Wordindex(msk,2) |
| 28 | + MaskValue = Strip(Substr(msk,posValue)) |
| 29 | + Say 'Found Mask for' MaskWord '=' MaskValue |
| 30 | + MaskValue = Strip(MaskValue,"B",'"') |
| 31 | + MaskValue = Strip(MaskValue,"B","'") |
| 32 | + Mask.MaskWord = MaskValue |
| 33 | + End ; /* Do m# = 1 to mask.0 */ |
| 34 | + |
| 35 | + X = OUTTRAP(LINE.); |
| 36 | + |
| 37 | + /* Apply mask values to Bind statement */ |
| 38 | + /* Read the BINDSTMT */ |
| 39 | + "EXECIO * DISKR BINDSTMT (Stem bind. Finis " |
| 40 | + |
| 41 | + /* Scan each line of the Bind Statement */ |
| 42 | + Do b# = 1 to bind.0 |
| 43 | + BindStatement = Strip(substr(bind.b#,1,72)) |
| 44 | + /* BindStatement = substr(BindStatement,1,72) */ |
| 45 | + If Words(BindStatement) = 0 then Iterate ; |
| 46 | + If b# > 1 & b# < bind.0 &, |
| 47 | + Substr(BindStatement,Length(BindStatement),1) /= '-' then, |
| 48 | + BindStatement = BindStatement '-' |
| 49 | + |
| 50 | + /* Scan each Word of the Bind Statement */ |
| 51 | + Do wrd# = 1 to Words(BindStatement) |
| 52 | + pos_db2_1 = pos("BIND",BindStatement) |
| 53 | + pos_db2_2 = pos("PLAN",BindStatement) |
| 54 | + myword = Word(BindStatement,wrd#) ; |
| 55 | + myword = Translate(myword,' ','(') |
| 56 | + myword = Word(myword,1) |
| 57 | + Mask = Mask.myword |
| 58 | + If Mask = '' then iterate |
| 59 | + tmp = Translate(myword,' ','()-+'); |
| 60 | + stmt = Word(tmp,1) |
| 61 | + Say 'Before:' BindStatement |
| 62 | + |
| 63 | + /* Find Starting and Ending positions of the clause */ |
| 64 | + /* to be masked */ |
| 65 | + plc = Wordindex(BindStatement,wrd#) |
| 66 | + startpos = Pos('(',BindStatement,plc) |
| 67 | + endpos = Pos(')',BindStatement,plc) |
| 68 | + clauseLen = endpos - startpos + 1 |
| 69 | + if plc = 0 then iterate ; |
| 70 | + MaskValue = Substr(BindStatement,startpos,clauseLen) |
| 71 | + MaskValue = Strip(MaskValue,'L','(') |
| 72 | + MaskValue = Strip(MaskValue,'T',')') |
| 73 | + MaskValue = Strip(MaskValue) |
| 74 | + If Pos('.',MaskValue) > 0 then, |
| 75 | + Do |
| 76 | + wherePeriod = Pos('.',MaskValue) |
| 77 | + Mask = Copies('-',wherePeriod) || Mask |
| 78 | + End |
| 79 | + OriginalLen = Length(MaskValue) |
| 80 | + ValueStarts = Pos(MaskValue,BindStatement) ; |
| 81 | + |
| 82 | + /* Apply Mask to clause within the DB2 bind */ |
| 83 | + Call ApplySingleMaskOverride ; |
| 84 | + say 'Mask:' Mask |
| 85 | + MaskValue = Strip(MaskValue) |
| 86 | + where = Wordindex(BindStatement,wrd#) |
| 87 | + newvalue = stmt'('MaskValue')' |
| 88 | + newvalue = Left(newvalue,Length(myword)) |
| 89 | + If ValueStarts > 1 then, |
| 90 | + head = Substr(BindStatement,1,ValueStarts-1) |
| 91 | + Else head = '' |
| 92 | + BindStatement = head || MaskValue || , |
| 93 | + Strip(Substr(BindStatement,ValueStarts+OriginalLen)) ; |
| 94 | + Say 'After: ' BindStatement |
| 95 | + Say Copies('-',70) |
| 96 | + End /* Do wrd# = 1 Words(BindStatement) */ |
| 97 | + |
| 98 | + bind.b# = BindStatement |
| 99 | + |
| 100 | + End /* Do b# = 1 to bind.0 */ |
| 101 | + |
| 102 | + /* Replace the member with the Masked data */ |
| 103 | + "EXECIO * DISKW BINDS (Stem bind. Finis " |
| 104 | + |
| 105 | + EXIT (MY_RC) ; |
| 106 | + |
| 107 | +ApplySingleMaskOverride: |
| 108 | + |
| 109 | + /* This routine applies values in 'Mask' */ |
| 110 | + /* to the value in 'MaskValue' */ |
| 111 | + SupportedWildCards = '?*-^' |
| 112 | + |
| 113 | + If Mask = ' ' then Mask ='*' ; |
| 114 | + Do char# = 1 to Length(Mask) |
| 115 | + maskchar = Substr(Mask,char#,1) ; |
| 116 | + If maskchar = "?" then iterate ; |
| 117 | + If maskchar = "*" then Leave ; |
| 118 | + If maskchar = "-" then, |
| 119 | + Do /* use one character from the value */ |
| 120 | + tail = Substr(MaskValue,char# + 1) |
| 121 | + head = Substr(MaskValue,1,char#) |
| 122 | + MaskValue = Strip( head || tail) ; |
| 123 | + Iterate ; |
| 124 | + End; |
| 125 | + If maskchar = "^" then, |
| 126 | + Do /* eat one character from each .... */ |
| 127 | + /* eat a MaskValue char */ |
| 128 | + if char# > Length(MaskValue) then, |
| 129 | + tail = '' |
| 130 | + else, |
| 131 | + tail = Substr(MaskValue,char# + 1) |
| 132 | + if char# > 1 then, |
| 133 | + head = Substr(MaskValue,1,char# - 1) |
| 134 | + else, |
| 135 | + head = '' |
| 136 | + MaskValue = Strip( head || tail) ; |
| 137 | + /* eat a Mask char too */ |
| 138 | + If char# > 1 then, |
| 139 | + Mask = Substr(Mask,1,(char#-1)) || Substr(Mask,(char#+1)) |
| 140 | + Else, |
| 141 | + Mask = Substr(Mask,2) |
| 142 | + /* Mask char is changed for char# position */ |
| 143 | + char# = char# - 1 |
| 144 | + Iterate ; |
| 145 | + End; |
| 146 | + Maskchar = Substr(Mask,char#,1) ; |
| 147 | + MaskValue = Overlay(Maskchar,MaskValue,char#) |
| 148 | + If char# = Length(Mask) then, |
| 149 | + MaskValue = Substr(MaskValue,1,char#) |
| 150 | + End /* Do char# = 1 to Length(Mask) */ |
| 151 | + |
| 152 | + Return |
| 153 | + |
| 154 | + |
0 commit comments