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: 

Call transaction in ALV Report Using OOPS

spartans007
Participant
0 Kudos

In my report i am displaying the Purchase Orders. On click of the particular PO Number i want to call transaction ME23N and open the particular Purchase order Clicked. Below is my Code. Can some help me to add a link to the PO Numbers to Call transaction.

 DATA: lo_gr_alv       TYPE REF TO cl_salv_table,
        lo_gr_functions TYPE REF TO cl_salv_functions_list.

  DATA: "lo_selections type ref to cl_salv_selections,
    lo_columns TYPE REF TO cl_salv_columns,
    lo_column  TYPE REF TO cl_salv_column_table.

  DATA: lo_header  TYPE REF TO cl_salv_form_layout_grid,
        lo_h_label TYPE REF TO cl_salv_form_label,
        lv_text    TYPE char100.

*Create alv object.
  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = lo_gr_alv
        CHANGING
          t_table      = gt_sel.

    CATCH cx_salv_msg.
  ENDTRY.


  lo_gr_alv->set_screen_status( pfstatus      = 'STANDARD_FULLSCREEN'
                                report        = 'SAPLSLVC_FULLSCREEN'
                                set_functions = lo_gr_alv->c_functions_all
                                  ).

* Show all alv functions.
  lo_gr_functions = lo_gr_alv->get_functions( ).
  lo_gr_functions->set_all( abap_true ).

* Display alv
  lo_gr_alv->display( ).
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Same as Ali -- minus call to ME23N --, this is a standalone demo/minimal reproducible example of HOTSPOT with CL_SALV_TABLE (just run it, data comes from the demo table SBOOK):

REPORT.
CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    METHODS constructor.
    METHODS on_link_click
      FOR EVENT link_click OF cl_salv_events_table
      IMPORTING column row.
    DATA gt_sbook TYPE TABLE OF sbook.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD constructor.
    SELECT * FROM sbook INTO TABLE gt_sbook.
    cl_salv_table=>factory( EXPORTING r_container  = cl_gui_container=>screen0
                            IMPORTING r_salv_table = DATA(salv)
                            CHANGING  t_table      = gt_sbook ).
    SET HANDLER on_link_click FOR salv->get_event( ).
    LOOP AT salv->get_columns( )->get( ) INTO DATA(column).
      CAST cl_salv_column_table( salv->get_columns( )->get_column( column-columnname ) )->set_cell_type( if_salv_c_cell_type=>hotspot ).
    ENDLOOP.
    salv->display( ).
  ENDMETHOD.
  METHOD on_link_click.
    READ TABLE gt_sbook INDEX row INTO DATA(ls_sbook).
    IF sy-subrc = 0.
      ASSIGN COMPONENT column OF STRUCTURE ls_sbook TO FIELD-SYMBOL(<field>).
      MESSAGE |click value "{ <field> }" col { column } row { row }| TYPE 'I'.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

DATA go_app TYPE REF TO lcl_app.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_app IS NOT BOUND.
    go_app = NEW lcl_app( ).
  ENDIF.

I have posted screenshots there: How to trigger code when the user clicks an ALV hotspot field?

15 REPLIES 15

thkolz
Contributor
0 Kudos

I've created a method for that.

Definition:

    CLASS-METHODS nav_to_purchase_order
      IMPORTING
        !iv_purchase_order TYPE stringval .

Implementation:

  METHOD nav_to_purchase_order.

    DATA: ls_bdcdata    TYPE bdcdata,
          lt_bdcdata    TYPE STANDARD TABLE OF bdcdata,
          lt_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll.

    DATA: lv_ebeln      TYPE ebeln.

    IF iv_purchase_order IS NOT INITIAL.

      lv_ebeln = iv_purchase_order.

      "Build batch input 
      ls_bdcdata-program    = 'SAPLMEGUI'.
      ls_bdcdata-dynpro     = '0014'.
      ls_bdcdata-dynbegin   = 'X'.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-fnam       = 'BDC_OKCODE'.
      ls_bdcdata-fval       = '=MECHOB'.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-program    = 'SAPLMEGUI'.
      ls_bdcdata-dynpro     = '0002'.
      ls_bdcdata-dynbegin   = 'X'.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-fnam       = 'BDC_CURSOR'.
      ls_bdcdata-fval       = 'MEPO_SELECT-EBELN'.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-fnam       = 'MEPO_SELECT-EBELN'.
      ls_bdcdata-fval       = lv_ebeln.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-fnam       = 'MEPO_SELECT-BSTYP_F'.
      ls_bdcdata-fval       = abap_true.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      CLEAR ls_bdcdata.
      ls_bdcdata-fnam       = 'BDC_OKCODE'.
      ls_bdcdata-fval       = '=MEOK'.
      INSERT ls_bdcdata INTO TABLE lt_bdcdata.

      "Call transaction
      CALL TRANSACTION 'ME23N' USING lt_bdcdata MODE 'E'
        MESSAGES INTO lt_bdcmsgcoll.

    ENDIF.

  ENDMETHOD.

Sandra_Rossi
Active Contributor

I love ABAP 7.40 😉

DATA(lt_bdcdata) = VALUE ettcd_bcd_tabtype(
    ( program = 'SAPLMEGUI' dynpro = '0014' dynbegin = 'X' )
        ( fnam = 'BDC_OKCODE'           fval = '=MECHOB' )
    ( program = 'SAPLMEGUI' dynpro = '0002' dynbegin = 'X' )
        ( fnam = 'BDC_CURSOR'           fval = 'MEPO_SELECT-EBELN' )
        ( fnam = 'MEPO_SELECT-EBELN'    fval = lv_ebeln )
        ( fnam = 'MEPO_SELECT-BSTYP_F'  fval = abap_true )
        ( fnam = 'BDC_OKCODE'           fval = '==MEOK' ) ).

If I remember correctly, this code has been done by my colleague who still prefers old-school ABAP. 🙂

0 Kudos

Thank you sandra.rossi

0 Kudos

Thank You c12b61ded10b4e18beae75c3b6218d2c

dukejib5
Participant

Assuming , you already have code setup for click event on your alv,
You can set the Parameter ID for Field Ebeln ( PO Number) in ME23n and then call the Transaction ME23n

A rough code is ;

SET PARAMETER ID 'BES' FIELD ebeln (this should hold your clicked PO Number).
CALL TRANSACTION 'ME23N'. [With Authority Check, SKIP etc]

thkolz
Contributor
0 Kudos
alijibran

I think it's not that easy.
We had to use batch input instead (see below).

spartans007
Participant
0 Kudos

No dukejib5 I have not set up the code yet for the click event

spartans007
Participant
0 Kudos

Can you please provide me the code dukejib5 To set the hotspot in the ALV

Sandra_Rossi
Active Contributor
0 Kudos

It's been answered lots of times in the forum.

Search answers for question about double-click, and question for ME23N.

Sandra_Rossi
Active Contributor
0 Kudos

c12b61ded10b4e18beae75c3b6218d2c A simple "SET PARAMETER ID 'BES'" plus "CALL TRANSACTION 'ME23N'" works for me (S/4HANA 2022). I wonder what are the rules when it works, when it doesn't work...

dukejib5
Participant

It seems you aren't using class based syntax.

So you should create a class to handle the click.

DATA: G_EVENTS TYPE REF TO LCL_HANDLE_EVENTS,              " Events Reference      
      L_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.           " For LCL_HANDLE_EVENTS
*--------------------------------------------------------------------*
*        Handle Click Events for ALV
*--------------------------------------------------------------------*
CLASS LCL_HANDLE_EVENTS DEFINITION.
  PUBLIC SECTION.    
    METHODS:      
      ON_LINE_CLICK FOR EVENT LINK_CLICK OF CL_SALV_EVENTS_TABLE        
      IMPORTING ROW COLUMN. " Import Row & Column Data
ENDCLASS.  " DEFINITION END

CLASS LCL_HANDLE_EVENTS IMPLEMENTATION.
  METHOD ON_LINE_CLICK. " Single CLick    
         IF COLUMN = 'YOUR COLUMN NAME'.
             READ TABLE gt_sel ASSIGNING FIELD-SYMBOL(<fs>) INDEX ROW.      
                  CHECK SY-SUBRC EQ 0.         
            SET PARAMETER ID 'BES' FIELD <fs>-ebeln.         
            CALL TRANSACTION 'ME23N'.
     ENDIF.
  ENDMETHOD.
ENDCLASS.

*-------- SET HOTSPOT CLICK EVENT-------------------*  
L_EVENTS = ALV->GET_EVENT( ).  
CREATE OBJECT G_EVENTS.  
SET HANDLER G_EVENTS->ON_LINE_CLICK FOR L_EVENTS.
*------------------------------------------------------
Now, You must get the columns for your alv and setup one column with hotspot, 
TRY.     
   COLUMN_LIST ?= COLUMNS->GET_COLUMN( 'HEADER_ID' ).      
   COLUMN_LIST->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
 CATCH CX_SALV_NOT_FOUND.
ENDTRY.

Thank You dukejib5

Sandra_Rossi
Active Contributor

Same as Ali -- minus call to ME23N --, this is a standalone demo/minimal reproducible example of HOTSPOT with CL_SALV_TABLE (just run it, data comes from the demo table SBOOK):

REPORT.
CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    METHODS constructor.
    METHODS on_link_click
      FOR EVENT link_click OF cl_salv_events_table
      IMPORTING column row.
    DATA gt_sbook TYPE TABLE OF sbook.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
  METHOD constructor.
    SELECT * FROM sbook INTO TABLE gt_sbook.
    cl_salv_table=>factory( EXPORTING r_container  = cl_gui_container=>screen0
                            IMPORTING r_salv_table = DATA(salv)
                            CHANGING  t_table      = gt_sbook ).
    SET HANDLER on_link_click FOR salv->get_event( ).
    LOOP AT salv->get_columns( )->get( ) INTO DATA(column).
      CAST cl_salv_column_table( salv->get_columns( )->get_column( column-columnname ) )->set_cell_type( if_salv_c_cell_type=>hotspot ).
    ENDLOOP.
    salv->display( ).
  ENDMETHOD.
  METHOD on_link_click.
    READ TABLE gt_sbook INDEX row INTO DATA(ls_sbook).
    IF sy-subrc = 0.
      ASSIGN COMPONENT column OF STRUCTURE ls_sbook TO FIELD-SYMBOL(<field>).
      MESSAGE |click value "{ <field> }" col { column } row { row }| TYPE 'I'.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

DATA go_app TYPE REF TO lcl_app.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_app IS NOT BOUND.
    go_app = NEW lcl_app( ).
  ENDIF.

I have posted screenshots there: How to trigger code when the user clicks an ALV hotspot field?

0 Kudos

Thank You sandra.rossi