If you want to build a procedure file of any size with a number of internal entries, whether internal procedures or functions, you can use the AppBuilder to create it for you. The AppBuilder generates most of the supporting statements you just read about here for user-defined functions, and provides a separate code section for each to make it easy to maintain your procedures.

To see how to define a function in the AppBuilder and what it does for you:

  1. Go into the Section Editor for the new h-OrderWin.w procedure.
  2. Select Functions from the Section drop-down list. This message appears:
  3. Answer Yes. The New Function dialog box appears:
  4. Enter the function name dateColor, specify INTEGER for the Returns value, and click OK.
  5. Enter this definition for the function:
    RETURNS INTEGER
    ( daFirst AS DATE, daSecond AS DATE ) :
    /*---------------------------------------------------------------------
    Purpose: Provides a standard warning color if one date
    is too far from another.
    Notes: The function returns a color code of:
    -- yellow if the dates differ at all
    -- purple if they are more than five days apart
    -- red if they are more than ten days apart
    ---------------------------------------------------------------------*/
    DEFINE VARIABLE iDifference AS INTEGER NO-UNDO.
    iDifference = daSecond - daFirst.
    RETURN IF iDifference = ? OR iDifference > 10 THEN 12 /* Red */
    ELSE IF iDifference > 5 THEN 13 /* Purple */
    ELSE IF iDifference > 0 THEN 14 /* Yellow */
    ELSE ?. /* Unknown value keeps the default background color. */
    END FUNCTION.

    The AppBuilder has generated the FUNCTION dateColor header syntax along with the RETURNS phrase, a placeholder RETURN statement and the END FUNCTION statement. You fill in the parameter definitions where the comment prompts you to do that. The function accepts two dates as INPUT parameters, calculates the difference between them (which is an integer value), and returns an integer value representing the appropriate background color for the second date. This is color code 12, 13, or 14, representing colors red, purple, and yellow, depending on how far apart the two dates are and whether either of them is undefined.

  6. Go into the main block and add a line of code to invoke the function and assign the BGCOLOR attribute for background color to the date field when the row is displayed:
    MAIN-BLOCK:
    DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
        ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
      RUN enable_UI.
      shipDate:BGCOLOR = dateColor(PromiseDate, ShipDate).
    ...
    END.
  7. Save h-OrderWin.w, then Run h-CustOrderWin6.w.

    There are only a few Orders where the ShipDate is later than the PromiseDate.

  8. To find a few, enter a New State of GA for Georgia.
    Note: If the New State button is no longer in your window, you can add it using step 10 of Extend the sample window to use the queries.
  9. Select Order number 10795 in the browse (for Customer 3010) and click the Order Detail button to run h-OrderWin.w. You see the field is displayed in red, as it should be:
  10. Select Order number 10940, which has no ShipDate at all, and click Order Detail:

    The ShipDate shows up in red here also because it has the Unknown value (?).

    Think about the code you just wrote. You defined an implementation for a function called dateColor, which goes to the bottom of the h-OrderWin.w procedure file, along with any internal procedures. Then you added a line to the main block that references the function.

    The main block is above the function in the procedure, but the AVM did not complain that there was no declaration for the function—because the AppBuilder generated it for you.

  11. Go into the Compile > Code Preview window for h-OrderWin.w and search for dateColor (use the CTRL+F sequence for Find).
You see the function prototype in one of the header sections that comes before the main block or any other executable code:
/* ************************  Function Prototypes ********************** */

FUNCTION dateColor RETURNS INTEGER
( daFirst AS DATE, daSecond AS DATE )  FORWARD.

Thus, the AppBuilder not only helps you generate the header for the function code itself, but it also generates a prototype for you and organizes all the code into sections where you can easily inspect and maintain individual entries.

The AppBuilder copies the parameter definitions from your function header just as you entered it in the Section Editor so you cannot remove them from the function header, even though in a hand-coded procedure file you could define them in the prototype and leave them out of the function header itself.