85 pts.
 how to write all the matching records in to antoher file in CL program
hi, i am having a pf in that pf contain many members, using display file i have to search a perticular string in all the members if it is found these matching records want to write into another file this is my requirement. in CL grogram how to do this? using FNDSTRPDM can we do that, please replay me if any other solution please send me with example.

Software/Hardware used:
ASKED: April 11, 2008  4:05 AM
UPDATED: April 11, 2008  3:35 PM

Answer Wiki:
Hi, I don't think you can do this using CL, I think you'll need to get into using another programming language for this. What you can try is using FNDTRPDM to a spooled file, and copy the spooled file to a physical file. But this is going to give you all the formatting that you have in a FNDSTRPDM print. Regards, Martin Gilbert.
Last Wiki Answer Submitted:  April 11, 2008  9:16 am  by  Gilly400   23,625 pts.
All Answer Wiki Contributors:  Gilly400   23,625 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

There is a way to do what you want, using the CPYF (Copy File) command.

CPYF will copy from multiple members in a file, and you can search for a string too. So, to get what you want, use something like this (my test program for this problem) :

PGM                                      
                                         
DCL        VAR(&CHAR) TYPE(*CHAR) LEN(20)
                                         
CRTPF      FILE(QTEMP/TEMP1) RCDLEN(200) 
MONMSG     MSGID(CPF0000)                
                                         
CHGVAR     VAR(&CHAR) VALUE('Programmer')
                                         
CPYF       FROMFILE(TGSMSRCDEV/QCLSRC) + 
              TOFILE(QTEMP/TEMP1)      + 
              FROMMBR(*ALL)            + 
              MBROPT(*REPLACE)         + 
              FMTOPT(*CVTSRC)          + 
              INCCHAR(*RCD 1 *CT &CHAR)  
                                         
DSPPFM     FILE(TEMP1)                   
                                         
ENDPGM                                   

Notes:

- The scan is case-sensitive; there is nothing you can do about that.

- In the example, I create a TO file. Because it is a different format to the FROM file, and the FROM file is a SOURCE file, I have to use the parameter FMTOPT(*CVTSRC), which ‘converts’ the source data in the FROM file to a string which is placed into the first (or only) field in the TO file.

- If the FROM file and the TO file are both ‘ordinary’ database files, and not SOURCE files, you must use FMTOPT(*NOCHK) if their formats are different.

- If the FROM and TO files have the same format (either the TO file was created using CRTDUPOBJ from the FROM file, or you let CPYF create it by specifying CRTFILE(*YES)), you do not need the FMTOPT parameter.

If the CPYF command is not able to do what you want, you may be able to get somewhere using SQL – but that will be a lot more complicated.

Regards,

Sloopy JB

 2,195 pts.