Posts

Showing posts with the label iseries

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

IBMi (AS400) fans only ' Modernizing RPG's indicator with INDARA (Indicator Area) keyword

Image
#IBMiSample INDARA (Indicator Area) keyword for ICF files workstn indds indicator data structure INDARA is used to put the field option indicators and function(response) key indicators in a separate area of memory called indicator area. By using this keyword, we can make indicator data structure in our program to give the customized name to indicators defined in the display file. Hence, it makes the program more readable and easy to understand. Step 1. indicate INDARA  keyword in your Display File Step 2. indicate INDDS in your RPG workstation file declaration dcl-f PKLTSFV workstn indds(Dspf) sfile(SFL1 : SF1NUM); Step 3. declare the  indicator area        dcl-ds Dspf qualified ;          Exit            ind pos(03) inz(*off);          SflClr          ind pos(50) inz(*off);          DspAtrRI        ind pos(61) inz(*off);          DspClrRed       ind pos(62) inz(*off);          SflEnd          ind pos(91) inz(*off);        end-ds ;     Step 4. In the RPG source program replace all the

IBMi (AS400) fans only ‘ Rpg Free: 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 (                    W3FANN CHARACTER(1) NOT NULL WITH DEFAULT,          W3TPMS CHARACTER(6) NOT NULL WITH DEFAULT,          W3COD0 NUMERIC(4, 0) NOT NULL WITH DEFAULT,         W3RIG0 NUMERIC(2, 0) NOT NULL WITH DEFAULT,         W3TXT0 CHARACTER(078) NOT NULL WITH DEFAULT         )                                                   RCDFMT W03AM                                       

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 check a date field ddmmyy

Image
#IBMiSample How to check the correctness of a numeric date field 6 with 0 decimals. This program receives as input 1. a date in the DDMMYY format ( p_data ), for example p_data= 100612, that is June 10, 2012, an Error field ( p_error ). 2. a Flag field accepts date = 0 ( p_zero ). 3. returns a BLANK or 'E' value in the p_error field as a result of the check. CHKDATA.RPGLE       **free        ctl-opt option(*nodebugio:*srcstmt:*nounref) dftactgrp(*no)         ALWNULL(*USRCTL) ;         // Try with  STRDBG and         // CALL CHKDATA PARM(X'0120718F' 'x' 'N') valid date         // CALL CHKDATA PARM(X'0999999F' 'x' 'N') wrong date         // CALL CHKDATA PARM(X'0000000F' 'x' 'Y') no date, but it is allowed         // CALL CHKDATA PARM(X'0000000F' 'x' 'N') no date, it is not allowed         dcl-pi CHKDATA;           p_data packed(6);           p_error char(1);           p_zero  char(1);

IBMi (AS400) fans only ' Rpg Free Program Sample: How to manage a table through a program with two or more video formats

Image
#IBMiSample Typically we have a table and we need to perform read, write, update operations. This simple program is an example of how. First of all look at  this post  and compile and populate these files to use this example.

IBMi (AS400) fans only ' Minimalist Subfile with filter fields

Image
#IBMiSample First of all look at this post and compile and populate these files to use this example. Then compile the two following soures, OT08SF displayfile, OT08SF sqlrpg file. OT08SFV.DSPF                                             CHGINPDFT(CS UL HI)                                             INDARA                                             CA03(03 'F3=EXIT')                                             REF(OTORD00F)       *--------------------------------------------------------------                 R SFL1                      SFL       *--------------------------------------------------------------                   S1OPT          1A  B  6  2                   S1ANN0    R             +3REFFLD(OTANN0)                   S1COR0    R            + 1REFFLD(OTCOR0) EDTCDE(Z)                   S1NOM0    R            + 1REFFLD(CLANA/CLNOM0 CLANA00F)       *--------------------------------------------------------------                 R FMT01                     SFLCTL(SFL1)

IBMi (AS400) fans only ' How to write to the same printerfile from more programs

Image
#IBMiSample A simple way is to leave the file open by ending programs with RETURN instead of SETON LR. Example: Program A calls Program B. Program B opens a printerfile and write some pages in the spool file. Program B closes with RETURN. The printer file is already open. Program A calls Program B again. Program B opens a printerfile (it is already open) and write some other pages on the same spool file. Program B closes with RETURN. The printer file is already open. Program A calls Program B again. Program B opens a printerfile (it is already open) and write some other pages on the same spool file. Program B closes with RETURN. The printer file is already open. ... and so on. At the end, run RCLACTGRP ACTGRP(QILE). This command will end the QILE activation group, it means the spool file will also be closed. I appreciate all the comments made on this blog.

IBMi (AS400) fans only Table with self-incrementing primary key and current time field

Image
#IBMiSample How to get a primary key field that increments itself and a time field that updates itself? Look at  LGID00 and  LGDTTM fields. Create a table: CREATE TABLE LGCUS00F ( LGID00 INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, LGDTTM TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, LGNAME CHAR(50), LGSURN CHAR(50)) RCDFMT LGCUS Now try to add a record: INSERT INTO LGCUS00F (LGNAME, LGSURN) VALUES ('Aldo', 'Succi') Let's see the result: SELECT * FROM LGCUS00F As you can see, LGID00=1 and LGDTTM=2018-04-01-10.01.49.781922 That's it! I appreciate all the comments made on this blog.

IBMi (AS400) fans only how does it works "ADD VERSIONING" and "USE HISTORY TABLE" to take trace of every changes on a table. This looks like magic!

Image
#IBMiSample This looks like magic! The operating system, in a totally automatic way, keeps track of every change in the data. This simple technique allows you to find the value of a field on a certain date and time. use STRSQL Step 1) CREATE TABLE CUSTOMER (CUSTOMER_ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH +1 INCREMENT BY +1 ) ,CUSTOMER_NAME VARCHAR(10) ,ADDRESS VARCHAR(20)) Step 2) alter table customer add system_start timestamp(12) generated always as row begin not null add system_end timestamp(12) generated always as row end not null add tx_start timestamp(12) generated always as transaction start id implicitly hidden add period system_time (system_start, system_end) Step 3) create table customer_h like customer Step 4) alter table customer add versioning use history table customer_h Step 5) Now use command line: CRTJRNRCV JRNRCV(VDOTEST1/JRNRCVNAME) THRESHOLD(150) TEXT('Journal receiver') Step 6) CRTJRN JRN(VDOTEST1/jrnname) JRNRCV(VDOTEST1/jrnrcv

IBMi (AS400) fans only - RPG Free. Minimalist program with a single video format

Image
  #IBMiSample Remember that you need my CLANA00F file to compile the following program. So, f irst of all look at this post and compile and populate these files to use this example. A01ARPCL.CLP              PGM                                                              DCL        VAR(&PPCCL0) TYPE(*DEC)   LEN(7 0)                    DCL        VAR(&PPEXIT) TYPE(*CHAR)  LEN(1)                      DCL        VAR(&OUTPU1) TYPE(*CHAR)  LEN(1)                      DCL        VAR(&OUTPU7) TYPE(*CHAR)  LEN(7)                      DCL        VAR(&OUTPU8) TYPE(*CHAR)  LEN(8)                      CALL       PGM(A01ARP) PARM(&PPEXIT &PPCCL0)                     CHGVAR     VAR(&OUTPU1) VALUE(&PPEXIT)                           CHGVAR     VAR(&OUTPU7) VALUE(&PPCCL0)                           CHGVAR     VAR(&OUTPU8) VALUE(&OUTPU1 *CAT &OUTPU7)              SNDPGMMSG  MSG(&OUTPU8)                                          ENDPGM