Skip to main content

How to Use ACCUMULATE in Progress 4GL | SQL SUM Equivalent

Hello developer friends! This week I want to talk about the ACCUM function in Progress 4GL. This function works similarly to the SQL SUM function. Both functions are used to consolidate or calculate the total value of a field based on specific conditions.

For example, if you want to calculate the total invoiced sales amount by customer, the SQL statement would look like this:


SELECT SUM(ih_invoicetotal), ih_bill FROM ih_hist WHERE ih_domain = 'domain' AND YEAR(ih_inv_date) = 2019 GROUP BY ih_bill


Now, the same example written in Progress 4GL:



FOR EACH ih_hist WHERE ih_domain = 'domain' AND YEAR(ih_inv_date) = 2019 NO-LOCK BREAK BY ih_bill: ACCUMULATE ih_invoicetotal (TOTAL BY ih_bill). IF LAST-OF(ih_hist.ih_bill) THEN DISPLAY ACCUM TOTAL BY ih_bill ih_invoicetotal ih_bill. END.


As shown in the images, both approaches generate the same result. The Progress functions used in this example were:

  • ACCUMULATE: Allows us to continuously sum or accumulate the value of a field from our table.
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/accum-function.html

  • TOTAL BY: Indicates which field will be used to group or consolidate the totals. Besides TOTAL, you can also use AVERAGE, COUNT, MAXIMUM, and MINIMUM.
  • ACCUM TOTAL BY: Used to display the accumulated total on screen.
  • LAST-OF: Tells the query to stop once all records for a specific group have been processed. There is also a FIRST-OF option available.

  • BREAK BY: Instructs the query to group and process records based on a specific database field.

As a personal anecdote, when I first started learning Progress, I used to search for ways to translate SQL queries into Progress syntax. Doing that helped me understand the logic before actually coding the solution. Today, I think differently: the most important thing is understanding the logic independently of the programming language. That is how programming should work: first think about the algorithm, then translate it into code.

Don’t forget to share this article and follow us on Facebook .

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...