Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SHARING] Code Validator (Things to check for)
Page 1 2 
Go
New
Search
Notify
Tools
Reply
  
[SHARING] Code Validator (Things to check for)
 Login/Join
 
Expert
posted
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post

  • Single line JOIN's that end with END.
  • Multiple -DEFAULT's for the same parameter (especially problematic when using -INCLUDE).
  • SQL blocks starting with a TAB character (often that just works, but then suddenly it doesn't - not sure what's going on there).
  • Indented DM code where the - (minus) is not at position 0 in the line.
  • Indented comments (similar to above, but asterisk can't be indented).


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 :
 
Posts: 1665 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Expert
posted Hide Post
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 
 
Posts: 5691 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Expert
posted Hide Post
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 **************************************************************************************************************
 
Posts: 3124 | Location: Tennessee, Nashville area | Registered: February 23, 2005Reply With QuoteReport This Post
Guru
posted Hide Post
False use of .EVAL
-?
?


Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
 
Posts: 450 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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 :
 
Posts: 1665 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Guru
posted Hide Post
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
 
Posts: 291 | Location: Greater Cincinnati  | Registered: May 11, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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...
 
Posts: 3124 | Location: Tennessee, Nashville area | Registered: February 23, 2005Reply With QuoteReport This Post
Guru
posted Hide Post
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
 
Posts: 291 | Location: Greater Cincinnati  | Registered: May 11, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 1973 | Location: Centennial, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
-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

 
Posts: 1976 | Location: Tel Aviv, Israel | Registered: March 23, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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 
 
Posts: 5691 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Guru
posted Hide Post
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.
 
Posts: 450 | Location: Europe | Registered: February 05, 2007Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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 :
 
Posts: 1665 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
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
 
Posts: 146 | Registered: November 09, 2015Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Expert
posted Hide Post
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!

 
Posts: 6309 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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
 
Posts: 2067 | Location: Customer Support | Registered: April 12, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
@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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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 
 
Posts: 5691 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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.
 
Posts: 1119 | Location: USA | Registered: January 27, 2015Reply With QuoteReport This Post
Expert
posted Hide Post
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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Reply With QuoteReport This Post
Expert
posted Hide Post
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 
 
Posts: 5691 | Location: United Kingdom | Registered: April 08, 2004Reply With QuoteReport This Post
Virtuoso
posted Hide Post
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.
 
Posts: 1119 | Location: USA | Registered: January 27, 2015Reply With QuoteReport This Post
  Powered by Social Strata Page 1 2  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SHARING] Code Validator (Things to check for)

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.