on 10-18-2019 4:42 PM
Hi,
I need to show several constant in multiple SQL selects. These constants are derived from a table that contains one record only.
How to pick up these constants from HANA procedures or functions if scalar function doesn't allow any SQL operations.
SELECT MANDT, MATNR , Costant01, constant02
FROM "SAPSR3"."MARA"
Thanks
Hi Aleksandrs,
Please try with below statement using cross join (1=1 condition). It will help you to take constant from setup table.
DO BEGIN
IT_MARA = SELECT 100 AS MANDT, '10-10' AS MATNR FROM DUMMY
UNION ALL
SELECT 100 AS MANDT, '10-20' AS MATNR FROM DUMMY
;
IT_SETUP = SELECT 'AA' AS Costant01, 'BB' AS constant02 FROM DUMMY;
SELECT MARA.*, SETUP.*
FROM :IT_MARA AS MARA
JOIN :IT_SETUP AS SETUP
ON 1 = 1
;
END
Output will be as below in the attached image:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aleksandrs,
Yes, that is possible through SQL statement. If you can let me know sample dummy setup data, I can help you more to provide details.
Regards
Kedar
Instead of the 1=1 "trick" one could also just use the correct SQL join for this:
CROSS JOIN
SELECT /* SELECT * really shouldn't be used */
MARA.<col_1>, MARA.<col_2>, MARA.<col_3, MARA.<col_...>
, SETUP.<col_1>, SETUP.<col_2>, SETUP.<col_3>, SETUP.<col_...>
FROM
:IT_MARA AS MARA
CROSS JOIN :IT_SETUP AS SETUP;
Note that the cross join will create a result tuple for every combination of tuples in both tables. That may not be what the OP intended.
Thanks Lars
The parameters from setup table are client dependent. I would like to pick them up via function/procedure to avoid join
Table MARA client dependent
Select MANDT, MATNR, procedure01() AS CLIENT_ID, procedure02 as CO_AREA
Parameters from table param - client dependent
MANDT CLIENT_ID CO_AREA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
select mandt,
matnr,
'abc' as constant1,
'123' as constant2
from MARA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.