Application Development and Automation 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: 
Read only

Function module

Former Member
0 Likes
1,289

Hi All

If suppose i wanna create any search help.....so im designing a selection screen where user enters the search keyword,so automatically the google search should be opened....and start searching.....

how can i do that?what function module should i use.....

thanks....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,263

Hi Asha,

Try out this way...

I am not sure but might it will work in your case...

Note : i have not checked it...

REPORT zilesh.

DATA: http_client TYPE REF TO if_http_client .

DATA: wf_string TYPE string ,

result TYPE string ,

r_str TYPE string .

DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .

PARAMETERS: search(100) LOWER CASE.

SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .

CLEAR wf_string .

CONCATENATE

'http://www.google.com/search?q='search INTO wf_string .

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = wf_string

IMPORTING

client = http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CALL METHOD http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2.

CALL METHOD http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CLEAR result .

result = http_client->response->get_cdata( ).

REFRESH result_tab .

SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .

LOOP AT result_tab INTO r_str.

WRITE:/ r_str .

ENDLOOP .

Reward points if it is useful.

ilesh

15 REPLIES 15
Read only

kiran_k8
Active Contributor
0 Likes
1,263

Asha,

By using the function module call_browser you can call www.google.com but the thing is how you will get the search key words into the googles search column.Are you working on SRM?

K.Kiran.

Read only

Former Member
0 Likes
1,263

HI,

Here are the example programs which you can use it in your program

<b>Program 1</b>



REPORT ZJURL .

* Type declarations.....................
TYPES pict_line(256) TYPE c.

* Data declarations......................
DATA :init,
      container TYPE REF TO cl_gui_custom_container,
      editor    TYPE REF TO cl_gui_textedit,
      picture   TYPE REF TO cl_gui_picture,
      pict_tab TYPE TABLE OF pict_line,
      document_viewer  TYPE REF TO i_oi_document_viewer.


PARAMETERS: URL(60) OBLIGATORY DEFAULT 'www.sap.ag'.


* In Screen 100, create container with name "PICTURE_CONTAINER"

CALL SCREEN 100.

* Dialog modules......................................
MODULE status_0100 OUTPUT.
 SET PF-STATUS 'SCREEN100'.    
  IF init is initial.
    init = 'X'.

    CREATE OBJECT:
           container  EXPORTING container_name = 'PICTURE_CONTAINER'.

    CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_DOCUMENT_VIEWER
              IMPORTING viewer = document_viewer.

    CALL METHOD document_viewer->init_viewer
              EXPORTING parent = container.

  ENDIF.


CALL METHOD document_viewer->view_document_from_url
          EXPORTING document_url = url
                    show_inplace = 'X'.


CALL METHOD document_viewer->destroy_viewer.

CALL METHOD container->free.

FREE: document_viewer, container.

ENDMODULE.

MODULE cancel INPUT.
  LEAVE TO SCREEN 0.
ENDMODULE.

<b>Program 2</b>

REPORT ZURL NO STANDARD PAGE HEADING.

DATA: BEGIN OF URL_TABLE OCCURS 10,

L(25),

END OF URL_TABLE.

URL_TABLE-L = 'http://www.lycos.com'.APPEND URL_TABLE.

URL_TABLE-L = 'http://www.hotbot.com'.APPEND URL_TABLE.

URL_TABLE-L = 'http://www.sap.com'.APPEND URL_TABLE.

LOOP AT URL_TABLE.

SKIP. FORMAT INTENSIFIED OFF.

WRITE: / 'Single click on '.

FORMAT HOTSPOT ON.

FORMAT INTENSIFIED ON.

WRITE: URL_TABLE.

HIDE URL_TABLE.

FORMAT HOTSPOT OFF.

FORMAT INTENSIFIED OFF.

WRITE: 'to go to', URL_TABLE.

ENDLOOP.

CLEAR URL_TABLE.

AT LINE-SELECTION.

IF NOT URL_TABLE IS INITIAL.

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

program = 'C:Program FilesInternet ExplorerIEXPLORE.EXE'

commandline = URL_TABLE

INFORM = ''

EXCEPTIONS

PROG_NOT_FOUND = 1.

IF SY-SUBRC <> 0.

WRITE:/ 'Cannot find program to open Internet'.

ENDIF.

ENDIF.

Regards

Sudheer

Read only

0 Likes
1,263

hii sudheer

I hav tried Program 2 but when i click the link it shows

"windows cannot find 'C:Program FiledInternet Explorer.EXE.Make sure you typed the name correctly and try again.To search for a file click start button and then click search."

E3:Unable to start a child process...

&----


*& Report ZGOOGLE

*&

&----


*&

*&

&----


REPORT ZGOOGLE NO STANDARD PAGE HEADING.

DATA: BEGIN OF URL_TABLE OCCURS 10,

L(25),

END OF URL_TABLE.

data : begin of it_vo,

search(100) type c,

end of it_vo.

selection-screen : begin of block blk1 with frame title text-001.

parameters : p_s like it_vo-search.

selection-screen : end of block blk1.

if p_s <> ''.

URL_TABLE-L = 'http://www.google.co.in'.APPEND URL_TABLE.

*URL_TABLE-L = 'http://www.hotbot.com'.APPEND URL_TABLE.

*URL_TABLE-L = 'http://www.sap.com'.APPEND URL_TABLE.

endif.

LOOP AT URL_TABLE.

SKIP. FORMAT INTENSIFIED OFF.

WRITE: / 'Single click on '.

FORMAT HOTSPOT ON.

FORMAT INTENSIFIED ON.

WRITE: URL_TABLE.

HIDE URL_TABLE.

FORMAT HOTSPOT OFF.

FORMAT INTENSIFIED OFF.

WRITE: 'to go to', URL_TABLE.

ENDLOOP.

CLEAR URL_TABLE.

AT LINE-SELECTION.

IF NOT URL_TABLE IS INITIAL.

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

program = 'C:Program FilesInternet ExplorerIEXPLORE.EXE'

commandline = URL_TABLE

INFORM = ''

EXCEPTIONS

PROG_NOT_FOUND = 1.

IF SY-SUBRC <> 0.

WRITE:/ 'Cannot find program to open Internet'.

ENDIF.

ENDIF.

thanks

asha

Read only

0 Likes
1,263

HI,

change the path for that as below.

'C:\Program Files\Internet Explorer\IEXPLORE.EXE'

rgds,

bharat.

Read only

Former Member
0 Likes
1,264

Hi Asha,

Try out this way...

I am not sure but might it will work in your case...

Note : i have not checked it...

REPORT zilesh.

DATA: http_client TYPE REF TO if_http_client .

DATA: wf_string TYPE string ,

result TYPE string ,

r_str TYPE string .

DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .

PARAMETERS: search(100) LOWER CASE.

SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .

CLEAR wf_string .

CONCATENATE

'http://www.google.com/search?q='search INTO wf_string .

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = wf_string

IMPORTING

client = http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CALL METHOD http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2.

CALL METHOD http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CLEAR result .

result = http_client->response->get_cdata( ).

REFRESH result_tab .

SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .

LOOP AT result_tab INTO r_str.

WRITE:/ r_str .

ENDLOOP .

Reward points if it is useful.

ilesh

Read only

0 Likes
1,263

Ilesh,

I checked your code,it is working but it is giving the html code as output.

K.Kiran.

Read only

0 Likes
1,263

Kiran

I hav tried Illesh program but

REPORT zgoogle.

DATA: http_client TYPE REF TO if_http_client .

DATA: wf_string TYPE string ,

result TYPE string ,

r_str TYPE string .

DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .

PARAMETERS: search(100) LOWER CASE.

SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .

CLEAR wf_string .

CONCATENATE

' http:// www.google.com/search?q='search INTO wf_string<b>.====>at this line it gives "After "' http:// www.google.com/search?q='", there must be a space or equivalent character (":", ",", ".") . . ." </b>

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = wf_string

IMPORTING

client = http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CALL METHOD http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2.

CALL METHOD http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CLEAR result .

result = http_client->response->get_cdata( ).

REFRESH result_tab .

SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .

LOOP AT result_tab INTO r_str.

WRITE:/ r_str .

ENDLOOP .

thanks

asha

Read only

0 Likes
1,263

Asha,

The word SEARCH should be in quotes,that was missing there in the code.correct it and execute.

K.Kiran.

Read only

0 Likes
1,263

Hi,

try this code.

PARAMETERS:term type string.

data:search_term TYPE string.

CONCATENATE 'http://www.google.co.in/search?hl=en&q=' term '&meta=' into search_term.

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

program = 'C:\Program Files\Internet Explorer\IEXPLORE.EXE'

commandline = search_term

INFORM = ''

EXCEPTIONS

PROG_NOT_FOUND = 1.

IF SY-SUBRC <> 0.

WRITE:/ 'Cannot find program to open Internet'.

ENDIF.

rgds,

bharat.

Read only

0 Likes
1,263

No kiran its showing error....possible error on spelling or commas.

Read only

0 Likes
1,263

Asha,

Mine is 4.7

It is the same code what he has posted but with a very minor modification and I doubt it will fulfill your requirement.

&----


*& Report ZSEARCH *

*& *

&----


*& *

*& *

&----


REPORT ZSEARCH .

DATA: http_client TYPE REF TO if_http_client .

DATA: wf_string TYPE string ,

result TYPE string ,

r_str TYPE string .

DATA: result_tab TYPE TABLE OF string.

SELECTION-SCREEN: BEGIN OF BLOCK a WITH FRAME .

PARAMETERS: search(100) LOWER CASE.

SELECTION-SCREEN: END OF BLOCK a .

START-OF-SELECTION .

CLEAR wf_string .

CONCATENATE 'http://www.google.com/search ? q=' 'search' INTO wf_string .

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = wf_string

IMPORTING

client = http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CALL METHOD http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2.

CALL METHOD http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CLEAR result .

result = http_client->response->get_cdata( ).

REFRESH result_tab .

SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .

LOOP AT result_tab INTO r_str.

WRITE:/ r_str .

ENDLOOP .

Read only

0 Likes
1,263

Thankyou so much bharat.....it has been solved.... and thankyou for all.....

Read only

0 Likes
1,263

Hi,

Thanks alot Bharath for the code snippet.It will be quite handy.

Thanks Asha.

K.Kiran.

Read only

Former Member
0 Likes
1,263

Hi Asha,

You need to change the path of the Internet explorer ...

I found the path in my system in --> program = 'C:\Program Files\Internet Explorer\IEXPLORE.EXE'

So, you also look at the path for IEXPLORE.EXE'. you might get the the IEXPLORE.EXE' in the same path and give the path over there then the program will work

Regards

Sudheer

Read only

Former Member
0 Likes
1,263

Hi Asha & Kiran,

As I don't have R/3 System now with me I can not check it but try out the below way...

Please try to correct the syntax error for URL...

CONCATENATE

'http://www.google.co.in/search?hl=en&q=' SEARCH '&btnG=Search&meta=' INTO wf_string .

Hope it will work for you...

Thanks & Regards

ilesh