Skip to Content
0
Feb 05, 2020 at 08:18 AM

SAP oData expand query returns "Unexpected text for XML-ABAP transformation error" Error

577 Views

Dear Friends!

I am trying to create Expand query in oData. while testing it gives me error "Unexpected text for XML-ABAP transformation error".

My Scenario is I have one Structure of Sales Order Header and Delivery Detail ( Both are custom and i am not using bapi ). I am trying to get sales order header information along with deliveries to Sales Order I receive the error in response. In debug i found that it gives me data when xml is getting prepared but for which property is throws the errow i couldnt find it.

I have cleaned the caches for both the system, changed the cardinality as well. Objects generated! still no luck... further I have one more issue.

that when I use $filter option in URL it gives me different entity set name and which is header entityset by the way and when I use ('1231231') it gives me item entityset and interestingly... selection option table and it_key_tab table both comes empty. then I hardcoded the value to get the data.

please help me to understand where I am doing wrong.

my url

/sap/opu/odata/sap/ZSD_LE_GPS_TRACKING_SRV/gps_delivery_detailsSet('0000014079')?$expand=ToDelivery

this will return empty key_tab.

/sap/opu/odata/sap/ZSD_LE_GPS_TRACKING_SRV/gps_delivery_detailsSet?$filter=Vbeln eq '0000014079'&$expand=ToDelivery

this will return empty filter tab.

please see : I am using this for Get Method.

my code:

SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET.
 data lv_entityset_name type string.
 data: begin of str_exp.
       include  type ZCL_ZSD_LE_GPS_TRACKIN_MPC_EXT=>TS_GPS_DELIVERY_DETAILS.
 data: ToDeliveryLog type  ZCL_ZSD_LE_GPS_TRACKIN_MPC_EXT=>TT_DELIVERYLOG.
 data:    end of str_exp.
 DATA:WA_SO TYPE /IWBEP/S_MGW_SELECT_OPTION.
 DATA WA_LO TYPE /IWBEP/S_COD_SELECT_OPTION.
 DATA lv_vdatu type TIMESTAMP.
 data: lt_expand   like   str_exp,
       ls_expand   like str_exp,
       ls_item type ZCL_ZSD_LE_GPS_TRACKIN_MPC_EXT=>TS_DELIVERYLOG.
 data: it_head   type  table of ZSDST_GPS_DELIVERY_HEADER,
       wa_head   like line of it_head,
       it_item type table of ZSDST_GPS_LOCATION,
       wa_delitem like line of it_item.
 data:ls_keytab TYPE LINE OF /IWBEP/T_MGW_NAME_VALUE_PAIR.
 DATA: LV_VBELN          Type  VBELN,
       DRIVER            Type  ZSDST_GPS_DRIVER_LIST,
       SALES_ORDER_DATA  Type  ZSDST_GPS_SO_HEADER,
       SHIPPING_ADDRESS  Type  ZSDST_GPS_SHIPPING_ADDRESS,
       DELIVERY_LOG      Type  ZSDTT_GPS_LOCATION.
 DATA WA_KEY TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.
 DATA ob_del type ref to ZSDCL_GPS_TRACKING.
*   DATA WA_ENTITY LIKE LINE OF ET_ENTITYSET.
    constants: lc_expand_tech_clause type string value 'ToDelivery'.
    lv_entityset_name = io_tech_request_context->get_entity_set_name( ).
       case lv_entityset_name.
           when 'DeliveryLogSet'  " When I use ('12323123') like value in URL I receive the item set
                 OR 'gps_delivery_detailsSet'. " when I use filter  I recieve headerset
              READ TABLE IT_FILTER_SELECT_OPTIONS INTO WA_SO WITH KEY PROPERTY = 'Vbeln'. "Alway empty
              if sy-subrc = '0'.
                READ TABLE WA_SO-SELECT_OPTIONS INTO WA_LO INDEX '1'.
                IF SY-SUBRC = '0'.
*                    TRANSLATE wa_so–property TO UPPER CASE.
                       CASE WA_SO-PROPERTY.
                          WHEN 'Vbeln'.
                            lv_vbeln = WA_LO-LOW.
                          WHEN OTHERS.
                         "Log message in the application log
                           me->/iwbep/if_sb_dpc_comm_services~log_message(
                                       EXPORTING
                                          iv_msg_type   = 'E'
                                          iv_msg_id     = '/IWBEP/MC_SB_DPC_ADM'
                                          iv_msg_number = 020
                                          iv_msg_v1     = WA_SO-PROPERTY ).
                          " Raise Exception
                           RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception
                                        EXPORTING
                                           textid = /iwbep/cx_mgw_tech_exception=>internal_error.
                        ENDCASE.
                    ENDIF.
                 ENDIF.
                 IF IT_FILTER_SELECT_OPTIONS is initial.
                    read table it_key_tab into wa_key index '1'. "Alway empty
                    if sy-subrc = '0'.
                       lv_vbeln = wa_key-value.
                    endif.
               endif.
             
                 if lv_vbeln is initial.
                    lv_vbeln = '0000014079'. "<-Hard code the Sales Order Number
                endif.
                create object ob_del.
                  CALL METHOD ob_del->get_delivery_detail
                      EXPORTING
                        i_vbeln         = LV_VBELN
                      IMPORTING
                        driver           = DRIVER
                        sales_order_data = sales_order_data
                        shipping_address = shipping_address
                        delivery_log     = delivery_log.
            insert lc_expand_tech_clause into table et_expanded_tech_clauses.
            MOVE-CORRESPONDING sales_order_data to ls_expand.
            MOVE-CORRESPONDING shipping_address to ls_expand.
            MOVE-CORRESPONDING driver to ls_expand.
            loop at delivery_log into wa_delitem.
               move-corresponding wa_delitem to ls_item.
               append ls_item to ls_expand-todeliverylog.
               clear wa_delitem.
            endloop.
 endcase.
  copy_data_to_ref(
           exporting
             is_data = ls_expand
           changing
             cr_data = er_entityset ).
endmethod. " No Error triggered so far here. error comes after this method finishes and xml getting prepared.

I have attached association, Navigation property along with this message.

Kindly help me to understand where I am doing mistake here. I will greatly appreciate your help in this regards.

Best Regards
Naim