Posts

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

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". 4. S

IBMi (AS400) fans only ' SQLCODE values: Dear readers, unleash your suggestions!

Image
This RPG code uses a DOU loop to fetch data from a cursor named C1 until the SQLCODE is not equal to 0, indicating the end of the recordset. Inside the loop, it clears a data structure (RecordDsC1), fetches data into it, and then checks if the fetch was successful. If successful, it assigns values and writes to an output file. After the loop, it checks if the SQLCODE is not 100, indicating unexpected termination, and displays a warning message if needed. // Loop until SQLCODE is not equal to 0 dow sqlCode = 0 ;   // Clear the data structure RecordDsC1   clear RecordDsC1;   // Fetch data into RecordDsC1 using cursor C1   exec sql fetch C1 into :RecordDsC1;   // If fetch was successful (SQLCODE = 0)   if sqlcode = 0 ;     // Assign values and write to output     W1QUEU = rDsW1QUEU;     write W1SF1;   endif; enddo; // Check if SQLCODE is not 100 (indicating unexpected termination) if sqlCode <> 100;   // Build a warning message   wMsg='Warning: +    The selection has terminated

IBMi (AS400) fans only ' Program Status Data Structure (PSDS), %editc BIF (Built-In Function), and %subst BIF in RPG free.

Image
The program is indeed a simple and minimal example that demonstrates the usage of Program Status Data Structure (PSDS), %editc BIF (Built-In Function), and %subst BIF  (Built-In Function)  in RPG free.   Program Status Data Structure (PSDS) : The psds named Pgm is utilized to store system-related information like the current user and program time. The pgm.User and pgm.PgmTime fields are accessed within the program.   %editc BIF : The %editc BIF is used to convert the zoned decimal value P_PGMTIME into a character representation. This is commonly done when formatting numeric values for display.   %subst BIF : The %subst BIF is used to extract portions of the formatted time string P_PGMTIMEchar. It is used to create a time string in the format "HH:MM:SS" by extracting and concatenating substrings.   Overall, this program is a concise example that showcases the use of these RPG features for obtaining system-related information and manipulating data for display.

IBMi (AS400) fans only : DEBUGGING - How to use the STRSRVJOB and STRDBG commands on IBMi to debug a program in another user's session

Image
How to use the STRSRVJOB and STRDBG commands on IBMi to debug a program in another user's session. Programming also means, always, debugging. But when a program is installed in a production environment , and an end-user calls to report an issue, sometimes it's useful to connect directly to the user's session in DEBUG mode and step through the program itself. To do this, the STRSRVJOB command comes to our aid. First, let me give a brief summary of what a Service Job is and what the debugging activity on IBMi entails. Service job : In the context of IBMi (formerly known as AS/400 or iSeries) and RPG programming, a service job refers to a separate job that is started to perform specific tasks or services related to a program. These service jobs are often used for debugging, monitoring, or other specialized purposes. Debugging : One common use of service jobs is for debugging RPG programs. When you want to debug a program interactively, you typically start a service job to run

IBMi (AS400) fans only ‘ Memories (IBM Coding Forms)

Image
 IBM Coding Forms Oh mom! No, not my sweet, sweet natural mom, but IBM, the mother of us RPG programmers. The adventure with IBM began way back in 1992 when my friend said to me: "They need smart guys at a software house in Cesena!" And thanks to my dear friend, I ended up there, amidst the hills, good wine, Piadina Romagnola, and fresh pasta! It was December, and the company was an IBM partner. They asked me to take a course followed by an exam at IBM in Bologna. If I passed the test, they would hire me. Boom! Just 20 days later, there I was, at work! I started tinkering with the legendary IBM S/36 - today considered an informatics relic, but I swear, back then, it was a powerful machine! The first program I wrote, believe it or not, was on paper provided by the ancient scribes of IBM. Yes, I handwrote a program on paper. It felt more like a grandma's recipe than the result of my hard-earned studies! The "boss" said: "It looks decent, but load it onto the

IBMi (AS400) fans only ‘ Recursion in RPGfree

Image
To my friend. I want to dedicate this short post to a dear friend of mine, a developer who uses the C language and other modern programming tools, who repeatedly asked me: "Is the RPG language recursive?". Until some time ago I had to answer: "unfortunately not". I defended myself by explaining that the RPG language is a programming language primarily used for developing business applications for the IBM i and there is no need for advanced features. Bullshit! Actually the RPG language was not recursive, STOP! But now, finally and with great satisfaction, I can answer yes, it is! What does "Recursion" mean? Recursion is a programming technique or approach where a function or a subroutine calls itself directly or indirectly to solve a problem. It involves breaking down a complex problem into simpler subproblems that can be solved easily, and then using the same function to solve those subproblems repeatedly until the base case is reached. Recursion can be a

IBM i (AS400) fans only ' Realtime exchange rate for any pair of physical and digital currency reading JSON data from a webservice with RPG, SQL and HTTPGETCLOB function

Image
Realtime exchange rate for any pair of digital or physical currency using HTTP GET and JSON_TABLE reading with SQL HTTPGETCLOB. This CLP is intended to test the FREX00.SQLRPGLE utility.

IBM i (AS400) fans only ' How to read a TXT file in the IFS with SQL

Image
In this post, I'm going to show how you can easily read a TXT file in IFS using SQL. I create a file named divina.txt  and copy it to IFS. Here we can see the file divina.txt into IFS. I use ACS to show it. Here we can see the file divina.txt into IFS. I use WRKLNK to show it. Here we can see the file divina.txt into IFS. I use option  5=Display into  WRKLNK ( Work with Object Links ). I read it through SQL and write it to QTEMP/OUTFILE: Execute this SQL command: CREATE TABLE QTEMP.OUTFILE (RECORD) AS                                          (SELECT CAST(LINE AS CHAR(50)) FROM TABLE                           (QSYS2.IFS_READ('/home/VDOTEST/WSF/DIVINA.txt')))               WITH DATA To display the QTEMP/OUTFILE file, type from the command line: DSPPFM FILE(QTEMP/OUTFILE) That's it. I appreciate all the comments made on this blog.