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: 

How to open / View URL using ABAP

Former Member
0 Kudos

Hi All,

My requirement is to open / view an url from SAP system. I need to call some function module to do that and after i need to attached that in a Method.

The Document need to opend is stored in a DMS.

The URL is holding all details of the PDF to be opened.

Please suggest any FM / Code for doing the same.

Thanks,

SJ

4 REPLIES 4

naimesh_patel
Active Contributor
0 Kudos

Try using FM MENU_START_OBJECT_VIA_INDX to open URL


data: l_obj type SMENSAPNEW-REPORT,
      l_rep type SMENSAPNEW-REPORTTYPE,
      l_url type SMEN_BUFFI-URL.

l_obj = 'URL'.
l_rep = 'OT'.
l_url = 'www.sdn.sap.com'.

CALL FUNCTION 'MENU_START_OBJECT_VIA_INDX'
 EXPORTING
   OBJECT_NAME         = l_obj
   REPORTTYPE          = l_rep
   URL                 = l_url.

This works well to open internet URL. I never tried with the document in DMS.

Regards,

Naimesh Patel

Former Member
0 Kudos

hie satya ,

Go through the standard report saphtml_demo1.

Hope this will solve your problem .

*&---------------------------------------------------------------------*
*& Report  SAPHTML_DEMO1                                               *
*&---------------------------------------------------------------------*
REPORT  saphtml_demo1.

DATA: html_control TYPE REF TO cl_gui_html_viewer,
      my_container TYPE REF TO cl_gui_custom_container,
      fcode LIKE sy-ucomm,
      myevent_tab TYPE cntl_simple_events,
      myevent TYPE cntl_simple_event,
      edurl(2048),
      alignment TYPE i.

*****************************************************
*              CLASS cl_myevent_handler             *
*****************************************************
CLASS cl_myevent_handler DEFINITION.

  PUBLIC SECTION.
    METHODS: on_navigate_complete
               FOR EVENT navigate_complete OF cl_gui_html_viewer
               IMPORTING url.
ENDCLASS.

DATA: evt_receiver TYPE REF TO cl_myevent_handler.

SET SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'TESTHTM1'.
  SET TITLEBAR '001'.

  IF my_container IS INITIAL.

    CREATE OBJECT my_container
        EXPORTING
            container_name = 'HTML'
        EXCEPTIONS
            others = 1.
    CASE sy-subrc.
      WHEN 0.
*
      WHEN OTHERS.
        RAISE cntl_error.
    ENDCASE.
  ENDIF.

  IF html_control IS INITIAL.
    CREATE OBJECT html_control
         EXPORTING
              parent    = my_container.
    IF sy-subrc NE 0.
      RAISE cntl_error.
    ENDIF.

* register event

*************************************************************
* DON'T USE the NAVIGATE_COMPLETE event in application logic
*************************************************************
    myevent-eventid = html_control->m_id_navigate_complete.
    myevent-appl_event = 'X'.
    APPEND myevent TO myevent_tab.
    CALL METHOD html_control->set_registered_events
        EXPORTING
           events = myevent_tab.

    CREATE OBJECT evt_receiver.

    SET HANDLER evt_receiver->on_navigate_complete
                FOR html_control.

    PERFORM load_home_page.
  ENDIF.
ENDMODULE.                             " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE fcode.
    WHEN 'BACK'.
      IF NOT html_control IS INITIAL.
        CALL METHOD html_control->free.
        FREE html_control.
      ENDIF.
      IF NOT my_container IS INITIAL.
        CALL METHOD my_container->free
          EXCEPTIONS
            OTHERS = 1.
        IF sy-subrc <> 0.
*         MESSAGE E002 WITH F_RETURN.
        ENDIF.
        FREE my_container.
      ENDIF.

      LEAVE PROGRAM.

    WHEN 'HHOM'.                       " show the home page
      CALL METHOD html_control->go_home.

      CALL METHOD html_control->get_current_url
           IMPORTING
                url  = edurl.

    WHEN 'HBAK'.
      CALL METHOD html_control->go_back.

      CALL METHOD html_control->get_current_url
           IMPORTING
                url  = edurl.

    WHEN 'HFWD'.
      CALL METHOD html_control->go_forward.

      CALL METHOD html_control->get_current_url
           IMPORTING
                url  = edurl.

    WHEN 'HRFR'.
      CALL METHOD html_control->do_refresh.

      CALL METHOD html_control->get_current_url
           IMPORTING
                url  = edurl.

    WHEN 'HNAV'.
      IF NOT edurl IS INITIAL.
        CALL METHOD html_control->show_url
             EXPORTING
                  url = edurl
             EXCEPTIONS
                  cnht_error_parameter = 1
                  OTHERS = 2.
        IF sy-subrc GE 2.
          RAISE cntl_error.
        ENDIF.
      ENDIF.

    WHEN OTHERS.
      CALL METHOD cl_gui_cfw=>dispatch.

  ENDCASE.
  CLEAR fcode.
ENDMODULE.                             " USER_COMMAND_0100  INPUT

* Homepage form
FORM load_home_page.
  DATA: doc_url(80).

  CALL METHOD html_control->load_html_document
       EXPORTING
            document_id  = 'HTMLCNTL_CNHTTST1_START'
       IMPORTING
            assigned_url = doc_url
       EXCEPTIONS
            OTHERS       = 1.

  IF sy-subrc EQ 0.
    CALL METHOD html_control->show_url
         EXPORTING
              url       = doc_url.
  ENDIF.
ENDFORM.                               " LOAD_HOME_PAGE

****************************************************
*    cl_myevent_handler implementation             *
****************************************************
CLASS cl_myevent_handler IMPLEMENTATION.

*************************************************************
* DON'T USE the NAVIGATE_COMPLETE event in application logic
*************************************************************
  METHOD on_navigate_complete.
    edurl = url.
  ENDMETHOD.

ENDCLASS.

0 Kudos

Hi All,

Thanks for all your response.With the below code the problem is now solved.

CALL METHOD cl_gui_frontend_services=>execute

EXPORTING

document = l_url_doculink

EXCEPTIONS

OTHERS = 1.

Regards,

SJ

marccawood
Participant
0 Kudos

Launch any URL even an email client from ABAP/ALV:

CALL FUNCTION 'CALL_BROWSER'
    EXPORTING
      url = 'mailto:me@you.com'.