ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to convert data from flat file into Physical File

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

  • How to convert data from flat file into Physical File

    Hi,

    I have a situation, data is entered using program described files. Therefore, the data is in flat file format (means it is not distributed amongs fields it is stored like continues stream of numbers without any spaces).

    Now, is there any way to use such flat file data in physical file. How to converty(populate) the data into the respective fields defined in physical file.

    Kaleem

  • #2
    Re: How to convert data from flat file into Physical File

    I would suggest creating a file via DDS or SQL and define the layout of the file exactly as your flat file. Then do a CPYF command from the flat file to your defined file with FMTOPT(*NOCHK).
    Jonas Temple
    Got FROG?
    Got Tadpole? No, because it's not done yet! Stay tuned....

    01010111 01100001 01110011 01110011 01110101 01110000 00100000 01100100 01101111 01100111 00111111

    Comment


    • #3
      Re: How to convert data from flat file into Physical File

      A flat file is a physical file. An externally defined file has the layout - field names, lengths, etc - stored with the file. The data will look the same as you describe above. An externally defined file can be processed in a program as you describe above.

      Are you sure the file is not externally defined?

      If so, you will have to create DDS specifications for the new file, compile it and copy the data across usong CPYF or a program you write for the purpose.


      John McKay
      jmckay@mckaysoftware.ie
      We offer website development and custom software on AS400. We also create spreadsheets.
      John McKay
      jmckay@mckaysoftware.ie
      http://www.rpglanguage.com

      Comment


      • #4
        Re: How to convert data from flat file into Physical File

        If the new file is not EXACTLY like the flat file, you can write a simple RPG pgm that reads the flat file (with pgm described fields) and writes to the externally defined file.

        Comment


        • #5
          Re: How to convert data from flat file into Physical File

          post some code please and we can help you better.


          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #6
            Re: How to convert data from flat file into Physical File

            Hi,

            Thanks for suggestions, let me clear the situation more,

            I have lots of data previously entered using program described files(all the fields thier lengths,positons etc. were described in the program; that makes the program so lengthy).

            Now I have created externally defined Physical files with same field names and lengths, problem comes when I need to populate the data from those program described files into externally defined physicla files. The data seems like contenious stream of numbers without any specification of field names above them(so that one could recognize that from this position to that position the data is of field1).

            How to converty(populate) data from such flat file into DDS defined physical files which shows field names above them and are properly manageable.

            There is no such code I could post on this matter because it is purely a logical thing to do.

            If any one could propely guide me and post any code or logic to do this work, I would be thankful.


            Kaleem.

            Comment


            • #7
              Re: How to convert data from flat file into Physical File

              Hi Kaleem,

              Since all the fields are described in your program, I believe that their lenth, position etc will also be described in the program. Now you need to describe all the fields with the same attributes in your new file which you have done already.

              please don't bother that fields are not having the heading etc. just do a cpyf to your created file having the fields same as described in the program.

              Hope it will work, pls let me know for any info......

              Thanks.

              Comment


              • #8
                Re: How to convert data from flat file into Physical File

                If you new file has the right lengths, types etc as the old file, simply follow jtemple's suggestion>

                CPYF FROMFILE(OLDFILE) TOFILE(NEWFILE) MBROPT(*REPLACE) FMTOPT(*NOCHK)

                Comment


                • #9
                  Re: How to convert data from flat file into Physical File

                  Beware of numeric fields. They may or not be packed or binary or whatever in the original program specs, so ensure that your DDS definitions match.

                  John McKay,
                  jmckay@mckaysoftware.ie
                  We offer website development and custom software on AS400. We also create spreadsheets.
                  John McKay
                  jmckay@mckaysoftware.ie
                  http://www.rpglanguage.com

                  Comment


                  • #10
                    Re: How to convert data from flat file into Physical File

                    This sequel code may be useful.

                    the case :
                    changing uploaded field into numeric field :

                    example data :

                    PARTNO---------ONHAND
                    1A1135 2
                    1A1734 3
                    1R0157 5

                    Solution :

                    - COBOL
                    working-storage section.
                    01 break-into.
                    05 partno pic x(20).
                    05 qtyhnd-char pic x(05).
                    01 qyhnd-x pic x(01) occurs 5.
                    01 qyhnd-9 pic 9(05).
                    01 ii pic 9.
                    procedure division.
                    .
                    .
                    convert-from-karakter-2-num.
                    move qyhnd-karakter qyhnd-x.
                    * make QYHND right justify ...
                    perfrom varying ii from 5 to 1 until ii = 1
                    if qyhnd(ii) = " "
                    move qyhnd(ii - 1) to qyhnd(ii)
                    end-if
                    end-perform.
                    * make leading spaces become leading zero.
                    inspect qyhnd-x replacing all " " with "0".
                    * move 0000n to numerik field
                    move qyhnd-x to qyhnd-9.

                    - SEQUEL
                    execute 'select
                    sst(rcdname,1,20) name(partno), /* extract partno */
                    wdata(translate(rtrim(sst(rcdname,21,5))," ","0")) name(qyhndx),
                    zoned(qyhndx,5,0) name(qyhnd9)
                    from library/sourcefile'
                    outfile(library/resultfile)

                    explanation :
                    wdata(translate(rtrim(sst(rcdname,24,5))," ","0")) name(qyhndx),
                    ----------------- SST (substring), extract onhand
                    ------------------------ rtrim, right justify
                    ------------------------------------- translate, change space to 0
                    ---------------------------------------------- wdata, working data, field will not be :
                    displayed (for sequel display command)
                    writed (for insert and execute)
                    zoned(qyhndx,5,0) name(qyhnd9) Zoned, change manipulated above wdata
                    from char to numeric (zoned)

                    Hope this code useful ...

                    Comment


                    • #11
                      Re: How to convert data from flat file into Physical File

                      you know the length of the fields,then it is easier to do with data structures...
                      for example..you have the record length of 100 in that flat file.you having situation to move that into 10 fields of 10 field length...........u define the data structure of 100 length...and subfields as 10 length and then move into the physical file....try this./..............

                      Comment


                      • #12
                        Re: How to convert data from flat file into Physical File

                        Originally posted by rajapandian View Post
                        you know the length of the fields,then it is easier to do with data structures...
                        for example..you have the record length of 100 in that flat file.you having situation to move that into 10 fields of 10 field length...........u define the data structure of 100 length...and subfields as 10 length and then move into the physical file....try this./..............
                        Why are you pulling up threads over a year old and replying to them? by now either the problem is resolved or the programmer has been fired or taken up a new career...
                        I'm not anti-social, I just don't like people -Tommy Holden

                        Comment


                        • #13
                          Re: How to convert data from flat file into Physical File

                          its a little off-topic - but can anyone give me advice on how to do the CISC-RISC conversion?
                          predictably positive, permanently punctilious, purposely proactive, potentially priceless, primarily professional : projex

                          Comment


                          • #14
                            Re: How to convert data from flat file into Physical File

                            Hey Finkpad:

                            I got that one down to one program:

                            Code:
                            D System          S              4A   Inz('Cisc')   
                             /Free                                              
                                     %Subst(System : 1 : 1) = 'R';              
                                     Dsply (System);                            
                                     *Inlr = *On;                               
                             /End-Free
                            Hope that helps
                            GLS
                            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

                            Comment


                            • #15
                              Re: How to convert data from flat file into Physical File

                              Surely you mean

                              Code:
                              C         MOVEL 'CISC'      SYSTEM      4
                              C         MOVEL 'R'         SYSTEM
                              C         SETON                                LR
                              predictably positive, permanently punctilious, purposely proactive, potentially priceless, primarily professional : projex

                              Comment

                              Working...
                              X