• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • CL Odds and Ends

    October 11, 2006 Hey, Ted

    I hope this question is not too simple for a newsletter that claims to be for gurus. An RPG program or module retains variables, open data paths, and other resources from one invocation to the next, as long as the LR indicator is not on. CL programs and modules, on the other hand, suffer from Alzheimer’s disease. They don’t remember anything from one invocation to the next. How do you handle this limitation?

    –Richard

    I can help you with part of this problem, Richard. Create a temporary data area to hold the variable values from one call to the next. In the following example, the program saves the values of two variables–&DecVar and &CharVar.

    pgm                                                          
                                                                 
       dcl   &SaveVars      *char     16                         
       dcl   &DecVar        *dec       3                         
       dcl   &CharVar       *char     12                         
                                                                 
       dcl   &MsgKey        *char      4                         
       dcl   &PgmName       *char     10                         
       dcl   &RtnType       *char      2                         
       dcl   &Sender        *char     80                         
                                                                 
    /* Determine the name of this program. */                    
                                                                 
       sndpgmmsg   msg('Dummy message') topgmq(*same) +          
                        msgtype(*info) keyvar(&msgkey)           
       rcvmsg      pgmq(*same) msgtype(*info) msgkey(&MsgKey) +  
                     rmv(*yes) sender(&Sender)                   
       chgvar      var(&PgmName) value(%sst(&Sender 27 10))      
                                                                 
       rtvdtaara (qtemp/&PgmName (1 16)) rtnvar(&SaveVars)       
       monmsg cpf1015 exec(do)                                   
          crtdtaara qtemp/&PgmName type(*char) len(16)           
       enddo
    
    /* Restore the value of the variables from the previous invocation */ 
       chgvar   &DecVar     %sst(&SaveVars  1  4)                         
       chgvar   &CharVar    %sst(&SaveVars  5 12)                         
                                                                          
    /* Do whatever */                                                     
    
    /* Save the value of the variables for the next invocation */         
       chgvar   %sst(&SaveVars  1  4)   &DecVar                           
       chgvar   %sst(&SaveVars  5 12)   &CharVar                          
       chgdtaara (qtemp/&PgmName ( 1 16)) value(&SaveVars)                
                                                                          
    endpgm
    

    When storing decimal numbers, allow an extra byte for the sign, and if there are decimal positions, allow another byte for the decimal point.

    Can you see a potential problem with this technique? If the data area already exists, from a previous run, say, then you will start off with old data. The caller needs to check for the existence of the data area of the data area and delete it before the first call to the CL routine.

    As for open data paths, locked data areas, or whatever, I don’t know a way to help you, but I’ve never found any of those things to be show-stoppers.

    And as for simple questions, be aware that readers of this publication come in all ranges of experience level. Don’t forget about the IT Jungle Forums, which you can find at https://www.itjungle.com/itjforums/. You’ll find some helpful and knowledgeable people there.

    I was recently working on a CL program that someone else had written, and came across a line that looked something like this:

    CALL SOMEPGM PARM(RESET)
    

    Why is there no ampersand on the beginning of RESET?

    –Sarah

    RESET is not a variable, but a character literal. If you had written the routine, you would have coded the command this way:

    CALL SOMEPGM PARM('RESET')
    

    You could also have coded it like this:

    CALL SOMEPGM PARM(reset)
    

    Character literals do not have to be quoted if:

    • they have no blanks and
    • the value is to be passed to the caller with uppercase letters

    In all three cases, the value RESET, in all uppercase letters, would have been passed to program SOMEPGM.

    Here another oddity you may not know. CL ignores everything after the ENDPGM command. Put anything down there you like: free-form comments without delimiters, code that you intend to put in later, code that you’ve removed but aren’t ready to throw away, etc.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    ASNA:  Monarch is a better way to modernize your RPG applications
    Bytware:  StandGuard Network Security 3.0, the next generation of System i security
    COMMON:  Join us at the Spring 2007 conference, April 29 – May 3, in Anaheim, California

    COMMON Picks Dufault as New President IBM Uncloaks Power6 Chip Details

    Leave a Reply Cancel reply

Volume 6, Number 37 -- October 11, 2006
THIS ISSUE SPONSORED BY:

Advanced Systems Concepts
WorksRight Software
Guild Companies

Table of Contents

  • CL Odds and Ends
  • Use SQL to Remove Extra Spaces
  • Admin Alert: The Ins and Outs of Loading Licensed Program Products

Content archive

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

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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