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

Call user command / PAI from ALV

roland_spindler
Participant
0 Likes
6,857

Hello,

Is there a possibility to call a user command from within an ALV method? I want the PAI module of the ALV's screen to run.

best regards

Roland

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
4,267

Hi,

Yes you can make an ALV interactive which will execute is PAI (USER COMMAND) when user performs any action.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = sy_repid       " report id
     i_callback_pf_status_set          = 'PF'           " for PF-STATUS
     i_callback_user_command           = 'COMMAND'      " for User-Command
     is_layout                         = wa_layout      " for layout
     it_fieldcat                       = it_field       " field catalog
   TABLES
     t_outtab                          = it_final      " internal table
   EXCEPTIONS
     program_error                     = 1
     OTHERS                            = 2.

When you double-click on any cell of alv grid, use this code to fetch the data of the line that you currently clicked, its working:-

When you double click on the ALV grid line, you will have sy-ucomm = '&IC1'.

So when you define a i_callback_user_command for the FM reuse_alv_grid_display, and create it as:-


FORM command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
  DATA : ok_code TYPE sy-ucomm.
  ok_code = ucomm.
  CASE ok_code.
    WHEN '&IC1'. "for double click on alv grid line
      " your code
  ENDCASE.
ENDFORM.

As you have used selfield TYPE slis_selfield, the field selfield will hold all the values.

To know on which row you have clicked and to retain that line, use code:-

Suppose you are currently displaying data from internal table itab and corresponding to it you have work area wa.


read table itab into wa index selfield-tabindex. "index value of line you clicked
" now you have the contents of line that you double clicked currently

Now to know the field name that you clicked, use:-


selfield-fieldname " will fetch you the name of field that you clicked

Now using the work-area and the name of field that you clicked, you can easily make out the details of the field i.e., field name and field value and you can code as per your requirement.

Also you can refer this wiki by me on:-

ALV Grid Display with checkbox to process selected records at runtime

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/alv%252bgrid%252bdisplay%252bwith%252bch...

To have checkbox with each record in alv and display on those records on next display which were selected by the user on initial grid.

Hope this helps you.

Regards,

Tarun

Edited by: Tarun Gambhir on Mar 6, 2009 2:48 PM

Hello,

Is there a possibility to call a user command from within an ALV method? I want the PAI module of the ALV's screen to run.

best regards

Roland

15 REPLIES 15
Read only

former_member376453
Contributor
0 Likes
4,267

Please be more specific, its not clear.

Kuntal

Read only

0 Likes
4,267

I have an ALV that lies on a screen. This screen has a PBO and a PAI module (that are called before and after the user can do stuff).

I want to the ALV to be able to call the PAI module (as if the user would click a button or select a menu item or hits return).

Roland

Read only

0 Likes
4,267

Hi,

If you have created the Push button on the application toolbar then PAI module is called.

If you have created the Push button on the ALV toolbar than the Perform you specify in the AT_USER_COMMAND parameter is called.

Read only

0 Likes
4,267

I never said I have a push button.

I want to call PAI from the data_changed_finished event handler.

Roland

Read only

0 Likes
4,267

Hi,

I don't think, that you can do something in your ALV coding to call the screen PAI. What you can do is Call the screen in your code. That will first trigger you PBO of that screen then PAI, if that screen doesn't have any selction screen, then directly you can have the PAI of that screen.

Kuntal

Read only

0 Likes
4,267

Hi,

when you call set_table_for_first_display method then

use this line

SET HANDLER lcl_event_handler=>data_changed FOR t_grid.

"define and implement a class method in the public section.
    CLASS-METHODS data_changed_method FOR EVENT data_changed
                                       OF cl_gui_alv_grid
                                        IMPORTING es_row_no.

" Dont forget to implement this class method....

Regards,

Siddarth

Read only

0 Likes
4,267

Kuntal,

I already tried that. It's not possible to do a call screen from the event handler method. I thought about calling a function module and do the call screen there, but I can't try until next week.

-


Siddarth,

This is not what I asked.

-


Roland

Read only

I355602
Product and Topic Expert
Product and Topic Expert
4,268

Hi,

Yes you can make an ALV interactive which will execute is PAI (USER COMMAND) when user performs any action.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
     i_callback_program                = sy_repid       " report id
     i_callback_pf_status_set          = 'PF'           " for PF-STATUS
     i_callback_user_command           = 'COMMAND'      " for User-Command
     is_layout                         = wa_layout      " for layout
     it_fieldcat                       = it_field       " field catalog
   TABLES
     t_outtab                          = it_final      " internal table
   EXCEPTIONS
     program_error                     = 1
     OTHERS                            = 2.

When you double-click on any cell of alv grid, use this code to fetch the data of the line that you currently clicked, its working:-

When you double click on the ALV grid line, you will have sy-ucomm = '&IC1'.

So when you define a i_callback_user_command for the FM reuse_alv_grid_display, and create it as:-


FORM command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.
  DATA : ok_code TYPE sy-ucomm.
  ok_code = ucomm.
  CASE ok_code.
    WHEN '&IC1'. "for double click on alv grid line
      " your code
  ENDCASE.
ENDFORM.

As you have used selfield TYPE slis_selfield, the field selfield will hold all the values.

To know on which row you have clicked and to retain that line, use code:-

Suppose you are currently displaying data from internal table itab and corresponding to it you have work area wa.


read table itab into wa index selfield-tabindex. "index value of line you clicked
" now you have the contents of line that you double clicked currently

Now to know the field name that you clicked, use:-


selfield-fieldname " will fetch you the name of field that you clicked

Now using the work-area and the name of field that you clicked, you can easily make out the details of the field i.e., field name and field value and you can code as per your requirement.

Also you can refer this wiki by me on:-

ALV Grid Display with checkbox to process selected records at runtime

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/alv%252bgrid%252bdisplay%252bwith%252bch...

To have checkbox with each record in alv and display on those records on next display which were selected by the user on initial grid.

Hope this helps you.

Regards,

Tarun

Edited by: Tarun Gambhir on Mar 6, 2009 2:48 PM

Read only

0 Likes
4,267

Tarun,

> Yes you can make an ALV interactive which will execute is PAI (USER

> COMMAND) when user performs any action.

This sounds interesting. Do you happen to know how this is done when I'm NOT using the REUSE function modules, but OO programming?

best regards

Roland

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
4,267

Hi,

You can refer:-

Interactive Editable OO ALV grid with dynamic itab,FCAT and ENTER key event trigger

https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/interactive%252beditable%252boo%252balv%252b...

object oriented Programming in ALV

https://www.sdn.sap.com/irj/scn/wiki?path=/display/home/object%252boriented%252bprogramming%252bin%2...

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
4,267

Hi Ronald,

You can create user command for your alv,first create the pf-status for your alv like:



FORM pf_status USING rt_extab TYPE slis_t_extab.

  SET PF-STATUS 'FIRST'.

ENDFORM.                    "PF_STATUS

Then pass subroutine to function module Reuse..parameter:



      i_callback_pf_status_set          = 'PF_STATUS'

Then for the user command can be created like:



FORM comm USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.

  DATA: okcode TYPE sy-ucomm.

  okcode = ucomm.
  CASE okcode.

    WHEN 'REF'.
    CALL FUNCTION 'POPUP_TO_INFORM'
      EXPORTING
        titel         = 'MANSI'
        txt1          = 'CREATED BY'
        txt2          = SY-UNAME
*       TXT3          = ' '
*       TXT4          = ' '

              .
endcase.

And pass this subroutine in the parameter:

i_callback_user_command = 'COMM'

Hope it helps

Regrds

Mansi

Read only

roland_spindler
Participant
0 Likes
4,267

For your information:

I think I found the solution myself. I have to pass the parameter I_APPL_EVENTS (Register Events as Application Events) to the constructor of the ALV. This should cause the ALV events to trigger PAI too.

I can't try this today, but I assume it'll work.

Roland

Read only

0 Likes
4,267

Hi,

you can trigger PAI the following way:

cl_gui_cfw=>set_new_ok_code( EXPORTING new_code = 'YOUR_OK_CODE_HERE' ).

This triggers PAI. You must not set the i_appl_events option for the Grid.

Read only

0 Likes
4,267

This works for me, thanks Thomas

Read only

Former Member
0 Likes
4,267

This message was moderated.