ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

OVRDBF command using QCMDEXC

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OVRDBF command using QCMDEXC

    Hi

    I am trying to execute OVRDBF in RPGLE using the command QCMDEXC. I didn't get any error message but it is not working as expected.

    Please find my below code

    FFILEIN IF E DISK RENAME(FILEIN:FILEA)
    F PREFIX(F_)
    D@cmd s 300a
    D@cmd1 s 15a
    D@cmdlen s 15p 5
    Dcmdex pr extpgm('QCMDEXC')
    d 300a
    d 15P 5
    /free
    @cmd='OVRDBF FILE(FILEIN) TOFILE(LIBRARY1/FILE1)' +
    ' MBR(*FIRST) OVRSCOPE(*JOB)';
    @cmdlen=%len(%trim(@cmd));
    cmdex(@cmd:@cmdlen);
    Read filein;
    @cmd1=%subst(F_Filein:1:15);
    dsply @cmd1;
    *inlr=*on;
    /end-free

  • #2
    The file is already open when the OVRDBF is run, so too late. Stick a USROPN on the F-Spec, do the OVRDBF then OPEN the file.

    Ringer

    Comment


    • #3
      Hi

      It's even easier with EXTFILE :


      Nathanaƫl

      Comment


      • #4
        Just a warning ... Overrides done with OVRSCOPE(*JOB) remain until you use the DLTOVR command, so the override will still exist in your job after your program ends. If you just want to control which file is opened in your program, it's probably better to use OVRSCOPE(*ACTGRPDFN).

        I agree with Nathanael that using EXTFILE would be easier. The only time I would use OVRDBF just to set the file name or member name within a program is if I wanted to set the override for some other program that my program was going to call.

        Comment


        • #5
          I can't go with EXTFILE because I will get to know the file name in run time.
          Now I have used OVRDBF. I am getting some error please find my code.


          /FREE
          @cmd='OVRDBF FILE(BANK) TOFILE(BANDARU901/ACCOUNT)' +
          ' OVRSCOPE(*ACTGRPDFN)';
          @cmdlen=%len(%trim(@cmd));
          execmd(@cmd:@cmdlen);
          Open bank;
          Read bank;
          dow not %eof(bank);
          dsply accno;
          read bank;
          enddo;




          Message . . . . : Error message CPF4131 appeared during OPEN.
          Cause . . . . . : RPG procedure QCMDEX in program BANDARU901/QCMDEX received
          the message CPF4131 while performing an explicit OPEN operation on file
          BANK. The actual file is BANK.
          Recovery . . . : Check the job log for a complete description of message
          CPF4131, and contact the person responsible for program maintenance.

          Comment


          • #6
            You can use a variable with EXTFILE.
            For exemple https://www.ibm.com/support/knowledg...sd/fextfil.htm and https://www.mcpressonline.com/progra...ile-and-extmbr.

            CPF4131 means that the BANK file used for compilation does not have the same format as the BANDARU901/ACCOUNT file.

            Nathanaƫl

            Comment


            • #7
              Overriding is fine. How come record format will be same. if it is same we will get compilation error I guess. If both record formats are different how to handle the situations.

              Comment


              • #8
                How to avoid below problem
                CPF4131 means that the BANK file used for compilation does not have the same format as the BANDARU901/ACCOUNT file.

                Comment


                • #9
                  Originally posted by CRinger400 View Post
                  The file is already open when the OVRDBF is run, so too late. Stick a USROPN on the F-Spec, do the OVRDBF then OPEN the file.

                  Ringer
                  I'd agree with this solution... usually the simple solution is easier to use as a fix than trying to put something complicated into problem.

                  Best Regards and Good Luck!
                  Fred Williams

                  Comment


                  • #10
                    Originally posted by b.reddikumar View Post
                    Overriding is fine. How come record format will be same. if it is same we will get compilation error I guess. If both record formats are different how to handle the situations.
                    For a file overridden with OVRDBF, there won't be a compiler error. The compiler only knows about the file referenced in the program. It won't know anything about the override because that happens at run-time, not at compile-time. And if the record formats are different, you shouldn't code the program to access a file with the mismatched format. Although it's technically possible to do, it can also cause many unexpected errors (which is why the system throws CPF4131).

                    That assumes I'm correctly interpreting the quoted post. There are a couple sentence structures that don't quite fit.
                    Tom

                    There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                    Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                    Comment


                    • #11
                      Originally posted by b.reddikumar View Post
                      How to avoid below problem
                      CPF4131 means that the BANK file used for compilation does not have the same format as the BANDARU901/ACCOUNT file.
                      You avoid the problem by avoiding overrides to files that have formats that are different from what the programming expects.

                      If the file formats are different, but the programming only accesses fields that match in both files, one potential way to handle it is with SQL that only retrieves the same fields from the different files.
                      Tom

                      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                      Comment


                      • #12
                        I resolved this situation using program described file. Thank you very much to every one.

                        Comment

                        Working...
                        X