ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Monitoring a Library size.

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

  • Monitoring a Library size.

    Hi,

    I've just joined the forum and I find it really interesting... even though I'm just a System Administrator trying to learn some programming.
    I need to monitor a Library and I thought about creating a CL program executing this:
    DSPOBJD OBJ(SMZ4DTA/*ALL) +
    OBJTYPE(*ALL) +
    OUTPUT(*OUTFILE) +
    OUTFILE(QTEMP/Library) +

    And then execute the SQL statement with RUNSQL:

    select sum(ODBPUN * ODSIZU) from library

    this gives me the size of the library...
    Now, what I'm having trouble with is trying to get the value calculated by the SQL statement into a variable so I can monitor the size.
    I thought about creating a database using SQL statements and then doing a RCVF to get the value but I'm not sure.
    All suggestions and ideas are welcome.
    Thanks!!!

  • #2
    Re: Monitoring a Library size.

    why dont you do a receive file on the table you created with the dspobjd?
    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


    • #3
      Re: Monitoring a Library size.

      Thanks for the idea!!! I didn't saw it that way, I was all focused on using SQL and forgot that I could actually process the table by just using CL. I will give it a try.
      Thanks again!!!

      Comment


      • #4
        Re: Monitoring a Library size.

        If you already think about using RUNSQL, then you might use it to create a VIEW over QTEMP/Library. Create the VIEW to run the sum(ODBPUN * ODSIZU) function and to CAST() it to a useful data type. Your CL would then become the DSPOBJD command followed by RUNSQL to set the VIEW and a RCVF to read the single row from the view. A DCLF would also be needed and you'd probably want to compile it interactively in order to have the VIEW available.

        However, the Retrieve Library Description (QLIRLIBD) API can return size information more directly. It's both more and less complicated to use, depending on what makes sense to you and what obstacles you run into.
        Tom

        There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

        Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

        Comment


        • #5
          Re: Monitoring a Library size.

          Nice API... with my limited knowledge I just did this:

          Seems to do the job... now I have to schedule it every 15 minutes and I'm done:
          PHP Code:
          PGM                                                               
                       DCLF       FILE
          (ACSLIB/LIBRARY)                      
                       
          DCL VAR(&SIZETYPE(*DECLEN(11 0)                  
                       
          DCL VAR(&MAXTYPE(*DECLEN(11 0VALUE(30000000000)
           
          DSPOBJD OBJ(SMZ4DTA/*ALL) OBJTYPE(*ALL) OUTPUT(*OUTFILE) +       
            OUTFILE(ACSLIB/LIBRARY)                                         
           CHGVAR VAR(&SIZE) VALUE(0)                                       
                                                                            
           RCVF                                                             
           IF         COND(*IN03 *EQ '1') THEN(GOTO CMDLBL(END))            
                                                                            
           CHGVAR VAR(&SIZE) VALUE(&SIZE + (&ODBPUN * &ODSIZU))             
                                                                            
          END:                                                              
           IF COND(&SIZE *GT &MAX) THEN(GOTO CMDLBL(MSG))                   
           GOTO CMDLBL(END2)                                                
          MSG:                                                                 
           SNDUSRMSG  MSG('LIBRARY SMZ4DTA SIZE IS &SIZE CONTACT DAVE HAYES') +
            TOUSR(*SYSOPR)                                                     
          END2:                                                                
                                                                               
                                                                               
           ENDPGM                                                              
          ****************** End of data ************************************** 
          It's not elegant but I'm a newbie

          Comment


          • #6
            Re: Monitoring a Library size.

            I'm posting a slightly modified version:
            Code:
            pgm
            
               dcl   &SIZE       *dec     ( 11 0 )
               dcl   &MAX        *dec     ( 11 0 ) value( 30000000000 )
            
               dclf  TOML/LIBRARY
            
               dspobjd     TOMLTEST/*ALL  objtype( *ALL ) +
                             output( *OUTFILE ) outfile( TOML/LIBRARY )
            
               chgvar      &SIZE       ( 0 )
            
               rcvf
               if ( *IN03 *EQ '1' ) then( goto END )
            
               chgvar      &SIZE       ( &SIZE + (&ODBPUN * &ODSIZU) )
            
            END:
            
               if ( &SIZE *gt &MAX ) then( goto MSG )
               goto  END2
            
            MSG:
            
               sndusrmsg   'LIBRARY SMZ4DTA SIZE IS &SIZE CONTACT DAVE HAYES'  +
                             tousr( *SYSOPR )
            
            END2:
            
               return
            
            endpgm
            If you review it, you should see that it has the exact same logic. I modified it to run on one of my systems, so I changed the library names. I also did some simple formatting just because I'm used to reading code in the style that I prefer, not because it was wrong. (With CL elements in lower-case, I get extra visual feedback on some things if I prompt the statement.) I moved the DCLF to the end of the declarative area because I prefer basic DCLs first. (The order can make a difference for some declaratives in special cases.) And I added a RETURN statement at the end because I believe exits should be explicit.

            Now the questions...

            I don't see where "*IN03" comes from. There is no DSPF declared, so it can't come from any display. You probably expect it to be a reference to an indicator, but it's actually nothing but a literal constant here. The code compares the literal value "*IN03" to the literal value "1". It will never be equal. What specifically were you wanting to happen there?

            With that, you only have RCVF executing once. That will be fine as long as the ACSLIB/LIBRARY file only has a single record, and that will be true only if library SMZ4DTA has a single object in it. Otherwise a DO-loop around RCVF is needed to total up all rows. The earlier suggestion to create a summary VIEW would take care of that. Since you've moved out of QTEMP, the VIEW could be permanent. With a summary VIEW, there would only be a single row and a single RCVF would be sufficient.

            There are additional style issues, particularly how GOTOs are used; but they're not significant and might be needed if your system is old enough. The "*IN03" and the single RCVF are important.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment


            • #7
              Re: Monitoring a Library size.

              Thanks for your help Tom!
              I used an old program I had as an example, the thing is that that program had a screen so I guess it was doing the loop until F3 was pressed or something like that... I thought that *IN03 was some kind of constant indicating the end of the file... how should I monitor the file for the end of file?

              Comment


              • #8
                Re: Monitoring a Library size.

                cpf0864



                PHP Code:
                READLOOP:  RCVF                          /* Read a file record  */
                           
                MONMSG  MSGID(CPF0864)  EXEC(GOTO CMDLBL(EOF))
                           
                /*  Process the file record  */
                           
                GOTO  CMDLBL(READLOOP)       /*  Get another record  */
                EOF:       /*  End of file processing  */ 
                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


                • #9
                  Re: Monitoring a Library size.

                  Thanks a lot Jamie!!!

                  Comment


                  • #10
                    Re: Monitoring a Library size.

                    I guess I'm done... I´ve modified the program to run all day every 15 minutes:
                    PHP Code:
                            *************** Beginning of data *************************************
                    0001.00 PGM                                                                    
                    0002.00              DCLF       FILE
                    (ACSLIB/LIBRARY)                           
                    0003.00              DCL VAR(&SIZETYPE(*DECLEN(11 0)                       
                    0004.00              DCL VAR(&MAXTYPE(*DECLEN(11 0VALUE(30000000000)     
                    0004.01              DCL VAR(&NTYPE(*DECLEN(1 0VALUE(0)                  
                    0004.02 LOOP:                                                                  
                    0004.03  CHGVAR VAR(&NVALUE(&1)                                          
                    0004.04  IF COND(&*EQ 96THEN(GOTO CMDLBL(END3))                            
                    0005.00  DSPOBJD OBJ(SMZ4DTA/*ALL) OBJTYPE(*ALL) OUTPUT(*OUTFILE) +            
                    0006.00   OUTFILE(ACSLIB/LIBRARY)                                              
                    0007.00  CHGVAR VAR(&SIZE) VALUE(0)                                            
                    0008.00 READLOOP:                                                              
                    0009.00  RCVF                                                                  
                    0010.00  MONMSG  MSGID(CPF0864)  EXEC(GOTO CMDLBL(EOF))                        
                    0011.00                                                                        
                    0012.00  CHGVAR VAR(&SIZE) VALUE(&SIZE + (&ODBPUN * &ODSIZU))                  
                    0013.00                                                                       
                    0014.00  GOTO  CMDLBL(READLOOP)                                               
                    0015.00 EOF:                                                                  
                    0016.00  IF COND(&SIZE *GT &MAX) THEN(GOTO CMDLBL(MSG))                       
                    0017.00  GOTO CMDLBL(END2)                                                    
                    0018.00 MSG:                                                                  
                    0019.00  SNDUSRMSG  MSG('LIBRARY SMZ4DTA SIZE IS &SIZE CONTACT XXXX') + 
                    0020.00   TOUSR(*SYSOPR)                                                      
                    0021.00 END2:                                                                 
                    0022.00  DLYJOB DLY(900)                                                       
                    0023.00  GOTO CMDLBL(LOOP)                                                     
                    0023.01 END3:                                                                  
                    0024.00  ENDPGM                                                                
                            ****************** End of data **************************************** 
                    Last edited by jamief; December 12, 2013, 09:32 AM. Reason: wrapped in : [ php ] [ /php ]

                    Comment


                    • #11
                      Re: Monitoring a Library size.

                      It makes sense the way it's coded. You're reading the object records in a RCVF-loop until notified of end-of-file. You're totaling the size correctly. But there are a couple problems.

                      You have &N defined as TYPE(*DEC) LEN(1 0), yet you're testing for a value that is two digits wide. You should expand the variable width to LEN(3 0). That should guarantee that your test doesn't run into trouble later.

                      The second problem is more interesting. You run RCVF until end-of-file (EOF). Normally, that can only be done once in the execution of a CL program. If you try to RCVF again, the CPF0864 message will be signaled again immediately. Once a file is at EOF, it is always at EOF for as long as the CL program continues to run. That's just how it works in CL which is not really intended to be a database file processor.

                      It would be difficult to notice this problem. The EOF condition isn't an error, so you won't be notified. All that would happen is that your test for maximum size would never report a problem. The sum would always be zero after the first processing of the file.

                      If your system is at i 6.1 or later, there is a resolution that should work.

                      At your EOF label, code a CLOSE command. That should close the file and allow it to restart at the beginning the next time RCVF runs. The first RCVF in a series will automatically open the file.

                      The little problems that have shown up are parts of why the summary VIEW was suggested and also why the API was suggested. Those are both a step or two beyond what you're doing now. As you progress and start learning about potential problems, you'll try new things and see how some problems can be avoided.
                      Tom

                      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                      Comment


                      • #12
                        Re: Monitoring a Library size.

                        Thanks a lot Tom!!!

                        Comment


                        • #13
                          Re: Monitoring a Library size.

                          Final Version, thanks Tom and Jamie!!!!

                          *************** Beginning of data *************************************
                          0001.00 PGM
                          0002.00 DCLF FILE(ACSLIB/LIBRARY)
                          0003.00 DCL VAR(&SIZE) TYPE(*DEC) LEN(11 0)
                          0004.00 DCL VAR(&MAX) TYPE(*DEC) LEN(11 0) VALUE(30000000000)
                          0005.00 DCL VAR(&N) TYPE(*DEC) LEN(3 0) VALUE(0)
                          0006.00 DCL VAR(&MSG1) TYPE(*CHAR) LEN(36) +
                          0007.00 VALUE('*Attention* Library SMZ4DTA size is')
                          0008.00 DCL VAR(&MSG2) TYPE(*CHAR) LEN(18) +
                          0009.00 VALUE('contact XXXXXXXXXX')
                          0010.00 DCL VAR(&MSG3) TYPE(*CHAR) LEN(40) +
                          0011.00 VALUE('Situation normal library SMZDTA +
                          0012.00 size is')
                          0013.00 DCL VAR(&ATT) TYPE(*CHAR) LEN(65)
                          0014.00 DCL VAR(&NORMAL) TYPE(*CHAR) LEN(51)
                          0015.00 DCL VAR(&SIZETXT) TYPE(*CHAR) LEN(11)
                          0016.00 LOOP:
                          0017.00 CHGVAR VAR(&N) VALUE(&N + 1)
                          0018.00 IF COND(&N *EQ 96) THEN(GOTO CMDLBL(END3))
                          0019.00 DSPOBJD OBJ(SMZ4DTA/*ALL) OBJTYPE(*ALL) OUTPUT(*OUTFILE) +
                          0020.00 OUTFILE(ACSLIB/LIBRARY)
                          0021.00 CHGVAR VAR(&SIZE) VALUE(0)
                          0022.00 READLOOP:
                          0023.00 RCVF
                          0024.00 MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF))
                          0025.00
                          0026.00 CHGVAR VAR(&SIZE) VALUE(&SIZE + (&ODBPUN * &ODSIZU))
                          0027.00 CHGVAR VAR(&SIZETXT) VALUE(&SIZE)
                          0028.00 GOTO CMDLBL(READLOOP)
                          0029.00 EOF:
                          0030.00 CLOSE
                          0031.00 IF COND(&SIZE *GT &MAX) THEN(GOTO CMDLBL(MSG))
                          0032.00 GOTO CMDLBL(END2)
                          0033.00 MSG:
                          0034.00 CHGVAR VAR(&ATT) VALUE(&MSG1 *CAT &SIZETXT *CAT &MSG2)
                          0035.00
                          0036.00 SNDUSRMSG MSG(&ATT) MSGTYPE(*INFO) TOUSR(*SYSOPR)
                          0037.00 END2:
                          0038.00 CHGVAR VAR(&NORMAL) VALUE(&MSG3 *CAT &SIZETXT)
                          0039.00
                          0040.00 SNDUSRMSG MSG(&NORMAL) MSGTYPE(*INFO) TOUSR(*SYSOPR)
                          0041.00 DLYJOB DLY(900)
                          0042.00 GOTO CMDLBL(LOOP)
                          0043.00 END3:
                          0044.00 ENDPGM
                          ****************** End of data ****************************************

                          Comment

                          Working...
                          X