Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Checking unused variables in a Cobol code

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: Checking unused variables in a Cobol code
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

Senior Member


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

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

Hi,

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

http://ibmmainframes.com/viewtopic.php?t=34675&highlight=unused
http://ibmmainframes.com/viewtopic.php?t=20057&highlight=unused
http://ibmmainframes.com/viewtopic.php?t=23268&highlight=unused
http://ibmmainframes.com/viewtopic.php?t=25745&highlight=unused
http://ibmmainframes.com/viewtopic.php?t=26148&highlight=unused
http://ibmmainframes.com/viewtopic.php?t=29474&highlight=unused
http://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    Post subject: Reply to: Checking unused variables in a Cobol code
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

Site Director


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

PostPosted: Thu Nov 20, 2008 7:41 am    Post subject: Reply to: Checking unused variables in a Cobol code
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    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Feb 25, 2009 10:45 pm    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Feb 26, 2009 8:45 pm    Post subject:
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    Post subject: Reply to: Checking unused variables in a Cobol code
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

Senior Member


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

PostPosted: Sat Mar 07, 2009 2:21 am    Post subject: Reply to: Checking unused variables in a Cobol code
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: 401
Location: Mumbai

PostPosted: Sat Mar 07, 2009 3:29 am    Post subject: Reply to: Checking unused variables in a Cobol code
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts PL/I code tuning/Performance improvement Virendra Shambharkar PL/I & Assembler 4 Mon Dec 05, 2016 11:57 am
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
No new posts IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us