In this tutorial, you will learn how to create functions in Progress 4GL (OpenEdge ABL), define input parameters, return values, and reuse business logic in QAD ERP Browse reports. This guide includes a complete real-world example and best practices for modular programming.
Progress OpenEdge ABL (formerly known as Progress 4GL) is primarily a structured programming language, but it also supports modular programming through the use of functions and procedures. Modular programming allows developers to organize code into reusable components, making applications easier to maintain, understand, and scale.
A simple way to understand modular programming is to compare it to a home theater system. The main controller represents the primary program, while the speakers, subwoofer, and audio devices represent functions, procedures, or subprograms. Each component has a specific responsibility and can be reused whenever needed.
This approach reduces duplicate code and makes enterprise applications easier to support over time.
Characteristics of Functions in Progress 4GL
- Functions must be defined before they are called or at the beginning of the program.
- The FUNCTION keyword is used to start a function and END FUNCTION marks its end.
- The return data type must be specified using the RETURNS clause.
- Functions may have input parameters defined using the INPUT keyword.
- The RETURN statement is used to send a value back to the calling program.
How to Create a Function in Progress 4GL
Let's look at a real-world example that retrieves the payment selection code used to pay a supplier invoice.
Progress OpenEdge Function Example
FUNCTION getpaydoc RETURNS CHAR (INPUT id_invoice LIKE Cinvoice.Cinvoice_Id):
DEF VAR vc-paysel AS CHAR NO-UNDO INITIAL "".
FOR FIRST Domains NO-LOCK WHERE
DomainCode = global_Domain,
FIRST Company OF Domains NO-LOCK,
FIRST CInvoice OF Company
WHERE CInvoice.CInvoice_ID = id_invoice NO-LOCK,
FIRST CDocumentInvoiceXref OF CInvoice NO-LOCK,
FIRST PaySelLine OF CDocumentInvoiceXref NO-LOCK,
FIRST PaySel OF PaySelLine NO-LOCK:
vc-paysel = PaySelCode.
END.
RETURN vc-paysel.
END FUNCTION.
Code Explanation
- getpaydoc is the name of the function.
- RETURNS CHAR specifies that the function returns a character value.
- INPUT id_invoice LIKE Cinvoice.Cinvoice_Id defines the input parameter.
- DEF VAR vc-paysel AS CHAR NO-UNDO INITIAL "" creates the variable used to store the result.
- The query retrieves the payment selection code associated with the invoice.
- RETURN vc-paysel returns the result to the calling program.
How to Use Functions in QAD Browse Reports
QAD ERP includes a reporting feature called Browse. Browses allow users to quickly build reports based on the entity relationship model by selecting tables and columns without developing a complete Progress program.
In addition to standard database fields, Browse reports support local variables and calculated fields. This means custom Progress functions can be embedded directly into the Browse definition.
To use the function in a Browse report, create a calculated field and place the function call in the Expression section as shown below.
By using functions, developers can reuse the same business logic across multiple programs, reports, and Browse definitions without rewriting code.
As your Progress OpenEdge projects grow, creating reusable function libraries can significantly reduce development time and improve maintainability.
Benefits of Functions in Progress OpenEdge ABL
- Improve code reusability.
- Reduce duplicate code.
- Simplify maintenance.
- Make applications easier to understand.
- Support modular programming practices.
Related Progress OpenEdge Tutorials
If you found this tutorial useful, feel free to share it with other Progress OpenEdge and QAD developers.
Comments
Post a Comment