ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Override a file in RPG?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Override a file in RPG?

    How can we override a file during runtime in RPG? [Without using QCMDEXC]

  • #2
    Re: Override a file in RPG?

    EXTFILE keyword on your F spec. (note: there's tons of things that OVRDBF provides that EXTFILE does not)
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: Override a file in RPG?

      PHP Code:
      faracustd  if   e           k disk    extfile(FileName1usropn 

      d Filename1       s             20    inz
      ('LSNFIL/ARACUSTD')     

                                                   
       
      open aracustd;                              
       
      setll *start aracustd;                      
       
      read  aracustd;                             
       
      dow not%eof(aracustd);                      
        if 
      AAACTS = *blanks and AASL# <> *zeros;   
         
      exsr  $printme;                           
        endif;                                     
        
      read  aracustd;                            
       
      enddo;                                      
                                                   
        *
      inlr = *on
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: Override a file in RPG?

        Curious to know why you dont want to use QCMDEXC. I used to put the overrides within my RPG using QCMDEXC but have finally decided that a simple three line CL wrap around the RPG is cleaner and more flexible.

        Comment


        • #5
          Re: Override a file in RPG?

          i saw that the OP (on another forum) mentioned that these questions are for an interview. with that in mind i personally refuse to assist someone in getting hired for a position he/she is definitely not qualified for.
          I'm not anti-social, I just don't like people -Tommy Holden

          Comment


          • #6
            Re: Override a file in RPG?

            I hate CL......
            IBM came up with the extfile ...
            I believe as non CSS attributes are depreciated in web development so is overriding in CL.

            jamie
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Override a file in RPG?

              Originally posted by jamief View Post
              I hate CL......
              IBM came up with the extfile ...
              I believe as non CSS attributes are depreciated in web development so is overriding in CL.

              jamie
              but QCMDEXC is an API
              I'm not anti-social, I just don't like people -Tommy Holden

              Comment


              • #8
                Re: Override a file in RPG?

                yes but QCMDEXC can be used for many other "commands" that IBM hasnt figured out a better way -- yet!
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: Override a file in RPG?

                  The reason we dont have integrated web development tools in RPG is because IBM blew the entire development budget a few years ago upgrading CL.
                  Michael Catalani
                  IS Director, eCommerce & Web Development
                  Acceptance Insurance Corporation
                  www.AcceptanceInsurance.com
                  www.ProvatoSys.com

                  Comment


                  • #10
                    Re: Override a file in RPG?

                    Michael -- That is why im an angry little troll to this DAY! @#%@#%@#%@#% Them....
                    All my answers were extracted from the "Big Dummy's Guide to the As400"
                    and I take no responsibility for any of them.

                    www.code400.com

                    Comment


                    • #11
                      Re: Override a file in RPG?

                      I did work with one customer where the powers-that-be had decreed that QCMDEXC was banned (and the ban enforced by source scanners) for "security" reasons. So the programmers "in the know" used the C system() function instead!

                      Comment


                      • #12
                        Re: Override a file in RPG?

                        Yea, I use the system() function to do this as well, because I have it wrapped in a service program and can add a library in a single clean line of code:

                        Command_System( 'ADDLIBLE MYLIB' );

                        There are also times where I want to set the library list at run-time based upon the library of the program that's running, where it would be completely impractical to do this with CL.

                        For instance, this is the cleanest way, so far, I have found to set up server instance library lists for CGI programs. (Because I havent found an api that can return to me the server instance that called the cgi program.) So I retrieve the library that the cgi program is running in, and from that I can tell which server instance called it, and what the resulting library list should be. (I couple this with binding the cgi program to a binding directory in which my service programs are set to *DEFER, which keeps the service programs from being activated until after the library list is completely set up.)
                        Michael Catalani
                        IS Director, eCommerce & Web Development
                        Acceptance Insurance Corporation
                        www.AcceptanceInsurance.com
                        www.ProvatoSys.com

                        Comment


                        • #13
                          Re: Override a file in RPG?

                          What I hate about systems() is, if the command failed I only know it failed, but do not get neither a message id nor an error message.
                          With QCMDEXC I can get both information out of the program status data structure.

                          Birgitta

                          Comment


                          • #14
                            Re: Override a file in RPG?

                            If you wrap the system() api into a function wrapper, you can have the function itself import the error ID, and then pass that back from the function call.

                            Michael Catalani
                            IS Director, eCommerce & Web Development
                            Acceptance Insurance Corporation
                            www.AcceptanceInsurance.com
                            www.ProvatoSys.com

                            Comment


                            • #15
                              Re: Override a file in RPG?

                              Here's an example of retrieving and passing back the CPF message with a call to the system() api. The sample program will make three calls to the system() api, passing it 3 different libraries to add to the library list. (The first should be a good library, the second a library that doesnt exist, and the third is an invalid library name that exceeds ten characters.) If you pass it a library that exists and is successfully added to your library list, the CprError return field should be blanks. (If it's already in your library list, you will get CPF2103 returned.) If you pass it a library that does not exist, it will return CPF2110. If you pass it invalid data, such as a library name that exceeds ten characters, you will receive CPF0006.

                              CPF0006 is a special return code, as it says that the command string is invalid in of itself. (Such as a bad parameter name, or a library name that exceeds ten characters, etc. )


                              The Command_System function wraps around the api, and imports in the CPF Error message. It then returns the Cpf Error as a part of the function. This keeps your programs from having to use the import function, as it is tucked away in the function itself.


                              Sample Program

                              Code:
                              h DftActGrp( *No ) BndDir( 'BNDDIR' )                     
                               
                              d CpfError        s              7a                       
                               
                               /copy *libl/qrpglesrc,Command_p                          
                               
                               /free                                                    
                               
                                CpfError = Command_System( 'ADDLIBLE GOODLIB' );        
                                dsply CpfError;                                         
                               
                                CpfError = Command_System( 'ADDLIBLE BADLIB' );         
                                dsply CpfError;                                         
                               
                                CpfError = Command_System( 'ADDLIBLE LONGLIBNAME' );    
                                dsply CpfError;                                         
                               
                                *inlr = *on;
                              Prototype for Command_P

                              Code:
                               
                              d Command_System...                                              
                              d                 pr             7a                              
                              d  CommandString                  *   Value Options(*String)     
                               
                              d SystemApi       pr            10i 0 ExtProc( 'system' )          
                              d  CommandString                  *   Value Options( *String )
                              Service program Command_S

                              Code:
                              h nomain                                                             
                               
                               /copy *libl/qrpglesrc,command_p                                   
                               
                              d CpfError        s              7a   Import('_EXCP_MSGID')          
                               
                              p Command_System...                                                  
                              p                 b                   Export                         
                              d                 pi             7a                                  
                              d  CommandString                  *   Value Options(*String)         
                               
                              d ReturnCode      s             10i 0                                
                              d NoError         s              7a   Inz( *blanks )                 
                               
                               
                               /free                                                               
                               
                                  ReturnCode = SystemApi( CommandString );                         
                                  if ReturnCode = 0;                                               
                                    return NoError;                     
                                  else;                                 
                                    return CpfError;                    
                                  endif;                                
                               /end-free                                
                              p                 e
                              Last edited by MichaelCatalani; June 9, 2011, 01:03 PM.
                              Michael Catalani
                              IS Director, eCommerce & Web Development
                              Acceptance Insurance Corporation
                              www.AcceptanceInsurance.com
                              www.ProvatoSys.com

                              Comment

                              Working...
                              X