on 2019 May 17 4:39 PM
Hi,
I have a DocStore collection named food_collection from which I'm getting data into the ABAP world through an AMDP.
The code for the AMDP looks like this:
PUBLIC SECTION.
INTERFACES if_amdp_marker_hdb.
TYPES:
BEGIN OF ty_food_json,
food_collection TYPE string,
END OF ty_food_json,
tt_food_json TYPE STANDARD TABLE OF ty_food_json WITH DEFAULT KEY.
CLASS-METHODS:
read_by_group IMPORTING VALUE(group) TYPE string
EXPORTING VALUE(result) TYPE tt_food_json.
CLASS zfetch_food_collection IMPLEMENTATION .
METHOD read_by_group BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
result =
SELECT * FROM "MYSCHEMA"."FOOD_COLLECTION"
where "group" = :group;
ENDMETHOD.
ENDCLASS.
Now, when I try to call to this AMDP with something like:
zfetch_food_collection=>read_by_group(
EXPORTING group = `'Vegetables'`
IMPORTING et_result = data(food)).
cl_demo_output=>display( food ).
I get the following error:
feature not supported: ... line 9 col 5 (at pos 302): a where clause has an expression that cannot be supported by collection tables
So for some reason I can't query JSON properties from the AMDP. This query works perfectly in the SQL console:
SELECT * FROM "MYSCHEMA"."FOOD_COLLECTION"where "group" = 'Vegetables';
Statement 'SELECT * FROM "MYSCHEMA"."FOOD_COLLECTION" where "group" = 'Vegetables''
successfully executed in 44 ms 26 µs (server processing time: 5 ms 994 µs)
Fetched 3 row(s) in 0 ms 44 µs (server processing time: 0 ms 0 µs)
I tried changing the parameter name to |'Vegetables'|, didn't work. I also tried concatenating the single quotes inside the AMDP body rather than from the caller, didn't work either.
Has anyone experienced this?
Request clarification before answering.
Managed to solve it in a very weird way. Makes me realizae the flexibility offered by the document store is lost when using the integration with the ABAP layer through AMDPs.
I had to specify the exact fields I want to fetch in the types definition of the AMDP class:
TYPES:
BEGIN OF ty_food_json,
name TYPE string,
fgroup TYPE string,
nutrients TYPE string,
description TYPE string,
END OF ty_food_json,
tt_food_json TYPE STANDARD TABLE OF ty_food_json WITH DEFAULT KEY.
CLASS-METHODS:
read_by_group IMPORTING VALUE(imgroup) TYPE string
EXPORTING VALUE(et_result) TYPE tt_food_json.
Then in the implementation I used a CTE. But here's the tricky part, the field names from the collection have to be renamed in uppercase!!! My guess is that ABAP internally uppercases the types definition from above, so the names wouldn't match otherwise (also renamed the GROUP field because it's a reserved word in SQL). With the CTE in place I can just query in traditional SQLScript (no single quotes or double quotes needed):
METHOD read_by_group BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.
et_result = WITH food_view AS (
SELECT "name" AS NAME,
"group" AS FGROUP,
"nutrients" AS NUTRIENTS,
"description" AS DESCRIPTION
FROM "MYSCHEMA"."FOOD_COLLECTION" )
SELECT * FROM food_view
WHERE FGROUP = :imgroup;
ENDMETHOD.
Then the caller :
zfetch_food_collection=>read_by_group(
EXPORTING
imgroup = `Vegetables`
IMPORTING
et_result = data(food)
).
cl_demo_output=>display( food ).
And finally the results from the console:
Within the nutrients column there's another JSON, so to extract those values I would need a nested structure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Macro,
I did follow SAP Help documenetaion and then found your question on SCN. I actually get below error in AMDOP class. However I am able to do all CRUD in SQL console on HANA Studio.
"DEMOCOLLECTION" is unknown. ABAP objects and DDIC objects must be declared in the METHOD statement. Local names must start with ":" here.
This error comes when accessing from system schema(example SAPCAR or SAPSLT etc) however works fine with user schema(example KDASS)
Regards,
Kevin Dass
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i had the same problem when use inside amdp a function like that:
BIND_AS_VALUE
example:
METHOD ins_doc BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT.
delete from "TYRHANA"."APPLCONFIG" where "Basic"."Id" = BIND_AS_VALUE(:applid);
endmethod.
then the system treats the importing variable - here applid - as value and it works, normally the optimizer decides if he interprets the variable as parameter or value, but with this function you can tell him that this is a value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
59 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.