ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Existance of an object in a library

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Existance of an object in a library

    Hi,

    I need to find out programatically whether an object is present in a library or not.
    Can anyone give me some idea regarding how this is to be done??
    Input Spec:
    Enter the object to find: TSTPGM
    Enter the library to serch: TSTLIB

    Thanks in advance....


    Warm Regards,
    Sudip Kumar Mondal
    Warm Regards,
    Sudip Kumar Mondal
    Pune || Maharastra || India
    Mail:
    s.k.mondal@aol.in || Cell: +919372226093

  • #2
    Re: Existance of an object in a library

    CL Command CHKOBJ!

    Birgitta

    Comment


    • #3
      Re: Existance of an object in a library

      That worked out fine in the program.
      Thanks for the responce...
      Warm Regards,
      Sudip Kumar Mondal
      Pune || Maharastra || India
      Mail:
      s.k.mondal@aol.in || Cell: +919372226093

      Comment


      • #4
        Re: Existance of an object in a library

        If I do not want to use the CL command as answered by one of my friends, then is there any other option available.
        In other words, I just want to implement the CHKOBJ command manually.
        Warm Regards,
        Sudip Kumar Mondal
        Pune || Maharastra || India
        Mail:
        s.k.mondal@aol.in || Cell: +919372226093

        Comment


        • #5
          Re: Existance of an object in a library

          You can use API functions [OR] maybe check qsys2/systables2 for a record corresponding to that file/library.

          What youre asking for is equivalent to "Can I implement the Right Click+Copy function of windows?" - Sure you can, as long as youre willing to go to the lengths of doing it.

          Why do this when the CHKOBJ command has been provided by IBM to do the very same thing?

          Comment


          • #6
            Re: Existance of an object in a library

            Originally posted by vikramx View Post
            ... Why do this when the CHKOBJ command has been provided by IBM to do the very same thing?
            How about...
            1. Most API's are faster than the CL command
            2. Better error handling.
            Regards

            Kit
            http://www.ecofitonline.com
            DeskfIT - ChangefIT - XrefIT
            ___________________________________
            There are only 3 kinds of people -
            Those that can count and those that can't.

            Comment


            • #7
              Re: Existance of an object in a library

              Originally posted by kitvb1 View Post
              How about...
              1. Most API's are faster than the CL command
              2. Better error handling.
              not sure about the "better" error handling. any error handling that can be used for APIs can also be handled using MONMSG in CL. but i agree that APIs can be faster...some commands however are simply easier interfaces that do nothing but call the API directly.

              Originally posted by Sadip
              If I do not want to use the CL command as answered by one of my friends, then is there any other option available.
              In other words, I just want to implement the CHKOBJ command manually.
              if you wanted to "manually" implement a CHKOBJ then why bother to ask for a programmatic way to achieve this? if you are simply wanting to do this interactively (i.e. from a command line) you could simply use WRKOBJ and the objects (if more than one in your library list would be displayed in the order found in your library list.
              I'm not anti-social, I just don't like people -Tommy Holden

              Comment


              • #8
                Re: Existance of an object in a library

                Originally posted by kitvb1 View Post
                How about...
                1. Most API's are faster than the CL command
                2. Better error handling.
                Which one is more intuitive for a newbie? Personally, I prefer the command and MONMSG.

                Comment


                • #9
                  Re: Existance of an object in a library

                  I agree using CL for a newbie is the way to go...
                  I think in a global scope it would be better to put API into a module, then include in service program.
                  then there is only one program to maintain.

                  If you follow the CHKOBJ path, by the time you get to using the API you may have hundreds of CHKOBJ's in
                  multiple programs.

                  I'm just saying...

                  Jamie
                  All my answers were extracted from the "Big Dummy's Guide to the As400"
                  and I take no responsibility for any of them.

                  www.code400.com

                  Comment


                  • #10
                    Re: Existance of an object in a library

                    The following snippet is copied out of the IBM Information Center:

                    System APIs or CL commands--when to use each
                    An API is designed to be used as a programming interface, and a CL command is intended to be entered either interactively or in a CL program.

                    Before system APIs were offered on the system, you had to either code separate CL programs to perform the needed functions using the appropriate CL commands or code a call to the Execute Command (QCMDEXC) API in your program. Both methods made coding an application on the system more cumbersome (less straightforward and not as fast as possible).

                    CL commands will always be needed; they are ideal for the interactive user and for CL applications that are performing basic tasks. They provide a complete set of functions on the system.

                    APIs are not provided as a replacement for CL commands, although in many cases there might be both an API and a CL command that perform the same function. If a CL command and an API provide the same function, at times the API provides more flexibility and information.

                    Some APIs have no equivalent CL commands. These APIs have been provided in areas where customers and business partners have indicated that they need high-level language (HLL) access.
                    API Overview

                    Comment


                    • #11
                      Re: Existance of an object in a library

                      @kit,

                      Perhaps you misunderstood my post. I meant why reinvent the CHKOBJ when you have the command and APIs provided by IBM. I never said that APIs shouldnt be used.

                      Comment


                      • #12
                        Re: Existance of an object in a library

                        I think the most basic answer is that, if the program you are dealing with is an existing CL program, then using the CHKOBJ command is fine.

                        If the existing program is not a CL program, then I would not create a cl program to just run the CHKOBJ cmomand. I would use the api wrapped into a service program. This is so that the wrapped procedure can return a boolean true / false as to whether the object exists, and then the function can be used in an expression inside the program.
                        Michael Catalani
                        IS Director, eCommerce & Web Development
                        Acceptance Insurance Corporation
                        www.AcceptanceInsurance.com
                        www.ProvatoSys.com

                        Comment


                        • #13
                          Re: Existance of an object in a library

                          If it's an RPG Program you can run CHKOBJ through QCMDEXC and check the program status data structure (position 40-46) for CPF9801 or what ever CPFMSG you'll Check!

                          Code:
                          D PGMSDS        SDS                                 Qualified
                          D   MsgId                              40   46
                          
                          D CLCmd           S                        256A
                           /Free
                              CLCmd = 'CHKOBJ OBJ(QTEMP/MYTABLE) + 
                                              OBJTYPE(*FILE)';
                              CallP(E) QcmdExc(%Trim(CLCMD): %Len(%Trim(CLCMD));
                              If %Error and PGMSDS.MsgId = 'CPF9801';
                                 //Create workfile
                              EndIf;
                           
                           /End-Free
                          Birgitta

                          Comment

                          Working...
                          X