STRING_AGG function in SAP HANA SQL Script

Hi,
We have HANA Revision 7.3.
STRING_AGG function seems to work when we just execute the query without assinging it to the value.
However as soon as we assign it to a value in a stored procedure or scripted Calcuation view, it fails.
Any ideas?
Thanks,
Hyun

Lars,
My apologies.
Here are 3 screen shots. Two are error message generated
when using STRING_AGG in a Calculation View, one is it running successfully in
SQL window when it is not assigned to output variable.
Thanks,
Hyun

Similar Messages

  • How to test a simple PL SQL function from another PL SQL script

    Hi,
    I have created a function. Now i need to test that whether it is returning the correct values or not.
    For that, i have written anothe pl sql script and trying to call this function. Im passing all the IN parameters in that function. I assume here that OUT parameters will provide me the result. Im trying to display the OUT parameter one by one to see my result.
    I'm using toad as sql client here connected with oracle.
    pl sql script:-
    DECLARE
    BEGIN
         DBMS_OUTPUT.PUT_LINE('$$$$$$$ VINOD KUMAR NAIR $$$$$$$');
         FETCH_ORDER_PRODUCT_DATA(320171302, 1006, 6999,
    ODNumber OUT VARCHAR2, Line_Number OUT VARCHAR2,
    ServiceID OUT VARCHAR2, BilltoNumber OUT VARCHAR2,
    AnnualPrice OUT NUMBER, CoverageCode OUT VARCHAR2)
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | ODNumber );
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | Line_Number );
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | ServiceID );
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | BilltoNumber );
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | AnnualPrice );
    DBMS_OUTPUT.PUT_LINE('HERE IS THE RESULT ' | CoverageCode );
    END;
    Function:-
    Program Name : SPOT_Order_Product_Data_For_CFS.sql
    Description : Function to Validate parameters from CFS
    By : Vinod Kumar
    Date : 08/19/2011
    Modification History
    By When TAR Description
    CREATE OR REPLACE FUNCTION FETCH_ORDER_PRODUCT_DATA(orderNumber IN VARCHAR2, customerNumber IN VARCHAR2,
    productLine IN VARCHAR2, ODNumber OUT VARCHAR2,
    Line_Number OUT VARCHAR2, ServiceID OUT VARCHAR2,
    BilltoNumber OUT VARCHAR2, AnnualPrice OUT NUMBER,
    CoverageCode OUT VARCHAR2)
    RETURN VARCHAR2 IS
    lv_err_msg VARCHAR2(100) := '';
    lv_bucket_id VARCHAR2(14);
    lv_bill_number VARCHAR2(30);
    lv_anual_price NUMBER;
    lv_coverage_code VARCHAR2(8);
    lv_quote_num NUMBER(10) := NULL;
    lv_line_num NUMBER(5) := 0;
    lv_customer_number VARCHAR2(30) := customerNumber;
    lv_product_id VARCHAR2(14) := productLine;
    lv_count_quote NUMBER := 0;
    lv_quote_status VARCHAR2(5);
    lv_quote_version NUMBER(2):=0;
    BEGIN
    IF INSTR(orderNumber, '-') = 0 THEN
    lv_quote_num := orderNumber;
    ELSE
    lv_quote_num := SPT_Delimiter(orderNumber, 1, '-');
    lv_line_num := SPT_Delimiter(orderNumber, 2, '-');
    END IF;
    --Check status of the quote COM, APP
    SELECT COUNT(*) INTO lv_count_quote FROM sot_order_header WHERE ORDER_NUMBER=lv_quote_num
    AND ORDER_STATUS IN ('APP', 'COM') AND CUSTOMER_NUMBER = lv_customer_number;
    IF lv_count_quote = 0 THEN
    lv_err_msg := 'Invalid Order number';
    RETURN lv_err_msg;
    END IF;
    -- Fetch the latest version on SPOT quote
    SELECT MAX(VERSION_NUMBER) INTO lv_quote_version FROM SPT_QUOTE_HEADER WHERE QUOTE_NUMBER = lv_quote_num
    AND CUSTOMER_NUMBER = lv_customer_number;
    -- If quote is valid fetch the data in OUT parameters
    IF lv_line_num = 0 THEN
    BEGIN
    SELECT a.CUSTOMER_BILLTO_NUMBER,
    b.LINE_NUMBER, b.BUCKET_ID,
    b.ANNUAL_REF_RATE_USD, b.COVERAGE_CODE
    INTO lv_bill_number,lv_line_num,lv_bucket_id,lv_anual_price,lv_coverage_code
    FROM SPT_QUOTE_HEADER a, SPT_QUOTE_LINE b
    WHERE a.QUOTE_NUMBER = lv_quote_num
    AND a.CUSTOMER_NUMBER = lv_customer_number
    AND a.VERSION_NUMBER = lv_quote_version
    AND a.QUOTE_NUMBER = b.QUOTE_NUMBER
    AND a.VERSION_NUMBER = b.VERSION_NUMBER
    AND b.PRODUCT_ID = lv_product_id;
    ODNumber := lv_quote_num;
    BilltoNumber := lv_bill_number;
    Line_Number := lv_line_num;
    ServiceID := lv_bucket_id;
    AnnualPrice := lv_anual_price;
    CoverageCode := lv_coverage_code;
    RETURN '';
    EXCEPTION WHEN OTHERS THEN
    lv_err_msg := 'Multiple PIDs existing in the SPOT order, please provide the SPOT order + line number as input data';
    RETURN lv_err_msg;
    END;
    ELSE
    BEGIN
    SELECT a.CUSTOMER_BILLTO_NUMBER,
    b.BUCKET_ID, b.ANNUAL_REF_RATE_USD,
    b.COVERAGE_CODE
    INTO lv_bill_number,lv_bucket_id,lv_anual_price,lv_coverage_code
    FROM SPT_QUOTE_HEADER a, SPT_QUOTE_LINE b
    WHERE a.QUOTE_NUMBER = lv_quote_num
    AND a.CUSTOMER_NUMBER = lv_customer_number
    AND a.VERSION_NUMBER = lv_quote_version
    AND a.QUOTE_NUMBER = b.QUOTE_NUMBER
    AND a.VERSION_NUMBER = b.VERSION_NUMBER
    AND b.PRODUCT_ID = lv_product_id
    AND b.LINE_NUMBER = lv_line_num;
    ODNumber := lv_quote_num;
    BilltoNumber := lv_bill_number;
    Line_Number := lv_line_num;
    ServiceID := lv_bucket_id;
    AnnualPrice := lv_anual_price;
    CoverageCode := lv_coverage_code;
    RETURN '';
    EXCEPTION WHEN OTHERS THEN
              lv_err_msg := 'Multiple SPOT lines exist with same parameter';
              RETURN lv_err_msg;
    END;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    lv_err_msg := '@@@ EXCEPTION THROWN @@@ '|| SUBSTR(SQLERRM,1,120);
    RETURN lv_err_msg ;
    END;
    Don't look at the function, it might have errors but my primary concern is how to test this function. Once I start doing its testing then only i can understand any bugs(if any).
    My pl sql is not so good. Im still learning. I don't understand IN and OUT parameters are.
    I just know that IN parameters r those whick we pass in to the function wen we call it and OUT parameters are those through which we get the result.
    Thanks in advance
    Vinod Kumar Nair

    20100511 wrote:
    I wondered how I could test the output of the function from within TOAD?I usually create the following function in my developer schema:
    create or replace function BoolToChar( b boolean ) return varchar2 is
    begin
      if b then
        return( 'TRUE' );
      else
        return( 'FALSE' );
      end if;
    end;To test a function like yours, the following will do in SQL*Plus/TOAD/etc:
    begin
      DBMS_OUTPUT.put_line(
        BoolToChar( XCCC_PO_APPROVALLIST_S1.does_cpa_exist(1017934)  )
    end;
    I'm probably doing 101 things wrong here, but thought I'd ask anyway and risk being shouted at.Shout at? You reckon? I thought people risked being beaten with a lead pipe, or pelted with beer cans and stale pretzels - which makes being shouted at a really safe and viable alternative. {noformat};-){noformat}

  • Guidelines for HANA SQL Script

    Dear Experts,
    Could you please share best practices on the usage of SQL script in procedures and Script based calculation views?
    I searched already for the relevant information, but could not find any yet. I request you share any information other than what is available in help.sap.com based on your experience.
    Thank you,
    Raghavendra.

    Hi Raghavendra,
    As Lars said, it is very difficult to answer your question and it always depend on the designing solution for specific requirements. General rules we follow in scripting are
    1. Avoid inline queries
    2. Break complex SQL to small and simple SQL statements and club the results
    3. Always analyze cost using Visualize Plan
    4. Avoid cursors/loops
    5. Avoid mix of SQL and CE (most commonly found best practice )
    Regards,
    Chandra.

  • 'Function in SAP HANA is currently not possible' error message at KE91 transaction

    System details:
         HANA Server - SPS7
        and  IDES ECC 6.0 EhP 6
    Background:
    Trying to implement  ERP Profitability Analysis accelerator for SAP HANA. We completed the configurations successfully as per the RDS building block guide
    V29 – ERP Finance and Controlling Accelerator with SAP HANA General Configuration and  VD1 – ERP profitability Analysis Accelerator with SAP HANA Configuration
    We could also see the tables (with data) replicated to HANA via HANA Studio.
    And all the statuses at tcode KEHC shows as green.
    Issue Description: When we try to test the Accelerated Transactions like KE91 kind of drill down reports
    Execute.I get the following pop-up. So, here Since I need to get data from HANA I select NO button
    Surprisingly I get the following error message.
    We have tried with other Accelerated transactions like KEU5,KEUB.But I get the same pop-up msg, and get the same error msg at status bar .
    Any help in this would be very helpful.

    Hi Kenny,
    Sorry for my late reply
    Here is the snapshot of SM21 system log
    I realized, this join path 'JP01' error msg I am getting even when running column views at HANA SQL editor.
    Could not execute 'select VRGAR, sum(vv010001) from "ERPTRI_800"."CE2CE4IDEA_HDB" group by vrgar' in 386 ms 128 µs . SAP DBTech JDBC: [2048]: column store error: search table error:  [2920] invalid schema: found inconsistent join path  "jp01" for viewattribute "MANDT" with fact table "ERPTRI_800:CE4IDEA" on olap index; for cube ERPTRI_800:CE2CE4IDEA_HDB
    Actually, All these Column Views and its underlying tables are got created from the given RDS solution only. Not sure why is this errorgetting triggered.IS this kind of bug in RDS solution?!!
    Regards
    Lokesh

  • SAP HANA Expert Script in BW Transformation

    Dear All,
    Please can anyone share some resource (as well as the sample codes) around Hana Expert Script in BW Transformation (Trx Code: RSA1).
    Many thanks,
    Sen

    Nanda,
    Check if generated transformation corresponds to inTab and outTab structures (you can find inTab and outTab fields as commented lines at the beginning of transformation. Also you can try to drop and regenerate this transformation with the same script. Or try to paste your statement in the following manner:
    outTab =
    SELECT
         "/BIC/ZOI_EBELN",
         RECORDMODE,
         "/BIC/ZEPMPNL"
    FROM
         :inTab;
    What is an "error line" this time?
    Best regards,
    Andrew
    P.S.
    You can ask your customer to provide you an install package of HANA Studio as it's usage included in  BW on HANA license.
    Message was edited by: Andrew Eliseev

  • What is the SQL ROWNUM equivalent in HANA SQL script

    Hi,
    Could any one let me know what is the ROWNUM equivalent in HANA? Thanks for the help.
    Thanks,
    Jyothirmayi

    Hi Jyothirmayi,
    ROW_NUMBER() OVER (ORDER BY <FIELD LIST>) is the function to generate row numbers.
    ORDER BY clause is mandatory to generate row numbers in HANA.
    Regards,
    Chandra.

  • Error while exceuting a SAP HANA Procedure

    Hi HANA Gurus,
    I am new to HANA SQL Scripting and I have created the following procedure
    CREATE PROCEDURE "RAJ_HANA"."CURSOR_FOR_LOOP" LANGUAGE SQLSCRIPT
    AS
    VAR_EMNO INTEGER;   
    CURSOR EMP FOR SELECT EMPNO FROM "RAJ_HANA"."EMP";
    BEGIN  
    FOR EMP_CUR AS EMP DO
    FETCH EMP INTO VAR_EMNO;
    INSERT INTO "RAJ_HANA"."EMP_1" VALUES(:VAR_EMNO) ;
    SELECT * FROM "RAJ_HANA"."EMP_1";
    END FOR;
    END;
    Error:
    Could not execute 'Call "RAJ_HANA"."CURSOR_FOR_LOOP"' in 41 ms 684 µs .
    SAP DBTech JDBC: [150]: statement cancelled or snapshot timestamp already invalidated: [150] "RAJ_HANA"."CURSOR_FOR_LOOP": line 8 col 1 (at pos 147): [150] (range 3): statement cancelled or snapshot timestamp already invalidated
    Please help

    If you want to copy data between two tables why use a cursor at all. This seems rather inefficient.  You can bulk insert data by embedding the select into the insert.  Here is an example:
    insert into "SP8DEMO"."playground.sp8.data::PurchaseOrder.Header"
      select * from "SP7DEMO"."playground.sp7.data::PurchaseOrder.Header";
    In your case I believe you could accomplish the same with
    INSERT INTO "RAJ_HANA"."EMP_1" (EPMNO) SELECT EMPNO FROM "RAJ_HANA"."EMP";

  • How to trigger a java program on INSERT in SAP HANA

    Hi,
    I need to trigger a java program whenever an INSERT happens on a table in SAP HANA.
    Please tell me how can I achieve the same.
    Thanks & Regards
    Divyank Mehta

    Hi Mehta,
    HANA SQL Script is not able to call external commands . May be from the context of your Java , you can keep pinging the database where the insert is happening for a data change via JDBC or ODBC . From SQL Context I don't think it is possible.
    Sree

  • How to change the unload priority of a table in SAP HANA?

    Hi Experts,
    How we can change the unload priority of a table in SAP HANA? I know by default the priority is 5. Is there any way so that we can check the unload priority of a particular table in HANA studio? Is there any SQL statement to get the same?
    Please suggest.
    Thanks in advance.
    Regards,
    Arindam

    Hello Arindam,
    Just for the future:
    ALTER TABLE - SAP HANA SQL and System Views Reference - SAP Library
    To check before hand:
    select
    table_name, unload_priority from SYS.TABLES
    where table_name = '<Your Table>'
    To Make the change:
    alter table <Your Table>unload priority <Priority You Want>.
    As you have asked in the BW on HANA section I assume you're on BW and you could also have checked this with tx SE14.
    Hopefully the above gives you everything you need.
    Kind Regards,
    Amerjit

  • SAP HANA calculation field

    Hello,
    I have a query on the new calculated field in SAP HANA. What is the usage of this field, what are the pre-requisites and potential case when it is recommended to use such fields? Do we need to have a calculative view to use the calcluated field or can it be used directly in ABAP code?
    Kindly let me know. We are in the process of code optimization for HANA.
    Best Regards,
    Mohit

    Hey Mohit,
    can you please give a bit more details, e.g. documentation about what you refer to as "the new calculated field in SAP HANA".
    Concerning the details of usage within HANA, i.e. whether you need a calculation view etc. you might have a look at the SAP Help (Introduction - SAP HANA SQL and System Views Reference - SAP Library)) or maybe directly in the HANA SQL reference (http://help.sap.de/hana/SAP_HANA_SQL_Script_Reference_en.pdf).
    From my answer I think you can directly guess, that there's no way in directly accessing the calculated field from ABAP - except of course if you access it using native SQL (ADBC or EXEC SQL).
    For code optimization in SAP HANA (from an ABAP developers perspective), you might want to have a look at our Open SAP course (ABAP Development for SAP HANA - Dr. Jasmin Gruschke and Jens Weiler) or in the documentation given in our "Get Started" Section of ABAP for SAP HANA namely ABAP for SAP HANA Reference Scenario and ABAP for SAP HANA Reference Scenario - AS ABAP 7.4 Support Packages.
    In case you need more HANA (less ABAP) related information for your question, you might additionally contact the HANA experts on SAP HANA Developer Center.
    Cheers,
    Jasmin

  • SAP Hana FAQ Frequently Asked Questions

    Hi All,
    SAP have published a fantastic Knowledge Base Article containing an extremely detailed
    SAP Hana FAQ - Frequently Asked Questions
    Go and download it now, it's here:
         2000003 - FAQ: SAP HANA
    And then come back to it from time to time, because not everything in there is released yet.
    Best regards,
    Andy.

    For the sake of completeness, there are now a number of very useful Hana FAQ OSS Notes, here's the list so far:
    . OSS 2000003 - FAQ: SAP HANA
    . OSS 2000000 - FAQ: SAP HANA Performance Optimization
    . OSS 1640741 - FAQ: "DB users for the DBA Cockpit for SAP HANA"
    . OSS 2039883 - FAQ: SAP HANA database and storage snapshots
    . OSS 2044468 - FAQ: SAP HANA Partitioning
    . OSS 2057595 - FAQ: SAP HANA High Availability
    . OSS 1999997 - FAQ: SAP HANA Memory
    . OSS 1999880 - FAQ: SAP HANA System Replication
    . OSS 2044468 - FAQ: SAP HANA Partitioning
    . OSS 2000002 - FAQ: SAP HANA SQL Optimization
    . OSS 2073112 - FAQ: SAP HANA Studio
    . OSS 1999998 - FAQ: SAP HANA Lock Analysis
    . OSS 1905137 - FAQ: SAP HANA - Obsolete tables
    . OSS 1999930 - FAQ: SAP HANA I/O Analysis
    . OSS 1914584 - SAP HANA Live Browser FAQ
    . OSS 2057046 - FAQ: SAP HANA Delta Merges
    . OSS 1642148 - FAQ: SAP HANA Database Backup & Recovery
    . OSS 2104291 - FAQ - SAP HANA multitenant database containers
    . OSS 2100009 - FAQ SAP HANA Savepoints
    . OSS 2082286 - FAQ: SAP HANA Graph
    . OSS 2081591 - FAQ: SAP HANA Table Distribution
    . OSS  2053330 - FAQ: Operations Recommendation on SAP HANA Alerts
    If you are interested in Hana Basis related OSS Notes, then the longest list of Hana OSS Notes publicly available on the internet is over here.
    Best regards,
    Andy

  • SQL Script VS HANA views

    Hi Gurus,
    We are in the process of building the SAP HANA views. As we know there are multiple options
    1) Attribute , Analytic & Calc views
    2) Scripted Calculation views and CE functions.
    I have read many articles and as per SAP Documentation, they say build the information view with  Attribute, analytic and calculation View (Graphical) If it does not suffice they go for scripted calculation view.
    Just wanted to understand. Are there any limitations or any issues faced in the projects with scripted calc views. If we look at the John Appleby tips, it suggests that avoid SQL script unless it cannot be done with graphical views.
    http://scn.sap.com/community/hana-in-memory/blog/2013/12/29/6-golden-rules-for-new-sap-hana-developers
    If we build the views with graphical method, then it seems the parallelism can very well achieved ,means query is split into multiple sub queries and executed in parallel as in Visualize plan.
    If we write the Sql script, can this parallel processing  achieved or not ?  If the requirement can be achieved without writing script which method to choose.
    I have included the 10 to 12 attribute views in analytic view then Calculation view; it seems there may be some performance issue which I am going to check. As we know we can use base table directly in calculation view. What is the best method to use .Can we use these base  tables in calculation view directly or build the attribute views first, then analytic  view and after that build calculation view.
    As we know we use the attribute views from re usability perspective.  Is there any other reason that we need to use attribute views instead of joining the base tables in calc view .
    Regards
    Ram Ramanathaiah

    Thank you Krishna for the answers. I have gone through those links. But there is nowhere consensus opinion that the way we use the views. Some of the answers conflict each other .When we are starting the project we need to make decision about the best approach we wanted to take. If possible I would like to understand more about this from you and other experts.
    1) Build the views with Attribute analytic or calc views or
    2) Build the views only with base tables in calc views or
    3) Build everything using the SQL script /CE functions.
    Regards
    Ram

  • Write to ERP Tables on HANA DB using SQL script

    Hello All,
    We are using HANA as our primary database for ABAP system and trying to feed the data to ABAP tables using SQL script and experiencing authorization errors . Please see below for more details.
    Scenario.
    I am getting no authorised error when i try to write some data to Z* tables using SQL script in HANA studio.But I am able to create new tables in the same schema.
    As shown above Query1: SAPSR1 is the schema which contains underline ABAP tables. ZGSA is existing table and now i am trying to insert new rows into it.
    Query 2&3: Creating new tables in SAPSR1 works fine.
    Can you please suggest me whether it is right approach or i need to have RFC to update these table from some other tool/app?.
    Thanks in advance,
    Naresh

    Hi Naresh,
    Obi Wan would now probably say: "this is not the functionality you're looking for".
    Even though you are working with Z-tables you really don't want to start messing with those from outside the context of the NetWeaver system.
    Instead you want to keep the control over all tables in the NetWeaver schema completely  to the SAP<sid> user and NetWeaver.
    For your data loading scenario, just write a simple ABAP report with native sql or an AMDP to do the copying of the data for you.
    Don't spread your code across the landscape and don't loosen access restrictions on your schema.
    - Lars

  • Using HANA SQL Functions in select list of CDS Views

    Dear Expert,
    Kindly please let me know if we can use the HANA SQL Function (Ex: ADD_DAYS, SECONDS_BETWEEN) in the select list of CDS Views?
    If I create a CDS like below I get error that timestamp is not supported.
    For Example:
    @AbapCatalog.sqlViewName: 'ZMR_H_CA'
    @EndUserText.label: 'CAG A'
    define view viewname
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    key resource_key,
    TO_TIMESTAMP(begtstmp) as start_tmp,
    TO_TIMESTAMP(begtstmp) as end_tmp
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    Thanks,
    Giri

    Hi Giri,
    the list of provided features can be found in the ABAP Language Documentation (F1 in the CDS View).
    As CDS in ABAP is abstracted from the database layer, the database features are not directly accessible. That means, you cannot use any HANA or MaxDB feature available. So the answer to your question is no. The reason for this is, that ABAP CDS views can be created on all SAP-supported databases, hence, we can only provide those features, supported by all databases.
    Having said this, there are some exception, e.g. the CDS views with input parameters, which are not supported by all databases. In these cases, you'd have to additionally use the utility class CL_ABAP_DBFEATURES (see http://scn.sap.com/community/abap/blog/2014/10/10/abap-news-for-740-sp08--abap-core-data-services-cds) for more details.
    Best,
      Jasmin

  • Standard Sql scripting Vs CE built-in functions ? Which one should I need to choose?

    Hello,
    My source is csv files and I need to load these source files into HANA after doing some Transformations based on multiple validations (for example , based on grade, some new column has to be populated with some relevant hikes i.e. need to use if/else logic, case logic, either insert or update in target table …etc. This validation should be done for each and every row).
    Assume some of the validations not possible through BODS and I need to implement this logic in HANA scripting (through procedures).
    I know HANA supports two kinds of writing scripts i.e. HANA standard sql statements and CE_functions and I’ve heard from HANA documentation that CE functions gives more performance than standard sql statements and we should not mix together in a single block of code.
    Please let me know which scenario should I go for?  (I doubt if we can do all the functionalities using CE functions?
    I am looking forward to your reply.
    Thanks,
    Sree

    Much awaited reply.
    Thanks a lot Jain !
    But just one more point to bring out, if some of requirements can be done through both CE functions and Scripting,  and some are possible through only scripting then we need to go for sql scripting only ..as we are not supposed to bring both the coding standards together, results in performance issues. ( Even your diagram shows either CE functions or Use SQL)
    am i right?
    Thanks,
    Sree

Maybe you are looking for