A simple file editor could aid the interface process or allow easy changes/problem fixing on data that was e.g. delivered as an .XML file. This article holds a ready-to-use simple file editor where a file is opened, edited through the SO10
all standard text editor and stored again.
The concept is quite simple: the file to be edited would need to be a textual file, like xml or plain text settings. The editor shows lines of up to 72 characters only. Longer lines are cut up and the paragraph indicator shows which lines are cut, through the '= '
. So if you need to edit long lines, keep working with the line-concatenator.
The definition of this method:
edit_file IMPORTING filename TYPE any RETURNING value(e_returncode) TYPE sy-subrc.
The actual method:
METHOD edit_file. data: lt_textlines type standard table of tline, lt_textlines_long type standard table of char512, lw_textline type tline, lv_textline_long type char512, lw_thead type THEAD. e_returncode = 4. "Default assumption * Open (server) file and read it's content open dataset filename for input in text mode encoding default with smart linefeed. check sy-subrc = 0. clear: lt_textlines[]. WHILE sy-subrc = 0. READ DATASET filename INTO lv_textline_long. lw_textline-tdformat = '*'. lw_textline-tdline = lv_textline_long(72). append lw_textline to lt_textlines. if strlen( lv_textline_long ) > 72. lw_textline-tdformat = '='. lw_textline-tdline = lv_textline_long+72(72). append lw_textline to lt_textlines. endif. if strlen( lv_textline_long ) > 144. lw_textline-tdformat = '='. lw_textline-tdline = lv_textline_long+144(72). append lw_textline to lt_textlines. endif. if strlen( lv_textline_long ) > 216. lw_textline-tdformat = '='. lw_textline-tdline = lv_textline_long+216(72). append lw_textline to lt_textlines. endif. ENDWHILE. CLOSE DATASET filename. check not lt_textlines[] is initial. lw_thead-tdobject = 'TEXT'. lw_thead-tdname = 'MY.XML'. "This is shown in the title lw_thead-tdid = 'ST'. lw_thead-tdspras = sy-langu. lw_thead-TDLINESIZE = 72. CALL FUNCTION 'EDIT_TEXT' EXPORTING EDITOR_TITLE = ' ' header = lw_thead SAVE = ' ' LINE_EDITOR = 'X' tables lines = lt_textlines EXCEPTIONS OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. exit. ELSE. * Open (server) file and store it's content clear: lt_textlines_long[], lv_textline_long. loop at lt_textlines into lw_textline. if lw_textline-tdformat = '*'. if not lv_textline_long is initial. append lv_textline_long to lt_textlines_long. endif. lv_textline_long = lw_textline-tdline. elseif lw_textline-tdformat = '='. concatenate lv_textline_long lw_textline-tdline(72) into lv_textline_long. endif. endloop. if not lv_textline_long is initial. append lv_textline_long to lt_textlines_long. endif. open dataset filename for output in text mode encoding default with smart linefeed. check sy-subrc = 0. loop at lt_textlines_long into lv_textline_long. TRANSFER lv_textline_long TO filename. endloop. CLOSE DATASET filename. message 'changes processed' type 'S'. ENDIF. e_returncode = 0. ENDMETHOD.
To implement simply call lcl_your_class=>edit_file( '/usr/sap/SYSA/log/Alertcontrols.xml' ).
and the editor is presented to you.