× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



> If library_exists(my_library_name)
> then
>     dltlib lib(my_library_name)
> end
> What is the CORRECT way of coding that in CL?

Not sure what you mean by "correct", but this is the easiest way:

PGM

    DLTLIB LIB(my_library_name)
    MONMSG MSGID(CPF2110)  /* IGNORE "NOT FOUND" ERROR */

ENDPGM


The above approach assumes success -- and only deals with failure if it
needs to.  If you expect the library to NOT exist more often than not, it
would perform slightly better to check for the object first:

PGM

    DCL VAR(&EXISTS) TYPE(*LGL)

    CHGVAR &EXISTS VALUE('1')
    CHKOBJ OBJ(MYLIB) OBJTYPE(*LIB)
    MONMSG MSGID(CPF9801) EXEC(CHGVAR &EXISTS VALUE('0')

    IF (&EXISTS *EQ '1') DO
        DLTLIB LIB(MYLIB)
    ENDDO

ENDPGM

IMHO, this code is more complex to read and to maintain, so unless it'll
make a significant difference (or if you want to do something other than
delete the library when it exists) I'd opt for the first technique.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.