SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

ALV Grid - Example with an ALV Grid list and 2 Popup Lists



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Jan 26, 2008 5:24 pm    Post subject: ALV Grid - Example with an ALV Grid list and 2 Popup Lists Reply with quote

Code:
REPORT z_alv_grid_and_2_popup.
*---------------------------------------------------------------------*
* This program is an example with an ALV Grid list and 2 Popup List   *
* The customers are displayed in a ALV Grid list                      *
* When a line is selected, the customer's orders are displayed in     *
* a popup list                                                        *
* When a line is selected in the second list, the items orders are    *
* displayed in the second popup list                                  *
*---------------------------------------------------------------------*
* Author : Michel PIOUD - Updated 19-nov-07                           *
* HomePage : http://www.geocities.com/mpioud                          *
*---------------------------------------------------------------------*
* 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.
*---------------------------------------------------------------------*
CONSTANTS :
  c_x VALUE 'X'.
*---------------------------------------------------------------------*

TYPE-POOLS: slis.                      " ALV Global types

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:
* Data displayed in the Grid list
  BEGIN OF ty_kna1,
    kunnr TYPE kna1-kunnr,             " Customer number
    name1 TYPE kna1-name1,             " Customer name
    ort01 TYPE kna1-ort01,             " Customer city
  END OF ty_kna1,

* Orders displayed in the first popup
  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
  END OF ty_vbak,

* Items displayed in the second popup
  BEGIN OF ty_vbap,
    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
  END OF ty_vbap.
*---------------------------------------------------------------------*
DATA :
  gt_kna1 TYPE TABLE OF ty_kna1,
  gt_vbak TYPE TABLE OF ty_vbak,
  gt_vbap TYPE TABLE OF ty_vbap.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_1 = 'Maximum of records to read'.

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

  PERFORM f_read_data_kna1.

  PERFORM f_display_data_kna1.

*---------------------------------------------------------------------*
*      Form  f_read_data_kna1
*---------------------------------------------------------------------*
FORM f_read_data_kna1.

* Read customer data with a least one order
  SELECT kunnr name1 ort01 INTO TABLE gt_kna1
           FROM kna1 AS k
             UP TO p_max ROWS
          WHERE EXISTS
       ( SELECT kunnr FROM vbak WHERE kunnr = k~kunnr ).

ENDFORM.                               " F_READ_DATA_KNA1
*---------------------------------------------------------------------*
*      Form  f_display_data_kna1
*---------------------------------------------------------------------*
FORM f_display_data_kna1.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'KUNNR' 'KNA1'.
  m_fieldcat 'NAME1' 'KNA1'.
  m_fieldcat 'ORT01' 'KNA1'.

* Display the first list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND_KNA1'
      it_fieldcat             = lt_fieldcat
    TABLES
      t_outtab                = gt_kna1.

ENDFORM.                               " F_DISPLAY_DATA_KNA1
*---------------------------------------------------------------------*
*       FORM USER_COMMAND_KNA1                                        *
*---------------------------------------------------------------------*
FORM user_command_kna1 USING u_ucomm     TYPE sy-ucomm
                             us_selfield TYPE slis_selfield."#EC CALLED

  DATA :
    ls_kna1 TYPE ty_kna1.

  CASE u_ucomm.
    WHEN '&IC1'.                       " Pick
      READ TABLE gt_kna1 INDEX us_selfield-tabindex INTO ls_kna1.
      CHECK sy-subrc EQ 0.
      PERFORM f_read_data_vbak         " Read data from VBAK
        USING ls_kna1-kunnr.
      PERFORM f_display_data_vbak.     " Display orders
  ENDCASE.

ENDFORM.                               " USER_COMMAND_KNA1
*---------------------------------------------------------------------*
*      Form  f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data_vbak USING u_kunnr TYPE kunnr.

  SELECT vkorg kunnr vbeln netwr INTO TABLE gt_vbak
    FROM vbak
      UP TO p_max ROWS
   WHERE kunnr = u_kunnr.

ENDFORM.                               " F_READ_DATA_VBAK
*---------------------------------------------------------------------*
*      Form  f_display_data_vbak
*---------------------------------------------------------------------*
FORM f_display_data_vbak.

  DATA:
    ls_private  TYPE slis_data_caller_exit,
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'VBELN' 'VBAK'.
  m_fieldcat 'VKORG' 'VBAK'.
  m_fieldcat 'KUNNR' 'VBAK'.
  m_fieldcat 'NETWR' 'VBAK'.

* Display the second list
  ls_private-columnopt = c_x.          " Optimize width

* Display orders in a POPUP
  CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
    EXPORTING
      i_selection             = ' '
      i_tabname               = 'GT_VBAK'
      it_fieldcat             = lt_fieldcat
      is_private              = ls_private
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND_VBAK'
    TABLES
      t_outtab                = gt_vbak.

ENDFORM.                               " F_DISPLAY_DATA_VBAK
*---------------------------------------------------------------------*
*       FORM USER_COMMAND_VBAK                                        *
*---------------------------------------------------------------------*
FORM user_command_vbak USING u_ucomm     TYPE sy-ucomm
                             us_selfield TYPE slis_selfield."#EC CALLED

  DATA:
    ls_vbak TYPE ty_vbak.

  CASE u_ucomm.
    WHEN '&ICM'.                       " Pick
      READ TABLE gt_vbak INDEX us_selfield-tabindex INTO ls_vbak.
      CHECK sy-subrc EQ 0.
      PERFORM f_read_data_vbap         " Read data from VBAP
        USING ls_vbak-vbeln.
      PERFORM f_display_data_vbap.     " Display items
  ENDCASE.

ENDFORM.                               " USER_COMMAND_VBAK
*---------------------------------------------------------------------*
*      Form  f_read_data_vbap
*---------------------------------------------------------------------*
FORM f_read_data_vbap USING u_vbeln TYPE vbeln_va.

  SELECT posnr matnr arktx kwmeng netwr
    INTO TABLE gt_vbap
    FROM vbap
   WHERE vbeln = u_vbeln.

ENDFORM.                               " F_READ_DATA_VBAP
*---------------------------------------------------------------------*
*      Form  f_display_data_vbap
*---------------------------------------------------------------------*
FORM f_display_data_vbap.

  TYPE-POOLS kkblo.

  DATA:
    ls_layout   TYPE kkblo_layout,
    ls_fieldcat TYPE kkblo_fieldcat,
    lt_fieldcat TYPE kkblo_t_fieldcat.

* Build the field catalog
  m_fieldcat 'POSNR'  'VBAP'.
  m_fieldcat 'MATNR'  'VBAP'.
  m_fieldcat 'ARKTX'  'VBAP'.
  m_fieldcat 'KWMENG' 'VBAP'.
  m_fieldcat 'NETWR'  'VBAP'.

  ls_layout-colwidth_optimize = c_x.   " Optimize width
  ls_layout-no_input = c_x.            " No selection

* Display items in a POPUP
  CALL FUNCTION 'K_KKB_LIST_DISPLAY'
    EXPORTING
      i_callback_program       = 'SAPLKKBL'
      i_callback_pf_status_set = 'LFIS_PF_STATUS_SET2'
      i_tabname                = 'GT_VBAP'
      is_layout                = ls_layout
      it_fieldcat              = lt_fieldcat
      i_screen_start_column    = 25
      i_screen_start_line      = 3
      i_screen_end_column      = 110
      i_screen_end_line        = 20
    TABLES
      t_outtab                 = gt_vbap.

ENDFORM.                               " F_DISPLAY_DATA_VBAP
************** END OF PROGRAM Z_ALV_GRID_AND_2_POPUP ******************
 
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.