ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

RPG sample to Read Write

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

  • RPG sample to Read Write

    Where can I find a sample program that will read a file, not by key and write entire row, all rows to another table with the same record format.

  • #2
    Could you use CRTDUPOBJ instead of writing a program?

    Comment


    • #3
      CPYF should work if you want to copy all the records.

      If your program isn't compiling because there is a message about the record format already being defined, you can use the RENAME keyword on your file definition to rename one of the record formats to some other name inside the RPG program.

      Comment


      • john.sev99
        john.sev99 commented
        Editing a comment
        I tested using CPYF, however if the file is keyed, it copies it in keyed order. The OP said not by key. Is there a way to force CPYF to copy in arrival sequence? I don't see an option in 7.2 at least...

    • #4
      Just curious.
      Is this a response to a test you are doing or
      is it something you have to code for your company?

      Comment


      • #5
        You could use embedded SQL, and use rrn() to define the order? Though I'm not sure exactly if rrn is the same thing as unkeyed copy order

        Code:
        exec sql
          insert into toFile
          select * from fromFile
           order by rrn(fromFile);

        Comment


        • #6
          Cpyf fromrcd(*start)

          Comment


          • #7
            Actually, CPYF FROMRCD(*START) copies in keyed order if the physical file has a key. To get the file copied in RRN order use CPYF FROMRCD(1).

            Comment

            Working...
            X