Use the AppBuilder to generate function definitions
- Last Updated: April 16, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
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:
- Go into the Section Editor for the new h-OrderWin.w procedure.
- Select Functions from the Section
drop-down list. This message appears:
- Answer Yes. The New Function dialog box
appears:
- Enter the function name dateColor, specify INTEGER for the Returns value, and click OK.
- 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 dateColorheader syntax along with theRETURNSphrase, a placeholderRETURNstatement and theEND FUNCTIONstatement. 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. - Go into the main block and add a line of code to invoke the function and assign the
BGCOLORattribute 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. - Save h-OrderWin.w, then Run
h-CustOrderWin6.w.
There are only a few Orders where the ShipDate is later than the PromiseDate.
- 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.
- 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:
- 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.
- Go into the window for h-OrderWin.w and search for
dateColor(use the CTRL+F sequence for Find).
|
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.