Errow with IF statement in Scripted Calculation view

Hi Team,
I am trying to use IF statement in Scripted Calculation view.
My scenario is:-
I need to create a restricted Key figure based on input date from user.
While i am activating my view system gives "Internal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Calculation View: SQL: transaction rolled back by an internal error: Syntax Error for calculated Attribute: line 29 col 9 (at pos 1501)" error.
Below is the code i have used in my CV.
CE_CALC('IF((to_int("BUDAT") >= to_int(2013-01-01),"AMOUNT",'''')', DECIMAL(13,2)) AS "DTR"
Here, "AMOUNT" is another calculated field created using CE_CALC.
Without above IF statement my CV runs perfectly fine. The moment i include IF statement it does not activate.
Kindly provide your inputs.
Thanks & Regards,
Anup

Hi Lars,
I am extremely sorry about the confusion.
There was an extra parenthesis in the IF statement which was not allowing the CV to be activated. CV is now successfully activated.
But my data is not getting restricted correctly.
It is showing 0 against all the records.
Below is the sql used for calling the CV.
SELECT * FROM "_SYS_BIC"."A_123/CV_SCR_BSID_BSAD_ITEMS" ('PLACEHOLDER' = ('$$Currency$$', '''Local'''),'PLACEHOLDER' = ('$$Date_From$$','2014-01-01' ), 'PLACEHOLDER' = ('$$Date_To$$','2014-06-30' ));
Below is my updated CE_CALC function :-
CE_CALC('IF(date("BUDAT") >= date(:Date_From) and date("BUDAT") <= date(:Date_To),"AMOUNT",0)', DECIMAL(13,2)) AS "DTR"
Is there any issue while passing values here?
Regards,
Anup

Similar Messages

  • Using Attribute views in Script based Calculation views

    I am trying to create a view for analysis on a fact table which has measure name as a dimension as opposed to having multiple measures. Here is an example of what the data looks like.
    #Customer, Product, Measure, Data
    Customer1, Product1, ASP, 4.2
    Customer1, Product1, Units, 100
    Customer2, Product2, ASP, 4.4
    Customer2, Product2, Units, 200
    ... and so on and so forth.
    I had build Attribute views with hierarchies for both customer and product dimensions and build analytic views. However now I have the need to flatten the Measures dimension and have the resulting Fact view look like:
    #Customer, Product, ASP, Units
    Customer1, Product1, 4.2, 100
    Customer2, Product2, 4.4, 200
    ... and so on and so forth.
    Now I want to build analytic views on this flattened view of my Fact table.
    I was able to create a calculation view using Script mode, on the fact table and write a SQL to flatten the Measure dimension. But I am not able to now join this calculation view with the attribute views. Is there a way to leverage the existing Attribute views and their hierarchies in this case?
    The only way I can see for now is to use manual SQL to build out the entire view, including joining the attribute views and re-build the hierarchies in the definition of the calculation view. This essentially wastes work I have already done in the attribute views and forces me to build the entire thing using SQL.
    Is there a better approach?

    It's extremely annoying that the FLD() command isn't yet availlable in NW, unless it's coming with 7.5 or has been included in one of the more recent support packs.
    As a an alternative you may be able to use the following MDX routine:
    Returns the value of a property of the current member of a dimension
    *function PRO(%DIMENSIONNAME%,%PROPERTYNAME%)
    %DIMENSIONNAME%.Properties("%PROPERTYNAME%")
    *endfunction
    Unfortunately I've never been able to use this with a When statement, so you may have to ask an ABAP resource to develop a BADI to achieve your required results.

  • Writing an sql script to query a calculation view  and an attribute view inside a calculation view

    Hi,
    I was trying to query a calculation view with sql , and as one of the input parameters i was trying to give a query over an attribute view
    So my sql will look like this
    SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"('PLACEHOLDER' = ('$$ACCOUNT_ID$$', '1','$$CHECKLIST_ID$$',' SELECT CHECKLIST_ID FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5'));
    So as an input to $$CHECKLIST_ID$$   i wanted to give an id selected from checklist products table where products id is passed as an input
    but this is not working, i am getting syntax error at the $$CHECKLIST_ID$$ there i can only pass values like  $$CHECKLIST_ID$$, '1'
    Please help me to figure out which  is the correct syntax  i tried putting the sql statement to get the checklist_id in '' but it too didnot work

    I'm not sure you'll be able to do a SELECT subquery directly in the placeholder definition, but you can create another calc view (scripted) as a wrapper to your original calc view and use a scalar variable to pass the parameter over.
    Try this as the base code for your second calc view:
    var_id VARCHAR(10);
    BEGIN
         SELECT CHECKLIST_ID INTO :var_id FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5;
         var_out = SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"
              (PLACEHOLDER."$$ACOUNT_ID" => 1, PLACEHOLDER."$$CHECKLIST_ID$$" => :var_id);
    END
    You could even create input parameters in the second Calc View for the Account Id & Product Id (which are currently hard coded in your code below).
    Best,
    Henrique.
    PS: avoid using SELECT * for the var_out in the scripted calc view. It's better, from a code maintenance perspective, to explicitly define the columns you're outputting.

  • Hierarchy on HANA Calculation View with Optional Input Parameters Fails

    Hi,
    Has anyone succeeded in building a hierarchy on top of a calculation view with optional input parameters, where an input parameter is not filled?
    The original requirement came from the wish to create a parent child hierarchy on a calculation view that was copied into the customer space from a HANA Live Financial Statement query view, but I have found the following when creating a simple level hierarchy on a calculation view that consumes one table. The Calculation View has one Input Parameter where the 'mandatory' box is unchecked.
    Calculation view reads ECC table FAGLFLEXT
    Simple level based hierarchy on fields PRCTR, RACCT and SEGMENT
    Input parameter is used as a filter for PRCTR with logic ("EMPTY" = '$$P_PROFITCTR$$' or "PRCTR" = '$$P_PROFITCTR$$')
    When I run the view I see the following behaviour in HANA Studio and Analysis for Excel
    Before building the hierarchy I could run the view with or without the Input Parameter
    After building the hierarchy I can run the view with the Input Parameter filled, but it fails when the Input Parameter is not filled.
    Error message is "error: search table error:  [2426] missing placeholder; missing value for mandatory parameter P_PROFITCTR"
    P_PROFITCTR is not a mandatory parameter, but the selection for the hierarchy view thinks it should be. I don't find any notes around this issue, so I don't think it's version related, however the version I have used for this test is 1.00.70.
    It's a shame we can't currently build the hierarchy as the parent child relationship is provided in HANA Live view NewGLFinancialStatementQuery.
    Thanks,
    Ken

    Hi Ken,
    We have been facing similar issue. We have even tried to set default value and as optional parameter. View still fails to create hierarchy (we are not using HANA live). As mentioned on page 97 of HANA modelling guide input parameter is mandatory from engine point of view. Hierarchy is generated as column view during the initial activation of calculation view and therefore expect a value by caller.
    This seems to be a product error. Some one from HANA development team should explain this issue in detail. I would expect someone like Thomas Jung reply to us.
    At the moment, we cant use input parameter for date prompt which gives us calendar popup feature for date selection. Hierarchies just don't work with input parameter. We are missing something.
    Regards
    Angad

  • Out of memory Error while querying SQL Script based Calculation View

    Hi All,
    I wanted to test the performance of Graphical and SQL Script based Calculation views.
    Created Graphical (CA_GRPH) and SQL Script (CA_SQL) Calculation views.
    Analytic View (AN_GRPH) for both Calculation views are the same which is Graphical based (90 Attributes and 5 Measures)
    In Analytic View data foundation I have a Fact table which has 1.5 Billion records and 9 Dimension Tables –collectively 500 million records (7 Attribute Views). 9 Referential joins with cardinality N:1 and 1 Referential join with cardinality N:N.
    I wanted to keep (CA_GRPH) and (CA_SQL) as a base Calculation views and leverage those to create various calculation views (Will be creating different Calc views for respective Business segments)
    In order to test this I have created below calc views on top of base calc views.
    Graphical Based: Created (CA_GRAPH_XYZ) by having CA_GRPH in projection with 30 Calculated Columns. – This retrieves data in 13 secs
    SQL Script Based: Created (CA_GRPH_ABC) by having CA_SQL in projection view with 30 calculated columns – This errors out after 1.50 mins.
    Could not execute 'SELECT "COLUMN_A","COLUMN _B"," COLUMN _C"," COLUMN _D", SUM("COLUMN _REVENUE") AS ...' in 1:50.480 minutes .
    SAP DBTech JDBC: [2048]: column store error:  [2048] column store error: search table error: [1000002] Error executing physical plan: exception 1000002:
    ltt/impl/memory.cpp:63
    Out of memory ; $size$=1507711; $name$=ihm; $type$=pool; $inuse_count$=170104; $allocated_size$=219215007925
    exception 1000002:
    Any suggestion / help in fixing this issue will be greatly appreciated.
    Regards,
    Av

    Hi Raj,
    Thanks for your time, please find edited snap hot of Analytic View (AN_GRPH) below,
    Calculation view(CA_SQL)
            /********* Begin Procedure Script ************/
    BEGIN
           var_out =
         SELECT
                "COLUMN_1"
                "COLUMN_2",
                "COLUMN_84",
                "COLUMN_85;",
                SUM("REVN") AS "REVN",
                SUM("MGN") AS "MGN",
                SUM("ORD_QTY") AS "ORD_QTY",
                SUM("SYS_QTY1") AS "SYS_QTY1",
                SUM("SYS_QTY") AS "SYS_QTY"
    FROM
          "_SYS_BIC"."XYZ/AN_GRPH"
    GROUP BY
                "COLUMN_1"
                "COLUMN_2",
                "COLUMN_84",
                "COLUMN_85";
    END
    /********* End Procedure Script ************/
    Later i have built one more Calculation view(CA_GRPH_ABC) using (CA_SQL)in projection. i have 30 calculated measures in this final calc view. this final calc view is throwing above mentioned error.
    Not sure if i can use SQL script based calc view in graphical based calc views?
    Regards,
    AV

  • Syntax error while creating Calculation view script based

    Hi Folks,
    I'm creating Calc view based on script and drafted a simple code but I'm getting syntax error.
    Its just fetching few coloumns from two tables products and purchaseorderitem.
    /********* Begin Procedure Script ************/
    BEGIN
      var_out = select productid , category, nameid, currency, grossamount, quantity
      FROM sap.hana.democontent.epm.data.products AS P , sap.hana.democontent.epm.data.purchaseorderitem AS B
      where P.productid = B.productid;
    END /********* End Procedure Script ************/
    Could you pls take a look and let me know what wrong I'm doing?
    Error logs are:-
    sap.hana..package.project.folder.mytest.CALCSCRIPTVIEWInternal deployment of object failed;Repository: Encountered an error in repository runtime extension;Internal Error:Deploy Calculation View: SQL: sql syntax error: incorrect syntax near "democontent": line 5 col 18 (at pos 439)nSet Schema DDL statement: set schema "SYSTEM"nType DDL: create type "_SYS_BIC"."sap.hana..package.project.folder.mytest/CALCSCRIPTVIEW/proc/tabletype/VAR_OUT" as table ("PRODUCTID" NVARCHAR(10), "CATEGORY" NVARCHAR(2), "NAMEID" NVARCHAR(10), "CURRENCY" NVARCHAR(5), "GROSSAMOUNT" DECIMAL(15,2), "QUANITYT" DECIMAL(13,3))nProcedure DDL: create procedure "_SYS_BIC"."sap.hana.package.project.folder.mytest/CALCSCRIPTVIEW/proc" ( OUT var_out "_SYS_BIC"."sap.hana.package.project.folder.mytest/CALCSCRIPTVIEW/proc/tabletype/VAR_OUT" ) language sqlscript sql security definer reads sql data as n /********* Begin Procedure Script ************/ n BEGIN n t var_out = select productid , category, nameid, currency, grossamount, quantityn t FROM sap.hana.democontent.epm.data.products AS P , sap.hana.democontent.epm.data.purchaseorderitem AS Bn t where P.productid = B.productid;nnEND /********* End Procedure Script ************/n

    Hi Rubane,
    I don't have EPM installed here but based on this Table User Defined Functions( Table UDF ) in HANA  you are not properly defining the source table.
    In your case missing 1) schema of EPM, 2) not using double quotes, 3) separation of package and view, 4) missing camel case on purchaseOrderItem:
    FROM sap.hana.democontent.epm.data.products AS P , sap.hana.democontent.epm.data.purchaseorderitem AS B
    On blog:
    from "SAP_HANA_EPM_DEMO"."sap.hana.democontent.epm.data::businessPartner" as a
    SAP_HANA_EPM_DEMO is the schema
    sap.hana.democontent.epm.data is the package
    businessPartner is the view
    Start simple... before the seletion try it out on Studio SQL.
    Regards, Fernando Da Rós

  • Calculation view with input parameters

    Hello there.
    I got a calculation with that expects 2 input parameters.
    But now I have to created another calculation view that import this calculation view.
    How can I pass these 2 parameters using sqlscript?
      My script so far
      cv1 = CE_CALC_VIEW("_SYS_BIC"."calc_1",["CR"],'"COMPANY"=''7000''');
    I must pass 2 parameters in this  "_SYS_BIC"."calc_1" table

    Hi Tiago,
    as I am aware, you cannot pass input parameters to CE function.
    You can try using regular SQL syntax:
    SELECT "CR" FROM "_SYS_BIC"."calc_1"
    WHERE "COMPANY" = 7000
    (PLACEHOLDER."$$PARAM_1$$" => VALUE_1,
    PLACEHOLDER."$$PARAM_2$$" => VALUE_2)

  • Underlying SQL or SQL Script for Calculated Views Create Graphically

    Hello,
    Is it possible to view the SQL or SQL script generated for calculated views that are created graphically?

    Hi Mike,
    For your calculation view you will find the corresponding column view created in schema '_SYS_BIC'-->Column Tables->
    <packagename>/<Calculation view> --> Open Definition of this and check the 'create statement'.
    Note: This is a information modeler generated SQL script which will show the generated Calculation Scenario and the respective Column View.
    Regards, Rahul
    Seems the answer was already given by Murali while I typed
    Edited by: Rahul Pant on Mar 2, 2012 5:22 AM

  • Error while creating a BO Universe (using IDT) on top of SAP HANA Calculation View with Input Parameters

    Hi All..
          We are trying to create a Universe (using IDT-Version4.0) on top of the HANA Calculation view. The Calculation view has 4 input parameters, So
    in Universe side we have created the respective prompts. For the creation of derived table we have used the following code
    SELECT *
    FROM "_SYS_BIC"."<schema_name>.<CV_Calculation_View_test>"
    'PLACEHOLDER'=('$$IP_A$$','@Prompt(A)'),
    'PLACEHOLDER'=('$$IP_B$$','@Prompt(B)'),
    'PLACEHOLDER'=('$$IP_C$$','@Prompt(C)'),
    'PLACEHOLDER'=('$$IP_D$$','@Prompt(D)')
    While validating the above code we are getting an error.
    I have attached the snapshot of that error for your reference. Please find the attachment and help me in resolving it.
    Thanks in advance.

    Hello George,
    I don't have any personalization set on the info space. Also I am using mapped Account in BI to connect to HANA. The confusing part is that it is able to validate the infospace with the input parameters and index it. However query does not return any results. I even tried running the same query which explorer sends to HANA in the SQL editor and there too the same results,the query does not return anything. The model does return data when I do a data preview and if accessed from other tools like AAO.
    Also when I use SSO connection to HANA, indexing of the infospace fails. Where can I see the error log?
    Thanks,

  • Calling a procedure from Calculation View with Debug function

    Is it possible to call a debuggable hana procedure in a calculation view?
    I just saw the video  HANA Academy - HANA Native Development Workshop: SQL Script Editor - YouTube for HANA Native Development workshop and got the debug functionality to work for a file Procedure.
    But I am unable to call this procedure from a Calculation View.
    Below is the code I am using for the SQLScript Calculation View. Can someone tell me if this is correct?
    /********* Begin Procedure Script ************/
    BEGIN
    call "_SYS_BIC"."test-package.RF.SalesOrders.procedures/get_sls_ordtype"(SalesDocNo => '0070004105', SalesDocTypes => ?) ;
    var_out = CE_PROJECTION(:SalesDocTypes, ["SALESDOCNO" , "SALESDOCTYPE", "ORDVALUE"] );
    END /********* End Procedure Script ************/

    Hello,
    Just provide the out parameter in the call:
    Declare
      amount   number; -- OUT number argument populated by the procedure
    Begin
      -- call the X procedure --
      x( amount ) ;
    End;Francois

  • Using calculation view in excel with input parameters

    Hello
    I have a calculation view which receives 2 input parameters for a range of dates, when i create the connecction with Excel i get the error "sql processing error: Hierarchy source query: SQL: column store error: search table error: [34092] search on calculation model requires parameters: Required variable $$MyVariable$$ is not set"
    I would like to know how can i pass the parameteres from excel to my calculation view??
    Thanks

    I doubt this can be achieved with a native Excel connection. Try SAP Advanced Analysis for Office. (I believe it may now just be called Analysis for Office).

  • Calculated view with input parameters

    Hello there.
    I've created a calculated view with input parameters, which I am going to call  it  'VIEW_A'.
    This view has been working just fine.
    But now I have to create another calculated view and import the last one(VIEW_A) in a projection.
    But I got a error when trying to see the data content. 
    It says :
    Error: SAP DBTech JDBC: [2048]: column store error: search table error:  [6968] Evaluator: syntax error in expression string;expected TK_ID,parsing '"DT_DOC_MES_ANO" >= [here]and "DT_DOC_MES_ANO" <='
    At the 'Problems' panel it says the all the input parameters are unmapped.
    What Am I doing wrong?  Sorry but I am kind new at SAP world.

    http://scn.sap.com/message/15489475Hello Tiago,
    Could you please let me know if you're able to resolve your issue, I'm getting the similar error when I'm passing alpha numeric values as parameter via my SP.
    Thanks for your help in advance!
    Regards,
    Sathish

  • With As subquery block in create view statement or In pl/sql block

    Hi All,
    Can I use the With as subquery block in create view statement??
    or in pl/sql
    -Thanks
    Edited by: xwo0owx on Mar 31, 2011 11:23 AM
    Edited by: xwo0owx on Mar 31, 2011 11:23 AM

    Hi, Mike,
    Dird wrote:
    Then why do I get an error? :s create view mike_test_view as    
    with carriers as(
    SELECT DISTINCT T0.CARRIER_SHORT_NAME carrier_name,
    T1.COMP_ID            carrier_id
    FROM CS2_CARRIER T0, USER_FUNCTION_QUALIFIER T2, CS2_COMP_SERV_PROV_PROF T1
    WHERE (((T1.SERV_PROV_ID = T2.QUALIFIER_VALUE) AND
    ((T2.FUNCTION_CODE = 'DOC_CCM') AND
    (T2.QUALIFIER_CODE = 'CARRIER_LIST'))) AND
    (T1.SERV_PROV_ID = T0.SERV_PROV_ID))
    ORDER BY T0.CARRIER_SHORT_NAME)
    select *
    from carriers c;ORA-00942: table or view does not exist -- carriers
    If I run every line but the create (just execute the query) it runs fine. It also works fine in a PL/SQL procedure.SQL*Plus abhors a vacuum.
    The default in SQL*Plus is that you can not have a completely blank line (that is, a line containing only white space) in the middle of a SQL statement. (Blank lines are okay in PL/SQL, including SQL statements embedded in PL/SQL.)
    If you want some space between the end of the WITH clause and the beginning of the main query (or anywhere else, for that matter), you can put comments there. For example:
          ORDER BY T0.CARRIER_SHORT_NAME)
         select *
           from carriers c;Now that line isn't just whitespace; it has the comment sign, and that's enough for SQL*Plus.
    You can allow completely blank lines with the SQL*Plus command:
    SET   SQLBLANKLINES  ON

  • Smo.Server.ExecuteNonQuery throw an error executing a script with IF statement

    I am trying to executed this script (see below) using Smo libraries with powershell (this script works in SSMS)
    use master;
    GO
    use master;
    if (not exists(select * from sys.databases where name = 'dbname'))
        alter database [dbname] set offline with rollback immediate;
    GO
    however, I always got an
    Exception calling "ExecuteNonQuery" with "1" argument(s): "An exception occurred while executing a Transact-SQL statement or batch."
    if I delete the if statement, the script execute without erros... is there any problem to use if statements?  I would really appreciate any help
    regards.!

    Olaf
    Helper answer does make sense and you won't be able to modify database which doesn't exists. However, your syntax's are correct.
    However, if you are executing it via Powershell as mentioned by HoroChan then
    I recommend you to increase the statementTimeout to appropriate value. 
    There may be chances that alerting database got hanged and exceeded the timeout.  So instead of IMMEDIATE ROLLBACK you can use
    WITH NO WAIT
    From MSDN:
    Specifies that if the requested database state or option change cannot complete immediately without waiting for transactions to commit or roll back on their own, the request will fail.
    So your overall code will look like 
    USE MASTER;
    IF EXISTS(select * from sys.databases where name = 'dbname')
    ALTER DATABASE [dbname] SET OFFLINE WITH NO_WAIT
    GO
    Hope this will help.

  • Invalid column Index error - While consuming Calculation view via Native SQL

    Hi Experts,
    I am trying to consume a Calculation view (sql script one) , which has input parameters, via Native SQL in a ABAP program .
    Code snippet for the same would be as follows , Upon execution, it throws an error "Invalid Column Index (8) error " . Can anyone help what could be the issue here ?
    Thanks in Advance,
    Suma
    REPORT ZTEST_HANA2.
    *Report to consume Calculation view (script based) from ABAP
    PARAMETERS: ip_docnr type BELNR_D,
                ip_gjahr type GJAHR,
                ip_bukrs type BUKRS,
                ip_blgr type FAGL_RLDNR.
       DATA: LO_SQL_STMT TYPE REF TO CL_SQL_STATEMENT,
              LO_CONN     TYPE REF TO CL_SQL_CONNECTION,
              LO_RESULT   TYPE REF TO CL_SQL_RESULT_SET,
              LV_SQL      TYPE STRING,
              LR_DATA     TYPE REF TO DATA.
        DATA: LX_SQL_EXC           TYPE REF TO CX_SQL_EXCEPTION,
              LT_SEPMAPPS_CLSDINV  TYPE TABLE OF SEPMAPPS_CLSDINV,
              LV_TEXT              TYPE STRING.
        TRY.
    lv_sql = |SELECT * FROM "_SYS_BIC"."DEMO-ABAP/CA_GET_FI_DATA" | &&
                     |WITH PARAMETERS ('placeholder'= ('$$p_DOCNR$$','{ ip_docnr }'),| &&
                      |'placeholder'=('$$p_GJAHR$$','{ ip_gjahr }')| &&
                      |,'placeholder'= ('$$S_BUKRS$$','{ ip_bukrs }')| &&
                      |,'placeholder'= ('$$p_base_ledger$$','{ ip_blgr }') )| .
             LO_CONN = CL_SQL_CONNECTION=>GET_CONNECTION( ).
             "Create an SQL statement to be executed via the connection
              LO_SQL_STMT = LO_CONN->CREATE_STATEMENT( ).
             "Execute the native SQL query
             LO_RESULT = LO_SQL_STMT->EXECUTE_QUERY( LV_SQL ).
             "Read the result into the internal table lt_sepmapps_clsdinv
             GET REFERENCE OF LT_SEPMAPPS_CLSDINV INTO LR_DATA.
             LO_RESULT->SET_PARAM_TABLE( LR_DATA ).
             LO_RESULT->NEXT_PACKAGE( ).
             LO_RESULT->CLOSE( ).
             LO_CONN->CLOSE( ).
        CATCH CX_SQL_EXCEPTION INTO LX_SQL_EXC.
             LV_TEXT = LX_SQL_EXC->GET_TEXT( ).
             MESSAGE LV_TEXT TYPE 'E'.
        ENDTRY.

    Hi Suma,
    Post the SQL you success run directly on Studio together with error message (even if is the Invalid column index error).
    Check there if the parameters case is working properly... Is it really this confusing options:
    p_GJAHR
    S_BUKRS
    p_base_ledger
    Why not all lower or all upper? Anyhow you must test and find which option works according your modeling
    Regards, Fernando Da Rós

Maybe you are looking for