ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Converting program-described input file to FREE

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

  • Converting program-described input file to FREE

    Hello,

    We have an old program that is relatively simple. A file is declared as a program-described file. The program uses sequences to define the fields depending on the value of the record read. There is an OVRDBF before calling the program to replace the file with the right file. Here's the code in RPG/400 :

    Code:
    FTPRECU  IP  F     240            DISK
    I'm trying to rewrite this program in full-free RPGLE from scratch but I can't figure out how to do this. I've found out how to declare my file, TPRECU

    Code:
    Dcl-F TPRecu   Disk(240);
    However, I can't figure out how to manipulate the data. In RPG/400, you can manipulate the data because the fields are declared using sequences. But I just need to take the whole 240 characters and put it into a DS. How do I do this ?

    Code:
    Setll *Start TPRecu;
    Read TPRecu;
    DoW not %eof(TPRecu);
      DSTPRecu = <data>;
      Read TPRecu;
    EndDo;
    What do I replace <data> with ?

    Any help? Thanks.​

  • #2
    Greetings,
    Dusting off some very old knowledge but your program described file should have a "default" fieldname defined in it. Usually your filename as the only field name.
    Run the command DSPFFD FILE(yourlib/yourfile) which should list the field name in your file. use that name in place of your <data>., Hope that helps.

    Comment


    • #3
      Thanks but a program-described file doesn't actually exist. It only exists during the execution of the program, hence the adjective "program-described". So can't run DSPFFD. As for the file that is used for the OVRDBF, it's just a file with a 240-character long field. I would just need to manipulate this data. I've come across this blog post that describes how one can manipulate the data with SQL. https://www.itjungle.com/2020/09/21/...escribed-data/

      Will try it. Thanks.

      Comment


      • #4
        You can read the contents of a program described file directly into a data structure (make sure the length of the data structure is the same as the file record length):

        Code:
        Setll *Start TPRecu;
        Read TPRecu DSTPRecu;
        DoW not %eof(TPRecu);
          Read TPRecu DSTPRecu;
        EndDo;

        Comment


        • #5
          While Brian is correct and may be your simplest solution, an input file which is used as input only must exist before your rpg program executes and does an initial file open.
          Perhaps you need to halt the execution of your program just prior to your program being called in perhaps a CL program (call method not explained in your request so I am making an assumption).
          Anyway there must be a physical file with a minimum file description containing one field (sometimes named the same as your filename or FLD001 is an old S/36E naming convention used).

          Good luck.

          Comment


          • #6
            What did the Input specifications look like when it was fixed form?

            In general, you would change the input specifications to be subfields in a data structure, and do the READ into the data structure.

            For example, if the I specs were like this:
            Code:
            ITPRECU    ns  01                                      
            I                                  1   10  ITEM        
            I                                 11   25  TYPE        
            I                                 26   29 0QUANTITY    
            I                             p   30   35 3PRICE      
            I                                 36  240  WHATEVER
            First, do a compile to see what the data types are:
            Code:
            ITEM              A(10)      
            PRICE             P(11,3)        
            QUANTITY          P(4,0)      No "type" in the I specs, so it has to be zoned
            TYPE              A(15)      
            WHATEVER          A(205)​
            Define a data structure with those fields as subfields. Put the starting position from the I specs into the POS keyword.
            Code:
            dcl-ds TPRECU_ds LEN(240);
               ITEM      CHAR(10) POS(1);
               PRICE     PACKED(11:3) POS(11);        
               QUANTITY  ZONED(4:0) POS(26);   //   No "type" in the I specs, so it has to be zoned
               TYPE      CHAR(15) POS(30);
               WHATEVER  CHAR(205) POS(36);
            end-ds;​
            Do the READ into the data structure:
            Code:
            Dcl-F TPRecu Disk(240);
            dcl-ds DSTPRecu Len(240);
               ITEM      CHAR(10) POS(1);
               PRICE     PACKED(11:3) POS(11);        
               QUANTITY  ZONED(4:0) POS(26);   //   No "type" in the I specs, so it has to be zoned
               TYPE      CHAR(15) POS(30);
               WHATEVER  CHAR(205) POS(36);
            end-ds;​
            
            Read TPRecu DSTPRecu;
            DoW not %eof(TPRecu);
               Read TPRecu DSTPRecu;
            EndDo;​
            You don't need the SETLL since the file will already be positioned at the beginning. (Unless you want to process it again ...)

            Comment


            • #7
              Ok, thanks for all the replies. I tried it and it seems to work.

              Comment

              Working...
              X