REPORT z_alv_standard_text .
*---------------------------------------------------------------------*
* ALV List of standard text
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
CONSTANTS :
c_x VALUE 'X',
c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------*
TYPE-POOLS :
slis. " ALV Global types
*---------------------------------------------------------------------*
TYPES BEGIN OF ty_data.
INCLUDE TYPE stxh.
TYPES: tdline TYPE tline-tdline,
checkbox(1) TYPE c.
TYPES: END OF ty_data.
*---------------------------------------------------------------------*
DATA: gs_stxh TYPE stxh.
DATA gt_data TYPE TABLE OF ty_data.
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK standard WITH FRAME.
SELECT-OPTIONS:
s_mandt FOR gs_stxh-mandt DEFAULT sy-mandt
MATCHCODE OBJECT ddsef4clnt,
s_tdname FOR gs_stxh-tdname,
s_id FOR gs_stxh-tdid,
s_spras FOR gs_stxh-tdspras.
SELECTION-SCREEN END OF BLOCK standard.
SELECTION-SCREEN BEGIN OF BLOCK extension WITH FRAME.
SELECT-OPTIONS:
s_title FOR gs_stxh-tdtitle NO INTERVALS,
s_macod1 FOR gs_stxh-tdmacode1 NO INTERVALS,
s_macod2 FOR gs_stxh-tdmacode2 NO INTERVALS,
s_fuser FOR gs_stxh-tdfuser MATCHCODE OBJECT user_comp,
s_fdate FOR gs_stxh-tdfdate,
s_freles FOR gs_stxh-tdfreles,
s_luser FOR gs_stxh-tdluser MATCHCODE OBJECT user_comp,
s_ldate FOR gs_stxh-tdldate,
s_lreles FOR gs_stxh-tdlreles.
SELECTION-SCREEN END OF BLOCK extension.
SELECTION-SCREEN BEGIN OF BLOCK max WITH FRAME.
PARAMETERS:
p_string TYPE tdtitle,
p_max TYPE numc3 DEFAULT '100'.
SELECTION-SCREEN END OF BLOCK max.
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.
FIELD-SYMBOLS <data> TYPE ty_data.
SELECT * FROM stxh CLIENT SPECIFIED
INTO TABLE gt_data
UP TO p_max ROWS
WHERE tdobject = 'TEXT'
AND mandt IN s_mandt
AND tdname IN s_tdname
AND tdid IN s_id
AND tdspras IN s_spras
AND tdfuser IN s_fuser
AND tdfdate IN s_fdate
AND tdfreles IN s_freles
AND tdluser IN s_luser
AND tdldate IN s_ldate
AND tdlreles IN s_lreles
AND tdmacode1 IN s_macod1
AND tdmacode2 IN s_macod2
AND tdtitle IN s_title.
LOOP AT gt_data ASSIGNING <data>.
PERFORM fill_firstline USING <data>.
ENDLOOP.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = &2.
ls_sort-down = &3.
ls_sort-group = &4.
append ls_sort to lt_sort.
END-OF-DEFINITION.
* Macro definition
DEFINE m_fieldcat.
clear ls_fieldcat.
add 1 to l_pos.
ls_fieldcat-col_pos = l_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DATA:
l_pos TYPE i,
ls_print TYPE slis_print_alv,
ls_layout TYPE slis_layout_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_event_exit TYPE slis_event_exit,
lt_event_exit TYPE slis_t_event_exit.
* Layout
ls_layout-zebra = c_x.
ls_layout-cell_merge = c_x.
ls_layout-colwidth_optimize = c_x.
ls_layout-group_change_edit = c_x.
ls_layout-box_fieldname = 'CHECKBOX'.
* Build sort table
m_sort 'TDNAME' 'X' '' ''.
m_sort 'MANDT' 'X' '' ''.
m_sort 'TDSPRAS' 'X' '' ''.
* Build field catalog table
m_fieldcat 'MANDT' 'STXH'.
m_fieldcat 'TDNAME' 'STXH'.
m_fieldcat 'TDID' 'STXH'.
m_fieldcat 'TDFORM' 'STXH'.
m_fieldcat 'TDSPRAS' 'STXH'.
m_fieldcat 'TDFUSER' 'STXH'.
m_fieldcat 'TDFDATE' 'STXH'.
m_fieldcat 'TDFTIME' 'STXH'.
m_fieldcat 'TDLUSER' 'STXH'.
m_fieldcat 'TDLDATE' 'STXH'.
m_fieldcat 'TDLTIME' 'STXH'.
m_fieldcat 'TDLINE' 'TLINE'.
m_fieldcat 'TDVERSION' 'STXH'.
* Activate refresh button
CLEAR ls_event_exit.
ls_event_exit-ucomm = c_refresh. " Refresh
ls_event_exit-after = c_x.
APPEND ls_event_exit TO lt_event_exit.
* Print options
ls_print-no_print_selinfos = c_x. " Display no selection infos
ls_print-no_print_listinfos = c_x. " Display no listinfos
* Display data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'PF_STATUS_SET'
is_layout = ls_layout
is_print = ls_print
it_fieldcat = lt_fieldcat
it_sort = lt_sort
it_event_exit = lt_event_exit
i_save = 'A'
TABLES
t_outtab = gt_data.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN '&IC1'.
PERFORM f_lines USING us_selfield-tabindex.
WHEN c_refresh.
PERFORM f_read_data.
us_selfield-refresh = c_x.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* FORM PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED
* Display refresh button
DELETE ut_extab WHERE fcode = c_refresh.
SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.
ENDFORM. " PF_STATUS_SET
*---------------------------------------------------------------------*
* FORM f_lines *
*---------------------------------------------------------------------*
FORM f_lines USING u_index TYPE sytabix.
DATA :
ls_thead TYPE thead,
ls_data TYPE ty_data,
lt_lines TYPE tline_t.
READ TABLE gt_data INDEX u_index INTO ls_data.
CHECK sy-subrc EQ 0.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = ls_data-mandt
object = ls_data-tdobject
name = ls_data-tdname
id = ls_data-tdid
language = ls_data-tdspras
IMPORTING
header = ls_thead
TABLES
lines = lt_lines
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION 'SAPSCRIPT_MESSAGE'.
EXIT. " Exit Form
ENDIF.
CALL FUNCTION 'CHECK_TEXT_AUTHORITY'
EXPORTING
activity = 'SHOW'
object = ls_data-tdobject
name = ls_data-tdname
id = ls_data-tdid
language = ls_data-tdspras
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* No authorization to display text &1 &2 &3
MESSAGE s613(td) WITH ls_data-tdspras
ls_data-tdid
ls_data-tdname.
EXIT.
ENDIF.
CALL FUNCTION 'EDIT_TEXT'
EXPORTING
header = ls_thead
display = c_x
TABLES
lines = lt_lines
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
CALL FUNCTION 'SAPSCRIPT_MESSAGE'.
ENDIF.
ENDFORM. "f_lines
*---------------------------------------------------------------------*
* Form FILL_FIRSTLINE
*---------------------------------------------------------------------*
FORM fill_firstline USING us_data TYPE ty_data.
DATA:
l_msgline(72) TYPE c,
ls_lines TYPE tline,
lt_lines TYPE tline_t.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = us_data-mandt
id = us_data-tdid
language = us_data-tdspras
name = us_data-tdname
object = us_data-tdobject
TABLES
lines = lt_lines
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
l_msgline = 'Selected text module &1 not found'(011).
REPLACE '&1' WITH us_data-tdname INTO l_msgline.
MESSAGE s030(td) WITH l_msgline.
EXIT.
ENDIF.
LOOP AT lt_lines INTO ls_lines WHERE NOT tdline IS INITIAL.
us_data-tdline = ls_lines-tdline.
EXIT.
ENDLOOP.
IF NOT p_string IS INITIAL.
LOOP AT lt_lines INTO ls_lines WHERE NOT tdline IS INITIAL.
IF ls_lines-tdline CS p_string.
us_data-tdline = ls_lines-tdline.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " FILL_FIRSTLINE
****************** END OF PROGRAM Z_ALV_STANDARD_TEXT ******************
유용하게 사용하겠습니다. 감사합니다^^