Implementing events of SAP VE Viewer inside SAP GUI or Accessing Metadata of an RH file for the node selected

Objective:

In my previous blog, I gave an idea about how to embed SAP VE Viewer inside SAP GUI and open an RH file in it.  In this blog, I will try to explain, how we can interact with the file present in VE Viewer, implement events  and display the selected node’s metadata information on the SAP GUI.

Pre-requisites:

  • Install SAP VE Viewer on your laptop/desktop. Here is the link from where you can download
  • Implement the classes and methods mentioned in my previous blog
  • Before going into detail, let me help you understand couple of things.
    • Metadata
      • What is Metadata for a model? It is known as structured data which describes and helps to find data resources inside the model. For example, if you a huge model which is made of different components. In order to identify easily, users would define some additional data under the section Metadata for a model like PART_NUMBER, MODEL_ID, PART_DESCRIPTION, WEIGHT, etc.
      • In the below snapshot,  I have selected SEAT of the vehicle, it has got highlighted with RED color on the model, and you will see the metadata of the same on the left hand bottom corner under section File Attributes, Material Info.

                                                      Metadata SEAT selection.jpg

      • You can view the same in a different manner, by right click on the part and select Object properties. You will see the output in below format.

                                                     Metadata output.jpg    

  • Events available for GAC viewer to access the data inside SAP Gui

In my previous blog, I said that we use “DeepViewForGAC 1.0 Type Library” Active-X control for accessing inside SAP Gui. Here is how you can view the Active-X using Active-X/COM inspector. If you expand  “DeepViewForGAC 1.0 Type Library”, under the Event interfaces, you can view all the events provided.

          GAC Viewer events.jpg

We will be using SAP_VISUALIZATION event in this blog in order to access the data.

Programming logic:

In order to achieve our objective, first we need to enhance the class we have created in the last blog by adding few attributes and implementing some methods.

(Please note: Class creation is done in my previous blog. Please refer it to before starting the programming logic for this blog)

Class ZCL_GUI_SVE_CONTROL changes:

  • Add new attributes to the class in the attributes tab as shown below:

           Attributes addition.jpg

  • Create a new event SAP_VISUALIZATION in the EVENTS tab and Add a parameter to it VALUE of type STRING

             SAP_VISUALIZATION event.jpg

         Event parameter addition.jpg

  • Now, implement the SET_REGISTERED_EVENTS by selecting the method and  clicking on the REDEFINE button

         Redefine SET_REGISTERED_EVENTS.jpg

  • In this step, we are going to register the EVENT we have declared in the above step inside this method. Add the following code inside the SET_REGISTERED_EVENTS.

DATA: simple_event TYPE cntl_simple_event, “// event

          ex_event     TYPE cntl_event,“// eventid, is_shellevent

                     events_ex TYPE cntl_events“// table

*   map simple_event into ex_event, append to events_ex

  LOOP AT events INTO simple_event.

    CASE simple_eventeventid.

      WHEN me->evt_sap_visualization.

        ex_eventeventid = me->evt_sap_visualization.

        ex_eventis_shellevent = ‘ ‘.

*         check for system / application event

        IF simple_eventappl_event IS INITIAL.

          ex_eventis_systemevent = ‘X’.

        ENDIF.

        APPEND ex_event TO events_ex.

      WHEN OTHERS.

        ex_eventeventid = simple_eventeventid.

        ex_eventis_shellevent = ‘ ‘.

        IF simple_eventappl_event IS INITIAL.

          ex_eventis_systemevent = ‘X’.

        ENDIF.

        APPEND ex_event TO events_ex.

*        RAISE illegal_event_combination.

    ENDCASE.

  ENDLOOP.

  CALL METHOD me->set_registered_events_ex

    EXPORTING

      eventtab                  = events_ex

    EXCEPTIONS

      cntl_error                = 1

      cntl_system_error         = 2

      illegal_event_combination = 3

      OTHERS                    = 4.

  CASE sysubrc.

    WHEN 0.

    WHEN 1.

      RAISE cntl_error.

    WHEN 2.

      RAISE cntl_system_error.

    WHEN 3.

      RAISE illegal_event_combination.

    WHEN OTHERS.

      RAISE cntl_error.

  ENDCASE.

  registered_simple_events[] = events.

  • Create a new method GET_SAP_VISUALIZATION_VALUE with the following signature and code inside it for reading the value of the node selected.

             GET_SAP_VISUALIZATION_VALUE addition.jpg                                                               

              Visualization value method signature, code.jpg

  • Similar to SET_REGISTERED_EVENTS method,  redefine the standard DISPATCH method which was inherited from Superclass and add the following code in it.

                Dispatch method code.jpg

Now,  create a new program “Z_SVE_READ_NODE”  to accept a file name, metadata field name as a selection screen parameters  and then use the class created above for displaying the file in VE Viewer inside SAP GUI.

Z_SVE_TEST_PROGRAM code:

REPORT  z_sve_read_node.

TYPE-POOLS: cntl.

CONSTANTS:

  gc_container TYPE char128 VALUE ‘CUSTOM_CONTROL_0100’.

DATA:

  obj_container TYPE REF TO cl_gui_custom_container,

  obj_ve TYPE REF TO zcl_gui_sve_control,

  g_syucomm TYPE syucomm.

DATA lw_vindex_value TYPE string.

DATA lw_visualvalue  TYPE string.

DATA:

  g_loadsingleresult TYPE string,

  g_single_view TYPE string.

DATA:

*  g_xmlforkey TYPE string.

  g_metadata  TYPE string.

DATA:

  i_events TYPE cntl_simple_events,

  wa_events TYPE cntl_simple_event.

DATA: editor_300           TYPE REF TO cl_gui_textedit,

      editor_300_container TYPE REF TO cl_gui_custom_container.

PARAMETERS:

* P_FNAME is the file name

  p_fname TYPE dxfieldslongpath DEFAULT ‘C:\Temp\rh.rh’ OBLIGATORY,

* P_ANAME is the Metadata field path, name

  p_aname TYPE string DEFAULT ‘File Attributes\\DESIGNATION’ OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  PERFORM f4_filename CHANGING p_fname.

*———————————————————————-*

*       CLASS lcl_application DEFINITION

*———————————————————————-*

CLASS lcl_application DEFINITION.

  PUBLIC SECTION.

    METHODS:

    handle_sap_visualization   FOR EVENT sap_visualization

     OF zcl_gui_sve_control.

ENDCLASS.                    “lcl_application DEFINITION

*———————————————————————-*

*       CLASS lcl_application IMPLEMENTATION

*———————————————————————-*

CLASS lcl_application IMPLEMENTATION.

  METHOD handle_sap_visualization.

    CALL METHOD obj_ve->get_sap_visualization_value

      IMPORTING

        value = g_metadata.

* Need to set a temporary value for the OK CODE to retrieve the value

* read succesfully.

    CALL METHOD cl_gui_cfw=>set_new_ok_code

      EXPORTING

        new_code = ‘ABC’.

  ENDMETHOD.                    “handle_sap_visualization

ENDCLASS.                    “lcl_application IMPLEMENTATION

DATA: obj_application TYPE REF TO lcl_application.

START-OF-SELECTION.

  CALL SCREEN 100.

*&———————————————————————*

*&      Module  STATUS_0100  OUTPUT

*&———————————————————————*

MODULE status_0100 OUTPUT.

* Set the Ok code for BACK, EXIT and CANCEL user command

  SET PF-STATUS ‘STATUS_0100’.

* Set the title bar text “SAP VE Viewer inside GUI”

  SET TITLEBAR ‘TITLE_0100’.

  IF obj_application IS INITIAL.

    CREATE OBJECT obj_application.

  ENDIF.

  IF obj_container IS INITIAL.

    CREATE OBJECT obj_container

      EXPORTING

*       PARENT =

        container_name = gc_container

*       STYLE =

*       LIFETIME = lifetime_default

*       REPID =

*       DYNNR =

*       NO_AUTODEF_PROGID_DYNNR =

      EXCEPTIONS

        cntl_error                  = 1

        cntl_system_error           = 2

        create_error                = 3

        lifetime_error              = 4

        lifetime_dynpro_dynpro_link = 5

        OTHERS                      = 6 .

    IF sysubrc <> 0.

      MESSAGE ID symsgid TYPE symsgty NUMBER symsgno WITH symsgv1 symsgv2 symsgv3 symsgv4.

    ENDIF.

    CREATE OBJECT obj_ve

      EXPORTING

*        clsid              = clsid

*        lifetime           = lifetime_default

*        shellstyle         = shellstyle

         parent             = obj_container

*        autoalign          = ‘x’

*        licensekey         = licensekey

*        name               = name

      EXCEPTIONS

        cntl_error         = 1

        cntl_system_error  = 2

        create_error       = 3

        lifetime_error     = 4

        parent_is_splitter = 5

        OTHERS             = 6.

    IF sysubrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    CLEAR g_single_view.

    IF p_fname IS NOT INITIAL.

      CONCATENATE ‘<SINGLE_VIEW FILEPATH=”‘

                  p_fname

                  ‘” ID_FIELD=”‘

                  P_ANAME

                  ‘” />’

             INTO g_single_view.

    ENDIF.

    CALL METHOD obj_ve->sap_load_viewer_single

      EXPORTING

        single_view            = g_single_view

*        action                 = ‘CREATE_LAYER’

      IMPORTING

        result                 = g_loadsingleresult

      EXCEPTIONS

        error_cntl_call_method = 1.

    IF sysubrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ELSE.

    ENDIF.

    SET HANDLER obj_application->handle_sap_visualization FOR obj_ve.

* Register the EVENT SAP_VISUALIZATION

* Value ‘7’ is depicted from ActiveX controller Events list

    CLEAR wa_events.

    wa_eventseventid = ‘7’.

    wa_eventsappl_event = .

    APPEND wa_events TO i_events.

    CALL METHOD obj_ve->set_registered_events

      EXPORTING

        events = i_events.

  ENDIF.

  IF editor_300 IS INITIAL.

* This container is added to display the Attributes of the node selected

*   create control container

    CREATE OBJECT editor_300_container

      EXPORTING

        container_name              = ‘CONT_EDITOR’

      EXCEPTIONS

        cntl_error                  = 1

        cntl_system_error           = 2

        create_error                = 3

        lifetime_error              = 4

        lifetime_dynpro_dynpro_link = 5.

    CREATE OBJECT editor_300

      EXPORTING

        parent                     = editor_300_container

        wordwrap_mode              = cl_gui_textedit=>wordwrap_at_fixed_position

        wordwrap_position          = 72

        wordwrap_to_linebreak_mode = cl_gui_textedit=>true.

    CALL METHOD editor_300->set_toolbar_mode

      EXPORTING

        toolbar_mode = editor_300->false.

    CALL METHOD editor_300->set_statusbar_mode

      EXPORTING

        statusbar_mode = editor_300->false.

* display

    CALL METHOD editor_300->set_readonly_mode

      EXPORTING

        readonly_mode = 1

      EXCEPTIONS

        OTHERS        = 1.

  ENDIF.

  CALL METHOD editor_300->set_textstream

    EXPORTING

      text = g_metadata.

ENDMODULE.                 ” STATUS_0100  OUTPUT

*&———————————————————————*

*&      Module  USER_COMMAND_0100  INPUT

*&———————————————————————*

MODULE user_command_0100 INPUT.

  IF g_syucomm EQ ‘BACK’ OR

     g_syucomm EQ ‘CANCEL’.

    IF obj_ve IS NOT INITIAL.

      CALL METHOD obj_ve->free.

      CLEAR obj_ve.

    ENDIF.

    IF obj_container IS NOT INITIAL.

      CALL METHOD obj_container->free.

      CLEAR obj_container.

    ENDIF.

    LEAVE TO SCREEN 0.

  ELSEIF g_syucomm EQ ‘EXIT’.

    LEAVE PROGRAM.

  ENDIF.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT

*&———————————————————————*

*&      Form  F4_FILENAME

*&———————————————————————*

FORM f4_filename  CHANGING pr_fname.

  DATA i_path     TYPE dxfieldslongpath.

  DATA filemask   TYPE dxfieldsfilemask.

  DATA o_path     TYPE dxfieldslongpath.

  DATA abend_flag TYPE dxfieldsabendflag.

  MOVE ‘C:\’ TO i_path.

  DATA: lwa_file_table TYPE file_table,

       lt_file_table  TYPE filetable.

  DATA multiselection    TYPE abap_bool.

*  DATA file_table        TYPE filetable.

  DATA rc                TYPE i.

*  DATA USER_ACTION       TYPE I.

*  DATA FILE_ENCODING     TYPE ABAP_ENCODING.

  cl_gui_frontend_services=>file_open_dialog(

     EXPORTING

       window_title            = ‘File Selection’

*     default_extension       = default_extension

       default_filename        = ‘C:\TEMP\RH.RH’ ” default_filename

*      file_filter             = file_filter

*      with_encoding           = with_encoding

*      initial_directory       = initial_directory

       multiselection          = abap_false

    CHANGING

      file_table              = lt_file_table

      rc                      = rc

*      user_action             = user_action

*      file_encoding           = file_encoding

    EXCEPTIONS

      file_open_dialog_failed = 1

      cntl_error              = 2

      error_no_gui            = 3

      not_supported_by_gui    = 4

      OTHERS                  = 5

         ).

  IF sysubrc <> 0.

*   Implement suitable error handling here

  ELSE.

    READ TABLE lt_file_table INTO lwa_file_table INDEX 1.

    MOVE lwa_file_tablefilename TO pr_fname.

  ENDIF.

ENDFORM.                    ” F4_FILENAME

Snapshots of Program output:

            Selection Screen

Selection screen.jpg

           Program output

           VE Viewer with  node selected.jpg

Please note:

  • Screen 0100 is created inside this program with Custom Control “CUSTOM_CONTROL_0100 ” for displaying the VE viewer, “CONT_EDITOR” for displaying the Text editor  and OK CODE is handled by using variable “G_SYUCOMM”.
  • PF STATUS “STATUS_0100” is created with commonly used user command BACK, EXIT, CANCEL.
  • Title bar “TITLE_0100” is created with text “SAP VE Viewer inside GUI
  • In the same way we have implemented the event SAP_VISUALIZATION, we can implement for other events like SAP_LOAD_DONE, SAP_VISUAL_INDEX.

References:

http://scn.sap.com/people/thomas.jung/blog/2005/05/11/using-classic-activex-controls-in-the-abap-control-framework

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Christof Ochmann

    Hello,

    thanks a lot for this article, it’s very helpful.

    I’ve loaded an assembly into the viewer with the SAP_LOAD_VIEWER_ASSEMBLY method in the hope that SAP_VISUALIZATION event will also be fired, but the ActiveX Control does not receive any event from the viewer by selecting an object.

    It’s generally not possible yet for the viewer to fire SAP_VISUALIZATION events on objects loaded with the method SAP_LOAD_VIEWER_ASSEMBLY?

    Or what must I consider?

    Regards, Chris.

    (0) 
    1. Christof Ochmann

      I’ve found out that the SAP_LOAD_DONE event has been skipped:

      Active-X shellId 247 tried to fire event 2 while token is at server => skipped event

      Does anybody know what causes this problem?

      (0) 

Leave a Reply