1

In a REXX tool, I want to check if the PS file contains a specific pattern (like continuous 16 digits) in mainframe, for which I want to execute a Regular expression and then check the RC for further processing. I tried below code, but not able to execute the regular expression.

/* REXX */
STRIGN = "rc'[0-9]{16}'"
ADDRESS ISPEXEC "VIEW DATASET('XXXX.XXXXX.XXXXX')"
ADDRESS ISREDIT "MACRO (STRING)"
"F" STRING
SAY RC

For the code I am getting error for line

"F" STRING' 'IKJ56500I COMMAND F NOT FOUND' and RC = '-3'.

Could anyone please suggest any way to execute a regular expression using REXX in mainframe.

Mahesh Waghmare
  • 726
  • 9
  • 27
S. Agrawal
  • 79
  • 1
  • 8
  • 3
    try doing `ADDRESS ISREDIT "f" string`. This will invoke the ispf edit find. just doing "f" string calls TSO – Bruce Martin Nov 18 '19 at 11:18
  • 1
    STRIGN = "rc'[0-]9]{16}'" should probably be STRING = "rc'[0-]9]{16}'" – Hogstrom Nov 19 '19 at 02:27
  • 2
    @BruceMartin Unless I've misunderstood you, that won't work as the 'ADDRESS ISPEDIT VIEW' branches into a 'view' session and the next line on the calling REXX (ADDRESS ISREDIT "f" string) doesn;t get executed until the view session is exited. At which point you get RC 20 as `ADDRESS ISREDIT "f" string` isn't valid (ISREDIT does not understand the F command). – Steve Ives Nov 19 '19 at 09:50

1 Answers1

2

You'll need to create a separate ISPF edit macro containing your edit commands:

/* REXX */
address isredit
"macro"
"f rc'[0-9]{16}'"
say rc

and then specify this macro when you edit the dataset. E.g. if you create a macro called 'findnum' then you'd code:

address ispexec                                           
  "edit dataset('XXXX.XXXXX.XXXXX') macro(findnum)" )

which will cause edit to be invoked for that dataset and to run the 'findnum' macro.

Your macro has to be in a dataset that is part of your SYSPROC or SYSEXEC concatenation.

Steve Ives
  • 7,894
  • 3
  • 24
  • 55
  • Thanks @Steve Ives, the solution worked, and your prior explanation helped to understand the issue. Could you please suggest any way to execute 'macro(findnum)' without opening the file in 'edit' or 'view' mode, or any way to ignore this opened dataset without manual intervention. – S. Agrawal Nov 19 '19 at 13:42
  • @S.Agrawal To find out if the dataset contains the string you want, you are going to have to open it. You could write a simple REXX program to read the file and look for the string (except REXX doesn't have regexes). Don;t forget that the edit macro can also end the edit session, allowing the calling rexx to resume control and you could pass back a return code. You could also run edit with the macro in batch so there are many ways to approach the problem. – Steve Ives Nov 25 '19 at 17:29