Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
johannes_gilbert
Employee
Employee
0 Kudos

Introduction

The following code snippet shows how to use the CRM Reporting Framework in order to search for 1Order documents for a Business Partner.

Code Snippet(s)

TABLES:
  but000.

DATA:
* Name of the search result structure, see table crmc_q1o_obj.
  lc_result_structure_name TYPE struname,

* Structure description (RTTS) of the result structure.
  lr_struc_type_descr      TYPE REF TO cl_abap_structdescr,
* Table description (RTTS) of the result table.
  lr_table_type_descr      TYPE REF TO cl_abap_tabledescr,
  lr_data_ref              TYPE REF TO data,

* Use for specifying a kind of search term.
  lt_search_tab            TYPE  crmt_name_value_pair_tab,
* (see above)
  ls_search_entry          TYPE  crmt_name_value_pair,
* The GUIDs of the objects found corresponding to the
* seatch term(s).
  lt_guidlist_search       TYPE  crmt_bsp_objectkey_tab,
  lt_return                TYPE bapiret2_tab,
  lv_partner_message       TYPE crmt_boolean.

FIELD-SYMBOLS: <fs_result> TYPE any,
               <fs_result_tab> TYPE STANDARD TABLE.

PARAMETERS: p_partno TYPE but000-partner.


lc_result_structure_name = 'CRMST_QUERY_R_1ORDER_BTIL' ##NO_TEXT.

* Get a description of the result structure.
lr_struc_type_descr ?= cl_abap_structdescr=>describe_by_name( lc_result_structure_name ). "#EC NOTEXT
CREATE DATA lr_data_ref TYPE HANDLE lr_struc_type_descr.
ASSIGN lr_data_ref->* TO <fs_result>.
lr_table_type_descr = cl_abap_tabledescr=>create( lr_struc_type_descr ).
CREATE DATA lr_data_ref TYPE HANDLE lr_table_type_descr.
ASSIGN lr_data_ref->* TO <fs_result_tab>.

ls_search_entry-name = 'BU_PARTNER' ##NO_TEXT.
ls_search_entry-value = p_partno.
INSERT ls_search_entry INTO TABLE lt_search_tab.

* Search for all objects.
CALL FUNCTION 'CRM_BSP_OIC_1O_SEARCH_FROM_RF'
  EXPORTING
    it_search_tab      = lt_search_tab
  IMPORTING
    et_guidlist        = lt_guidlist_search
    et_return          = lt_return
    ev_partner_message = lv_partner_message
  EXCEPTIONS
    date_not_correct   = 1
    no_card_type       = 2
    no_card_no         = 3
    no_program_id      = 4
    OTHERS             = 5.

IF sy-subrc <> 0.
  RETURN.
ENDIF.

* Read the found results.
CALL FUNCTION 'CRM_BSP_OIC_1O_READ_FROM_RF'
  EXPORTING
    it_object_key            = lt_guidlist_search
    iv_screen_structure_name = lc_result_structure_name
    iv_refresh_headeredition = abap_false
    iv_call_authority_badi   = abap_false
    iv_avoid_authorization   = abap_true
  IMPORTING
    et_screen_structure      = <fs_result_tab>.

Explanation

Looking at table CRMC_Q1O_OBJ you will find out that there are several entries for 'BTQ1ORDER' which refers to 1Order. Without going into detail this tables provides the information what structure type will be used for the search result when querying for documents using 'BTQ1ORDER'. This structure name is 'CRMST_QUERY_R_1ORDER_BTIL'. If you don't like to hard-code this you could thus, also provide a dynamic determination code.

Using this structure name we determine a structure as well as a table definition in order to get a field symbol for both. The actual query or search term is specified within itab 'lt_search_tab'. It is just a key-value table. Function module CRM_BSP_OIC_1O_SEARCH_FROM_RF searches for all corresponding documents and returns their GUIDs. Function module CRM_BSP_OIC_1O_READ_FROM_RF is used to get information for each of the found search results. Here structure 'CRMST_QUERY_R_1ORDER_BTIL' comes again in play as the information gathered has exactly this structure.

Take a look into table CRMC_Q1O_OBJ. There are other objects to query for too.

Availability

KeyValue
Software ComponentBBPCRM                                                                  
Requires Client-Side Software LibraryNo
Code Snippet is OS dependentNo