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
 

 

RExx code to find the unused variables in COBOL prog
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
babuprashad
Warnings : 1

New User


Joined: 09 Aug 2007
Posts: 15
Location: mysore

PostPosted: Fri Apr 08, 2011 3:27 pm    Post subject: RExx code to find the unused variables in COBOL prog
Reply with quote

Hi,

I am writing a small rexx code to find the list of unused variables in the prog. For this,
1. I have put the data division lines in a array and procedure division lines in another array.
2. extract the variable names from the data division array.
3. check for occurance of each variable in the procedure division array.

Here, I have a problem with the group variable names...Some times the group variable name are not used in the program instead they use the idividual element names....In these cases the group variable name pops up in the unused var list.......and some times if the group name is used and individual names are not used then the individual item names pop up as unused vars.....

Can any1 suggest a better idea to deal with this issue.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 08, 2011 4:33 pm    Post subject:
Reply with quote

use a syntax only compile with a xref.
the xref will tell you which data elements are not referenced.

In Rexx, there is no such thing as an array.
Rexx uses a convention called stems.

Also, you do not write small rexx codes REXX is a SCRIPT language. - you write scripts.
Use proper terminology, and you will find answers.

also, this is not a chat room. any1 is not standard english, do not use such abreviations in this forum, please.

the problem is that you need to keep track of what elements are in a group.
and since a group can contain a group, which also can contain a group
which would contain elements,
keeping track of the group to group to group to element relationship would be difficult.

i would load elements into a stem. then if found in the procedure division,
replace the element reference with spaces. then you would know
what elements were not referenced.

then you could go backwards with that knowledge and make decisions about groups.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Apr 08, 2011 6:14 pm    Post subject:
Reply with quote

You will also face the challenge that some data division items or even procedure division usage might be brought in by copy members or macro expansion, so unless you find a way to expand this, these references will not be covered.

I have actually written an edit macro in REXX that utilises commands in a Cobol-aware editor environment Smartedit, supplied by a 3rd party software vendor. It will highlight every unused definition in a module even if they where included from a copy or a macro expansion.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Fri Apr 08, 2011 10:06 pm    Post subject:
Reply with quote

And why dont you share that with us?
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Fri Apr 08, 2011 10:11 pm    Post subject:
Reply with quote

Can anyone tell me why it's so bad if there are actually any unused variables in a program?

There does not seem to be any point in removing them, and as far as PL/I is concerned, just specify *process rules(nounref) and the compiler will actually flag them.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 641
Location: Whitby, ON, Canada

PostPosted: Fri Apr 08, 2011 10:43 pm    Post subject:
Reply with quote

If I recall correctly, the Cobol compile option OPTIMIZE(FULL) gets rid of unused variables from the object module.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Fri Apr 08, 2011 10:54 pm    Post subject:
Reply with quote

From the COBOL Programming Guide manual:
Quote:
The FULL suboption requests that, in addition to the optimizations performed with OPT(STD), the compiler discard unreferenced data items from the DATA DIVISION and suppress generation of code to initialize these data items to the values in their VALUE clauses. When OPT(FULL) is in effect, all unreferenced level-77 items and elementary level-01 items are discarded. In addition, level-01 group items are discarded if none of their subordinate items are referenced. The deleted items are shown in the listing. If the MAP option is in effect, a BL number of XXXXX in the data map information indicates that the data item was discarded.

Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Fri Apr 08, 2011 11:00 pm    Post subject:
Reply with quote

You will also have to consider redefines ... but as stated why bother and if you must let the compiler do the hard work
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 641
Location: Whitby, ON, Canada

PostPosted: Fri Apr 08, 2011 11:54 pm    Post subject:
Reply with quote

Robert Sample wrote:
From the COBOL Programming Guide manual:
Quote:
The FULL suboption requests that, in addition to the optimizations performed with OPT(STD), the compiler discard unreferenced data items from the DATA DIVISION and suppress generation of code to initialize these data items to the values in their VALUE clauses. When OPT(FULL) is in effect, all unreferenced level-77 items and elementary level-01 items are discarded. In addition, level-01 group items are discarded if none of their subordinate items are referenced. The deleted items are shown in the listing. If the MAP option is in effect, a BL number of XXXXX in the data map information indicates that the data item was discarded.

That greatly simplifies the problem. You'd just have to compile the program with MAP,OPT(FULL) and write a Rexx program to read the listing and pull out the names. If it were me, I would have the Rexx program generate a simple edit macro to delete the unreferenced items from the source code. You'd want to be careful about testing that, of course. icon_eek.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sat Apr 09, 2011 4:28 am    Post subject:
Reply with quote

Robert Sample wrote:
From the COBOL Programming Guide manual:
Quote:
The FULL suboption requests that, in addition to the optimizations performed with OPT(STD), the compiler discard unreferenced data items from the DATA DIVISION and suppress generation of code to initialize these data items to the values in their VALUE clauses. When OPT(FULL) is in effect, all unreferenced level-77 items and elementary level-01 items are discarded. In addition, level-01 group items are discarded if none of their subordinate items are referenced. The deleted items are shown in the listing. If the MAP option is in effect, a BL number of XXXXX in the data map information indicates that the data item was discarded.



Code:

01  GROUP-DATA-WITH-SUBORDINATE.
      05  SUBORDINATE-ITEM PIC X.
01  REDEFINES-GROUP REDEFINES GROUP-DATA-WITH-SUBORDINATE.
      05  REDEFINES-SUBORDINATE-ITEM PIC X.

In PROCEDURE DIVISION,
MOVE SPACE TO REDEFINES-SUBORDINATE-ITEM but no other references.



It would seem from the manual that with OPT(FULL) that GROUP-DATA-WITH-SUBORDINATE and SUBORDINATE-ITEM should be deleted by the compiler. Causing a compile error? If it did cause an error, that would turn off the optimising (according to the manual). Would you then see the XXXXX in the DMAP?

I suppose it depends if I'm reading it correctly (but can't see how not), or if it is a documentation error, or where the non-referenced data removal takes place (would the REDEFINEd group somehow occupy the space, or would it be looking at what is now (after removal of the group by the optimiser) storage belonging to someone else?).

I guess someone could try it if they felt inclined... and had access to a mainframe. I do feel inclined, but...

And, yes, I know such a construct is unlikely to deliberately exist.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Sat Apr 09, 2011 7:33 am    Post subject:
Reply with quote

Code:
       WORKING-STORAGE SECTION.
       77  NOT-REF-1                   PIC X(05) VALUE '25'.
       77  REF-1                       PIC 9(05).
       01  GROUP-DATA-WITH-SUBORDINATE.
             05  SUBORDINATE-ITEM PIC X.
       01  REDEFINES-GROUP REDEFINES GROUP-DATA-WITH-SUBORDINATE.
             05  REDEFINES-SUBORDINATE-ITEM PIC X.
       PROCEDURE DIVISION                  .
       PARA-1.
           DISPLAY 'REF-1 <' REF-1 '>'.
           MOVE SPACE TO REDEFINES-SUBORDINATE-ITEM

           STOP RUN.
produces compile map of
Code:
0Data Division Map
0Data Definition Attribute codes (rightmost column) have the following meanings:
     D = Object of OCCURS DEPENDING    G = GLOBAL                             S
     E = EXTERNAL                      O = Has OCCURS clause                  U
     F = Fixed-length file             OG= Group has own length definition    V
     FB= Fixed-length blocked file     R = REDEFINES                          VB
0Source   Hierarchy and                                    Base       Hex-Displa
 LineID   Data Name                                        Locator    Blk   Stru
      2  PROGRAM-ID MF0177------------------------------------------------------
     15   77 NOT-REF-1 . . . . . . . . . . . . . . . . . . BLW=XXXXX  000
     16   77 REF-1 . . . . . . . . . . . . . . . . . . . . BLW=00000  000
     17   1  GROUP-DATA-WITH-SUBORDINATE . . . . . . . . . BLW=00000  008
     18     2  SUBORDINATE-ITEM. . . . . . . . . . . . . . BLW=00000  008   0 00
     19   1  REDEFINES-GROUP . . . . . . . . . . . . . . . BLW=00000  008
     20     2  REDEFINES-SUBORDINATE-ITEM. . . . . . . . . BLW=00000  008   0 00
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1713
Location: UK

PostPosted: Sat Apr 09, 2011 10:12 am    Post subject:
Reply with quote

Quote:
It would seem from the manual that with OPT(FULL) that GROUP-DATA-WITH-SUBORDINATE and SUBORDINATE-ITEM should be deleted by the compiler.

Why? GROUP-DATA-WITH-SUBORDINATE is referenced by the following REDEFINES. The extract from the manual does not mention anything about being not referenced in the PROCEDURE division only.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sat Apr 09, 2011 1:51 pm    Post subject:
Reply with quote

Thanks very much for your time Robert, I appreciate it.


Nic Clouston wrote:
Why? GROUP-DATA-WITH-SUBORDINATE is referenced by the following REDEFINES. The extract from the manual does not mention anything about being not referenced in the PROCEDURE division only.


Quote:
all unreferenced level-77 items and elementary level-01 items are discarded (my emphasis added)


Nope, doesn't refer to my example. Mine is not elementary.


Quote:
level-01 group items are discarded if none of their subordinate items are referenced(my emphasis added)


Seems to refer to my example. A REDEFINES is not "subordinate" to an 01-level. I checked in the manual before posting. I also checked the full text for the OPTIMIZE. Nothing there either.

If I had thought the text only referred to PROCEDURE references, I would have used an example like this, wouldn't I?

Code:

01  GROUP-DATA-WITH-SUBORDINATE.
      05  SUBORDINATE-ITEM PIC X.
      05  FILLER REDEFINES SUBORDINATE-ITEM PIC X.


But then I didn't think that.

I tried to use fairly explicit data-names and thought that, along with the manual text quoted, it would be clear to people in this forum what I was getting at.

At least we see that the documentation error causes confusion.

I did make a mistake. I thought that the situation would not arise deliberately (knowiningly or otherwise). However, what if there is a COPYBOOK with an 01 defined in it. Then someone REDEFINES the 01 in the copybook, makes their own names but does not refer to anything in the copybook itself? Having said that, I'm not sure they'd worry about it not being documented in OPT(FULL).
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1713
Location: UK

PostPosted: Sat Apr 09, 2011 6:07 pm    Post subject:
Reply with quote

01 GROUP-DATA-WITH-SUBORDINATE.
05 SUBORDINATE-ITEM PIC X.
01 REDEFINES-GROUP REDEFINES GROUP-DATA-WITH-SUBORDINATE.

there is the reference - 2 lines down.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sat Apr 09, 2011 7:47 pm    Post subject:
Reply with quote

Nic, I accept that you don't get it.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Sat Apr 09, 2011 8:00 pm    Post subject:
Reply with quote

As to why one would care:

An analogous situation is the compiler's warning messages about dead code.

In investigating a dead code warning a few years back, I discovered a stray period at the end of a line of indented code following an ELSE. It seemed that since the several following lines were also indented, the last of which had a period, that the earlier period was wrong.

It of course ended the ELSE code, and the following (indented lines) were therefore always executed.

One of these set a variable to a constant value. This in turn caused the following IF to be always false, and the compiler could see that, therefore causing this IF's THEN code to be dead code.

So - warnings of this nature, and analogously unref'd variables, can point out problems in clean code.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sat Apr 09, 2011 8:23 pm    Post subject:
Reply with quote

Very good point Phrz... er, I'll call you Phil, if you don't mind

I've seen the same sort of thing. The instances I saw were "editor errors" as people were tossing blocks of code around with the editor. From a block of unconditional code, copy it to a condition, change the indentation, but, leave a period behind.

With the advent of Cobol II I very happily only coded the mandatory period. On a line of its own.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 641
Location: Whitby, ON, Canada

PostPosted: Sat Apr 09, 2011 8:28 pm    Post subject:
Reply with quote

Bill Woodger wrote:

.....

With the advent of Cobol II I very happily only coded the mandatory period. On a line of its own.
I second that! Using END-IF and minimizing period usage makes for much more maintainable code. In my opinion END-IF was the most important innovation made to Cobol in the 30 years I've been in this business.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sun Apr 10, 2011 4:28 am    Post subject:
Reply with quote

Hi Nic. Sorry if I seemed a bit short earlier, but there was no time. Looking at your profile, I see that there can easily be things that are "obvious" but aren't really so, I'm guessing you are enormously more familiar with PL/1 than with Cobol.

Here is the quote again from the manual.

Quote:

The FULL suboption requests that, in addition to the optimizations performed with OPT(STD), the compiler discard unreferenced data items from the DATA DIVISION and suppress generation of code to initialize these data items to the values in their VALUE clauses. When OPT(FULL) is in effect, all unreferenced level-77 items and elementary level-01 items are discarded. In addition, level-01 group items are discarded if none of their subordinate items are referenced. The deleted items are shown in the listing. If the MAP option is in effect, a BL number of XXXXX in the data
map information indicates that the data item was discarded.


Firstly "all unreferenced level-77 items and elementary level-01 items are discarded"

An "elementary level-01 item" is like this

Code:

01  ELEMENTARY-LEVEL-01-ITEM PIC X(50).


The is the whole of the 01-level. There is nothing else. It is "elementary" as opposed to "group".

Code:

01  GROUP-LEVEL-01.
      05  FILLER PIC X.


Here is a "group". A group consists of subordinate items, which may be groups of a higher level-number or elementary items of a higher level-number.

"In addition, level-01 group items are discarded if none of their subordinate items are referenced."

Here is my example again:

Code:

       01  GROUP-DATA-WITH-SUBORDINATE.
             05  SUBORDINATE-ITEM PIC X.
       01  REDEFINES-GROUP REDEFINES GROUP-DATA-WITH-SUBORDINATE.
             05  REDEFINES-SUBORDINATE-ITEM PIC X.


It is a level-01 group item, and none of its subordinate items are referenced. The only subordinate item is SUBORDINATE-ITEM. The REDEFINES is referencing the 01-level. Items in a redefines are not subordinate to items in the level being redefined (see, for instance, MOVE CORRESPONDING). According to the documentation, it should be deleted by OPT(FULL). However, the compiler treats it logically and does not delete it, ergo the documentation is wrong.

We even have a second situation. Remove the "MOVE..." to REDEFINES-SUBORDINATE-ITEM from Robert's program, so that now none of the storage area is referred to in the PROCEDURE. It is, however, still referred to in the DATA division (the REDEFINES). Does the compiler remove the storage or not, with OPT(FULL)? I say that you can't tell by reading the manual. My "best guess" is that it would be. But, ideally, I'm not reading manuals just so that I can "guess" afterwards.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1713
Location: UK

PostPosted: Sun Apr 10, 2011 4:58 pm    Post subject:
Reply with quote

Hi Bill,

No prob. I was debating with myself as to whether I should just drop out of the debate or review the whole caboodle before (not) taking further part. I do not know who won tht debate!

Yes I am P/1 but record structures are familiar as are redefines and I do have COBOL but I do not 'dream' it as I do PL/1 - sad or not??!!
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts PL/I code tuning/Performance improvement Virendra Shambharkar PL/I & Assembler 3 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
No new posts How to find the first monday of the w... abdulrafi COBOL Programming 10 Fri Nov 25, 2016 3:24 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm


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