有幾種使用ALV的方法,所以我們確實需要更多的代碼信息來幫助。
- 第一種方法是使用功能模塊REUSE_ALV_GRID_DISPLAY。這將直接在輸出dynpro中顯示錶格內容。如果你所需要的只是一個顯示,那就去做吧,因爲這是最簡單的:如果表結構在字典中,這個調用可以像下面這樣簡單(這將顯示結構的所有成員作爲列)
myreport = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = myreport
it_excluding = exclude_tab
TABLES
t_outtab = display_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
如果結構在程序中聲明,那麼你必須創建一個字段目錄。 下面的代碼可以作爲基礎:
FORM fill_fieldcat CHANGING p_fieldcat TYPE slis_t_fieldcat_alv.
* Data definition
DATA ls_fieldcat TYPE slis_fieldcat_alv.
* Macro definition
DEFINE append_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = &1. * name of the field in struct
ls_fieldcat-tabname = &2. * name of the table
ls_fieldcat-row_pos = &3. * column
ls_fieldcat-ref_fieldname = &4. * field in ref table
ls_fieldcat-ref_tabname = &5. * ref table
ls_fieldcat-outputlen = &6. * size of output
ls_fieldcat-seltext_m = &7. * text (space if using the element typetext)
ls_fieldcat-ddictxt = 'M'.
ls_fieldcat-key = &8. * is this a key field in table
ls_fieldcat-emphasize = &9. * emphisze column display
append ls_fieldcat to p_fieldcat.
END-OF-DEFINITION.
* Init.
REFRESH p_fieldcat.
* Append fielcatalog for ALV
append_fieldcat:
'FORMATIONCODE' 'DISPLAY_TAB' 1 'SHORT' 'HRP1000' 12 'Code Stage' space space,
'FORMATIONTEXT' 'DISPLAY_TAB' 1 'STEXT' 'HRP1000' 20 'Libelle Stage' space space,
'SESSIONID' 'DISPLAY_TAB' 1 'OBJID' 'HRP1000' space 'Session' space space,
'BEGDA' 'DISPLAY_TAB' 1 'BEGDA' 'HRP1000' space 'Debut' space space,
'ENDDA' 'DISPLAY_TAB' 1 'BEGDA' 'HRP1000' space 'Fin' space space,
ENDFORM. "fill_fieldCat
你再調用形式來創建字段目錄,並在函數調用的參數it_fieldcat使用它。
- 第二種方法是使用ABAP對象。使用檢查se83作爲這種用法的例子。基礎如下:
在您的Dynpro中,您聲明瞭一個具有給定名稱(「ALV_CONT」)的自定義容器。然後,在隨後的dynpro的PBO初始化容器,並把一個ALV objct內:
* global variables :
DATA : delegationlist_table TYPE REF TO cl_gui_alv_grid,
delegationlist_container TYPE REF TO cl_gui_custom_container.
data : gs_layout TYPE lvc_s_layo.
在PBO
IF delegationlist_container IS INITIAL.
* create a custom container control for our ALV Control
CREATE OBJECT delegationlist_container
EXPORTING
container_name = 'ALV_CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
* create an instance of alv control
CREATE OBJECT delegationlist_table
EXPORTING
i_parent = delegationlist_container.
* Set a titlebar for the grid control
gs_layout-grid_title = 'Délégations'.
gs_layout-sel_mode = 'A'.
gs_layout-cwidth_opt ='X'.
* set table as data source
* the struct name *must* be uppercase
* the table must have this struc
CALL METHOD delegationlist_table->set_table_for_first_display
EXPORTING
i_structure_name = 'ZPRT_DELEGATIONLIST'
is_layout = gs_layout
CHANGING
it_outtab = delegationlist.
ENDIF.
希望,這幫助下,
問候
紀堯姆·帕特里
你在打什麼功能模塊? – BenV 2010-09-17 13:24:55
如果可能的話,你應該總是提供一些示例代碼,這將使答案更容易。 – vwegert 2010-09-18 14:23:37