Posts

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

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

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

(IBM i 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/OUTFI...

IBMi (AS400) fans only ' How to copy a library to a Windows PC folder

Image
Step 1. On your IBMi create a Save File in any library (A Save File is a special type of file that is used to store a backup of data or objects). I use the MYSELF1 library in this example. CRTSAVF FILE(MYSELF1/YourSavF) Step 2. Save Your library to Your Save File. SAVLIB LIB(LibraryToSave) DEV(*SAVF) SAVF(MYSELF1/YourSavF) Now go to your Windows Personal Computer 1. Open a command prompt window ( CMD ). 2. Type the following: CD C:\TEMP Press the Enter key. 3. FTP SYSTEMNAME or FTP xxx.xxx.xxx.xxx where SYSTEMNAME is the IBM i system name and xxx.xxx.xxx.xxx is the IP address. Press the Enter key. 4. Type the user ID and password. 5. To change to binary mode, type the following: BIN Press the Enter key. 6. To change the host and client to naming convention type 1, type the following: QUOTE SITE NAMEFMT 1 Press the Enter key. 7. Get the SAVF and put it into C:\TEMP GET /QSYS.LIB/MYSELF1.LIB/YOURSAVF.SAVF YourSavF.SAVF Press the Enter key. Now YourSavF.SAVF is in PC folder C:\TEMP

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 ' How to access multimember physical file using SQL alias

Image
#IBMiSample Each IBMi user knows they run the most efficient system. All others just have too much money. SQL does not have direct access to multiple-member physical files on IBM i. However, OS/400 provides a solution through the SQL `ALIAS` statement. By creating an alias for the specific member you want to access, you can work with that member using SQL. Example Using the IBM i PUB400 Public Server Let's walk through an example using the IBM i PUB400 public server. In this scenario, we have a physical file `QDDSLF` located in the library `VDOTEST1`, which contains multiple members: In library VDOTEST1, file QDDSLF I have 8 members. CLANA01L CLANA02L CLANA03L CLANA04L CLANA05L CLANA06L CNCON01L OTORD01L Suppose you want to access the member `CLANA03L` using SQL. To do this, follow these steps: 1. Create an Alias for the Member:         Open an SQL session using `STRSQL` and create an alias for the specific member:    CREATE ALIAS A_CLANA03L FOR VDOTES...

IBMi (AS400) fans only ' From Query to SQL with one command

Image
#IBMiSample Each IBMi user knows they run the most efficient system. All others just have too much money. In most of IBMi we have a large number of QUERIES. Often these QUERIES are provided to end users, with all limitations of this practice. I think this practice is deplorable. How about turning these queries into SQL and then writing an RPG with embedded SQL? The QUERY to SQL translation process is really simple, it only takes one command: RTVQMQRY QMQRY(MyQueryLib/MyQuery) SRCFILE(MyLib/MySrcFile) ALWQRYDFN(*YES) That's it! Below an example of a cursor declaration in an SQLRPGLE program (Sql embedded) // preapre the data recordset exec sql declare C1 cursor for select OTORD00F.OTANN0, OTORD00F.OTCOR0, CLANA00F.CLNOM0 from OTORD00F inner join CLANA00F on OTCCL0 = CLCCL0 where OTANN0 like :F1ANN0lke and OTCOR0 between :F1COR0str and :F1COR0end and CLNOM0 like :F1NOM0lke order by OTCOR0 for read only; Here is a complete SQLRPGLE sample program with SQL embedded . #IBMiSam...