185 pts.
 How to write flat file data into pf?
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? 

 

 



Software/Hardware used:
ASKED: August 27, 2010  4:12 AM
UPDATED: August 30, 2010  8:52 AM

Answer Wiki:
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
Last Wiki Answer Submitted:  August 30, 2010  8:40 am  by  TomLiotta   107,935 pts.
All Answer Wiki Contributors:  TomLiotta   107,935 pts. , CharlieBrowne   32,825 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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,540 pts.

 

To clarify, CharlieBrowne responded first with the RPG suggestion. I only added the CPYF comments.

Tom

 107,935 pts.

 

Sorry CharlieBrowne, I overlooked that you were the source. Thanks to Tom for the info :-)
DanF

 2,540 pts.