class lcl_mp_entity definition inheriting from cl_sadl_mp_entity.
protected section.
methods: get_sadl_definition redefinition.
endclass.
class lcl_mp_entity implementation.
method get_sadl_definition.
" Any implementation if necessary
endmethod.
endclass.
try.
" Preparation with service name
data(lr_iomp) = new lcl_mp_entity(
iv_uuid = 'ZPAMV2'
iv_timestamp = new zcl_zpamv2_mpc( )->get_last_modified( )
).
data(lr_sapi) = cl_sadl_entity_api_factory=>create( cast #( lr_iomp ) ).
" Initialize runtime with interface view name
data(lr_runt) = lr_sapi->get_runtime( 'ZI_PAM_ROLE' ).
" Set scope for selected fields (from CDS view), and flag data to be fetched
data ls_parameters type if_sadl_query_engine_types=>ty_requested.
ls_parameters-fill_data = abap_true.
append:
'FIELD1' to ls_parameters-elements,
'ETC' to ls_parameters-elements.
" Get the data
data lt_data type standard table of zi_pam_role.
lr_runt->fetch(
exporting
is_requested = ls_parameters
importing
et_data_rows = lt_data
).
catch cx_root into data(lx).
... .
endtry.
class lcl_sadl_trans definition inheriting from cl_sadl_entity_transactional.
endclass.
data(lr_iomp) = new lcl_mp_entity(
iv_uuid = 'ZPAMV2'
iv_timestamp = new zcl_zpamv2_mpc( )->get_last_modified( )
).
data(lr_sadl_transaction) = new lcl_sadl_trans(
iv_entity_type = 'SADL' " TYPE SADL_ENTITY_TYPE
iv_entity_id = 'ZPAMV2~ZI_PAM_ROLE' " SADL_ENTITY_ID
).
data(lr_sapi) = cl_sadl_entity_api_factory=>create( cast #( lr_iomp ) ).
data(lr_runt) = lr_sapi->get_runtime( 'ZI_PAM_ROLE' ).
data ls_role type zi_pam_role.
ls_role-field1 = 'VALUE'. " Just values for a record to create
ls_role-etc = 'OTHERVALUE'.
lr_runt->if_sadl_entity_transactional~create_single(
importing
ev_failed = data(lv_updatefailed)
changing
cs_entity_data = ls_role
).
data(lr_trans_man) =
cl_sadl_transact_manager_fctr=>get_transaction_manager( ).
if lv_updatefailed = abap_false.
lv_updatefailed = lr_trans_man->save( ). " Commit the changes
else.
lr_trans_man->discard_changes( ). " Rollback
endif.
if lv_updatefailed eq abap_true.
lr_trans_man->get_message_handler( )->get_messages(
exporting
iv_severity = if_sadl_message_handler=>co_severity-error
importing
et_messages = data(lt_message)
).
loop at lt_message assigning field-symbol(<message>).
message id <message>-message->t100key-msgid
type <message>-severity
number <message>-message->t100key-msgno
with cl_sadl_entity_util=>message_value(
iv_attr = <message>-message->t100key-attr1
io_message = <message>-message )
" V2, V3 and V4 likewise
.
endloop.
data(ls_key_value) = value ZI_PAM_ROLE( field1 = '040000002514' ).
lr_runt->if_sadl_entity_transactional~delete_single(
exporting
is_key_values = ls_key_value
importing
ev_failed = data(lv_updatefailed)
).
data(ls_role) = value zi_pam_role( field1 = '040000002514' etc = 'YD' ).
lr_runt->if_sadl_entity_transactional~update_single(
exporting
is_entity_data = ls_role
it_updated_elements = value #( ( |ETC| ) )
importing
ev_failed = data(lv_updatefailed)
).
data lt_table type table of zi_pam_role.
" Fill data
r_sadl_runtime->if_sadl_entity_transactional~create(
importing
et_failed = data(lt_updatefailed)
changing
ct_entity_data = lt_table
)..
data(lr_trans_man) = cl_sadl_transact_manager_fctr=>get_transaction_manager( ).
if lines( lt_updatefailed ) > 0.
" Rollback
class lcl_cond definition. " Example taken from CL_SADL_COND_GROUPED_RANGES
public section.
interfaces:
if_sadl_condition_provider.
methods: constructor
importing it_ranges type if_sadl_cond_provider_grpd_rng=>tt_grouped_range
iv_use_placeholders type abap_bool default abap_false.
protected section.
data mt_ranges type if_sadl_cond_provider_grpd_rng=>tt_grouped_range.
data mt_sadl_condition type if_sadl_query_engine_types=>tt_complex_condition.
data mt_elements type if_sadl_query_engine_types=>tt_element_info.
data mv_use_placeholders type abap_bool.
endclass.
class lcl_cond implementation.
method if_sadl_condition_provider~get_condition.
if mt_ranges is not initial and ( mt_sadl_condition is initial or it_elements <> mt_elements ).
mt_elements = it_elements.
if mv_use_placeholders = abap_false and it_elements is not initial.
data lt_elements like it_elements.
loop at mt_ranges assigning field-symbol(<s_range>).
read table it_elements with key id = <s_range>-field_path assigning field-symbol(<s_element>).
if sy-subrc = 0.
insert <s_element> into table lt_elements.
endif.
endloop.
cl_sadl_condition_generator=>get_field_descr(
exporting it_elements = lt_elements
importing et_field_descriptors = data(lt_field_descriptors) ).
endif.
cl_sadl_condition_generator=>convert_ranges_to_conditions(
exporting it_ranges = mt_ranges
it_field_descriptors = lt_field_descriptors
iv_use_placeholders = mv_use_placeholders
importing et_conditions = mt_sadl_condition ).
endif.
et_sadl_condition = mt_sadl_condition.
endmethod.
method constructor.
* check_range_consistency( it_ranges ).
mt_ranges = it_ranges. "#EC CI_CONV_OK
mv_use_placeholders = iv_use_placeholders.
clear mt_sadl_condition.
endmethod.
endclass.
" In your method fetching the data
" Initialize runtime with interface view name
data(lr_runt) = lr_sapi->get_runtime( 'ZI_PAM_ROLE' ).
" Set (optional query conditions). Note the simple implementation of class lcl_cond
lr_runt->if_sadl_query_fetch~register_condition_provider(
new lcl_cond( value #( (
column_name = 'PROJECTID'
rule_group = 0
field_path = 'PROJECTID' " Just a field from CDS view
t_selopt = value #( ( sign = 'I' " Range options
option = 'EQ' "
low = '000001001366' ) ) ) " Just a value as example
)
)
).
" Set scope for selected fields (from CDS view), and flag data to be fetched
data ls_parameters type if_sadl_query_engine_types=>ty_requested.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |