Posts

Showing posts with the label sql

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 CHARACTER(50) NOT NULL WITH DEFAULT           )           RCDFMT CLANA           ;         // Create index         exec sql           CREATE INDEX myLib/CLANA01L ON myLib/CLANA00F (CLCCL0 ASC);         // Fill values         exec sql           INSERT INTO CLANA00F (CLCIB0, CLNOM0)          

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

Image
                               

AS/400 fans only ' Take it for fun - How to download data from a Web Service - Weather report from openweathermap.org

Weather report from openweathermap.org   first of all get your own API key on https://openweathermap.org/ , it's free. The Key looks like '35a545c6ce3bda8347f588353aa59fbd' Compile and run the program below to create the WBSWL00F table that will contain the weather data for a location, each row one location. WBSWL00F.SQLRPGLE       **free       *********************************       * create WBSWL00F Location list *       *********************************        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 table WBSWL00F             (                WWIDNM numeric (9, 0) generated always as identity,                WWORIN TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP,                WWORCR TIMESTAMP GENERATED ALWAYS FOR EACH ROW ON UPDATE                     AS ROW CHANGE TIMESTAMP NOT N

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                                 *       *                                              *       * DECRYPT_BIT                                  *       ************************************************        ctl-opt        option(*nodebugio) dftactgrp(*no) actgrp(*new);        dcl-s encryptionPassword VARCHAR(128);        dcl-s p0                     CHAR(10);        dcl-s p1                     CHAR(10);        dcl-s p2                     CHAR(10);        dcl-s p3                     CHAR(10);        // The EXEC SQL is never executed. It is