ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Batch script on the AS/400

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

  • Batch script on the AS/400

    Hello,

    If I have to run 50 similar AS/400 commands - example: I need description of 50 *MODULEs:

    Code:
    DSPOBJD OBJ(LIBRARY/OBJECT1) OBJTYPE(*MODULE)  OUTPUT(*OUTFILE) OUTFILE(tool/wrkk) OUTMBR(*FIRST *ADD)
    If I understand correctly I have to run this command for every object I need description of (OBJECT1 - OBJECT50), but is there any way of somehow 'scripting' this, e.g. I save this 50 commands (for every object from OBJECT1 to OBJECT50) to some kind of a txt file and than tell AS/400 to run all the commands in this text file...?


    Would this be possible on the 400?


    (Or is there any other way of getting OBJ description of 50 objects with a single command instead of running 50 of these OBJD commands)?

    Thanks!

  • #2
    Re: Batch script on the AS/400

    You could use the generic OBJ(LIBRARY/OBJECT*), then just disregard any records that you do not require i.e. records not in the range OBJECT1 to OBJECT50.

    PHP Code:
    DSPOBJD OBJ(LIBRARY/OBJECT*) OBJTYPE(*MODULEOUTPUT(*OUTFILEOUTFILE(tool/wrkkOUTMBR(*FIRST *ADD
    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


    • #3
      Re: Batch script on the AS/400

      Thanks, that's not a bad idea, I could even select only those that i need with SQL. Nevertheless, is there any other way similar to what I described in the first post?

      Thanks

      Comment


      • #4
        Re: Batch script on the AS/400

        Here is an API (QUSROBJD) -- If you are just looking for description convert this to a procedure.
        **needs to be converted to free
        PHP Code:

        **-- Header specifications:  --------------------------------------------**         
        H Option( *SrcStmt )                                                                
        **-- 
        Api error data structure:  -----------------------------------------**         
        D ApiError        Ds                                                                
        D  AeBytPro                     10i 0 Inz
        ( %SizeApiError ))                       
        D  AeBytAvl                     10i 0 Inz                                           
        D  AeMsgId                       7a                                                 
        D                                1a                                                 
        D  AeMsgDta                    128a                                                 
        **-- Object description structure OBJD0400:  ----------------------------**         
        D ObjDscDs        Ds                  Inz                                           
        D  ObjDscLen                    10i 0                                               
        D  ObjDscSiz                    10i 0                                               
        D  ObjNam                       10                                                  
        D  ObjLib                       10                                                  
        D  ObjTyp                       10                                                  
        D  ObjRtnLib                    10                                                  
        D  ObjAsp                       10i 0                                               
        D  ObjOwnr                      10                                                  
        D  ObjDmn                        2                               
        D  ObjCrtDat                    13                               
        D  ObjChgDat                    13                               
        D  ObjAtr                       10                               
        D  ObjTxt                       50                               
        D  ObjSrcFil                    10                               
        D  ObjSrcLib                    10                               
        D  ObjSrcMbr                    10                               
        D  ObjSrcChgDat                 13                               
        D  ObjSrcSavDat                 13                               
        D  ObjSrcRstDat                 13                               
        D  ObjCrtUsr                    10                               
        D  ObjCrtSys                     8                               
        D  ObjResDat                     7                               
        D  ObjSavSiz                    10i 0                            
        D  ObjSavSeq                    10i 0                            
        D  ObjStg                       10                               
        D  ObjSavCmd                    10                               
        D  ObjSavVolId                  71                               
        D  ObjSavDvc                    10                               
        D  ObjSavFil                    10                               
        D  ObjSavLib                    10                               
        D  ObjSavLbl                    17                               
        D  ObjSavLvl                     9                               
        D  ObjCompiler                  16                               
        D  ObjLvl                        8                               
        D  ObjUsrChg                     1                               
        D  ObjLicPgm                    16                               
        D  ObjPtf                       10                               
        D  ObjApar                      10                               
         
        *  start of four                                                
        D  ObjUseDat                     7                               
        D  ObjUsgInf                     1                               
        D  ObjUseDay                    10i 0                            
        D  ObjSiz                       10i 0                            
        D  ObjSizMlt                    10i 0                            
        D  ObjCprSts                     1                               
        D  ObjAlwChg                     1                               
        D  ObjChgByPgm                   1                               
        D  ObjUsrAtr                    10    
        D  ObjOvrflwAsp                  1                                               
        D  ObjSavActDat                  7                                               
        D  ObjSavActTim                  6                                               
        D  ObjAudVal                    10                                               
        D  ObjPrmGrp                    10                                               
                                                                                         
         
        *                                                                               
        d RtvObjD         Pr                  ExtPgm'QUSROBJD' )                       
        d  RoRcvVar                  32767a         Options( *VarSize )                  
        d  RoRcvVarLen                  10i 0 Const                                      
        d  RoFmtNam                      8a   Const                                      
        d  RoObjNamQ                    20a   Const                                      
        d  RoObjTyp                     10a   Const                                      
        d  RoError                   32767a         Options( *VarSize )                  
         *                                                                               
        **                                                                               
        **-- 
        Get  value:  ----------------------------------------------------**      
        **                                                                               
        C                   Eval      ObjNam     =  'BRC02INT'                           
        C                   Eval      ObjLib     =  'LBIOBJ'                 
        C                   Eval      ObjTyp     =  '*MODULE'                          
        **                                                                             
        C                   CallP     RtvObjDObjDscDs                                
        C                                    
        : %SizeObjDscDs )                       
        C                                    'OBJD0400'                              
        C                                    ObjNam ObjLib                         
        C                                    
        ObjTyp                                  
        C                                    
        ApiError                                
        C                                    
        )                                         
        **                                                                             
        C                   If        AeBytAvl   >  *Zero         And                  
        C                             AeMsgId    =  'CPF9801'                          
        **-- Object doesn't exist...                                                   
        C                   EndIf                                                      
        **                                                                             
        C                   Return                                                     
        ** 
        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


        • #5
          Re: Batch script on the AS/400

          You could write a simple CL program to do this... Seems to me that's what you're asking at the start of this thread, right? What I don't know is where you're going to get the list of objects... you didn't say.

          Comment


          • #6
            Re: Batch script on the AS/400

            Originally posted by Scott Klement View Post
            You could write a simple CL program to do this... Seems to me that's what you're asking at the start of this thread, right? What I don't know is where you're going to get the list of objects... you didn't say.
            1.
            Yes, this also occured to me, but I was not sure if it's really necessary to compile a CL program (I can do it from PDM) just to execute a few simple commands. There is really no other way? No linux/windows-style batch scripts?

            2.
            I planned to enter objects names manually, that is - paste them in DSPOBJD and than execute these prepared commands. But on the other hand, is it possible to get these object names from a database table?
            Example - I write one DSPOBJD command and than it pulls objects names from a table? Hm...

            Thanks, this really helps...

            Comment


            • #7
              Re: Batch script on the AS/400

              It's possible to write CL in a non-compiled manner. It's also possible to use other environments that are never compiled.
              • Shell scripts (like you would have on Linux and similar Unix-like environments) are possible through both the QShell and PASE environments. PASE supports many different shells, including Korn, Bourne, BASH, C-Shell
              • CL commands can be put into a CL batch script, and run uncompiled
              • REXX scripts are also built-in to the IBM i environment


              However, I personally think the simplest and most powerful/flexible method is to use a CL program. What is your objection to compiling the your script? It only takes a fraction of a second to do...

              Comment


              • #8
                Re: Batch script on the AS/400

                Originally posted by Scott Klement View Post
                It's possible to write CL in a non-compiled manner. It's also possible to use other environments that are never compiled.
                • Shell scripts (like you would have on Linux and similar Unix-like environments) are possible through both the QShell and PASE environments. PASE supports many different shells, including Korn, Bourne, BASH, C-Shell
                • CL commands can be put into a CL batch script, and run uncompiled
                • REXX scripts are also built-in to the IBM i environment


                However, I personally think the simplest and most powerful/flexible method is to use a CL program. What is your objection to compiling the your script? It only takes a fraction of a second to do...
                Thanks Scott for your suggestions. Generally I don't have anything against compiling CL programs, I just thought maybe there is a more efficient way to execute a batch of the same simple commands (and thus skipping the step of compiling so the same script could be executed on both our v5.4 and v6.1 iOS).

                Nevertheless I would like to try running CL script uncompiled, could you tell me more about this bullet you mentioned:
                CL commands can be put into a CL batch script, and run uncompiled
                or maybe paste a link on IBM's Infocenter?
                (Where should I put this kind of script and how do I execute it?)

                I don't think we have neither of QSHELL/PASE on our 400s, so I would try this CL batch script method...

                Thanks again!

                Comment


                • #9
                  Re: Batch script on the AS/400

                  if you compile the object to be v5r4 compatible then there is no problem with running the same program "script" on both boxes. you can either compile on the v6.1 box to TGTRLS(V5R4M0) or compile on the v5r4 box and then transfer the object to the other system. it's not rocket surgery...
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment


                  • #10
                    Re: Batch script on the AS/400

                    Originally posted by tock085 View Post
                    Thanks Scott for your suggestions. Generally I don't have anything against compiling CL programs, I just thought maybe there is a more efficient way to execute a batch of the same simple commands (and thus skipping the step of compiling so the same script could be executed on both our v5.4 and v6.1 iOS).
                    Compiling it would be the "normal" way that this sort of thing would be done on IBM i. It's the method that virtually evreryone will be familiar with, and is the most flexible method. You can compile the program on 6.1 with TGTRLS(V5R4M0) and the compiled object will run just fine on both releases. Or, you can compile it on the V5R4 box, and it'll automatically work on both, without any special options.

                    Originally posted by tock085 View Post
                    Nevertheless I would like to try running CL script uncompiled, could you tell me more about this bullet you mentioned:
                    CL commands can be put into a CL batch script, and run uncompiled
                    or maybe paste a link on IBM's Infocenter?
                    (Where should I put this kind of script and how do I execute it?)
                    It's very unusual to see someone using this technique... but if you want to try it, here's a quick intro article from Ted Holt:
                    I am thinking of writing a program that will read a source member of CL commands, interpreting them and running them dynamically one at a time. I can think of several situations in which such a utility would be more suitable than compiled CL programs. Before I re-invent the wheel, I want to know if


                    Originally posted by tock085 View Post
                    I don't think we have neither of QSHELL/PASE on our 400s, so I would try this CL batch script method...
                    But, you do have REXX... which is also a better choice than the interpreted CL method, IMHO.

                    I'm a bit torn here, because I like to encourage people to learn new things -- but, at the same time, I think the best solution for your particular situation is the compiled CL program. :-)

                    Comment


                    • #11
                      Re: Batch script on the AS/400

                      Originally posted by Scott Klement View Post
                      Compiling it would be the "normal" way that this sort of thing would be done on IBM i. It's the method that virtually evreryone will be familiar with, and is the most flexible method. You can compile the program on 6.1 with TGTRLS(V5R4M0) and the compiled object will run just fine on both releases. Or, you can compile it on the V5R4 box, and it'll automatically work on both, without any special options.



                      It's very unusual to see someone using this technique... but if you want to try it, here's a quick intro article from Ted Holt:
                      I am thinking of writing a program that will read a source member of CL commands, interpreting them and running them dynamically one at a time. I can think of several situations in which such a utility would be more suitable than compiled CL programs. Before I re-invent the wheel, I want to know if




                      But, you do have REXX... which is also a better choice than the interpreted CL method, IMHO.

                      I'm a bit torn here, because I like to encourage people to learn new things -- but, at the same time, I think the best solution for your particular situation is the compiled CL program. :-)

                      OK, thanks for your suggestions, it seems I'll continue with compiling my scripts from PDM, and I'm happy to know that is a 'standard' way of doing it.
                      However I'll try a REXX tutorial if this is really something that works on 400 out-of-the-box, and also work through that tutorial on ITJungle that you pasted.

                      I do have one additional question - Is it possible to execute SQL commands from CL? I'm thinking about updating my script to include just one DSPOBJD command and it would be great if I could read all the objects I need a description of from a database table.

                      To make long story short is it possible to read a stream of object names from a table in CL...?

                      Thanks everyone, Scott especially...

                      Comment


                      • #12
                        Re: Batch script on the AS/400

                        on v7.1 you can use RUNSQL (it may have been PTFed back to v6.1) but for v5r4 the only way is to either use a QM query or an embedded SQL HLL(RPG or COBOL) program. if you are writing a CL you don't really need SQL for this.
                        here is an example for using DSPOBJD & reading the file in CL:
                        Code:
                        Pgm
                           DclF AudJrnRcv
                        
                               /* Get Outfile Of All Audit Journal Receivers */
                                     DSPOBJD    OBJ(AUD*) OBJTYPE(*JRNRCV) OUTPUT(*OUTFILE) +
                                                  OUTFILE(QTEMP/AUDJRNRCV)
                                     MonMsg CPF0000
                                     DSPOBJD    OBJ(*ALLUSR/Q*) OBJTYPE(*JRNRCV) +
                                                  OUTPUT(*OUTFILE) OUTFILE(QTEMP/AUDJRNRCV) +
                                                  OUTMBR(*FIRST *ADD)
                                     MonMsg CPF0000
                        
                               OvrDBF AudJrnRcv QTemp/AudJrnRcv
                        
                            /* Process Outfile */
                        Loop:
                            RcvF
                            MonMsg CPF0864 Exec(GoTo EndPgm)
                        
                               /* Delete The Journal Receiver, Currently Attached */
                               /*  Receivers Will Not Be Deleted                  */
                               DltJrnRcv &ODLbNm/&OdObNm DltOpt(*IgnInqMsg)
                               MonMsg CPF0000
                        
                               GoTo Loop
                        
                            /* Termination */
                        EndPgm:
                            RclRsc
                            Return
                            EndPgm
                        I'm not anti-social, I just don't like people -Tommy Holden

                        Comment


                        • #13
                          Re: Batch script on the AS/400

                          Tommy,

                          A couple of points:
                          • RUNSQL requires PTFs on both 6.1 and 7.1. (You made it sound like it was in the initial release of 7.1. This is not the case.) To get it, update the DB2 Group PTF. On 6.1, you need group SF99601 (DB2) to be updated to level 25 (or higher) On 7.1 you need group SF99701 updated to level 14 (or higher.)
                          • RUNSQLSTM might also be a possibility (though QMQRY is also a good suggestion.)


                          Also, REXX has a command envrionment called EXECSQL that should make it easy to run SQL statements from within REXX.

                          Comment

                          Working...
                          X