emptyblock

empty code block

Rule "emptyblock" searches for code blocks that do not have any code in them. For example, there may be a a repeat block where the import statement has been commented out.


REPEAT: 
/* 
  CREATE customer. 
  IMPORT customer. 
*/ 
END. 

Technically speaking, this rule belongs to an existing rule that checks for code that has no effect - but in this case, the warning message is more detailed, providing info on the type of a block that is empty.

Notes:

  • The program locates 'Code_block' node and checks that node's first
    child. If child node is not found, then there was nothing in the
    block.
  • The rule is really to flag 'empty' blocks, not meaningless blocks (
    i.e. blocks that don't do anything, like just define local variables).
  • There may be a false positive when utilizing a super/persistent procedure, and a function has an input or output parameter that sets or returns a private variable or a table:
    DEFINE TEMP-TABLE ttData NO-UNDO 
        FIELD dataLine AS CHAR. 
    
    FUNCTION fnGetData RETURNS LOGICAL (OUTPUT TABLE ttData): 
    /* In this case the function is not really empty */ 
    END FUNCTION. 
    
    FUNCTION fnSetData RETURNS LOGICAL (INPUT TABLE ttData): 
    /* Code block is not useless either */ 
    END FUNCTION. 
    
  • The rule should be enhanced to check for the input/output/input-
    output function parameters at some point and suppress a warning if the
    parameter refers to a global object (temp-tables are always global).
    Not sure what to do about buffer parameters ...
  • It also needs to be enhanced to read the contents of non-empty
    blocks that have only local variables defined and no other code at
    all.