Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ABAP Database Connectivity also known as ADBC provides Object Oriented approach to
access the database. You can also access the DB dynamically using the ADBC.
Using ADBC, you can establish Connection the various DB as well as you can execute
Database specific SQL commands. ADBC classes were introduced in ABAP release 6.10,
but they were documented in Database connectivity as part of ABAP release 7.20.
Involved Classes
CL_SQL_CONNECTION – This class handles the external DB connection. If you
want to connect to any other DB other than your default DB, you need to
instantiate the connection object with connection name.
CL_SQL_STATEMENT – This class contains methods to execute the DB
operations. When you instantiate an object for SQL, you can pass the Connection
reference of type CL_SQL_CONNECTION. Use the Connection object if you
want to execute the statement on other DB.
CL_SQL_PREPARED_STATEMENT – This class is inherited from
CL_SQL_STATEMENT. This class will accept the SQL Statement which is ready
to be understood by DB. Since DB doesn’t need to convert translate this to
internal format, you can execute this multiple times and improve the performance
over using CL_SQL_STATEMENT.
CL_SQL_RESULT_SET – Class would be used to get the result back from the
SQL statements.
CX_SQL_EXCEPTION – Will raise this exception if any of the error occurs
REPORT znp_ADBC_demo.
*
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
METHODS:
get_data,
generate_output.
PRIVATE SECTION.
START-OF-SELECTION.
o_main->get_data( ).
o_main->generate_output( ).
*
CLASS lcl_main IMPLEMENTATION.
METHOD get_data.
" Fill up the columns which you want to select from the DB
CONCATENATE
`SELECT * `
`FROM T100 `
`WHERE sprsl = '` sy-langu `' `
`AND ARBGB = '` p_arbgb `' `
INTO lv_query.
TRY.
CREATE OBJECT lo_sql.
IF lo_result->next_package( ) > 0.
EXIT.
ENDIF.
ENDTRY.
ENDMETHOD. "get_Data
METHOD generate_output.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_salv
CHANGING
t_table = t_output ).
o_salv->display( ).
ENDMETHOD. "generate_otuput
Variations
You can also provide field = ? in the Query and use the method SET_PARAM to set the
proper data reference to the field in question.
CONCATENATE
`SELECT * `
`FROM T100 `
`WHERE sprsl = '` sy-langu `' `
`AND ARBGB = ?`
INTO lv_query.