在此贴先介绍the single read ( get_entity )。
前面章节介绍了,简单ODATA的开发,但在ODATA的使用中,还有很多ODATA的参数的使用,
此介绍介绍ODATA的查询
更详细学习请参看:SAP Press – OData and SAP NetWeaver Gateway
ODATA学习(SAP Press – OData and SAP NetWeaver Gateway)第6.5.2章节,第269页
That’s why the single read ( get_entity ) is typi-
cally implemented after the get_entityset .
Sim il ar to the QU E RY method, you can easily develop the single read via
the ABAP Class Builde r. Th is time, expand the SERVICE IMPLEMENTATION •
PRODUCT(OLLECTION node, right-click on GETENTITY (READ), and choose
GoTo ABAP WORKBENCH. An information pop-up screen appears
because the method hasn’t yet been implemen te d.
————————————————————————————————————
在上一节中,我们学习了简单ODATA开发时,在重定义了类的get_entityset方法,并取出数据,
但在使用ODATA时,有时我们会使用如 /sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1002′).的查询方式 ,这里就需要对get_entity方法进行重定义了,
写入方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
method ZTSALE_HSET_GET_ENTITY. DATA:gt_data TYPE STANDARD TABLE OF ZTSALE_H. FIELD-SYMBOLS:<gs_data> TYPE ZTSALE_H. DATA: LS_KEY_TAB TYPE LINE OF /IWBEP/T_MGW_NAME_VALUE_PAIR. DATA: LS_GJAHR TYPE GJAHR, LS_ZSALEID TYPE ZSALEID. LOOP AT IT_KEY_TAB INTO LS_KEY_TAB. IF LS_KEY_TAB-NAME = 'Gjahr'. LS_GJAHR = LS_KEY_TAB-VALUE. ELSEIF LS_KEY_TAB-NAME = 'Zsaleid '. LS_ZSALEID = LS_KEY_TAB-VALUE. ENDIF. ENDLOOP . SELECT SINGLE * INTO CORRESPONDING FIELDS OF ER_ENTITY FROM ZTSALE_H WHERE GJAHR = LS_GJAHR AND ZSALEID = LS_ZSALEID . endmethod. |
这里就可以使用/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1002′).的查询方式查询出数据了。
更详细学习ODATA请参看:SAP Press – OData and SAP NetWeaver Gateway
后面将说明Query Options更多的查询选项$select , $filter , Hop , $skip , $in li necou nt , and $orderby。