Question

  Asked: Apr 11 2008   4:05 AM GMT
  Asked by: It doubts


how to write all the matching records in to antoher file in CL program


CLLE, FNDSTRPDM, CL

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.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0




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.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on AS/400.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Sloopy  |   Apr 11 2008  3:35PM GMT

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