Visit SDSUSA site please  

Go Back   mvsHelp Boards > Help Bulletin Board > REXX, CLIST
User Name
Password
-->
FAQ Search Manuals Calendar New Posts Search Today's PostsMark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-22-2010, 04:24 AM
Michael Simpson Michael Simpson is offline
Senior Member
 
Join Date: Oct 2002
Location: Stockholm
Posts: 794
Default Find IF as first word

I have a mainframe script that checks the level of nesting in cobol programs (so people get a slap on the wrist for coding something like if else if else if else if else if else etc etc)
Code:
/* Remove any commented lines from the FIND command */ 'exclude "*" .strts .ends all 'leading leading /* Count only NON-commented IF's */ 'find " IF " .strts .ends all nx' "(res) = find_counts"
This has worked fine, until it hit the following code
Code:
string '*** You have defined default values for ' delimited by size '(character) field ' delimited by size def-col-name(ix-1) delimited by ' ' ' with BN (as if it were numeric). Use = instead' delimited by size into shbgg015-meddelande-tab end-string
whereupon it finds the IF in quotes and treats it as if it was part of an IF/END-IF statement.

I could easily change the
Code:
'find " IF " .strts .ends all nx'
to perform a loop, but is there a variation on the find command that would do the job for me (basically, I only want to count the word IF if it's the first word on the line)
Reply With Quote
  #2  
Old 07-22-2010, 06:32 AM
dbzthedinosaur's Avatar
dbzthedinosaur dbzthedinosaur is offline
Senior Member
 
Join Date: Nov 2005
Location: Varel, Germany
Posts: 1,306
Default

part of the FIND command syntax is FIRST and WORD
__________________
Dick Brenholtz
American in Varel, Germany
Reply With Quote
  #3  
Old 07-22-2010, 06:50 AM
Nic Clouston Nic Clouston is offline
Senior Member
 
Join Date: Jan 2007
Location: Portsmouth
Posts: 223
Default

But FIRST refers to the first OCCURRENCE on a line, not the first word so the 'IF' could be the last word on the line and still be in the result set. WORD just makes sure that only the WORD 'IF' is included in the result set and not words such as 'dIFficult'.

You may have to check the POS of any ' and see if the IF comes after it and before a second '.

Or, find the position of the first non-blank character and see if it is IF.
__________________
Everything I say is a lie - believe me!
Reply With Quote
  #4  
Old 07-22-2010, 07:10 AM
Michael Simpson Michael Simpson is offline
Senior Member
 
Join Date: Oct 2002
Location: Stockholm
Posts: 794
Default Thanks Nic

that's about what I'd figured - have to perform a loop.

Just wanted to check that there wasn't some finesse I didn't know about
Reply With Quote
  #5  
Old 07-22-2010, 07:28 AM
dbzthedinosaur's Avatar
dbzthedinosaur dbzthedinosaur is offline
Senior Member
 
Join Date: Nov 2005
Location: Varel, Germany
Posts: 1,306
Default

I stand corrected, FIND parms do not fit as I suggested.

I don't use FIND that often basically due to this problem. have to check the columns, etc...

normally for this kind of task, I use a combination of LINE to populate a stem, and PARSE to detemine if the 'IF' is really an IF.
__________________
Dick Brenholtz
American in Varel, Germany
Reply With Quote
  #6  
Old 07-22-2010, 07:49 AM
dbzthedinosaur's Avatar
dbzthedinosaur dbzthedinosaur is offline
Senior Member
 
Join Date: Nov 2005
Location: Varel, Germany
Posts: 1,306
Default

enforcing standards is always alot of fun.

when the site could not afford (or would not buy) standards enforcing software
(it is expensive)
I would write a COBOL program that would insert a non astriked '*' comment in the source explaining the offense.
This program was part of the compile proc, that everyone had to use,
and of course the un-astriked comment(s) would cause a compile failure.

this allowed for consequences - can't compile the program
and avoided such issues as:
  • a script has to be invoked either by the user or you
  • 'the program works and needs to go to production, now'
__________________
Dick Brenholtz
American in Varel, Germany
Reply With Quote
  #7  
Old 07-22-2010, 08:57 AM
RonB RonB is offline
Senior Member
 
Join Date: Aug 1999
Location: Orlando, FL, USA
Posts: 865
Default

Quote:
Originally Posted by Michael Simpson
(basically, I only want to count the word IF if it's the first word on the line)
What would you want to do if legitimate 'IF'(s) are not the first word(s) on (a) line(s), for example
Code:
IF VAR-X > VAR-Y THEN IF VAR-Y = VAR-Z THEN PERFORM PARA-A ELSE IF VAR-Y > VAR-Z THEN PERFORM PARA-B ELSE PERFORM PARA-C END-IF END-IF ELSE PERFORM PARA-D END-IF
__________________
Ron
Reply With Quote
  #8  
Old 07-22-2010, 09:21 AM
don.leahy don.leahy is offline
Senior Member
 
Join Date: Apr 2007
Location: Whitby, ON, Canada
Posts: 456
Default

Quote:
Originally Posted by RonB
What would you want to do if legitimate 'IF'(s) are not the first word(s) on (a) line(s), for example
Code:
IF VAR-X > VAR-Y THEN IF VAR-Y = VAR-Z THEN PERFORM PARA-A ELSE IF VAR-Y > VAR-Z THEN PERFORM PARA-B ELSE PERFORM PARA-C END-IF END-IF ELSE PERFORM PARA-D END-IF

The above is a good example of why the commercial software products that enforce standards are so expensive. To do this rigourously requires you to re-engineer the Cobol language parser used by the compiler and then apply your local standards. A challenging undertaking, so say the least.
__________________
"Don't tell me how it works, tell me how it fails."
Reply With Quote
  #9  
Old 07-22-2010, 09:32 AM
dbzthedinosaur's Avatar
dbzthedinosaur dbzthedinosaur is offline
Senior Member
 
Join Date: Nov 2005
Location: Varel, Germany
Posts: 1,306
Default

I would bounce the code because it violated standards.
I work with a lot of doctorates (physics)
and they also have no sensitivity to readability.

THEN, ELSE also alone on a separate line

Code:
IF VAR-X > VAR-Y THEN IF VAR-Y = VAR-Z THEN PERFORM PARA-A ELSE IF VAR-Y > VAR-Z THEN PERFORM PARA-B ELSE PERFORM PARA-C END-IF END-IF ELSE PERFORM PARA-D END-IF
__________________
Dick Brenholtz
American in Varel, Germany
Reply With Quote
  #10  
Old 07-22-2010, 09:42 AM
RonB RonB is offline
Senior Member
 
Join Date: Aug 1999
Location: Orlando, FL, USA
Posts: 865
Default

FWIW, I, myself, would NEVER write COBOL code in the manner that I posted as an "example" of the kind of code that "might" be encountered in someone else's source code. I merely posted it as an example of another kind of code that Michael "might" encounter that may cause his filter to hiccup or misfire.

In his preamble he, himself, used the phrase "coding something like if else if else if else if else if else etc etc" - a phrase in which there are multiple IF's following the word ELSE on the same line.
__________________
Ron
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 06:57 AM.


Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.