메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_reuse_alv_popup_to_select

노름마치 2007.11.05 22:06 조회 수 : 3444

REPORT z_reuse_alv_popup_to_select.
*---------------------------------------------------------------------*
* Example with FM REUSE_ALV_POPUP_TO_SELECT                           *
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : mpioud@yahoo.fr  HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
TYPES:
  BEGIN OF ty_user_addr,
    bname      TYPE user_addr-bname,        " User name
    name_first TYPE user_addr-name_first,   " First name
    name_last  TYPE user_addr-name_last,    " Last name
    checkbox,
  END OF ty_user_addr.
*---------------------------------------------------------------------*
DATA:
* Data displayed
  gt_user TYPE TABLE OF ty_user_addr.
*---------------------------------------------------------------------*
INITIALIZATION.


  v_1 = 'Maximum of records to read'.


*---------------------------------------------------------------------*
START-OF-SELECTION.


  PERFORM f_read_data.


  PERFORM f_display_data.


*---------------------------------------------------------------------*
*      Form  f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.


* Read Users address data
  SELECT bname name_first name_last
      UP TO p_max ROWS
    INTO CORRESPONDING FIELDS OF TABLE gt_user
    FROM user_addr.


ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.


* Macro definition
  DEFINE m_fieldcat.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = &2.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.


  TYPE-POOLS: slis.                    " ALV Global types


  DATA:
    l_exit,
    ls_private  TYPE slis_data_caller_exit,
    ls_user     TYPE ty_user_addr,
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.


* Build the field catalog
  m_fieldcat 'BNAME'      'USER_ADDR'.
  m_fieldcat 'NAME_FIRST' 'USER_ADDR'.
  m_fieldcat 'NAME_LAST'  'USER_ADDR'.


* Optimize column width
  ls_private-columnopt = 'X'.


* Display data in a POPUP
  CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
       EXPORTING
            i_selection          = 'X'
            i_zebra              = 'X'
            it_fieldcat          = lt_fieldcat
            i_tabname            = 'GT_USER'
            i_checkbox_fieldname = 'CHECKBOX'
            is_private           = ls_private
       IMPORTING
            e_exit               = l_exit
       TABLES
            t_outtab             = gt_user.


  CHECK l_exit = space.


* What has been selected ?
  LOOP AT gt_user INTO ls_user WHERE checkbox = 'X'.
    MESSAGE i368(00) WITH ls_user-bname 'selected'.
  ENDLOOP.


ENDFORM.                               " F_DISPLAY_DATA
*********** END OF PROGRAM Z_REUSE_ALV_POPUP_TO_SELECT ****************