• 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
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    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

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

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