Posts

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

(IBM i fans only) Detecting and Handling Non-Printable Characters in DB2 SQL Using LOCATE() and REPLACE() Functions

Image
When working with DB2 SQL on the IBMi platform, one of the challenges we might encounter is dealing with non-printable characters in our data. These are characters that don't have a direct representation on a standard keyboard and can cause display programs to crash if not handled properly. For this example, we'll be working with the CLANA00F file, which contains customer data. You can find details on how to create this file on my blog post here . Non-printable characters can sneak into our records for various reasons, and to prevent issues, we can run an SQL query that uses the LOCATE() function. This function returns the position of the first occurrence of a substring within a string, allowing us to detect these problematic characters. Suppose we have a customer name with a non-printable character, specifically the EBCDIC '0D' character, which corresponds to the "Carriage Return" (CR) control character in ASCII. To find this character in our records, we can ...

(IBM i fans only) Efficient WRKSPLF with WSF - How to Search string into spooled files, Sort, and Generate PDFs on IBMi

Image
Searching Spooled Files Made Easy: A Unique Solution Managing spooled files efficiently is crucial for users dealing with numerous rows of print data. IBM's WRKSPLF command provides a standard way to interact with spooled files, but it lacks certain features that can significantly enhance user experience. In this article, we'll delve into a powerful functionality that IBM doesn't offer — the ability to search among spooled file lists. Our goal is to highlight the advantages of this capability and introduce a practical solution. The Limitations of Standard WRKSPLF While the WRKSPLF command is a handy tool for working with spooled files, it falls short in certain aspects. One prominent limitation is the inability to search efficiently through the list of spooled file rows. Users often find it challenging to quickly locate specific files based on criteria like creation date, status, or content. Introducing a Unique Solution: WSF (WorkSpooledFiles) To address the limitations of...

(IBM i fans only) Extracting Data from DB2 to Excel with ODBC

Image
Configuring ODBC is the first crucial step to enable data transmission between your PC and the IBMi server (AS400). In my example, I am using the Windows 10 operating system and want to extract data from the public IBMi server PUB400.COM. However, make sure to configure ODBC to point to your specific IBMi environment. ODBC Configuration on Windows: 1. Open "ODBC Data Sources" in either 32-bit or 64-bit (in my case, 64-bit). 2. Select "iSeries Access ODBC Driver" and click "Add". **Data Source:** Specify the data source name. 3. Fill in the nine configuration tabs: - **Server:** Indicate the address of your IBMi server.     -  **Libraries:** List the libraries containing the files you want to access. 4. Once the tabs are filled, click "Apply" and "OK". Extracting Data to Excel: 1. Open Excel. 2. Go to "Data" and then "Get Data". 3. Select "From Other Sources" and choose "From Microsoft Query". 3b. ...