× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On Thu, 11 Dec 2003 CarollaT@xxxxxxxxxxxxxx wrote:
>
> Then I attended RPGWorld, and found that, with a simple keyword and a
> variable, I could overcome this 'CL handicap'.

That's true, the EXTFILE keyword does make this slightly simpler.  Though,
using QCMDEXC and doing a OVRDBF also works, if you need to do this in an
older release.

I saw the light on the "keep the overrides in the same program" scenario
when I was still an RPG/400 programmer in 1994 on V2R2.  It just makes for
cleaner code.

> Which works marvelously - when the file exists, and is not locked, etc.
> Inside my CL program, I could use the MONMSG command, and deal with those
> situations as they arose.  Is there a way to find out whether or not a
> command completed successfully, and catch the message if it doesn't complete
> successfully?

Sort-of.  Just keep in mind that, unlike CL, you can't monitor for only
some of the messages.  If you tell RPG that you're going to handle the
error, you need some plan for dealing with ALL errors, not just "object
not found" and "object in use."

Here's a sample of your code with message monitoring:

D                SDS
D  ErrMsgID              40     46A

D Command         S             80    INZ('CLRPFM DMART/ACCNEW')
D CmdLength       S             15  5 INZ(80)

c                   call(e)   'QCMDEXC'
c                   parm                    Command
c                   parm                    CmdLength

c                   select
c                   when      not %error
 **           command successful
c                   when      ErrMsgID = 'CPF3142'
 **           handle object not found here...
c                   when      ErrMsgID = 'CPF3156'
 **           handle object in use here...
c                   other
 **           Unhandled error -- End program abnormally.
c                   endsl



Now, let's take it one step further and use a prototype.  This way, we
don't need temporary variables for the "command" and "length" and the
compiler will do some extra validity checking and conversions for us:

D                SDS
D  ErrMsgID              40     46A

D QCMDEXC         PR                  ExtPgm('QCMDEXC')
D   command                   3000A   const options(*varsize)
D   length                      15P 5 const

c                   callp(e)  QCMDEXC('CLRPFM DMART/ACCNEW': 19)

c                   select
c                   when      not %error
 **           command successful
c                   when      ErrMsgID = 'CPF3142'
 **           handle object not found here...
c                   when      ErrMsgID = 'CPF3156'
 **           handle object in use here...
c                   other
 **           Unhandled error -- End program abnormally.
c                   endsl

c                   eval      *inlr = *on


So, that's a little bit nicer, but we've still got to deal with either
counting the length of the command, or passing extra blanks that the
system has to read through each time.   If we use the System() function,
we can avoid that...

Here's a sample of the same thing using the system() function:

H DFTACTGRP(*NO) BNDDIR('QC2LE')
D ErrMsgID        S              7A   Import('_EXCP_MSGID')

D system          PR            10I 0 extproc('system')
D   command                       *   value options(*string)

D rc              s             10I 0

c                   eval      rc = system('CLRPFM DMART/ACCNEW')

c                   select
c                   when      rc = 0
 **           command successful
c                   when      rc = -1
 **           command string was NULL
c                   when      ErrMsgID = 'CPF3142'
 **           handle object not found here...
c                   when      ErrMsgID = 'CPF3156'
 **           handle object in use here...
c                   other
 **           Unhandled error -- End program abnormally.
c                   endsl


There's other ways too, but that's enough for now :)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.