Skip to Content
0

Not able to capture Sy-Ucomm from REUSE_ALV_POPUP_TO_SELECT

Jun 27, 2017 at 04:27 PM

245

avatar image

Hi All,

I am calling the FM 'REUSE_ALV_POPUP_TO_SELECT' inside another Function module.

When the user clicks on any lines or the green tick mark from the pop-up , i want to capture the sy-ucomm code and display something accordingly.


CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

    EXPORTING

      i_title                 = lv_string

      i_selection             = 'X'            "<--enable selection

      i_allow_no_selection    = 'X'            "<--allow exiting without selection

      i_zebra                 = 'X'

      i_screen_start_column   = 100

      i_screen_start_line     = 5

      i_screen_end_column     = 217 "120 Character

      i_screen_end_line       = 13

      i_tabname               = 'L_ACTIVE_Dxxx'

      i_structure_name        = 'ZSD_Dxxx_STRUCT'       "<--custom structure goes here

      i_callback_user_command = 'HANDLE_USER_COMMAND'  " "

    IMPORTING

      es_selfield             = ls_selfield

    TABLES

      t_outtab                = l_active_deals.



* Export dealtype selected by user

  CLEAR: w_active_deals, lv_dealtyp.

  READ TABLE l_active_deals INTO w_active_deals

    INDEX ls_selfield-tabindex.

  o_dealtype = w_active_deals-zzdealtyp.



PERFORM handle_user_command USING r_ucomm ls_selfield

                            CHANGING ok_code.


form handle_user_command  using    p_r_ucomm

                                   p_selfield

                          changing p_ok_code.

  case p_r_ucomm.

    when '&ETA'.

      p_ok_code = 'X'.

    when others.

  endcase.

  endform.         
10 |10000 characters needed characters left characters exceeded

Hi raymond ,

I used both callback_user and callback_program as per your suggestion and checked but i think user_command works only for reuse_alv_merge , i got sy-xcode which captures the sy-ucomm.

thanks,

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Sandra Rossi Jul 01, 2017 at 06:41 AM
0

Your question is misleading :

  • If you want to do something when the user "clicks on any lines or the green tick mark"
    .....Then you don't need to retrieve the function code (you're talking about SY-UCOMM/SY-XCODE but you should better never trust these values, they are not guaranteed in future releases): the function module returns the E_EXIT parameter which tells you whether the user cancelled the dialog ('X') or has selected one or more values (' ')
  • If you want to handle the "Detail" button inside the popup, then you use the two I_CALLBACK_* parameters (see Raymond's answer), and the subroutine must have this interface or it won't work:
  • FORM user_command
      CHANGING
        r_ucomm     TYPE syucomm
        rs_selfield TYPE slis_selfield.
    ENDFORM.
    
  • In your code, you defined the subroutine with an extra parameter, which will trigger a SHORT DUMP at runtime when the detail button is pressed.
  • In the subroutine, you may change R_UCOMM, for instance to prevent the standard detail dialog from being displayed, or change one of the components of RS_SELFIELD, for instance to modify the ALV table and refresh the screen, and you have other possibilities. These features are described in the documentation of REUSE_ALV_LIST_DISPLAY function module.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

First , thanks Sandra, Rice and Raymond.

Well i tried the callback_user_program and callback_user_command first in my "REUSE_ALV_POPUP_TO_SELECT".

But actually i am calling this reuse pop up inside a function module . So when i added the below code

after the Reuse FM call i got an error saying that "endform should be outside endfunction"

However i included a perform inside an endfunction and later called the form outside and my r_ucomm did not have any values.

FORM user_command
  CHANGING
    r_ucomm     TYPE syucomm
    rs_selfield TYPE slis_selfield.ENDFORM.
0
Raymond Giuseppi
Jun 28, 2017 at 08:12 AM
1

If you use your own form for user_command you MUST provide the I_CALLBACK_USER_COMMAND parameter but also the I_CALLBACK_PROGRAM parameter (and don't use sy-repid in the call of the FM but use a local variable)

Show 3 Share
10 |10000 characters needed characters left characters exceeded

PS: SY-REPID may be passed as a parameter without any problem since 6.10. It's not a system variable anymore, but a variable belonging to every program:

1

Old habits die hard...

0

Yes they do...

However, I've decided to still copy sy-repid to a local variable each time because as a contractor I work on many different systems so if I do that i don't need to worry about whether it's 6.10 or not.

0
Divya Venkatakrishnan Jul 06, 2017 at 05:11 PM
0

So My code looks like this

call function 'REUSE_ALV_POPUP_TO_SELECT'
 exporting
 i_title = lv_string
 i_selection = 'X' "<--enable selection
 i_allow_no_selection = 'X' "<--allow exiting without selection
 i_zebra = 'X'
 i_screen_start_column = 100
 i_screen_start_line = 5
 i_screen_end_column = 217 "120 Character
 i_screen_end_line = 13
 i_tabname = 'L_ACTIVE_DEALS'
 i_structure_name = 'ZSD_DEAL_STRUCT' "<--custom structure goes here
 i_callback_program = sy-repid
 i_callback_user_command = 'USER_COMMAND'
 importing
 es_selfield = ls_selfield
 e_exit = lv_exit
 tables
 t_outtab = l_active_deals.


perform user_command using ls_selfield r_ucomm.

if lv_exit is initial.
 if sy-xcode = '&NT1' and ( sy-tcode = 'VA01' or sy-tcode = 'VA02' ). 
 ok_code = 'X'. 
 endif.
endif.


Show 6 Share
10 |10000 characters needed characters left characters exceeded

No no no, don't call yourself the USER_COMMAND subroutine. Please read the SAP documentation, have a look at all the demo programs in your system (like BCALV_TEST_LIST_EVENTS) and all examples around the WWW.

0

Hi Sandra,

When i added the i_callback_user_command ='USER_COMMAND' to the Function module('REUSE_ALV_POPUP_TO_SELECT') and clicked on pretty printer the Form endform was craeted automatically.

But again it threw an error saying that "Error: Before the statement "FORM", conclude with "ENDFUNCTION"".

So i tried using a perform.

Ps: I am calling this reuse_popup inside another function module.

0
Divya Venkatakrishnan

I don't know what happened, but FORM ENDFORM must be outside FUNCTION ENDFUNCTION. You must not use PERFORM (you have probably seen that all the demo programs and examples around the web don't PERFORM this subroutine, haven't you?)

0

Yes i have never seen perform, totally agree, But to avoid error and make my program point to the ("form..endform") i tried using a perform.

0
Divya Venkatakrishnan

So, now, I guess you moved successfully your FORM USER_COMMAND ... ENDFORM subroutine outside your Z function module. Does it work?

0

Hi Sandra,

No Luck,

I moved it (form.endform subroutine) outside the endfunction and it doesn capture anything. I am not sure why. I have checked almost all the internet.

I also found this in the forum

PS : Functionality of ‘REUSE_ALV_POPUP_TO_SELECT'

if you do a doubleclick on a record of ALV, it means you want to select it, so the ALV is closed and returns the selected value in ES_SELFIELD parameter without to call USER_COMMAND routine.

0