REPORT ZPD_LANGTEXT.
*&---------------------------------------------------------------------*
*& Report ZPD_LANGTEXT
*& Auslesen von Langtexten über Funktionsbaustein READ_TEXT
*&---------------------------------------------------------------------*
*& Frank Sauter
*& Version 1.0 2008-02-20
*&---------------------------------------------------------------------*
TABLES: thead, itcpo.
DATA:
BEGIN OF forms OCCURS 10,
name LIKE stxh-tdname,
END OF forms,
len_find TYPE i,
len_2 TYPE i,
len_text TYPE i,
len_rest TYPE i,
len_replace TYPE i,
fdpos TYPE i,
replaced(300),
function,
string_replaced,
ausgeben,
thead_new LIKE thead,
tstxh LIKE stxh OCCURS 0 WITH HEADER LINE,
xtlines LIKE tline OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS:
<replace>,
<vorher>,
<nachher>,
<findstr>,
<col>.
*-- Selektionsbild --*
SELECTION-SCREEN BEGIN OF BLOCK txt WITH FRAME TITLE text-001.
SELECT-OPTIONS:
name FOR tstxh-tdname DEFAULT 'Z*' OPTION cp,
id FOR tstxh-tdid DEFAULT 'ST '.
PARAMETERS:
object LIKE tstxh-tdobject DEFAULT 'TEXT'.
SELECT-OPTIONS:
s_spras FOR tstxh-tdspras DEFAULT sy-langu NO INTERVALS.
SELECTION-SCREEN END OF BLOCK txt.
SELECTION-SCREEN BEGIN OF BLOCK suc WITH FRAME TITLE text-002.
PARAMETERS:
find(50) LOWER CASE,
replace(50) LOWER CASE.
SELECTION-SCREEN END OF BLOCK suc.
SELECTION-SCREEN BEGIN OF BLOCK par WITH FRAME TITLE text-003.
PARAMETERS:
del AS CHECKBOX, "leerzeilen löschen??
update AS CHECKBOX, "Sichern?
pagebrk AS CHECKBOX, "Seitenumbruch
nur_fs AS CHECKBOX. "Nur Fundstellen anzeigen?
SELECTION-SCREEN END OF BLOCK par.
START-OF-SELECTION.
len_find = strlen( find ).
len_replace = strlen( replace ).
* assign mit Längenangabe ist nötig, da sonst beim Replace der Text
* sowie die Leerzeichen bis zum Variablenende mit ersetzt werden :-)
IF len_replace > 0.
ASSIGN replace(len_replace) TO <replace>.
ENDIF.
*--> Lesen aller Texte <--*
SELECT * FROM stxh into table tstxh
WHERE tdobject = object
AND tdname IN name
AND tdid IN id
AND tdspras IN s_spras.
LOOP AT tstxh.
REFRESH xtlines.
*--> Lesen der gesammelten Texte <--*
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = tstxh-tdid
language = tstxh-tdspras
name = tstxh-tdname
object = tstxh-tdobject
IMPORTING
header = thead
TABLES
lines = xtlines
EXCEPTIONS
OTHERS = 8.
CHECK sy-subrc = 0.
*-- Prüfen, ob Text angezeigt werden soll --*
IF find NE space.
ausgeben = ' '.
LOOP AT xtlines.
IF xtlines-tdline CS find.
ausgeben = 'X'.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
ausgeben = 'X'.
ENDIF.
*-- Kopfinfo ausgeben --*
IF ausgeben = 'X'.
IF pagebrk = 'X'.
NEW-PAGE.
ENDIF.
FORMAT COLOR OFF.
WRITE AT /1(sy-linsz) sy-uline.
WRITE: / 'Text:', tstxh-tdname(50), 'in Sprache', tstxh-tdspras.
WRITE AT /1(sy-linsz) sy-uline.
*--> Ausgabe der Texte <--*
CLEAR string_replaced.
LOOP AT xtlines.
IF xtlines-tdline IS INITIAL AND del = 'X'.
DELETE xtlines.
string_replaced = 'X'.
ELSEIF xtlines-tdline CS find AND find NE space.
len_text = strlen( xtlines-tdline ).
fdpos = sy-fdpos.
WRITE / xtlines-tdformat COLOR 2.
IF replace NE space.
REPLACE find LENGTH len_find
WITH <replace> INTO xtlines-tdline.
string_replaced = 'X'.
MODIFY xtlines.
PERFORM ausgabe.
ELSE.
len_replace = len_find.
PERFORM ausgabe.
ENDIF.
ELSE.
CHECK nur_fs = space.
WRITE / xtlines-tdformat COLOR 2.
CASE xtlines-tdformat.
WHEN '/:'.
*-- SAP-Script: Befehl
WRITE xtlines-tdline(77) INTENSIFIED OFF.
WHEN '/E'.
*-- SAP-Script: Formular-Element
WRITE xtlines-tdline(77) COLOR 6.
WHEN '/W'.
*-- SAP-Script: Window
WRITE xtlines-tdline(77) COLOR 5.
WHEN OTHERS.
WRITE xtlines-tdline(77).
ENDCASE.
ENDIF.
ENDLOOP.
ENDIF.
*--> Speichern der Texte wenn im Text ersetzt wurde <--*
IF string_replaced = 'X' AND update = 'X'.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = thead
savemode_direct = 'X'
IMPORTING
function = function
newheader = thead_new
TABLES
lines = xtlines
EXCEPTIONS
OTHERS = 5.
ENDIF.
ENDLOOP.
*---------------------------------------------------------------------*
* FORM AUSGABE *
*---------------------------------------------------------------------*
FORM ausgabe.
UNASSIGN: <vorher>, <nachher>, <findstr>.
IF fdpos > 0.
ASSIGN xtlines-tdline(fdpos) TO <vorher>.
ELSE.
ASSIGN space TO <vorher>.
ENDIF.
ASSIGN xtlines-tdline+fdpos(len_replace) TO <findstr>.
ADD len_replace TO fdpos.
len_2 = 132 - fdpos.
ASSIGN xtlines-tdline+fdpos(len_2) TO <nachher>.
WRITE: <vorher> NO-GAP,
<findstr> COLOR 3 NO-GAP,
<nachher>.
ENDFORM.