on 08-04-2015 3:04 PM
Hi All,
I am developing a Odata to fetch Vendor invoices based on the BAPIS:
BAPI_INCOMINGINVOICE_GETLIST
BAPI_INCOMINGINVOICE_GETDETAIL
So in the Odata I created one entity type for Invoice list, and get the list of invoices based on BAPI: BAPI_INCOMINGINVOICE_GETLIST, however when displaying the item data related things, I have ITEM DATA, ACCOUNT DATA, TAX DATA as return tables of the BAPI : BAPI_INCOMINGINVOICE_GETDETAIL.
Now my Question is since the single BAPI Calls returns entire details about the invoices, Can I fetch all the data of a vendor invoice in single call and use the same in my Fiori App? If so How the Nested Tables should be read from the ODATA??
And the second question is that, in Couple of blogs I read that OData structures should be Flat and cannot be nested, if that is the case how can I get the entire data in single call??
I can use association and navigations to drill down however, for each entity the BAPI is called multiple times, will that not be perfomance issue??
Kindly advise.
Regards
Manoj
Hi Manoj,
$expand is used for getting values from associated entities in a single call. There are two types of expand available: Framework expand & data provider expand . Since you are getting all the tables in single RFC call, you should go for Data provider expand.
Please check these links for implementing expand in your OData service:
Regards,
Ekansh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ekansh,
Hope you are doing good.
I tried the data expand framework, and implemented the Expanded_entity_set method. However I am not getting the Item (depdenet Entities) data.. through debug I found that data from header and the 2 depedent entities (ITEM, and ACCOUNT) data is moved properly to er_entityset.. but in the browser.. only header data is visible...
I checked my data declartion for the deep entity and it looks Ok.. Could you please help me further..
Please find the Expanded_entitySet Code Snippet below:
*-------------------------------------------------------------------------*
* Deep Structure
*-------------------------------------------------------------------------*
DATA: BEGIN OF ls_vendor_details.
INCLUDE TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_invlist.
DATA: vendoritemdetails TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_itemdata. " WITH DEFAULT KEY.
DATA: vendoraccountdetails TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_account_data, " WITH DEFAULT KEY,
END OF ls_vendor_details.
DATA: ls_item1 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
ls_account1 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_account_data.
DATA ls_keys TYPE /iwbep/s_mgw_name_value_pair.
DATA: lv_invoicedocnumber TYPE bapi_incinv_fld-inv_doc_no.
DATA: lt_itemdata TYPE TABLE OF bapi_incinv_detail_item,
ls_itemdata TYPE bapi_incinv_detail_item,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_docno TYPE bapi_incinv_fld-inv_doc_no.
*-------------------------------------------------------------------------*
* Data Declarations
*-------------------------------------------------------------------------*
DATA : ls_item TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
lt_item TYPE TABLE OF zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
ls_account2 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_account_data,
lt_account2 TYPE TABLE OF zcl_z_fi_vendor_inv_01_mpc=>ts_account_data,
ls_header TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_invlist,
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_vendor_details LIKE TABLE OF ls_vendor_details.
* ltaccount TYPE STANDARD TABLE OF bapieket,
* lssch TYPE bapieket.
DATA: lt_account TYPE STANDARD TABLE OF bapi_incinv_detail_account,
lt_gl_account TYPE STANDARD TABLE OF bapi_incinv_detail_gl_account,
lt_material TYPE STANDARD TABLE OF bapi_incinv_detail_material,
lt_tax TYPE STANDARD TABLE OF bapi_incinv_detail_tax,
ls_account TYPE bapi_incinv_detail_account,
ls_gl_account TYPE bapi_incinv_detail_gl_account,
ls_material TYPE bapi_incinv_detail_material,
ls_tax TYPE bapi_incinv_detail_tax.
*Get the key property values
READ TABLE it_key_tab WITH KEY name = 'InvDocNo' INTO ls_keys.
* if sy-subrc eq 0.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_keys-value
IMPORTING
output = lv_docno.
DATA: ls_year TYPE bapi_incinv_fld-fisc_year.
CLEAR: ls_keys.
READ TABLE it_key_tab WITH KEY name = 'FiscYear' INTO ls_keys.
IF sy-subrc EQ 0.
ls_year = ls_keys-value.
ELSE.
ls_year = '2004'.
ENDIF.
DATA: ls_header_detail TYPE bapi_incinv_detail_header.
IF NOT lv_docno IS INITIAL AND ls_year IS NOT INITIAL.
*Call the BAPI to get the Vendor invoice details..
CALL FUNCTION 'BAPI_INCOMINGINVOICE_GETDETAIL'
EXPORTING
invoicedocnumber = lv_docno
fiscalyear = ls_year
IMPORTING
headerdata = ls_header_detail
* ADDRESSDATA =
TABLES
itemdata = lt_itemdata
accountingdata = lt_account
glaccountdata = lt_gl_account
materialdata = lt_material
taxdata = lt_tax
* WITHTAXDATA =
* VENDORITEMSPLITDATA =
return = lt_return .
* EXTENSIONOUT =
* TMDATA = .
IF sy-subrc EQ 0.
* move the details to result set...
*-------------------------------------------------------------------------*
* Fill Header Values to Deep Structure
*-------------------------------------------------------------------------*
MOVE-CORRESPONDING ls_header_detail TO ls_vendor_details.
*-------------------------------------------------------------------------*
* Fill Item values to Deep Structure
*-------------------------------------------------------------------------*
LOOP AT lt_itemdata INTO ls_itemdata.
CLEAR ls_item1.
ls_item1-invoicedocnumber = ls_header_detail-inv_doc_no.
MOVE-CORRESPONDING ls_itemdata TO ls_item1.
APPEND ls_item1 TO ls_vendor_details-vendoritemdetails.
ENDLOOP.
LOOP AT lt_account INTO ls_account.
CLEAR ls_account1.
MOVE-CORRESPONDING ls_account TO ls_account1.
APPEND ls_account1 TO ls_vendor_details-vendoraccountdetails.
ENDLOOP.
*-------------------------------------------------------------------------*
* Assign the Navigation Proprties name to Expanded Tech clauses
*-------------------------------------------------------------------------*
ls_expanded_clause1 = 'VENDORITEMDETAILS'.
ls_expanded_clause2 = 'VENDORACCOUNTDETAILS'.
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_vendor_details TO lt_vendor_details.
*-------------------------------------------------------------------------*
* Send back Response to Consumer
*-------------------------------------------------------------------------*
copy_data_to_ref(
EXPORTING
is_data = lt_vendor_details
CHANGING
cr_data = er_entityset ).
ENDIF.
ENDIF.
Hello Manoj,
In the below declaration names vendoritemdetails & vendoraccountdetails used for item table declarations are same as the navigation properties defined in your GW Model ?
DATA: BEGIN OF ls_vendor_details.
INCLUDE TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_invlist.
DATA: vendoritemdetails TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_itemdata. " WITH DEFAULT KEY.
DATA: vendoraccountdetails TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_account_data, " WITH DEFAULT KEY,
END OF ls_vendor_details.
Navigation properties defined in GW Model should be same as the names used to declare the item tables in the deep structure. And the same names should be appended to the Expand_Clauses in caps as well.
Please check this again.
Regards,
Ashwin
Hi Ashwin,
Thanks for the response.
Yes The names were same in the Navigation, Exclude clause.. However I made few changes to my Service..
Account details has a direct relation ship with Item data entity, so I made a navigation among these two..
So my Entitiy types are
1. INVLIST
2. ITEMDATA
3. Account_DATA.
Invlist and ITEMDATA are llinked, and ITEMDATA and Account_data are linked... However even after chaing this I am not getting any data in the ITEMEntity, and one more thing observed was the sequqence, First ITemDATA and ACcount data are displayed which are blank and then Heder(this has proper data)..
In Debugging I can see the data moved to all these three entities properly after that I only see header data.. no Item and Account data...
If I dont use Data Expand, I am able to display both the Header and ITEM DATA...
Naivgatins:
Now I changed the EXPAND_ENTITYSET as below:
-------------------------------------------------------------------------*
* Deep Structure
*-------------------------------------------------------------------------*
DATA: BEGIN OF ls_vendor_details.
INCLUDE TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_invlist.
DATA: itemdata TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_itemdata. " WITH DEFAULT KEY.
DATA: account_data TYPE zcl_z_fi_vendor_inv_01_mpc=>tt_account_data, " WITH DEFAULT KEY,
END OF ls_vendor_details.
DATA: ls_item1 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
ls_account1 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_account_data.
DATA ls_keys TYPE /iwbep/s_mgw_name_value_pair.
DATA: lv_invoicedocnumber TYPE bapi_incinv_fld-inv_doc_no.
DATA: lt_itemdata TYPE TABLE OF bapi_incinv_detail_item,
ls_itemdata TYPE bapi_incinv_detail_item,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_docno TYPE bapi_incinv_fld-inv_doc_no.
*-------------------------------------------------------------------------*
* Data Declarations
*-------------------------------------------------------------------------*
DATA : ls_item TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
lt_item TYPE TABLE OF zcl_z_fi_vendor_inv_01_mpc=>ts_itemdata,
ls_account2 TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_account_data,
lt_account2 TYPE TABLE OF zcl_z_fi_vendor_inv_01_mpc=>ts_account_data,
ls_header TYPE zcl_z_fi_vendor_inv_01_mpc=>ts_invlist,
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_vendor_details LIKE TABLE OF ls_vendor_details.
DATA: lt_account TYPE STANDARD TABLE OF bapi_incinv_detail_account,
lt_gl_account TYPE STANDARD TABLE OF bapi_incinv_detail_gl_account,
lt_material TYPE STANDARD TABLE OF bapi_incinv_detail_material,
lt_tax TYPE STANDARD TABLE OF bapi_incinv_detail_tax,
ls_account TYPE bapi_incinv_detail_account,
ls_gl_account TYPE bapi_incinv_detail_gl_account,
ls_material TYPE bapi_incinv_detail_material,
ls_tax TYPE bapi_incinv_detail_tax.
*Get the key property values
READ TABLE it_key_tab WITH KEY name = 'InvDocNo' INTO ls_keys.
* if sy-subrc eq 0.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_keys-value
IMPORTING
output = lv_docno.
DATA: ls_year TYPE bapi_incinv_fld-fisc_year.
CLEAR: ls_keys.
READ TABLE it_key_tab WITH KEY name = 'FiscYear' INTO ls_keys.
IF sy-subrc EQ 0.
ls_year = ls_keys-value.
ELSE.
ls_year = '2004'.
ENDIF.
DATA: ls_header_detail TYPE bapi_incinv_detail_header.
IF NOT lv_docno IS INITIAL AND ls_year IS NOT INITIAL.
*Call the BAPI to get the Vendor invoice details..
CALL FUNCTION 'BAPI_INCOMINGINVOICE_GETDETAIL'
EXPORTING
invoicedocnumber = lv_docno
fiscalyear = ls_year
IMPORTING
headerdata = ls_header_detail
TABLES
itemdata = lt_itemdata
accountingdata = lt_account
glaccountdata = lt_gl_account
materialdata = lt_material
taxdata = lt_tax
return = lt_return.
IF sy-subrc EQ 0.
* move the details to result set...
*-------------------------------------------------------------------------*
* Fill Header Values to Deep Structure
*-------------------------------------------------------------------------*
MOVE-CORRESPONDING ls_header_detail TO ls_vendor_details.
*-------------------------------------------------------------------------*
* Fill Item values to Deep Structure
*-------------------------------------------------------------------------*
LOOP AT lt_itemdata INTO ls_itemdata.
CLEAR ls_item1.
ls_item1-invoicedocnumber = ls_header_detail-inv_doc_no.
MOVE-CORRESPONDING ls_itemdata TO ls_item1.
* ls_item1-poitem = lsitem-po_item.
* ls_item1-material = lsitem-material.
APPEND ls_item1 TO ls_vendor_details-itemdata.
ENDLOOP.
LOOP AT lt_account INTO ls_account.
CLEAR ls_account1.
MOVE-CORRESPONDING ls_account TO ls_account1.
APPEND ls_account1 TO ls_vendor_details-account_data.
ENDLOOP.
*-------------------------------------------------------------------------*
* Assign the Navigation Proprties name to Expanded Tech clauses
*-------------------------------------------------------------------------*
ls_expanded_clause1 = 'ITEMDATA'.
ls_expanded_clause2 = 'ITEMDATA/Account_Data'.
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_vendor_details TO lt_vendor_details.
*-------------------------------------------------------------------------*
* Send back Response to Consumer
*-------------------------------------------------------------------------*
copy_data_to_ref(
EXPORTING
is_data = lt_vendor_details
CHANGING
cr_data = er_entityset ).
ENDIF.
ENDIF.
Hi Manoj,
Please try with only one excluded clause i.e.
ls_expanded_clause2 = 'ITEMDATA/ACCOUNT_DATA'.
APPEND ls_expanded_clause2 TO et_expanded_tech_clauses.
and remove the ls_expanded_clause1 and its appending statement. Also please note that this excluded clause should have CAPS letters only.
Also please share the URL that you are using to call this.
Regards,
Ekansh
Hi Ekansh,
I tried passing the one Excluded cluase:
Like Below:
ls_expanded_clause1 = 'ITEMDATA'.
APPEND ls_expanded_clause1 TO et_expanded_tech_clauses.
and for testing I am using /IWFND/GW_CLIENT Tx. and URL is:
/sap/opu/odata/sap/Z_FI_VENDOR_INVOICE_DISPLAY_XT_SRV/INVLISTSet(InvDocNo='5105605880',FiscYear='2014')?$expand=ITEMDATA
Output:
Here I get blank Item details... Header filled in proper.
Then I tried changing the Excluded clause as Below:
ls_expanded_clause2 = 'ITEMDATA/ACCOUNT_DATA'.
APPEND ls_expanded_clause2 TO et_expanded_tech_clauses.
and URL:
/sap/opu/odata/sap/Z_FI_VENDOR_INVOICE_DISPLAY_XT_SRV/INVLISTSet(InvDocNo='5105605880',FiscYear='2014')?$expand=ITEMDATA/ACCOUNT_DATA
Output:
Resource not found for the segment 'ACCOUNT_DATA'.
Could you please help...
Regards
Manoj
Hi,
The URL would point to GET_EXPANDED_ENTITY and not to GET_EXPANDED_ENTITYSET. Thus make sure you implement the correct method.
Thus in get_expanded_entity you have to pass ls_vendor_details to the response and not lt_vendor_details. So please go ahead with excluded data = 'ITEMDATA/ACCOUNT_DATA' and copy_data_to_ref( EXPORTING is_data = ls_vendor_details CHANGING cr_entity = er_entity ).
Please check and update us.You can also check:
Regards,
Ekansh
Hi Ekansh,
Hope you are doing good.
Thanks for the Reply.. I implemented the get_EXPANDED_ENTITY, However I am still not able to read the second level data...
INVLIST->ITEMDATA
ITEMDATA->ACCOUNTDATA..
I am not able to read any data of Account Data entity...
I have ITEMDATA and INVLIST coming in the output.. and in the Debug I can see that all the three entity types data moved to the ER_Enity... but on the output onlu INVLIST(Header) and ITEMDATA(detail) is displayed...
Could you please help...
User | Count |
---|---|
86 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.