Showing posts with label ISPEXEC. Show all posts
Showing posts with label ISPEXEC. Show all posts

Thursday, August 25, 2016

REXX: LMINIT, LMOPEN, LMMLIST, LMCLOSE, LMFREE

We shall read all member names using LISTDS "Dataset" Members. But however, I felt that this technique requires some logic to ignore certain statements before we could really get hold of the member name.

So,how to read all members of a Dataset without having any additional logical overhead?

It is possible via LMMLIST. We will go through the steps briefly in this post.

Step 1: LMINIT

LMINIT generates a DataId for the dataset.

REXX can be executed in foreground or background. When we execute from background, the DDNAMES are already allocated. In Foreground, we have to allocate the DDNames. This DDName can be provided in the LMINIT or we shall directly provide the Dataset Name. When we are providing DDname, we should use the keyword DDNAME. When we are providing the dataset, we should use the keyword DATASET.

In our example, we are using DATASET.

Dataset = "DATASET('"Your-Dataset"')"            
address "ISPEXEC"                                       
"LMINIT" Dataset "DATAID(DataId) ENQ(SHR)"

Step 2: LMOPEN

LMOPEN opens dataset associated with DataId generated using the LMINIT step.
Option INPUT means its only read only.
Option OUTPUT means its for writing the dataset. When opened with OUTPUT option, then it is necessary to have a matching LMCLOSE. If LMCLOSE is not issued for the DataID, then the DataID is not released until ISPF terminates.

"LMOPEN DATAID("DataID") OPTION(INPUT)"   

Step 3:

DO FOREVER
  "LMMLIST DATAID("DataId") OPTION(LIST) MEMBER(Member) STATS(NO)"      IF RC = 8 THEN LEAVE
   SAY MEMBER
END 

This step displays you all the member names.

Step 4:
"LMCLOSE DATAID("DATAID")" 

Close the DataID.

Step 5:
"LMFREE DATAID("DATAID")"   

Free the DataID.

Incase of questions, please drop your questions in the comments.

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....