• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Fooling Around With SQL And RPG

    April 15, 2024 Gregory Simmons

    Editor’s Note: This was originally scheduled to be published on April 1. No joke. And for a lot of complex reasons, that could not happen. But, it’s still fun, so enjoy.

    I started out one morning, purely interested in having a bit of fun. Honest. In RSS within ACS, I often like to run this SQL:

     select *
     from json_table(
          QSYS2.HTTP_GET('https://icanhazdadjoke.com/',
                  '{"header": "Accept,application/json", "sslTolerate":"true"}'),
                  'lax $' columns ("joke" varchar(200) CCSID 1208)
          )
    

    Okay, that was fun. This is harmless, good fun. But then I thought, what if I put this into a simple RPG program? Then I could call this anytime I wanted to and email all of my co-workers a dad joke! Now, because I don’t want to be accused of spreading mayhem to every RPG shop, I’m going to just write an entry to my joblog with the new enhancement to RPG in V7R4 TR6 or V7R5; the operation code snd-msg. Here is what I came up with:

    **Free
    Ctl-Opt Main(DAD_Joke_Generator);
    Ctl-Opt Debug Option(*SrcStmt:*NoDebugIO);
    Ctl-Opt ActGrp(*Caller);
    
    Dcl-Proc DAD_Joke_Generator;
    
    Dcl-Pi DAD_Joke_Generator;
    End-Pi;
    
    Dcl-s dad_joke VarChar(200);
    
    Exec SQL
      Select *
      Into :dad_joke
      From json_table(QSYS2.HTTP_GET('https://icanhazdadjoke.com/',
     '{"header": "Accept,application/json",                          "sslTolerate":"true"}'),
                      'lax $'
                      columns ("joke" varchar(200) CCSID 1208)
                     );
    
    snd-msg dad_joke;
    
    // Or if you're feeling devious, email all your coworkers a dad joke...
    
    Return;
    
    On-Exit;
    End-Proc DAD_Joke_Generator;
     
    

    As you can see, I’ve written a simple linear-main RPG program to run my previous SQL statement to retrieve a dad joke from https://icanhazdadjoke.com/ . Then I use the new snd-msg operation code to put an entry into my joblog. Running it yields this:

    Now, again, I am not condoning or suggesting that you do this, which is why I left out the emailing logic from my demo program. Perhaps you wanted to run this program and let’s say, just email yourself a joke every Monday morning, we can use the IBM i job scheduler. Adding an entry is simple with the ADDJOBSCDE command:

    ADDJOBSCDE JOB(APRILFOOLS)          
                               CMD(CALL PGM(APRILFOOLS))
                               FRQ(*WEEKLY)            
                               SCDDATE(*NONE)          
                               SCDDAY(*MON)            
                               SCDTIME('06:00:00')     
    

    In V7R2M0, the DB2 for i team gave us the SCHEDULED_JOB_INFO view, which gives us a nice way, for instance, have a look at all of the jobs that are scheduled to run on Monday mornings at 6:00:00 am!

    SELECT SCDJOBNAME,STATUS,SBMTIMSTMP,SCHEDULED_DATE_VALUE,
       		  SCHEDULED_TIME,SCHEDULED_DAYS, COMMAND_STRING
    FROM QSYS2.SCHEDULED_JOB_INFO
    Where STATUS = 'SCHEDULED' and
          	  SCHEDULED_DAYS = '*MON' and
          	  SCHEDULED_TIME = '06.00.00'
    ORDER BY SCDJOBNAME
    

    Other commands are available for working with your job scheduled entries:

    And if you did go the extra devious step and setup the DADJOKES program to email your co-workers, you’ll probably quickly want to remove the scheduled job entry with the RMVJOBSCDE command. For example:

    RMVJOBSCDE JOB(APRILFOOLS)
    

    I hope you find a chuckle in the SQL statement to retrieve a dad joke – for yourself. And I hope you find the snd-msg operation code useful as well as working with job scheduled entries.

    Until next time, happy coding.

    Gregory Simmons is a software engineer with PC Richard & Son. He started on the IBM i platform in 1994, graduated with a degree in Computer Information Systems in 1997 and has been working on the OS/400 and IBM i platform ever since. He has been a registered instructor with the IBM Academic Initiative since 2007, and holds a COMMON Application Developer certification. When he’s not trying to figure out how to speed up legacy programs, he enjoys speaking at technical conferences, running, backpacking, hunting, and fishing.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, ACS, DB2 for i, Four Hundred Guru, IBM i, RMVJOBSCDE, RPG, SQL, V7R4, V7R5

    Sponsored by
    Rocket Software

    Meet digital age demands while maximizing your IT investment.

    Future-proof your mission-critical applications with Rocket® Solutions for IBM® i that keep your business ahead of the curve.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    As I See It: With Deepfakes, Nothing Is Real Except The Consequences Securing The Crown Jewels When Intruders Break Into The Glass House

    2 thoughts on “Guru: Fooling Around With SQL And RPG”

    • Gil Dewey says:
      April 15, 2024 at 4:30 pm

      Thanks Gregory. We all too often forget to have some fun with this stuff from time to time. 🙂 I never knew this existed!

      Reply
    • Les Turner says:
      April 16, 2024 at 7:06 am

      Love it! Thanks Gregory!

      Reply

    Leave a Reply Cancel reply

TFH Volume: 34 Issue: 20

This Issue Sponsored By

  • ServiceExpress
  • Maxava
  • WorksRight Software
  • Software Engineering of America
  • New Generation Software

Table of Contents

  • Drilling Down Into New IBM i Perpetual And Subscription Pricing
  • Securing The Crown Jewels When Intruders Break Into The Glass House
  • Guru: Fooling Around With SQL And RPG
  • As I See It: With Deepfakes, Nothing Is Real Except The Consequences
  • IBM i PTF Guide, Volume 26, Number 15

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle