ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP and SAP HANA → ABAP and SAP HANA, Examples
SAP HANA, ABAP-Specific Session Variables
This example demonstrates potential Native SQL reads on session variables on the SAP HANA database.
Other versions:
7.31 | 7.40 | 7.54
Source Code
DATA(out) = cl_demo_output=>new( ).
IF cl_db_sys=>is_in_memory_db = abap_false.
out->display(
`Example can be executed on SAP HANA Database only` ).
LEAVE PROGRAM.
ENDIF.
DATA(oref) = NEW cl_demo_hana_session_variables( ).
TRY.
DATA(result_exec_sql) =
oref->get_session_variables_exec_sql( ).
out->write( result_exec_sql ).
CATCH cx_sy_native_sql_error INTO DATA(exec_sql_exc).
out->write( exec_sql_exc->get_text( ) ).
ENDTRY.
TRY.
DATA(result_adbc) =
oref->get_session_variables_adbc( ).
out->write( result_adbc ).
CATCH cx_sql_exception INTO DATA(adbc_exc).
out->write( adbc_exc->get_text( ) ).
ENDTRY.
TRY.
DATA result_amdp
TYPE cl_demo_hana_session_variables=>session_variables.
oref->get_session_variables_amdp(
IMPORTING clnt = result_amdp-client
cds_clnt = result_amdp-cds_client
unam = result_amdp-uname
lang = result_amdp-langu
date = result_amdp-datum ).
out->write( result_amdp ).
CATCH cx_amdp_error INTO DATA(amdp_exc).
out->write( amdp_exc->get_text( ) ).
ENDTRY.
out->display( ).
Description
This program calls the following methods of the class CL_DEMO_HANA_SESSION_VARIABLES:
- GET_SESSION_VARIABLES_EXEC_SQL
EXEC SQL.
select SESSION_CONTEXT('CLIENT')
from DUMMY
into :session_variables-client
ENDEXEC.
EXEC SQL.
select SESSION_CONTEXT('CDS_CLIENT')
from DUMMY
into :session_variables-cds_client
ENDEXEC.
EXEC SQL.
select SESSION_CONTEXT('APPLICATIONUSER')
from DUMMY
into :session_variables-uname
ENDEXEC.
EXEC SQL.
select SESSION_CONTEXT('LOCALE_SAP')
from DUMMY
into :session_variables-langu
ENDEXEC.
EXEC SQL.
select SESSION_CONTEXT('SAP_SYSTEM_DATE')
from DUMMY
into :session_variables-datum
ENDEXEC.
ENDMETHOD.
SELECT
list of an access to the pseudo table DUMMY.
- GET_SESSION_VARIABLES_ADBC
DATA(result) = NEW cl_sql_statement( )->execute_query(
`select SESSION_CONTEXT('CLIENT') from DUMMY` ).
result->set_param( REF #( session_variables-client ) ).
result->next( ).
result = NEW cl_sql_statement( )->execute_query(
`select SESSION_CONTEXT('CDS_CLIENT') from DUMMY` ).
result->set_param( REF #( session_variables-cds_client ) ).
result->next( ).
result = NEW cl_sql_statement( )->execute_query(
`select SESSION_CONTEXT('APPLICATIONUSER') from DUMMY` ).
result->set_param( REF #( session_variables-uname ) ).
result->next( ).
result = NEW cl_sql_statement( )->execute_query(
`select SESSION_CONTEXT('LOCALE_SAP') from DUMMY` ).
result->set_param( REF #( session_variables-langu ) ).
result->next( ).
result = NEW cl_sql_statement( )->execute_query(
`select SESSION_CONTEXT('SAP_SYSTEM_DATE') from DUMMY` ).
result->set_param( REF #( session_variables-datum ) ).
result->next( ).
ENDMETHOD.
- GET_SESSION_VARIABLES_AMDP
BY DATABASE PROCEDURE FOR HDB
LANGUAGE SQLSCRIPT.
clnt := session_context('CLIENT');
cds_clnt := session_context('CDS_CLIENT');
unam := session_context('APPLICATIONUSER');
lang := session_context('LOCALE_SAP');
date := session_context('SAP_SYSTEM_DATE');
ENDMETHOD.