CPYF selecting a record by a variable

440 pts.
Tags:
AS/400
CL
CPYF
Hi friends, I have a CL and I dont know how making a cpyf selecting records with a variable, like this example: 5722SS1 V5R3M0 040528 Control Language DLTOLDSPLF/CARGA TDBSBC14 04/06/08 19:54:32 Page 1 Program . . . . . . . . . . . . . . . . . . . : CARGA Library . . . . . . . . . . . . . . . . . . : DLTOLDSPLF Source file . . . . . . . . . . . . . . . . . : QCLSRC Library . . . . . . . . . . . . . . . . . . : DLTOLDSPLF Source member name . . . . . . . . . . . . . : CARGA 04/06/08 19:54:29 Source printing options . . . . . . . . . . . : *SOURCE *XREF *GEN *NOSECLVL *NOSRCDBG *NOLSTDBG Program generation options . . . . . . . . . : *NOLIST *NOXREF *NOPATCH User profile . . . . . . . . . . . . . . . . : *USER Program logging . . . . . . . . . . . . . . . : *JOB Allow RTVCLSRC command . . . . . . . . . . . : *YES Replace program . . . . . . . . . . . . . . . : *YES Target release . . . . . . . . . . . . . . . : V5R3M0 Authority . . . . . . . . . . . . . . . . . . : *LIBCRTAUT Sort sequence . . . . . . . . . . . . . . . . : *HEX Language identifier . . . . . . . . . . . . . : *JOBRUN Text . . . . . . . . . . . . . . . . . . . . : Deleta spoolfiles com mais de NN dias Compiler . . . . . . . . . . . . . . . . . . : IBM iSeries Control Language Compiler Control Language Source SEQNBR *...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+... 9 ...+. DATE 100- PGM /* Deleta spoolfiles com mais de NN dias */ 03/06/08 200- DCLF FILE(DLTOLDSPLF/REC_SFT) /* este arquivo é + 03/06/08 300 gerado na QRY */ 03/06/08 QUALIFIED FILE NAME - DLTOLDSPLF/REC_SFT RECORD FORMAT NAME - REC_SFT CL VARIABLE TYPE LENGTH PRECISION TEXT &SPLFNAM *CHAR 10 SUBSTR(WRKSPLF,2,10) &USRNAM *CHAR 10 SUBSTR(WRKSPLF,13,10) &USRDTA *CHAR 10 SUBSTR(WRKSPLF,35,10) &STATUS *CHAR 3 SUBSTR(WRKSPLF,46,3) &TOTPAG *CHAR 5 SUBSTR(WRKSPLF,51,5) &SPLDAT *CHAR 6 SUBSTR(WRKSPLF,89,2)|| SUBSTR(WRKSPLF,86 &SPLTIM *CHAR 8 SUBSTR(WRKSPLF,92,8) &SPLNBR *CHAR 5 SUBSTR(WRKSPLF,102,5) &JOBNAM *CHAR 10 SUBSTR(WRKSPLF,108,10) &JOBNBR *CHAR 6 SUBSTR(WRKSPLF,119,6) &QNAM *CHAR 10 SUBSTR(WRKSPLF,126,10) &QLIB *CHAR 10 SUBSTR(WRKSPLF,137,10) 400- 03/06/08 500- DCL VAR(&SYSDATE) TYPE(*CHAR) LEN(6) 02/06/08 600- 03/06/08 700- WRKSPLF SELECT(RBDSILVA) OUTPUT(*PRINT) 03/06/08 800- CRTPF FILE(QTEMP/WRKSPLF) RCDLEN(170) SIZE(*NOMAX) 02/06/08 900- 03/06/08 1000- MONMSG MSGID(CPF7302) 02/06/08 1100- 03/06/08 1200- CPYSPLF FILE(QPRTSPLF) TOFILE(QTEMP/WRKSPLF) 03/06/08 1300- MONMSG MSGID(CPF3340) 04/06/08 5722SS1 V5R3M0 040528 Control Language DLTOLDSPLF/CARGA TDBSBC14 04/06/08 19:54:32 Page 2 Control Language Source SEQNBR *...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+... 9 ...+. DATE 1400- 03/06/08 1500- OVRDBF FILE(REC_SFT) TOFILE(DLTOLDSPLF/REC_SFT) 03/06/08 1600- 03/06/08 1700- RUNQRY QRY(DLTOLDSPLF/REC_SFT) 03/06/08 1800- 03/06/08 1900- RTVSYSVAL SYSVAL(QDATE) RTNVAR(&SYSDATE) 02/06/08 2000- 03/06/08 2100- CVTDAT DATE(&SYSDATE) TOVAR(&SYSDATE) FROMFMT(*DMY) + 03/06/08 2200 TOFMT(*YMD) TOSEP(*NONE) 03/06/08 2300- ler: 03/06/08 2400- 04/06/08 2500- IF COND(&SPLDAT *NE &SYSDATE) THEN(GOTO + 04/06/08 2600 CMDLBL(LER)) 03/06/08 2700- else cmd(do) 03/06/08 2800- 04/06/08 2900- CPYF FROMFILE(DLTOLDSPLF/REC_SFT) + 04/06/08 3000 TOFILE(QTEMP/REC_SFT) FROMMBR(*FIRST) + 04/06/08 3100 MBROPT(*REPLACE) CRTFILE(*YES) + 04/06/08 3200 INCREL((*IF &SPLDAT *EQ &SYSDATE)) + 04/06/08 3300 FMTOPT(*MAP *DROP) 04/06/08 3400- ENDDO 03/06/08 3500- 04/06/08 3600- CPYTOPCD FROMFILE(QTEMP/REC_SFT) TOFLR(TOYOTA) + 03/06/08 3700 TODOC(REC_SFT.TXT) REPLACE(*YES) 03/06/08 3800- 03/06/08 3900- SNDDST TYPE(*DOC) + 03/06/08 4000 TOINTNET((rbdsilva.ts@uol.com.br)) + 03/06/08 4100 DSTD('Informacoes das Execucoes do Job + 03/06/08 4200 REC_SFT') MSG('Segue anexo checklist das + 03/06/08 4300 execucoes do Job REC_SFT') CFMDEL(*YES) + 03/06/08 4400 PTY(*HIGH) USRID(*CURRENT) + 03/06/08 4500 DOC(REC_SFT.TXT) FLR(TOYOTA) + 03/06/08 4600 SUBJECT('CHECKLIST REC_SFT') 03/06/08 4700- MONMSG MSGID(CPF0000) 03/06/08 4800- fim: 03/06/08 4900- ENDPGM 02/06/08 * * * * * E N D O F S O U R C E * * * * * 5722SS1 V5R3M0 040528 Control Language DLTOLDSPLF/CARGA TDBSBC14 04/06/08 19:54:32 Page 3 Cross Reference Declared Variables Name Defined Type Length References &JOBNAM 200 *CHAR 10 * CPD0726 10 Variable &JOBNAM declared but not referred to. &JOBNBR 200 *CHAR 6 * CPD0726 10 Variable &JOBNBR declared but not referred to. &QLIB 200 *CHAR 10 * CPD0726 10 Variable &QLIB declared but not referred to. &QNAM 200 *CHAR 10 * CPD0726 10 Variable &QNAM declared but not referred to. &SPLDAT 200 *CHAR 6 2500 2900 &SPLFNAM 200 *CHAR 10 * CPD0726 10 Variable &SPLFNAM declared but not referred to. &SPLNBR 200 *CHAR 5 * CPD0726 10 Variable &SPLNBR declared but not referred to. &SPLTIM 200 *CHAR 8 * CPD0726 10 Variable &SPLTIM declared but not referred to. &STATUS 200 *CHAR 3 * CPD0726 10 Variable &STATUS declared but not referred to. &SYSDATE 500 *CHAR 6 1900 2100 2100 2500 2900 &TOTPAG 200 *CHAR 5 * CPD0726 10 Variable &TOTPAG declared but not referred to. &USRDTA 200 *CHAR 10 * CPD0726 10 Variable &USRDTA declared but not referred to. &USRNAM 200 *CHAR 10 * CPD0726 10 Variable &USRNAM declared but not referred to. Defined Labels Label Defined References FIM 4800 LER 2300 2500 * * * * * E N D O F C R O S S R E F E R E N C E * * * * * 5722SS1 V5R3M0 040528 Control Language DLTOLDSPLF/CARGA TDBSBC14 04/06/08 19:54:32 Page 4 Message Summary Severity Total 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99 11 0 11 0 0 0 0 0 0 0 0 Program CARGA created in library DLTOLDSPLF on 04/06/08 at 19:54:36. Program CARGA created in library DLTOLDSPLF. Maximum error severity 10. * * * * * E N D O F M E S S A G E S U M M A R Y * * * * * * * * * * E N D O F C O M P I L A T I O N * * * * *
ASKED: June 5, 2008  1:46 PM
UPDATED: April 25, 2010  7:57 AM

Answer Wiki

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

Thanks Martin

I have a Physical file and this phisical have this field:
&SPLDAT *CHAR 6 SUBSTR(WRKSPLF,89,2)|| SUBSTR(WRKSPLF,86

I need read this file and compare if the field &SPLDAT is equal the variable Sysdate, if this information is equal, only copy this records.

Thanks for Your help

Hi,

Can you explain exactly what your question is?

Regards,

Martin Gilbert.

————————————————————————-
Hi, Silvarb.

Wow, there is a lot wrong with your program! I suspect that you have been dropped in at the deep end.

I assume that the RUNQRY populates your DLTOLDSPLF/REC_SFT file from the QTEMP/WRKSPLF file.

First, you need to clear (CLRPFM) the DLTOLDSPLF/REC_SFT file before you do the RUNQRY, unless you intend to ADD records to those already in that file.

Next, although you declare the file, you are not reading it in the program. You need to do a RCVF command, like this:

ler: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDDATA))

The label ENDDATA: will be on your line 3500.

Now when you test the dates, your &SPLDAT variable will not be empty.

Next, you don’t need the ELSE at line 2700, or the ENDDO at line 3400. The IF by itself is enough to skip for the next record when the dates don’t match.

Next, you don’t need the FMTOPT parameter on the CPYF command, since the TO file will be an exact copy of the FROM file.

Now, your loop to read the file will loop around until it finds a record where the spooled file date matches the system date, and then it will do the CPYF, the CPYTOPCD and the SNDDST and then end.

BUT, if it does NOT find any matching dates, it will STILL do all those things. Your CPYF may fall over if the QTEMP file already exists and there are no records to copy. If the QTEMP file does NOT exist, it will be created and will be empty.

I would suggest that there is no need to read the DLTOLDSPLF/REC_SFT file in your program. There is no need for a loop – you just do the copy. In which case, that part of your program will be a lot simpler.

If you don’t want to email an empty file, then after the CPYF you can use the RTVMBRD command with the NBRCURRCD parameter, which takes a numeric CL variable. If that variable is zero, the file is empty and you can do something different, like sending an email which says ‘There are no spooled files for today’.

That’s pretty much it.

However, I am puzzled that the program title seems to show that this program is to delete old spooled files, but the code extracts information about today’s spooled files and sends the information in an email. Really, you ought to make sure that comments accurately reflect the purpose of a program – otherwise when you come back to it in six months, you will get very confused!

If you DO want to delete old spooled files, one way is to use the “Move Spooled Files using BRM” (MOVSPLFBRM) command to move the spooled files you select to a ‘junk’ output queue, then just clear that queue using the CLROUTQ command.

Regards,

Sloopy

Discuss This Question: 5  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
  • SILVARB
    have a Physical file and this phisical have this field: &SPLDAT *CHAR 6 SUBSTR(WRKSPLF,89,2)|| SUBSTR(WRKSPLF,86 I need read this file and compare if the field &SPLDAT is equal the variable Sysdate, if this information is equal, only copy this records. Thanks for Your help
    440 pointsBadges:
    report
  • Gilly400
    Hi, This should do what you want :-
    CPYF FROMFILE(Yourfile) TOFILE(Newfile) CRTFILE(*YES) INCREL((*IF SPLDAT *EQ &SYSDATE)) 
    
    Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • SILVARB
    Sloopy Thanks for Your patiente and cooperation, You and Gilly400 are my best friends !!! Regards, Roberto
    440 pointsBadges:
    report
  • Sloopy
    Thanks! Martin and I will be over for a drink later.... :-D
    2,195 pointsBadges:
    report
  • TomLiotta
    ...you need to clear (CLRPFM) the DLTOLDSPLF/REC_SFT file before you do the RUNQRY, unless you intend to ADD records to those already in that file. RUNQRY allows OUTFILE( ... *RPLMBR) to replace records in a member. This eliminates a need to code a CLRPFM command. And note that MOVSPLFBRM is only available for sites that have BRMS installed. Tom Tom
    125,585 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