cancel
Showing results for 
Search instead for 
Did you mean: 

Expanded Entity and Entityset and Delta Query

Former Member
0 Kudos

Hello fellow SAPers. I've come to you guys with a few questions for my current requirement.

We need to obtain the information regarding the Customer and it's details.

Customers are obtained by the name of the user, this will fetch every customer assigned to the user using the app. There's a custom built RFC that will fetch the information. I know that, using associations and $expand I could easily fetch the other related colections such as Address, Contact Numbers and Pictures. However the tricky part is that, as part of the requirement, this has to be done in one go, whereas, as per my understanding, in a normal scenario, this would be done in n calls depending the number of the customers assigned to the user. Looking throught possible options to fullfil this requirement I've found that this could be possibly achieved using GET_EXPANDED_ENTITY and ENTITYSET, however I want to make sure this is the right path to follow. The information required should output something like:

<customer>               1..n

     <basicData/>        1

     .

     .

     .

     <Addresses>          0..n

          <addressDetail>

          .

          .

          .

    </Addresses>

     <Addresses>

          <addressDetail>

          .

          .

          .

     </Addresses>

     <ContactNumbers> 0..n

And so on.

The reason behind of this requirement is because FrontEnd team told us they need the information to be retrieved in such way because it's to be used for offline scenarios and for that, the information should be retrieved all in the first operation of the call.

The question are, will this be achiveable by means of EXPAND? or should we look for another way to solve this.

The next questions and more important is, if this kind of operation is compatible with Delta Query?.

With no further ado, thank you guys in advance.

Best regards.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

So.. little update.

I've tried again using the GET_EXTENDED_ENTITYSET, however we found the same result before.

The method gets called multiple times, and the information is being deleted from the table with the addresses per client.

We have the current set up:

-Maping is done via File

-Association betwen Customer and Address is set, cardinality is set to 1-n, both have the same key field defined in the constrains

-Navigation property is created

-Information is obtained via Function Module, the field names and the ones in the mapping are different, so the created table that will hold the response is built manualy.

-Navigation property name is contained in the tech field and inserted/appended at the end of the operation. The table field that will contain the addresses is named as the navigation property,

I don't know if there's any fine detail we're skipping, we tried to use the same example as it's on the previous links and it worked correctly, so I'm not sure what we're exactly doing wrong.

If you guys have any other insight i'll be pretty greatful about it.

Cheers.

AshwinDutt
Active Contributor
0 Kudos

Hello Emmanuel,

Are you filling the Technical Expand Clauses with navigation properties ? Please check this.

If this is not done then method gets called again and again for all the child entities as well.

Can you share the code here ?

Regards,

Ashwin

Former Member
0 Kudos

Thank you. Here's the code we're using.

DATA: BEGIN OF ls_expanded_info.
           INCLUDE TYPE zcl_zprueba_rfc_egc_mpc=>ts_client.
   DATA: bptoaddress TYPE STANDARD TABLE OF zcl_zprueba_rfc_egc_mpc=>ts_address WITH DEFAULT KEY,
         END OF ls_expanded_info.

   DATA: lt_user_list    TYPE /cbcr/ty_prospectlistbybp_ao,
         lt_return       TYPE STANDARD TABLE OF bapiret2,
         lt_address      TYPE zty_mobilebp_stdaddr_data,
         lt_client_info  TYPE STANDARD TABLE OF zes_mobilebp_basic_data,
         lt_address_comp TYPE zty_mobilebp_stdaddr_data,
         lt_expand_tab   LIKE TABLE OF ls_expanded_info.

   DATA: ls_user_list   TYPE /cbcr/es_prospectlistbybp_ao,
         ls_client      TYPE zes_mobilebp_basic_data,
         ls_address_comp TYPE zes_mobilebp_stdaddr_data,
         ls_address     TYPE zcl_zprueba_rfc_egc_mpc=>ts_address,
         ls_expand_tab  LIKE ls_expanded_info.

   DATA: lv_user_name  TYPE uname.

   CONSTANTS: lc_expand_tech_clause TYPE string VALUE 'BPtoAddress'.


   lv_user_name = 'GARCINIEGA'.

*Obtain all the clients assigned to a user by its user name
   CALL FUNCTION '/CBCR/MF_PROSPECTLISTBYBP_AO'
     EXPORTING
       iv_username              = lv_user_name
     IMPORTING
       et_prospectlistbybp_data = lt_user_list
       et_return                = lt_return.

*Obtain the details for every client and addresses, build up the tables with the info needed.
   LOOP AT lt_user_list INTO ls_user_list.

     CALL FUNCTION 'ZMF_BP_DETAILS_AO'
       EXPORTING
         iv_business_partner = ls_user_list-partner_no
       IMPORTING
         es_basic_data       = ls_client
         et_address_data     = lt_address
         et_return           = lt_return.

     APPEND ls_client TO lt_client_info.
     APPEND LINES OF lt_address TO lt_address_comp.

   ENDLOOP.

   CLEAR ls_client.

*Loop at the full client list and build the first data:
   LOOP AT lt_client_info INTO ls_client.

     MOVE-CORRESPONDING ls_client TO ls_expand_tab.

*Append the address data for the corresponding client and insert it into the response of the service
     LOOP AT lt_address_comp INTO ls_address_comp WHERE bp_id = ls_client-bp_id.
       MOVE-CORRESPONDING ls_address_comp TO ls_address.
       APPEND ls_address TO ls_expand_tab-bptoaddress.
       CLEAR ls_address.
     ENDLOOP.

     APPEND ls_expand_tab TO lt_expand_tab.
     CLEAR: ls_expand_tab.
   ENDLOOP.

*Copy the refs
   copy_data_to_ref(
     EXPORTING
       is_data = lt_expand_tab
     CHANGING
       cr_data = er_entityset ).
*Insert the expand clause
   INSERT lc_expand_tech_clause INTO TABLE et_expanded_tech_clauses.

ENDMETHOD.


Also add the SS of the modeling for reference:


We're generating the modeling based on the RFC that provides the data as a part of a test that the issue was because of name missmatch, but we got the same answer.


Referencial Constrains for the association

I don't know if there's anything else wrong.

Debug data:

The info is being created correctly, we have 2 Clients and each has 1 Address

Address 1 detail:

Address 2 detail:

Attach the XML with the response.

Thank you in advance.

Former Member
0 Kudos

So.....I found the error.

The issue was that, the method got named with both collections defined in the $expand call, we did not had a validation on checking the name of the calling entitySet, so once it did the first call, the second call, with the Address entity set, it overwrotte the info in the method copy_data_to_ref. I'll add more if anything else changes.

Thank you everybody for the help trying to figure out what was the problem.

Cheers.

Answers (2)

Answers (2)

AshwinDutt
Active Contributor
0 Kudos

Hello Emmanuel,

Its possible with $expand to get all those details in one call.

Regarding Delta Query in combination with $expand, please have a look at the Technical Restrictions section in the below blog by Andre ->

Use batch operation to get all those details by implementing Delta Query for each of them.

Regards,

Ashwin

Former Member
0 Kudos

Thank you for the reply Ashwin.

I see you're mentioning it could be done in one call, would you mind to guide me on how to do so or if we're on the right track trying to use the EXPANDED_ENTITYSET?

Also I'm sorry I didn't add this, we are using Syclo Framework to use the Delta Functionality. What we're planning to do is. if we end up using the 2 step proposal would be.

First step should focus on get for a given UNAME a list of customers associated to it, this would be a basic GET_ENTITYSET that would also provide the Delta Token for it to be stored in a DB for further comparation. This step should return to us the list of ID's for the clients for the given user name.

The second step, now with the ID's, should perform a batch process to retrieve the details for every Client ID making use of the expand functionality.

For Delta Query functionality, once the delta token is provided as part of the request, system knows that it requires to trigger the GET_DELTA method of the DPC class, we need to make it so, it will give us back only those ID's that had any CUD operation done on them depending the calculations of the delta token timestamp or if no changes were made, this is where the second step would focus on retrieving the data for those ID's that were modified or to know if it should not query the backend and use the information stored on its internal DB.

Thank you in advance for your reply and your time, if you have any more insights on how to solve the issue I'll be more than grateful to hear them.

Cheers.

AshwinDutt
Active Contributor
0 Kudos

Hello Emmanuel,

It could have been done using $expand in one call if Delta Query was not in your scope.

I am not sure if Delta Query can be combined with $expand.

From Andre's blog its been mentioned that there is a technical restriction for using $expand and Delta Query together. So i doubt if we can combine these two and use it.

Considering the above challenge i would suggest to try the below ->

Implement separate Get_Entity_Set for Customer, Address, ContactNumber entities with Delta Query Functionality etc...

Combine all these operation inside a batch request.

This way you can perform all GET operations on all those entities with Delta Query inside a batch.

Regards,

Ashwin

SB9
Active Participant
0 Kudos

This can be done through $expand. Another way would be to do it separately and batch all the GET calls so that one call is made from front-end to back-end server.

I guess for offline support you need to use some storage to persist the data. Maybe data can be stored in browser database (Web SQL Database).

The final implementation would depend upon the real business scenario and the technologies you have at your disposal.

Former Member
0 Kudos

Thank you for your answer.

We tried doing it via GET_EXPANDED_ENTITYSET, but we're having issues with the way the information is being sent back, in the method Move_Corresponding our data is being deleted and changed completly, which returns info that's useless for us. We have two mainly issues with this path, first, the method is getting called multiple times for some reason, and second, as just said, the move corresponding part of the code is deleting our info. Is there any special consideration I need to follow for this scenario to work correctly? I'm basing my code using the example code present on multiple tutorials, but we end up having the same issue.

I was considering doing it in a two step, just like you said using $batch, one call would fetch the number of clients corresponding to the SalesPerson and then second call will perform a batch call with the corresponding expands to obtain the whole info. The problem also, would be the way we need to implement the deltaQuery for this part, since this is going to be one of the most used Query service, we want to improve the performance by using deltas in order to lower the amount of query calls to the backend. However, since the DeltaQuery part is called by default, we need to figure our, how we're exaclty going to build up the response for the Query since our response has to look something like this:

-Client Basic Data

-Basically a simple list of general fields for a client

-Address Table

  -A list of registered addresses for the client, can have multiple records.

-Contact Numbers

  -A list of registered contact cellphone numbers, can have multiple records.

-Images Table

   -A list of registered photos of documents from a client, can have multiple records.

And this could repeat n times, where n is the number of assigned clients for a sales person.

I thank you again for your time and your insight. If you could point out any good source of information/tutorials for this same kind of issue, it will be greatly appreciated.

Best regards.

SB9
Active Participant
0 Kudos

Did you look at the following blog ?

Your odata should look like

ClientSet('001234') - GET for one client Data

ClientSet - List of all clients

ClientSet('001234')?$expand=ClientToAddress - List of all address for client no - 1234

Similarly,

ClientSet('001234')?$expand=ClientToPhone

ClientSet('001234')?$expand=ClientToImages


The client id should be Foreign Key for address, phone and image table.

Former Member
0 Kudos

Thank you for the reply Soujanya.

Yes, we followed the tutorial on the link, we can't use the ClientID's for a expand because we only know them on processing time, and thus we can't use them for a expand call, the only thing we know is the user for the app, however if we'd use a expand using that as a key field, we won't get the information corresponding to an specific client. That's why we thought of using a GET_EXPANDED_ENTITYSET, the issue is, while we have already built the info as it should be sent to front end, we are having the problem that:

-If we use copy_Data_to_ref, for some reason, the code is triggered 3 times, we know this because, if we use a breakpoint and F8, it will return to the breakpoint.

- The second issue is that, once the ref is copied correctly, the system runs the standar code and when it reaches the move_corresponding method, the information that is filled inside the address tables is deleted, and even more, it adds another row to it.

Perhaps, the issue is how we're declaring the associations at mapping level.

Our mapping puts customer being the main entity, that can have an Address table, Contact table, and so on. The associations relate them with the client id on both as the referential constrain. However looking at the tutorial, we see that for one of the sides, the referential constrain is ignored.

We're gonna run a test and see if that could be part of the issue.

I also have one last question, if we redefine the Expand functionality, then it's not required to code the GET_ENTITY/ENTITYSET for any of the relations, is it?

Thank you in advance for your comments.

Cheers.