Consuming HANA Views, Procedures, External Views in ABAP 7.40 Syntax – Part 3
- ABAP Report with new data declaration syntaxes on 7.40
- ABAP Report on HANA using ADBC
- Consuming Attribute View using External View.
- Consuming Attribute View using Native SQL
- Consuming Analytic View/Calculation View in ABAP
Part 3: http://scn.sap.com/community/abap/hana/blog/2014/01/08/as
- Consuming HANA artifact Stored Procedure using ABAP Proxy Procedure.
- Consume HANA artifact Stored Procedure by Calling it in ABAP Code.
T6. Consuming HANA artifact Stored Procedure using ABAP Proxy Procedure.
Steps to create Stored Procedure:
Step 1: Go to ‘Modeler’ or ‘SAP HANA Development ‘prospective and right click on your package and create a new procedure.
Step 2: Enter name and description, select the ‘Default Schema’ (SAP-SID) and Run With as ‘Invoker’s Right’ and click on finish.
Step 3: Add ‘Output’ and ‘Input’ parameters by right clicking on the respective folders
Step 4: Place the code in the procedure editor
BEGIN
et_last_rev_bill = SELECT empinfo.pernr as PERNR, DAYS_BETWEEN(empbill.BILL_DATE,CURRENT_UTCDATE) AS LAST_REV_BILL
FROM DTAB_EMP_INFO AS empinfo INNER JOIN DTAB_EMP_BILL AS empbill
ON empinfo.pernr = empbill.pernr
WHERE empbill.mandt = empinfo.mandt
GROUP BY empinfo.pernr, empbill.bill_date ;
END;
/********* End Procedure Script ************/
Step5: Save and activate the procedure. Execute the procedure in ‘SQL Console’.
Call “_SYS_BIC”.“mohas97_ha5/ZEMP_BILL_PP”(?) WITH OVERVIEW;
Call “_SYS_BIC”.“mohas97_ha5/ZEMP_BILL_PP”(?);
Now create a Proxy Procedure in ABAP:
Step 1: Go to ‘ABAP’ prospective.
Step 2: Right click on ABAP package under which you want to create this Proxy Procedure. Under ‘New’ click on ‘Other ABAP Repository Object’
Step 3: Choose ‘Database Procedure Proxy’.
Step 4: Enter name, description, HANA s procedure name
Step 5: Now your proxy procedure is created just activate the object.
Source code to Consume the ‘Proxy Procedure’ in ABAP:
DATA: lt_bill_rev_days TYPE TABLE OF if_emp_bill_proxy_procedure=>et_last_rev_bill,
lv_count TYPE i.
CALL DATABASE PROCEDURE emp_bill_proxy_procedure
IMPORTING et_last_rev_bill = lt_bill_rev_days.
LOOP AT lt_bill_rev_days ASSIGNING FIELD-SYMBOL(<fs_bill_rev_days>).
WRITE: / ‘Days Since Bill Rate is changed’ ,<fs_bill_rev_days>-pernr.
WRITE: ‘=’, <fs_bill_rev_days>-last_rev_bill , /.
ENDLOOP.
Output:
T7. Consume HANA artifact Stored Procedure by Calling it in ABAP Code.
Source Code
* Calling hana procedure in ABAP
TYPES: BEGIN OF lty_s_overview,
param TYPE string,
value TYPE string,
END OF lty_s_overview.
DATA: lt_overview TYPE TABLE OF lty_s_overview.
DATA: ls_overview TYPE lty_s_overview.
TRY.
lv_sql = | CALL _SYS_BIC.“mohas97_ha5/ZEMP_BILL_PP” | &&
| ( null ) WITH OVERVIEW |.
* execute the native SQL query/ SQL Call
lo_result = NEW cl_sql_statement( )->execute_query( lv_sql ). ” new syntax
* read the result into the internal table lt_partner
GET REFERENCE OF lt_overview INTO lr_data.
lo_result->set_param_table( lr_data ). “Retrieve result of native SQL call
lo_result->next_package( ).
lo_result->close( ).
* Read internal table
READ TABLE lt_overview INTO ls_overview WITH KEY param = ‘ET_LAST_REV_BILL’.
lv_sql = ` select * from ` && ls_overview–value.
* execute the native SQL query/ SQL Call
lo_result = NEW cl_sql_statement( )->execute_query( lv_sql ). ” new syntax
* read the result into the internal table lt_partner
GET REFERENCE OF lt_bill_rev_days INTO lr_data.
lo_result->set_param_table( lr_data ). “Retrieve result of native SQL call
lo_result->next_package( ).
lo_result->close( ).
CATCH cx_sql_exception INTO lx_sql_exc.
lv_text = lx_sql_exc->get_text( ).
MESSAGE lv_text TYPE ‘E’.
ENDTRY.
LOOP AT lt_bill_rev_days ASSIGNING FIELD–SYMBOL(<fs_bill_rev_days>).
WRITE: / ‘Days Since Bill Rate is changed::’ ,<fs_bill_rev_days>–pernr.
WRITE: ‘::’, <fs_bill_rev_days>–last_rev_bill , /.
ENDLOOP.
Hi Syed, I'm Murali an Abaper with 8 and half years of exp. Now planning to learn ABAP Programming on HANA. I have done 2 online certifications on SAP HANA conductedby OPENSAP.com. Need your help on how can i start on ABAP Hana. Please share if you have any documents on the same and let me know if there any related trainings for the same.
Thank you.
Murali.M
You can go thru the link what Jasmin Shared
ABAP for SAP HANA Reference Scenario .
Thanks Syed.
Hi Shahid,
Will this work using HANA as a secondary db to SAP on Oracle? ie: I want to show our ABAP team how they can consume some of my HANA stored procedures.
Thanks,
-Patrick
Shahid, can you also check this other question I have?
Different ways to create procedures
Thanks!!
-Patrick
Hi Patrick,
which way of consumption are you asking about? For sure you can use a secondary DB connection within ADBC and consume the HANA Procedure when HANA is the secondary DB.
DB procedure proxies you won't be able to create on the secondary DB (only using a programmatical approach). But if the proxy exists (either created via the ADT directly or programatically), you'll again be able to consume it via the connection statements in the CALL DATABASE PROCEDURE call (see e.g. http://scn.sap.com/thread/3517597).
Cheers,
Jasmin
Hi Jasmin,
Thanks for your valuable feedback. Basically up until now our ABAP team has just been writing sidecar ABAP reports on SAP source system and calling tables directly from HANA as secondary db. There was immediate improvements in runtime for long reports of course however we want to start doing more code push-down into HANA.
So our approach is;
1) Teach them all about HANA and views/models/procedures
2) Teach them how to consume this from ABAP
3) We have installed ABAP add-on for studio.
So I'm not entirely clear if we should focus on A) still writing all the abap from SAP source system and consume HANA views and procedures or B) should we be writing ABAP from within studio with the ABAP add-on. For now I'd just be happy with showing them option A to at least get them moving so I'm trying to understand which of the methods in these blogs would fit this option A. It looks like external view would not work and I'm not 100% clear of passing parameter(s) to a procedure will work with option A as well with HANA as secondary db?
Many thanks!
-Patrick
Hi Patrick,
I don't have the ultimate answer to your question, so if you have 99% side-car scenarios and only 1% scenarios, where you have an "ABAP-based system on HANA as primary DB architecture", I think your approach is perfectly fine. We (well, me and the team around) rather focus on the latter, which is e.g. also the case for S/4HANA etc. In that case, I'd strongly recommend to take the "top-down-approach" path.
I typically refer to our openSAP course ABAP Development for SAP HANA - Dr. Jasmin Gruschke and Jens Weiler, but that's (as mentioned above) mainly targeting for the ABAP-based system on HANA as primary DB case.
Cheers,
Jasmin
What shall I say about it ... ? 😉
It's the best I found and solve a lot of my problems.
Thank you soooo mutch. 🙂
Best Regards
Thank you
Creating procedure in this way seems to have been deprecated! Do you have any idea how to consume SP , created as a repo object, and consume in ABAP ? Because the SP is not shown,created as repo object, in the procedure list while creating procedure proxy!