21
Sat, Dec
3 New Articles

TechTip: User-Defined SEU Line Commands

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
I know it's not terribly popular these days to be advocating the use of SEU, but regardless of the benefits of using other IDEs, a large number of us (myself included) are still using SEU. Let's face it, AS/400 developers, for the most part, are a very conservative group. We don't typically get too excited about the latest "bleeding edge" technology. We are more the type to look at it and say to ourselves, "I know three other ways to do that, and I've been using them for the last nn years." On the other hand, we do like it when we can get more from the tools we are already familiar with. But I digress. What we are talking about here is using SEU and extending the functionality that IBM has provided us by using user-defined line commands.

At first glance, adding line commands may not seem useful. But think about how often you need to do any of the following when you are editing a program: print just a selected block of code, change the code from uppercase to lowercase, actually copy in /COPY code because you can't remember the field names, clear out the first five columns of the source lines, clear out the comment area of C specs, etc. All of these things can be done with user-defined line commands.

IBM's documentation of how to create these user-defined line commands is fairly detailed and easy to follow. You can find the PDF version of the SEU documentation at the IBM iSeries Information Web site. I have included here a simple exit program that will process line commands to change the text from uppercase to lowercase (LC or LCC) or lowercase to uppercase (UC or UCC). This is a handy tool for when you are converting from "old" RPG to "new" RPG (I have given up trying to determine if it's RPG III, RPG IV, or RPG ILE, but I'm sure you get the idea).

The program I have included at the end of this tip is based on a C program that was written by one of my cohorts, Philip Read. The C version is longer and more tedious because string handling is not as easy in C as it is in RPG.

The parameters passed to the exit program by SEU are pointers to a user space in QTEMP called QSUSPC. The first parameter points to the beginning of the user space and the header information. The second points to the return/output information section of the user space. The last points to the beginning of the source code lines. For specific information about fields in the user space, check out the SEU documentation.

The first pointer is really the only pointer you need because all the other fields and source code lines can be accessed by using offsets from this pointer. The offset to the return/output information is not necessary because it lies just after the header information. That being the case, I have included the return/output data in the data structure defined for the header. The offset to the source code lines is calculated using the pointer to the first source code line that is passed from SEU. From that first line (which can also be calculated as an offset from the header pointer), you can calculate the pointer to all the other source lines by using the length of the source records (hdRecLen) and the length of the source code header information as shown in the pseudo-code below:

Pointer to rec. = pointer to 1st rec. + ((source rec. length + source header length)*(source rec.# - 1))

Once you get the hang of stepping through the user space using pointers, the rest of the program is very simple.

There are some oddities to watch out for or at least be aware of. First, SEU will load into the user space all source lines--from the first "unidentified line command" to the last. This means that if you are using LC on line 1 and LC on line 18, then all the lines from 1 to 18 will be placed in the user space. Not a big deal because only the two lines that have the LC in the line command area should be updated (if you write your program correctly). But SEU does not recognize that the other lines have not been updated. So what you will see is that all the lines between 1 and 18 will have their SEU sequence number and last update date updated (say that three times fast). This can be a problem if you use the last updated date for change tracking.

Also, even when you use a line command on only a single line, SEU will load the user space with that line and the next line. So you will always have at least two lines of source code in the user space. This can be a problem when you are setting the number of lines to be output (hdRecsOut). My first inclination was to simply "Z-ADD" the number of lines input to the number of lines output. This was not a good, idea but you should try it just to see the results. Unless you are adding lines to your source member, then the output lines should be the number of input lines minus one.

Adding lines to your source code is a little tricky. You add the lines to the user space again using offsets. Don't forget to include the source line "header" information for each added line. If you are adding many lines, you may need to extend the user space (use the QUSCUSAT API). You will also need to track how many lines you are adding and adjust the number of lines to output accordingly.

Once your program is written, you must let SEU know that it should use that program to process line commands. This can be done two ways. One way is to start editing a source member and use F13 to get to the Change Session Defaults display. From there, page down and enter your exit program name and library at the User Exit Program prompt. This will change your exit program for the current session and all future sessions. However, if you want to have the exit program available to everyone, you will need to use the other way--the Work with Registration Information (WRKREGINF) command. When the WRKREGINF display appears, scroll through the entries until you find the QIBM_QSU_LCMD exit point. Use option 8 to add, remove, or display user-defined line command programs.

I have found the user-defined line commands to be very useful, and they have saved me a lot of time. I mentioned several possible applications for line commands. If you have others or think of others, please share them on the forums. I'm always interested in better ways to do things.

Jeff Olen is a member of the AS/400 development team at Gauss Interprise, a content management software company located in Irvine, California. He can be reached by email at This email address is being protected from spambots. You need JavaScript enabled to view it..


       *----------------------------------------------------------------------
      *  SEULNCMDS - Program to process user-defined SEU line commands
      *------------------------------------------------------------------------
      *  Author: Jeff Olen
      *  Written: Feb. 21, 2003
      *------------------------------------------------------------------------
      *  Currently supported line commands:
      *  LC - "L"ower"c"ase command will change all characters on selected line
      *         to lowercase.
      *  UC - "U"pper"c"ase command will change all characters on selected line
      *         to uppercase.
      *------------------------------------------------------------------------

      * Variable definitions

      * pointers to user space
     d pHeader         s               *
     d pHeader2        s               *
     d pRtn            s               *
     d pLine1          s               *
     d pLine           s               *
     d pData           s               *

      * data structures for accessing user space
      * line command header info
     d dsHeader        ds                  based(pHeader2)
     d  hdRecLen               1      4b 0
     d  hdCsrRrn               5      8b 0
     d  hdCsrCol               9     12b 0
     d  hdNbrRecs             17     20b 0
     d  hdFuncKey             61     61a
     d  hdMode                62     62a
     d  hdSplit               63     63a
     d  hdRtnCd               65     65a
     d  hdRecsOut             69     72b 0
     d  hdSeqUpd              73     79a

      * source code header info
     d srcHdr          ds                  Based(pLine)
     d  srcCmd                 1      7a
     d  srcRtnCd               8      8a
     d  srcSeq                 9     14a
     d  srcChgDt              15     20a

      * actual souce code
     d srcDta          ds                  Based(pData)
     d  srcCode                1    999a


      * Lowercase and uppercase strings
     d lo              c                   const('abcdefghijklmnopqrstuvwxyz')
     d up              c                   const('ABCDEFGHIJKLMNOPQRSTUVWXYZ')

      * comparison flags
     d Yes             c                   const('Y')
     d No              c                   const('N')

      * work fields
     d rec#            s             10i 0
     d wkCode          s            999a
     d hldCmd          s              3a
     d lastRec         s              1    inz('N')

      *------------------------------------------------------------------------
      *-  Mainline
      *------------------------------------------------------------------------
     c     *entry        plist
     c                   parm                    pHeader
     c                   parm                    pRtn
     c                   parm                    pLine1

     c                   eval      pHeader2 = pHeader

      *  if F7 or F8 then do nothing
     c                   if        hdFuncKey = '7' or
     c                             hdFuncKey = '8'
     c                   eval      *inlr = *on
     c                   return
     c                   endif

      * otherwise process all records in workspace
     c                   do        hdNbrRecs     rec#
     c                   eval      pLine = pLine1 + ((hdRecLen + %len(srchdr))
     c                             * (rec# - 1))
     c                   eval      pData = pLine + %len(srcHdr)

      * save multi-line command when it is encountered
     c                   if        hldCmd = *blanks

     c                   select

     c                   when      srcCmd = 'UCC'
     c                   eval      hldCmd = 'UCC'

     c                   when      srcCmd = 'LCC'
     c                   eval      hldCmd = 'LCC'

     c                   endsl

     c                   else
      * if this is the second occurrence of the multi-line command then this is 
      *   the last line to apply the multi-line command to.
     c                   if        hldCmd = srcCmd
     c                   eval      lastRec = Yes
     c                   endif

     c                   endif

      * check which command is being used
     c                   select
      * uppercase - UC
     c                   when      srcCmd = 'UC'
     c                             or hldCmd = 'UCC'
     c                   eval      wkCode = %subst(srcCode:1:hdRecLen)
     c     lo:up         xlate     wkCode        wkCode
     c                   eval      %subst(srcCode:1:hdRecLen) =
     c                             %subst(wkCode:1:hdRecLen)
     c                   eval      srcRtnCd = '0'
     c                   eval      srcCmd = *blanks

      * lowercase - LC
     c                   when      srcCmd = 'LC'
     c                             or hldCmd = 'LCC'
     c                   eval      wkCode = %subst(srcCode:1:hdRecLen)
     c     up:lo         xlate     wkCode        wkCode
     c                   eval      %subst(srcCode:1:hdRecLen) =
     c                             %subst(wkCode:1:hdRecLen)
     c                   eval      srcRtnCd = '0'
     c                   eval      srcCmd = *blanks

     c                   endsl

      * clear multi-line command after encountering second line command
     c                   if        lastRec = Yes
     c                   eval      hldCmd = *blanks
     c                   endif

     c                   enddo

     c                   eval      hdRecsOut = hdNbrRecs - 1
     c                   eval      hdRtnCd = '2'

     c                   eval      *inlr = *on
     c                   return





BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: