Skip to main content

How to Create Functions in Progress 4GL (OpenEdge ABL) with Examples

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

Popular posts from this blog

Guía Completa de Oficinas Tributarias y Tax ID por País

Gestionar los impuestos puede ser un proceso complejo, especialmente cuando se trata de cumplir con las normativas internacionales. Cada país tiene sus propias reglas fiscales, oficinas tributarias y formas de identificación fiscal, conocidas comúnmente como Tax ID o NIF (Número de Identificación Fiscal). Esta guía está diseñada para simplificar esa tarea, proporcionando una lista de oficinas tributarias y los tipos de Tax ID que utilizan en distintos países. Con esta herramienta, podrás mantenerte al día con las obligaciones tributarias internacionales y asegurarte de cumplir con las normativas específicas de cada país de manera eficiente. Les comparto el listado también en una hoja de cálculo Listado países Si les interesa que agreguemos alguno más dejen sus comentarios.

Qad browse maintenance

En esta ocasión les quiero platicar acerca de un reporte nuevo en QAD, que son los Browse o Vistas. In new version of QAD we have new time of reports they name are Browse or View. Para crear un browse, necesitamos acceso a la opción Browse Maintenance o Mantenimiento de Vista To modify or create a new browse we need access to option Browse Maintenance Los pasos para crear un nuevo reporte /The steps to create a new browse are: Agregar tablas en esta parte debes agregar todas las tablas que requieras utilizar  Add tables like the entity diagram  Enlazar las tablas por los campos indice solo seleccionando el campo de una tabla y arrastrando el mouse. Made the relation with the index fields pick a filed in the table and drag to the field in the other table. Agregar los campos que quieres mostrar en el reporte en la parte de abajo. I n the button of the screen add fields that you need in your report  Guarda los cambios y ...

Error QADFIN-59938

Problema / Problem:  Al momento de Guardar una Factura proveedor que tienen Matching con recibos de almacén y no marca el siguiente error QADFIN-59938 dira que el recibo ya esta registrado en otra factura. We got the error QADFIN-59938 when we try to save a Supplier Invoice in the Matching process. Versión / Version :  QAD EE 2013, 2014,2016 Solución / Solve Primero validar que no este en matching en ninguna otra factura de proveedor. Dos se debe validar cuantos decimales tienen la cantidad recibida a hacer matching y comparar contra la cantidad de decimales que maneja la entidad, esto lo validan en la Vista Entidad 36.1.1.2.3 Este error ocurre normalmente cuando recibimos parcialidades y tenemos factores de conversión muy pequeños o recibimos con muchos decimales en la opción 5.13.1 First we have to review if the receivers are not matching in other supplier invoice, Then look how many decimals have our receivers and how many decimals have our ent...