IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

ISPF search - capturing result


IBM Mainframe Forums -> TSO/ISPF
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Sat Dec 07, 2019 5:20 am
Reply with quote

does anyone know if the result of an ISPF edit search is accessible in an ISPF variable ?

eg, from a REXX macro, i might have something like:

"F r'ab.+z'" which would match, for example, "abcdz"

is the result mapped to any .Z variable ?
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 712
Location: Denmark

PostPosted: Sat Dec 07, 2019 4:49 pm
Reply with quote

The ISPF EDIT macro FIND service will set rc=0 and the special variable .zcsr to the line number if a match is found.

Sample:
"find ' XXMACS ' first nx"
if rc=0 then "change ' ' '*' .zcsr .zcsr first"

See the 'Edit and Edit Macros' manual for details.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2545
Location: Silicon Valley

PostPosted: Tue Dec 10, 2019 11:18 pm
Reply with quote

After the FIND is successful, you can use the CURSOR macro statement to get the line number and column value of where the cursor is. Then use the LINE macro statement to get the entire line. Use rexx PARSE statement to break up the line based on the column offset.
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Wed Dec 11, 2019 2:29 am
Reply with quote

@Pedro: You might not get the RegEx search string in full detail when using parse afterwards.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Wed Dec 11, 2019 2:46 am
Reply with quote

Use the "macro_msg" edit macro command, and parse the resulting variables, ZEDILMSG, ZEDISMSG, and ZEDMSGNO.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2545
Location: Silicon Valley

PostPosted: Wed Dec 11, 2019 11:47 am
Reply with quote

Quote:
You might not get the RegEx search string in full detail


I was guessing it would be a blank delimited string.
Back to top
View user's profile Send private message
Willy Jensen

Active Member


Joined: 01 Sep 2015
Posts: 712
Location: Denmark

PostPosted: Wed Dec 11, 2019 12:48 pm
Reply with quote

Ok, slightly better sample than my first one:
"find 'text' first"
if rc=0 then "(r) = line .zcsr"
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Wed Dec 11, 2019 2:50 pm
Reply with quote

This snippet works for me.

Code:
"MACRO_MSG = ON"                   
"F r'ab.+z'"                       
parse var ZEDISMSG . "'"string"'" .
say string
Back to top
View user's profile Send private message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Tue Dec 17, 2019 8:39 am
Reply with quote

thanks ! works brilliantly

slightly related, is there any way to get capture elements from a matching Regex ?

so, if an input line contained :

xyz : 123

any my match was r'xyz : *([^ ]+) *$'

then it would capture 123
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Tue Dec 17, 2019 8:45 am
Reply with quote

Have you tried the code snippet? Guess not.. icon_rolleyes.gif
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Tue Dec 17, 2019 8:56 am
Reply with quote

For your RegEx I'd use:

Code:
^xyz[ ]+:[ ]+([0-9])+.*$
Back to top
View user's profile Send private message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Fri Jan 03, 2020 8:04 am
Reply with quote

sorry all, some clarification required on my part

my follow up was more about capture elements specifically. A regex expression can have one or more capture elements, identified by bracket pairs.

so, r'x(..)y(..)' would capture :

xyzyab

returning yz into capture element 1 and 'ab' into capture element 2. This is supported by a full implementation of REgex, but suspect it is not possible in ISPF regex.
Back to top
View user's profile Send private message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Fri Jan 03, 2020 8:06 am
Reply with quote

.. meaning I want to be able to capture an element into a variable ...
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Sat Jan 04, 2020 2:18 pm
Reply with quote

AFAIK it is not (yet) possible with ISPF to have the captured groups as variables.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2545
Location: Silicon Valley

PostPosted: Wed Jan 08, 2020 3:41 am
Reply with quote

Quote:
it is not (yet) possible with ISPF to have the captured groups as variables.


You should submit a Request For Enhancment at developerworks. www.ibm.com/developerworks/rfe/ You will need to get an userid
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Thu Jan 09, 2020 1:40 am
Reply with quote

@Pedro: You only get one or two votes for that and it's being considered niche. Of course ISPF variables ZRE0..9 for up to 10 capture groups are available and it could work like that. The second string in a CHANGE could have r'\0 .. \9' for those variables if the first is also a RegEx but the total unresolved(?) expression length for both must not exceed 256 characters afaik presently.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> TSO/ISPF

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Looking for a little history of ISPF ... TSO/ISPF 5
No new posts Adding QMF and SPUFI to the ISPF menu DB2 20
No new posts Capturing Job Execution Information All Other Mainframe Topics 3
Search our Forums:

Back to Top