How efficiently (not by manually searching in actual code of a Cobol program) we can identify unused variables in the program which are defined in working storage section and not used anywhere in the procedure division? These variables are not part of any copybook.
The compiler (used to?) creates a listing of all data names and which line of the procedure division that they were referenced. I have used that list, comparing the unused data names against the actual data division listing to identify unused data names. Watch out for redefined names.....
I have one way to do it manually.It's not a efficient way to do it but
would work for you.Use find all commad for group level in descending order(eg first for 01 then 02 so on ) and accordingly remove the ws section entry if any item is not used by group name or individualy.