I have a requirement wherein I have to filter CHANGED_AT from CRM_ORDER_READ.
I used the dynamic query as follows:
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->load_component_set( 'ONEORDER' ).
lr_qs ?= cl_crm_bol_dquery_service=>get_instance( 'BTQSrvOrd' ).
lr_qs->set_query_parameters( lt_param ).
lr_qs->ADD_SELECTION_PARAM( iv_attr_name = 'CHANGED_AT'
iv_sign = 'I'
iv_option = 'GT'
iv_low = '20171127000000' ).
lr_result = lr_qs->get_query_result( ).
But the result is null though there are entries.
I found the blogs regarding the same issue but none solved the issue. Is the query correct?
Or is there any other way to filter CHANGED_AT?
Complete Code:
*"----------------------------------------------------------------------
INCLUDE: ztest_rfc_incl,
crm_object_kinds_con,
crm_object_names_con.
TYPES:
BEGIN OF ty_but000,
name_org1 TYPE bu_nameor1,
name_org2 TYPE bu_nameor2,
partner_guid TYPE bu_partner_guid,
END OF ty_but000,
BEGIN OF ty_tickets,
guid TYPE crmt_object_guid,
object_id TYPE crmt_object_id,
END OF ty_tickets,
BEGIN OF ty_ibint,
instance TYPE ib_instance,
descr TYPE ib_inst_descr,
END OF ty_ibint.
FIELD-SYMBOLS: <f_guid> TYPE crmt_object_guid,
<f_result> TYPE znasm_workorders,
<f_items_result> TYPE znasm_workorderitems,
<f_data> TYPE any,
<f_but000> TYPE ty_but000,
<f_ticket> TYPE ty_tickets,
<f_ibint> TYPE ty_ibint.
FIELD-SYMBOLS: <f_orderadm_h> TYPE crmt_orderadm_h_wrk,
<f_orderadm_i> TYPE crmt_orderadm_i_wrk,
<f_higher_item> TYPE crmt_orderadm_i_wrk,
<f_sales> TYPE crmt_sales_wrk,
<f_customer_h> TYPE crmt_customer_h_wrk,
<f_customer_i> TYPE crmt_customer_i_wrk,
<f_appointment> TYPE crmt_appointment_wrk,
<f_text> TYPE crmt_text_wrk,
<f_lines> TYPE tline,
<f_schedlin> TYPE crmt_schedlin_wrk,
<f_partner> TYPE crmt_partner_external_wrk,
<f_service_os> TYPE crmt_srv_osset_wrk,
<f_refobj> TYPE crmt_refobj_wrk,
<f_status> TYPE crmt_status_wrk,
<f_status_h> TYPE crmt_status_h_wrk,
<f_schedlin_i> TYPE crmt_schedlin_i_wrk,
<f_doc_flow> TYPE crmt_doc_flow_wrk.
DATA:
lt_status_filter TYPE rsdsselopt_t,
ls_status_filter TYPE rsdsselopt,
lt_header_guids TYPE crmt_object_guid_tab,
lt_requested_objects TYPE crmt_object_name_tab,
lr_dref TYPE REF TO data,
lv_log_handle TYPE balloghndl,
lv_or_flag TYPE boolean,
lv_cnt TYPE i,
lt_attachments TYPE zsm_attachments_tab,
ls_attachments TYPE zsm_attachments.
DATA:
lt_ibint TYPE TABLE OF ty_ibint,
lt_but000 TYPE TABLE OF ty_but000,
lt_tickets TYPE TABLE OF ty_tickets,
lt_orderadm_h TYPE crmt_orderadm_h_wrkt,
lt_opport_h TYPE crmt_opport_h_wrkt,
lt_orderadm_i TYPE crmt_orderadm_i_wrkt,
lt_sales TYPE crmt_sales_wrkt,
lt_customer_h TYPE crmt_customer_h_wrkt,
lt_customer_i TYPE crmt_customer_i_wrkt,
lt_appointment TYPE crmt_appointment_wrkt,
lt_text TYPE crmt_text_wrkt,
lt_schedlin TYPE crmt_schedlin_wrkt,
lt_partner TYPE crmt_partner_external_wrkt,
lt_shipto TYPE crmt_partner_external_wrkt,
lt_refobj TYPE crmt_refobj_wrkt,
lt_status TYPE crmt_status_wrkt,
lt_status_temp TYPE crmt_status_wrkt,
lt_schedlin_i TYPE crmt_schedlin_i_wrkt,
lt_doc_flow TYPE crmt_doc_flow_wrkt.
*-----------------------------------------------------------
" Create the filter query
*-----------------------------------------------------------
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->load_component_set( 'ONEORDER' ).
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = iv_ship_to
IMPORTING
output = iv_ship_to.
*Get and prepare dynamic query service.
lr_qs ?= cl_crm_bol_dquery_service=>get_instance( 'BTQSrvOrd' ).
IF lr_qs IS NOT INITIAL.
*build object id query
PERFORM add_to_selection_param USING it_order
'OBJECT_ID'
CHANGING lr_qs
lv_query_exists.
***status query build
lt_status_filter = it_status.
* Filter on open and in progress orders
IF it_status IS INITIAL."
MOVE 'E0002ZRPM_H' TO ls_status_filter-low. "Pending Customer
MOVE 'I' TO ls_status_filter-sign.
MOVE 'EQ' TO ls_status_filter-option.
APPEND ls_status_filter TO lt_status_filter.
MOVE 'E0003ZRPM_H' TO ls_status_filter-low. "Requires Approval
MOVE 'I' TO ls_status_filter-sign.
MOVE 'EQ' TO ls_status_filter-option.
APPEND ls_status_filter TO lt_status_filter.
MOVE 'E0009ZRPM_H' TO ls_status_filter-low. "PM In Progress
MOVE 'I' TO ls_status_filter-sign.
MOVE 'EQ' TO ls_status_filter-option.
APPEND ls_status_filter TO lt_status_filter.
ENDIF.
PERFORM add_to_selection_param USING lt_status_filter
'STATUS_COMMON'
CHANGING lr_qs
lv_query_exists.
*date query build
PERFORM add_to_selection_param USING it_date_range
'POSTING_DATE' "'DATE_RANGE'
CHANGING lr_qs
lv_query_exists.
*build ship to party queries
PERFORM add_to_selection_param USING it_ship_to
'BU_PARTNER'
CHANGING lr_qs
lv_query_exists.
PERFORM add_to_selection_param USING it_sold_to
'SOLD_TO_PARTY'
CHANGING lr_qs
lv_query_exists.
*build assigned to queries
PERFORM add_to_selection_param USING it_assigned_to
'CREATED_BY'
CHANGING lr_qs
lv_query_exists.
PERFORM add_to_selection_param USING it_territory
'SERVICE_ORG'
CHANGING lr_qs
lv_query_exists.
PERFORM add_to_selection_param USING it_process_type
'PROCESS_TYPE'
CHANGING lr_qs
lv_query_exists.
ELSE.
RETURN.
ENDIF.
CHECK lv_query_exists EQ abap_true.
* Set Query Parameters.
IF iv_max_hits IS NOT INITIAL.
ls_param-name = 'MAX_HITS'.
ls_param-value = iv_max_hits.
APPEND ls_param TO lt_param.
ENDIF.
lr_qs->set_query_parameters( lt_param ).
lr_qs->ADD_SELECTION_PARAM( iv_attr_name = 'CHANGED_AT'
iv_sign = 'I'
iv_option = 'GT'
iv_low = '20171127000000' ).
*Execute Query and retrieve result
lr_result = lr_qs->get_query_result( ).
*
CHECK lr_result IS BOUND.
*Use Iterator to access entities in query result
lr_iter ?= lr_result->get_iterator( ).
*
* Get the first record from Collection.
lr_entity = lr_iter->get_first( ).
WHILE lr_entity IS BOUND.
*Access Attributes of Business object.
* lv_object_id_fm = lr_entity->get_property_as_string( 'OBJECT_ID' ).
IF ( lr_entity->get_property_as_string( 'CONCATSTATUSER' ) EQ 'PM Complete'
OR lr_entity->get_property_as_string( 'CONCATSTATUSER' ) EQ 'Cancelled' )." and ( sy-uname ne 'HASAXENA.EXT' ).
lr_entity = lr_iter->get_next( ).
CONTINUE.
ENDIF.
lr_dref = lr_entity->get_property( 'GUID' ).
ASSIGN lr_dref->* TO <f_guid>.
INSERT <f_guid> INTO TABLE lt_header_guids.
APPEND INITIAL LINE TO et_result ASSIGNING <f_result>.
lr_dref = lr_entity->get_property( 'OBJECT_ID' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-workorder = <f_data>.
lr_dref = lr_entity->get_property( 'SOLD_TO_PARTY' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-kunnr = <f_data>.
lr_dref = lr_entity->get_property( 'CONTACT_PERSON' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-contact = <f_data>.
lr_dref = lr_entity->get_property( 'SOLD_TO_PARTY_LIST' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-sold_party_name = <f_data>.
lr_dref = lr_entity->get_property( 'NET_VALUE' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-price = <f_data>.
lr_dref = lr_entity->get_property( 'PROCESS_TYPE' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-type = <f_data>.
lr_dref = lr_entity->get_property( 'CREATED_BY' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-assignedto = <f_data>.
lr_dref = lr_entity->get_property( 'SERVICE_ORG' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-territory = <f_data>.
lr_dref = lr_entity->get_property( 'PO_NUMBER_SOLD' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-customer_po = <f_data>.
lr_dref = lr_entity->get_property( 'VALID_FROM' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-startdate = <f_data>.
lr_dref = lr_entity->get_property( 'VALID_TO' ).
ASSIGN lr_dref->* TO <f_data>.
<f_result>-enddate = <f_data>.
lr_entity = lr_iter->get_next( ).
ENDWHILE.
*-----------------------------------------------------------
" Read additional data for result list
*-----------------------------------------------------------
IF lt_header_guids IS NOT INITIAL.
* fill internal tables
INSERT gc_object_name-orderadm_h INTO TABLE lt_requested_objects.
INSERT gc_object_name-orderadm_i INTO TABLE lt_requested_objects.
INSERT gc_object_name-status INTO TABLE lt_requested_objects.
INSERT gc_object_name-partner INTO TABLE lt_requested_objects.
INSERT gc_object_name-doc_flow INTO TABLE lt_requested_objects.
INSERT gc_object_name-refobj INTO TABLE lt_requested_objects.
INSERT gc_object_name-schedlin INTO TABLE lt_requested_objects.
INSERT gc_object_name-schedlin_i INTO TABLE lt_requested_objects.
INSERT gc_object_name-appointment INTO TABLE lt_requested_objects.
INSERT gc_object_name-texts INTO TABLE lt_requested_objects.
INSERT gc_object_name-sales INTO TABLE lt_requested_objects.
INSERT gc_object_name-customer_i INTO TABLE lt_requested_objects.
INSERT gc_object_name-customer_h INTO TABLE lt_requested_objects.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_header_guids
iv_mode = 'C'
it_requested_objects = lt_requested_objects
iv_only_spec_items = iv_header_only
iv_no_auth_check = 'X'
IMPORTING
et_orderadm_h = lt_orderadm_h
et_orderadm_i = lt_orderadm_i
et_sales = lt_sales
et_customer_h = lt_customer_h
et_customer_i = lt_customer_i
et_appointment = lt_appointment
et_text = lt_text
et_schedlin = lt_schedlin
et_partner = lt_partner
et_refobj = lt_refobj
et_status = lt_status
et_schedlin_i = lt_schedlin_i
et_doc_flow = lt_doc_flow
CHANGING
cv_log_handle = lv_log_handle
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7.
ENDIF.
FORM add_to_selection_param USING p_selopt TYPE rsdsselopt_t
VALUE(p_attr_name)
CHANGING lr_qs TYPE REF TO cl_crm_bol_dquery_service
p_query_exists TYPE boolean.
FIELD-SYMBOLS: <f_selopt> TYPE rsdsselopt.
DATA: lv_low TYPE string,
lv_high TYPE string.
LOOP AT p_selopt ASSIGNING <f_selopt>.
IF <f_selopt>-low IS NOT INITIAL.
lv_low = <f_selopt>-low.
lv_high = <f_selopt>-high.
* *Add selected parameters or criteria .
lr_qs->add_selection_param( iv_attr_name = p_attr_name
iv_sign = <f_selopt>-sign
iv_low = lv_low
iv_option = <f_selopt>-option
iv_high = lv_high ).
p_query_exists = abap_true.
ENDIF.
ENDLOOP.
ENDFORM.
Maybe it is because of the data type?
instead of
maybe try