I would like to explain about creation of SAP HANA Procedure Object to ABAP Perspective by step by step procedure. This blog Post is mainly useful for beginners.
An SAP HANA procedure is a database-stored procedure that gives you programming functionality with the help of SAP HANA SQL Script, similar to ABAP functions. Now I guide you through the creation of SAP HANA data flows with the help of calculation views (graphical and SQL Script-based views), as well as some pitfalls you may run into.
The first calculation view is a plain graphical view. Right-click your development package and select New and then Calculation View as shown in
Following are the Steps involved to extract SAP HANA Procedure Object to ABAP Perspective
Step -1 : Open HANA development and Create your Own Package ,Under that Create a Calculation View in that Select Script based View.
Step-2 : After creating a Script View , A modeller will be opened to write Script that you want.
Below Image shows Sample Script in the Console
Note :
- While Creating Script View In the Console , Try to create Column Names Exactly same as mentioned in the Script that is Written based on Columns taken from Particular Table. Otherwise the Created View will not be Activated.
Below Image shows ,How to Create Columns in Script based View
Click on save and active button and click on data preview drop down select open data preview editor.
click on ok and select RAW DATA
Step -3 : After Completion of Script View ,Create a Stored Procedure on top of Script View .
Select the HANA Database system and click on SAP HANA DEVELOPMENT
Below images shows, How to create XML Procedure
First of all to create XML procedure Go to repositories
Next RightClick on Package->New->Others
Now Select SAP HANA-> Database Development -> Stored Procedure
Now Select XML Procedure Option in File Format
After that Select the target Schema present in Catlog
Now the created object is visible at the target Package
Below Image is sample procedure that is created in one package
Note:
Difference between .hdb procedure and XML procedure is that in XML procedure there is two options, one is to write SQL script and other is Local table types but in .hdb procedure we have only SQL script option.
- Here in this procedure I am passing output parameter to get required fields from a table. So in local table type ,create a table with same name given in output parameter for reference. After this Execute the stored Procedure ,this will automatically create Xml Procedure and place that object in the target Package that is created.
Step-4: Now call this XML Stored Procedure in the ABAP Perspective.
To call the Stored procedure into ABAP Environment first connect the SAP HANA System to ABAP by below steps.
Goto->ABAP repository
Give the SAP HANA System and connect through your User credentials to ABAP Environment.
Now Go to-> Project Explorer->Local Objects ->New->Others
Type Proxy Procedure and search for it in ABAP Repository Object
Now this will open Database Procedure Proxy
Note : While selecting XML Procedure into Proxy Procedure
1.In HANA procedure option press “Ctrl+Space” to get all the Procedures from HANA perspective.
After calling the stored procedure into ABAP Environment , a new Proxy Procedure will be created as shown below
The object will be Visible in Repository as shown below
Create and implement an ABAP Report consuming Procedure We will now call the database procedure proxy from an ABAP program. We will implement a simple report which will just output the result with a WRITE statement.
The following steps are performed in the ABAP perspective. a. Create a new ABAP Program in the package of your choice by just right-clicking on it and selecting “New -> ABAP Program” from the context menu. Enter a name (e.g. zstore_procedure ) and a description (e.g. “Display Top and Flop Customers”).
Press on Next and then on Finish on the dialog step.
Store Procedure via report.
*&---------------------------------------------------------------------*
*& Report zstore_procedure
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zstore_procedure.
types: begin of out_var,
mandt type c length 3,
matnr type c length 40,
meins type c length 3,
ntgew type i,
end of out_var.
PARAMETERS: p_matnr TYPE mara-matnr.
*Define parameters using the created DPP interfaces ZIF_ZMARA1
DATA : lv_data TYPE zif_zproxy=>matnr,
lt_data TYPE STANDARD TABLE OF zif_zproxy=>out_var,
ls_data TYPE zif_zproxy=>out_var,
Lt_fcat TYPE slis_t_fieldcat_alv,
ls_fcat TYPE slis_fieldcat_alv.
*Set the value of procedure input parameters
lv_data = p_matnr.
*Call the created database procedure proxy
CALL DATABASE PROCEDURE zproxy
EXPORTING matnr = lv_data
IMPORTING out_var = lt_data.
PERFORM build_fieldcatalog.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = lt_fcat "PASS FIELD CATALOG TO ALV
TABLES
t_outtab = lt_data.
FORM build_fieldcatalog.
ls_fcat-col_pos = '1'.
ls_fcat-fieldname = 'MANDT' .
ls_fcat-tabname = 'LT_DATA' .
ls_fcat-seltext_m = 'MANDT' .
APPEND ls_fcat TO Lt_fcat .
CLEAR ls_fcat.
ls_fcat-col_pos = '2' .
ls_fcat-fieldname = 'MATNR' .
ls_fcat-tabname = 'LT_DATA' .
ls_fcat-seltext_m = 'MATNR' .
APPEND ls_fcat TO LT_FCAT.
CLEAR ls_fcat.
ls_fcat-col_pos = '3' .
ls_fcat-fieldname = 'meins' .
ls_fcat-tabname = 'LT_DATA' .
ls_fcat-seltext_m = 'meins' .
APPEND ls_fcat TO Lt_fcat .
CLEAR ls_fcat.
ls_fcat-col_pos = '4' .
ls_fcat-fieldname = 'ntgew' .
ls_fcat-tabname = 'LT_DATA' .
ls_fcat-seltext_m = 'ntgew' .
APPEND ls_fcat TO Lt_fcat .
CLEAR ls_fcat.
ENDFORM.
Save and Activate your report.
You can now run the report (press on F8) – and by the way see the result of your effort .
Creation of ABAP Managed Database Procedure in ABAP:
Open ABAP Development Tool ( Eclipse or HANA studio ) and Go to ABAP Perspective. Create new ABAP Class.- Provide Name and Description. Click on NEXT Button.
Click on FINISH button.
Calling HANA Procedure in AMDP
CLASS zcall_amdp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
* Makes interface for Database Procedures
INTERFACES IF_AMDP_MARKER_HDB.
*Structure
TYPES:
BEGIN OF ty_DATA,
MANDT TYPE MANDT,
MATNR TYPE MATNR,
MEINS TYPE MEINS,
NTGEW TYPE NTGEW,
END OF ty_DATA.
* Table type
TYPES: Lt_DATA TYPE TABLE OF ty_DATA .
* Method Definition
CLASS-METHODS GET_DETAILS
IMPORTING
VALUE(LV_MATNR) TYPE MATNR
EXPORTING
VALUE(OUT_VAR) TYPE LT_DATA.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcall_amdp IMPLEMENTATION.
METHOD GET_DETAILS BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT.
call "_SYS_BIC"."ZPRO_VIEW/ZSTORE" (:LV_MATNR,OUT_VAR );
ENDMETHOD.
ENDCLASS.
REPORT:
AMDP Report:
*&---------------------------------------------------------------------*
*& Report zcall_abap_report
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zcall_abap_report.
TYPES:
BEGIN OF ty_data,
mandt TYPE mandt,
matnr TYPE matnr,
meins TYPE meins,
ntgew TYPE ntgew,
END OF ty_data.
* Table type
DATA: lt_data TYPE TABLE OF ty_data.
PARAMETERS : p_matnr TYPE matnr DEFAULT '28'.
DATA : r_amdp TYPE REF TO zcall_amdp,
* out_var TYPE TABLE OF ty_data,
r_salv TYPE REF TO cl_salv_table.
CREATE OBJECT r_amdp.
r_amdp->get_details(
EXPORTING
lv_matnr = p_matnr
IMPORTING
out_var = lt_data
).
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = r_salv
CHANGING
t_table = lt_data.
CATCH cx_salv_msg .
ENDTRY.
r_salv->display( ).
Conclusion:
I hope this blog Post helps to SAP HANA Procedure Object to ABAP Perspective.