CL/400 program for copying files

265 pts.
Tags:
AS/400 administration
CL
CL/400
regarding as/400. I need to create a CL program for copying all files from HWMSFMODS(library) to HEXPFMODS(library). we are suppose to clear all data in from files. Please advice...

Answer Wiki

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

Hi,

1. First do a DSPOBJD to an output file.
2. Read the DSPOBJD file in your CL program using RCVF.
3. If end of file, goto end.
4. Use CPYF to copy your file from one library to the other. You can specify REPLACE(*YES) and CRTFILE(*YES)
— phil’s addition you may need to set the from member and to member to *ALL
5. Clear the from file.
6. Go to (2) read file.

Regards,

Martin Gilbert.

////////////////
Note above: just in case include all members

It’s assumed that library HEXPFMODS is empty when this process starts.
If files with the same name exist in HEXPFMODS they will be overwritten by this process if they are
of identical structure, an error will occur if they aren’t.

— just copy physical files – source and data types
— logical files would require different handling I think.
Are there any other types of objects in the from library?
Phil
*********************************************************
No Gilly’s logic is for all the physical files in the library – when you do the DSPOBJD
the Object is *ALL and Object Type is *FILE to an outfile
so you now have a list of all files

His logic loops through this file and copies each physical file.

Phil

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
  • Askt
    I hope above one is used for single file transfer. actually i need to copy all files in library at the time.
    265 pointsBadges:
    report
  • WoodEngineer
    If your destination library is empty . . . might want to try CRTDUPOBJ OBJ(*ALL) OBJTYPE(*ALL). One thing to check after the copy - be sure the logicals in the destination library point to physicals also in the destination library.
    6,680 pointsBadges:
    report
  • Gilly400
    Hi, Here's a program which should do this for you - (I haven't tested this):- PGM DCL VAR(&FROMLIB) TYPE(*CHAR) LEN(10) VALUE(HWMSFMODS) DCL VAR(&TOLIB) TYPE(*CHAR) LEN(10) VALUE(HEXPFMODS) DCLF QADSPOBJ DSPOBJD OBJ(&FROMLIB/*ALL) OBJTYPE(*FILE) OUTPUT(*OUTFILE) OUTFILE(QTEMP/DSPOBJD) OVRDBF QADSPOBJ QTEMP/DSPOBJD READ: RCVF MONMSG CPF0864 EXEC(GOTO ENDPGM) /* Copy File */ CPYF FROMFILE(&ODLBNM/&ODOBNM) TOFILE(&TOLIB/&ODOBNM) FROMMBR(*ALL) TOMBR(*FROMMBR) MBROPT(*REPLACE) CRTFILE(*YES) /* Clear from file */ CLRPFM &ODLBNM/&ODOBNM *ALL GOTO READ ENDPGM: ENDPGM Make sure you have a backup before you start, of course... Regards, Martin Gilbert.
    23,730 pointsBadges:
    report
  • RonKoontz
    Just copy the file QSYS/QADBXREF!!! use CPYF to copy this file to a new file and put the library you want. This file is a list of everything in the file already. Then read the file in the CL program and copy. I do this every Sunday night to update our test environment. You cold also go one step further. I put code to check the objects change date and time and only copy the file if its been change in the last 7 days. This codes works for us but you will have to modify it for your won needs. Code: DCL VAR(&USEDATE) TYPE(*CHAR) LEN(8) DCL VAR(&USEDATEC) TYPE(*CHAR) LEN(8) DCL VAR(&JUL) TYPE(*CHAR) LEN(7) DCL VAR(&MDAY) TYPE(*DEC) LEN(3 0) DCL VAR(&MDAY1) TYPE(*CHAR) LEN(3) DCL VAR(&JULADD) TYPE(*DEC) LEN(6 0) DCL VAR(&DBXLIBTST) TYPE(*CHAR) LEN(10) DCLF FILE(RSTFILE) OPNID(RSTLIST) DCL VAR(&EOF) TYPE(*LGL) RTVJOBA DATE(&USEDATEC) CVTDAT DATE(&USEDATEC) TOVAR(&JUL) FROMFMT(*MDY) + TOFMT(*JUL) CHGVAR VAR(&MDAY) VALUE(%SST(&JUL 4 3)) CHGVAR VAR(&JULADD) VALUE(&MDAY - 7) CHGVAR VAR(&MDAY1) VALUE(&JULADD) CHGVAR VAR(&JUL) VALUE(%SST(&JUL 1 3) *TCAT &MDAY1) CVTDAT DATE(&JUL) TOVAR(&USEDATEC) FROMFMT(*JUL) + TOFMT(*CYMD) TOSEP(*NONE) CPYF FROMFILE(QSYS/QADBXREF) TOFILE(NEW/RSTFILE) + MBROPT(*REPLACE) CRTFILE(*YES) + TORCD(*END) INCREL((*IF DBXLIB *EQ + 'TLDB70') (*AND DBXATR *EQ 'PF') (*OR + DBXLIB *EQ 'YOURLIBRARY') (*AND DBXATR *EQ 'PF')) + FMTOPT(*NOCHK) CHGVAR &EOF '0' DOUNTIL COND(&EOF) RCVF OPNID(RSTLIST) MONMSG MSGID(CPF0864) EXEC(DO) CHGVAR VAR(&EOF) VALUE('1') ITERATE ENDDO RTVMBRD FILE(&RSTLIST_DBXLIB/&RSTLIST_DBXFIL) + USEDATE(&USEDATE) IF COND(&USEDATE *GE &USEDATEC) THEN(DO) CPYF FROMFILE(&RSTLIST_DBXLIB/&RSTLIST_DBXFIL) + TOFILE(&DBXLIBTST/&RSTLIST_DBXFIL) + MBROPT(*REPLACE) CRTFILE(*YES) FMTOPT(*NOCHK) MONMSG MSGID(CPF0000) ENDDO ENDDO ENDPGM
    1,780 pointsBadges:
    report
  • Gilly400
    Hi, That's a good tip! I always forget about the cross ref files - probably comes from using the S/36 environment for so long (the S/36 environment files don't show up in the cross ref files). I always find using DSPOBJD and DSPFD so slow...Will try and remember to use the cross reference files in future. Regards, Martin Gilbert.
    23,730 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