Google

ALV PROGARM WITH POPUP

*&---------------------------------------------------------------------*
*& Report ZALV_WITH_POPUP
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*

REPORT ZALV_WITH_POPUP .
* Macro definition
DEFINE M_FIELDCAT.
ADD 1 TO LS_FIELDCAT-COL_POS.
LS_FIELDCAT-FIELDNAME = &1.
LS_FIELDCAT-REF_TABNAME = &2.
* LS_FIELDCAT-CHECKBOX = &3.
ls_fieldcat-edit ='X'..
APPEND LS_FIELDCAT TO LT_FIELDCAT.
END-OF-DEFINITION.

TABLES : VBAK. " Sales Document: Header Data

TYPE-POOLS: SLIS. " ALV Global types

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.
PARAMETERS P_MAX(2) TYPE N DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

DATA:
* Data displayed in the first list
BEGIN OF GT_VBAK OCCURS 0,
* CHECKBOX,
VKORG LIKE VBAK-VKORG, " Sales organization
KUNNR LIKE VBAK-KUNNR, " Sold-to party
VBELN LIKE VBAK-VBELN, " Sales document
NETWR LIKE VBAK-NETWR, " Net Value of the Sales Order
END OF GT_VBAK,

* Data displayed in the popup list
BEGIN OF GT_VBAP OCCURS 0,
POSNR LIKE VBAP-POSNR, " Sales document item
MATNR LIKE VBAP-MATNR, " Material number
ARKTX LIKE VBAP-ARKTX, " Short text for sales order
item
KWMENG LIKE VBAP-KWMENG, " Order quantity
NETWR LIKE VBAP-NETWR, " Net value of the order item
END OF GT_VBAP,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

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

V_1 = 'Maximum of records to read'.

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

PERFORM F_READ_DATA_VBAK.

PERFORM F_DISPLAY_DATA_VBAK.

*---------------------------------------------------------------------*
* Form f_read_data_vbak
*---------------------------------------------------------------------*
FORM F_READ_DATA_VBAK.

SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_VBAK
FROM VBAK
UP TO P_MAX ROWS
WHERE KUNNR IN S_KUNNR
AND VBELN IN S_VBELN
AND VKORG IN S_VKORG.

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

* DATA:
* LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
* LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

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

* GS_LAYOUT-SEL_MODE = 'A'.
* Display the first list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = LT_FIELDCAT
IS_LAYOUT = GS_LAYOUT
TABLES
T_OUTTAB = GT_VBAK.

ENDFORM. " F_DISPLAY_DATA_VBAK
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING U_UCOMM LIKE SY-UCOMM
US_SELFIELD TYPE SLIS_SELFIELD.

CASE U_UCOMM.
WHEN '&IC1'.
READ TABLE GT_VBAK INDEX US_SELFIELD-TABINDEX.
CHECK SY-SUBRC EQ 0.
PERFORM F_READ_DATA_VBAP. " Read data from VBAP
PERFORM F_DISPLAY_DATA_VBAP.
ENDCASE.

ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form f_read_data_vbap
*---------------------------------------------------------------------*
FORM F_READ_DATA_VBAP.

SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_VBAP
FROM VBAP
WHERE VBELN = GT_VBAK-VBELN.

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

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 'POSNR' 'VBAP' .
M_FIELDCAT 'MATNR' 'VBAP' .
M_FIELDCAT 'ARKTX' 'VBAP' .
M_FIELDCAT 'KWMENG' 'VBAP' .
M_FIELDCAT 'NETWR' 'VBAP' .

LS_PRIVATE-COLUMNOPT = 'X'. " Optimize width

* Display items in a POPUP
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
I_SELECTION = ' '
I_TABNAME = 'GT_VBAP'
IT_FIELDCAT = LT_FIELDCAT
IS_PRIVATE = LS_PRIVATE
TABLES
T_OUTTAB = GT_VBAP.

ENDFORM. " F_DISPLAY_DATA_VBAP
**************** END OF PROGRAM Z_ALV_GRID_AND_POPUP ******************