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.

3 comments:

  1. I've lately noticed all sorts of people writing
    address 'TSO' or
    address 'ISPEXEC'

    Quoting the address specification is useless/redundant. The language spec REQUIRES a constant there. There is little you can do to get around that. Quoted or unquoted, the interpreter sees a constant.

    Why do you think people do this?

    ReplyDelete
  2. Normally REXX is seldom learnt from Authenticated tutorials. People learn through examples from their colleagues or through internet. Over the internet, you shall see people using Quoting over ISPEXEC and TSO. The usage of Quoting and Unquoting wasn't consistent.

    ReplyDelete
  3. not sure why the command is returning RC = -3

    address "ISPEXEC"
    "LMINIT" Dataset "DATAID(DataId) ENQ(SHR)"

    Not able to find the root cause.

    ReplyDelete

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....