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

    November 8, 2002 Timothy Prickett Morgan

    Dear Readers:

    Here, by popular demand, are more “Odds and Ends.” I hope you find something here you like.

    — Ted

    Question:

    I’m trying to read a table by key in a CL program, and I am having trouble. I know there has to be a way to do this, but I keep getting either the first record in the table or an error message that states ‘key not found.’ Can you provide an example of a CL program that reads a file randomly by key?

    Answer:

    It sounds as if the Receive File (RCVF) command didn’t find a matching key. I suggest you use *KEYAE instead of *KEY on the Override with Database (OVRDBF) command. Then after you RCVF, use an IF to make sure you got the record you wanted. I have seen some weird stuff happen when using *KEY:

    In the following example, the program attempts to read a record whose key value matches the value in &PCAT. When a record is read, its key field, &CATEG, is compared to &PCAT to see if the proper record was found.

    PGM        PARM(&PCAT) 
    
    DCL        VAR(&PCAT) TYPE(*CHAR) LEN(2) 
    DCLF       FILE(CATEGORIES) 
    
    OVRDBF     FILE(CATEGORIES) POSITION(*KEYAE 1 *N &PCAT)
    RCVF 
    MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF))
    
    IF         COND(&CATCODE *EQ &PCAT) THEN(DO)
    /* a matching key was found -- do whatever */
    ENDDO
    

    Question:

    Work with User Profiles (WRKUSRPRF) command will not load a list of user profile names into a database file. Is there some other way to do this?

    Answer:

    Use the Display Object Description (DSPOBJD) command. I think a lot of us forget this command exists, since so many object-specific commands have *OUTFILE capabilities:

    DSPOBJD OBJ(*ALL) +
       OBJTYPE(*USRPRF) +
       OUTPUT(*OUTFILE) +
       OUTFILE(QTEMP/X)
    

    Question:

    I am entering two 130-byte note fields on a screen and then using them as parameters on a Submit Job (SBMJOB) command. The system throws away the trailing blanks and appends the following fields to them. Do you know why this happens and how to fix this problem?

    Answer:

    The problem is that you are using a variable that is longer than 32 bytes as a parameter to a CALL command in the CMD parameter of the SBMJOB command. The system discards the trailing blanks. There are several ways to solve this problem, but the easiest one is to pass one extra non-blank byte. In your case, pass two 131-byte values and make sure the last byte of each one in not blank. Here’s an example:

    dcl   &msg     *char 130
    dcl   &msgparm *char 131
    
    chgvar &msgparm (&msg *cat 'X')
    
    sbmjob cmd(call somepgm (&msgparm))
    

    The called program will define the parameters as 130 bytes, as always, not 131 bytes.

    Question:

    I am trying to get this API to work, and I can’t get the receiver variable to work correctly. I know there is a trick to using API’s, but can’t remember it.

    d  InputData      ds
    d   BytesRet                     4b 0
    d   BytesAvail                   4b 0
    d   Outque                      10
     * .... some source code omitted 
    c                   call      'QSPROUTQ'
    c                   parm                    InputData
    c                   parm                    RecieverLength
    c                   parm                    FormatName
    c                   parm                    OutQueueName
    c                   parm                    ErrorCode
    

    Answer:

    This is a common mistake with APIs. The BytesRet, BytesAvail, and other binary variables are supposed to be four-byte integers. You have coded them as four-digit integers, which is not the same. This will solve your problem:

    d   BytesRet                     4i 0
    d   BytesAvail                   4i 0
    

    Question:

    We have a junior programmer who messed up an RPG Source member without using our change management system. He then tried to correct his own mistake and only proceeded to make things worse.

     

    My question is, can I restore a specified member from tape from the QRPGSRC file?  I know how to restore the whole library, but I really only need one member from the QRPGSRC File.

    Answer:

    Restore Object (RSTOBJ) command allows you to restore individual file members. You’ll need to use the FILEMBR parameter.

    RSTOBJ OBJ(QRPGSRC) +
       SAVLIB(saved-lib) +
       DEV(TAP01) + 
       OBJTYPE(*FILE) + 
       FILEMBR((QRPGSRC (member-name))) +
       RSTLIB(another-lib)
    

    I recommend you restore to another library, and then copy the restored member to the production library.

    — Ted

    Sponsored By
    ADVANCED SYSTEMS CONCEPTS

    Business Analytics
    – Practical –
    – Cost Effective –
    – Easy to Deploy –

    SEQUEL FYI

    User Quote:
    “I love SEQUEL FYI because it lets me look at the data any way I need to see it, instantly. This is the easiest tool to manage complex product relationships that I have ever seen.”

    SEQUEL FYI offers outstanding OLAP business intelligence functionality for a fraction of the cost of comparable solutions.

    Read More > View Streaming Video

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 86 -- November 8, 2002

    Sponsored by
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Watch Now

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Use the Full-Screen Debugger with OPM Programs Reader Feedback and Insights: Modernizing RPG II Programs

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 86

This Issue Sponsored By

    Table of Contents

    • Reader Feedback and Insights: Overlooking the Obvious
    • Odds and Ends
    • Omitting Parameters in RPG Programs and Modules

    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