2007 Sep 28 1:56 PM
hi iam new to abap can anyone help me in converting a alv_list programme into alv_grid.I just need to know what r the changes i need to make.below is the code.
************************************************************************
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_mara ,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
END OF ty_mara ,
BEGIN OF ty_makt ,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_makt ,
BEGIN OF ty_final ,
mtart TYPE mara-mtart,
matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_final .
************************************************************************
*************************INTERNAL TABLES******************************
************************************************************************
DATA: it_mara TYPE TABLE OF ty_mara ,
it_makt TYPE TABLE OF ty_makt ,
it_final TYPE TABLE OF ty_final ,
it_fieldcat TYPE slis_t_fieldcat_alv,
it_events TYPE slis_t_event .
************************************************************************
*************************WORK AREAS***********************************
************************************************************************
DATA: wa_mara TYPE ty_mara ,
wa_makt TYPE ty_makt ,
wa_final TYPE ty_final ,
wa_fieldcat TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv ,
wa_events TYPE slis_alv_event .
************************************************************************
**************************VARIABLES***********************************
************************************************************************
DATA: v_mtart TYPE mara-mtart, "#EC NEEDED
v_repid TYPE sy-repid ,
v_text TYPE string .
************************************************************************
**************************CONSTANTS***********************************
************************************************************************
CONSTANTS: c_zroh(4) TYPE c VALUE 'ZROH' ,
c_x(1) TYPE c VALUE 'X' ,
c_02(2) TYPE c VALUE '02' ,
c_04(2) TYPE c VALUE '04' ,
c_06(2) TYPE c VALUE '06' ,
c_mtart(5) TYPE c VALUE 'MTART' ,
c_matnr(5) TYPE c VALUE 'MATNR' ,
c_maktx(5) TYPE c VALUE 'MAKTX' ,
c_it_final(8) TYPE c VALUE 'IT_FINAL' ,
c_mara(4) TYPE c VALUE 'MARA' ,
c_makt(4) TYPE c VALUE 'MAKT' ,
c_l(1) TYPE c VALUE 'L' ,
c_user_command(12) TYPE c VALUE 'USER_COMMAND' ,
c_alv_user_command(16) TYPE c VALUE 'ALV_USER_COMMAND',
c_top_of_page(11) TYPE c VALUE 'TOP_OF_PAGE' ,
c_alv_top_of_page(15) TYPE c VALUE 'ALV_TOP_OF_PAGE' ,
c_end_of_list(11) TYPE c VALUE 'END_OF_LIST' ,
c_alv_end_of_list(15) TYPE c VALUE 'ALV_END_OF_LIST' .
************************************************************************
************************INITIALIZATION********************************
************************************************************************
INITIALIZATION.
Initialize MTART at the selection screen
PERFORM initialize_mtart.
************************************************************************
*********************SELECTION SCREEN*********************************
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: p_mtart TYPE mara-mtart.
SELECTION-SCREEN END OF BLOCK blk1.
************************************************************************
*********************AT SELECTION SCREEN******************************
************************************************************************
AT SELECTION-SCREEN.
Validate MTART entered at the selection screen.
PERFORM validate_mtart.
************************************************************************
**********************START-OF-SELECTION******************************
************************************************************************
START-OF-SELECTION.
Select all the required data
PERFORM select_data.
Prepare final table
PERFORM populate_final_tab.
************************************************************************
**********************END-OF-SELECTION********************************
************************************************************************
END-OF-SELECTION.
Prepare ALV settings for display
PERFORM prepare_settings.
Display ALV Report
PERFORM display_report.
************************************************************************
**********************SUBROUTINES*************************************
************************************************************************
&----
*& Form initialize_mtart
&----
Subroutine to Initialize MTART at the selection screen.
----
FORM initialize_mtart .
p_mtart = c_zroh.
ENDFORM. " initialize_mtart
&----
*& Form validate_mtart
&----
This subroutine is to validate MTART entered at the
selection screen.
----
FORM validate_mtart .
SELECT SINGLE mtart
FROM t134
INTO v_mtart
WHERE mtart = p_mtart.
If not found display error message
IF sy-subrc <> 0.
MESSAGE e014 WITH text-002.
ENDIF.
ENDFORM. " validate_mtart
&----
*& Form select_data
&----
This subroutine selects all the required data
----
FORM select_data .
SELECT matnr
mtart
FROM mara
INTO TABLE it_mara
WHERE mtart = p_mtart.
IF sy-subrc <> 0.
MESSAGE i014 WITH text-003.
LEAVE LIST-PROCESSING.
ELSE.
SORT it_mara BY matnr.
SELECT matnr
maktx
FROM makt
INTO TABLE it_makt
FOR ALL ENTRIES IN it_mara
WHERE matnr = it_mara-matnr
AND spras = sy-langu.
IF sy-subrc <> 0.
MESSAGE i014 WITH text-004.
LEAVE LIST-PROCESSING.
ELSE.
SORT it_mara BY mtart.
SORT it_makt BY matnr.
ENDIF.
ENDIF.
ENDFORM. " select_data
&----
*& Form populate_final_tab
&----
This subroutine prepares final internal table.
----
FORM populate_final_tab .
LOOP AT it_mara INTO wa_mara.
CLEAR wa_final.
CLEAR wa_makt.
READ TABLE it_makt INTO wa_makt
WITH KEY matnr = wa_mara-matnr
BINARY SEARCH.
IF sy-subrc = 0.
wa_final-mtart = wa_mara-mtart.
wa_final-matnr = wa_mara-matnr.
wa_final-maktx = wa_makt-maktx.
APPEND wa_final TO it_final.
ENDIF.
ENDLOOP.
ENDFORM. " populate_final_tab
&----
*& Form prepare_settings
&----
This subroutine prepares ALV settings for display
----
FORM prepare_settings .
Prepare layout
CLEAR wa_layout.
wa_layout-zebra = c_x.
Prepare fieldcat
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = c_02.
wa_fieldcat-fieldname = c_mtart.
wa_fieldcat-tabname = c_it_final.
wa_fieldcat-ref_fieldname = c_mtart.
wa_fieldcat-ref_tabname = c_mara.
wa_fieldcat-ddictxt = c_l.
wa_fieldcat-seltext_l = text-005.
wa_fieldcat-seltext_m = text-005.
wa_fieldcat-seltext_s = text-005.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = c_04.
wa_fieldcat-fieldname = c_matnr.
wa_fieldcat-tabname = c_it_final.
wa_fieldcat-ref_fieldname = c_matnr.
wa_fieldcat-ref_tabname = c_mara.
wa_fieldcat-ddictxt = c_l.
wa_fieldcat-seltext_l = text-006.
wa_fieldcat-seltext_m = text-006.
wa_fieldcat-seltext_s = text-006.
wa_fieldcat-hotspot = c_x.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = c_06.
wa_fieldcat-fieldname = c_maktx.
wa_fieldcat-tabname = c_it_final.
wa_fieldcat-ref_fieldname = c_maktx.
wa_fieldcat-ref_tabname = c_makt.
wa_fieldcat-ddictxt = c_l.
wa_fieldcat-seltext_l = text-007.
wa_fieldcat-seltext_m = text-007.
wa_fieldcat-seltext_s = text-007.
APPEND wa_fieldcat TO it_fieldcat.
Prepare Events table.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
SORT it_events BY name.
CLEAR wa_events.
READ TABLE it_events INTO wa_events
WITH KEY name = c_user_command
BINARY SEARCH.
IF sy-subrc = 0.
wa_events-form = c_alv_user_command.
MODIFY it_events
FROM wa_events
INDEX sy-tabix
TRANSPORTING form.
ENDIF.
CLEAR wa_events.
READ TABLE it_events INTO wa_events
WITH KEY name = c_top_of_page
BINARY SEARCH.
IF sy-subrc = 0.
wa_events-form = c_alv_top_of_page.
MODIFY it_events
FROM wa_events
INDEX sy-tabix
TRANSPORTING form.
ENDIF.
CLEAR wa_events.
READ TABLE it_events INTO wa_events
WITH KEY name = c_end_of_list
BINARY SEARCH.
IF sy-subrc = 0.
wa_events-form = c_alv_end_of_list.
MODIFY it_events
FROM wa_events
INDEX sy-tabix
TRANSPORTING form.
ENDIF.
ENDFORM. " prepare_settings
&----
*& Form display_report
&----
This subroutine calls FM to display report
----
FORM display_report .
CLEAR v_repid.
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
is_layout = wa_layout
it_fieldcat = it_fieldcat
it_events = it_events
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " display_report
&----
*& Form alv_user_command
&----
This subroutine handles user command
----
FORM alv_user_command USING v_cmd TYPE sy-ucomm
wa_selfield TYPE slis_selfield. "#EC * "#EC CALLED
CLEAR wa_final.
READ TABLE it_final INTO wa_final
INDEX wa_selfield-tabindex.
CLEAR v_text.
CONCATENATE text-008
wa_final-matnr
INTO v_text
SEPARATED BY space.
Display to user which material he/she has clicked
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
titel = text-009
textline1 = v_text
start_column = 25
start_row = 6.
ENDFORM. "alv_user_command.
&----
*& Form alv_top_of_page
&----
This subroutine writes top of page
----
FORM alv_top_of_page. "#EC CALLED
FORMAT COLOR COL_HEADING.
ULINE AT /1(80).
WRITE:/1 sy-vline,
2 text-010,
9 sy-datum,
80 sy-vline.
WRITE:/1 sy-vline,
2 text-011,
9 sy-uzeit,
40 text-012,
80 sy-vline.
WRITE:/1 sy-vline,
2 text-013,
9 sy-uname,
80 sy-vline.
ULINE AT /1(80).
FORMAT COLOR OFF.
ENDFORM. "alv_top_of_page.
&----
*& Form alv_end_of_list
&----
This subroutine writes end of list
----
FORM alv_end_of_list. "#EC CALLED
FORMAT COLOR COL_HEADING.
ULINE AT /1(80).
WRITE:/1 sy-vline,
2 text-014,
12 sy-pagno,
80 sy-vline.
ULINE AT /1(80).
FORMAT COLOR OFF.
ENDFORM. "alv_end_of_list.
2007 Sep 28 1:58 PM
Hi,
Now u need to use the FM ' Reuse_alv_grid_display insted of
the FM 'Reuse_alv_list_display.
regards,
S.Agarwal..