You are on page 1of 5

Today's Class:

____________________________________
Fetching data based on SEARCH string :
________________________________________
For eXample :
search=VIJAYENDAR

, here fetch data based on search string VIJAYENDAR

search=REDDY , here fetch data based on search string REDDY


_________________________________________________________________
NOTE : Use

_GET_ENTITYSET method

data searchstring TYPE STRING.


searchstring

= IO_TECH_REQUEST_CONTEXT->get_Search_String( ).

NOTE : get_search_String( ) is a standard method to capture the Search string V


Alue
using IO_TECH_REQUEST_CONTEXT
_______________________________________________________________
GET_ENTTITYSET by passing search string INPUT
________________________________________________________________
STEPS :
IN SEGW , create ZDBPROJECT.
save
Right click DATA MODEL, Insert DDIC structure,
provide ENTITY NAME = USER
DDIC structure = ZUSERINFO
chose Create default ENTITYSET
chose USERID field as KEY field
and continue and save
click on "GENERATE RUNTIME OBJECTS"
open DATA PRovider EXTENSION CLASS
chose change,
select GET_ENTITYSET

method and click on "REDEFINE"

--------------------------------------

Implement the below code :


data lt_user
TYPE ZCL_ZDBPROJECT4_MPC=>TT_USER.
data searchstring TYPE STRING.
searchstring =

IO_TECH_REQUEST_CONTEXT->GET_SEARCH_STRING( ).

select * from zuserinfo into


corresponding fields of table lt_user
where FIRSTNAME = searchstring.
ET_ENTITYSET =
lt_user.
___________________________________________________________________
activate the Class:
and REGISTER the service
and MAINTAIN the service
goto GATEWAY CLIENT
Provide
/sap/opu/odata/sap/ZDBPROJECT4_SRV/USERSet?search=VIJAYENDAR
------- ----- ----entityset Keyword value
and execute :
note : IN the this scenario, GET_ENTITYSET method is executed.
_____________________________________________________________________
Fetching the data based on Conditions by generating NEW COLUMNS at Gateway servi
ce level:
________________________________________________________________________________
_______
Requirement :
if Salary
STATUS

< 12000.
=

'FRESHER'.

elseif SALARY >= 12000 and Salary <= 30000.


STATUS

= 'AVERAGE'.

elseif sALARY
STATUS

> 30000.

= 'GOOD'.

endif.
If country = 'INDIA'.

currency

= 'INDIAN RUPEE'.

elseif country = 'US'.


currency

= 'US DOLLAR'.

endif.
________________________________________________
Note : STATUS , CURRENCY is not physically available in the data base
so, STATUS , CURRENCY can be generated virtually at SERVICE LEVEL
____________________________________________________________________________
NOTE :
rties

INside ENTITY TYPE, based on requirement, we can add new fields/prope

but we need to "remove the ABAP DDIC STRUCTURE"


-----------------------------________________________________________________________________________________
______
STEPS :
IN SEGW , create ZDBPROJECT.
save
Right click DATA MODEL, Insert DDIC structure,
provide ENTITY NAME = USER
DDIC structure = ZUSERINFO
chose Create default ENTITYSET
chose USERID field as KEY field
and continue and save
goto entity set properties , and ADD NEW Fields
STATUS =====Edm.STRING
CURRENCY====Edm.STRING

with 12
with 12

save
goto properties section of ENTITY TYPE
and remove "DDIC ABAP STRUCTURE"
----------------------------save
click on "GENERATE RUNTIME OBJECTS"
open DATA PRovider EXTENSION CLASS
chose change,
select GET_ENTITYSET

method and click on "REDEFINE"

and implement the below code:


-------------------------------------------------------data lt_itab TYPE ZCL_ZDBPROJECT55_MPC=>TT_USER.
data lt_itab2 TYPE ZCL_ZDBPROJECT55_MPC=>TT_USER.
data ls_itab TYPE ZCL_ZDBPROJECT55_MPC=>TS_USER.
select * from ZUSERINFO into
corresponding fields of table

lt_itab.

Loop at lt_itab into ls_itab.


if ls_itab-SALARY < 12000.
ls_itab-STATUS = 'FRESHER'.
elseif

ls_itab-SALARY

>= 12000 and ls_itab-SALARY

<= 30000.

ls_itab-STATUS = 'AVERAGE'.
elseif ls_itab-SALARY > 30000.
ls_itab-STATUS

= 'GOOD'.

endif.
if ls_itab-COUNTRY = 'INDIA'.
ls_itab-CURRENCY = 'INDIAN RUPEE'.
elseif ls_itab-COUNTRY = 'US'.
ls_itab-CURRENCY = 'US DOLLAR'.
endif.
append ls_itab to lt_itab2.
endloop.
ET_ENTITYSET = lt_itab2.
________________________________________________
activate the class, and
REgister the service
MAintain the service
and goto GATEWAY client.
and provide
/sap/opu/odata/SAP/ZDBPROJECT55_SRV/USERSet
and execute.
__________________________________________________________________________
Note :

Observe the new columns and its values

for "STATUS" column and "CURRENCY" Column


__________________________________________________________________________

You might also like