SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Insert hyperlink in ALV Grid

By Ankit Doshi, TCS

This is a simple tutorial which shows how to insert hyperlinks in the ALV Grid. On clicking the hyperlink, a web browser will open up which will point to the URL which has been configured programmatically.  

Besides the regular steps for ALV grid some additional steps needs to be followed to populate hyperlinks into the ALV grid.  

Steps to create hyperlink in ALV:  

1.       Create additional fields for the hyperlink handles in your type declaration for the final table(the table that is passed to the it_output parameter of the method set_table_for_first_display)

 

2.       Pass the appropriate handle to the web_field field of fieldcatalog.

 

3.       Create an internal table of type lvc_t_hype.

Assign an appropriate handle number and URL for a particular column and populate the internal table with this data and pass this internal table to the it_hyperlink parameter of the method set_table_for_first_display.  

               

4.       Pass the appropriate handle number while populating the list data.

Code:

*&-------------------------------------------------------------------
*& Report  YALV_HYPERLINK
*&
*&-------------------------------------------------------------------

REPORT  yalv_hyperlink.

TYPES : BEGIN OF y_dataset,
          product   TYPE char100,
          variant   TYPE char100,
          price     TYPE char100,
          pd_handle TYPE int4,
          vr_handle TYPE int4,
        END OF y_dataset.

DATA : ts_data TYPE STANDARD TABLE OF y_dataset,
       e_fcat  TYPE lvc_s_fcat,
       ts_fcat TYPE lvc_t_fcat,
       e_data  TYPE y_dataset,
       e_hype  TYPE lvc_s_hype,
       ts_hype TYPE lvc_t_hype.

DATA : ref_grid TYPE REF TO cl_gui_custom_container,
       ref_alv  TYPE REF TO cl_gui_alv_grid.

START-OF-SELECTION.

  PERFORM f_fill_data.

  PERFORM f_fill_fieldcat.

  PERFORM f_fill_hyperlink.

  CALL SCREEN 9000.

*&-------------------------------------------------------------------
*&      Form  F_FILL_DATA
*&-------------------------------------------------------------------
*       Populate the list data
*--------------------------------------------------------------------

FORM f_fill_data .

  CLEAR e_data.
  MOVE : 'iPhone'   TO e_data-product,
         'iPhone5'  TO e_data-variant,
         '$599'     TO e_data-price,
         '1'        TO e_data-pd_handle,
         '2'        TO e_data-vr_handle.

  APPEND e_data  TO ts_data.

  CLEAR e_data.
  MOVE : 'iPhone'    TO e_data-product,
         'iPhone 4S' TO e_data-variant,
         '$399'      TO e_data-price,
         '1'         TO e_data-pd_handle,
         '2'         TO e_data-vr_handle.

  APPEND e_data TO ts_data.

  CLEAR e_data.
  MOVE : 'iPhone'   TO e_data-product,
         'iPhone 4' TO e_data-variant,
         '$299'     TO e_data-price,
         '1'        TO e_data-pd_handle,
         '2'        TO e_data-vr_handle.

  APPEND e_data TO ts_data.

ENDFORM.                    " F_FILL_DATA
*&-------------------------------------------------------------------
*&      Form  F_FILL_FIELDCAT
*&-------------------------------------------------------------------
*       Populate field catalog
*--------------------------------------------------------------------
FORM f_fill_fieldcat .

  FREE ts_fcat.

  CLEAR : e_fcat.

  MOVE : 'TS_DATA'   TO e_fcat-tabname,
         'product'   TO e_fcat-fieldname,
         1           TO e_fcat-col_pos,
         1           TO e_fcat-indx_field,
         20          TO e_fcat-outputlen,
         'Product'   TO e_fcat-coltext,
         'PD_HANDLE' TO e_fcat-web_field.

  APPEND e_fcat TO ts_fcat.

  CLEAR : e_fcat.

  MOVE : 'TS_DATA'   TO e_fcat-tabname,
         'variant'   TO e_fcat-fieldname,
         2           TO e_fcat-col_pos,
         2           TO e_fcat-indx_field,
         20          TO e_fcat-outputlen,
         'Variant'   TO e_fcat-coltext,
         'VR_HANDLE' TO e_fcat-web_field.

  APPEND e_fcat TO ts_fcat.

  MOVE : 'TS_DATA'  TO e_fcat-tabname,
         'Price'    TO e_fcat-fieldname,
         3          TO e_fcat-col_pos,
         3          TO e_fcat-indx_field,
         20         TO e_fcat-outputlen,
         'Price'    TO e_fcat-coltext,
*"       Handle from the previous field catalog is carried here
*"       in order to prevent this handle to continue here pass a null
*"       value here.
         ''         TO e_fcat-web_field.

  APPEND e_fcat TO ts_fcat.

ENDFORM.                    " F_FILL_FIELDCAT
*&-------------------------------------------------------------------
*&      Module  STATUS_9000  OUTPUT
*&-------------------------------------------------------------------
*       PBO for screen 9000
*--------------------------------------------------------------------
MODULE status_9000 OUTPUT.

  SET PF-STATUS 'STATUS'.

  CREATE OBJECT ref_grid
    EXPORTING
      container_name              = 'CONT'
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.

  IF sy-subrc EQ 0.


  ENDIF.

  CREATE OBJECT ref_alv
    EXPORTING
      i_parent          = ref_grid
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5.
  IF sy-subrc <> 0.

  ENDIF.

  CALL METHOD ref_alv->set_table_for_first_display
    EXPORTING
      it_hyperlink                  = ts_hype
    CHANGING
      it_outtab                     = ts_data
      it_fieldcatalog               = ts_fcat
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.

  IF sy-subrc <> 0.

  ENDIF.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&-------------------------------------------------------------------
*&      Module  USER_COMMAND_9000  INPUT
*&-------------------------------------------------------------------
*       PAI for screen 9000
*--------------------------------------------------------------------
MODULE user_command_9000 INPUT.

  DATA ok_code TYPE sy-ucomm.

  CASE ok_code.

    WHEN 'BACK'.

      LEAVE TO SCREEN 0.

    WHEN OTHERS.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&-------------------------------------------------------------------
*&      Form  F_FILL_HYPERLINK
*&-------------------------------------------------------------------
*       To populate the hyperlink table
*--------------------------------------------------------------------
FORM f_fill_hyperlink .

  FREE ts_hype.

  CLEAR e_hype.
  MOVE : '1' TO e_hype-handle,
         'http://www.apple.com' TO e_hype-href.
  APPEND e_hype TO ts_hype.

  CLEAR e_hype.
  MOVE : '2' TO e_hype-handle,
         'http://www.apple.com/iphone' TO e_hype-href.
  APPEND e_hype TO ts_hype.

ENDFORM.                    " F_FILL_HYPERLINK
 

Final output:  

 

On clicking data in Product column you will be directed to the url http://www.apple.com  

On clicking data in Variant column you will be directed to the url http://www.apple.com/iphone

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image