7 Replies Latest reply: May 15, 2014 9:56 AM by frugalman _ RSS

    V9 User Defined Functions

    frugalman _

      I'm excited about this capability but I can't seem to get off of ground zero.  The first thing I want to do, is to make a function called YM that would return a character string "YYYY/MM" from an input date.  From the user defined function input panel, it's not obvious how to do this.  So I tried finding it in my new manual, and there is only a reference to online help.  Online help says to look at userdefinedfunctions.xmod to see how it's done. 

      I did that and the process is still not obvious.

      TIA!

       

      [size="1"][ March 20, 2007, 02:11 PM: Message edited by: frugalman ][/size]

        • V9 User Defined Functions
          Data Kruncher

          Hi frugalman,

           

          My first v9 response! Hopefully I get it right...      

           

          The concept is pretty cool, isn't it?

           

          There are a few steps to doing this:

          1) Name the new function YM.

          2) Set your function to be a String category.

          3) "Add" parameters to your function. I added Year and Month, both of Numeric type.

          4) Set the Return Type to Character.

          5) I setup the formula for the function as follows:

           

          [font="courier"]trim(str(Year)"/"right("00"+trim(str(Month)),2))  /font[/quote]I opted to use the trick to pad with leading zeros for your month number.

           

          Now, in step 6, you can call the function in a calculated field as follows:

           

          [font="courier"]YM(2007,3)  /font[/quote]or

          [font="courier"]YM(ReportYear,ReportMonthNumber)  /font[/quote]This will return 2007/03.

           

          HTH,

          Kruncher

           

          Edit: I forgot that you need to set the Return Type to Character.

           

          [size="1"][ March 20, 2007, 04:15 PM: Message edited by: Data Kruncher ][/size]

          • V9 User Defined Functions
            frugalman _

            Datakruncher, thanks so much to you and all the experts who help us out.  I was able to get User Functions to work after your reply, the key concept I was missing was that I needed to define a "parameter" for my function to work on.  To help others out, I took notes and this is how I created my new User Defined function YM()

             

            Really Simple User Function walk through:

             

            Click the f(x) button which gets you to the User Defined functions window

            Click new

            Enter a name for your new function like YM

             

            Flesh out the description area which is now set to just YM() to something like -

            YM()  this will return a character string of an input date field, for example YM() will return "2006/08" if the field Tran Date is {08/22/2006}

             

            We are going to need to name a parameter for the function to use, so click on the Add button to the right of the Forms area in this window

             

            Use something like dateinput for Name, then Date/Time for Type, then {08/22/2006} for Test Value

            Select character for Return Type

             

            So "dateinput" is the name of our parameter to be used by this function, but it is not the name of a real field in our table.

             

            Click the formula tab, and enter the following formula:

             

            str(year(dateinput),4)"/"str(month(dateinput),2,0,"0")

             

            Then click OK a couple of times until the windows go away.

             

            The function is now available for your use.

             

            So, for example, right click on any field in the table, select New Calculated Field, Formula Based, name the new field Tran Month, type Character, then click the formula tab, double click YM() in the functions list (our User Defined functions appear in the overall functions list now), then put your cursor in between the parentheses in YM(), then double click on some date in your Fields list like Tran Date, then click OK.  You now have a new User Defined field in your table, using a new User Defined function YM() that you just created.

             

            Hope this helps..

             

            P.S. As we all agree, Monarch is a wonderful product!  My main wish is for Tech Writing to catch up with the product.  The new manual is only 16 pages longer than the old V8 manual, and there is NOTHING there on User Functions, for example.

             

            [size="1"][ March 21, 2007, 08:06 AM: Message edited by: frugalman ][/size]

            • V9 User Defined Functions
              frugalman _

              OK, another issue on User Defined functions.  I saved my model and report, then opened another model and report.  I was going to use my new YM()user defined function, but it's not in my functions list!  Why didn't it save it so that all my models can use it?

              • V9 User Defined Functions
                Grant Perkins

                Originally posted by frugalman:

                OK, another issue on User Defined functions.  I saved my model and report, then opened another model and report.  I was going to use my new YM()user defined function, but it's not in my functions list!  Why didn't it save it so that all my models can use it? /b[/quote]Hmm,

                 

                You're leaping into the slightly less intuitive aspects of some of the new functions here.    

                 

                Which I guess is a perfect opportunity to start to discuss the options available to you.   :cool: 

                 

                Used Defined Functions are stored in models, as you know. The UDF model supplied with V9 as an example can be set up as the default which menas it can be available for all models to call on.

                 

                So one option is to add you function(s) to that model and make them available by default.

                 

                Or you could copy that model, remove the functions you will not use, add your own and have that collection as the default.

                 

                Or you could create you own model to contain the functions, adding any new ones as you go, and make that the default.

                 

                Another approach for you would be to use the Linked Objects functionality to make your model with the YM function available to 'supply' objects to your new (or existing) model. As pert of that process you will be asked if you want to 'expose' the UDFs available in the model being linked to. If you do the UDFs will be available in the new model along with the standard embedded Functions.

                 

                There are some User Defined Function controls to help manage what is and is not available to the model you are working on. So you can always make the association with an external UDF source and then work with it.

                 

                My guess is that most users will generate their own UDF models as central resources, probably for both UDFs and commonly re-used objects of all sorts from other models. If you work in several areas of analysis with different requirements you may well create a number of 'core' object library models to help keep the models mangeable and relevant to the different areas of activity.

                 

                To manage that situation what I would do (I think) is to create my 'master' model but create new functions (or whatever) in the model for which I forst need them.

                 

                When complete I would open my 'master' model and use the Linked Object functionality to Import (no link - this version will now become the master UDF) the new function from it original model to the master.

                 

                It will probably arrive with errors (since the master model probably does not have or need all the fields you will have defined) but the open model will tolerate that.

                 

                If the original UDF (or other object) has, say, specific field names that you wish to make more generic for future shared use you can edit the new master UDF. Editing is not fault tolerant so there will be a few little 'tricks' required to make the changes, maybe. I won't go into those for this post.

                 

                On the other hand if the use of any fields named in the function(s) is obvious (or better still documented in the new "Comments" feature) the UDF could be left as it is and simply be modified by changing field names, if required, whenever it is subsequently used in other models.

                 

                As you have already created a UDF you will know about the f(x) button on the menu bar. Use the wizard again and follow the 'Import' option which will take you through the process. It will probably look familiar as it is similar to wizards in Monarch. It should be a lot easier spending 10 or 15 minutes playing with it for familiarity than it would be reading anything I could write here on the subject.

                 

                HTH, but please feel free to come back with further questions if something does not seem to make sense. Understanding the basic idea is not too difficult but getting a handle on exactly what is possible (a lot!) and how to plan to make best use of it can take a little more exposure in my experience.

                 

                 

                Grant

                • V9 User Defined Functions
                  frugalman _

                  Again, thanks to Data Kruncher, Todd Niemi and Grant Perkins and many others for sharing their knowledge.

                   

                  Todd, I took a harder look at the online documentation for User Defined fields, and am finding what I needed there.  I understand the Learning Guide is not intended to go into depth in advanced topics, but to teach people how to do basic Monarch functions.  I think several of us have pointed out that we would pay good money, like $50 a copy, for a hard copy book covering indepth all of Monarch's features, and showing examples with pictures and diagrams of how to use them.  I guess the lack of such a book at Barnes and Noble is because the Monarch installed base is too small.

                   

                  I'm just beginning to smell the possibilities of what we have here.  I learned how to import functions from other models, and will indeed set up a common model on our shared network drive so people can import common functions that we develop.  I haven't gotten to it yet, but I'm smelling the possibility that other items such as calculated fields and calculated lookup tables can be imported from the common model as well.  Right, Grant?  And thanks for your lengthy and clear reply!

                   

                  I have taken my company of 10,000 people to about 10 installed Monarch licenses now, and I can envision a whole lot more if we can share objects like functions and lookup tables and calculated fields!

                  • V9 User Defined Functions
                    Grant Perkins

                    Originally posted by frugalman:

                    I haven't gotten to it yet, but I'm smelling the possibility that other items such as calculated fields and calculated lookup tables can be imported from the common model as well.  Right, Grant?  And thanks for your lengthy and clear reply!

                     

                    I have taken my company of 10,000 people to about 10 installed Monarch licenses now, and I can envision a whole lot more if we can share objects like functions and lookup tables and calculated fields! [/b][/quote]frugalman,

                     

                    Yep. I think you are catching on fast to the possibilities (as I see them at least, and there is a great possibility that I haven't spotted most of them!) and my personal belief is that the roll out potential (and resulting benefits throughout an enterprise) is hugely enhanced with this new functionality.

                     

                    One of the problems I can see with the learning guide is that if people use it the way I did back in V3 days (Do the first 5 chapters or so and then leap all over the place according to interests!) they may hit the UDF and Linked Objects stuff a little before it would be optimal.

                     

                    A second problem is that the guide is a bit bigger than it was back then. I think it runs to about 400 pages now. Both UDF and Object Linking, if written at the same level, would probably run to another 80 - 90 pages each. It starts to get to be a very thick book and maybe a little overwhelming. Plus they always seem to disappear!

                     

                    I have a feeling that the new functionality may just be the starting point for a growth in demand for an advanced user book of some form.

                     

                    In part this may be driven by the growth of users we might hope for as a result of a wider rollout within an enterprise. But I suspect that the new features we are discussing in this post will likely provide a broader basis for standardised best practice in the management and cooperation areas of Monarch especially when a wider rollout occurs. In with that consistent core I could see options for adding the specific solutions which might be useful to quite a few users but not enough for any single group of solutions to be able to define and create an advanced user book with a commercial return on the investment.

                     

                    The thing about Monarch is that it is a toolbox for performing a variety of tasks according the the individual needs of the user. The Learning Guide covers the common basics. Once you get into the uncommon areas it is more difficult to deliver useful specifics other than on a case by case basis - which is how the forum works!

                     

                    But I think subjects like "Getting the best out of your shared User Defined Functions" and "Optimising Object Linking for Global Standards" may have a deeper corporate significance and maybe even some budget to buy the book!         

                     

                    Mind you, I also think we might need some snappier titles!

                     

                    Time will tell. There is just the possibility that, as with the longterm Monarch philosophy, a little exposure to these new features results in everyone finding them straightforward to use and clear as to how to make them work best in their environments and thus puts the book on the back burner once again. And in some ways that would be a rather positive comment about Monarch.

                     

                    Grant

                     

                    [size="1"][ March 21, 2007, 03:16 PM: Message edited by: Grant Perkins ][/size]

                    • V9 User Defined Functions
                      frugalman _

                      I just found a document in ProgramsMonarch called Monarch Pro Linked Objects Tutorial (it's a PDF).  It's 85 pages long, and is WONDERFUL!

                      It starts with what is an object (templates, fields, sorts, filters, runtime parameter definitions, summaries, address blocks and external lookups).  Then what is a link, how to find objects, etc.  I think this will tell me what I need to know!