Skip to main content

4GL's virtues (Part 2) Intergration with SQL

4GL makes code that would be difficult to write purely in SQL easy ,
plus it adds extra capabilities that would not be possible.

The following is a select loop that retrieves the result set
of a SQL query row by row and then manipulates it inside the loop.
Inside the loop you are free to use more SQL queries or 4GL code or mix them both!

For example, you can test conditions using if..then..else statements, assign values to host variables, load a tablefield or update tables in the database!

select   h_c_ylik = c_ylik,
         h_no_seir = no_seir,
         h_ps = ps,
         h_sxolia = sxolia
  from  mlax
  where end_axr='Ο'
  {
  if h_no_seir = '' then
     update mlax m
     set ps = ps + :h_ps
     where end_axr = ''  and
           no_seir = '' and
           c_ylik = :h_c_ylik;
     inquire_ingres (h_rowcount = rowcount,
                     h_errorno=errorno);
     if h_errorno!=0 then 
        rollback;
      callframe err_handler;
     endif;    
     if h_rowcount = 0 then
        insert into mlax
        (c_ylik,no_seir,end_axr,ps,sxolia)
        values
        (:h_c_ylik,'','',:h_ps,:h_sxolia);
        inquire_ingres (h_rowcount = rowcount,
                        h_errorno=errorno);
      if h_errorno!=0 then 
                   rollback;
           callframe err_handler;
               endif;
     endif;       
    else
       insert into mlaxr
       (c_ylik,no_seir,end_axr,ps,sxolia)
       values
       (:h_c_ylik,:h_no_seir,'',:h_ps,:h_sxolia);
       inquire_ingres (h_rowcount = rowcount,
                       h_errorno=errorno);
       if h_errorno!=0 then 
          rollback;
          callframe err_handler;
       endif;
    endif;
  };





There are many situations like this that make evident that 4GL is a rapid development tool

Comments

Popular posts from this blog

The Advent of SQL 2024 Has Commenced

  It's Advent - the time of year when we countdown the days to Christmas - and if your are a programmer complete daily coding challenges with the Advent of Code, the Advent of Perl, the Advent of Java, Javascriptmas, etc. Now we have the Advent of SQL too with 24 SQL challenges to complete before Christmas! https://www.i-programmer.info/news/204-challenges/17678-the-advent-of-sql-2024-has-commenced.html

Greenplum's Cloudberry Fork Enters Apache Incubator

  Cloudberry is the open source equivalent of Greenplum. Now it is fostered by the Apache Foundation as it acquires incubating status. It all began about six months ago. Greenplum's Github repositories was archived and went dark. This meant no more free new releases or security and bug fixes for its users. Why? Because in May 2024, Tanzu made the decision to close-source the project. https://www.i-programmer.info/news/84-database/17694-greenplums-cloudberry-fork-enters-apache-incubator-.html