5 Replies Latest reply on Jun 15, 2010 10:13 PM by David Allan-Oracle

    Common code within experts.

    767810
      Hi There,

      A while ago we created 6 experts. In order to get them up and running, we have duplicated some code through these experts, with a view of coming back later to modularise. I am now at this point, but am struggling to conceptually understand how i can achieve this. I had thought i could use nested experts, but am now not sure.

      One of the duplicated code pieces is a debug function, which records what is happening throughout the execution of the expert. The experts themselves are made up of multiple custom dialogs and OMB tasks. We had originally defined the debug function at the first object within the expert, for the others to then use.

      How can i create one version of the debug 'function' for all my experts to then utilise? Kkeeping in mind that the calling of the debug functionality will not be 'flow-controlled' in the way you piece together the OWB objects.

      Thanks in advance.

      Cheers,

      Andrew
        • 1. Re: Common code within experts.
          David Allan-Oracle
          Hi Andrew

          Can either put common code/packages in a file external to the expert and source the file (the tcl source command) in each place to be used. Or define the procedures in the Procedure Declaration panel of a common expert, and then add the expert into another (nest it), then call the procedure - for example if the expert define procedure PX is defined EX1, and the top level is called EX2, add EX1 into EX2, then in some OMB of EX2, call EX1_ns::PX

          Cheers
          David
          • 2. Re: Common code within experts.
            767810
            Hi David,

            Thanks for the response, one thing perhaps I didn't make clear, was i needed to pass/get things from this common code. As shown below, i have a common file writer module to pass messages to the module for writing to file. This requirement seems to cancel out the use of TCL source command.

            I created 1 expert (debug) and created a transition from start task to end task. No other elements in the expert. I then placed in the 'Procedure Declaration' of the start task the following code.

            #-------------------------------------------------
            # Procedures
            #-------------------------------------------------
            proc Debug {arg1} { 
            # Writes the passed variable to the debug file
            set arg2 "c:/temp/test"
            file mkdir "$arg2"
            if {[file exists "$arg2/debug.txt"] == 1} { 
            set fileId [open "$arg2/debug.txt" "a"]
            } else { 
            set fileId [open "$arg2/debug.txt" "w"]
            }
            puts $fileId "[clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}] $arg1"
            close $fileId
            }

            I then created another expert (nested). I then nested the debug expert and added a custom dialog. The sequence flow is Start-->Debug-->Custom Dialog-->End.
            I added the following code to the post-processing section of the custom dialog.

            Debug "harvest_comment:"

            When i run the nested expert though (both have been validated with no errors or significant warnings) I get an error saying that the "Invalid command name "debug"". This appears to me as though the procedure that should have been loaded though nesting the expert, hasn't been and that's why call to Debug isn't being recognised. The end result should be that i get a file created in c:/temp/test/debug.txt with "harvest comment:" included in it.

            Is this in line with one of the approaches you recommended?

            Thanks again.

            Andrew

            Edited by: user8767720 on Jun 11, 2010 1:47 PM (added some clarification about requirement for passing/getting stuff to/from module
            • 3. Re: Common code within experts.
              David Allan-Oracle
              Hi

              The source command will just define the procedures and/or packages, they can have parameters that are then supplied when the routines are invoked. As for the nested expert definitions, you can't just invoke debug for example, it will be scoped by the namespace of the expert. So you would need EXPERTNAME_ns:: prefix to procedure call.

              Cheers
              David
              • 4. Re: Common code within experts.
                767810
                Hi David,

                Thanks for this and i understand now what you mean by the EXPERTNAME_ns:: prefix (which you included in the first reply, so sorry about that :)). I want to understand the scoping nature further, I presume this is TCL scoping rather than OWB specific?

                Thanks again for your help, this will be a great help for us.

                Cheers,

                Andrew
                • 5. Re: Common code within experts.
                  David Allan-Oracle
                  Hi Andrew

                  Yep, the expert generates tcl code which is just a bunch of tcl procedures. If you nest an expert, a tcl namespace (see here ) is defined for the nested code (so it does not conflict). You can actually generate within OWB and inspect what is created.

                  Cheers
                  David