Create flat file in AS/400

5 pts.
Tags:
AS/400
Flat files
RPG
Is there a sample code in RPG to create a flat file?

Answer Wiki

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

Not to create the file but to load data into the file

Discuss This Question: 3  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.
  • philpl1jb

    You may not need an RPG program to do this but if you do ..

    1. Use the CRTPF to create a physical file with

    Record length, if no DDS long enough for your needs

    2.  Get the first data set

    3.  Populate the field (which will have the same name as the file) with data using string functions to put the data into the field .. and whatever delimiters you need.

    4,  Write the row

    5.  Repeat

    54,090 pointsBadges:
    report
  • ToddN2000
    Another option is after defining your file like philpl1jb mentioned, user the rename option to change the field name in the file. Then define it as a data structure by adding all the fields you want to have in your flat file. Then read you data, build the DS and then write your record.
    107,875 pointsBadges:
    report
  • WashingtonW
    If you're using SQL to load data into a flat file, just do a simple INSERT.

    Just make sure that the field name (which is the same name as the file if you used the default) is correct.

    Example:

    CRTPF FILE(mylib/myflatfile) RCDLEN(100)

    Now, to add records using SQL, do:

    INSERT INTO mylib/myflatfile (myflatfile) VALUES('the data I want');

    Of course, you could use variables as well.  In SQLRPGLE:

    variable = 'the data I want';
    exec sql INSERT INTO mylib/myflatfile (myflatfile) VALUES(:variable);




    10 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: