Identify and remove the unused variables from a long running COBOL Program.

All sort of Mainframes Interview Questions.
Post Reply
ravindra singh MF
New Member
Posts: 3
Joined: Mon Dec 15, 2014 2:42 pm

Identify and remove the unused variables from a long running COBOL Program.

Post by ravindra singh MF »

Hi,

Assume there is a long running program which was written long back. It has gone multiple revisions. It's a batch COBOL, DB2 program. According to an audit, it is advised to remove the all unwanted variables. How can we know the unwanted variables in the program?

I just don't know how to do this? Apart from working with program long and multiple times. Please help how can we do this?
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by William Collins »

Compile with compiler option OPT(FULL). If your compiler doesn't support that, look in your Programming Guide to see what to use instead.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by enrico-sorichetti »

removing unused variables will not make Your code run faster or better

it might be OK to remove standalone variables/fields/whatever definitions

removing variables/fields/whatever definitions that are part of a structure WILL misalign the rest
and cause all kind of errors
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by Robert Sample »

If you want to identify them, use the XREF compiler option. However, just removing them without considering where they are will, as pointed out already, cause potentially major problems with the program. Your first step should be to go back and find out why the auditors are concerned about unused variables.
ravindra singh MF
New Member
Posts: 3
Joined: Mon Dec 15, 2014 2:42 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by ravindra singh MF »

William Collins wrote:Compile with compiler option OPT(FULL). If your compiler doesn't support that, look in your Programming Guide to see what to use instead.
Thank you.

OPTIMIZE
The OPTIMIZE option is modified to allow more levels of performance optimization for your application. The previous OPTIMIZE option format is deprecated but is tolerated for compatibility.
Note: Although OPT(0) is equivalent to the NOOPTIMIZE option in previous compilers, it now removes some code that previously was not removed.
The storage optimization provided by the old FULL suboption of OPT is now provided by the new compiler option STGOPT.
In the above, "it now removes some code that previously was not removed", does it actually make changes in the program? And if this option is so helpful, why it is not used as default compiler option? Can you please help with these questions?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by nicc »

If you mean: "does it change the source member?" then the answer is 'no' - it simply does not process the 'unused' code beyond recognising it and reporting it. The compiler may, internally to itself, move code around if it deems it wise to do so - e,g, if a variable is set to a constant value inside a loop but is not otherwise referenced within that loop.

FULL optimise probably should not be use in your testing but should be used in production. If it isn't then you should ask your support why they have chosen the options that are being used/defaulted to.
Regards
Nic
ravindra singh MF
New Member
Posts: 3
Joined: Mon Dec 15, 2014 2:42 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by ravindra singh MF »

If you mean: "does it change the source member?" then the answer is 'no' - it simply does not process the 'unused' code beyond recognising it and reporting it. The compiler may, internally to itself, move code around if it deems it wise to do so - e,g, if a variable is set to a constant value inside a loop but is not otherwise referenced within that loop.
That's what I meant. Thanks for the explnation.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Identify and remove the unused variables from a long running COBOL Program.

Post by William Collins »

You have COBOL V5. The additional functionality provided by OPT(FULL) over OPT in V3/V4 is provided by a new option in V5 (see the last line of the quoted text). So now, in V5, OPT does not remove unused storage, the new option does.

What the quote is about is the identification and removal of generated code which can never be executed. NOOPT in V3/V4 would not do this. OPT(0) in V5 will be able to identify some.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”