Posted: Tue Sep 11, 2007 7:09 pm Post subject: Display a Secondary List using ALV Grid
To display a secondary list when you click on one of the row items in an alv grid. The secondary list should also be an alv.
Try out this code. You will have to make a structure ZSTR same as the output internal table.
Code:
REPORT ZSECOND_LIST_REP.
TABLES : MARA,
BHDGD,
zstr.
TYPES: BEGIN OF T_MARA,
MATNR LIKE MARA-MATNR,
ERNAM LIKE MARA-ERNAM,
END OF T_MARA.
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*Constants for ALV Implementation
CONSTANTS: C_SET VALUE 'X',
C_RESET VALUE '0',
C_SAVE VALUE 'A',
C_EXIT(4) VALUE 'EXIT',
C_BACK(4) VALUE 'BACK',
C_CANC(4) VALUE 'CANC',
C_PGTOP(5) VALUE 'PGTOP',
C_PGUP(4) VALUE 'PGUP',
C_PGDN(4) VALUE 'PGDN',
C_PGEND(5) VALUE 'PGEND'.
DATA : I_MARA TYPE STANDARD TABLE OF T_MARA WITH HEADER LINE,
* Internal table for fields catalouge
I_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
* i_fieldcat2 type lvc_t_fcat with header line,
* Internal table for cursor position
I_GT_SELROWS TYPE LVC_T_ROW .
DATA : WA_MARA LIKE I_MARA,
WA_GRIDROW LIKE LVC_S_ROW,
WA_GRIDCOL LIKE LVC_S_COL.
*Data for ALV Implementation.
DATA: OK_CODE LIKE SY-UCOMM,
W_OK_CODE LIKE SY-UCOMM,
W_CALL TYPE I VALUE 1,
W_TAB LIKE SY-UCOMM VALUE 'TAB1',
W_SAVE, "For Parameter I_SAVE
W_VARIANT TYPE DISVARIANT, "For parameter IS_VARIANT
W_GRID TYPE REF TO CL_GUI_ALV_GRID,
* w_grid1 type ref to cl_gui_alv_grid,
W_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
* w_container1 type ref to cl_gui_custom_container,
W_REPID LIKE SY-REPID,
W_GS_PRINT TYPE LVC_S_PRNT,
W_GS_LAYOUT TYPE LVC_S_LAYO,
W_EVENT_REC TYPE REF TO LCL_EVENT_RECEIVER,
W_CONT_MAIN TYPE SCRFNAME VALUE 'CCCONTAINER',
W_LN TYPE I, "line number
W_INDEX LIKE SY-TABIX,
W_FLAG,
W_TEMP_VAL TYPE I.
*---------------------------------------------------------------------*
* Definition:
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_TOP_OF_PAGE
FOR EVENT PRINT_TOP_OF_PAGE OF CL_GUI_ALV_GRID,
HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
ENDCLASS.
*---------------------------------------------------------------------*
* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_TOP_OF_PAGE.
PERFORM F_GET_HEADER.
ENDMETHOD. "handle_top_of_page
METHOD HANDLE_DOUBLE_CLICK.
* The event DOUBLE_CLICK provides parameters for row and column
* of the click. We use row parameter to select a line of the
* corresponding internal table.
* read selected row from internal table
READ TABLE I_MARA INDEX E_ROW-INDEX INTO WA_MARA.
IF SY-SUBRC <> 0.
* message i001. " Cursor position not correct.
ELSE.
* call dialog screen and display the details
call screen 200 starting at 10 5.
ENDIF.
*&---------------------------------------------------------------------*
*& Form f_get_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_GET_HEADER.
DATA: L_LINE1 LIKE BHDGD-LINE1,
L_LINE2 LIKE BHDGD-LINE2.
CONSTANTS LC_SPACE VALUE ' '.
DATA: L_F1(7), L_F2(11), L_F3(9), L_F4(6), L_F5(11), L_F6(4), L_F7(8),
L_F8(4),L_F9(10), L_F11(11), L_F12(24), L_F13(4),
L_F14(3).
* take the values of line1 and line2 into two new variables, otherwise
* after coming back to the first screen from the print preview, the
* header shows the condensed lines
L_LINE1 = BHDGD-LINE1.
L_LINE2 = BHDGD-LINE2.
CONDENSE L_LINE1.
CONDENSE L_LINE2.
*split the lines to display the whole lines within the
*stipulated report-width
SPLIT L_LINE1 AT LC_SPACE INTO L_F1 L_F2 L_F3 L_F4 L_F5 L_F6 L_F7 L_F8
L_F9 .
ENDFORM. " f_get_header
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STAT'.
SET TITLEBAR 'TITL'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM .
WHEN C_EXIT OR C_BACK OR C_CANC.
IF NOT W_CONTAINER IS INITIAL.
CALL METHOD W_CONTAINER->FREE.
ENDIF.
LEAVE TO SCREEN 0.
WHEN C_PGTOP.
WA_GRIDROW-INDEX = 1.
WHEN C_PGUP.
IF WA_GRIDROW-INDEX <= 15.
WA_GRIDROW-INDEX = 1.
ELSE.
WA_GRIDROW-INDEX = WA_GRIDROW-INDEX - 15.
ENDIF.
WHEN C_PGEND.
PERFORM F_GET_NO_ROWS.
WA_GRIDROW-INDEX = W_LN.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form f_get_no_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_GET_NO_ROWS.
* Build the fieldcat according to structure
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZSTR'
CHANGING
CT_FIELDCAT = I_FIELDCAT[].
LOOP AT I_FIELDCAT.
W_INDEX = SY-TABIX.
CASE I_FIELDCAT-FIELDNAME.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_TOP_OF_PAGE FOR W_GRID.
CREATE OBJECT W_EVENT_REC.
SET HANDLER W_EVENT_REC->HANDLE_DOUBLE_CLICK FOR W_GRID.
W_FLAG = C_RESET.
ENDMODULE. " DISPLAY_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Form f_std_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_STD_HEADER.
ENDFORM. " f_std_header
*&---------------------------------------------------------------------*
*& Module DYNPRONR_CHECK_500 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE DYNPRONR_CHECK_500 OUTPUT.
* if w_dynpronr is initial.
* w_dynpronr = '0100'.
* endif.
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.