This example initializes and opens an input and an output data set, using LMINIT and LMOPEN respectively. The exec loops through the all the records of the input data set using the LMGET service. Each record of the input data set is stored into the variable srchline. The variable srchline is parsed to find a member name. The string 'SELECT ' followed by the member name is stored into a variable called selline which is added to the output data set, using the LMPUT service. The input and output data sets are closed and freed using LMCLOSE and LMFREE.
/* rexx *************************************************************/
/* */
/* Member: SETSRCH */
/* */
/* Purpose: To create a srchfor.stmts data set that contains */
/* only those members with a certain string. For example, */
/* if both CLIST and REXX execs are stored in the same */
/* library, but you only want to search the REXX members */
/* search the library for the word rexx, with the options */
/* listed below to create srchfor.list. Use the resulting */
/* statements data set as input to the next search. */
/* */
/* Setup: Create the srchfor output using option 3.15 with */
/* process options: */
/* LMTO NOSUMS NOPRTCC */
/* to create an output listing data set called */
/* userid.srchfor.list without a summary section or page */
/* dividers. */
/* */
/* Input: userid.SRCHFOR.LIST (as created in setup). */
/* */
/* Output: userid.SRCHFOR.STMTS containing a SELECT statement */
/* for each member to be searched. */
/* */
/********************************************************************/
address ispexec
'lminit dataid(srchout) dataset(srchfor.list) enq(shr) '
if rc = 0 then
do
'lmopen dataid('srchout') option(input)'
if rc = 0 then
do
'lminit dataid(srchstmt) dataset(srchfor.stmts) enq(exclu)'
if rc = 0 then
do
'lmopen dataid('srchstmt') option(output)'
if rc = 0 then
do
done = 'n'
datavar = 0
linenum = 1
do while done = 'n'
'lmget dataid('srchout') mode(invar) dataloc(srchline)
datalen(datavar) maxlen(132)'
if rc = 0 then
do
linenum = linenum + 1
if linenum > 5 then /* skip over header */
do
parse var srchline memname linesfnd linesrch
if memname /= ' ' then
do
selline = 'SELECT ' memname
'lmput dataid('srchstmt') mode(invar),
dataloc(selline) datalen(80)'
if rc > 0 then
done = 'y'
end
end
end
else
done = 'y'
end
'lmclose dataid('srchstmt ')'
end
'lmfree dataid('srchstmt ')'
end
'lmclose dataid('srchout ')'
end
'lmfree dataid('srchout ')'
end
exit