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

Checking unused variables in a Cobol code


IBM Mainframe Forums -> CLIST & REXX
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
lekshmi_ci

New User


Joined: 14 Mar 2007
Posts: 60
Location: Thiruvananthapuram

PostPosted: Thu Oct 30, 2008 12:22 pm
Reply with quote

Hey,
Have you people come across any REXX code for checking unused variables in a cobol program. Please share if anyone has. Thaks in advance.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Oct 30, 2008 12:36 pm
Reply with quote

Hi,

Please search the forum first, here are some similar topics:

ibmmainframes.com/viewtopic.php?t=34675&highlight=unused
ibmmainframes.com/viewtopic.php?t=20057&highlight=unused
ibmmainframes.com/viewtopic.php?t=23268&highlight=unused
ibmmainframes.com/viewtopic.php?t=25745&highlight=unused
ibmmainframes.com/viewtopic.php?t=26148&highlight=unused
ibmmainframes.com/viewtopic.php?t=29474&highlight=unused
ibmmainframes.com/viewtopic.php?t=34553&highlight=unused
Back to top
View user's profile Send private message
Jose Villafranca

New User


Joined: 12 Nov 2008
Posts: 4
Location: Monterrey

PostPosted: Thu Nov 20, 2008 3:38 am
Reply with quote

Hi, I wrote this code some days ago and it should do the trick.
The program first list all variables between working storage and procedure division and then search if there is an incidence for each variable from procedure division till the end of code. If an incidence is found then the variable is flagged with 1 and the search for that variable is stoped. Then it continue with the next found variable.

Code:
 
 PATH.1 = 'LIBRARY(MEMBER)'
 "ALLOC DDN(INFILE) SHR REUSE DSN("PATH.1""
 "EXECIO * DISKR INFILE (STEM PARA. FINIS"
   CALL FIND_SECTION 'WORKING-STORAGE SECTION'                           
   N1 = RESULT                                                           
   CALL FIND_SECTION 'PROCEDURE DIVISION'                               
   N2 = RESULT                                                           
   CALL UNUSED_VAR N1 N2   
 
/*******************************************************************/   
/* UNUSED_VAR:  UNUSED VARIABLES                                   */   
/* USE:   CALL UNUSED_VAR NUM1 NUM2                                */   
/* WHERE NUM1 IS THE FIRST LINE TO SEARCH                          */   
/* AND   NUM2 IS THE LAST LINE TO SEARCH                           */   
/*******************************************************************/   
 UNUSED_VAR:                                                             
  ARG NUM1 NUM2                                                         
  FOUND = 0                                                             
  NUM. = 0                                                               
  J=1                                                                   
  DO I = NUM1 TO NUM2                                                   
    PARSE VAR PARA.I WITH 7 COL7 +1 STRING 73                           
    IF COL7 = '*' | COL7 = '-' | COL7 = '/' THEN                         
      NOP                                                               
    ELSE                                                                 
    DO                                                                   
      NO_WORD = FIND(STRING,'PIC')                                       
      IF NO_WORD <> 0 THEN                                               
        DO                                                               
          FSTRING.J = WORD(STRING,NO_WORD-1)                             
          IF FSTRING.J <> "" THEN                                       
           J = J+1                                                       
          ELSE NOP                                                       
        END                                                             
      ELSE NOP                                                           
    END                                                                 
  END                                                                   
  J = J-1                                                               
  DO I = NUM2 TO PARA.0                                                 
     DO K=1 TO J                                                         
       INCIDENCES = FIND(TRANSLATE(PARA.I,' ','()'),FSTRING.K)           
       IF INCIDENCES <> 0 THEN                                           
         NUM.FSTRING.K = 1                                               
       ELSE NOP                                                         
     END                                                                 
  END                                                                   
  SAY '< UNUSED VARIABLES >'                                             
  DO I = 1 TO J                                                         
    IF NUM.FSTRING.I <1 THEN DO                                         
       SAY FSTRING.I                                                     
       FOUND = 1                                                         
       END                                                               
    ELSE NOP                                                             
  END                                                                   
  IF FOUND <> 1 THEN                                                     
     SAY '--NONE FOUND--'                                               
  ELSE NOP                                                               
  SAY '********************************************************'         
 RETURN                                                                 
/*********************************************************************/ 
/* FIND_SECTION: FIND WORKING STORAGE SECTION AND PROCEDURE DIVISION */ 
/* SECTION.                                                          */ 
/* USE:    CALL FIND_SECTION PHRASE                                  */ 
/* WHERE PHRASE = PHRASE TO BE FOUND                                 */ 
/* AND   RESULT = NUMBER OF PHARAGRAPH WHERE IS FIRST FOUND          */ 
/*********************************************************************/ 
 FIND_SECTION:                                                           
  ARG PHRASE                                                             
  DO I = 1 TO PARA.0                                                     
    PARSE VAR PARA.I WITH 7 COL7 +1 STRING 73                           
    IF COL7 = '*' | COL7 = '-' | COL7 = '/' THEN                         
      NOP                                                               
    ELSE                                                                 
    DO                                                                   
      NO_WORD = FIND(TRANSLATE(STRING,,'.'),PHRASE)                     
      IF NO_WORD <> 0 THEN                                               
        LEAVE                                                           
      ELSE NOP                                                           
    END                                                                 
  END                                                                   
 RETURN I   
 
       
 


Hope you find it useful. icon_biggrin.gif

Jose L. Villafranca
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Nov 20, 2008 7:41 am
Reply with quote

Hello Jose and welcome to the forum,

Thank you for posting your code icon_smile.gif

d
Back to top
View user's profile Send private message
lekshmi_ci

New User


Joined: 14 Mar 2007
Posts: 60
Location: Thiruvananthapuram

PostPosted: Thu Nov 20, 2008 7:47 am
Reply with quote

Thank you Jose icon_smile.gif
Back to top
View user's profile Send private message
Jose Villafranca

New User


Joined: 12 Nov 2008
Posts: 4
Location: Monterrey

PostPosted: Sat Jan 17, 2009 12:15 am
Reply with quote

There is a sligth modification in the code for taking only from column 7 to 73 in the search and also the translate change ":" for SPACE for cases such this: VARIABLE(CNT-1:CNT2).
In this case the variables CNT-1 and CNT-2 was detected as unused because of the ':'
Code:
PATH.1 = 'LIBRARY(MEMBER)'
 "ALLOC DDN(INFILE) SHR REUSE DSN("PATH.1""
 "EXECIO * DISKR INFILE (STEM PARA. FINIS"
   CALL FIND_SECTION 'WORKING-STORAGE SECTION'                           
   N1 = RESULT                                                           
   CALL FIND_SECTION 'PROCEDURE DIVISION'                               
   N2 = RESULT                                                           
   CALL UNUSED_VAR N1 N2   
 
/*******************************************************************/   
/* UNUSED_VAR:  UNUSED VARIABLES                                   */   
/* USE:   CALL UNUSED_VAR NUM1 NUM2                                */   
/* WHERE NUM1 IS THE FIRST LINE TO SEARCH                          */   
/* AND   NUM2 IS THE LAST LINE TO SEARCH                           */   
/*******************************************************************/   
 UNUSED_VAR:                                                             
  ARG NUM1 NUM2                                                         
  FOUND = 0                                                             
  NUM. = 0                                                               
  J=1                                                                   
  DO I = NUM1 TO NUM2                                                   
    PARSE VAR PARA.I WITH 7 COL7 +1 STRING 73                           
    IF COL7 = '*' | COL7 = '-' | COL7 = '/' THEN                         
      NOP                                                               
    ELSE                                                                 
    DO                                                                   
      NO_WORD = FIND(STRING,'PIC')                                       
      IF NO_WORD <> 0 THEN                                               
        DO                                                               
          FSTRING.J = WORD(STRING,NO_WORD-1)                             
          IF FSTRING.J <> "" THEN                                       
           J = J+1                                                       
          ELSE NOP                                                       
        END                                                             
      ELSE NOP                                                           
    END                                                                 
  END                                                                   
  J = J-1                                                               
  DO I = NUM2 TO PARA.0                                                 
     DO K=1 TO J     
       /*EXTRACT INFO FROM COLUMN 7 TO COLUMN 73*/
       PARSE VAR PARA.I WITH 7 COL7 +1 STRINGTEMP 73
       /* IN TRANSLATE I INCLUDE ":" FOR THIS CASE VAR(CTE-1:CTE2)*/
       INCIDENCES = FIND(TRANSLATE(STRINGTEMP,' ','():'),FSTRING.K)
       IF INCIDENCES <> 0 THEN                                           
         NUM.FSTRING.K = 1                                               
       ELSE NOP                                                         
     END                                                                 
  END                                                                   
  SAY '< UNUSED VARIABLES >'                                             
  DO I = 1 TO J                                                         
    IF NUM.FSTRING.I <1 THEN DO                                         
       SAY FSTRING.I                                                     
       FOUND = 1                                                         
       END                                                               
    ELSE NOP                                                             
  END                                                                   
  IF FOUND <> 1 THEN                                                     
     SAY '--NONE FOUND--'                                               
  ELSE NOP                                                               
  SAY '********************************************************'         
 RETURN                                                                 
/*********************************************************************/ 
/* FIND_SECTION: FIND WORKING STORAGE SECTION AND PROCEDURE DIVISION */ 
/* SECTION.                                                          */ 
/* USE:    CALL FIND_SECTION PHRASE                                  */ 
/* WHERE PHRASE = PHRASE TO BE FOUND                                 */ 
/* AND   RESULT = NUMBER OF PHARAGRAPH WHERE IS FIRST FOUND          */ 
/*********************************************************************/ 
 FIND_SECTION:                                                           
  ARG PHRASE                                                             
  DO I = 1 TO PARA.0                                                     
    PARSE VAR PARA.I WITH 7 COL7 +1 STRING 73                           
    IF COL7 = '*' | COL7 = '-' | COL7 = '/' THEN                         
      NOP                                                               
    ELSE                                                                 
    DO                                                                   
      NO_WORD = FIND(TRANSLATE(STRING,,'.'),PHRASE)                     
      IF NO_WORD <> 0 THEN                                               
        LEAVE                                                           
      ELSE NOP                                                           
    END                                                                 
  END                                                                   
 RETURN I   


The modifications are in the following lines

/*EXTRACT INFO FROM COLUMN 7 TO COLUMN 73*/
PARSE VAR PARA.I WITH 7 COL7 +1 STRINGTEMP 73
/* IN TRANSLATE I INCLUDE ":" FOR THIS CASE VAR(CTE-1:CTE2)*/
INCIDENCES = FIND(TRANSLATE(STRINGTEMP,' ','():'),FSTRING.K)
Back to top
View user's profile Send private message
saroragu

New User


Joined: 12 Nov 2008
Posts: 22
Location: india

PostPosted: Wed Feb 25, 2009 5:24 pm
Reply with quote

Hi all could you tell me how to use this because I dont know about REXX, but I need to use this because the install date is so near if you help me then it will be very usefull.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Feb 25, 2009 10:45 pm
Reply with quote

Hello,

Suggest you work with someone in your organization to have this code placed in a library already accessable to you. They should be able to run it once to verify it works and to show you anything you might need to know to use it for other than the verification run.

If you cannot get this running quickly on your system and your time is short, you could simply compile the program and look at the cross-reference for any unused variables.
Back to top
View user's profile Send private message
saroragu

New User


Joined: 12 Nov 2008
Posts: 22
Location: india

PostPosted: Thu Feb 26, 2009 11:40 am
Reply with quote

LABEL UNUSED_VAR SPECIFIED BUT COMMAND NOT FOUND
LABEL FIND_SECTION SPECIFIED BUT COMMAND NOT FOUND
This giving the above error messages.
will you please explain me about this.
Back to top
View user's profile Send private message
saroragu

New User


Joined: 12 Nov 2008
Posts: 22
Location: india

PostPosted: Thu Feb 26, 2009 12:24 pm
Reply with quote

Sorry that problem was solved. will you please tell me what value to be entered in that path.1.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Feb 26, 2009 8:45 pm
Reply with quote

Hello,

Maybe the datasetname(membername) for the source to be processed?
Back to top
View user's profile Send private message
SangeethaMahesh

New User


Joined: 04 Mar 2009
Posts: 1
Location: India

PostPosted: Fri Mar 06, 2009 9:51 am
Reply with quote

Hello all,

I tried the above code for my program, but it is giving the below msg

< unused variables >
-- none found --
***************************************
21 +++ Do I = num1 to num2
error running this rexx, line 21: Bad arithmetic conversion.

what is the prob in my case? Im unable to resolve it.

I have another question:
Other than PATH.1 for anything else Do I need to give values from my side?

Thanks in advance,
SangeethaMahesh
Back to top
View user's profile Send private message
Pedro

Global Moderator


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

PostPosted: Sat Mar 07, 2009 2:21 am
Reply with quote

Use a Say instruction to display the contents of num1 and num2. Then figure out why the values are not numeric.
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 400
Location: Mumbai

PostPosted: Sat Mar 07, 2009 3:29 am
Reply with quote

The most reliable way to do this is to compile the program with the ADATA option to create a SYSADATA file and scan that for type '0044'x records (xref). Those variables with zero read or modify references are unused. This way you don't have to parse any code or listings. It also means that variables from all copybooks are included in the list, though I think you could exclude them easily. There are loads of useful things you can do with the SYSADATA file in editor macros and tools, and this exercise is among the simplest.
Back to top
View user's profile Send private message
Bharath Vikraman

New User


Joined: 06 Aug 2017
Posts: 9
Location: India

PostPosted: Mon Aug 07, 2017 3:22 pm
Reply with quote

fOR THIS LINE " IF COL7 = '*' | COL7 = '-' | COL7 = '/' THEN "

Error running SELECT, line 26: Invalid character in program

COULD YOU PLEASE HELP HERE?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Aug 07, 2017 3:46 pm
Reply with quote

most probably You messed up things downloading the script
and You might have a codepage problem with the | char

topic locked anyway , no reason to resurrect a 8 years old topic
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compile rexx code with jcl CLIST & REXX 6
Search our Forums:

Back to Top