Posts

Showing posts with the label ibm

(IBM i fans only) Retrieving Files Used in Queries of an IBM i Library

Image
A colleague of mine left me a real treasure trove of queries, accumulated over many years of work. It’s an endless list: over 1000 queries, all well cataloged and described. Recently, I needed to find a query related to customer orders. Knowing that the order file is called OTORD, the customer file CLCLI, and the sample file CMCMP, I started opening the most likely queries. The process was long and frustrating: Open Query > Specify file selections > View the files used > Close Query. Stressful, right?   So, I thought I’d let our trusty IBM i do some work for me. I created a procedure to retrieve the list of files used by all the queries in a specific library, with the ability to add some filters to answer more specific questions. For example:   Which queries use the files OTORD00F, CLCLI00F, and CMCMP00F?   The result? A clean and well-organized subfile: Don't forget to set the screen to 132 columns! The source code follows: FQRCL    ...

(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); ...

(IBM i fans only) How to Sniff User Access

Image
If you need to monitor user access on your IBM i system, you can use SQL to query the history log. Note: At the end of this post, you'll find a request directly addressed to you, the readers. Here’s a simple example of how you can do this: SELECT MESSAGE_ID,        MESSAGE_TIMESTAMP,        FROM_USER,        MESSAGE_TEXT     FROM TABLE (             QSYS2.HISTORY_LOG_INFO()         )     WHERE message_id IN ('CPF1164', 'CPF1124')           AND FROM_USER IN ('QSECOFR', 'QSYS', 'QSYSOPR')     ORDER BY MESSAGE_TIMESTAMP In this query: - QSYS2.HISTORY_LOG_INFO(): This function retrieves information from the history log. -  message_id IN ('CPF1164', 'CPF1124') : Filters the results to include only specific message IDs, which indicate sign-on and sign-off events. - FROM_USER in ('QSECOFR', 'QSYS', 'QSYSOPR'): Filters the resu...

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 ‘ Another way to manage spooled files

Image
New feature:  F18=Search string into listed files WSF utility, works like WRKSPLF but... New feature: Searching a string into  spooled files New feature: Generate a PDF from a spooled file #IBMiSample Each IBMi user knows they run the most efficient system. All others just have too much money. Users often have many spool-file rows. How to  quickly   find the last done? how to quickly find the one produced on October 15th? These and other options are just a click away. The WRKSPLF command does not show spool-file rows sorted by Creation-Date/Creation-Time, so the last one is not the first one in the list. I thought a different way of looking at spooled-file rows might be useful. In this program (WSF) the spool-file rows appears in order of Creation-Date/Creation-Time, with the last one at the top of the list. I also added the ability to filter each column, for example to see only the rows in HOLD status. I also added the possibility to sort each column ...

IBMi (AS400) fans only - How to call a C runtime function from RPG program.

Image
#IBMiSample Each IBMi user knows they run the most efficient system. All others just have too much money. This example comes from https://www.ibm.com/support/pages/coding-rpg-iv-beginners-tutorial This example calls the C runtime printf() function to print a message to the standard output instead of to the external message queue.

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