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

QAD cloud version

Since 2019 QAD launched the ERP cloud version, this version has many different names, Channel island Cloud version Adaptive ERP QAD Adaptive UX The last one is the official name QAD Adaptive ERP. In the last release in September 2022 , almost all modules are in this version, I can said the main transactions are migrated. I have experience using this ERP , I think has many good thinks ,let me mentioned some of those, Approval process flow using different criteria and define multiple approvers Business Components more easy to made customization  Import/Export tools (no more CIM) Some video trainings Budget load is more easy You could attach image to the records and use to show like a picture For fixed asset exist a very easy way to load all the asset, more reports The metrics now are dinamyc dashboard,easy to build using a browse There is an APP to connect using you mobile devices Other think that happen to QAD is they was absorbed by Thomas Bravo company  Thomas Bravo complete...