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

ALV User Command Issue

Former Member
0 Likes
1,042

Hello,

I am trying to have transaction CO09 popup after the user clicks on a material displayed in an ALV. However, when the material is clicked in the ALV, CO09 is not popping up. Any help would be greatly appreciated. Below is the code I am currently using. Thanks!

*---------------------------------------------------------------------*

*       FORM USEREXIT_MOVE_FIELD_TO_VBAP                              *

*---------------------------------------------------------------------*

*       This userexit can be used to move some fields into the sales  *

*       dokument item workaerea VBAP                                  *

*                                                                     *

*       SVBAP-TABIX = 0:  Create item                                 *

*       SVBAP-TABIX > 0:  Change item                                 *

*                                                                     *

*       This form is called at the end of form VBAP_FUELLEN.          *

*                                                                     *

*---------------------------------------------------------------------*

FORM userexit_move_field_to_vbap.

***********************************************************************

*Condition where dialog box will only appear when the material

*number is populated/changed but will not display if any other field

*in the line is modified.

   DATA ls_xvbap TYPE vbap.

   LOOP AT xvbap INTO ls_xvbap WHERE posnr = vbap-posnr AND

                                     vbeln = vbap-vbeln.

   ENDLOOP.

   IF  ls_xvbap-matnr <> rv45a-mabnr.

     TYPES: BEGIN OF ty_output, "Type used for outputting to ALV

        matnr TYPE matnr,

        menge TYPE bstmg,

        eindt TYPE eindt,

        lbkum TYPE lbkum,

        mng02 TYPE vrfmg,

        comtd TYPE vrfmg,

       END OF ty_output.

     DATA lt_output TYPE TABLE OF ty_output.

     SELECT ekpo~matnr

            ekpo~menge

            eket~eindt

            mbew~lbkum

     FROM ekpo

     JOIN eket ON ( ekpo~ebeln = eket~ebeln AND ekpo~ebelp = eket~ebelp )

     JOIN mbew ON ( ekpo~matnr = mbew~matnr )

     INTO CORRESPONDING FIELDS OF TABLE lt_output

     WHERE ekpo~matnr = rv45a-mabnr. "and eket~eindt >= sy-datum.

     SORT lt_output DESCENDING BY eindt.

***********************************************************************

*Retrieval of value for 'Available Qty' from table displayed in tcode

*MD04

     DATA ls_mrp_stock_detail TYPE bapi_mrp_stock_detail.

     CALL FUNCTION 'BAPI_MATERIAL_STOCK_REQ_LIST'

       EXPORTING

         material                = rv45a-mabnr

*      PLANT                   =

*      MRP_AREA                =

*      PLAN_SCENARIO           =

*      SELECTION_RULE          =

*      DISPLAY_FILTER          =

*      PERIOD_INDICATOR        =

*      GET_ITEM_DETAILS        =

*      GET_IND_LINES           = 'X'

*      GET_TOTAL_LINES         =

*      IGNORE_BUFFER           =

*      MATERIAL_EVG            =

       IMPORTING

*      MRP_LIST                =

*      MRP_CONTROL_PARAM       =

         mrp_stock_detail        = ls_mrp_stock_detail

*      RETURN                  =

*    TABLES

*      MRP_ITEMS               =

*      MRP_IND_LINES           =

*      MRP_TOTAL_LINES         =

*      EXTENSIONOUT            =

               .

*Calculation of 'Committed Quantity' and 'Available Quantity'

     DATA lt_mdsux TYPE TABLE OF mdsu.

     CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'

       EXPORTING

*   PLSCN                          =

         matnr                          = rv45a-mabnr

         werks                          = vbap-werks

*   BERID                          =

*   ERGBZ                          =

*   AFIBZ                          =

*   INPER                          =

*   DISPLAY_LIST_MDPSX             =

*   DISPLAY_LIST_MDEZX             =

*   DISPLAY_LIST_MDSUX             =

*   NOBUF                          =

*   PLAUF                          =

*   IS_SFILT                       =

*   IS_AFILT                       =

* IMPORTING

*   E_MT61D                        =

*   E_MDKP                         =

*   E_CM61M                        =

*   E_MDSTA                        =

*   E_ERGBZ                        =

       TABLES

*   MDPSX                          =

*   MDEZX                          =

         mdsux                          = lt_mdsux

* EXCEPTIONS

*   MATERIAL_PLANT_NOT_FOUND       = 1

*   PLANT_NOT_FOUND                = 2

*   OTHERS                         = 3

               .

     IF sy-subrc <> 0.

* Implement suitable error handling here

     ENDIF.

     DATA ls_mdsux TYPE mdsu.

     DATA lv_committed_qty TYPE vrfmg VALUE 0.

     LOOP AT lt_mdsux INTO ls_mdsux.

       lv_committed_qty = ls_mdsux-mng02 + lv_committed_qty.

     ENDLOOP.

***********************************************************************

*Reduces lt_output to a table of one row (ALV function used below

*requires a table as input). Also, population of avail qty and committed

*quantity

     DATA lt_mrp_stock_detail TYPE TABLE OF bapi_mrp_stock_detail.

     DATA ls_output TYPE ty_output.

     LOOP AT lt_output INTO ls_output.

       IF sy-tabix > 1.

         DELETE lt_output.

       ENDIF.

       ls_output-comtd = - ( lv_committed_qty ).

       ls_output-mng02 = ls_output-lbkum + lv_committed_qty.

       MODIFY TABLE lt_output FROM ls_output.

     ENDLOOP.

***********************************************************************

*If a PO Delivery date doesn't exist for current date or future date,

*ALV columns 'Next PO Del. Qty' and 'Next PO Del. Date' will return a

*value of '0' and '00/00/0000' respectively.

     LOOP AT lt_output INTO ls_output.

       IF ls_output-eindt < sy-datum.

         ls_output-eindt = '00000000'.

         ls_output-menge = '0'.

       ENDIF.

       MODIFY lt_output FROM ls_output.

     ENDLOOP.

***********************************************************************

*Creation of Field Catalog

     DATA: ls_fieldcatalog TYPE slis_fieldcat_alv,

           lt_fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.

     ls_fieldcatalog-fieldname = 'MATNR'.

     ls_fieldcatalog-seltext_m = 'Material Number'.

     ls_fieldcatalog-col_pos = 0.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

     ls_fieldcatalog-fieldname = 'MENGE'.

     ls_fieldcatalog-seltext_m = 'Next PO Del. Qty'.

     ls_fieldcatalog-col_pos = 1.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

     ls_fieldcatalog-fieldname = 'EINDT'.

     ls_fieldcatalog-seltext_m = 'Next PO Del. Date'.

     ls_fieldcatalog-col_pos = 2.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

     ls_fieldcatalog-fieldname = 'LBKUM'.

     ls_fieldcatalog-seltext_m = 'Stock Qty'.

     ls_fieldcatalog-col_pos = 3.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

     ls_fieldcatalog-fieldname = 'MNG02'.

     ls_fieldcatalog-seltext_m = 'Available'.

     ls_fieldcatalog-col_pos = 4.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

     ls_fieldcatalog-fieldname = 'COMTD'.

     ls_fieldcatalog-seltext_m = 'Committed'.

     ls_fieldcatalog-col_pos = 5.

     ls_fieldcatalog-emphasize = 'X'.

     APPEND ls_fieldcatalog TO lt_fieldcatalog.

     CLEAR ls_fieldcatalog.

***********************************************************************

**Creation of ALV output

     CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

       EXPORTING

     i_title                       = 'Line Item Added'

*    i_selection                   = 'X'

*   I_ALLOW_NO_SELECTION          =

     i_zebra                       = 'X'

*   I_SCREEN_START_COLUMN         = 0

*   I_SCREEN_START_LINE           = 0

*   I_SCREEN_END_COLUMN           = 0

*   I_SCREEN_END_LINE             = 0

*   I_CHECKBOX_FIELDNAME          =

*   I_LINEMARK_FIELDNAME          =

*   I_SCROLL_TO_SEL_LINE          = 'X'

     i_tabname                     = 'lt_output'

*   I_STRUCTURE_NAME              =

     it_fieldcat                   = lt_fieldcatalog[]

*   IT_EXCLUDING                  =

     i_callback_program            = sy-repid

     i_callback_user_command       = 'USER_COMMAND'

*   IS_PRIVATE                    =

* IMPORTING

*   ES_SELFIELD                   =

*   E_EXIT                        =

       TABLES

         t_outtab                      = lt_output

* EXCEPTIONS

*   PROGRAM_ERROR                 = 1

*   OTHERS                        = 2

               .

     IF sy-subrc <> 0.

* Implement suitable error handling here

     ENDIF.

   ENDIF.

ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBAP

*&---------------------------------------------------------------------*

*&      Form  USER_COMMAND

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->R_UCOMM      text

*      -->RS_SELFIELD  text

*----------------------------------------------------------------------*

FORM user_command USING r_ucomm LIKE sy-ucomm

                   rs_selfield TYPE slis_selfield.

   Case r_ucomm.

   When '&IC1'. "for double click in ALV

     if rs_selfield-fieldname = 'MATNR'.

       set parameter id 'MAT' field rs_selfield-value.

       call TRANSACTION 'CO09' and SKIP FIRST SCREEN.

       ENDIF.

       endcase.

ENDFORM.                    "user_command

7 REPLIES 7
Read only

RaymondGiuseppi
Active Contributor
0 Likes
931

(FAQ) never pass sy-repid to a FM if the parameter has not the "by value" set as it will be interpreted by the called FM as the main program of the called function group.

     i_callback_program            = sy-repid " No : use a lv_repid previously copied

Move sy-repid to a local variable and pass this to the FM.

Regards,

Raymond

Read only

schneidertho
Product and Topic Expert
Product and Topic Expert
0 Likes
931

Hi Vincent,

have you checked that the USER_COMMAND form is called at all?

Best regards

Thorsten

Read only

0 Likes
931

Hi Thorsten,

The USER_COMMAND form is not being called which is my problem. I'm not quite sure why it is not being called however. Any idea why that might be?

Thanks!

Read only

schneidertho
Product and Topic Expert
Product and Topic Expert
0 Likes
931

Hi Vincent,

have you tried Raymond's suggestion regarding sy-repid.

I have tried a ALV test program and it works for me.

Cheers

Thorsten

Read only

0 Likes
931

I tried out Raymond's fix but still no luck.

Read only

0 Likes
931

The FM REUSE_ALV_LIST_DISPLAY (which the documentation for REUSE_ALV_POPUP_TO_SELECT refers to) has some additional parameters, including IT_EVENT_EXIT. According to the documentation, standard user commands which you would like to handle with application specific logic need to be populated into this table and passed into the FM. Otherwise, the user command subroutine will only be called for custom user commands. Perhaps standard user commands cannot be handled using REUSE_ALV_POPUP_TO_SELECT.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
931

Also I'm not sure that this FM allows you to intercept this code, is not double-click used to select a line, try to ask for "detail" in the ALV grid and check if your USER_COMMAND routine is called (but not with '&IC1', but with '&ETA' ?).

You could also call another ALV grid which allows windows pop-up, and allows full management of user_command. But you may have to manage the return of selected line.

Regards,

Raympnd