메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_alv_switch_list

노름마치 2007.11.05 21:54 조회 수 : 3287

REPORT z_alv_switch_list.
*---------------------------------------------------------------------*
* Button to switch alv list                                           *
*---------------------------------------------------------------------*
* Author : Michel PIOUD                                               *
* Email : mpioud@yahoo.fr  HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
CONSTANTS:
  c_x VALUE 'X',
  c_eb9 TYPE syucomm VALUE '&EB9'.
*---------------------------------------------------------------------*
TYPES :
  BEGIN OF ty_vbak,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr TYPE vbak-kunnr,             " Sold-to party
    vbeln TYPE vbak-vbeln,             " Sales document
    netwr TYPE vbak-netwr,             " Net Value of the Sales Order
    waerk TYPE vbak-waerk,             " Document currency
  END OF ty_vbak,


  BEGIN OF ty_vbap,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr  TYPE vbak-kunnr,            " Sold-to party
    vbeln  TYPE vbak-vbeln,            " Sales document
    posnr  TYPE vbap-posnr,            " Sales document item
    matnr  TYPE vbap-matnr,            " Material number
    arktx  TYPE vbap-arktx,            " Short text for sales order item
    kwmeng TYPE vbap-kwmeng,           " Order Quantity
    netwr  TYPE vbap-netwr,            " Net value of the order item
    waerk  TYPE vbap-waerk,            " SD document currency
  END OF ty_vbap.
*---------------------------------------------------------------------*
DATA:
  vbak    TYPE vbak,
  gt_vbak TYPE TABLE OF ty_vbak,
  gt_vbap TYPE TABLE OF ty_vbap.
*---------------------------------------------------------------------*
SELECT-OPTIONS :
  s_vkorg FOR vbak-vkorg,              " Sales organization
  s_kunnr FOR vbak-kunnr,              " Sold-to party
  s_vbeln FOR vbak-vbeln.              " Sales document


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.
*---------------------------------------------------------------------*
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 Sales Document: Header Data
  SELECT vkorg kunnr vbeln netwr waerk
      UP TO p_max ROWS
    INTO TABLE gt_vbak
    FROM vbak
   WHERE kunnr IN s_kunnr
     AND vbeln IN s_vbeln
     AND vkorg IN s_vkorg.


  CHECK NOT gt_vbak[] IS INITIAL.


* Read Sales Document: Header Data and items
  SELECT vkorg kunnr k~vbeln posnr matnr arktx kwmeng p~netwr p~waerk
    INTO CORRESPONDING FIELDS OF TABLE gt_vbap
    FROM vbak AS k
   INNER JOIN vbap AS p
      ON k~vbeln = p~vbeln
     FOR ALL ENTRIES IN gt_vbak
   WHERE k~vbeln = gt_vbak-vbeln.
  .
ENDFORM.                               " F_READ_DATA
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.


  TYPE-POOLS: slis.                    " ALV Global types


  DEFINE m_fieldcat_k.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = &2.
    ls_fieldcat-do_sum      = &3.
    ls_fieldcat-cfieldname  = &4.
    append ls_fieldcat to lt_fieldcat_k.
  END-OF-DEFINITION.


  DEFINE m_fieldcat_p.
    add 1 to ls_fieldcat-col_pos.
    ls_fieldcat-fieldname   = &1.
    ls_fieldcat-ref_tabname = &2.
    ls_fieldcat-do_sum      = &3.
    ls_fieldcat-cfieldname  = &4.
    append ls_fieldcat to lt_fieldcat_p.
  END-OF-DEFINITION.


  DATA:
    l_exit,
    l_flag        TYPE i VALUE 1,
    ls_print      TYPE slis_print_alv,
    ls_layout     TYPE slis_layout_alv,
    ls_fieldcat   TYPE slis_fieldcat_alv,
    lt_fieldcat_k TYPE slis_t_fieldcat_alv,
    lt_fieldcat_p TYPE slis_t_fieldcat_alv,
    ls_event_exit TYPE slis_event_exit,
    lt_event_exit TYPE slis_t_event_exit.


  m_fieldcat_k 'VKORG' 'VBAK'  ''  ''.
  m_fieldcat_k 'KUNNR' 'VBAK'  ''  ''.
  m_fieldcat_k 'VBELN' 'VBAK'  ''  ''.
  m_fieldcat_k 'NETWR' 'VBAK' c_x  'WAERK'.
  m_fieldcat_k 'WAERK' 'VBAK' ''   ''.


  m_fieldcat_p 'VKORG'  'VBAK' ''  ''.
  m_fieldcat_p 'KUNNR'  'VBAK' ''  ''.
  m_fieldcat_p 'VBELN'  'VBAK' ''  ''.
  m_fieldcat_p 'MATNR'  'VBAP' '' ''.
  m_fieldcat_p 'ARKTX'  'VBAP' ''  '' .
  m_fieldcat_p 'KWMENG' 'VBAP' ''  ''.
  m_fieldcat_p 'NETWR'  'VBAP' c_x  'WAERK'.
  m_fieldcat_p 'WAERK'  'VBAP' c_x  ''.


  ls_layout-zebra             = c_x.
  ls_layout-cell_merge        = c_x.
  ls_layout-colwidth_optimize = c_x.
  ls_layout-group_change_edit = c_x.


* Activate switch button
  CLEAR ls_event_exit.
  ls_event_exit-ucomm = c_eb9.     " Button switch
  ls_event_exit-after = c_x.
  APPEND ls_event_exit TO lt_event_exit.


  ls_print-no_print_selinfos  = c_x.   " Display no selection infos
  ls_print-no_print_listinfos = c_x.   " Display no listinfos


  l_exit = c_x.
  WHILE l_exit = c_x.
    IF l_flag = 1.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program       = sy-cprog
                i_callback_user_command  = 'USER_COMMAND'
                i_callback_pf_status_set = 'PF_STATUS_SET'
                is_layout                = ls_layout
                is_print                 = ls_print
                it_fieldcat              = lt_fieldcat_k
                it_event_exit            = lt_event_exit
                i_save                   = 'A'
           IMPORTING
                e_exit_caused_by_caller  = l_exit
           TABLES
                t_outtab                 = gt_vbak.
    ELSE.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program       = sy-cprog
                i_callback_user_command  = 'USER_COMMAND'
                i_callback_pf_status_set = 'PF_STATUS_SET'
                is_layout                = ls_layout
                is_print                 = ls_print
                it_fieldcat              = lt_fieldcat_p
                it_event_exit            = lt_event_exit
                i_save                   = 'A'
           IMPORTING
                e_exit_caused_by_caller  = l_exit
           TABLES
                t_outtab                 = gt_vbap.
    ENDIF.
    l_flag = l_flag * -1.
  ENDWHILE.


ENDFORM.                               " F_DISPLAY_DATA
*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm     TYPE syucomm
                        us_selfield TYPE slis_selfield.     "#EC CALLED


  CASE u_ucomm.
    WHEN c_eb9.
      us_selfield-exit = c_x.
  ENDCASE.


ENDFORM.                               " USER_COMMAND
*---------------------------------------------------------------------*
*       FORM PF_STATUS_SET                                            *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab.        "#EC CALLED


* Display switch button
  DELETE ut_extab WHERE fcode = c_eb9.


  SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
      EXCLUDING ut_extab.


ENDFORM.                               " PF_STATUS_SET
***************** END OF PROGRAM Z_ALV_SWITCH_LIST ********************