How to write flat file data into pf?

185 pts.
Tags:
AS400 physical file
Flat files
Physical File
RPGLE
Hi,,  M25 is one of my flat file which is 34 char length. I want to write data from flat file to normal pf. Pf contains 3 char field which is equally devide.

Now generaly to read file we have to requre key field but flat file doesn't have any key field then how i will write this pf? 

 

 

Answer Wiki

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

You define the input file within your RPG Specs
Then read through the file moving data to the fields in the output file and do a WRITE
Here is some sample code
<pre>
FM25 IF F 34 DISK
FOutFile O E Disk
IM25 AA 01
I 1 34 Rec
/Free
Read M25;
DoU %EOF(M25);
Ouput = Rec;
Read M25;
Write OutFileR;
EndDo;
*InLr = *On;
/End-Free</pre>

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

If your flat file is 34 characters wide, and your externally-described file is also 34 characters wide and has its field definitions lined up with the appropriate positions in the flat file, you use the CPYF command with the FMTOPT( *NOCHK ) parameter value set.

FMTOPT( *NOCHK ) tells CPYF to copy record images without checking field constraints.

Tom

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.

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
  • DanTheDane
    Several options are vailale to do what you want. Tom mentiond two of them. I'll supply you with 2 other options: 1. Use Query/400 over your flat file, and define result fields within the query using the fieldnames and field attributes from the target pf (SUBSTR from flat file). Then select Output type as '3' ('Database file'), whereafter you will be prompted for the name and lib of the outputfile ; - use '4' or '5' to replace/add to member. Having created the query, use RUNQRY command in your application-CL. That's it.. 2. Use RPG cycle. Using Tom's RPG code as model, here is my version, which uses the RPG-cycle for automatic reading a file from start till end ('ip' (input primary)). Thus there is no need for any more RPG-code to readthe file and end the program - the 'cycle' does just that.
    fM25       ip   f   34        disk
    foutfile   o  a e             disk
    iM25       aa  01
    i                                  1   34  Rec
     /free
         F1    = %subst(Rec: 1:11);
          .
          .
         Fn    = %subst(Rec:12:11);
         Write OutFileR;
    
    Since you'l propably need to move data to fields, I inserted some lines assuming fieldnmes in targetfile to be F1, F2 etc. It is often claimed that this method is executing faster tha doing your on read. Well, - I did some tests (timestamp added to outputrec) on this and must report that on a 10+ mio recs inputfile, the IP-model used 82 secs whereas Tom's READ-model used 80 secs. I recommend you to use the READ-model, since this code is propably more clear to maintain for the future, even though I (being an oldtimer) is still fascinated by the fact that the IP-model reduces needed coding. DanF
    2,555 pointsBadges:
    report
  • TomLiotta
    To clarify, CharlieBrowne responded first with the RPG suggestion. I only added the CPYF comments. Tom
    125,585 pointsBadges:
    report
  • DanTheDane
    Sorry CharlieBrowne, I overlooked that you were the source. Thanks to Tom for the info :-) DanF
    2,555 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