View previous topic :: View next topic
|
Author |
Message |
lekshmi_ci
New User
Joined: 14 Mar 2007 Posts: 60 Location: Thiruvananthapuram
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
Back to top |
|
|
Jose Villafranca
New User
Joined: 12 Nov 2008 Posts: 4 Location: Monterrey
|
|
|
|
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.
Jose L. Villafranca |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Jose and welcome to the forum,
Thank you for posting your code
d |
|
Back to top |
|
|
lekshmi_ci
New User
Joined: 14 Mar 2007 Posts: 60 Location: Thiruvananthapuram
|
|
|
|
Thank you Jose |
|
Back to top |
|
|
Jose Villafranca
New User
Joined: 12 Nov 2008 Posts: 4 Location: Monterrey
|
|
|
|
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 |
|
|
saroragu
New User
Joined: 12 Nov 2008 Posts: 22 Location: india
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
saroragu
New User
Joined: 12 Nov 2008 Posts: 22 Location: india
|
|
|
|
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 |
|
|
saroragu
New User
Joined: 12 Nov 2008 Posts: 22 Location: india
|
|
|
|
Sorry that problem was solved. will you please tell me what value to be entered in that path.1. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Maybe the datasetname(membername) for the source to be processed? |
|
Back to top |
|
|
SangeethaMahesh
New User
Joined: 04 Mar 2009 Posts: 1 Location: India
|
|
|
|
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 |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2596 Location: Silicon Valley
|
|
|
|
Use a Say instruction to display the contents of num1 and num2. Then figure out why the values are not numeric. |
|
Back to top |
|
|
MBabu
Active User
Joined: 03 Aug 2008 Posts: 400 Location: Mumbai
|
|
|
|
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 |
|
|
Bharath Vikraman
New User
Joined: 06 Aug 2017 Posts: 9 Location: India
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10889 Location: italy
|
|
|
|
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 |
|
|
|