initial commit after the full course

main
Stefan Haslinger (root) 2022-07-20 15:02:18 +00:00
parent b307bc7a31
commit 89dd6297a6
111 changed files with 4993 additions and 0 deletions

11
src/package.devc.xml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Rap Exercises</CTEXT>
<TPCLASS>X</TPCLASS>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,19 @@
CLASS zcl_hello_world_stefan DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_hello_world_stefan IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
out->write( |Hello World! ({ cl_abap_context_info=>get_user_description( ) })| ).
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_HELLO_WORLD_STEFAN</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Hello World Console App</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SUSH" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<HEAD>
<NAME>197385FDF8925AD5A592CDEEAD7E12</NAME>
<TYPE>HT</TYPE>
<DISPLAY_NAME>R3TR IWSG ZAPI_RAP_TRAVEL_STEFAN_0001</DISPLAY_NAME>
<DEVCLASS>ZRAP_TRAVEL_API_STEFAN</DEVCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</HEAD>
<USOBX>
<USOBX>
<NAME>197385FDF8925AD5A592CDEEAD7E12</NAME>
<TYPE>HT</TYPE>
<OBJECT>S_SERVICE</OBJECT>
<OKFLAG>X</OKFLAG>
</USOBX>
</USOBX>
<USOBX_EXT>
<item>
<OBJECT>S_SERVICE</OBJECT>
<TTEXT>Check at Start of External Services</TTEXT>
<OCLSS>AAAB</OCLSS>
<OKFLAG>X</OKFLAG>
<DEVCLASS>S_PROFGEN</DEVCLASS>
<PS_POSID>BC-SEC-AUT-PFC</PS_POSID>
<CI_TEXT>Check</CI_TEXT>
<CH_TEXT>Check</CH_TEXT>
<PR_TEXT>No</PR_TEXT>
<EXCEP>3</EXCEP>
<EXCEP_TX>Okay</EXCEP_TX>
<EXCEP_ICON>@08@</EXCEP_ICON>
</item>
</USOBX_EXT>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SUSH" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<HEAD>
<NAME>B658DCCB21E16A41D6CAD4011E8ECC</NAME>
<TYPE>HT</TYPE>
<DISPLAY_NAME>R3TR IWSV ZAPI_RAP_TRAVEL_STEFAN 0001</DISPLAY_NAME>
<DEVCLASS>ZRAP_TRAVEL_API_STEFAN</DEVCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</HEAD>
<USOBX>
<USOBX>
<NAME>B658DCCB21E16A41D6CAD4011E8ECC</NAME>
<TYPE>HT</TYPE>
<OBJECT>S_SERVICE</OBJECT>
<OKFLAG>X</OKFLAG>
</USOBX>
</USOBX>
<USOBX_EXT>
<item>
<OBJECT>S_SERVICE</OBJECT>
<TTEXT>Check at Start of External Services</TTEXT>
<OCLSS>AAAB</OCLSS>
<OKFLAG>X</OKFLAG>
<DEVCLASS>S_PROFGEN</DEVCLASS>
<PS_POSID>BC-SEC-AUT-PFC</PS_POSID>
<CI_TEXT>Check</CI_TEXT>
<CH_TEXT>Check</CH_TEXT>
<PR_TEXT>No</PR_TEXT>
<EXCEP>3</EXCEP>
<EXCEP_TX>Okay</EXCEP_TX>
<EXCEP_ICON>@08@</EXCEP_ICON>
</item>
</USOBX_EXT>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Travel API scenario</CTEXT>
<TPCLASS>X</TPCLASS>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SRVB" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SRVB>
<METADATA>
<NAME>ZAPI_RAP_TRAVEL_STEFAN</NAME>
<TYPE>SRVB/SVB</TYPE>
<DESCRIPTION>API scenario</DESCRIPTION>
<LANGUAGE>EN</LANGUAGE>
<LINKS>
<item>
<HREF>versions</HREF>
<REL>http://www.sap.com/adt/relations/versions</REL>
<TITLE>Historic versions</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/businessservices/odatav2/ZAPI_RAP_TRAVEL_STEFAN</HREF>
<REL>http://www.sap.com/categories/odatav2</REL>
<TYPE>application/vnd.sap.adt.businessservices.odatav2.v2+xml</TYPE>
<TITLE>ODATAV2</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/businessservices/testclass</HREF>
<REL>http://www.sap.com/categories/testclass</REL>
<TYPE>application/vnd.sap.adt.businessservices.testclass.v1+xml</TYPE>
<TITLE>TESTCLASS</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/businessservices/testclass</HREF>
<REL>http://www.sap.com/categories/testclass</REL>
<TYPE>application/vnd.sap.adt.businessservices.testclassv4.v1+xml</TYPE>
<TITLE>TESTCLASSV4</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/businessservices/semanticversion</HREF>
<REL>http://www.sap.com/categories/semanticversion</REL>
<TYPE>application/vnd.sap.adt.businessservices.semanticversion.v1+xml</TYPE>
<TITLE>SemanticVersion</TITLE>
</item>
</LINKS>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
</METADATA>
<CONTENT>
<BIND_TYPE_IMPL>
<NAME>ZAPI_RAP_TRAVEL_STEFAN</NAME>
</BIND_TYPE_IMPL>
<BIND_TYPE>ODATA</BIND_TYPE>
<BIND_TYPE_CATEGORY>1</BIND_TYPE_CATEGORY>
<BIND_TYPE_VERSION>V2</BIND_TYPE_VERSION>
<SERVICES>
<item>
<SERVICE_NAME>ZAPI_RAP_TRAVEL_STEFAN</SERVICE_NAME>
<SERVICE_CONTENT>
<item>
<SERVICE_VERSION>0001</SERVICE_VERSION>
<RELEASE_STATE>NOT_RELEASED</RELEASE_STATE>
<SRVD_REF>
<URI>/sap/bc/adt/ddic/srvd/sources/zapi_rap_travel_stefan</URI>
<TYPE>SRVD/SRV</TYPE>
<NAME>ZAPI_RAP_TRAVEL_STEFAN</NAME>
</SRVD_REF>
</item>
</SERVICE_CONTENT>
</item>
</SERVICES>
</CONTENT>
<CONTRACT>C2</CONTRACT>
<RELEASE_SUPPORTED>true</RELEASE_SUPPORTED>
<PUBLISHED>true</PUBLISHED>
<BINDING_CREATED>true</BINDING_CREATED>
</SRVB>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,4 @@
@EndUserText.label: 'Travel API'
define service ZAPI_RAP_Travel_Stefan {
expose ZC_RAP_Travel_Stefan as Travel;
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SRVD" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SRVD>
<NAME>ZAPI_RAP_TRAVEL_STEFAN</NAME>
<TYPE>SRVD/SRV</TYPE>
<DESCRIPTION>Travel API</DESCRIPTION>
<LANGUAGE>EN</LANGUAGE>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<SOURCE_URI>./zapi_rap_travel_stefan/source/main</SOURCE_URI>
<SOURCE_TYPE>ABAP_SOURCE</SOURCE_TYPE>
<SOURCE_ORIGIN_DESCRIPTION>ABAP Development Tools</SOURCE_ORIGIN_DESCRIPTION>
<SRVD_SOURCE_TYPE>S</SRVD_SOURCE_TYPE>
<SRVD_SOURCE_TYPE_DESC>Definition</SRVD_SOURCE_TYPE_DESC>
</SRVD>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SCO2" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SCO2>
<IBS_ID>ZAPI_RAP_TRAVEL_STEFAN_IWSG</IBS_ID>
<IBS_TYPE>IWSG</IBS_TYPE>
<ODATA_SRV_IDENTIFIER>ZAPI_RAP_TRAVEL_STEFAN_0001</ODATA_SRV_IDENTIFIER>
<REL_FOR_CUST_CSCN>X</REL_FOR_CUST_CSCN>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
<NAME>ZAPI_RAP_TRAVEL_STEFAN_IWSG</NAME>
<DESCRIPTION>ZAPI_RAP_TRAVEL_STEFAN</DESCRIPTION>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>
</SCO2>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SIA6" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SIA6>
<MAIN_OBJECT>
<NAME>ZAPI_RAP_TRAVEL_STEFAN_IWSG_IBS</NAME>
<TYPE>SIA6</TYPE>
<DESCRIPTION>ZAPI_RAP_TRAVEL_STEFAN</DESCRIPTION>
<RESPONSIBLE>CB9980009493</RESPONSIBLE>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<MASTER_SYSTEM>TRL</MASTER_SYSTEM>
<PACKAGE_REF>
<PACKAGE_NAME>ZRAP_TRAVEL_API_STEFAN</PACKAGE_NAME>
</PACKAGE_REF>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>
</MAIN_OBJECT>
<APP_ID>ZAPI_RAP_TRAVEL_STEFAN_IWSG_IBS</APP_ID>
<APP_TYPE>IBS</APP_TYPE>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
<SECONDARY_ID>ZAPI_RAP_TRAVEL_STEFAN_IWSG</SECONDARY_ID>
</SIA6>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SCO1" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SCO1>
<COMMUNICATION_SCENARIO_ID>ZCS_TRAVEL_STEFAN</COMMUNICATION_SCENARIO_ID>
<COMMUNICATION_SCENARIO_TYPE>1</COMMUNICATION_SCENARIO_TYPE>
<ALLOWED_CA_INSTANCES>1</ALLOWED_CA_INSTANCES>
<IB_TRUST_PSE_ID>SSLC_CUSTOMER_DEFAULT</IB_TRUST_PSE_ID>
<IB_BASIC_AUTH>X</IB_BASIC_AUTH>
<IB_X509_AUTH>X</IB_X509_AUTH>
<INBOUND_ROLE_ID>ZCR_CILMAJJFMEPN3APKZS26AGS7DM</INBOUND_ROLE_ID>
<OB_AUTH_PSE_ID>SSLC_CUSTOMER_DEFAULT</OB_AUTH_PSE_ID>
<OB_TRUST_PSE_ID>SSLC_CUSTOMER_DEFAULT</OB_TRUST_PSE_ID>
<OB_BASIC_AUTH>X</OB_BASIC_AUTH>
<OB_X509_AUTH>X</OB_X509_AUTH>
<OB_OAUTH2_AUTH>X</OB_OAUTH2_AUTH>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
<MAIN_OBJECT>
<NAME>ZCS_TRAVEL_STEFAN</NAME>
<TYPE>SCO1</TYPE>
<DESCRIPTION>Travel Data</DESCRIPTION>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>
</MAIN_OBJECT>
<SCOPE_STATUS>3</SCOPE_STATUS>
<SCOPE_STATUS_TEXT>On</SCOPE_STATUS_TEXT>
<PLUGIN_CONFIG>
<item>
<UI_OBJECT>cscn_type_selection</UI_OBJECT>
<IS_VISIBLE>X</IS_VISIBLE>
<IS_ENABLED>X</IS_ENABLED>
</item>
<item>
<UI_OBJECT>cscn_allow_create_by_key_checkbox</UI_OBJECT>
</item>
<item>
<UI_OBJECT>cscn_badi_impl_class_input</UI_OBJECT>
</item>
<item>
<UI_OBJECT>cscn_scope_status</UI_OBJECT>
</item>
</PLUGIN_CONFIG>
</SCO1>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Extension scenario - Travel List Report App</CTEXT>
<TPCLASS>X</TPCLASS>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,28 @@
@EndUserText.label: 'Custom entity for agencies from ES5'
@ObjectModel.query.implementedBy: 'ABAP:ZCL_CE_RAP_AGENCY_STEFAN'
define custom entity ZCE_RAP_AGENCY_Stefan
{
key AgencyId : abap.numc( 6 );
@OData.property.valueControl: 'Name_vc'
Name : abap.char( 31 );
Name_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'Street_vc'
Street : abap.char( 30 );
Street_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'PostalCode_vc'
PostalCode : abap.char( 10 );
PostalCode_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'City_vc'
City : abap.char( 25 );
City_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'Country_vc'
Country : abap.char( 3 );
Country_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'PhoneNumber_vc'
PhoneNumber : abap.char( 30 );
PhoneNumber_vc : rap_cp_odata_value_control;
@OData.property.valueControl: 'WebAddress_vc'
WebAddress : abap.char( 255 );
WebAddress_vc : rap_cp_odata_value_control;
}

View File

@ -0,0 +1,17 @@
{
"BASEINFO":
{
"FROM":
[],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZCE_RAP_AGENCY_STEFAN</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>Custom entity for agencies from ES5</DDTEXT>
<SOURCE_TYPE>Q</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,172 @@
CLASS zcl_ce_rap_agency_Stefan DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
INTERFACES if_rap_query_provider.
TYPES t_agency_range TYPE RANGE OF zrap_Stefanz_travel_agency_es5-agencyid.
TYPES t_business_data TYPE TABLE OF zrap_Stefanz_travel_agency_es5.
METHODS get_agencies
IMPORTING
filter_cond TYPE if_rap_query_filter=>tt_name_range_pairs OPTIONAL
top TYPE i OPTIONAL
skip TYPE i OPTIONAL
is_data_requested TYPE abap_bool
is_count_requested TYPE abap_bool
EXPORTING
business_data TYPE t_business_data
count TYPE int8
RAISING
/iwbep/cx_cp_remote
/iwbep/cx_gateway
cx_web_http_client_error
cx_http_dest_provider_error
.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_ce_rap_agency_Stefan IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA business_data TYPE t_business_data.
DATA count TYPE int8.
DATA filter_conditions TYPE if_rap_query_filter=>tt_name_range_pairs .
DATA ranges_table TYPE if_rap_query_filter=>tt_range_option .
ranges_table = VALUE #( ( sign = 'I' option = 'GE' low = '070015' ) ).
filter_conditions = VALUE #( ( name = 'AGENCYID' range = ranges_table ) ).
TRY.
get_agencies(
EXPORTING
filter_cond = filter_conditions
top = 3
skip = 1
is_count_requested = abap_true
is_data_requested = abap_true
IMPORTING
business_data = business_data
count = count
) .
out->write( |Total number of records = { count }| ) .
out->write( business_data ).
CATCH cx_root INTO DATA(exception).
out->write( cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_longtext( ) ).
ENDTRY.
ENDMETHOD.
METHOD get_agencies.
DATA: filter_factory TYPE REF TO /iwbep/if_cp_filter_factory,
filter_node TYPE REF TO /iwbep/if_cp_filter_node,
root_filter_node TYPE REF TO /iwbep/if_cp_filter_node.
DATA: http_client TYPE REF TO if_web_http_client,
odata_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy,
read_list_request TYPE REF TO /iwbep/if_cp_request_read_list,
read_list_response TYPE REF TO /iwbep/if_cp_response_read_lst.
DATA service_consumption_name TYPE cl_web_odata_client_factory=>ty_service_definition_name.
DATA(http_destination) = cl_http_destination_provider=>create_by_url( i_url = 'https://sapes5.sapdevcenter.com' ).
http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = http_destination ).
service_consumption_name = to_upper( 'ZSC_RAP_AGENCY_Stefan' ).
odata_client_proxy = cl_web_odata_client_factory=>create_v2_remote_proxy(
EXPORTING
iv_service_definition_name = service_consumption_name
io_http_client = http_client
iv_relative_service_root = '/sap/opu/odata/sap/ZAGENCYCDS_SRV/' ).
" Navigate to the resource and create a request for the read operation
read_list_request = odata_client_proxy->create_resource_for_entity_set( 'Z_TRAVEL_AGENCY_ES5' )->create_request_for_read( ).
" Create the filter tree
filter_factory = read_list_request->create_filter_factory( ).
LOOP AT filter_cond INTO DATA(filter_condition).
filter_node = filter_factory->create_by_range( iv_property_path = filter_condition-name
it_range = filter_condition-range ).
IF root_filter_node IS INITIAL.
root_filter_node = filter_node.
ELSE.
root_filter_node = root_filter_node->and( filter_node ).
ENDIF.
ENDLOOP.
IF root_filter_node IS NOT INITIAL.
read_list_request->set_filter( root_filter_node ).
ENDIF.
IF is_data_requested = abap_true.
read_list_request->set_skip( skip ).
IF top > 0 .
read_list_request->set_top( top ).
ENDIF.
ENDIF.
IF is_count_requested = abap_true.
read_list_request->request_count( ).
ENDIF.
IF is_data_requested = abap_false.
read_list_request->request_no_business_data( ).
ENDIF.
" Execute the request and retrieve the business data and count if requested
read_list_response = read_list_request->execute( ).
IF is_data_requested = abap_true.
read_list_response->get_business_data( IMPORTING et_business_data = business_data ).
ENDIF.
IF is_count_requested = abap_true.
count = read_list_response->get_count( ).
ENDIF.
ENDMETHOD.
METHOD if_rap_query_provider~select.
DATA business_data TYPE t_business_data.
DATA(top) = io_request->get_paging( )->get_page_size( ).
DATA(skip) = io_request->get_paging( )->get_offset( ).
DATA(requested_fields) = io_request->get_requested_elements( ).
DATA(sort_order) = io_request->get_sort_elements( ).
DATA count TYPE int8.
TRY.
DATA(filter_condition) = io_request->get_filter( )->get_as_ranges( ).
get_agencies(
EXPORTING
filter_cond = filter_condition
top = CONV i( top )
skip = CONV i( skip )
is_data_requested = io_request->is_data_requested( )
is_count_requested = io_request->is_total_numb_of_rec_requested( )
IMPORTING
business_data = business_data
count = count
) .
IF io_request->is_total_numb_of_rec_requested( ).
io_response->set_total_number_of_records( count ).
ENDIF.
IF io_request->is_data_requested( ).
io_response->set_data( business_data ).
ENDIF.
CATCH cx_root INTO DATA(exception).
DATA(exception_message) = cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_longtext( ).
ENDTRY.
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_CE_RAP_AGENCY_STEFAN</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Query implementation custom entity</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,28 @@
/********** GENERATED on 07/19/2022 at 08:21:34 by CB9980009493**************/
@OData.entitySet.name: 'Z_TRAVEL_AGENCY_ES5'
@OData.entityType.name: 'Z_TRAVEL_AGENCY_ES5Type'
define root abstract entity ZRAP_STEFANZ_TRAVEL_AGENCY_ES5 {
key AgencyId : abap.numc( 6 ) ;
@Odata.property.valueControl: 'Name_vc'
Name : abap.char( 31 ) ;
Name_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'Street_vc'
Street : abap.char( 30 ) ;
Street_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'PostalCode_vc'
PostalCode : abap.char( 10 ) ;
PostalCode_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'City_vc'
City : abap.char( 25 ) ;
City_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'Country_vc'
Country : abap.char( 3 ) ;
Country_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'PhoneNumber_vc'
PhoneNumber : abap.char( 30 ) ;
PhoneNumber_vc : RAP_CP_ODATA_VALUE_CONTROL ;
@Odata.property.valueControl: 'WebAddress_vc'
WebAddress : abap.char( 255 ) ;
WebAddress_vc : RAP_CP_ODATA_VALUE_CONTROL ;
}

View File

@ -0,0 +1,17 @@
{
"BASEINFO":
{
"FROM":
[],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZRAP_STEFANZ_TRAVEL_AGENCY_ES5</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>Service Consumption ZRAP_STEFANZ_TRAVEL_AGENCY_ES5</DDTEXT>
<SOURCE_TYPE>A</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,5 @@
@EndUserText.label: 'ZSC_RAP_AGENCY_STEFAN'
@OData.schema.name: 'ZAGENCYCDS_SRV'
define service ZSC_RAP_AGENCY_STEFAN {
expose ZRAP_STEFANZ_TRAVEL_AGENCY_ES5;
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SRVD" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<SRVD>
<NAME>ZSC_RAP_AGENCY_STEFAN</NAME>
<TYPE>SRVD/SRV</TYPE>
<DESCRIPTION>ZSC_RAP_AGENCY_STEFAN</DESCRIPTION>
<LANGUAGE>EN</LANGUAGE>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<SOURCE_URI>./zsc_rap_agency_stefan/source/main</SOURCE_URI>
<SOURCE_TYPE>ABAP_SOURCE</SOURCE_TYPE>
<SOURCE_ORIGIN>9</SOURCE_ORIGIN>
<SOURCE_ORIGIN_DESCRIPTION>Service consumption model</SOURCE_ORIGIN_DESCRIPTION>
<SRVD_SOURCE_TYPE>S</SRVD_SOURCE_TYPE>
<SRVD_SOURCE_TYPE_DESC>Definition</SRVD_SOURCE_TYPE_DESC>
</SRVD>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SUSH" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<HEAD>
<NAME>22BBD3C9BCC1B9EC6B06B7A6B64CB5</NAME>
<TYPE>HT</TYPE>
<DISPLAY_NAME>R3TR IWSG ZUI_RAP_TRAVEL_O2_STEFAN_0001</DISPLAY_NAME>
<DEVCLASS>ZRAP_TRAVEL_STEFAN</DEVCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</HEAD>
<USOBX>
<USOBX>
<NAME>22BBD3C9BCC1B9EC6B06B7A6B64CB5</NAME>
<TYPE>HT</TYPE>
<OBJECT>S_SERVICE</OBJECT>
<OKFLAG>X</OKFLAG>
</USOBX>
</USOBX>
<USOBX_EXT>
<item>
<OBJECT>S_SERVICE</OBJECT>
<TTEXT>Check at Start of External Services</TTEXT>
<OCLSS>AAAB</OCLSS>
<OKFLAG>X</OKFLAG>
<DEVCLASS>S_PROFGEN</DEVCLASS>
<PS_POSID>BC-SEC-AUT-PFC</PS_POSID>
<CI_TEXT>Check</CI_TEXT>
<CH_TEXT>Check</CH_TEXT>
<PR_TEXT>No</PR_TEXT>
<EXCEP>3</EXCEP>
<EXCEP_TX>Okay</EXCEP_TX>
<EXCEP_ICON>@08@</EXCEP_ICON>
</item>
</USOBX_EXT>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_SUSH" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<HEAD>
<NAME>C148050A24EDD1C9D135F8F6E70CDC</NAME>
<TYPE>HT</TYPE>
<DISPLAY_NAME>R3TR IWSV ZUI_RAP_TRAVEL_O2_STEFAN 0001</DISPLAY_NAME>
<DEVCLASS>ZRAP_TRAVEL_STEFAN</DEVCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</HEAD>
<USOBX>
<USOBX>
<NAME>C148050A24EDD1C9D135F8F6E70CDC</NAME>
<TYPE>HT</TYPE>
<OBJECT>S_SERVICE</OBJECT>
<OKFLAG>X</OKFLAG>
</USOBX>
</USOBX>
<USOBX_EXT>
<item>
<OBJECT>S_SERVICE</OBJECT>
<TTEXT>Check at Start of External Services</TTEXT>
<OCLSS>AAAB</OCLSS>
<OKFLAG>X</OKFLAG>
<DEVCLASS>S_PROFGEN</DEVCLASS>
<PS_POSID>BC-SEC-AUT-PFC</PS_POSID>
<CI_TEXT>Check</CI_TEXT>
<CH_TEXT>Check</CH_TEXT>
<PR_TEXT>No</PR_TEXT>
<EXCEP>3</EXCEP>
<EXCEP_TX>Okay</EXCEP_TX>
<EXCEP_ICON>@08@</EXCEP_ICON>
</item>
</USOBX_EXT>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Greenfield Implementation - Travel List Report App</CTEXT>
<TPCLASS>X</TPCLASS>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,5 @@
CLASS zbp_i_rap_booking_stefan DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zi_rap_travel_stefan.
ENDCLASS.
CLASS zbp_i_rap_booking_stefan IMPLEMENTATION.
ENDCLASS.

View File

@ -0,0 +1,81 @@
CLASS lhc_Booking DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS calculateBookingID FOR DETERMINE ON MODIFY
IMPORTING keys FOR Booking~calculateBookingID.
METHODS calculateTotalPrice FOR DETERMINE ON MODIFY
IMPORTING keys FOR Booking~calculateTotalPrice.
ENDCLASS.
CLASS lhc_Booking IMPLEMENTATION.
METHOD calculateBookingID.
DATA max_bookingid TYPE /dmo/booking_id.
DATA update TYPE TABLE FOR UPDATE ZI_RAP_Travel_Stefan\\Booking.
" Read all travels for the requested bookings.
" If multiple bookings of the same travel are requested, the travel is returned only once.
READ ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Booking BY \_Travel
FIELDS ( TravelUUID )
WITH CORRESPONDING #( keys )
RESULT DATA(travels).
" Process all affected Travels. Read respective bookings, determine the max-id and update the bookings without ID.
LOOP AT travels INTO DATA(travel).
READ ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Travel BY \_Booking
FIELDS ( BookingID )
WITH VALUE #( ( %tky = travel-%tky ) )
RESULT DATA(bookings).
" Find max used BookingID in all bookings of this travel
max_bookingid ='0000'.
LOOP AT bookings INTO DATA(booking).
IF booking-BookingID > max_bookingid.
max_bookingid = booking-BookingID.
ENDIF.
ENDLOOP.
" Provide a booking ID for all bookings that have none.
LOOP AT bookings INTO booking WHERE BookingID IS INITIAL.
max_bookingid += 10.
APPEND VALUE #( %tky = booking-%tky
BookingID = max_bookingid
) TO update.
ENDLOOP.
ENDLOOP.
" Update the Booking ID of all relevant bookings
MODIFY ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Booking
UPDATE FIELDS ( BookingID ) WITH update
REPORTED DATA(update_reported).
reported = CORRESPONDING #( DEEP update_reported ).
ENDMETHOD.
METHOD calculateTotalPrice.
" Read all travels for the requested bookings.
" If multiple bookings of the same travel are requested, the travel is returned only once.
READ ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Booking BY \_Travel
FIELDS ( TravelUUID )
WITH CORRESPONDING #( keys )
RESULT DATA(travels)
FAILED DATA(read_failed).
" Trigger calculation of the total price
MODIFY ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Travel
EXECUTE recalcTotalPrice
FROM CORRESPONDING #( travels )
REPORTED DATA(execute_reported).
reported = CORRESPONDING #( DEEP execute_reported ).
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZBP_I_RAP_BOOKING_STEFAN</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Behavior Implementation for ZI_RAP_TRAVEL_STEFAN</DESCRIPT>
<CATEGORY>06</CATEGORY>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZI_RAP_TRAVEL_STEFAN</CLSDEFINT>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -0,0 +1,5 @@
CLASS zbp_i_rap_travel_stefan DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zi_rap_travel_stefan.
ENDCLASS.
CLASS zbp_i_rap_travel_stefan IMPLEMENTATION.
ENDCLASS.

View File

@ -0,0 +1,580 @@
CLASS lhc_Travel DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
CONSTANTS:
BEGIN OF travel_status,
open TYPE c LENGTH 1 VALUE 'O', " Open
accepted TYPE c LENGTH 1 VALUE 'A', " Accepted
canceled TYPE c LENGTH 1 VALUE 'X', " Cancelled
END OF travel_status.
METHODS get_instance_features FOR INSTANCE FEATURES
IMPORTING keys REQUEST requested_features FOR Travel RESULT result.
METHODS acceptTravel FOR MODIFY
IMPORTING keys FOR ACTION Travel~acceptTravel RESULT result.
METHODS recalcTotalPrice FOR MODIFY
IMPORTING keys FOR ACTION Travel~recalcTotalPrice.
METHODS rejectTravel FOR MODIFY
IMPORTING keys FOR ACTION Travel~rejectTravel RESULT result.
METHODS calculateTotalPrice FOR DETERMINE ON MODIFY
IMPORTING keys FOR Travel~calculateTotalPrice.
METHODS setInitialStatus FOR DETERMINE ON MODIFY
IMPORTING keys FOR Travel~setInitialStatus.
METHODS calculateTravelID FOR DETERMINE ON SAVE
IMPORTING keys FOR Travel~calculateTravelID.
METHODS validateAgency FOR VALIDATE ON SAVE
IMPORTING keys FOR Travel~validateAgency.
METHODS validateCustomer FOR VALIDATE ON SAVE
IMPORTING keys FOR Travel~validateCustomer.
METHODS validateDates FOR VALIDATE ON SAVE
IMPORTING keys FOR Travel~validateDates.
METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR Travel RESULT result.
METHODS is_update_granted IMPORTING has_before_image TYPE abap_bool
overall_status TYPE /dmo/overall_status
RETURNING VALUE(update_granted) TYPE abap_bool.
METHODS is_delete_granted IMPORTING has_before_image TYPE abap_bool
overall_status TYPE /dmo/overall_status
RETURNING VALUE(delete_granted) TYPE abap_bool.
METHODS is_create_granted RETURNING VALUE(create_granted) TYPE abap_bool.
ENDCLASS.
CLASS lhc_Travel IMPLEMENTATION.
METHOD get_instance_features.
" Read the travel status of the existing travels
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( TravelStatus ) WITH CORRESPONDING #( keys )
RESULT DATA(travels)
FAILED failed.
result =
VALUE #(
FOR travel IN travels
LET is_accepted = COND #( WHEN travel-TravelStatus = travel_status-accepted
THEN if_abap_behv=>fc-o-disabled
ELSE if_abap_behv=>fc-o-enabled )
is_rejected = COND #( WHEN travel-TravelStatus = travel_status-canceled
THEN if_abap_behv=>fc-o-disabled
ELSE if_abap_behv=>fc-o-enabled )
IN
( %tky = travel-%tky
%action-acceptTravel = is_accepted
%action-rejectTravel = is_rejected
) ).
ENDMETHOD.
METHOD acceptTravel.
" Set the new overall status
MODIFY ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
UPDATE
FIELDS ( TravelStatus )
WITH VALUE #( FOR key IN keys
( %tky = key-%tky
TravelStatus = travel_status-accepted ) )
FAILED failed
REPORTED reported.
" Fill the response table
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(travels).
result = VALUE #( FOR travel IN travels
( %tky = travel-%tky
%param = travel ) ).
ENDMETHOD.
METHOD recalcTotalPrice.
TYPES: BEGIN OF ty_amount_per_currencycode,
amount TYPE /dmo/total_price,
currency_code TYPE /dmo/currency_code,
END OF ty_amount_per_currencycode.
DATA: amount_per_currencycode TYPE STANDARD TABLE OF ty_amount_per_currencycode.
" Read all relevant travel instances.
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( BookingFee CurrencyCode )
WITH CORRESPONDING #( keys )
RESULT DATA(travels).
DELETE travels WHERE CurrencyCode IS INITIAL.
LOOP AT travels ASSIGNING FIELD-SYMBOL(<travel>).
" Set the start for the calculation by adding the booking fee.
amount_per_currencycode = VALUE #( ( amount = <travel>-BookingFee
currency_code = <travel>-CurrencyCode ) ).
" Read all associated bookings and add them to the total price.
READ ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY Travel BY \_Booking
FIELDS ( FlightPrice CurrencyCode )
WITH VALUE #( ( %tky = <travel>-%tky ) )
RESULT DATA(bookings).
LOOP AT bookings INTO DATA(booking) WHERE CurrencyCode IS NOT INITIAL.
COLLECT VALUE ty_amount_per_currencycode( amount = booking-FlightPrice
currency_code = booking-CurrencyCode ) INTO amount_per_currencycode.
ENDLOOP.
CLEAR <travel>-TotalPrice.
LOOP AT amount_per_currencycode INTO DATA(single_amount_per_currencycode).
" If needed do a Currency Conversion
IF single_amount_per_currencycode-currency_code = <travel>-CurrencyCode.
<travel>-TotalPrice += single_amount_per_currencycode-amount.
ELSE.
/dmo/cl_flight_amdp=>convert_currency(
EXPORTING
iv_amount = single_amount_per_currencycode-amount
iv_currency_code_source = single_amount_per_currencycode-currency_code
iv_currency_code_target = <travel>-CurrencyCode
iv_exchange_rate_date = cl_abap_context_info=>get_system_date( )
IMPORTING
ev_amount = DATA(total_booking_price_per_curr)
).
<travel>-TotalPrice += total_booking_price_per_curr.
ENDIF.
ENDLOOP.
ENDLOOP.
" write back the modified total_price of travels
MODIFY ENTITIES OF ZI_RAP_Travel_Stefan IN LOCAL MODE
ENTITY travel
UPDATE FIELDS ( TotalPrice )
WITH CORRESPONDING #( travels ).
ENDMETHOD.
METHOD rejectTravel.
" Set the new overall status
MODIFY ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
UPDATE
FIELDS ( TravelStatus )
WITH VALUE #( FOR key IN keys
( %tky = key-%tky
TravelStatus = travel_status-canceled ) )
FAILED failed
REPORTED reported.
" Fill the response table
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(travels).
result = VALUE #( FOR travel IN travels
( %tky = travel-%tky
%param = travel ) ).
ENDMETHOD.
METHOD calculateTotalPrice.
MODIFY ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY travel
EXECUTE recalcTotalPrice
FROM CORRESPONDING #( keys )
REPORTED DATA(execute_reported).
reported = CORRESPONDING #( DEEP execute_reported ).
ENDMETHOD.
METHOD setInitialStatus.
" Read relevant travel instance data
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( TravelStatus ) WITH CORRESPONDING #( keys )
RESULT DATA(travels).
" Remove all travel instance data with defined status
DELETE travels WHERE TravelStatus IS NOT INITIAL.
CHECK travels IS NOT INITIAL.
" Set default travel status
MODIFY ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
UPDATE
FIELDS ( TravelStatus )
WITH VALUE #( FOR travel IN travels
( %tky = travel-%tky
TravelStatus = travel_status-open ) )
REPORTED DATA(update_reported).
reported = CORRESPONDING #( DEEP update_reported ).
ENDMETHOD.
METHOD calculateTravelID.
" Please note that this is just an example for calculating a field during _onSave_.
" This approach does NOT ensure for gap free or unique travel IDs! It just helps to provide a readable ID.
" The key of this business object is a UUID, calculated by the framework.
" check if TravelID is already filled
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( TravelID ) WITH CORRESPONDING #( keys )
RESULT DATA(travels).
" remove lines where TravelID is already filled.
DELETE travels WHERE TravelID IS NOT INITIAL.
" anything left ?
CHECK travels IS NOT INITIAL.
" Select max travel ID
SELECT SINGLE
FROM zrap_atrav_Stefa
FIELDS MAX( travel_id ) AS travelID
INTO @DATA(max_travelid).
" Set the travel ID
MODIFY ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
UPDATE
FROM VALUE #( FOR travel IN travels INDEX INTO i (
%tky = travel-%tky
TravelID = max_travelid + i
%control-TravelID = if_abap_behv=>mk-on ) )
REPORTED DATA(update_reported).
reported = CORRESPONDING #( DEEP update_reported ).
ENDMETHOD.
METHOD validateAgency.
" Read relevant travel instance data
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( AgencyID ) WITH CORRESPONDING #( keys )
RESULT DATA(travels).
DATA agencies TYPE SORTED TABLE OF /dmo/agency WITH UNIQUE KEY agency_id.
" Optimization of DB select: extract distinct non-initial agency IDs
agencies = CORRESPONDING #( travels DISCARDING DUPLICATES MAPPING agency_id = AgencyID EXCEPT * ).
DELETE agencies WHERE agency_id IS INITIAL.
** IF agencies IS NOT INITIAL.
** " Check if agency ID exist
** SELECT FROM /dmo/agency FIELDS agency_id
** FOR ALL ENTRIES IN @agencies
** WHERE agency_id = @agencies-agency_id
** INTO TABLE @DATA(agencies_db).
** ENDIF.
LOOP AT travels INTO DATA(travel).
* " Clear state messages that might exist
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_AGENCY' )
TO reported-travel.
ENDLOOP.
DATA filter_conditions TYPE if_rap_query_filter=>tt_name_range_pairs .
DATA ranges_table TYPE if_rap_query_filter=>tt_range_option .
DATA business_data TYPE TABLE OF zrap_Stefanz_travel_agency_es5.
IF agencies IS NOT INITIAL.
ranges_table = VALUE #( FOR agency IN agencies ( sign = 'I' option = 'EQ' low = agency-agency_id ) ).
filter_conditions = VALUE #( ( name = 'AGENCYID' range = ranges_table ) ).
TRY.
"skip and top must not be used
"but an appropriate filter will be provided
NEW zcl_ce_rap_agency_1234( )->get_agencies(
EXPORTING
filter_cond = filter_conditions
is_data_requested = abap_true
is_count_requested = abap_false
IMPORTING
business_data = business_data
) .
CATCH /iwbep/cx_cp_remote
/iwbep/cx_gateway
cx_web_http_client_error
cx_http_dest_provider_error
INTO DATA(exception).
DATA(exception_message) = cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_text( ) .
LOOP AT travels INTO travel.
APPEND VALUE #( %tky = travel-%tky ) TO failed-travel.
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_AGENCY'
%msg = new_message_with_text( severity = if_abap_behv_message=>severity-error text = exception_message )
%element-AgencyID = if_abap_behv=>mk-on )
TO reported-travel.
ENDLOOP.
RETURN.
ENDTRY.
ENDIF.
" Raise msg for non existing and initial agencyID
** LOOP AT travels INTO DATA(travel).
LOOP AT travels INTO travel.
** " Clear state messages that might exist
** APPEND VALUE #( %tky = travel-%tky
** %state_area = 'VALIDATE_AGENCY' )
** TO reported-travel.
** IF travel-AgencyID IS INITIAL OR NOT line_exists( agencies_db[ agency_id = travel-AgencyID ] ).
IF travel-AgencyID IS INITIAL OR NOT line_exists( business_data[ agencyid = travel-AgencyID ] ).
APPEND VALUE #( %tky = travel-%tky ) TO failed-travel.
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_AGENCY'
%msg = NEW zcm_rap_Stefan(
severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>agency_unknown
agencyid = travel-AgencyID )
%element-AgencyID = if_abap_behv=>mk-on )
TO reported-travel.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD validateCustomer.
" Read relevant travel instance data
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( CustomerID ) WITH CORRESPONDING #( keys )
RESULT DATA(travels).
DATA customers TYPE SORTED TABLE OF /dmo/customer WITH UNIQUE KEY customer_id.
" Optimization of DB select: extract distinct non-initial customer IDs
customers = CORRESPONDING #( travels DISCARDING DUPLICATES MAPPING customer_id = CustomerID EXCEPT * ).
DELETE customers WHERE customer_id IS INITIAL.
IF customers IS NOT INITIAL.
" Check if customer ID exist
SELECT FROM /dmo/customer FIELDS customer_id
FOR ALL ENTRIES IN @customers
WHERE customer_id = @customers-customer_id
INTO TABLE @DATA(customers_db).
ENDIF.
" Raise msg for non existing and initial customerID
LOOP AT travels INTO DATA(travel).
" Clear state messages that might exist
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_CUSTOMER' )
TO reported-travel.
IF travel-CustomerID IS INITIAL OR NOT line_exists( customers_db[ customer_id = travel-CustomerID ] ).
APPEND VALUE #( %tky = travel-%tky ) TO failed-travel.
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_CUSTOMER'
%msg = NEW zcm_rap_Stefan(
severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>customer_unknown
customerid = travel-CustomerID )
%element-CustomerID = if_abap_behv=>mk-on )
TO reported-travel.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD validateDates.
" Read relevant travel instance data
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( TravelID BeginDate EndDate ) WITH CORRESPONDING #( keys )
RESULT DATA(travels).
LOOP AT travels INTO DATA(travel).
" Clear state messages that might exist
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_DATES' )
TO reported-travel.
IF travel-EndDate < travel-BeginDate.
APPEND VALUE #( %tky = travel-%tky ) TO failed-travel.
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_DATES'
%msg = NEW zcm_rap_Stefan(
severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>date_interval
begindate = travel-BeginDate
enddate = travel-EndDate
travelid = travel-TravelID )
%element-BeginDate = if_abap_behv=>mk-on
%element-EndDate = if_abap_behv=>mk-on ) TO reported-travel.
ELSEIF travel-BeginDate < cl_abap_context_info=>get_system_date( ).
APPEND VALUE #( %tky = travel-%tky ) TO failed-travel.
APPEND VALUE #( %tky = travel-%tky
%state_area = 'VALIDATE_DATES'
%msg = NEW zcm_rap_Stefan(
severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>begin_date_before_system_date
begindate = travel-BeginDate )
%element-BeginDate = if_abap_behv=>mk-on ) TO reported-travel.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD get_instance_authorizations.
DATA: has_before_image TYPE abap_bool,
is_update_requested TYPE abap_bool,
is_delete_requested TYPE abap_bool,
update_granted TYPE abap_bool,
delete_granted TYPE abap_bool.
DATA: failed_travel LIKE LINE OF failed-travel.
" Read the existing travels
READ ENTITIES OF zi_rap_travel_Stefan IN LOCAL MODE
ENTITY Travel
FIELDS ( TravelStatus ) WITH CORRESPONDING #( keys )
RESULT DATA(travels)
FAILED failed.
CHECK travels IS NOT INITIAL.
* In this example the authorization is defined based on the Activity + Travel Status
* For the Travel Status we need the before-image from the database. We perform this for active (is_draft=00) as well as for drafts (is_draft=01) as we can't distinguish between edit or new drafts
SELECT FROM zrap_atrav_Stef
FIELDS travel_uuid,overall_status
FOR ALL ENTRIES IN @travels
WHERE travel_uuid EQ @travels-TravelUUID
ORDER BY PRIMARY KEY
INTO TABLE @DATA(travels_before_image).
is_update_requested = COND #( WHEN requested_authorizations-%update = if_abap_behv=>mk-on OR
requested_authorizations-%action-acceptTravel = if_abap_behv=>mk-on OR
requested_authorizations-%action-rejectTravel = if_abap_behv=>mk-on OR
requested_authorizations-%action-Prepare = if_abap_behv=>mk-on OR
requested_authorizations-%action-Edit = if_abap_behv=>mk-on OR
requested_authorizations-%assoc-_Booking = if_abap_behv=>mk-on
THEN abap_true ELSE abap_false ).
is_delete_requested = COND #( WHEN requested_authorizations-%delete = if_abap_behv=>mk-on
THEN abap_true ELSE abap_false ).
LOOP AT travels INTO DATA(travel).
update_granted = delete_granted = abap_false.
READ TABLE travels_before_image INTO DATA(travel_before_image)
WITH KEY travel_uuid = travel-TravelUUID BINARY SEARCH.
has_before_image = COND #( WHEN sy-subrc = 0 THEN abap_true ELSE abap_false ).
IF is_update_requested = abap_true.
" Edit of an existing record -> check update authorization
IF has_before_image = abap_true.
update_granted = is_update_granted( has_before_image = has_before_image overall_status = travel_before_image-overall_status ).
IF update_granted = abap_false.
APPEND VALUE #( %tky = travel-%tky
%msg = NEW zcm_rap_Stefan( severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>unauthorized )
) TO reported-travel.
ENDIF.
" Creation of a new record -> check create authorization
ELSE.
update_granted = is_create_granted( ).
IF update_granted = abap_false.
APPEND VALUE #( %tky = travel-%tky
%msg = NEW zcm_rap_Stefan( severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>unauthorized )
) TO reported-travel.
ENDIF.
ENDIF.
ENDIF.
IF is_delete_requested = abap_true.
delete_granted = is_delete_granted( has_before_image = has_before_image overall_status = travel_before_image-overall_status ).
IF delete_granted = abap_false.
APPEND VALUE #( %tky = travel-%tky
%msg = NEW zcm_rap_Stefan( severity = if_abap_behv_message=>severity-error
textid = zcm_rap_Stefan=>unauthorized )
) TO reported-travel.
ENDIF.
ENDIF.
APPEND VALUE #( %tky = travel-%tky
%update = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%action-acceptTravel = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%action-rejectTravel = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%action-Prepare = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%action-Edit = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%assoc-_Booking = COND #( WHEN update_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
%delete = COND #( WHEN delete_granted = abap_true THEN if_abap_behv=>auth-allowed ELSE if_abap_behv=>auth-unauthorized )
)
TO result.
ENDLOOP.
ENDMETHOD.
METHOD is_create_granted.
AUTHORITY-CHECK OBJECT 'ZOSTATStef'
ID 'ZOSTATStef' DUMMY