Focal Point
[SHARING] Code Validator (Things to check for)

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9417041986

January 28, 2018, 08:55 PM
Waz
[SHARING] Code Validator (Things to check for)
Hi All,

I've been working on a code validator for our release process to try to force coding to standards we have.

The Validator will check for things like:
Missing DM Labels
Duplicate DM Labels
Missing Semocolons on -SET's
-EXIT
-QUIT
&ECHO to ON or ALL
-TYPE
SQL Tracing
READ/RECORDLIMITs

Does anyone have any other ideas on commands that could cause issues and therefore be checked and highlighted ?

This message has been edited. Last edited by: FP Mod Chuck,


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 29, 2018, 05:31 AM
Wep5622



WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
January 29, 2018, 09:36 AM
Tony A
quote:
Indented comments (similar to above, but asterisk can't be indented).

Shouldn't be an issue?

 COMPUTE SOMETHING/A1 = 'X'; -* this comment is syntactically correct from version 8.something


@ Waz,

I'm waiting for Francis to suggest "anything written outside of the GUI" Wink Razzer

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
January 29, 2018, 09:42 AM
Doug
1) Ensure that all "Test" and "Extraneous" code has been removed.

2) I like to add a -TYPE statement in my flower boxes at the start and end of all fexes for easy fex identification when debugging, such as the following:
-TYPE **************************************************************************************************************
-TYPE *** IBFS:/Dev/WFC/Repository/Vendor/KPIs/&FOCFEXNAME.EVAL.fex *** Start &TOD ***
. . . comments . . .
-TYPE **************************************************************************************************************

and,
-RUN
-SET &TOD=HHMMSS('A8') ;
-TYPE **************************************************************************************************************
-TYPE *** IBFS:/Dev/WFC/Repository/Vendor/KPIs/&FOCFEXNAME.EVAL.fex *** Ended &TOD ***
-TYPE **************************************************************************************************************

January 29, 2018, 10:59 AM
Frans
False use of .EVAL
-?
?


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
January 29, 2018, 11:32 AM
Wep5622
quote:
False use of .EVAL

Good One

Another one:
SET XRETRIEVAL = OFF


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
January 29, 2018, 12:59 PM
Don Garland
How about any line that has nothing but a dash -

This is a nasty little problem to find. It's like trying to find a needle in a hay stack! Eeker


WebFOCUS Administrator @ Worldpay FIS
PROD/DEV/TEST: 8204, SANDBOX: 8206 soon - BIP, Reportcaster, Resource Manager, EUM, HyperStage soon, DB: HIVE,Oracle,MSSQL
January 29, 2018, 01:03 PM
Doug
quote:
How about any line that has nothing but a dash -
I remember it well... Eeker But, we (how many of us did it take?) found it...
January 29, 2018, 02:55 PM
Don Garland
I remember trying to find out what the heck was going on for longer than I want to admit in public. Music


WebFOCUS Administrator @ Worldpay FIS
PROD/DEV/TEST: 8204, SANDBOX: 8206 soon - BIP, Reportcaster, Resource Manager, EUM, HyperStage soon, DB: HIVE,Oracle,MSSQL
January 29, 2018, 03:37 PM
Waz
quote:
I'm waiting for Francis to suggest "anything written outside of the GUI"



Ha ha, probably


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 29, 2018, 03:43 PM
Waz
As we are on 8.1.x, so some of the suggestions shouldn't be an issue (until experienced, I guess)

Already have XRETRIEVAL

Single line Joins with END, multiple -DEFAULTS, -? and just - are great suggestions.

Wondering how I would detect false use of .EVAL


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 29, 2018, 03:47 PM
Waz
quote:
I like to add a -TYPE statement in my flower boxes at the start



Doug, something I've implemented here is to -DEFAULTH &Type to *, then pass &Type=TYPE to turn on TYPE statements.

e.g.

-&Type.EVAL Message

This way, the TYPE statements can be turned on in production when needed, but by default are hidden away.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 29, 2018, 04:20 PM
Tom Flynn
Double semi-colons at the end of DEFINEs: ;;
SET commands with a semi-colon

David,
LOL!!! You forgot Chocolate!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
January 29, 2018, 04:34 PM
Waz
Great idea, thanks


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 30, 2018, 02:06 AM
Danny-SRL
-GOTO label ending with a ;

BTW, is your code validator written in FOCUS?


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

January 30, 2018, 03:09 AM
Tony A
quote:
Double semi-colons at the end of DEFINEs: ;;

.. and not just defines, computes as well.

Saw that at a few upgrades from early 7 to 7.7.03 but not seen it since - probably because all the occurences were found upgrading to 7.7.03 and that version objected!


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
January 30, 2018, 04:27 AM
Frans
quote:
Originally posted by Waz:
Wondering how I would detect false use of .EVAL


I think one case is when it's surrounded by quotes ('&ABC.EVAL' instead of &ABC.QUOTEDSTRING)


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
January 30, 2018, 07:26 AM
Wep5622
I think .EVAL in a DM -SET is almost always wrong. An assignment to a -DEFAULT expression not so much though.

Within FOCUS code it depends a lot on the value of the .EVAL'ed parameter. If it contains '-*' or '', for example, that's a valid usage.

Your example substituting -TYPE or -* using .EVAL is another case that's valid.

I do see things like these from time to time:
ON TABLE HOLD AS &HOLDFILE.EVAL
-INCLUDE &FEX.EVAL


But valid is (in fact, that's a common workaround for "&FEX not found" warnings here):
-SET &FEX = '-INCLUDE fex.fex';
&FEX.EVAL


I think the very nature of .EVAL makes it hard, if not impossible, to detect invalid or valid usage. I think it's okay to issue a warning whenever you encounter .EVAL though.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
January 30, 2018, 03:18 PM
Waz
quote:
is your code validator written in FOCUS?



Of course, what else would I write it in. Big Grin


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 30, 2018, 03:25 PM
Waz
quote:
I think the very nature of .EVAL makes it hard, if not impossible



Agreed, but it is something that I may look at.

There is a lot of code here that will use .EVAL when it isn't needed, like in FOCUS code, but for a PGM to check it will be tough.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 30, 2018, 04:59 PM
jcannavo
quote:
quote:
Indented comments (similar to above, but asterisk can't be indented).

Shouldn't be an issue?

COMPUTE SOMETHING/A1 = 'X'; -* this comment is syntactically correct from version 8.something


I'm fairly certain this indeed needs to be something to be aware of. One of our team members is in the process of cleaning things up for upgrade to 8.2.02 and one of the objectives he's required to do is ensure all comments are left aligned in the code. We were told by IBI any comments not left aligned or placed in the first two character spaces may cause problems.


JC
WebFOCUS Dev Studio / App Studio
8.2.01
Windows 7
January 30, 2018, 05:12 PM
Waz
I guess there is two ways to look at this.

1. Follow the documentation
2. What works in your version and what doesn't.

It would always be safer to side on the documentation.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

January 30, 2018, 05:28 PM
Waz
OK, so in 8.1.04

This is what happens with the code below.

Run from the repository:
Leading spaces are removed, so the indented comments work.
The comment on the end of the -SET works
Comments on the end of FOCUS code (DEFINE field) fails.

Run from the reporting server:
Leading spaces are NOT removed, so the indented comments 3 to 6 fail.
The comment on the end of the -SET works
Comments on the end of FOCUS code (DEFINE field) fails.


-SET &ECHO=ALL;

-* correct syntax 1
 -* correct syntax 2
  -* correct syntax 3
   -* correct syntax 4
    -* correct syntax 5
     -* correct syntax 6

-SET &Set = 'Test' ; -* Set Command

DEFINE FILE SYSTABLE
 Name/A100V = Name ; -* DefField
END


I think this points to the reporting server as the place to determine what works and what doesn't.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

February 08, 2018, 02:56 PM
FP Mod Chuck
Everyone

This is a great thread.. I am just commenting to keep it near the top for additional comments.


Thank you for using Focal Point!

Chuck Wolff - Focal Point Moderator
WebFOCUS 7x and 8x, Windows, Linux All output Formats
February 14, 2018, 11:40 AM
Francis Mariani
@Tony, @Waz - I'm not sure a cynic's comments are welcome here Smiler


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
February 14, 2018, 12:07 PM
Tony A
Francis, Cynic? no, very often a voice of reason - however it's put over! Wink They'll miss us when we retire!

@Waz, not sure if you have this stye of coding, but have you considered looking for use of &VAR.. in lieu of &VAR.EVAL?

An old colleague used this frequently (as did I at one stage Razzer) and I came across some of his code recently.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 14, 2018, 12:25 PM
CoolGuy
Pretty cool thread, all.

I recently created a .NET Core 2.0 console app written in C# I called SearchReplace. It takes any file directory and searches through it to locate specific strings in whichever file types you desire (prompts for a pattern), and then replaces them with whatever you want. This was the beginning of what Waz is looking to do (just not in FOCUS...lol), but I've only used it to search CM packages for strings where a specific server was mentioned explicitly within our code somewhere (SQLOUT statements, etc.), and replacing those with a new server name. Then I CM the whole thing back into the environment (UPDATE/REPLACE) and things just work. LOL

There's not much code either:

/* 
    SearchReplace is a utility app I created to give users the ability to search any directory on their PC
    and all that directory's subdirectories for anything they are searching for within the files found therein.

    The program will ask the user for the root directory to search in, which files to search in, and which strings
    to use to search for and replace with.

    Author:  Anthony Cool
    Created: 10/26/2017
*/

using System;
using System.IO;

namespace SearchReplace
{
    class Program
    {
        static void Main(string[] args)
        {
            // C:\pathToSearchDirectory\..

            string rootDirectory = "";

            // Welcome and ask user what folder to search in:
            Console.WriteLine("\nWelcome to SearchReplace.\n\n"
                            + "What's the full path to the directory to search in?\n");
            // Store response:
            try {
                rootDirectory = @Console.ReadLine();
                // If user fails to give a directory/folder, set to something to exit app smoothly:
                if(rootDirectory == null || rootDirectory == "") {
                    rootDirectory = "YOU DID NOT GIVE A DIRECTORY TO SEARCH WITHIN";
                }
                // Set directory given to current directory to check if valid:
                Directory.SetCurrentDirectory(rootDirectory);
            }
            catch (DirectoryNotFoundException dirEx) {
                    // Let the user know that the directory did not exist:
                    Console.WriteLine("The directory does not exist. Details: " + dirEx.Message);
                    Environment.Exit(0);
            }

            // Ask user what file pattern to restrict the search to:
            Console.WriteLine("\nWhen we search your directory, which file names & types would you like to search in?\n"
                            + "This is specified by giving a pattern.  * means 0 or more chars, while ? means 0 or 1 chars.\n"
                            + "Example:  *.* = all names & types, *.fex = all fex files regardless of names, etc.\n");
            // Store response:
            string searchPattern = @Console.ReadLine();

            // Ask user which string to search for:
            Console.WriteLine("\nWhat string should be searched for and replaced?\n");
            // Store response:
            string searchString = @Console.ReadLine();

            // Ask user what string should replace the search string:
            Console.WriteLine("\nWhat string should replace the string we're searching for?\n");
            // Store response:
            string replacementString = @Console.ReadLine();

            // Gather all the files in the root directory and its subdirectories and store them to be looped through:
            var files = Directory.EnumerateFiles(rootDirectory, searchPattern, SearchOption.AllDirectories);
            // Loop through every file found above:
            foreach (string file in files) {
                try {
                    // If the file contains the string to be replaced:
                    if(File.ReadAllText(file).Contains(searchString) == true){
                        // Read the text from the file and store it:
                        string contents = File.ReadAllText(file);
                        // Replace search string with replacement string (using .NET Core 2.0+ overload):
                        contents = contents.Replace(searchString, replacementString, StringComparison.OrdinalIgnoreCase);
                        // Make file writable if it isn't already:
                        File.SetAttributes(file, FileAttributes.Normal);
                        // Overwrite the file with the changes made:
                        File.WriteAllText(file, contents);
                    }
                    else {
                        // Skip the file and move to the next file:
                        continue;
                    }
                }
                catch (Exception ex) { 
                    Console.WriteLine("Sorry. The following error has occurred:\n\n" + ex.Message);
                }
            }
            // State that the text replacements have been made:
            Console.WriteLine("\nThank you for your patience.\n\n"
                             + "\"" + searchString + "\"" + " has been fully replaced with " + "\"" + replacementString + "\".");
            // Pause the program before exiting so the end user can read the above message beforehand:
            Console.ReadLine();
        }
    }
}


Have fun!! (feel free to use it)

This message has been edited. Last edited by: CoolGuy,


8.2.02M (production), 8.2.02M (test), Windows 10, all outputs.
February 14, 2018, 01:28 PM
Francis Mariani
CoolGuy has a first name.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
February 14, 2018, 01:37 PM
Tony A
quote:
CoolGuy has a first name.

.. and a damn fine one at that Wink

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
February 14, 2018, 01:38 PM
CoolGuy
lol You would point that out, Francis. Yeah, the cat's out of the bag for some, but then others (from Summit) already knew. Wink

UPDATE: Agreed, Anthony! haha


8.2.02M (production), 8.2.02M (test), Windows 10, all outputs.