Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OLE - Search for a string in Outlook folders

Former Member
0 Kudos
331

Hi everyone,

I'm using the Application.AdvancedSearch objekt to search for a string in the Outlook folder "Inbox'.

I' having trouble passing the filter parameter. With a pair of Concatenate instructions I've built it up in order to pass it in the precise characters chain (see Microsoft reference for Application.AdvancedSearch Method :http://msdn.microsoft.com/en-us/library/bb219884.aspx)

I've already testet that it works without passing the filter parameter, or with an empty filter paramenter. Only by passing it it doesn't work any more, and I don't know if it depends on the passed string (which anyhow by debugging totally corresponds to the string in the microsoft reference).

It would be greatful if anyone has an idea about it.

Here my code: by the way, I testet with both of the Methods : 'ci_phrasematch' and 'like' , without success.

with 'ci_phrasematch':

lv_filter = 'Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " ci_phrasematch' .

concatenate lv_filter '''' into lv_filter SEPARATED BY space.

concatenate lv_filter 'Hallo' '''' '"' INTO lv_filter.

with 'like'

lv_filter = 'Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like' .

concatenate lv_filter '''' into lv_filter SEPARATED BY space.

concatenate lv_filter '%Hallo%' '''' '"' INTO lv_filter.

CALL METHOD OF OUT 'ADVANCEDSEARCH' = SEARCH EXPORTING #1 = 'Inbox' #2 = LV_FILTER ."#3 = 'True' #4 = 'MySearch'.

Thank you,

Christian

1 ACCEPTED SOLUTION

former_member182670
Contributor
0 Kudos
114

Hi,

Chr(34) in examples from Microsoft stands for ASCII 34 - double quote. You shouldn't concatenate it in ABAP literally.

It works just fine:

INCLUDE ole2incl.

DATA outlook TYPE ole2_object.
DATA search TYPE ole2_object.
DATA results TYPE ole2_object.
DATA count TYPE i.

DATA filter TYPE string.
DATA scope TYPE string.
CREATE OBJECT outlook 'Outlook.Application'.

check sy-subrc = 0.

filter = '"urn:schemas:httpmail:subject" like ''%Test%'''.
scope = '''Inbox'''.
CALL METHOD OF
    outlook
    'AdvancedSearch' = search
  EXPORTING
    #1               = scope
    #2               = filter
    #3               = 'False'.
check sy-subrc = 0.

GET PROPERTY OF search 'Results' = results.
check sy-subrc = 0.

GET PROPERTY OF results 'Count' = count.
check sy-subrc = 0.

WRITE count.

2 REPLIES 2

former_member182670
Contributor
0 Kudos
115

Hi,

Chr(34) in examples from Microsoft stands for ASCII 34 - double quote. You shouldn't concatenate it in ABAP literally.

It works just fine:

INCLUDE ole2incl.

DATA outlook TYPE ole2_object.
DATA search TYPE ole2_object.
DATA results TYPE ole2_object.
DATA count TYPE i.

DATA filter TYPE string.
DATA scope TYPE string.
CREATE OBJECT outlook 'Outlook.Application'.

check sy-subrc = 0.

filter = '"urn:schemas:httpmail:subject" like ''%Test%'''.
scope = '''Inbox'''.
CALL METHOD OF
    outlook
    'AdvancedSearch' = search
  EXPORTING
    #1               = scope
    #2               = filter
    #3               = 'False'.
check sy-subrc = 0.

GET PROPERTY OF search 'Results' = results.
check sy-subrc = 0.

GET PROPERTY OF results 'Count' = count.
check sy-subrc = 0.

WRITE count.

0 Kudos
114

Hi,

I am practically doing the same thing as you have shown here, but somehow the AdvancedSearch method is never called.

I have tried with several possibilities like

  • With Filter,
  • Without Filter,
  • Getting Default folder name from Session.GetDefaultFolder( ).FolderPath
  • Using different folders etc.

Do you think I am missing anything here?