Writing to a flat file/stream file in a CL program

1150 pts.
Tags:
CL programming
Flat files
IBM i
Stream files
V6R1
Can we write to a flat file/stream file or both, a variable value using CL program?

Software/Hardware used:
IBM i,V6R1

Answer Wiki

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

Sure, but why would you want to?

I/O for stream files/flat files in the IFS is done using APIs, which are much easier to deal with in a language like RPG or COBOL. Use the right tool for the job.

============================================================

As of V5R4, ILE CL handles streamfile I/O almost the same as ILE RPG, C or COBOL. It’s probably much easier to write in CL, but the APIs will be the same ones. Use the open(), write() and close() APIs. These are listed and described in the Integrated File System APIs topic.

Although these can be easier in ILE CL than other languages, it should probably be done for proofs-of-concept or prototyping or learning, rather than for significant production programming. ILE CL can only include a single procedure in each source module. For some purposes, that is okay for CL.

Tom

Discuss This Question: 2  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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Brijesh
    Create a RPG program that accepts the CL variable as a parameter and writes a record to the flat file.
    9,870 pointsBadges:
    report
  • bvining

    As for the flat file question, with 6.1 that's pretty easy from CL also (assuming that by flat file you mean a non-externally described file).

     

    I created the file FLATFILE with the following command:

     CrtPF QTemp/FlatFile RcdLen(50)

    and then inserted the contents of a CL variable into the file with the following CL program:

    Pgm                                                    
    Dcl        Var(&CLVar)   Type(*Char) Len(50) +         
                 Value('This is my variable value')        
    Dcl        Var(&SQLStmt) Type(*Char) Len(4096)         
                                                           
    ChgVar     Var(&SQLStmt) Value( +                      
                 'Insert into QTemp/FlatFile (FlatFile) +  
                  Values(''' *TCat &CLVar *TCat ''')')     
    RunSQL     SQL(&SQLStmt) Commit(*None)                 
    EndPgm                                                 

    With the 6.1 support for the RunSQL command inserting data into a file from CL is not difficult.

     

    Bruce Vining

    6,620 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following