Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running CL Commands within an RPG Progam.

Status
Not open for further replies.

Fooch

Programmer
Dec 19, 2005
63
US
What is the most efficient, easiest, or best way to go about running CL commands from within an RPG? I ask because I have a program that monitors a data queue and whenever a record shows up it is procesed and send to the file in the library specified by the data queu record. Since this will change all the time I need a way within the RPG to override the file to the correct library. I heard that someone thought there was a way to prototype CL commands, is that true? If so, how? Thanks in advance for any help.
 
Without getting into too much detail, the best way to handle this is to do it all in RPG-IV, without having CL involved at all.

Define the file as a USROPN type, build an ovrdbf command that is called by QCMDEXC, open the file, write the record, close the file, delete the override.
 
You don't need to use overrides - use the EXTFILE keyword:
Code:
     FArslp     IF   E           K Disk    Usropn Extfile(Arslp_Name) 
      * Salesperson Master File  

                                     
      * Stand-Alone Fields              
     D Arslp_Name      S             21A

     C                   If        %OPEN(Arslp)                         
     C                   Close     Arslp                                
     C                   Endif                                          
     C                   Eval      Arslp_Name = %TRIM(your_lib) + '/ARSLP'
     C                   Open      Arslp

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
There is no better way to do the override that QCMDEXC. I didn't want to use that because it looks sloppy, to me anyway. I thought there might be a cleaner way to do it.
 
How about this:

D ClCmd PR 10I 0 Extproc('system')
D CmdString * Value D Options(*String)


/Free
Returncode = ClCmd(OVRDBF FILE(filename));
...
/End-Free
 
fooch said:
There is no better way to do the override that QCMDEXC. I didn't want to use that because it looks sloppy, to me anyway. I thought there might be a cleaner way to do it.

"Sloppy"? You still have to close and re-open the file, whether you ust QCMDEXC or EXTFILE. Processing QCMDEXC takes up resources; the EXTFILE keyword takes up no resources at all.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Fooch -
The original question boils down to "How can I open a specific file in multiple libraries?" I'm just pointing out that you don't need to call 'system' or QCMDEXEC to do that. RPG has that capability built into the F-specs with the EXTFILE keyword.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Ok, I may have misunderstood what you were saying in your first post. You are saying NOT to use CMDEXC...and to use EXTFILE as a field that you can change throughout the program. So whenever the library changes, you just set that field in EXTNAME to your new library i.e. %TRIM(your_lib) + '/ARSLP' ?

This will work like an override? All I have to do is change that field and then i can immeadiately write to the correct file in the correct library without having to read/chain/override? If so, that is a lot better of a way. I apolagize if I said your code looked sloppy. I didn't mean your code. I am looking through old QCMDEXC commands here at the company and they are filling compile time arrays with the CL command line, doing all these extra steps, etc.
 
Ok, I see that the file has to be closed and opened after the change. Can this EXTFILE keyword handle Members? I have 6 files to override to a library depending on the record I pull from a Data Queue. 3 of these files are memberes and three are not, so I will need to write to the correct member for a few of these files, can EXTFILE handle that? or is CL required?
 
Lol I think I just answered my own question. I see that there is an EXTMBR keyword that can be used with a variable. So:

FFile IF E K Disk USROPN EXTFILE(FileField)
EXTMBR(MbrField)

Should allow me to do this correctly?
 
fooch -

I didn't mention EXTMBR because you didn't mention members in your original question. In our shop, files have only one member.

Yes, you can use EXTMBR as well.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
I have to add that you need to close the file before you change the variable for EXTFILE or EXTMBR, then re-open it. That's why I have the IF %open(file) clause -- the first time through the loop, the file will not be open.

Feles mala! Cur cista non uteris? Stramentum novum in ea posui!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top