Calling expand entity from SAP Gateway Client - odata

I try to call a GET_EXPANDED_ENTITYSET method of SRA020_PO_TRACKING Project, po tracking project. The following is the method:
METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.
DATA: lv_ponumber TYPE bapiekko-po_number,
lv_leading_msg TYPE boolean.
DATA: lo_api TYPE REF TO cl_sra020_po_tracking_api.
DATA: ls_po_details TYPE cl_sra020_po_tracking_api=>ts_podetails,
lt_return TYPE bapirettab,
lo_msgcontainer TYPE REF TO /iwbep/if_message_container.
DATA: lt_poitem_details TYPE cl_sra020_po_tracking_api=>tt_poitemdetail.
FIELD-SYMBOLS: <fs_return> TYPE bapiret2,
<fs_key_tab> TYPE /iwbep/s_mgw_name_value_pair.
lo_api = cl_sra020_po_tracking_api=>get_instance( ).
*========================================================================================
* Read Entities key values within oData service URL
*========================================================================================
IF it_key_tab IS NOT INITIAL.
LOOP AT it_key_tab ASSIGNING <fs_key_tab>.
CASE <fs_key_tab>-name.
WHEN if_sra020_po_tracking_constant=>cc_po_number.
lv_ponumber = <fs_key_tab>-value.
ENDCASE.
ENDLOOP.
ENDIF.
TRY.
CASE iv_entity_set_name.
WHEN if_sra020_po_tracking_constant=>cc_podetaileddatas.
CALL METHOD lo_api->get_po_details
EXPORTING
iv_item_additional_data = 'X' "#EC NOTEXT
iv_po_number = lv_ponumber
IMPORTING
es_po_details = ls_po_details
et_return = lt_return.
IF NOT lt_return IS INITIAL.
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception.
ENDIF.
lt_poitem_details = ls_po_details-poitemdetaildatas.
no_cache( ).
* Return the expanded clauses
APPEND cl_sra020_po_tracking_mpc=>gc_poitemdocflow TO et_expanded_tech_clauses.
APPEND cl_sra020_po_tracking_mpc=>gc_accounting TO et_expanded_tech_clauses.
APPEND cl_sra020_po_tracking_mpc=>gc_pricingconditions TO et_expanded_tech_clauses.
APPEND cl_sra020_po_tracking_mpc=>gc_confirmation TO et_expanded_tech_clauses.
CALL METHOD copy_data_to_ref
EXPORTING
is_data = lt_poitem_details
CHANGING
cr_data = er_entityset.
ENDCASE.
CATCH /iwbep/cx_mgw_busi_exception.
lo_msgcontainer = me->mo_context->get_message_container( ).
LOOP AT lt_return ASSIGNING <fs_return> WHERE type EQ 'E' OR type EQ 'A'. "#EC NOTEXT
IF <fs_return>-id EQ 'SRA020'.
lv_leading_msg = abap_true.
ELSE.
lv_leading_msg = abap_false.
ENDIF.
lo_msgcontainer->add_message(
iv_msg_type = <fs_return>-type
iv_msg_id = <fs_return>-id
iv_msg_number = <fs_return>-number
iv_msg_text = <fs_return>-message
iv_msg_v1 = <fs_return>-message_v1
iv_msg_v2 = <fs_return>-message_v2
iv_msg_v3 = <fs_return>-message_v3
iv_msg_v4 = <fs_return>-message_v4
iv_is_leading_message = lv_leading_msg
).
ENDLOOP.
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message_container = lo_msgcontainer.
ENDTRY.
ENDMETHOD.
Where
if_sra020_po_tracking_constant=>cc_po_number = PONumber
if_sra020_po_tracking_constant=>cc_podetaileddatas = PODetailedDatas
and PODetailedData entity has navigation properties of POItemDetailDatas,POItems,and POList
I try to call the method from Gateway Service Client by executing
/sap/opu/odata/SAP/SRA020_PO_TRACKING_SRV/PODetailedDatas?$expand=POItemDetailDatas,POItems,POList
However I got status code 400 Bad Request instead. What did I miss?
regards
Edit:
The message in the Bad Request says: Error while reading Purchase Order
edit 2:
association screen shot:
navigation screen shot:

Turns out I have to provide PONumber, so that:
PODetailedDatas(PONumber='4500000039')?$expand=POItems
works fine

Related

Select particular listbox value on start of Dynpro?

I have a custom dialog dynpro including an input field named DYN_MATNR as listbox for which I have included a list of particular materials as selection.
How can I set a specific material (of that list) as selected when the dialog dynpro is opened?
PBO of dialog dynpro:
data lt_values type vrm_values.
select matnr,
maktx
into table #data(lt_materials)
from makt
where matnr in #so_matnr
and spras = 'D'
order by matnr.
loop at lt_materials assigning field-symbol(<material>).
append initial line to lt_values assigning field-symbol(<value>).
<value>-key = <material>-matnr.
<value>-text = <material>-maktx.
endloop.
call function 'VRM_SET_VALUES'
exporting
id = 'DYN_MATNR'
values = lt_values
exceptions
id_illegal_name = 1
others = 2.
if sy-subrc <> 0.
" ...
endif.
This works and it shows the list of materials as listbox values. To select a particular material I have included the FM DYNP_VALUES_UPDATE afterwards and also in PBO but this did not work:
data lv_stepl type syst-stepl.
call function 'DYNP_GET_STEPL'
importing
povstepl = lv_stepl
exceptions
stepl_not_found = 1
others = 2.
if sy-subrc <> 0.
" ...
endif.
data(lt_dynpfields) = value dynpread_tabtype(
( fieldname = 'DYN_MATNR'
stepl = lv_stepl
fieldvalue = gcl_helper->get_matnr( ) " matnr which should be selected is stored here
fieldinp = space )
).
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = sy-repid
dynumb = sy-dynnr
tables
dynpfields = lt_dynpfields
exceptions
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
others = 8.
if sy-subrc <> 0.
" ...
endif.
I am also not able to directly set DYN_MATNR as it is not available in PBO.
Any hints?
Got it:
You need to additionally define a global(!) variable with the name and (wished) type of the input field (e.g. in the top include of the report or in a separate include of the dynpro logic):
data dyn_matnr type matnr.
Then you can set the initial value of the dynpro field in PBO directly:
dyn_matnr = gcl_helper->get_matnr( ).
As this becomes rather irritating when using various dialog dynpros I recommend including the dynpro number in those variables and input fields.

OData getEntity method fetches only first entity

I have a service with a working getEntitySet method. The output looks like this:
But when I try to get only a single entity with /ColumnSet(1) my Output fetches only the first entity which is ColumnSet(0)
method COLUMNSET_GET_ENTITY.
data: ls_key_tab type /iwbep/s_mgw_name_value_pair,
lv_columnid type string,
ls_column type zst_column.
loop at it_key_tab into ls_key_tab.
if ls_key_tab-name = 'COLUMNID'.
lv_columnid = ls_key_tab-value.
endif.
endloop.
select single * from zst_column into ls_column where id_num = lv_columnid.
er_entity-id_num = ls_column-id_num.
er_entity-id = ls_column-id.
er_entity-posi = ls_column-posi.
er_entity-data_id = ls_column-data_id.
er_entity-headertext = ls_column-headertext.
er_entity-ui_element_typ = ls_column-ui_element_typ.
er_entity-enable = ls_column-enable.
er_entity-enable_ref = ls_column-enable_ref.
endmethod.
I dont know, why it only shows the first entity.
Your Key field is IDNUM, not COLUMNID.
loop at it_key_tab into ls_key_tab.
if ls_key_tab-name = 'IdNum'.
lv_columnid = ls_key_tab-value.
endif.
endloop.

LSXLC ODBC Stored Procedure

I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.

Unable to pass URL params into api request

I'm working with the Bing API and when I am making a SOAP request to acquire my campaign stats I'm having trouble passing URL params for date (provided by bootstrap datepicker) to the request.
I keep receiving the following error -
(a:DeserializationFailed) The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://adcenter.microsoft.com/v8:ReportRequest. The InnerException message was 'There was an error deserializing the object of type Microsoft.AdCenter.Advertiser.Reporting.Api.DataContracts.Request.ReportRequest. The value '' cannot be parsed as the type 'Int32'.'. Please see InnerException for more details.
It seems to me as though it is not able to receive the values I have set as the start/end date in the params. It is working when the params[:start]/[:end] values are nil
Here is the controller code setting up the date params (datepicker works fine for all other requests):
#Start Bing Reporting Code - set date for request ID
if params[:start].nil?
bing_start_date = DateTime.parse((Date.today - 7).to_s).strftime("%Y-%m-%d")
yearstart = bing_start_date[0,4]
monthstart = bing_start_date[5..6]
daystart = bing_start_date[8..9]
bing_end_date = DateTime.parse((Date.today - 1).to_s).strftime("%Y-%m-%d")
yearend = bing_end_date[0,4]
monthend = bing_end_date[5..6]
dayend = bing_end_date[8..9]
else
bing_start_date = params[:start]
yearstart = bing_start_date[2,4]
monthstart = bing_start_date[5..6]
daystart = bing_start_date[8..9]
bing_end_date = params[:end]
yearend = bing_end_date[2,4]
monthend = bing_end_date[5..6]
dayend = bing_end_date[8..9]
end
Here is the SOAP request body where I set the custom date range (using Savon gem):
soap.body = "<CustomDateRangeEnd i:nil=\"false\"><Day>#{dayend}</Day><Month>#{monthend}</Month><Year>#{yearend}</Year></CustomDateRangeEnd><CustomDateRangeStart i:nil=\"false\"><Day>#{daystart}</Day><Month>#{monthstart}</Month><Year>#{yearstart}</Year></CustomDateRangeStart></Time></ReportRequest>"
It works fine If I just set the yearend/start, monthend/start, dayend/start variables manually like so:
yearstart = '2014'
monthstart = '01'
daystart = '01'
#this would set the start date properly to Jan 1 2014
Foolish mistake. I used the same start index/length and ranges for the 'if' statement as I did for the 'else'. As a result it was throwing and empty string to <day>
The date output for the 'if' was "2014-01-13" and the output for the else was "20140113"
Therefore, I needed to adjust the index/length and ranges like so:
bing_start_date = params[:start]
yearstart = bing_start_date[0,4]
monthstart = bing_start_date[4..5]
daystart = bing_start_date[6..7]

How can I call ActiveX from SAP?

I have a custom ActiveX control that I would like to Call from SAP.
In this case I cannot use PI, what other options do I have?
See program SAPRDEMO_ACTIVEX_INTEGRATION as an example.
DATA: control TYPE REF TO i_oi_container_control,
ocx_document TYPE REF TO i_oi_document_proxy,
has_activex TYPE flag,
retcode TYPE soi_ret_string,
doc_handle TYPE cntl_handle,
document_type TYPE soi_document_type VALUE 'SAPActiveXDoc.Example1'.
"Test whether activeX is supported"
CALL FUNCTION 'GUI_HAS_ACTIVEX'
IMPORTING return = has_activex.
CHECK NOT has_activex IS INITIAL.
CALL METHOD control->init_control
EXPORTING r3_application_name = 'R/3 Basis'
inplace_enabled = 'X'
register_on_close_event = 'X'
register_on_custom_event = 'X'
parent = cl_gui_container=>default_screen
IMPORTING retcode = retcode.
CALL METHOD control->get_document_proxy
EXPORTING document_type = document_type
IMPORTING document_proxy = oxc_document
retcode = retcode.
CALL METHOD oxc_document->open_activex_document
IMPORTING retcode = retcode.
CALL METHOD ocx_document->get_document_handle
IMPORTING handle = doc_handle
retcode = retcode.
CALL FUNCTION 'CONTROL_CALL_METHOD'
EXPORTING h_control = doc_handle
method = 'MyMethod'
p_count = 0.
CALL METHOD ocx_document->clsoe_activex_document
IMPORTING retcode = retcode.
I've stripped out the screen processing & error handling of the example program in order to give an overview of main calls that are needed.

Resources