Posts

Showing posts with the label DB2

(IBM i fans only) Each IBMi User Knows They Run the Most Efficient System. All Others Just Have Too Much Money

Image
Each IBMi User Knows They Run the Most Efficient System. All Others Just Have Too Much Money. Let's take a moment to ponder this thought-provoking and slightly provocative motto: Each IBMi user knows they run the most efficient system. All others just have too much money. I can't take credit for this line—I read it somewhere a while ago, and unfortunately, I don’t know who the original author is. Nonetheless, it's a statement that resonates with many of us in the IBM i community.  But is this motto still relevant today? With advancements in technology and the rise of various competing platforms, some might argue that the landscape has changed. Others might say that IBM i remains unparalleled in terms of reliability, efficiency, and total cost of ownership. So, why not take a 5-minute break, grab a coffee, and let's discuss this! Why IBM i Users Swear by It IBM i has long been known for its rock-solid stability, security, and seamless integration capabilities. Many busin...

(IBM i fans only) Discover the power of the %SPLIT BIF in RPG

In RPG, we often need to manage strings, split them into substrings, and manipulate them efficiently. The %SPLIT BIF is a powerful and useful tool to handle this task.   But what exactly is %SPLIT? 🤔   %SPLIT divides a string into multiple parts using a specified delimiter. It can return an array of values based on the delimiter you choose, making it easier to handle complex data or composite strings.   Here’s a practical code example to understand it better:     **FREE Dcl-s stringa    Varchar(100) Inz('apple,banana,orange'); Dcl-s array      Varchar(20) Dim(10); Dcl-s delimiter Varchar(1) Inz(','); Dcl-s i          Int(10); // Index for the loop // ***************************************************** // PGM start // ***************************************************** array = %Split(stringa : delimiter); *inlr = *on; For i = 1 to %Elem(array); ...

IBMi (AS400) fans only ' Journaling database physical files (tables)

Image
Journaling database physical files is a powerful, built-in OS feature. It allows you to audit data file changes. Tracks additions, updates, deletions of a physical file. Let's see how it works. Scenario: I have a phisical file (Tabel) called CLANA00F, I wont tracks additions, updates and deletions about CLANA00F. Step 1: CRTJRNRCV create a journal receiver in your library CRTJRNRCV JRNRCV(VDOTEST1/JRCV) THRESHOLD(1500000) TEXT('My Journal Receiver') Step 2: CRTJRN create a journal into the journal receiver CRTJRN JRN(VDOTEST1/JRNL) JRNRCV(VDOTEST1/JRCV) Here is the just created journal receiver and the journal.  Step 3: STRJRNPF start auditing STRJRNPF FILE(VDOTEST1/CLANA00F) JRN(VDOTEST1/JRNL) IMAGES(*BOTH) OMTJRNE(*OPNCLO) // the option OMTJRNE(*OPNCLO) omit open and close entries. // Open and close operations on the specified file members do not create open and close journal entries. It saves some storage space in the attached receivers.           ...

IBMi (AS400) fans only : how to read a flat file with sql embedded

Image
#IBMiSample It often happens that you have to read all the records of a file. Years ago I would have used the RPG cycle defining the Input/Primary file. Today, with the introduction of embedded SQL, I would do this: First of all I create a file, then I manually write some records. to create a file I write this SQL source: IPFLSQL.SQL -- --  RUNSQLSTM SRCFILE(myLib/MySouceFile) SRCMBR(IPFLSQL) -- --  Generazione tabella CREATE OR REPLACE TABLE myLib /IPFLI00F ( IIFANN CHARACTER(1) NOT NULL WITH DEFAULT, IITEXT CHARACTER(25) NOT NULL WITH DEFAULT ) RCDFMT IPFLI ;  Run IPFLSQL.SQL with RUNSQLSTM SRCFILE(myLib/MySouceFile) SRCMBR(IPFLSQL) to create the file IPFLI00F. Then populate IPFLI00F with some records. No matter what you type, just a few records are enough. Then compile and run  IPFL01.SQLRPGLE **free // ******************************************************* // *  How to read an entire file from the beginning    ...

IBMi (AS400) fans only : A simple way to create table with Rpg Free & SQL embedded

Image
#IBMiSample Compile and Run this SQLRPGLE to create table CLANA00F, index CLANA01L and table OTORD00F, and populate:       **free       *****************************       * create CLANA00F & OTORD00F       *****************************        ctl-opt option(*nodebugio) dftactgrp(*no) actgrp(*new);         // The EXEC SQL is never executed. It is used at compile time.         exec sql Set Option Commit = *None;         // Create File         exec sql           CREATE or REPLACE TABLE myLib/CLANA00F (           CLANN0 CHARACTER(01) NOT NULL WITH DEFAULT,           CLCCL0 NUMERIC(7, 0) GENERATED ALWAYS AS IDENTITY PRIMARY KEY,           CLCIB0 CHARACTER(03) NOT NULL WITH DEFAULT,           CLNOM0 CHARACTE...

IBMi (AS400) fans only : UTILITIES - How to retrieve physical file description

Image
                               

IBMi (AS400) fans only : Encrypting/Decrypting data with RpgFree & SQL embedded

Image
  #IBMiSample Compile and Run this SQLRPGLE. This is an explanation how to encrypt/decrypt data in a DB2 table using RpgFree & SQL embedded.       **free       ************************************************       * Encrypting/Decrypting data with SQL embedded *       * Encrypt/decript example with                 *       * ENCRYPT_AES                                  *       * ENCRYPT_RC2                                  *       * ENCRYPT_TDES                                 *       *                      ...

IBMi (AS400) fans only : Create a Window to display a very long program message

Image
#IBMiSample I'm tired of one-line messages. Too short. The average user needs clear and comprehensive messages. Then I need a large enough window to display a clear and complete message . Why not use a SUBFILE? A SUBFILE program can handle a list of many lines, a clear and complete message is just a list of many text lines! Here's how I did it I need a table that contains the messages.                           --                                                  --  RUNSQLSTM SRCFILE(VDOTEST1/QSOURCE) SRCMBR(W03AM00F) --                                                  CREATE TABLE VDOTEST1/W03AM00F (                  ...

IBMi (AS400) fans only : RUNSQLSTM Run SQL Scripts example

Image
#IBMiSample The Run SQL Statements (RUNSQLSTM) command processes a source file of Structure Query Language (SQL) statements. let's have an example: Create a source member AS52A00F into library VDOTEST1/QSQLSRC. VDOTEST1 is MyLibrary. Use your library name. AS52A00F.SQL

IBMi (AS400) fans only * How to import a CSV file into db2

Image
#IBMiSample Let's try with a very simple csv like this, called file1.csv: Code;Name 3741;Joe 3742;Barth 3810; 3945; First of all we need to save file1.csv into ISF . In my PUB400 (free AS400 at pub400.com) I have this directory: /home/PALDO I copy file1.csv to  /home/PALDO Use standard FTP transfer software (I use WinScp, I think Filezilla will work too) Let's take a look inside my directory I type WRKLNK and I verify the existence of File1.csv It looks as expected: To import this file I need a similar table on DB2. In my example it means that I will create a table with a decimal field and a charachter field . I create the table TEMPCSV (PALDO1 is my Library): CREATE TABLE PALDO1.TEMPCSV ( CLCCL0 DECIMAL(7, 0) DEFAULT 0 , CLNOM0 CHAR(50) DEFAULT ' ' ) RCDFMT FMTXX Here's my new table TEMPCSV : The table  TEMPCSV  is now created and it is empty: We can optionally set up a source file to note lines not imported by the CPYF...