Selective file copy
Selective file copy is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Copy part of input records to an output file.
Show how file processing as known from PL/I or COBOL can be implemented in the language of your choice.
PL/I
<lang pli>*process source attributes xref or(!);
copys: Proc Options(Main); Dcl 1 s1 unal, 2 a Char(5), 2 b Char(5), 2 c Bin Fixed(31), 2 d Char(5); Dcl 1 s2, 2 a Char(5), 2 c Pic'99', 2 x Char(5) Init('XXXXX'); Dcl o1 Record Output; /* create a test file */ Dcl in Record Input; Dcl out Record Output; Do i=1 To 5; s1.a=repeat('A',i); s1.b=repeat('B',i); s1.c=i; s1.d=repeat('D',i); Write File(o1) From(s1); End; Close File(o1);
On Endfile(in) Goto eoj; Do i=1 By 1; /* copy parts of the test file */ Read File(in) Into(s1); s2=s1, by name; /* only fields a and c are copied */ Write File(out) From(s2); End; eoj: End;
</lang>
- Output:
AA 01XXXXX AAA 02XXXXX AAAA 03XXXXX AAAAA04XXXXX AAAAA05XXXXX