Database Creation using CLP

130 pts.
Tags:
CLP
Hello Everybody,

I have a small question. First I will explain my requirement.

Requirement:

I have a database file let’s say “PF1”; I am fetching some records from this file based on some criteria. This fetched record I have to write to one database file “PF2” (This contain six fields). This database file (PF2) doesnt exist and I have to create it before I start writing. And after the successful completions of data write in “PF2”, I am using one utility to mail the data’s of “PF2” to one email id as an excel sheet. Once after sending this email I want to delete the file.

Question:

Can any one please tell me the way to create a physical file at run time? (This physical file should contain six fields with column heading also).

 



Software/Hardware used:
AS400 - CLP

Answer Wiki

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

You can use SQL to CREATE TABLE
OR
If you have the database created ahead of time in another library, you can use CRTDUPOBJ.

——————————————

If both PF1 and PF2 contain only the same six fields and you simply want to create a subset of the records then Create Duplicate Object of PF1 to PF2 (with DATA(*NO)) would get you the desired PF2. You could then write the appropriate records to PF2.

Depending on the data merge utility you are using you may also (in the above scenario) be able to simply add a temporary member to PF1 (called PF2), write the appropriate records to PF2, merge the data of this member into the spreadsheet, and then remove the member.

If the six fields of PF2 are a subset of the greater-than six fields found in PF1 and if the six fields are known in advance then you could create an appropriate (empty) file in advance (PF2_Model), use CRTDUPOBJ from PF2_Model to PF2, and then write the appropriate records to PF2.

If the six fields of PF2 are a subset of the greater-than six fields found in PF1 and the six fields are not known in advance (which I suspect is not the case as your intent is to merge the contents of PF2 into an existing spreadsheet) then you could either:

1. Use SQL Create Table and write the appropriate records to PF2
or
2. Write the appropriate DDS defining PF2 to a source file, create PF2 using the Create Physical File (CRTPF) command, and then write the appropriate records to PF2

In the above cases “write the appropriate records to PF2″ may be the Copy File (CPYF) command if your selection criteria is simple enough, writing records from your CLP using CL for Files (CLF) commands such as Write Record using CLF (WRTRCDCLF), or some other mechanism.

As you can see, there is more than one way.

Bruce Vining

Discuss This Question:  

 
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

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