Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Gateway Services $Expand doesn't return nested(inline) data

$
0
0

Hi all

I build a REST Gateway Services through SEGW and I followed all the step in this tutorial:

 

just the read operations

Let’s code CRUDQ and Function Import operations in OData service!

 

and from this to build my association/navigation between my Entities

Let's code association/navigation and data provider expand in OData service!

 

so my entities are:

Imagen1.png

DocFi is a based on BKPF and POSFI is based on BSEG,

 

this the code I implemented in /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET

 

METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.   DATA: BEGIN OF ty_expand_fi.           INCLUDE TYPE zcl_zgw_fi_doc_mpc_ext=>ts_docfi.   DATA: posfi TYPE zcl_zgw_fi_doc_mpc_ext=>tt_posfi,         END OF ty_expand_fi.   DATA: lti_expand_fi LIKE STANDARD TABLE OF ty_expand_fi,         lwa_expand_fi LIKE LINE OF           lti_expand_fi,         lwa_posfi     TYPE                   zcl_zgw_fi_doc_mpc_ext=>ts_posfi.   DATA: lti_bkpf TYPE STANDARD TABLE OF bkpf,         lti_bseg TYPE STANDARD TABLE OF bseg,         lwa_bkpf TYPE                   bkpf,         lwa_bseg TYPE                   bseg.   CONSTANTS: lc_expand_tech_clause TYPE string VALUE 'POSFISET'.
 *consulta de datos de la bkpf   SELECT bukrs belnr gjahr blart bldat budat monat cpudt cputm          aedat upddt wwert usnam tcode bvorg xblnr dbblg stblg          FROM bkpf INTO CORRESPONDING FIELDS OF TABLE lti_bkpf UP TO 2 ROWS.
 *consulta de datos de la bseg   SELECT bukrs belnr gjahr buzei buzid augdt augcp augbl          bschl koart umskz umsks zumsk shkzg gsber pargb          mwskz qsskz dmbtr wrbtr kzbtr pswbt pswsl txbhw          txbfw mwsts wmwst hwbas fwbas hwzuz fwzuz shzuz          stekz mwart txgrp ktosl FROM bseg          INTO CORRESPONDING FIELDS OF TABLE lti_bseg          FOR ALL ENTRIES IN lti_bkpf           WHERE bukrs EQ lti_bkpf-bukrs           AND belnr EQ lti_bkpf-belnr           AND gjahr EQ lti_bkpf-gjahr.
 *se agregan las cab con las pos en la tabla de salida   LOOP AT lti_bkpf INTO lwa_bkpf.     MOVE-CORRESPONDING lwa_bkpf TO lwa_expand_fi.     LOOP AT lti_bseg INTO lwa_bseg WHERE belnr EQ lwa_bkpf-belnr.       MOVE-CORRESPONDING lwa_bseg TO lwa_posfi.       APPEND lwa_posfi TO lwa_expand_fi-posfi.       CLEAR lwa_posfi.     ENDLOOP.     APPEND lwa_expand_fi TO lti_expand_fi.     CLEAR lwa_expand_fi.   ENDLOOP.
 * se llena ER_ENTITYSET   CALL METHOD me->copy_data_to_ref     EXPORTING       is_data = lti_expand_fi     CHANGING       cr_data = er_entityset.
 * se inserta propiedad de navegacion "PosFISet" en la tabla ET_EXPANDED_TECH_CLAUSES   INSERT lc_expand_tech_clause INTO TABLE et_expanded_tech_clauses.
ENDMETHOD.

and this the code I implemented in /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY


METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entity.
 **TRY.
 *CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY
 **  EXPORTING
 **    iv_entity_name           =
 **    iv_entity_set_name       =
 **    iv_source_name           =
 **    it_key_tab               =
 **    it_navigation_path       =
 **    io_expand                =
 **    io_tech_request_context  =
 **  IMPORTING
 **    er_entity                =
 **    es_response_context      =
 **    et_expanded_clauses      =
 **    et_expanded_tech_clauses =
 *    .
 ** CATCH /iwbep/cx_mgw_busi_exception .
 ** CATCH /iwbep/cx_mgw_tech_exception .
 **ENDTRY.     DATA: BEGIN OF ty_expand_fi.             INCLUDE TYPE zcl_zgw_fi_doc_mpc_ext=>ts_docfi.     DATA: posfi TYPE zcl_zgw_fi_doc_mpc_ext=>tt_posfi,           END OF ty_expand_fi.
 *     DATA: lwa_expand_fi LIKE ty_expand_fi,           lwa_posfi     TYPE zcl_zgw_fi_doc_mpc_ext=>ts_posfi.     DATA: lst_key_tab   TYPE                   /iwbep/s_mgw_name_value_pair,           ldr_bukrs     TYPE                   bukrs,           ldr_belnr     TYPE                   belnr_d,           ldr_gjahr     TYPE                   gjahr,           ldr_entity_id TYPE                   /iwbep/med_entity_id,           lti_bseg      TYPE STANDARD TABLE OF bseg,           lwa_bkpf      TYPE                   bkpf,           lwa_bseg      TYPE                   bseg.     CONSTANTS: lc_expand_tech_clause TYPE string VALUE 'POSFISET'.     READ TABLE it_key_tab WITH KEY name = 'Bukrs' INTO lst_key_tab.     ldr_bukrs = lst_key_tab-value.     CLEAR lst_key_tab.     READ TABLE it_key_tab WITH KEY name = 'Belnr' INTO lst_key_tab.     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'       EXPORTING         input  = lst_key_tab-value       IMPORTING         output = ldr_belnr.     CLEAR lst_key_tab.     READ TABLE it_key_tab WITH KEY name = 'Gjahr' INTO lst_key_tab.     ldr_gjahr = lst_key_tab-value.     CLEAR lst_key_tab.
 *consulta de datos de la bkpf     SELECT SINGLE bukrs belnr gjahr blart bldat budat monat cpudt cputm            aedat upddt wwert usnam tcode bvorg xblnr dbblg stblg         FROM bkpf INTO CORRESPONDING FIELDS OF lwa_bkpf           WHERE bukrs EQ ldr_bukrs             AND belnr EQ ldr_belnr             AND gjahr EQ ldr_gjahr.
 *consulta de datos de la bseg     SELECT bukrs belnr gjahr buzei buzid augdt augcp augbl            bschl koart umskz umsks zumsk shkzg gsber pargb            mwskz qsskz dmbtr wrbtr kzbtr pswbt pswsl txbhw            txbfw mwsts wmwst hwbas fwbas hwzuz fwzuz shzuz            stekz mwart txgrp ktosl FROM bseg            INTO CORRESPONDING FIELDS OF TABLE lti_bseg             WHERE bukrs EQ lwa_bkpf-bukrs             AND belnr EQ lwa_bkpf-belnr             AND gjahr EQ lwa_bkpf-gjahr.     IF lwa_bkpf IS INITIAL.       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'         EXPORTING           input  = ldr_belnr         IMPORTING           output = ldr_belnr.       CONCATENATE 'Soc.' ldr_bukrs 'Doc.' ldr_belnr 'Año' ldr_gjahr INTO ldr_entity_id SEPARATED BY space.       RAISE EXCEPTION TYPE /iwbep/cx_mgw_med_exception         EXPORTING           textid      = /iwbep/cx_mgw_med_exception=>entity_id_not_found           method      = 'DOCFISET_GET_ENTITY'           entity_type = 'DocFI'           entity_id   = ldr_entity_id           username    = sy-uname.     ELSE.       MOVE-CORRESPONDING lwa_bkpf TO lwa_expand_fi.       LOOP AT lti_bseg INTO lwa_bseg.         MOVE-CORRESPONDING lwa_bseg TO lwa_posfi.         APPEND lwa_posfi TO lwa_expand_fi-posfi.         CLEAR lwa_posfi.       ENDLOOP.
 * se llena ER_ENTITY       CALL METHOD me->copy_data_to_ref         EXPORTING           is_data = lwa_expand_fi         CHANGING           cr_data = er_entity.
 * se inserta propiedad de navegacion "PosFISet" en la tabla ET_EXPANDED_TECH_CLAUSES       INSERT lc_expand_tech_clause INTO TABLE et_expanded_tech_clauses.     ENDIF.
ENDMETHOD.


and when a I do a request with the $expand returns header data but doesn't return items.... this is the response

 

Imagen2.png

 

{  "d" : {    "__metadata" : {      "id" : "http://myserver:8000/sap/opu/odata/sap/ZGW_FI_DOC_SRV/DocFISet(Bukrs='XXX',Belnr='XX',Gjahr='2015')",      "uri" : "http://myserver:8000/sap/opu/odata/sap/ZGW_FI_DOC_SRV/DocFISet(Bukrs='XXX',Belnr='XX',Gjahr='2015')",      "type" : "ZGW_FI_DOC_SRV.DocFI"    },    "Bukrs" : "XXX",    "Belnr" : "XX",    "Gjahr" : "2015",    "Blart" : "KR",    "Bldat" : "20150624",    "Budat" : "20150624",    "Monat" : "06",    "Cpudt" : "20150624",    "Cputm" : "155121",    "Aedat" : "00000000",    "Upddt" : "00000000",    "Wwert" : "20150624",    "Usnam" : "YYY",    "Tcode" : "FB60",    "Bvorg" : "",    "Xblnr" : "",    "Dbblg" : "",    "Stblg" : "0000840003",    "PosFISet" : {      "results" : [      ]    }
}

as you can see I get the header data but in the "PosFISet" the result came empty, I already check that the internal table had the bseg data, and searching on SCN I found this notes



but the Basis team said those notes can't be implemented because the system have a superior Support pacakage, any help would be appreciate and I don't know what else to do .


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>