ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Rnf7030

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

  • Rnf7030

    I have FILE_A, I want to move all the data inside to another file FILE_B.
    I prefix all the fields in FILE_B with "PF_" so the field names are not the same.

    in the F spec, I am declaring FILE_A and FILE_B:
    Code:
    FFILE_A  O    E             DISK                
     * Output file                                    
     *                                                                                                
    FFILE_B    O    E             DISK    PREFIX(PF_)  
     * New PF
     *
    in the C spec, I am moving the data. MOVEL for char and Z-ADD for numeric
    Code:
    MOVEL     EDATE         PF_EDATE
    Z-ADD     ETIME         PF_ETIME
    MOVEL     ETRPID        PF_ETRPID
    MOVEL     EMLBX         PF_EMLBX
    MOVEL     EGSPID        PF_EGSPID
    MOVEL     EN101         PF_EN101
    MOVEL     EHEAD         PF_EHEAD
    MOVEL     EN104         PF_EN104
    MOVEL     EN301         PF_EN301
    I am getting all the errors on the field names prefixed with PF_.
    "The name or indicator PF_EDATE is not defined"
    "The name or indicator PF_ETIME is not defined" and so on....

    I think it's because I haven't declared the prefixed variables. But I feel like I am missing an important part. That is probably why it wants me to declare all the prefixed fields...Please help!

  • #2
    What you are trying to do doesn't make a whole bunch of sense in many ways.

    If there is a field in FILE_B named EDATE then this should work. I suspect though that perhaps you have named the field in FILE_B as PF_EDATE? If that is th case simply remove the PREFIX option.

    If that is not the case show us the field definitions for BOTH files.

    P.S. If the field names are the same in both files no MOVEs are required. All you need to do is remove the PREFIX keyword and READ FILE_A and WRITE FILE_B.

    P.P.S. Unless you are coding in RPG III (which you don't appear to be since PREFIX is an RPG IV feature) then why on earth are you doing MOVE at all? It is effectively a deprecated feature of the language and is only used for compatibility with old code. Just do EVAL PF_EDATE = EDATE or better still just PF_EDATE = EDATE;

    Comment


    • #3
      Originally posted by JonBoy View Post
      What you are trying to do doesn't make a whole bunch of sense in many ways.

      If there is a field in FILE_B named EDATE then this should work. I suspect though that perhaps you have named the field in FILE_B as PF_EDATE? If that is th case simply remove the PREFIX option.

      If that is not the case show us the field definitions for BOTH files.

      P.S. If the field names are the same in both files no MOVEs are required. All you need to do is remove the PREFIX keyword and READ FILE_A and WRITE FILE_B.

      P.P.S. Unless you are coding in RPG III (which you don't appear to be since PREFIX is an RPG IV feature) then why on earth are you doing MOVE at all? It is effectively a deprecated feature of the language and is only used for compatibility with old code. Just do EVAL PF_EDATE = EDATE or better still just PF_EDATE = EDATE;
      Thank you for the reply Jon. I failed to mention that I manually created the PF FILE_B. FILE_B has all the fields from FILE_A plus 2 additional ones (I wasn't told what to do with those 2 yet). The fields in FILE_B have exactly the same name as FILE_A, without the PF_, which is why I thought to have the prefix PF_. This is my first non-free rpg program, only one other free rpg program before that so you'll have to go easy on me!! one developer told me to use movel for chars and z-add for numeric, so I assumed that is what I would be using. same with PREFIX since the field names are the same in both files.

      Comment


      • #4
        Prefix works like you expect. But if you are just reading FILE-A and writing to FILE_B, it is not needed. In fact, you do not need to do anything with the fields, unless you want to initialize the "new" fields. But FILE_A appears to be defined as an Output file, so how are you reading the fields? Second, check the record format names. If they are the same, one will get rejected, and the fields in it will be undefined.

        Comment


        • #5
          OK then. I suspect the reason for your original errors were that you have no Write op-code in place. If there is no output operation for the file then RPG will by default not bother defining the field.

          Given that all your field names are the same, you don't need the Prefix. Nor do you need the MOVE <shudder> or Z-ADD <bigger shudder> - simply read from one file and write the other. RPG will always take care of populating the fields with matching names.

          This is my version:
          Code:
                 dcl-f salesdata;
          
                 dcl-f salesdatX usage(*Output);
          
                 read salesdata;
          
                 write salesdatxr;
          
                 *InLr = *On;

          Comment


          • #6
            As a matter of interest, if you're just copying data to another file with the same field names, why not use CPYF?
            CPYF FROMFILE(FILE_A) TOFILE(FILE_B) MBROPT(*REPLACE) FMTOPT(*MAP)

            For the program approach though, I think arrow483 may be on the right track and the record formats are likely the same causing the 2nd file to be ignored (that should have shown up in the compiler listing). You will need to rename the record formats: RENAME(<record format>:<new format name>)

            Comment


            • #7
              Are you wanting to copy one specific record from FILE_A to FILE_B, or all records?

              Comment


              • #8
                to make things clear, FILE_B (empty) is already created with the same exact field names as FILE_A, but with 2 more fields that FILE_A does not have.

                I guess I will show the file names, it doesn't matter anyways, so
                I have attached my code, only the parts that I think is relevant.
                EKK824R is the record format name of FILE_A(EKK824WK) and
                EK824PF is the record format name of FILE_B (EK824P).

                I want to copy ALL the records from FILE_A to FILE_B. but FILE_B has 2 more columns than FILE_A, so when I try the method of just copying, it didn't work because the number of columns are different. so I am copying the fields one by one and leaving the extra 2 fields in FILE_B alone. I am running into something strange however.

                note: the portion of copying fields is in a giant loop, so I did not have to put this into a loops of its own.
                FILE_A looks like this(there are more fields, but I am showing just one of them) :
                Code:
                FILE_A
                
                EDATE
                A
                B
                C
                D
                E
                it gets copied into FILE_B like so:
                Code:
                FILE_B
                
                EDATE
                ++++++++
                A
                B
                C
                D
                the first record is just plus signs, and E is missing. field 1 is a 8 length date type.



                I have cut off the rest of the fields being copied becuase there are too many. Field 1 is EDATE which is the one I am having trouble with. 3rd attachment is the field definition of EDATE.

                I have no idea why this is happening...??
                Attached Files

                Comment


                • #9
                  Have you tried my suggestion? Or the CPYF as suggested by john.sev99 ? Both will work. Given the file definition you have shown. Just dump the Prefix if you want to go with the program approach.

                  Comment


                  • #10
                    Originally posted by JonBoy View Post
                    Have you tried my suggestion? Or the CPYF as suggested by john.sev99 ? Both will work. Given the file definition you have shown. Just dump the Prefix if you want to go with the program approach.
                    I did, but they want me to do it a certain way...which is copying all the fields one by one and then writing to FILE_B. I got it to work now, it was a silly, dumb mistake. I was writing to FILE_B BEFORE moving all the fields. so now, it moves all the fields first (inside a loop) then writes to FILE_B and it works. I think your suggestion or CPYF could have been much less code, but yea...thank you so much!

                    Comment


                    • #11
                      Originally posted by skwon9642 View Post

                      I did, but they want me to do it a certain way...which is copying all the fields one by one and then writing to FILE_B. I got it to work now, it was a silly, dumb mistake. I was writing to FILE_B BEFORE moving all the fields. so now, it moves all the fields first (inside a loop) then writes to FILE_B and it works. I think your suggestion or CPYF could have been much less code, but yea...thank you so much!
                      Weird people you work for! One of the most powerful features of RPG (ignoring for a moment the even better CPYF approach) is that you don't _have_ to move fields the way you do in other languages. If the name is the same RPG handles it automatically - and that is a critical lesson that every RPG newcomer needs to understand because from time to time you will encounter a situation where that capability will get in you way and confuse you.

                      Oh well - you have it working - albeit in a non-optimal way. Please tell me that you didn't use MOVE though!

                      Comment


                      • #12
                        Originally posted by JonBoy View Post
                        Please tell me that you didn't use MOVE though!
                        Absolutely agree - why the OP isn't using freeform to start with is beyond me and using ancient op-codes is just plain silly. RPG III programs are very hard to read compared to modern RPG syntax making future upkeep far more difficult.

                        Comment

                        Working...
                        X