Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Declare Two Files with the Same Format

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

  • Declare Two Files with the Same Format

    ** This thread discusses the article: Declare Two Files with the Same Format **
    ** This thread discusses the Content article: Declare Two Files with the Same Format **
    0

  • #2
    Declare Two Files with the Same Format

    ** This thread discusses the article: Declare Two Files with the Same Format **
    Bob, So what improvements / advantages does this technique give me verses just prefixing file fields and creating a non-qualified data structure? For example, here is what I typically use (we always define fields with 2 character prefix IDs in each unique PF)... FFILEPF IF E K DISK PREFIX(II:2) FFILELF UF A E K DISK PREFIX(UU:2) D FILEDS E DS EXTNAME(FILE) PREFIX(II) D FILE2DS E DS EXTNAME(FILE2) PREFIX(UU) I would still get the DS fields populated from the database files and to move data around I can just use the DS names (if I want to move all data). I like the idea of qualified DS's but if I introduce this techique I have to give a reason for others to change and accept the methods (I always get the "what's business reason?" question).

    Comment


    • #3
      Declare Two Files with the Same Format

      ** This thread discusses the article: Declare Two Files with the Same Format **
      Don't we have to rename the record formats as well? If you don't I believe you'll receive a compile-time error indicating duplicate record format names are not allowed. Garrett

      Comment


      • #4
        Declare Two Files with the Same Format

        ** This thread discusses the article: Declare Two Files with the Same Format **
        To follow-up, I did a little test compile. We are on V5R1M0. The compile fails when specifying two files with the same record format (see first set of compile report lines below). If I add the special prefix with the quotes and period ('file1.'), the compile fails because it doesn't like the syntax of the prefix. (see second set of compile report lines below). Bob, is it possible that this is really available only in V5R2 or V5R3 instead of V5R1 as you indicate in the article? Thanks, Garrett
        Code

        Comment


        • #5
          Declare Two Files with the Same Format

          ** This thread discusses the article: Declare Two Files with the Same Format **
          I tried it and it would not put the data in the DS. I renamed the logical format file and did everything else like the example. I did a chain instead of a read to the 2nd file. after the chain, my DS was still empty. (verified thru debugger).

          Comment


          • #6
            Declare Two Files with the Same Format

            ** This thread discusses the article: Declare Two Files with the Same Format **
            I found I didn't follow Bob's instructions to the letter. So, the error I got about an invalid prefix name was because I did not capitalize the prefix as Bob indicated is required. Sure enough, that error went away but I still get the record format already defined error.

            Comment


            • #7
              Declare Two Files with the Same Format

              ** This thread discusses the article: Declare Two Files with the Same Format **
              Bob, There may be a good use of using qualified field names in RPG but this isn’t one of them. To qualify a data-name in COBOL you use the reserved word IN (or OF) and that probably goes back to the time when you wore three cornered pants. Few programmers back then used qualifiers. There are two reasons for this. First, it required more coding, and with more coding more places to make errors are introduced. Second, the use of data-name prefixes (or suffixes) is generally considered more readable and easier to work with. When unique prefixes are used for fields of each record, places where qualification can be used are practically eliminated.

              Comment


              • #8
                Declare Two Files with the Same Format

                ** This thread discusses the article: Declare Two Files with the Same Format **
                One of the pros (and I think I am correct here), is that this qualified syntax is typical of several other languages. So seeing and using this may help in analyzing/reading/becoming familiar with other languages (like Java for example). Garrett

                Comment


                • #9
                  Declare Two Files with the Same Format

                  ** This thread discusses the article: Declare Two Files with the Same Format **
                  Fantastic stuff young Bob. I tested it & it works well. Two annoyances I found: 1. Cannot use the original file name as the qualified datastruct name. My file is called VC003WL1 and it contains a field called CNKEY1, so I wanted to conjure up a nice VC003WL1.CNKEY1 with this new Bobby trick. "Nooooo" says the compiler, "You've already defined VC003WL1". 2. The compiler is fussy about the length of this kind of qualified field name. Apparently "VC003WL1.CNKEY1" is 1 character too long. I am used to creating qualified datastruct names far longer than this. I've long been searching for a way to qualify file fields & this pretty much solves it. Thanks Bob. What other nifty tricks are you withholding?

                  Comment


                  • #10
                    Declare Two Files with the Same Format

                    ** This thread discusses the article: Declare Two Files with the Same Format **
                    Lets say that You have in Your shop many many programmers. Not all of them behave according to the rules to define the files with the right prefix for the fields. In addition some files in your shop are from outside systems. You are afraid that after You will create your program, a new filed will be added to a file tha does no adhere to the rules of your shop, and your program, and that filed will collide with one of the fields in your program. What coud You do to protect your program? example: FILEA: aacust, aaaddr. FILEB: cust_1, addr_1. Now a new field was added to FILEB: AACUST, and an automaic program compiled all program on the system, including yours. how do you protect yourself from that? Prefix is helpful. But what about if FILEB will add field A_CUST. by coincidence he will use the same prefix that is used in filea on the prefix statement in your program. But with QUALIFIED, the rules of DDS and SQL do not allow to define a field with a name A.CUST. So this way Your RPG Program is 100 percent protected.

                    Comment


                    • #11
                      Declare Two Files with the Same Format

                      ** This thread discusses the article: Declare Two Files with the Same Format **
                      I have used qualified data structures for file I/O for awhile, with the LIKEREC keyword. The main reason why I started using qualified data structures was because, as I understand it, reading into a DS, or writing from a DS is quicker than a plain READ or WRITE, because the entire record buffer is plunked down right on the DS, and not in the field buffers. I am wondering, if this is the case here. It sounds like it is, and if so -- Thanks for clearing this up! This will make my code much more readable, and now I won't have to remember the DS name every time I READ/WRITE/CHAIN/READE.

                      Comment


                      • #12
                        Declare Two Files with the Same Format

                        ** This thread discusses the article: Declare Two Files with the Same Format **
                        I ran a rough speed test comparison between reading to a data structure and just reading read_ary ds likerec(cusmas00:*input) read(e) fpcusmas read(e) fpcusmas read_ary There were 10000 records with 100 fields were read each run (batch/interactive by rrn/key) Overall just reading was quicker for most runs
                        Code

                        Comment

                        Working...
                        X