Sap Gateway Beginers
Sap Gateway Beginers
In three-tier architecture, SAP Gateways make up the middle or application tier. This middle layer is
essential for communication between the frontend and the backend. The use of multi-tier architecture to
implement a data processing system adds a valuable level of modularity and flexibility to the system by
being able to develop and maintain each tier individually. The purpose of this tutorial is to create a
Gateway that will extract data from the flight carrier database table, which will be accessed from the
Gateway Client. The Gateway will be able to retrieve a list of carriers as well as individual carriers. Lets
get started
First, navigate to the Gateway Service Builder with the T-Code SEGW
Click the Create Project button
Type SCARR for ABAP Structure and press enter. A list of properties should appear
Make Carrier the object name for the entity
Change the Usage of the property MANDT to Ignore and click the check mark at the bottom right
The naming convention is to either make the Entity Set name the plural form of the name of the entity or
append _Set to the Entity name. For training purposes, name the entity set Carriers or Carrier_Set.
Carriers will be used for the remainder of this tutorial
Use the Entity name, Carrier, for Entity Type Name. Make sure to save and the Entity and corresponding
Entity Set have successfully created
Click on the Generate Runtime Objects button towards the top left of the IDE
How to Activate Gateway Service
Navigate to the Activate and Maintain Services page, /iwfnd/maint_service, and click Add Service
Set System Alias to LOCAL and Technical Service Name to the name of the Gateway
To test the service, verify the HTTP Method is set to GET and then click Execute. There should now be
some auto-generated XML
In order to view the entity and its properties add a URI option to the end of the URI. Click Add URI Option
and use $metadata and sap-ds-debug=true
Now we can see the Entity Type as well as its properties
Congratulations! You have made a usable Gateway Service. Now the backend functionality
of the Gateway must be coded in order to make it useful.
Implementing GetEntitySet
Navigate back to the gateway service builder, expand the Service Implementation folder, and expand the
entity set. There will be a few auto-generated methods
Right click GetEntitySet, click Go to ABAP Workbench, and ignore the popup that follows. This will take
bring up the Class Builder
In the left menu, expand the Methods folder, right click on the GET_ENTITYSET method, and select
Redefine
Under Signature, what the method is exporting to the frontend service can be seen, ET_ENTITYSET. This
exporting table needs to be populated with data from the backend database
It is generally bad practice to select all the records from a database table because it can be extremely inefficient
and redundant so instead of using SELECT *, only select the first 100 records from the database using the
following statement
SELECT * FROM scarr INTO CORRESPONDING FIELDS OF TABLE et_entityset UP TO 100 ROWS.
Testing GetEntitySet
Reenter the Activate and Maintain Services or if it is already in a window click Refresh Catalog
Open the service again using the Gateway Client
Append the name of the Entity Set to the end of the URI, verify HTTP Method is set to GET, and execute.
There should now be multiple Carrier entries
Implementing GetEntity
The above code will select a Carrier using the Carrid that will be passed into the URI
Activate this method and open the Gateway Client one more time
Make sure HTTP Method is GET, type /sap/opu/odata/sap/Z_GATEWAY_DEMO_SRV/Carriers(AF)
for the URI, and press execute
There should now be an individual Carrier using the Carrid that was just passed in the URI
2]
In this first part of tutorial, I am going to show how to prepare a data model using SEGW transaction. If you
got stuck, you can try to look at this official document that describes the process in more details.
1. You need to prepare a database table that will be used for storing data. Below you can see the specific
database table which is used in this example.
2. You need to run the transaction (t-code) SEGW and create your first project.
3. Click on Data Model > Import from DDIC structure. Follow all the steps using your created database
table. At the end you should be able to see following table. Then select relevant keys and finish this process.
4. Creatable, updatable, deletable and addressable parameters need to be checked for your entity.
5. Now, you need to generate a runtime object. Select a property panel on your project by right click and
choose Generate runtime action.
6. In Service implementation > UserSet > GetEntitySet click by right and choose Go to ABAP Workbench.
7. The main goal now is to redefine relevant methods in USERS_DPC_EXT class. See content of redefined
methods below.
1 METHOD userset_create_entity.
7 er_entity = ls_user.
8 ENDMETHOD.
1 METHOD userset_get_entity.
2 DATA: lt_keys TYPE /iwbep/t_mgw_tech_pairs,
7 lt_keys = io_tech_request_context->get_keys( ).
9 lv_email = ls_key-value.
10
11 SELECT SINGLE * FROM zsa_users INTO CORRESPONDING FIELDS OF ls_user WHERE email = lv_email.
12
13 er_entity = ls_user.
14 ENDMETHOD.
1 METHOD userset_get_entityset.
5 et_entityset = lt_users.
6 ENDMETHOD.
1 METHOD userset_update_entity.
6 firstname = ls_user-firstname
7 lastname = ls_user-lastname
8 age = ls_user-age
9 address = ls_user-address
11
12 er_entity = ls_user.
13 ENDMETHOD.
1 METHOD userset_delete_entity.
6 lt_keys = io_tech_request_context->get_keys( ).
8 lv_email = ls_key-value.
11 ENDMETHOD.
There is a gateway client which can be used for testing running services. Just run transaction(t-
code) /IWFND/GW_CLIENT and you can find out, if your service runs correctly.
Your oData service is running, now you can start to consume your data!
3]
step1) Open TCode SEGW and create a project as shown in below screen shot.
Provide the following details
Same way create entity type PR_Item for the item also and give the following values
step 6.After completion of data model in Odata service in Service Implementation is filled automatically as shown in
below screen shot.
step 7.Now we need to generate runtime artifacts ,for that you need to select Runtime Artifacts and click on
step 9 A.Then we need to right click on the methods and redefine required methods in following process.
method PRHEADERCOLLECTI_GET_ENTITY.
ER_ENTITY-prnumber = LS_KEY_TAB-VALUE.
* lv_pR_item = ls_key_tab-value.
**TRY.
*CALL METHOD SUPER->PRHEADERCOLLECTI_GET_ENTITY
* EXPORTING
* IV_ENTITY_NAME =
* IV_ENTITY_SET_NAME =
* IV_SOURCE_NAME =
* IT_KEY_TAB =
** io_request_object =
** io_tech_request_context =
* IT_NAVIGATION_PATH =
** IMPORTING
** er_entity =
** es_response_context =
* .
** CATCH /iwbep/cx_mgw_busi_exception .
** CATCH /iwbep/cx_mgw_tech_exception .
**ENDTRY.
endmethod.
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY.
**TRY.
*CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY
* EXPORTING
** iv_entity_name =
** iv_entity_set_name =
** iv_source_name =
* IO_DATA_PROVIDER =
** it_key_tab =
** it_navigation_path =
* IO_EXPAND =
** io_tech_request_context =
** IMPORTING
** er_deep_entity =
* .
** CATCH /iwbep/cx_mgw_busi_exception .
** CATCH /iwbep/cx_mgw_tech_exception .
**ENDTRY.
ls_bapi_item-material = ls_item-material.
ls_bapi_item-plant = ls_item-plant.
ls_bapi_item-quantity = ls_item-quantity.
ls_bapi_item-doc_type = ls_item-DocumentType.
ls_bapi_item-DELIv_DATE = ls_item-DeliveryDate.
ls_bapi_item-PUR_GROUP = ls_item-PURGROUP.
ls_bapi_item-PREQ_ITEM = ls_item-PRITEM.
ls_bapi_item-SHORT_TEXT = ls_item-SHORTTEXT.
ls_bapi_item-MAT_GRP = ls_item-MATERIALGROUP.
ls_bapi_item-UNIT = ls_item-UNIT.
ls_bapi_item-ITEM_CAT = ls_item-ITEMCATEGORY.
ls_bapi_item-ACCTASSCAT = ls_item-ACCTASSIGNCATEGORY.
ls_bapi_item-PREQ_NO = ls_item-PRNUMBER.
* ls_itemx-po_item = ls_item-item.
APPEND ls_bapi_item TO lt_bapi_item.
* APPEND ls_itemx TO lt_itemx.
CLEAR ls_item.
ENDLOOP.
copy_data_to_ref(
EXPORTING
is_data = ls_pritems
CHANGING
cr_data = er_deep_entity ).
endmethod.
step10: Now Service Maintenance is automatically created but we need to register the service. So select the system i.e.
EC7 and click on register.
Give the system Alias LOCAL_GW and click OK. Then Maintain The register
step 11.Test the service
/sap/opu/odata/SAP/Z_PURCHASE_REQUISITION_TEST_SRV/PRHeaderCollection() in
gateway client and click on post
Purchase Requisition is created 0010017270 as shown in below screen shot.
Check in Table level entries in EBAN we can find the Purchase Requisition '0010017270'
4]
Implementing Expand Entity/Entity Set
Posted by Srikanth Gajula in SAP Gateway on Jul 18, 2014 7:21:30 AM
inShare1
Hi Folks,
Finally got some time to write a Blog on something which was a common question from a lot of audience here, so doing my bit
of help here .. hope this helps a lot of beginners and not for experts
https://help.sap.com/saphelp_gateway20sp08/helpdata/en/ca/c683e803494b77a2e1290b987556e2/content.htm
Some of the Blogs already posted in SCN relevant to Expand and Deep Entity .
Requirement
Considering a basic scenario where i am using BAPI_PO_GETDETAIL which has multiple output tables and input is PO number
Create Association
Create Navigation
Navigation-1 - NavItem
Navigation-2 - NavSchedule
Lets generate runtime artifacts. Click on generate runtime objects button. It will display
popup . Keep the default class names as-is and click on enter button.
Once generation is successful, you will get 4 classes. 2 for Data provider and 2 for Model provider.
Code Snippet
METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.
*-------------------------------------------------------------------------*
* Deep Structure
*-------------------------------------------------------------------------*
DATA: BEGIN OF ls_order_items.
INCLUDE TYPE zcl_zproj_982_mpc=>ts_header.
DATA: navitem TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_item WITH DEFAULT KEY.
DATA: navschedule TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_schedule WITH DEFAULT KEY,
END OF ls_order_items,
ls_item1 TYPE zcl_zproj_982_mpc=>ts_item,
ls_schedle1 TYPE zcl_zproj_982_mpc=>ts_schedule.
*-------------------------------------------------------------------------*
* Data Declarations
*-------------------------------------------------------------------------*
DATA : ls_item TYPE zcl_zproj_982_mpc_ext=>ts_item,
lt_item TYPE TABLE OF zcl_zproj_982_mpc_ext=>ts_item,
ls_sch TYPE zcl_zproj_982_mpc_ext=>ts_schedule,
lt_sch TYPE TABLE OF zcl_zproj_982_mpc_ext=>ts_schedule,
ls_header TYPE zcl_zproj_982_mpc_ext=>ty_header,
lthead TYPE STANDARD TABLE OF bapiekkol,
lshead TYPE bapiekkol,
lsitem TYPE bapiekpo,
ltitem TYPE STANDARD TABLE OF bapiekpo,
lv_filter_str TYPE string,
lt_filter_select_options TYPE /iwbep/t_mgw_select_option,
ls_filter TYPE /iwbep/s_mgw_select_option,
ls_filter_range TYPE /iwbep/s_cod_select_option,
ls_expanded_clause1 LIKE LINE OF et_expanded_tech_clauses,
ls_expanded_clause2 LIKE LINE OF et_expanded_tech_clauses,
lv_ebeln TYPE ebeln,
lt_order_items LIKE TABLE OF ls_order_items,
ltsch TYPE STANDARD TABLE OF bapieket,
lssch TYPE bapieket.
*-------------------------------------------------------------------------*
* Entity Set - HeaderSet
*-------------------------------------------------------------------------*
CASE iv_entity_set_name.
WHEN 'HeaderSet'.
LOOP AT it_filter_select_options INTO ls_filter.
ENDLOOP.
*-------------------------------------------------------------------------*
* Call Method-BAPI_PO_GETDETAIL
*-------------------------------------------------------------------------*
ls_item1-poitem = lsitem-po_item.
ls_item1-material = lsitem-material.
APPEND ls_item1 TO ls_order_items-navitem.
ENDLOOP.
*-------------------------------------------------------------------------*
* Fill Schedule values to Deep Strcture
*-------------------------------------------------------------------------*
LOOP AT ltsch INTO lssch.
CLEAR ls_item1.
* ls_item1-ponumber = lsitem-po_number.
ls_schedle1-poitem = lssch-po_item.
ls_schedle1-serial = lssch-serial_no.
APPEND ls_schedle1 TO ls_order_items-navschedule.
ENDLOOP.
*-------------------------------------------------------------------------*
* Assign the Navigation Proprties name to Expanded Tech clauses
*-------------------------------------------------------------------------*
ls_expanded_clause1 = 'NAVITEM'.
ls_expanded_clause2 = 'NAVSCHEDULE'.
APPEND ls_expanded_clause1 TO et_expanded_tech_clauses.
APPEND ls_expanded_clause2 TO et_expanded_tech_clauses.
*-------------------------------------------------------------------------*
* Append Deep Strcture Values to Final Internal Table
*-------------------------------------------------------------------------*
APPEND ls_order_items TO lt_order_items.
*-------------------------------------------------------------------------*
* Send back Response to Consumer
*-------------------------------------------------------------------------*
copy_data_to_ref(
EXPORTING
is_data = lt_order_items
CHANGING
cr_data = er_entityset ).
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
Test Case 1:
Test Case 2:
*-------------------------------------------------------------------------*
* Deep Structure
*-------------------------------------------------------------------------*
DATA: BEGIN OF ls_order_items.
INCLUDE TYPE zcl_zproj_982_mpc=>ts_header.
DATA: navitem TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_item WITH DEFAULT KEY.
DATA: navschedule TYPE STANDARD TABLE OF zcl_zproj_982_mpc=>ts_schedule WITH DEFAULT KEY,
END OF ls_order_items,
ls_item1 TYPE zcl_zproj_982_mpc=>ts_item,
ls_schedle1 TYPE zcl_zproj_982_mpc=>ts_schedule.
copy_data_to_ref(
EXPORTING
is_data = ls_order_items
CHANGING
cr_data = er_entity ).
5]
Detailed step by step procedure for Creating Gateway
Service with all the CRUD Operations and testing them in
Service Explorer Part1
Posted by Nagesh A in SAP NetWeaver Gateway Developer Center on Dec 22, 2013 12:15:49 PM
inShare4
In this blog I will explain Creating Gateway service with all CRUD operations Before starting, I am expecting that you have
basic idea of gateway service and gateway service builder i.e SEGW
1. Create service in Gateway system with all the CRUD operations.(Create Read Update Delete)
Give the Entity type name, RFC destination and name of the RFC to be imported and click on next
Give appropriate Entity set name and select the necessary Entity type then click on continue.
CREATE: This is to create a new entry. Right click on create and choose Map to data source option.
Give the RFC destination name and select required RFC then click on ok.
Now click on propose mapping, the system will do mapping automatically or else we can do it manually for required fields. Here
no need to map all the properties of the entity type; we will map only the required properties. We will do the mapping by drag
drop from Function Module onto data source parameter of the Service operation.
Here all the required fields will have input mapping as below.
Here in our case we need to pass constant values for BASE_UOM, MATL_GROUP and BASIC_VIEW, we will do that as
follows. First append the rows and maintain values under constant value tab.
Once mapping is done save your changes. Now we will implement DELETE operation.
DELETE: Right click on Delete and choose Map to data source option.
Give the RFC destination name and select required RFC then click on ok. Here we are mapping
withBAPI_MATERIAL_SAVEDATA.
Do the required mapping as follows. Here we are passing Material, DelFlag, MatlGroup fields so do the mapping accordingly.
READ: Right click on Read and choose Map to data source option.
Give the required RFC and do the mapping as below. Here we are mapping Material, MatlDesc,
IndSector,
MatlType, MatlGroup, BaseUom fields. Except Material all are having output mapping.
Note: In READ operation all key fields should have input mapping, here in our example Material is key.
QUERY: Right click on Query and choose Map to data source option.
Note: In Query operation all key fields should have output mapping. Here we can also map ranges directly to pass range value for
selection.
Give the required RFC and do the mapping as below. Here we are mapping with BAPI_MATERIAL_GETLIST
Here we will map MatlDesc property with appropriate Function field and our key property Material with range table, for that
just drag drop that filed on to the data source field. Click on ok in the below screen.
Give the required RFC, Here we are mapping with BAPI_MATERIAL_SAVEDATA.Do the required mapping as follows. Here
we are going to update MatlGroup Field.
After completing all the implementations save the changes and check for syntax errors.
With this we have successfully created a gateway service with implementing all CRUD operations.
Detailed step by step procedure for Creating Gateway
Service with all the CRUD Operations and testing them in
Service Explorer Part2
Posted by Nagesh A in SAP NetWeaver Gateway Developer Center on Dec 22, 2013 12:16:30 PM
inShare8
In the first part Detailed step by step procedure for Creating Gateway Service with all the CRUD Operations and testing them in
Service Explorer Part1
I discussed the the below topic.
1.Create service in Gateway system with all the CRUD operations.(Create Read Update Delete).
Before starting, I am expecting that you are able to create gateway service or you have gone through my previous blog.In this
blog i will discuss about maintaining our service and testing it in ServiceExplorer.
Enter system alias and press enter. From the displayed list locate our service and click o it.
Save it in a package and click on Ok.
Select the request and click on Ok. Again click on ok. Come back and click on our service.
b. Now we need to add System alias to our service, i.e. systems with which we are going to interact.
Click on Create System alias button and enter the required system details and save the changes and
come back.
Save the changes in the request.
Now we can see our system alias details.
Now we will explore our service for that click on Explore service button.
Click on Execute to get Service Document .
Service Document: Describes the location and capabilities of one or more Collections.
Here we can check our Entity set name and we will get our Service URI.
Now we will test our service in Gateway Client transaction for that is /IWFND/GW_CLIENT.
Paste our URI in Request URI field and click on Get HTTP Method.
READ:
Here in URI we can pass values for key fields only.
In our example we are trying to READ Material 000000000000000023 and we will do that in Gateway client.
Paste this URI against Request URI field in Gateway client and select HTTP Method GET and click on execute.
Output:
QUERY:
Query is to get multiple entries and here we can pass ranges for selection.
In our example we will try to fetch Materials within the range 000000000000000023 to 000000000000000038.
URI:
http:// <hostname>:<port>/sap/opu/odata/sap/ZBPS_MATR_DEMO_SRV/matrset?$filter=Material ge '000000000000000023'
and Material le '000000000000000053'
Paste this URI @ Request URI in Gateway client and select HTTP Method GET and click on execute.
CREATE:
Now we will try to create Material 000000000000000016. For this first we will READ an existing material and using that XML
we will CREATE desired material.
First try to READ Material 000000000000000023 by using the URI same as in our READ operation in Gateway client.
URI:
http:// <hostname>:<port>/sap/opu/odata/sap/ZBPS_MATR_DEMO_SRV/matrset
OUTPUT:
UPDATE: Now we will try to UPDATE the Material just we have created through CREATE operation.
Do the same steps as in create operation, first read the Material 000000000000000016 through READ operation and by using
that xml as a Request we will try to UPDATE Material Group of that Material.
Here MatlGroup is 00108, we will update that to 00107 and we will verify it through READ operation.
Click on Use as Request and make the necessary changes to the XML as below and select the HTTP Method PUT for Updating
and click on execute.
Xml:
OUTPUT:
Now we will check that whether that Material is updated or not by using READ operation. Select the HTTP Method GET and
check the output.
DELETE:
Now we will try to DELETE the Material which we have created, for this we use HTTP method DELETE.
Here to delete the Material we will just set the Delete Flag to X. First we will read that material and using that xml as a request
we will process Delete operation. Here we will select HTTP method DELETE and execute it after modifying xml.
XML:
<?xml version="1.0" encoding="utf-8"?>
<entry
xml:base="http:// <hostname>:<port>/sap/opu/odata/sap/ZBPS_MATR_DEMO_SRV/"xmlns="http://www.w3
.org/2005/Atom"xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:d="http://s
chemas.microsoft.com/ado/2007/08/dataservices">
<content type="application/xml">
<m:properties>
<d:MatlGroup>00107</d:MatlGroup>
<d:Material>000000000000000019</d:Material>
<d:DelFlag>X</d:DelFlag>
</m:properties>
</content>
</entry>
OUTPUT: