Create a Word document which will serve as a template for
the final document
For the variable parts use placeholders &[xxx] where xxx
stands for the name of a GuiXT variable
For GuiXT text variables use &text[xxx] where xxx
stands for the name of a GuiXT text variable
For Word tables put placeholders &[xxx.###] into the cells. Here
### will be replaced with the row number 1,2,3,... to form a GuiXT
variable name xxx.1, xxx.2, ...
Save the Word document as .rtf file, e.g. mytemplate.rtf
In your InputScript, use CopyText ...
fromTemplate="mytemplate.rtf". The template file is read
and your
placeholders are replaced with the content of the GuiXT variables.
New table
rows are added as long as a GuiXT variable with the corresponding row number exists
for the first column
Save the file as .rtf file or .doc file
Remark The
placeholders &[xxx] must not contain any inner formatting, for example
&[xxx] (first 2 xx
in bold). It is important that the placeholder strings appear in the
form &[xxx] in the resulting template .rtf file. If a placeholder is
not substituted by the value of the corresponding GuiXT variable, copy the
whole placeholder string &[xxx] into a simple editor such as "notepad",
delete the string in Word and copy the string from notepad again into
the Word document. This removes any inner formatting of the placeholder
string. If you open the rtf file with notepad, a wrong placeholder
looks like &[rtf.c}{\rtlch\fcs1 \af1 \ltrch\fcs0... instead of
&[rtf.cn] for example.
Example We generate a Word document that shows all customer orders for one
month.
Template file
The upper part of the page, including the column headers, is
within the page heading of the Word document so that the column headers
are repeated on each new page.
Result
InputScript We read the customer orders
directly from the database tables VBAK and KNA1 via the function
/GUIXT/dbselect. Other options would be to use a BAPI or to call up a
suitable transaction, ABAP report or an SQ01 query. GuiXT
// read customer orders as database join of VBAK and KNA1
Clear text[r]
Set V[dateCondition] "VBAK~AUDAT BETWEEN '20180101' AND '20180131'"
Set V[trvogCondition] "VBAK~TRVOG = '0'"
Set V[allcondition] "&V[dateCondition] AND &V[trvogCondition]"
Call "/guixt/dbselect" _
in.table="VBAK join KNA1 on KNA1~KUNNR = VBAK~KUNNR" _
in.fields="KNA1~NAME1,KNA1~STRAS,KNA1~PSTLZ,KNA1~ORT01,
VBAK~VBELN,VBAK~AUDAT AS D1,VBAK~NETWR AS P1" _
in.orderBy="D1 ascending" _
in.condition="&V[allcondition]" _
table.values="r"
// fill rtf variables
Clear V[rtf.*]
Set V[rtf.month] "January"
Set V[rtf.year] "2018"
Set V[k] 1
Set V[n] 1
label next_value
// customer name
CopyText fromText="r" toString="rtf.cn.&V[n]" line=&V[k]
if Q[ok]
Set V[k] &V[k] + 1
// street
CopyText fromText="r" toString="rtf.cs.&V[n]" line=&V[k]
Set V[k] &V[k] + 1
// post code
CopyText fromText="r" toString="rtf.cp.&V[n]" line=&V[k]
Set V[k] &V[k] + 1
// city
CopyText fromText="r" toString="rtf.cc.&V[n]" line=&V[k]
Set V[k] &V[k] + 1
// order number
CopyText fromText="r" toString="rtf.on.&V[n]" line=&V[k]
Set V[k] &V[k] + 1
// order date
CopyText fromText="r" toString="rtf.od.&V[n]" line=&V[k]
Set V[k] &V[k] + 1
// order value
CopyText fromText="r" toString="rtf.ov.&V[n]" line=&V[k]
// no decimal places, use Space as group separator
Set V[rtf.ov.&V[n]] _
"&V[rtf.ov.&V[n]]" + 0 decimals=0 groupSeparator=" "
Set V[k] &V[k] + 1
Set V[n] &V[n] + 1
goto next_value
endif
// all GuiXT variables are set, copy template now
CopyText fromTemplate="mytemplate.rtf" toText="temp"
// save to file
// you may work with a temporary filename instead
CopyText fromText="temp" toFile="C:\temp\sales.doc"
// display in MS Word
Start "C:\temp\sales.doc"
Return