Skip to Content
author's profile photo Former Member
Former Member

HANA Select from SAP BW Hierarchie with CalculationView

Hello,

I want to select a Hierarchie from a SAP BW Hierarchie in a table with an CalculationView.

When I select only one Item in my first select (saleseng) everything works fine.

but when I want to fetch all Items I receive the failure "Error: SAP DBTech JDBC: [305]: single-row query returns more than one row".

In ABAP I would fix this issue with an loop, but how can I fix this error in SQL?

/********* Begin Procedure Script ************/ 

 BEGIN 

 saleseng = select "/BIC/PSD_FA" || "/BIC/SALESENG" as PSDFASALESENG 
 	from "SAPEBH"."/BIC/PSALESENG"
 	where "/BIC/PSD_FA" = '00001';


 var_out = select 
  nodename as SALESENG,

  right( 	 	
  (select nodename from "SAPEBH"."/BIC/HSALESENG" where NODEID = 
   (select parentid from "SAPEBH"."/BIC/HSALESENG" where NODEID =         (select parentid from "SAPEBH"."/BIC/HSALESENG" where NODEID = 
     (select parentid from "SAPEBH"."/BIC/HSALESENG" where nodename =        se.psdfasaleseng 		                                     and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
      and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
     and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
   and hieid = '0005PF0NDLY7G20J8L1R2OIBV'),5) as PSD_FA,

 right(			                                              
 (select nodename from "SAPEBH"."/BIC/HSALESENG" where NODEID = 
  (select parentid from "SAPEBH"."/BIC/HSALESENG" where NODEID = 
   (select parentid from "SAPEBH"."/BIC/HSALESENG" where nodename =        se.psdfasaleseng 
     and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
    and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
   and hieid = '0005PF0NDLY7G20J8L1R2OIBV'),5) as REGION,

 right(
 (select nodename from "SAPEBH"."/BIC/HSALESENG" where NODEID = 
  (select parentid from "SAPEBH"."/BIC/HSALESENG" where nodename = 
   se.psdfasaleseng
   and hieid = '0005PF0NDLY7G20J8L1R2OIBV') 
  and hieid = '0005PF0NDLY7G20J8L1R2OIBV'),5) as BRANCH,

  Count(NODENAME) as COUNT

 from "SAPEBH"."/BIC/HSALESENG" as h
 inner join :saleseng as se on
    psdfasaleseng = nodename
 where nodename = se.psdfasaleseng and 
       hieid = '0005PF0NDLY7G20J8L1R2OIBV'

 group by nodename, se.psdfasaleseng;


END /********* End Procedure Script ************/

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Sep 01, 2017 at 07:10 AM

    The directly corresponding concept to "looping over internal tables" in ABAP would be "Cursor-For-Loop" in SQL script.

    Looking at the approach above to resolve the hierarchy, I'd say, you will probably be better off by implementing a function that returns the necessary strings.

    The "single-row..." error is due to the fact, that your subqueries don't simply return the first (and only the first) matching record from a join, but all matching records. So the WHERE condition with "hied = ..." is failing as it can only compare to single values.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.