Skip to Content

Hotspot and FM REUSE_ALV_GRID_DISPLAY not working

Good day, everyone!

First of all, I have searched on this topic, and I've come across slight variations in answers. I've spent all day so far trying them all, trying them in combination, etc., but I haven't been able to get it to work. I am displaying a report using the FM REUSE_ALV_GRID_DISPLAY. All I want to do is call transaction ME32N, passing along the Purchase Order Number, when the user selects a row.

Here's what I've done so far, based on my searching on this topic:

1) Added to program:

TYPE-POOLS: slis.

2) Added a line to the program to declare a hotspot on the desired field:

fieldcat_ln-tabname = 'IT_OUTPUT'.

fieldcat_ln-fieldname = 'EBELN'.

fieldcat_ln-seltext_l = 'PO Number'.

fieldcat_ln-outputlen = '10'.

fieldcat_ln-hotspot = 'X'. "<-- ADDED THIS LINE!

APPEND fieldcat_ln TO fieldcat.

CLEAR fieldcat_ln.

3) Added a section of code to my existing form build_evencat:

FORM build_eventcat.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = i_events.

READ TABLE i_events

WITH KEY name = slis_ev_top_of_page

INTO w_events.

IF sy-subrc = 0.

MOVE 'ALV_TOP_OF_PAGE' TO w_events-form.

MODIFY i_events FROM w_events INDEX sy-tabix.

ENDIF.

READ TABLE i_events

WITH KEY name = slis_ev_end_of_list

INTO w_events.

IF sy-subrc = 0.

MOVE 'ALV_END_OF_LIST' TO w_events-form.

MODIFY i_events FROM w_events INDEX sy-tabix.

ENDIF.

  • ADDED THE FOLLOWING SECTION!

READ TABLE i_events

WITH KEY name = slis_ev_user_command

INTO w_events.

IF sy-subrc = 0.

MOVE 'USER_COMMAND' TO w_events-name.

MOVE 'USER_COMMAND_FORM' TO w_events-form.

MODIFY i_events FROM w_events INDEX sy-tabix.

ENDIF.

ENDFORM. " build_eventcat

4) Added this form:

&----


*& Form user_command_form

&----


  • text

----


FORM user_command_form USING p_ucomm LIKE sy-ucomm

p_selfield TYPE slis_selfield.

CASE p_ucomm.

WHEN '&IC1'. " SAP standard code for double-clicking

BREAK-POINT.

SET PARAMETER ID 'XXX' FIELD p_selfield-value.

CALL TRANSACTION 'YYYY'.

ENDCASE.

ENDFORM. "user_command_form

So what happens is I run the report, it displays, and I notice that the field values for the Purchase Order Number are highlighted, thanks to the hotspot declaration. But when I click on the field, I don't even get to the breakpoint I have hard-coded in my user_command_form routine. Instead, I get an SAP error:

Select at least one column

Even if I try double-clicking anywhere in the row, I get the error. All I want to do is call ME23N, passing that Purchase Order Number, if the user clicks/double-clicks (whatever it should be) on the desired row. As I said, I've been searching on this (both SDN and Google), and I've tried to incorporate what I've read is the solution, but it's not working.

Can someone tell me what I'm missing or doing wrong? <REMOVED BY MODERATOR>

Thanks!

Dave

Edited by: Alvaro Tejada Galindo on Mar 12, 2008 1:46 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2008 at 04:17 PM

    Hi,

    Please refer to the code below, which is as per your exact requirement:

    
    REPORT  zdemo_alvgrid                 .
    
    TABLES:     ekko.
    
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    *----------------
    TYPES: BEGIN OF t_ekko,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
     END OF t_ekko.
    
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid,
          gt_events     type slis_t_event,
          gd_prntparams type slis_print_alv.
    
    
    ************************************************************************
    *Start-of-selection.
    START-OF-SELECTION.
    
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform build_events.
    perform build_print_params.
    perform display_alv_report.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    *       Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    form build_fieldcatalog.
    
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
    
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    *       Build layout for ALV grid report
    *----------------------------------------------------------------------*
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    *  gd_layout-totals_only        = 'X'.
    *  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
    *                                         "click(press f2)
    *  gd_layout-zebra             = 'X'.
    *  gd_layout-group_change_edit = 'X'.
    *  gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    *       Display report using ALV grid
    *----------------------------------------------------------------------*
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
                i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
                it_events               = gt_events
                is_print                = gd_prntparams
                i_save                  = 'X'
    *            is_variant              = z_template
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    endform.                    " DISPLAY_ALV_REPORT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    *       Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    form data_retrieval.
    
    select ebeln ebelp statu aedat matnr menge meins netpr peinh
     up to 10 rows
      from ekpo
      into table it_ekko.
    endform.                    " DATA_RETRIEVAL
    
    
    *-------------------------------------------------------------------*
    * Form  TOP-OF-PAGE                                                 *
    *-------------------------------------------------------------------*
    * ALV Report Header                                                 *
    *-------------------------------------------------------------------*
    Form top-of-page.
    *ALV Header declarations
    data: t_header type slis_t_listheader,
          wa_header type slis_listheader,
          t_line like wa_header-info,
          ld_lines type i,
          ld_linesc(10) type c.
    
    * Title
      wa_header-typ  = 'H'.
      wa_header-info = 'EKKO Table Report'.
      append wa_header to t_header.
      clear wa_header.
    
    * Date
      wa_header-typ  = 'S'.
      wa_header-key = 'Date: '.
      CONCATENATE  sy-datum+6(2) '.'
                   sy-datum+4(2) '.'
                   sy-datum(4) INTO wa_header-info.   "todays date
      append wa_header to t_header.
      clear: wa_header.
    
    * Total No. of Records Selected
      describe table it_ekko lines ld_lines.
      ld_linesc = ld_lines.
      concatenate 'Total No. of Records Selected: ' ld_linesc
                        into t_line separated by space.
      wa_header-typ  = 'A'.
      wa_header-info = t_line.
      append wa_header to t_header.
      clear: wa_header, t_line.
    
      call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
                it_list_commentary = t_header.
    *            i_logo             = 'Z_LOGO'.
    endform.
    
    
    *------------------------------------------------------------------*
    *       FORM USER_COMMAND                                          *
    *------------------------------------------------------------------*
    *       --> R_UCOMM                                                *
    *       --> RS_SELFIELD                                            *
    *------------------------------------------------------------------*
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    
    * Check function code
      CASE r_ucomm.
        WHEN '&IC1'.
    *   Check field clicked on within ALVgrid report
        IF rs_selfield-fieldname = 'EBELN'.
    *     Read data table, using index of row user clicked on
          READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    *     Set parameter ID for transaction screen field
          SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    *     Sxecute transaction ME23N, and skip initial data entry screen
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDCASE.
    ENDFORM.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_EVENTS
    *&---------------------------------------------------------------------*
    *       Build events table
    *----------------------------------------------------------------------*
    form build_events.
      data: ls_event type slis_alv_event.
    
      call function 'REUSE_ALV_EVENTS_GET'
           exporting
                i_list_type = 0
           importing
                et_events   = gt_events[].
      read table gt_events with key name =  slis_ev_end_of_page
                               into ls_event.
      if sy-subrc = 0.
        move 'END_OF_PAGE' to ls_event-form.
        append ls_event to gt_events.
      endif.
    
        read table gt_events with key name =  slis_ev_end_of_list
                               into ls_event.
      if sy-subrc = 0.
        move 'END_OF_LIST' to ls_event-form.
        append ls_event to gt_events.
      endif.
    endform.                    " BUILD_EVENTS
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_PRINT_PARAMS
    *&---------------------------------------------------------------------*
    *       Setup print parameters
    *----------------------------------------------------------------------*
    form build_print_params.
      gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
      gd_prntparams-no_coverpage = 'X'.
    endform.                    " BUILD_PRINT_PARAMS
    
    
    *&---------------------------------------------------------------------*
    *&      Form  END_OF_PAGE
    *&---------------------------------------------------------------------*
    form END_OF_PAGE.
      data: listwidth type i,
            ld_pagepos(10) type c,
            ld_page(10)    type c.
    
      write: sy-uline(50).
      skip.
      write:/40 'Page:', sy-pagno .
    endform.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  END_OF_LIST
    *&---------------------------------------------------------------------*
    form END_OF_LIST.
      data: listwidth type i,
            ld_pagepos(10) type c,
            ld_page(10)    type c.
    
      skip.
      write:/40 'Page:', sy-pagno .
    endform.
    
    
    

    Thanks,

    Sriram Ponna.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2008 at 03:59 PM

    Try the below code.

    data: v_repid type syst-repid.
    
    v_repid = sy-repid.
    
    pass
         i_callback_program                = v_repid
         i_callback_user_command     = 'USER_COMMAND'
    to the FM REUSE_ALV_GRID_DISPLAY
    
    form user_command using r_ucomm like sy-ucomm
                                           rs_selfield type slis_selfield.
      case r_ucomm.
        when '&IC1'.
          read table it_ekko into wa_ekko index rs_selfield-tabindex.
          if sy-subrc eq 0.
             set parameter id 'xxx' field p_selfield-value.
             call transaction 'yyyy'.
          endif.
      endcase.
    endform.
    
    

    Hope this helps.

    Thanks,

    Balaji

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 12, 2008 at 04:00 PM

    Hello Dave,

    Your requirement is very easy. Just do this.

    " For Hotspot
          WHEN 'EBELN'.
            G_R_FIELDCAT-HOTSPOT = 'X'.
    
      DATA: IT_EVENTS TYPE SLIS_T_EVENT,
            WA_EVENTS LIKE LINE OF IT_EVENTS.
      DATA: IT_VARIANT LIKE DISVARIANT.
      REFRESH: IT_EVENTS.
      CLEAR: WA_EVENTS,IT_EVENTS.
      WA_EVENTS-NAME = 'USER_COMMAND'.
      WA_EVENTS-FORM = 'USER_COMMAND'.
      APPEND WA_EVENTS TO IT_EVENTS .
    *--- ALV List Display
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM          = G_PROGNAME
                I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE'
                IT_FIELDCAT                 = G_T_FIELDCAT
                IT_EVENTS                   = IT_EVENTS " Check here
                I_SAVE                      = 'A'
                IS_VARIANT                  = IT_VARIANT
           TABLES
                T_OUTTAB                    = G_T_OUTTAB
           EXCEPTIONS
                PROGRAM_ERROR               = 1
                OTHERS                      = 2.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    
    *---------------------------------------------------------------------*
    *       FORM user_command                                             *
    *---------------------------------------------------------------------*
    *       ........                                                      *
    *---------------------------------------------------------------------*
    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                            RS_SELFIELD TYPE SLIS_SELFIELD.
      CASE R_UCOMM.
        WHEN '&IC1'.   "doubleclick
          IF RS_SELFIELD-FIELDNAME = 'EBELN'.
            READ TABLE G_T_OUTTAB INDEX RS_SELFIELD-TABINDEX.
            IF SY-SUBRC = 0.
              SET PARAMETER ID 'BES' FIELD G_T_OUTTAB-EBELN.
              CALL TRANSACTION 'ME23' AND SKIP FIRST SCREEN.
            ENDIF.
          ENDIF.
      ENDCASE.
    ENDFORM.
    

    Hope this will solve ur issue.

    Cheers,

    Vasanth

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 16, 2015 at 09:35 AM

    SUBTOTAL, TOTAL, DIVIDE & Linking ME23N to OP .

    WORKING FINE WITH ME...

    THANK`S TO ALL...

    IF HELPFUL PLZ REWARD.


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

    *& Report ZALLTEST1

    *&

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

    *&

    *&

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

    REPORT ZALLTEST1.

    TYPE-POOLS : SLIS.

    TYPES: BEGIN OF IT_EKPO,

    EBELN TYPE EKPO-EBELN,

    MATNR TYPE EKPO-MATNR,

    MENGE TYPE EKPO-MENGE,

    EBELP TYPE EKPO-EBELP,

    NETPR TYPE EKPO-NETPR,

    END OF IT_EKPO.

    TYPES: BEGIN OF IT_EKKO,

    EBELN TYPE EKKO-EBELN,

    BEDAT TYPE EKKO-BEDAT,

    END OF IT_EKKO.

    TYPES: BEGIN OF IT_MAKT,

    MATNR TYPE MAKT-MATNR,

    MAKTX TYPE MAKT-MAKTX,

    END OF IT_MAKT.

    TYPES : BEGIN OF IT_SORT,

    EBELN TYPE EKPO-EBELN,

    MENGE TYPE EKPO-MENGE,

    END OF IT_SORT.

    TYPES: BEGIN OF IT_FINAL,

    EBELN TYPE EKPO-EBELN,

    MATNR TYPE EKPO-MATNR,

    MENGE TYPE EKPO-MENGE,

    EBELP TYPE EKPO-EBELP,

    NETPR TYPE EKPO-NETPR,

    BEDAT TYPE EKKO-BEDAT,

    MAKTX TYPE MAKT-MAKTX,

    RESULT TYPE EKPO-NETPR,

    END OF IT_FINAL.

    DATA: IT_EKPO TYPE STANDARD TABLE OF IT_EKPO INITIAL SIZE 0,

    WA_EKPO TYPE IT_EKPO.

    DATA: IT_EKKO TYPE STANDARD TABLE OF IT_EKKO INITIAL SIZE 0,

    WA_EKKO TYPE IT_EKKO.

    DATA: IT_MAKT TYPE STANDARD TABLE OF IT_MAKT INITIAL SIZE 0,

    WA_MAKT TYPE IT_MAKT.

    DATA: IT_FINAL TYPE STANDARD TABLE OF IT_FINAL INITIAL SIZE 0,

    WA_FINAL TYPE IT_FINAL.

    DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

    GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,

    GD_LAYOUT TYPE SLIS_LAYOUT_ALV,

    GD_REPID LIKE SY-REPID.

    SELECT-OPTIONS : PO_NO FOR WA_EKKO-EBELN,

    PO_DATE FOR WA_EKKO-BEDAT.

    START-OF-SELECTION.

    PERFORM DATA_RETRIEVAL.

    PERFORM BUILD_FIELDCATALOG.

    PERFORM DISPLAY_ALV_REPORT.

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

    *& Form build_fieldcatalog

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

    * text

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

    FORM BUILD_FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'EBELN'.

    FIELDCATALOG-SELTEXT_M = 'PO.NO'.

    FIELDCATALOG-COL_POS = 1.

    FIELDCATALOG-OUTPUTLEN = 15.

    FIELDCATALOG-DO_SUM = 'X'.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    FIELDCATALOG-NO_ZERO = 'X'.

    FIELDCATALOG-HOTSPOT = 'x'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'MATNR'.

    FIELDCATALOG-SELTEXT_M = 'MATERIAL.NO'.

    FIELDCATALOG-COL_POS = 2.

    FIELDCATALOG-OUTPUTLEN = 20.

    FIELDCATALOG-DO_SUM = 'X'.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'EBELP'.

    FIELDCATALOG-SELTEXT_M = 'ITEM'.

    "wa_sort-subtot = 'X'.

    FIELDCATALOG-COL_POS = 3.

    FIELDCATALOG-OUTPUTLEN = 20.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    "FIELDCATALOG-SUBTOT = 'X'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'MENGE'.

    FIELDCATALOG-SELTEXT_M = 'PO QUANTITY'.

    FIELDCATALOG-COL_POS = 4.

    FIELDCATALOG-OUTPUTLEN = 15.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    FIELDCATALOG-DO_SUM = '+'.

    FIELDCATALOG-DO_SUM = 'X'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'NETPR'.

    FIELDCATALOG-SELTEXT_M = 'NET PRICE'.

    FIELDCATALOG-COL_POS = 5.

    FIELDCATALOG-OUTPUTLEN = 15.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    FIELDCATALOG-DO_SUM = '+'.

    FIELDCATALOG-DO_SUM = 'X'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'RESULT'.

    FIELDCATALOG-SELTEXT_M = 'PRICE PER PIECE'.

    FIELDCATALOG-COL_POS = 6.

    FIELDCATALOG-OUTPUTLEN = 15.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    FIELDCATALOG-DO_SUM = '/'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'BEDAT'.

    FIELDCATALOG-SELTEXT_M = 'PO.DATE'.

    FIELDCATALOG-COL_POS = 7.

    FIELDCATALOG-OUTPUTLEN = 10.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    FIELDCATALOG-FIELDNAME = 'MAKTX'.

    FIELDCATALOG-SELTEXT_M = 'MATERIAL DESCRIPTION'.

    FIELDCATALOG-COL_POS = 8.

    FIELDCATALOG-OUTPUTLEN = 35.

    FIELDCATALOG-TABNAME = 'IT_FINAL'.

    APPEND FIELDCATALOG TO FIELDCATALOG.

    CLEAR FIELDCATALOG.

    ENDFORM. "build_fieldcatalog

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

    *& Form DISPLAY_ALV_REPORT

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

    * Display report using ALV grid

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

    FORM DISPLAY_ALV_REPORT.

    GD_REPID = SY-REPID.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = GD_REPID

    " I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE' "see FORM

    IS_LAYOUT = GD_LAYOUT

    IT_FIELDCAT = FIELDCATALOG[]

    I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

    I_SAVE = 'X'

    TABLES

    T_OUTTAB = IT_FINAL

    EXCEPTIONS

    PROGRAM_ERROR = 1

    OTHERS = 2.

    IF SY-SUBRC <> 0.

    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    ENDFORM. " DISPLAY_ALV_REPORT

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

    **& Form DATA_RETRIEVAL

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

    ** Retrieve data form MARA table and populate itab it_MARA

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

    FORM DATA_RETRIEVAL.

    BREAK-POINT .

    SELECT EBELN

    BEDAT

    FROM EKKO INTO CORRESPONDING FIELDS OF TABLE IT_EKKO WHERE EBELN IN PO_NO AND BEDAT IN PO_DATE.

    SELECT EBELN

    MATNR

    MENGE

    EBELP

    NETPR

    FROM EKPO INTO TABLE IT_EKPO FOR ALL ENTRIES IN IT_EKKO WHERE EBELN = IT_EKKO-EBELN.

    SELECT MATNR

    MAKTX

    FROM MAKT INTO TABLE IT_MAKT FOR ALL ENTRIES IN IT_EKPO WHERE MATNR = IT_EKPO-MATNR.

    LOOP AT IT_EKPO INTO WA_EKPO.

    WA_FINAL-EBELN = WA_EKPO-EBELN.

    WA_FINAL-MATNR = WA_EKPO-MATNR.

    WA_FINAL-MENGE = WA_EKPO-MENGE.

    WA_FINAL-EBELP = WA_EKPO-EBELP.

    WA_FINAL-NETPR = WA_EKPO-NETPR.

    WA_FINAL-RESULT = WA_FINAL-NETPR / WA_FINAL-MENGE.

    " LOOP AT IT_EKKO INTO WA_EKKO.

    READ TABLE IT_EKKO INTO WA_EKKO WITH KEY EBELN = WA_EKPO-EBELN.

    IF SY-SUBRC = 0.

    WA_FINAL-EBELN = WA_EKKO-EBELN.

    WA_FINAL-BEDAT = WA_EKKO-BEDAT.

    READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_EKPO-MATNR.

    IF SY-SUBRC = 0.

    WA_FINAL-MATNR = WA_MAKT-MATNR.

    WA_FINAL-MAKTX = WA_MAKT-MAKTX.

    ENDIF.

    ENDIF.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    ENDLOOP.

    ENDFORM. "DATA_RETRIEVAL

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

    * FORM USER_COMMAND *

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

    * --> R_UCOMM *

    * --> RS_SELFIELD *

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

    FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

    RS_SELFIELD TYPE SLIS_SELFIELD.

    * Check function code

    CASE R_UCOMM.

    WHEN '&IC1'.

    * Check field clicked on within ALVgrid report

    IF RS_SELFIELD-FIELDNAME = 'EBELN'.

    * Read data table, using index of row user clicked on

    READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.

    * Set parameter ID for transaction screen field

    SET PARAMETER ID 'BES' FIELD WA_EKKO-EBELN.

    * Sxecute transaction ME23N, and skip initial data entry screen

    CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

    ENDIF.

    ENDCASE.

    ENDFORM. "user_command

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.