今天学习表的联合查询,
ODATA学习(SAP Press – OData and SAP NetWeaver Gateway)第6.5.4章节,第281页
本来是想用实现http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1001′)/ZTSALE_I这样的URL,然后查询出此销售订单的明细,当然,明细应该是会有多行的,
可文档中说的好像是调用的Get_Entity方法,而实际上确认也是调用 的是Get_Entity方法,而调用此方法时,返回的结果集,只能是一行了,所以最终没实现想我的效果,
可后面才发现,在地址中的最后不是输入明细表的Entity名字,而要输入主表中的Navigation properties的名字,所以地址应该为:
http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1001′)/ZTSALE_ISet
———————————————————————————————————————————————————————
先把实现的步骤记录如下:
一、在SEGW项目中,在Associations上点右键,选择创建,输入入名字,表关联名字,如图
二、…在此略去大于100字。
三、创建完成后,应该是要重新生成对应的;
四,记得在明细表的GET_ENTITYSET方法中写入取数据程序;
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
method ZTSALE_ISET_GET_ENTITYSET. DATA:GT_DATA TYPE STANDARD TABLE OF ZTSALE_I. FIELD-SYMBOLS:<GS_DATA> TYPE ZTSALE_I. DATA: LS_ENTITYSET LIKE LINE OF ET_ENTITYSET. DATA: LS_FILTER_SELECT_OPTIONS TYPE /IWBEP/S_MGW_SELECT_OPTION , LS_SELECT_OPTION TYPE /IWBEP/S_COD_SELECT_OPTION . DATA: LI_MAXROW TYPE INT4, LV_START TYPE INT4, LV_END TYPE INT4. DATA: II_GJAHR TYPE EVAL_IV_GJAHR_RANGE_T, LS_GJAHR TYPE LINE OF EVAL_IV_GJAHR_RANGE_T, II_ZSALEID TYPE ZRANGE_SALEID_T, LS_ZSALEID TYPE LINE OF ZRANGE_SALEID_T. DATA: LS_FIELD TYPE FIELD. BREAK YANGSEN. LOOP AT IT_FILTER_SELECT_OPTIONS INTO LS_FILTER_SELECT_OPTIONS . LS_FIELD = LS_FILTER_SELECT_OPTIONS-PROPERTY. TRANSLATE LS_FIELD TO UPPER CASE. IF LS_FIELD EQ 'GJAHR'. LOOP AT LS_FILTER_SELECT_OPTIONS-SELECT_OPTIONS INTO LS_SELECT_OPTION . MOVE-CORRESPONDING LS_SELECT_OPTION TO LS_GJAHR. APPEND LS_GJAHR TO II_GJAHR . ENDLOOP . ELSEIF LS_FIELD EQ 'ZSALEID '. LOOP AT LS_FILTER_SELECT_OPTIONS-SELECT_OPTIONS INTO LS_SELECT_OPTION . MOVE-CORRESPONDING LS_SELECT_OPTION TO LS_ZSALEID. APPEND LS_ZSALEID TO II_ZSALEID . ENDLOOP . ENDIF. ENDLOOP. LI_MAXROW = 0 . IF ( IS_PAGING-TOP IS NOT INITIAL ) AND ( IO_TECH_REQUEST_CONTEXT->HAS_INLINECOUNT( ) EQ ABAP_FALSE ) . LI_MAXROW = IS_PAGING-TOP + IS_PAGING-SKIP . ENDIF. SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_DATA FROM ZTSALE_I UP TO LI_MAXROW ROWS WHERE GJAHR IN II_GJAHR AND ZSALEID IN II_ZSALEID . LV_START = 1. IF IS_PAGING-SKIP IS NOT INITIAL. LV_START = IS_PAGING-SKIP + 1. ENDIF . IF IS_PAGING-TOP IS NOT INITIAL . LV_END = IS_PAGING-TOP + LV_START - 1. ELSE . LV_END = LINES( GT_DATA ) . ENDIF. LOOP AT GT_DATA ASSIGNING <GS_DATA> FROM LV_START TO LV_END. MOVE-CORRESPONDING <GS_DATA> TO LS_ENTITYSET. APPEND LS_ENTITYSET TO ET_ENTITYSET. ENDLOOP. IF IO_TECH_REQUEST_CONTEXT->HAS_INLINECOUNT( ) EQ ABAP_TRUE . ES_RESPONSE_CONTEXT-INLINECOUNT = LINES( GT_DATA ) . ENDIF. DATA: ZCL_ODATA_PUBLIC TYPE REF TO ZODATA_PUBLIC. IF IT_ORDER IS NOT INITIAL. CREATE OBJECT ZCL_ODATA_PUBLIC. CALL METHOD ZCL_ODATA_PUBLIC->ORDERBY EXPORTING ET_ORDER = IT_ORDER CHANGING IT_DATA = ET_ENTITYSET . ENDIF. endmethod. |
五、运行地址:http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H
发现在返回的XML中增加了如下:
<link href=”ZTSALE_H(Gjahr=’2016′,Zsaleid=’1001′)/ZTSALE_ISet” rel=”http://schemas.microsoft.com/ado/2007/08/dataservices/related/ZTSALE_ISet” type=”application/atom+xml;type=feed”title=”ZTSALE_ISet”/>
六、最后运行地址:http://bwnep:8917/sap/opu/odata/sap/ZSALE_SRV/ZTSALE_H(Gjahr=’2016′,Zsaleid=’1001′)/ZTSALE_ISet
确发现在返回了明细表的所有行内容,DEBUG发现在调用GET_ENTITYSET方法时,IT_FILTER_SELECT_OPTIONS传的查询参数是空的,所以相当于没有查询条件,这里明天再看一下要如何处理。
破网络,限制发不出图片,将就着看吧,