Actually, my requirement is to add RLSQUIESCE & LOG parameters to the existing parm cards.
Parm card can have multiple define statements as well.
I have written the rexx code for this requirement but it's not working only if for all scenarios.
Scenario 1:
It's not working when the parameter NIXD, IXD and NUMD are not present. I read in some books that If any of this parameter is not present then it will considered as "KSDS".
"(CURRLN) = LINENUM .ZCSR" /* CURRENT LINE */
"(LASTLN) = LINENUM .ZLAST" /* LAST LINE NUMBER */
I = 0
DO FOREVER
I = I + 1
IF I > LASTLN THEN LEAVE
"(LINE) = LINE " I
LINE = SUBSTR(LINE,1,80)
IF SUBSTR(LINE,1,3) = "//*" | SUBSTR(LINE,1,3) = " /*" THEN ITERATE
VAR1 = SUBWORD(LINE,1,1)
UPPER VAR1
PRMT2 = "RLSQUIESCE"||' '||"-"
SELECT
WHEN VAR1 = 'NONINDEXED' | VAR1 = 'NIXD' THEN DO
PRMT3 = "LOG(NONE)"||' '||"-"
CALL ADD_ATTRIBUTES
END
WHEN VAR1 = 'INDEXED' | VAR1 = 'IXD' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
END
WHEN VAR1 = 'NUMBERED' | VAR1 = 'NUMD' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
END
OTHERWISE
NOP
END
END
/* EXIT(RC) */
One thing to watch out for is to have a keyword to appear as part of the object name.
My example two posts above fixes this problem too, in 99.99% of possible cases.
Thanks for your quick response.
I believe your code also will help only when the below parameters are present
NONINDEXED,
NIXD,
INDEXED,
IXD,
NUMBERED,
NUMD
Below scenario will not work i.e., scenario 1 in my example.
If these keywords are not present then we need consider as KSDS and default parameter should LOG(UNDO).
If any of the below parameters are not present then need to find for keyword Keys and add the required parameters.
NONINDEXED,
NIXD,
INDEXED,
IXD,
NUMBERED,
NUMD
To overcome this scenarios i have added "Keyp?" & "Defines?" to your code.
Code:
Defines? = Pos( ' DEFINE', LINE ) > 0
NoIndex? = Pos( ' NONINDEXED', LINE ) > 0 ,
| Pos( ' NIXD', LINE ) > 0
Index? = Pos( ' INDEXED', LINE ) > 0 ,
| Pos( ' IXD', LINE ) > 0
Number? = Pos( ' NUMBERED', LINE ) > 0 ,
| Pos( ' NUMD', LINE ) > 0
Keysp? = Pos( ' KEYS', LINE ) > 0
. . . . . . . . . . . . .
SELECT
WHEN Defines? THEN DO
ADDPERM = 'N'
END
WHEN NoIndex? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(NONE)"||' '||"-"
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Index? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Number? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Keysp? & ADDPERM = 'N' THEN DO
ATTR3 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
. . . . . . . . .
It's adding parameters in below scenarios:
1. When there is space between Keys and '(" ex: "KEYS (09 00)" .
2. If parameter is ending with ')' i.e., last parameter ex: INDEXED)
1. When there is space between Keys and '(" ex: "KEYS (09 00)" . ==> This issue is resolved by added or statement to the existing one as below.
Code:
Keysp? = Pos( ' KEYS', LINE ) > 0,
| Pos( ' KEYS ', LINE ) > 0
Please correct me if i'm wrong.
There is no need to check both cases; the first POS detects both of them, and there is a very low chance some other cases might fall into this simple check mistakenly; I do not re-call those. If they do exist, we might need to check them more specifically.
spizen556 wrote:
2. If parameter is ending with ')' i.e., last parameter ex: INDEXED) ==> Still this is pending.
I don't have any simple idea to solve this. Please help if you have any suggestion.
The idea what i have is ,
Index1? = Pos( ' INDEXED)', LINE ) > 0 ,
| Pos( ' IXD)', LINE ) > 0
For all the other parameters i need to add ')' also and add another paragraph to add the parameters before that line.
The same story: any test via POS on ' STRING' is enough to verify all cases:
Code:
' STRING'
' STRING '
' STRING)'
' STRING )'
and many other combinations, too.
No need to check for optional parenthesis, commas, or whatever else.
We may rely on reasonably correct source syntax; no need to create sophisticated syntax parser to be able to parse any possible garbage.
P.S.
If comments are allowed within /* and */, it makes sense just to exclude that parts from LINE before verification on all other keywords under question.
stmt = ""
do isys = 1 to sysin.0
card = sysin.isys
if stmt = "" then do
if left(space(card),6) \= "DEFINE" then ,
iterate
else ,
stmt = space( card )
end
else do
stmt = space( stmt card )
end
if right(stmt,1) = "-" then do
stmt = strip(stmt, "T", "-")
iterate
end
stmt_new = ""
do i = 1 to length(stmt)
tk = substr(stmt,i,1)
select
when tk = "(" then ,
stmt_new = stmt_new " ( "
when substr(stmt,i,1) = ")" then ,
stmt_new = stmt_new " ) "
otherwise ,
stmt_new = stmt_new || tk
end
end
stmt = space( stmt_new )
CLUSTER.RSLQUIESCE = ""
CLUSTER.LOG = "( UNDO )"
do while stmt \= ""
parse var stmt tk .
tk = space(tk)
if tk = ")" then do
/* build the reformatted idcams statements
for CLUSTER AIX DATA INDEX
*/
if wordpos(comp, "CLUSTER AIX PATH" ) > 0 then do
say "/* */"
say " DEFINE "comp" ( -"
end
else do
say " "comp" ( -"
end
do k = 1 to words(idckwds idcflgs)
kw = word(idckwds idcflgs, k)
if symbol( comp"."kw ) = "VAR" then do
interpret "say ' '"kw" "comp"."kw"' -'"
interpret drop comp"."kw
end
end
parse var stmt . stmt
comp = ""
if stmt = "" then do
say " )"
end
else do
say " ) -"
end
iterate
end
if tk = "(" then do
parse var stmt "(" kval ")" stmt
kval = space(kval)
stmt = space(stmt)
interpret comp"."keyw"=" "'( "kval" )'"
iterate
end
if tk = "DEFINE" then do
parse var stmt . stmt
stmt = space(stmt)
iterate
end
if wordpos( tk, "CLUSTER AIX PATH DATA INDEX" ) > 0 then do
/* lookahead one symbol to discard the open parenthesis */
parse var stmt . stmt
comp = tk
parse var stmt tk .
tk = space(tk)
if tk \= "(" then ,
signal logic_error
parse var stmt . stmt
stmt = space(stmt)
iterate
end
keyw = space(tk)
if wordpos(keyw, idcflgs ) > 0 then ,
interpret comp"."keyw"=" "''"
parse var stmt . stmt
stmt = space(stmt)
end
There are lot of other scenarios as well but the code which was provided by me is working fine except the three scenarios which I have mentioned in my initial post.
I will test this code and let you know the outcome.
My only concern here is, in above code there are hardcoded keywords idckwds, idcflgs but for the VSAM cluster there are few more attributes also. My examples might have covered only few Keywords. I'm not sure if we need to incorporate all keywords here.
Just want to provide more clarification on the requirement.
The overall requirement is to add RSLQUIESCE & LOG attributes to the existing parm cards.
1. Only ESDS(Nonindexed) log parameter should be LOG(NONE) and for remaining all types of files log parameter should be LOG(UNDO).
2. RSLQUIESCE should be added for all kind of files.
in above code there are hardcoded keywords idckwds, idcflgs
they were hardcoded to make the parsing easier and more understandable
the parsing for a flag is complete when the script sees the flag
the parsing for a keyword with arguments is complete only after the next entity has been processed ( one lookahead )
anyway it is useful to hardcode some keywords/flags because the table will give the sequence in which the keyword are generated
If any of the below parameters are not present then need to find for keyword Keys and add the required parameters.
NONINDEXED,
NIXD,
INDEXED,
IXD,
NUMBERED,
NUMD
To overcome this scenarios i have added "Keyp?" & "Defines?" to your code.
Code:
Defines? = Pos( ' DEFINE', LINE ) > 0
NoIndex? = Pos( ' NONINDEXED', LINE ) > 0 ,
| Pos( ' NIXD', LINE ) > 0
Index? = Pos( ' INDEXED', LINE ) > 0 ,
| Pos( ' IXD', LINE ) > 0
Number? = Pos( ' NUMBERED', LINE ) > 0 ,
| Pos( ' NUMD', LINE ) > 0
Keysp? = Pos( ' KEYS', LINE ) > 0
. . . . . . . . . . . . .
SELECT
WHEN Defines? THEN DO
ADDPERM = 'N'
END
WHEN NoIndex? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(NONE)"||' '||"-"
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Index? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Number? & ADDPERM = 'N' THEN DO
PRMT3 = "LOG(UNDO)"||' '||"-"
P1=POS(VAR1,LINE)
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
WHEN Keysp? & ADDPERM = 'N' THEN DO
ATTR3 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRIBUTES
ADDPERM = 'Y'
END
. . . . . . . . .
It's adding parameters in below scenarios:
1. When there is space between Keys and '(" ex: "KEYS (09 00)" .
2. If parameter is ending with ')' i.e., last parameter ex: INDEXED)
"(CURRLN) = LINENUM .ZCSR" /* CURRENT LINE */
"(LASTLN) = LINENUM .ZLAST" /* LAST LINE NUMBER */
I = 0
DO FOREVER
I = I + 1
IF I > LASTLN THEN LEAVE
"(LINE) = LINE " I
LINE = SUBSTR(LINE,1,80)
IF SUBSTR(LINE,1,3) = "//*" | SUBSTR(LINE,1,3) = " /*" THEN ITERATE
VAR1 = SUBWORD(LINE,1,1)
UPPER VAR1
PRMT1 = "RLSQUIESCE"||' '||"-"
Defines? = Pos( ' DEFINE', LINE ) > 0,
| Pos( ' DEFINE ', LINE ) > 0
stringa? = Pos( ' STRINGA', LINE ) > 0,
| Pos( ' STRINGA ', LINE ) > 0,
| Pos( ' STRINGA)', LINE ) > 0,
| Pos( ' STRINGA )', LINE ) > 0
stringb? = Pos( ' STRINGb', LINE ) > 0,
| Pos( ' STRINGb ', LINE ) > 0,
| Pos( ' STRINGb)', LINE ) > 0,
| Pos( ' STRINGb )', LINE ) > 0
NoIndex? = Pos( ' NONINDEXED', LINE ) > 0 ,
| Pos( ' NIXD', LINE ) > 0
Index? = Pos( ' INDEXED', LINE ) > 0 ,
| Pos( ' IXD', LINE ) > 0
Number? = Pos( ' NUMBERED', LINE ) > 0 ,
| Pos( ' NUMD', LINE ) > 0
Keysp? = Pos( ' KEYS', LINE ) > 0,
| Pos( ' KEYS ', LINE ) > 0
SELECT
WHEN Defines? THEN DO
ADDATTR = 'N'
END
WHEN stringa? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRB
ADDATTR = 'Y'
END
WHEN stringb? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(NONE)"||' '||"-"
CALL ADD_ATTRB
ADDATTR = 'Y'
END
WHEN NoIndex? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(NONE)"||' '||"-"
CALL ADD_ATTRA
ADDATTR = 'Y'
END
WHEN Index? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRA
ADDATTR = 'Y'
END
WHEN Number? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRA
ADDATTR = 'Y'
END
WHEN Keysp? & ADDATTR = 'N' THEN DO
PRMT2 = "LOG(UNDO)"||' '||"-"
CALL ADD_ATTRA
ADDATTR = 'Y'
END
OTHERWISE
NOP
END
END
/* EXIT(RC) */
NoIndex? = Pos( ' NONINDEXED', LINE ) > 0 ,
| Pos( ' NIXD', LINE ) > 0
Index? = Pos( ' INDEXED', LINE ) > 0 ,
| Pos( ' IXD', LINE ) > 0
So every time you set NoIndex? you also set Index? SIASD!
The flags are used ONLY to indicate the presence of each specific keyword in the current line.
Alternate way is - explicit reset of all flags before every new line, and/or conditional verification of each flag depending on those previously set.
This approach would be really SIASD - if only you thought a little about this.