Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
  • 1.  Macro Include Function

    Posted Thu September 07, 2023 11:11 AM
    Edited by Marc Reed Thu September 07, 2023 11:16 AM

    I am trying ti use the Macro Include function, hopefully to reuse code in lots of macros. Alas, I am struggling with something that is probably really simple. I have defined a calculation as

    (I know this isn't a proper macro as the include error says it must be a string with # in it)

    I want to include this in another macro.

    The macro help text has this sample...

    let model = "/content/folder[@name='Calendars']/module[@name='Gregorian calendar4']";
    let mobj = getMetadataObject('TimePerspectiveVariables', model);
    include mobj;  // will get the expression and inline it
    But I cannot find a data module called Gregorian calendar4 that contains a standalone calculation called TimePerspectiveVariables anywhere to copy the code.

    Does anyone have any idea of the format that BaseMacros should look like in order for it to be used in the include function



    ------------------------------
    Marc Reed
    ------------------------------



  • 2.  RE: Macro Include Function

    Posted Thu September 07, 2023 11:35 PM
      |   view attached

    Hi Marc,

    Thanks for the question, yes this is a bit tricky. I've written a trivial example in the included note, hopefully that will get the ball rolling.
    Let me know if you have more questions.



    ------------------------------
    Kind regards,
    Henk Cazemier
    ------------------------------

    Attachment(s)



  • 3.  RE: Macro Include Function

    Posted Fri September 08, 2023 02:05 AM
    Edited by Marc Reed Fri September 08, 2023 05:11 AM

    @HENK CAZEMIER thanks for these samples.

    I think my issue is that I am trying to build macros on macros. (as an aside I use a calculation for Level 1 to work out Level 2, I then try and use Level 2 to work out level 3, and so on.)

    I can use the sample you have supplied to demonstrate this.

    In the samples you have  a calculation called eval_mac_01. This previews to 'abcxyz'. In my head, evaluating the macro expression in eval_mac_01 results in 'abcxyz'

    How can I use the results of eval_mac_01 in another macro?

    For example, if I try:


    let m1 = getMetadataObject (' eval_mac_01 ' );
    evaluate(  m1.expression  )
    #

    I get an error

    Is it possible to use the results from one macro expression into another? I have tried various versions of the calcs but am getting no where.

    EDIT

    After more investigating, I think the basic issue is that it doesn't appear you can nest include statements. 

    If I try and include inc_mac_01 in another macro and use the things that inc_mac_01 can use then you error:  

    ------------------------------
    Marc Reed
    ------------------------------



  • 4.  RE: Macro Include Function

    Posted Fri September 08, 2023 10:15 AM

    Hi Marc,

    The check is probably a little too tight.
    When using evaluate, the text that is referenced must start and end with a '#' sign
    So the referenced macro can not have any leading comments either.



    ------------------------------
    Kind regards,
    Henk Cazemier
    ------------------------------



  • 5.  RE: Macro Include Function

    Posted Fri September 08, 2023 10:52 AM

    For anyone else following this thread...

    These functions are white space sensitive. Some of my issues are because my macros have had a trailing space in them. This isn't visible in the editor. Removing these has allowed me to go to the next step!

    For example is mac01 has a trailing space after the last hash sign that closes the macro these functions will fail.



    ------------------------------
    Marc Reed
    ------------------------------