Purpose Read and update texts (SAPscript long texts) The SAP function modules READ_TEXT and SAVE_TEXT can be used to read and update texts such as customer order header texts, plant maintenance notification texts and so on. You can call up these functions via the GuiXT Open Call interface. General suggestion: We suggest you use an InputScript with CopyText ... toScreen for updating texts, or call up a suitable BAPI function. The reason is that the SAP applications often have special rules to build up parts of the texts or to format ithem in a special way, which you can violate with your own SAVE_TEXT call. Also, some applications (e.g. IW21/IW22) maintain an additional "long text indicator" in a database table so that your new text added with "SAVE_TEXT" will not become visible in the transaction. Adding text lines to an existing text can be done, but even in this case it is better to use the BAPI based solution that we describe at the end of this article. |
Example
After saving the text, the transactions IW22/IW23 will show the added lines: In order to implement the application we first need the key data of the text in the SAP long text database. The easiest way to obtain the text key is to navigate to the long text editor in the SAP transaction , e.g. in IW22, and to display the text header (click on Goto->Header): The text name in our case is the full notification number, with leading zeros. With this knowledge we can read the text via READ_TEXT in the following way: // text key fields // notification number, 12 digits Set V[tdname](1-12) "000000000000&V[qmnum]" -alignRight // language EN, FR, DE,... // structure for returning the text header and content CreateTable V[textlines] tdformat tdline // read the text export.OBJECT="tdobject" _ export.NAME="tdname" _ export.ID="tdid" _ export.LANGUAGE="tdspras" _ import.HEADER="thead" _ import.LINES="textlines" We use the -try option in the Call statement in order to avoid an exception if the text does not exist. During the development it is better to work without -try so that you obtain any other exceptions, e.g. a wrong text object. Another way to find the text keys is to display table STXH: Since table STXH normally has many entries, you will need to guess the TDNAME in order to find the right entry. All possible text objects and text IDs can be found in the following tables: TTXOB Definition of the text objects A third way to find the text key is the SAP trace (transaction ST01). Switch on the trace for the database calls, then display the long text. In the trace output search for "STXH": The detail view (press F2) of the STXH trace entry will show the STXH
keys: With the text keys we read the text into a GuiXT table variable (see the above coding) and now want to copy the text lines into our textbox. We start with a test display of the text read via READ_TEXT, showing both the 2-character ITF format and the content for each line: CopyText
fromTable=V[textlines]
toText="temp"
You see that the ITF format of each line is ">X" which means
"read-only text line" in SAPScript:
You can use any number or letter for the 'x'. You can therefore separate different sub-headings, for example. If several fixed lines occur consecutively with the same indicator, they are regarded as a unit by the SAPscript editor. It is not possible to insert anything between these lines in the editor. In the case of fixed lines, SAPscript print formatting interprets the first two characters of the line as a paragraph format for formatting. You therefore need to enter the required paragraph format or blank here. Other common SAPscript line formats are: / New line See the SAP documentation for a full list of possible line formats. The formatting of the long text as "read-only" and the generation of the log header line (date, time and user name / id) can be configured in SAP. For example, for notification type M2:
So, when you work with SAVE_TEXT later on, you really have to know what you are doing in order to observe the formatting rules. In this example, we copy the content into the GuiXT long text
variable and assume that the whole text is read-only, see
InputScript "read_qmel_longtext.txt" below for the details. Analogously, when we save the text, we add the ITF line format ">X" to mark it as read-only and start each line with "* " (new paragraph), see InputScript "save_qmel_longtext.txt" below for the details.
GuiXT script InputField (2,1) "Notification" (2,12) size="12" name="qmnum" searchHelp="QMEG"TextBox (4,1) (8,72) name="qmel_longtext" -readOnlyTextBox (9,1) (14,72) name="qmel_addtext" Pushbutton (15,3) "Read text" process="read_qmel_longtext.txt" size=(2,16)Pushbutton (15,30) "Save text" process="save_qmel_longtext.txt" size=(2,16)
InputScript "read_qmel_longtext.txt" // text type (object and id) Set V[tdid] "LTXT" // text key: notification number, 12 digits Set V[tdname](1-12) "000000000000&V[qmnum]" -alignRight // language EN, FR, DE,... // structure for returning the text header and content CreateTable V[textlines] tdformat tdline Call "READ_TEXT" -try _export.OBJECT="tdobject" _ export.NAME="tdname" _ export.ID="tdid" _ export.LANGUAGE="tdspras" _ import.HEADER="thead" _ import.LINES="textlines" Clear
text[qmel_longtext] // copy text lines label next_lineif V[k<&V[textlines.rowcount]] Set V[k] &V[k] + 1 // skip the first two characters, they contain the format // since the lines are read-only (format >X ) Set V[line] "&V[textlines.tdline.&V[k]](3-200)" CopyText fromString="line" toText="qmel_longtext" -appendLine goto next_line endif
InputScript "save_qmel_longtext.txt" // anything to add ? else return return endif // add textbox content Set V[n] &V[textlines.rowcount] + 1 // add a line with date, time and author // set format: no change // set text line // add text Set V[k] &V[k] + 1 Set V[n] &V[n] + 1 CopyText fromText="qmel_addtext" toString="s" line="&V[k]"if Q[ok] // set format: no changeSet V[textlines.tdformat.&V[n]] ">X" // set text line Set V[textlines.tdline.&V[n]] "* &V[s]" goto next_textline endif // save text Call "SAVE_TEXT" _export.HEADER="thead" _ export.SAVEMODE_DIRECT="TRUE" _ export.LINES="textlines" // read text again
BAPI based soulution
// table for returning the text content Call "BAPI_ALM_NOTIF_GET_DETAIL" _export.NUMBER="qmnum" _ import.NOTLONGTXT="texttab" // copy text into our textbox // clear text box for
user input Return
// anything to add ? else return return endif // text table for BAPI call // fill text tableSet V[k] 1 label copy_add_lineCopyText fromText="qmel_addtext" toString=s line=&V[k] if q[ok] Set V[bapilongtext.objtype.&V[k]] "QMEL" Set V[bapilongtext.format_col.&V[k]] "/" Set V[bapilongtext.text_line.&V[k]] "&V[s]" Set V[k] &V[k] + 1 goto copy_add_line endif CreateStructure V[bapireturn] type messageCreateTable V[bapireturntab] include=V[bapireturn] Call "BAPI_ALM_NOTIF_DATA_ADD" _export.NUMBER="qmnum" _ export.NOTFULLTXT="bapilongtext" _ import.RETURN="bapireturntab" // Any error message? if Q[ok]Call "BAPI_TRANSACTION_ROLLBACK" Return "E: &V[bapireturn.message]" -statusline endif // Save to database export.NUMBER="qmnum" Call "BAPI_TRANSACTION_COMMIT"// read text again |
Components InputAssistant |