How to read physical file and split to another physical file

Tags:
AS 400
AS/400 physical file
Hi, how to split physical file when we have first column is 1? that means page break. Than create new physical file automatically when split file.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can do it a number of ways. Use the WRKQRY and select only the records you want and send the output to create a new file. A simple CPYF
withe a field test would work as well. Another option to split the file would be with an SQL. Create the new PF the use the SQL command INSERT INTO. If you need multiple splits you could probably do it with a CASE as well.

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Can you be more specific? What type of computer are you on like an i-Series, PC, Mac? What OS is it running? How is the file defined meaning is it a PF on an i-Series or one of the following PC formats TXT, XLS CSV or something else?

    You may need to do a bit of coding to split it up and rename the new files it would create.
    136,240 pointsBadges:
    report
  • mmanley
    If you're on an AS/400(iSeries), you can use the CPYF command. Press F10 after entering the current and new file names, etc. and use the INCCHAR (include records by char test) option to select specific records.
    470 pointsBadges:
    report
  • TheRealRaven
    It sounds as if you have the output for a printer file put into a physical file. The "1" would be a 'new page' indicator.

    Practically speaking, you can either create a program to do the basic work of splitting or do it manually. With a little more info, a method might become clear; but functions such as CPYF, WRKQRY and SQL won't work directly.

    A major useful detail -- Is the "1" always on an empty line, or is there other data following it on that line?
    36,880 pointsBadges:
    report
  • amiruladli95
    Thanks because replying. I'm using AS/400 (iSeries). In physical file I have record starting '1' follow by other data (Flat File). Not the empty data. Data might be like that:

    1    ABCD
          EFGH
          LFMN     
    1    OPQR
          STUV
          WXYZ
    40 pointsBadges:
    report
  • ToddN2000
    If that is a sample of the data, then I can only think of doing it programaticaly. Read the file by RRN, check for the 1 to determine the writing of a new file. You could get a bit fancy and make the output file user controlled and in you program call another that copies the output file, renames it and clears it for use for the next file break.
    136,240 pointsBadges:
    report
  • amiruladli95
    Thanks a lot Mr.
    40 pointsBadges:
    report
  • BigKat
    @amiruladli95

    I am not trying to attack you or make fun of you, but I am assuming you are from an Asian area and I wanted to offer some friendly advice.

    The phrase "Thanks a lot Mr" (and "Thanks a lot" in general) has a very sarcastic and negative tone to the Western ear.  It would be better to say "Thank you very much" when you want to express gratitude.
    9,460 pointsBadges:
    report
  • TheRealRaven
    The major problem with trying to do it with SQL or any other "utility" function is that the output files need to be generated dynamically without actually knowing how many there will be.

    The new file names will be generated each time a "1"-record is encountered. At that time, any current output file should also be closed.

    I haven't thought it through, but a complex compound SQL statement could bet close. E.g., a CTE would start perhaps by building a temp table of "1"-records to mark their relative record numbers. That makes it easy enough to get the first block of rows to the first output table, but no clear way to shift the next block to another file.

    Some programming will get it done faster. Some basic RPG plus a couple CL commands should do it.
    36,880 pointsBadges:
    report
  • WoodEngineer
    Do you want to do this with a traditional RPG program or are all options open?
    8,235 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: