Cognos Analytics

 View Only
Expand all | Collapse all

Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

  • 1.  Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Tue June 06, 2023 05:22 PM

    Re: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    I think it is, but having a hard time getting started and I don't know the correct terminology to use. I am an MS SQL developer so the SP is not the problem. It is the FM. 

    So first step would be to import the SP into FM. Obviously the SP (MS SQL) would have three varchar parameters and have a single SELECT at the end (single result set returned) .

    Second step is the prompts. Two of the prompts read the same table - RelationshipCode. Prompt1 - client selects each RelationshipCode that is a Sole Owner. Prompt2 - client selects each RelationshipCode that is a Joint Owner. Prompt3 - reads the account table with a DISTINCT needed on AccountType. If the client enters nothing in one of the prompts I want to be able to know that in my SP and will use default values. 

    Do the prompts need to be in FM? And if the client selects multiple entries for a prompt will they be passed as a CSV string to the SP? Guess how to setup the prompts and then associate the selections to the SP is my primary stumbling block. 

    Does anyone have a small example, any doc, links or even informal steps on how to get started?



    ------------------------------
    brenda grossnickle
    BI Programmer Analyst
    FIS
    ------------------------------


  • 2.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Wed June 07, 2023 02:13 AM

    Hey Brenda,

    I use a SP to let users decide which kind of ETL job they want to perform during the day. The Sp has two parameters: pUSER and pJOB. Both are linked to macro functions in FM to achieve the desired behaviour: pUSER can't be modified as this is the user that clicks the button and pJOB is a prompt value that comes from a drop-down list.

    Here's my setup in FM. As you can see, you "just" have to write the right macro function for each parameter. Of course you can use this short version or even type the default values right into the prompt macro. It's up to you (hope this helps):



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 3.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Fri December 22, 2023 11:32 AM

    Hi Mr. Robert,

    I created a value prompt (dropdown list) that references a querie that uses a very similar scenario that you a re showing here. My issue is that this only work when I execute the query itself, with the report don't works... do you have any idea what's could be happening in my case?

    Thank you so much.



    ------------------------------
    Rudak Duarte Mendonça
    ------------------------------



  • 4.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Sat December 23, 2023 04:27 AM

    Hi @Rudak Duarte Mendonça,

    what I've forgotten to tell is that if you use a stored procedure you always have to add one OUT parameter to it. This is the case as Cognos always needs returned data from a query. If you only create IN parameters to be sent to the SP, then Cognos does not execute the query as there's no data coming back.

    Here's an example of a very simple SP that inserts a row into a table and returns a string to the Cognos query:

    In the Cognos query and on the report page (somewhere) you have to place the return data column so the query get's executed. Cognos then sends the data via IN parameters to your SP and the SP returns the data of the OUT parameter which Cognos than shows o the report page.

    I use conditional blocks to change what is displayed. If the parameter is empty/null, the drop down box is shown. When a user selects and sends the value of the drop down box, the parameter is not null any more and the conditional block changes to show the returned data from the query.

    Is that helpful?



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 5.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Wed December 27, 2023 04:58 AM

    Hello Mr. Robert,

    Thank you for your kindness. Let me explain the details. I think my SP already has a return value, because when I run the query inside Cognos Reports, I get "1" as a result. Let me share my SP source:

    Explaining the scenario: the user will choose a month to open, but can close all months. By choosing "Close", all months will be closed; If you choose a single month, that one will be open and the others will be closed. Simple here.

    The problem is: I created a dropdown prompt object that uses SP through Framework, but running the entire report doesn't work:

    But when I run the "View Tabular Data" of the same query used in the dropdown object, the SP runs and updates the table normally:

    The main question is: why, in my case, does it only work with "View Tabular Data" and does not work when running reports, if they both use the same query?

    Thank you!



    ------------------------------
    Rudak Duarte Mendonça
    ------------------------------



  • 6.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Wed December 27, 2023 08:05 AM

    create table log_table (mes nvarchar(15), update_dt datetime)

    insert into log_table(mes, update_dt)

      select @mes, getdate()

    for debugginig I would create a logging table and then insert into that table from your sproc. i found that my sproc was executed multiple times, seemed to be one time for each report parameter. Then query your logging table ordered by update_dt to see how many times your sproc is executed. if the sproc is executed multiple times per report, does your @mes parameter value stay the same or is it reset? 



    ------------------------------
    brenda grossnickle
    BI Programmer Analyst
    FIS
    ------------------------------



  • 7.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Sun December 31, 2023 03:46 AM

    Hi @Rudak Duarte Mendonça,

    just to be clear: have you forced Cognos to run the SP after the user have selected a value from the dropdown-box?
    My aproach is to have the following items: the dropdown-box which sits in a conditional block. That block ist linked to a bool variable that checks if the the parameter of the dropdown-box has been set or not. If NO then show the dropdown-box, if YES then show the result (list, singleton, crosstab) of the query that has the returned value from the SP. This setup forces Cognos to hand over the choosen parameter value from the dropdown-box to the SP and executes it as it as the conditional block now has to show the YES variant and switches to the other view.

    Got it?



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 8.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Wed June 07, 2023 02:42 AM

    You can do this in report studio by using a SQL object from your toolbox and calling the stored proc. Set the source to your DB / data source and paste in the stored proc in the format as shown below. It's a basic example that has a start and end date parameter. You'll need to use prompt macros to get it to work. This is the only time I've ever had to do this but it works fine. There are probably better ways...

    {EXECUTE report.spOutputExample @StartDate = #Prompt('Start Date', 'varchar')#, @EndDate = #Prompt('End Date', 'varchar')#}



    ------------------------------
    Eric Mueller
    ------------------------------



  • 9.  RE: Cognos Report Studio with prompt values passed to Stored Procedure which returns report data - is it possible?

    Posted Wed June 14, 2023 02:40 PM

    If a procedure assumes to receive several values in a single parameter, then you'd need to use the macro features. See examples in Chapt4 re split/join etc
    https://www.redbooks.ibm.com/redbooks/pdfs/sg248121.pdf

    Normally you would set them up in a model  and define how the values are passed (prompts or constants etc)
    https://www.ibm.com/docs/en/cognos-analytics/12.0.0?topic=subjects-creating-modifying-stored-procedure-query

    Should the procedure author presume transactional semantics (i.e. commit) then see also
    https://www.ibm.com/docs/en/cognos-analytics/12.0.0?topic=mode-stored-procedures-transaction-access-modes



    ------------------------------
    NIGEL CAMPBELL
    ------------------------------