Debug AS400 program

Posted on 2004-11-23
Last Modified: 2008-02-01
I am using BPCS405CD on our AS400.
There is a program that often generate errors.
I don't know what language it use. My guess is RPG.
I just wonder whether there is any command that can see what the program does, what files are opened and how many steps; or use any command to generate a report or job log on those information.

Thanks a lot.
Question by:amphastar
    LVL 14

    Expert Comment

    There is not a lot you can do with-out the source.
    You can see what files and other objects are used by using the DSPPGMREF command

    To get the program info you can use the DSPPGM command.

    If the program fails you should get a joblog. It is just a case of starting from the bottom and reading back until you find out what has caused it.

    Are you getting a joblog?



    Author Comment

    No, I didn't get a joblog.
    In fact, the problem is that some records are locked. I don't why the program gave me that message. That is why I want to check how the program check the lock.
    LVL 9

    Accepted Solution

    When you say the program generates errors, is the program reporting the errors in a summary report or is the program falling over and displaying an error message which needs a reply.
    If you get an error message which needs a reply, display the job log before answering the error message and you should be able to identify the cause of the problem - if there is a locked record, there should be a message in the job log just before the error message identifying the record which is locked from which file and the user & job which has the record (you may need to look at the second level text to get all the info).

    RPG (and probably the other languages on AS400) by default lock a record when reading from a file opened for update (programmers can stop the record from locking if desired), if another program already has the record locked for update then an error is returned which can be caught by the program to avoid it falling over - it is common for programs not to handle locked records as on the AS400 there is usually a retry option on the record locked message, which does what is says - it retrys to read the record again then either continues happily or falls over again with the record still locked.

    I would suggest you look at the job log and identify the record locked, by which job and user, then attempt a retry, if it fails straight away on the same record and same user/job then get in touch with the user and ask them to finish what they are doing, then do another retry and the program should then continue.

    If this happens quite often, you may need to identify the trend and maybe schedule the job to a time when the users aren't so active or maybe stop the user from having a coffee break in the middle of an  update.
    LVL 6

    Expert Comment

    hi amphastar,

    As far as i can remember (I used BPCS around 6-7 years ago), in BPCS, the error of 'record locked' is caused by the record is flagged of being open (there's a flag field in the record).
    This may be because previous open was not closed properly like session being ended.
    If you're more specific (what transaction), i think your vendor will be able to help

    for TOM:
    I think you're BPCS user, right? please correct me if i'm wrong.
    LVL 26

    Assisted Solution


    Unfortunately in this case, no. I've worked in a large BPCS shop (starting around 7 years ago... hmmm...), but currently have no BPCS environment to review.

    However, the flag-field sounds familiar. There might be no "system lock" that can be seen with functions such as WRKOBJLCK, but BPCS might still report the record being in use because of a flag. This is one reason I try to avoid techniques that 'get around' system features -- for me, a "lock" means a specific thing. If an application uses the same word in a message but with a different meaning, it only confuses things.

    However, getting a joblog _shouldn't_ be a problem. AFAIK, all that needs to be done is change the job description for a BPCS batch job or run a CHGJOB command for an interactive BPCS job. The change to the jobd would be permanent until changed back later. A change to an interactive job might need to be done every time unless there's a BPCS setting that controls it.



    Assisted Solution

    Do you know what the program is *supposed* to do? In other words, do you have a specification for it, or could you write one? If so, then rewrite the program from scratch. This is often easier and more satisfactory than trying to debug crappy programs even when the source is available.

    The problem you face is that even if you could identify the bug(s) in your PGM object, without the source you cannot eliminate it/them.

    You give no clue as to the nature of the "errors" that this program throws up. It might not be the program at all but the data that is being fed to it. Although every program should check divisors for zero value before executing a division, few programs do. Check your data.

    It is possible to identify any bug by obtaining a hex core dump and translating the machine code at the address pointed to by the error trap. I have done this on an IBM mainframe but I do not know if IBM has published machine codes for the AS/400. However, even if it has, it is a long, laborious task that could take a lot longer than recreating the program as I suggested at top.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now