ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Read and Write File with Same Name

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

  • Read and Write File with Same Name

    Hi guys,

    I want read and write file with same name but in different library.
    in previous case I create new LF for one of file, but now I can't do that.
    Any advice?

  • #2
    Re: Read and Write File with Same Name

    Change the name of one of the files, and use OVRDBF to point to it

    Comment


    • #3
      Re: Read and Write File with Same Name

      Is this just "read and write"? Just use SQL to INSERT from a SELECT list.
      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


      • #4
        Re: Read and Write File with Same Name

        arrow483 : I can't rename this file because many process used it.

        tomliotta : I need in RPG for this case

        any other advice?

        Comment


        • #5
          Re: Read and Write File with Same Name

          OVRDBF to a different name will be enough.
          But remember at compile time the file (with the overridden name) must exist in your library list.
          Just use a CRTDUPOBJ command for creating an empty file in the QTEMP library at compile time.

          Birgitta

          Comment


          • #6
            Re: Read and Write File with Same Name

            Originally posted by ricods View Post
            ...I need in RPG for this case

            any other advice?
            Put the SQL INSERT into a RPG program then. No problem.

            It's hard to give appropriate advice when we don't know the actual problem. You just told us "RPG" for the first time. We still don't know if it must be OPM RPG or you're allowed to use ILE RPG. We don't know what version you will program for, so we don't know what features you can use.

            Please remember to list any requirements when asking about a technical problem. Answers will be easier and there will be fewer irrelevant (and potentially confusing) replies.
            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


            • #7
              Re: Read and Write File with Same Name

              Here's how to do it with RPG F specs:

              Use EXTDESC, EXTFILE, and RENAME on the F spec for at least one of the files.

              This program opens file LIB1/SOMEFILE for input and file LIB2/SOMEFILE for output.

              Code:
              Finfile    if   e             disk    extdesc('SOMEFILE')       
              F                                     extfile('LIB1/SOMEFILE')  
              F                                     rename(SOMEREC:INREC)     
              Foutfile   o    e             disk    extdesc('SOMEFILE')       
              F                                     extfile('LIB2/SOMEFILE')  
              F                                     rename(SOMEREC:OUTREC)
              You could leave off the keywords for the input file, and just use a different name for the output file and its record format.

              Code:
              Fsomefile  if   e             disk    extfile('LIB1/SOMEFILE') 
              Fsomefile2 o    e             disk    extdesc('SOMEFILE')      
              F                                     extfile('LIB2/SOMEFILE') 
              F                                     rename(SOMEREC:OUTREC)

              Comment


              • #8
                Re: Read and Write File with Same Name

                Originally posted by Barbara Morris View Post
                Here's how to do it with RPG F specs:

                Use EXTDESC, EXTFILE, and RENAME on the F spec for at least one of the files.
                seem EXTDESC not compatible in V5R4M0, is there any similar code?

                Comment


                • #9
                  Re: Read and Write File with Same Name

                  arrow483's and Birgitta's suggestion to use OVRDBF to override to a file that is named different from the file named on one of your two F-specs is appropriate. You'll probably still need the RENAME keyword if the two files share the same record format name.

                  An override like that needs to be applied twice. It has to be applied at compile-time so the compiler knows what the real file name is, and it has to be active again at run-time so the running program gets to the right file.

                  The compile-time override can point to either of your two files as long as they share the same record format definition. The compiler is really only interested in getting all of the appropriate file and field attributes. The compiler doesn't actually care what file will be selected at run-time.

                  BTW, the "V5R4" restriction is one of the details that would have been useful at the beginning.
                  Last edited by tomliotta; September 4, 2013, 02:33 AM. Reason: Give credit.
                  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


                  • #10
                    Re: Read and Write File with Same Name

                    I would use EXTFILE at run-time, and (at V5R4) use OVRDBF only at compile time. (In newer versions, use EXTDESC at compile-time.)

                    Comment


                    • #11
                      Re: Read and Write File with Same Name

                      solved guys, many thanks

                      since beginning, most of you said about OVRDBF and i still don't know how this command works.
                      please forgive this newbie :P

                      Comment


                      • #12
                        Re: Read and Write File with Same Name

                        the OVRDBF is a CL command usually issued just prior to the program call. It looks something like:

                        Code:
                        PGM
                        OVRDBF     FILE(LIB1/ITEMMAS) TOFILE(LIB2/ITEMMAS)
                        CALL         PGM(SEASLS01)
                        ENDPGM
                        In this case, LIB1 and LIB2 both have a copy of ITEMMAS in it, The OVRDBF allows us to control which ITEMMAS the SEASLS01 program uses.

                        Hope that helps you see why they suggested it.

                        Andy

                        Comment

                        Working...
                        X