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!

OVRDBF using QCMDEXC in RPG 4

Status
Not open for further replies.

TracyV

Programmer
Nov 24, 2003
35
US
I want to override a database file to a user supplied member name within my RPG program using QCMDEXC. I created the command in a table and use that to populate the parm to QCMDEXC. How do i pass the user supplied data to the command? The command expects a '&' but i cannot create that type of workfield in RPG. Any suggestions would be appreciated!!!

 
Tracy,

I'm not sure what you mean by:

The command expects a '&' but i cannot create that type of workfield in RPG.

We use QCMDEXC all the time to override print files like so:

Code:
  * Prototyped call definitions                                 
                                                                
 D Command         PR                  EXTPGM('QCMDEXC')        
 D   CmdStr                    3000A   Const Options(*VARSIZE)  
 D   CmdLen                      15P 5 Const                    


 // Print file override                                    
                                                           
 ClpPgm  = *BLANKS;                                        
 RpgPgm  =  WQPGMN;                                        
 PrtF    = 'QSYSPRT';                                      
 OvrPrtF = *BLANKS;                                        
                                                           
 CallP GetPrtAttribes( ClpPgm : RpgPgm : PrtF : OvrPrtF ); 
 CallP Command( Ovrprtf : 256 );                           
                                                           
 Open QSYSPRT;                                             
 Except Header;

HTH,
MdnghtPgmr
 
I'm trying to override a database file with multiple members to the member name the user supplies. How do I pass this user supplied data to QCMDEXC as a parm? In your example, you know what the parmaters are you and can hardcode them. I havent had much experience with procedures and subprocedures, but any help would be greatly appreciated!

Thanks!
 
Tracy,

Sorry, I meant to explain the program GetPrtAttribes. Here is a snippet from that program that shows how we build the command passed in the parm Ovrprtf.

Code:
OvrPrtf = 'OVRPRTF FILE(' + %TRIM(PRPRTF)
           + ') OUTQ(' + %TRIM(PROUTQ)   
           + ') COPIES(' + %TRIM(COPIES) 
           + ') ' +  %TRIM(HOLD) + ' '   
           + %TRIM(SAVE)

Note that the fields PRPRTF, PROUTQ, COPIES, HOLD and SAVE all come from a database file. The users control the file and thus where and how their spooled files print.

You could do something simular for the OVRTDBF command. Anyway I hope that gives you a lead.

MdnghtPgmr
 
I'm trying to OVRDBF not OVRPRTF.

I found what I needed tho. Thanks for the other info, I'm sure I'll use that at a later date!


You can, however, execute the OVRDBF command from within an RPG program using the QCMDEXC API. The procedure is straightforward; simply follow these steps:

Declare a compile time array with dimension 80, where each element's length is Char 1.
Declare command and command length variables for QCMDEXC of Char 80 and Packed 15,5.
Move the overriding member name from the temporary variable to the member name's physical position of the array.
Move the array value to the command variable.
Call QCMDEXC.
Figure 1 (below) shows the code to execute the OVRDBF command using QCMDEXC.

Gopal Gora, software analyst, Poorva Consultants, India.



--------------------------------------------------------------------------------


Figure 1: Code to execute the OVRDBF command using QCMDEXC

dmbrnm s 10a // mbrnm is
the variable for overriding member name

* To override the file FILE1234 with member MBRNEW1234 using * API
QCMDEXC

darrct1 s 1a Dim(80) Ctdata Perrcd(80)
//arrctl is the variable for compile-time array.
D Cmd s 80A
D Cmdlen s 15P 5

C Movea mbrnm arrct1(44)
C Movea arrct1 Cmd
C Eval Cmdlen = 80

C CALL 'QCMDEXC'
C Parm Cmd
C Parm Cmdlen


**Ctdata arrct1
44
OVRDBF FILE(FILE1234) TOFILE(FILE1234) MBR(MBROLD1234) OVRSCOPE(*JOB)
 
Tracyv:

If all you need to do is override the member name, use the EXTMBR keyword on the file specifications.

The only reason to usr OVRDBF instead is if your program calls another one that will also depend on the override to this member being in place. EXTMBR is not, strictly speaking, an override.


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Since it looks like you're coding in RPG IV, try using the EXTFILE and EXTMBR keywords on the "F" specs. Then just send the member name to the program as a parm.

RedMage1967
IBM Certifed - RPG IV Progammer
 
I guess I'm not making myself clear. The program is already running. If a user adds a new record, then I want to also add this new record to a history file which has multiple members. Depending what year the user enters, that is the member name. I am controlling the opening and closing of this history file. I'll only open it and override to the member if the user is adding a new record. I am not calling a new program to write the record to history, I just want to override the file to the correct member and write the new record to that member. This is why I need to pass variables to QCMDEXC. I need to pass variables because I don't know which member the user will choose.

Clear as mud, right!

Thanks for your help, but I think the above posting will work fine.
 
Well, I'm pretty sure I'd write it like so without that Movea. Much simpler.
Code:
d mbrnm           s             10A          

D Cmd             s             80A
D Cmdlen          s             15P 5

C                   Eval      Cmd= 'OVRDBF FILE(FILE1234)+ 
C                                   TOFILE(FILE1234) +
C                                   MBR(' + %Trim(mbrnm) + ') ' +
C                                   'OVRSCOPE(*JOB)'

C                   CALL      'QCMDEXC'
C                   Parm                    Cmd
C                   Parm                    %Len(Cmd)
 
Or, use the EXTMBR keyword (you can use a variable). Much easier than doing an override, in this case, if I'm understanding the situation.

De mortuis nihil nisi bonum.

 
Yes, it could be easier BUT TracyV wants to override a database file using QCMDEXC nothing else. See his initial posting.

Felix qui potuit reum cognoscere causas

 
I did read his posts. As far as I can tell, all he needs the override for is to write to a specific member, based on the user's choice. He can save the user's choice in a variable, and compare it to the member currently being used in the variable for the EXTMBR keyword. If they are different, close the file, change the variable for the member in the EXTMBR keyword, and re-open the file.

De mortuis nihil nisi bonum.

 
I've done about the same thing myself. It's much easier to use the EXTMBR, than to use QCMDEXC.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Thanks, RedMage. From TracyV's earlier posts, the only reason he was using QCMDEXC is because he was under the (mistaken) impression that EXTMBR does not take varible names. It does, however, at least according to IBM. If you put the name in quotes, it assumes you are giving it a literal name; otherwise (without the quotes), it assumes you have a 10-byte character variable (or named constant).

De mortuis nihil nisi bonum.

 
It does. I have several apps that need to read two different file members, from the same file. I use the EXTMBR keyword, then define a variable for the member name. I change the variable name depending on the program logic that determines which member to read from.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top