Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
In these blog I am going explain about:

How to create the Gate Way service using CDS Views with Parameters and Without Parameters:

Pre-requisite is to learn basics about the Core Data Services , Basic understanding about SADL Frame work.

Overview of CDS: https://blogs.sap.com/2016/09/26/core-data-services-cds-in-sap-s4-hana/

SADL: https://help.sap.com/saphelp_nw75/helpdata/en/eb/2282b05f1f4667b758a764e332fd88/frameset.htm

Setting Up ABAP On Eclipse: https://blogs.sap.com/2014/07/29/step-by-step-guide-to-setup-abap-on-hana-with-eclipse/

Step 1: Create the CDS view in Eclipse or Hana Studio.

Here I am creating two CDS views in Hana Studio

Creating CDS View for the House Bank Details

DDL SQL View: ZVTX_HBANK

DDL Source : ZTX_HBANK
@AbapCatalog.sqlViewName: 'zvtx_hbank'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'house bank data'
define view ztx_hbank
as select from t012
left outer join t001 on t001.bukrs = t012.bukrs
left outer join t012d on t012d.bukrs = t012.bukrs
and t012d.hbkid = t012.hbkid
{
key t012.bukrs as CompanyCode,
key t012.hbkid as HouseBankKey,
butxt as CompanyName,
banks as BankCountry,
bankl as BankInternalId,
t012d.dtbid as AlternativeBankId,
t012d.dtelz as BankNoReceiver,
dtkid as CustomerNumber,
dtfin as CompanyNumber,
edipn as PartnerNumber,
edisn as TypeOfSignature,
dtglz as BankNumber,
dtgbk as AccountNumber,
dtgko as ControlKey,
dtgis as IsoCurrencyCode,
dtaws as InstructionKey,
dtvta as LeadDays,
telf1 as Telephone,
stcd1 as TaxNumber,
name1 as NameOfContactPerson
}

On Activation of CDS view got created in the BACK END. Please find the below screen shot



Step 2: Creating the another CDS view with bank master details

Creating the CDS view ZTX_BANK in association with the ZTX_HBANK with Parameter.

DDL SQL View: ZVTX_BANK

DDL Source : ZTX_BANK

 
@AbapCatalog.sqlViewName: 'zvtx_bank'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'bank master'
define view ztx_bank
with parameters
p_spras: sylangu
as select from bnka
association[0..*] to ztx_hbank as _hbank on $projection.BankCountry = _hbank.BankCountry
and $projection.BankInternalId = _hbank.BankInternalId
{
key banks as BankCountry,
key bankl as BankInternalId,
erdat as CreateOn,
ernam as CreateBy,
bnka.banka as BankName,
provz as Region,
stras as StreetName,
ort01 as BankCity,
bnka.swift as Swift,
bgrup as BankGroup,
xpgro as PostOfficeAccount,
bnklz as BankNumber,
@EndUserText.label: 'Homeland or not'
case when banks = 'CN' then
// 'Homeland'
cast( 'Homeland' as abap.char( 20 ))
else cast ('Foreign Country' as abap.char( 20 ))
end as Country,
_hbank.CompanyCode,
_hbank.CompanyName,
_hbank
}

 

On activation View got generated in the back end please find the attached screen shot:



 

Step 3:Two CDS views created, now we are going to create the GATE WAY SERVICE using the                     CDS VIEWS.

In SAP GUI , Open the T-code SEGW

Create the project

Click on create button below POP-UP will open:



Step 4:  In Data Model right click on Entity type and Click on Create button, below POPUP will open                give the entity name and create the Entity Set and click on enter.



Step 5: Give the ABAP Structure name as ZVTX_BANK as shown below which is created on                          activation of CDS View



Step 6:  Right Click on Entity and Import Properties as shown below



Select the parameters which are required and click on next



Select the key and click on finish



Follow the same steps for the Hbank Entity as well it looks like as below shown fig:



  Creation of Properties for the Bank Master and house bank data is done

Step 7: Creating Association BankToHbank i.e optional if you need any associations between two                    entities we can create as shown below:

Right Click on the association node and Click on Create below screen appears:

click on next



Click on Next



Click on Finish



 

Step 8: In Service implementation:

Right Click on Service Implementation node & click on Map to Data Source



We have different types of business Entities as shown below:



In our case we are using the CDS view as a business entity:

ZTX_BANK is the CDS View Name



 

Step 9: Click on continue below mapping screen will appear



Click on generate Mapping or drag and drop the properties , below screen appears after                     mapping



Follow same steps for the Hbank Entity as well below screen appears after Mapping



 

Step 10: Save the Project and click on the generate run-time objects



Create of the model and service definitions , Click on okay and save the objects



Model Provider class and the Data provider classes generated success fully

Step 11:  Register the service i.e. Service registration in the Sap Gateway Hub System



Click on Register button, Select the system alias



Select the SYSTEM and add the service in the package and click on continue, Service                       gets added



 

Step 12:Test the service

Click on the SAP Gateway Client, below screen will appear



Select GET radio button and click on Execute button

HTTP Response with two entity sets get Displayed as shown below i.e BANKSet and                          HbankSet



For the bank set we used the CDS view with parameter i.e. Language, So add the                              parameter open ZCL_ZTX_BANK_DEMO1_DPC_EXT (Data Provider Extension class),                      Redefine the method.

Note: If you don’t  need any parameter kindly remove the parameter in the CDS view                            and activate it.

IF_SADL_GW_QUERY_CONTROL~SET_QUERY_OPTIONS

Add the below code for adding the parameters to the query.



 
DATA: lt_parameters TYPE if_sadl_public_types=>tt_entity_parameters,
ls_parameter LIKE LINE OF lt_parameters,
lt_para LIKE ls_parameter-parameters,
ls_para LIKE LINE OF lt_para.

DATA(lo_auth_provider) = cl_sadl_cond_prov_factory_pub=>create_for_authorization( ).
DATA(lv_target_set_name) = me->mr_request_details->*-target_entity_set.
IF me->mr_request_details->technical_request-navigation_path IS INITIAL.
CLEAR lv_target_set_name.
ENDIF.

CASE iv_entity_set.
WHEN 'BANKSet'.
lo_auth_provider->add_authorization_for_object(
EXPORTING
iv_authorization_object = 'F_BNKA_MAO'
it_activities = VALUE #( ( auth_field = 'ACTVT' value = '03' ) )
it_field_mapping = VALUE #( ( auth_field = 'BBANKS' view_field = 'BANKCOUNTRY' ) ) ).
ls_para-name = 'P_SPRAS'.
ls_para-value = sy-langu.
APPEND ls_para TO lt_para.

ls_parameter-entity_alias = iv_entity_set.
ls_parameter-parameters = lt_para.
APPEND ls_parameter TO lt_parameters.
io_query_options->set_entity_parameters( lt_parameters ).
WHEN OTHERS.
ENDCASE.

io_query_options->set_authority_provider( io_authority_provider = lo_auth_provider ).

 

If we are not adding the above code, then it will throw the below error i.e. Missing Parameter:



If you add the above code, we will get the http response with the data as shown below



Same way select the Hbank Entity set i.e Hbank cds view without Parameter so no need to redefine the set query options



 

Hope the Document is useful….
13 Comments