1、 SAPScript编程指南方案 97 2020年5月29日 文档仅供参考 1 SAPscript Forms 3 1.1 SAPscript的组成 3 1.2 Forms: 组件和技术 3 1.2.1 概念 3 1.2.1.1修改SAP Forms 3 1.2.1.2 Forms:概念 4 1.2.1.3 Client和语言版本:概念 4 1.2.2 组件 4 1.2.2.1 Header Data 4 1.2.2.2 Paragraph Formats and Attributes 6 1.2.2.3 Character F
2、ormats and Attributes 8 1.2.2.4 Windows 8 1.2.2.5 Pages(页面) 10 1.2.2.6 Pages window(页面窗口) 11 1.2.2.7 Text Elements (文本元素) 12 1.2.3 技术 15 1.2.3.1在Form中包含图形 15 1.2.3.2在FORM中包含公司logo 17 1.2.3.3在form中打印条形码 24 1.2.3.4 Using Boxes, Lines, and Shading 27 2.SAPscript Control Commands 30 2.1 Contr
3、ol Commands语法 30 2.2 Control Commands 种类 30 2.2.1 显示分页:NEW-PAGE 30 2.2.2 限制分页:PROTECT 31 2.2.3 下一个main window命令:NEW-WINDOW 31 2.2.4 给文本symbol分配值:DEFINE 31 2.2.5 格式化日期字段:SET DATE MASK 32 2.2.6 格式化Time字段:SET TIME MASK 33 2.2.7 设置与国家相关的格式:SET COUNTRY 33 2.2.8 设置symbol位:SET SIGN 34 2.2.9 Initi
4、alizing Numbered Paragraphs:RESET 34 2.2.10包含其它文本:INCLUDE 35 2.2.11改变样式:STYLE 35 2.2.12格式化地址:ADDRESS 35 2.2.13在main window中设置Header Text:TOP 37 2.2.14在main window中设置Footer Text:BOTTOM 37 2.2.15条件文本:IF 37 2.2.16条件文本:CASE 38 2.2.17调用ABAP子程序:PERFORM 38 2.2.18合计:SUMMING 40 3.SAPscript Symbols
5、40 3.1Syntax of Symbols 40 3.2System Symbols 41 3.3Program Symbols 42 3.4Standard Symbols 43 3.5Text Symbols 43 4.Formatting Options 43 4.1Offset(偏移量) 43 4.2Output Length 44 4.3 Omitting the Leading Sign 44 4.3 Omitting Leading Zeros 45 4.4 Space Compression 45 4.5 Number of Decimal Plac
6、es 45 4.6 Omitting the Separator for ‘Thousands’ 46 4.7 Specifying an Exponent for Floating Point Numbers 46 4.8 Right-Justified Output 46 4.9 Fill Characters 47 4.10 Suppressing Output of Initial Values 47 4.11Local Dates(Currently Only for Japan) 47 4.12Changing the Value of a Counter 47 4
7、13Preceding and Subsequent Texts(Pre-Text/Post-Text) 48 5.SAPscript Function Modules 49 5.1OPEN_FORM 51 5.2CLOSE_FORM 52 5.3WRITE_FORM 52 6一个完整的例子 53 1 SAPscript Forms 1.1 SAPscript的组成 SAPscript由下面五个部分组成: 1)编辑器用来编辑一行文本。如果用户决定维护与应用程序相关的文本,应用程序事务会自动调用这个文本编辑器, 2)s
8、tyles和forms,用来打印layout。 3)中央输出模块设计器。它的任务是根据相应的格式信息为某种外部设备准备文本,这些格式信息来自于分配了文本的style和forms。 4)程序接口,经过将SAPscript组件包括在程序中来控制form的输出。 5)用来存储文本、styles、forms的数据库表格。 能够用下图来表示: 1.2 Forms: 组件和技术 1.2.1 概念 1.2.1.1修改SAP Forms 如果需要修改SAP Forms,能够象下面这样设置开发环境: l 确信客户端没有标准的SAP Forms l 拷贝你需要的标准SAP Forms到你
9、的开发环境中 l 重新命名,最好以Y或者Z开头 l 为了使更改生效,需要修改相关的SAP 打印程序使用经过你修改后的Forms,能够使用SAP IMG来进行。 1.2.1.2 Forms:概念 Forms用来控制文档中的页面layout和文本格式。在将某一文档输出到打印机或者屏幕的时候,必须将一个Form分配给该文档。如果没有指定,就使用系统默认的Form。 在SAP应用中,一般利用Forms来定制诸如发票、支票之类的特殊文档的layout。这些Forms用来描述文档页面中的信息结构,比如地址抬头、item行、页脚等等。 有两种方法来格式化Forms中的的文本: l 在标准的SA
10、Pscript文本处理器中(Tools ® Word processing ® Standard text),能够为一个文档选择一Form。然后在Form的Main窗口中输入文本并格式化。例如,我们为信件选择一个Form,然后在Main窗口中输入信件内容,当打印该信件时,信件内容随同其它信息一并打印出来(比如抬头、页脚等等)。 l 经过SAP应用中的打印程序生成文档。该打印程序使用一个Form,并提示用户输入相关文本信息。 1.2.1.3 Client和语言版本:概念 Forms和Styles是与客户端相关的,也就是说,在哪一个客户端创立的Form和Styles只能在这个客户端使用。
11、同样的,Forms和Styles也是语言相关的,在Forms和Styles中的定义的文本只能用一种语言来进行定义。能够用SAP翻译工具来翻译这些Forms和Styles Client 000缺省:SAPscript给在client000中的Forms和Styles赋予一种特殊状态。 如果在打印一个文档的时候,文档中定义的Forms和Styles在当前客户端不可用,则SAPscript就在client000中检查所定义的Forms和Styles,如果找到,就利用client000中的来进行打印。SAP标准Forms和Styles总是存储在client000中。能够经过拷贝这些标准Forms和
12、Styles到当前客户端并重新以YXXX或者ZXXX命名加以使用。 Language rules: SAPscript uses the following rules to manage versions of forms and styles in different languages: · The language in which a form or style is created is its "original language." You can translate a form or style into other languages using SAP’s tran
13、slation tools. · If a form or style is needed only in its original language and need not be translated, then you can indicate this in the language attributes in the header data. The form or style then does not appear in work lists in the translation tools. · In versions other than the original l
14、anguage version, changes to a form or style are limited only to translation of texts. No changes to definitions and attributes are permitted. 1.2.2 组件 1.2.2.1 Header Data Header Data由全局数据,比如page格式、page方向、初始字体等组成。在Header Data的Basic settings标签中能够对这些数据进行维护。Header Data还包括form的名字、描述、类以及状态。 Header Da
15、ta的操作画面如下: 一个例子: 下图是简单的发票的例子,是利用SAPscript Form创立的。每一个form由一个start page和任意数量的subsequent pages组成,这依赖于字符文本的长度。在这个例子中,start page由地址栏窗口、包含参考消息的信息窗口、包含公司相关数据的窗口以及包含真正业务数据的窗口(业务数据也显示在subsequent page中)和包含页码的窗口组成。 包含业务数据的窗口不同于其它窗口。无论什么时候,只要一页数据显示不下时,会自动显示在subsequent中。因而,这个窗口控制换页,而且这种窗口只能有一个,在SAPscript
16、 form中称这种窗口为main window. 如下图所示: 1.2.2.2 Paragraph Formats and Attributes 在SAPscript中,Paragraph(段落)就是使用某种格式和相应属性的一种格式设置。经过应用不同的段落属性组来简化文本处理,这些属性组包括: l 标准属性 l 字体 l Tabs l Outline 对一个段落标志命名有下面的约定束成: l 段落名由一到两个字符组成; l 第一个字符必须是字母,第二个字符能够是字母、数字或者空格;特殊字符无效; l 段落格式在Description域中必须进行标识。 段
17、落格式设置画面如下: 下面分别对前面的属性组加以说明: 1) 标准属性 在标准属性组中,能够设置在段落格式中需要用到的通用属性,包括: 描述信息(Description) 左边右边距(Left margin, Right margin) 第一行的缩进(indent 1st line) 前后空格(Space before, Space after) 对齐方式(Alignment) 行间距(Line spacing) 是否空行(No blank lines) 是否页面保护(Page protection) 同一页上是否有下一个段落(Next para
18、graph same page) 2) Font 属性 能够为段落格式指定字体属性,用来控制文本中的字体。字体属性包括字体、大小、黑体/粗体/斜体、下划线等等。、 3) Tabs in Paragraph Formats 能够根据需要为每个段落格式定义tabs的位置,在pc editor中两个”,,”symbol代表段落中的一个tabs。能够使用下面的度量单位来定义tabs的位置: CH (字符) CM (厘米) MM(毫米) PT(点阵) TW(1/20 点) 4) Outline 用来指定文档中的层次和目录结构。具体请参见sap online help 1.2.2.
19、3 Character Formats and Attributes Character formats and Attributes能够用来格式段落中的一段文字。命名方式与段落一样。字符属性组能够是: l Standard l Font Standard 属性包括marker(标记或者超连接)、Barcode、Protected、Hidden、Superscript等。 Font属性与段落中的Font属性一样使用。 1.2.2.4 Windows Windows在Form维护中定义。代表页面中的一个区域(Page Window),每一个Form中至少定一个window,否则,S
20、APscript不能格式化文本。 能够为window定义类型和名字,注意在每一个Form中只能有一个Main window。 在定义一个Form Window的时候,必须选择一个窗口类型。 下面是能够使用的窗口类型: l Main Window 每一个Form必须有一个MAIN类型的窗口,这样的窗口叫做Main Window。在SAPscript中主窗口具有下面的意义: 1) 控制换页; 2) 包含能够跨越多个pages的内容; 3) 能够在page window中固定文本元素,比如列标题。 一旦main window内容填满后,就会自动换页,在下一页的main window
21、中继续输出余下的内容。而且格式保持不变。 注意:如果page中没有main window,系统会隐含处理page中的其它window以及subsequent page,在这种情况下,SAPscript会在处理完(最多)三个subsequent pages后终止处理。 为了输出header line或者totals,需要指定main window中的输出区域(output area)。 为了在页面(page)中的main window中进行文本输出,能够选择三种类型的区域之一。Main window中的顶层区域叫TOP Area;下层区域叫BOTTOM Area;它们之间的区域叫做BO
22、DY Area。TOP Area和BOTTOM Area的大小依赖于各自的文本内容,BODY Area的大小相应的发生变化。 如下图所示: 在Form输出时,能够对这三个区域的内容进行动态修改。SAPscript在包含main windwo的Form的每一页上自动输出这些区域。当在调用函数模块WRITE_FORM或者WRITE_FORM_LINES时,TYPE参数决定在哪一个区域输出文本,如果在调用时,没有指定TYPE参数,系统默认输出BODY区域的内容。 比如下面的图示以及代码: l VAR Window(可变窗口) 可变窗口的内容在每一个page中都要处理一次
23、系统输出仅仅适合窗口尺寸,超出窗口的文本被自动截掉;可变窗口也不会触发换页处理。不象CONST Window,page window如果声明为VAR Window,意味着在不同的Form pages中能够有不同的尺寸。 注意:在窗口内容处理方面,系统并不区分CONST Window和VAR Window,唯一的区别就是在全部Form中具有同样尺寸。 l CONST window(常量窗口) 从版本4.0开始,在系统内部处理中,并不区分CONST Window和VAR Window,因此,如果创立一个新的window,总是使用VAR类型的。 1.2.2.5 Pages(页面) 对每一
24、个Form必须定义至少一个page,而且必须在Form的header属性标签中指定”first” page。否则,不能进行文本格式化。另外,应该指定当到达第一页的末尾的时候,接下来的一页是哪页。如果没有指定的话,输出就在当前页的末尾终止。 为了定义一个page,需要为它指定名字和属性: l 下一页的名字 l page的计数模式 l page数的数字类型 l 资源名字 l 打印模式 文档的单个pages一般有不同的layouts:发票的第一页与接下来的页不一样,在这些页上不需要重复通用信息,比如地址或者客户数据,象窗口中的文本元素一样,page也有名字,在有需要换页的情况下,需要经
25、过这些名字来指定下一页,如果想文档的样式变化越多,就需要在SAPscript中定义越多的page。 下图说明如何利用事务代码SE71维护一个page。在WIN32操作系统中能够利用Form Painter。 1.2.2.6 Pages window(页面窗口) Pages window就是定义在页面中的窗口,这里的页面和窗口都是已经预先定义好的,定义pages window的主要任务就是将窗口和页面关联起来,一个页面中能够有多个窗口。 在定义pages windows时,窗口的名字与page的名字关联起来。必须指定分配给page的窗口的位置和大小。 经过指定左边和上边距来
26、定义窗口的位置,指定其高度和宽度来定义窗口的大小。 注意: 1)在所有pages中的main window的宽度必须相同。其它的窗口类型在不同的pages中能够有不同的尺寸和位置。 2)为了打印多列,需要在一个page中定义多个main window。因为文本条目是连续的,一旦第一个main window被写满之后,输出能够在第二个窗口继续。 当定义windows和pages的时候,能够不必指定位置和输出的文本间隔。为了指定这些值,能够直接创立一个page window。 l 当定义page window时,需要指定: l 显示在page上的window l window的尺
27、寸(包括大小、宽度、高度) l 页面中各个window的位置 如下图所示: 1.2.2.7 Text Elements (文本元素) SAPscript将form中的单个文本组件称之为Text Elements(文本元素),为了获得较好的结构和可读性,能够为form中的每一个Text Elements分配一个固定的名字,打印程序经过这些定义的名字来访问Text Elements。 Text Elements与window相关,就是说,打印程序仅仅能够调用定义在窗口中的文本元素。下图显示了定义在main window中的HEADING和FLIGHTIST两个Text Element
28、s。 能够将这里定义的Text Elements和ABAP程序中(比如TEXT-001)定义的文本相比较来学习,可是,Text Elements比ABAP程序中(比如TEXT-001)定义的文本更灵活,主要表现在: l Text Elements的长度没有限制; l Text Elements能够包含变量符; l 在一个Text Elements中能够使用几个不同的格式选项; l 在Text Elements中能够使用SAPscript控制语句。 在window中,能够使用两种不同的Text Elements,一种叫做有名Text Elements;另外一种叫做无名Text E
29、lements。
1) 有名Text Elements
经过段落格式”/E”来识别有名Text Elements,在行编辑器中,看起来象这样:
字符串
30、使用函数模块WRITE_FORM。 下图说明了发票中的列头Text Elements。 2) 无名Text Elements 无名Text Elements或者叫做缺省文本元素是这样的一些文本行和控制语句,它们显示在相应window contents的起始处,没有”/E”段落格式。包括所有的行直到出现”/E” 段落格式,或者直到末尾,如果中间没有其它”/E”标志出现,因此,在一个window中只能包括一个无名Text Elements。 这两种Text Elements之间的区别在于: l 对于有Text Elements来说,只有当系统显示调用函数模块WRITE_FORM时,才
31、被输出;而对名Text Elements,系统会自动处理。 l Main window 中的Text Elements仅仅出现一次,它不会出现在包含main window的form的subsequent page中。 l 其它window类型(除main window外)的无名Text Elements每次都会出现。 下面的例说明了在form中的ADDRESS window的无名Text Elements,这个Text Elements输出客户地址,ADRS_SENDER标准文本仅仅在第一页显示(经过IF AND CASE语句能够控制)。 3) 激活Text Elements 当
32、函数模块WRITE_FORM的时候,能够经过设置FUNCTION参数的值在打印程序中激活窗口中的Text Elements,FUNCTION能够是下面的值: l SET 用当前的值代替所有window中激活的文本元素 l APPEND 将当前的Text Elements追加到激活的Text Elements l DELETE 从激活的Text Elements列表中删除当前的Text Elements 注:激活Text Elements是指当当前page调用时,系统准备输出的window Text Elements。 在main window BODY域中,APPEND和S
33、ET具有相同的效果,DELETE对其没有影响,在TOP和BOTTOM域中,与上面描述的相同。 1.2.3 技术 1.2.3.1在Form中包含图形 这一节主要介绍在form中包括图形的技术,主要介绍如何在form中打印公司logo和如何打印条形码。 1) 在form中打印公司logo 为了能够打印公司logo,不论是在form中,还是在PCL-5打印机预定的宏中,下面的规则有助于选择合适的方法: l 如果不能够以TIF6.0的格式提供logo,则公司logo应该在PCL-5打印机预定的宏中进行打印; l 如果没有PCL-5打印机,则需要将公司logo包含在form中; l 在其
34、它任何情况下,将公司logo包含在form中。 如果在打印公司logo的时候,正确的参照了这里的说明,但还是没有能够正确打印出公司的logo,可能是因为你提供的logo的图形格式不是基于TIF6.0的,如果文件格式不正确,SAP并不给出任何错误信息。 下面介绍在form中包含公司logo的步骤: 1.2.3.2在FORM中包含公司logo Step-by-Step Guide Task 1 Convert your company logo into a SAPscript standard text. 1. Create your company logo
35、with a graphic program and save it in the Baseline TIFF 6.0 format. In this guide, the filename is LOGO.TIF. 2. From the SAP main menu, choose Tools ® ABAP Workbench. 3 3. On the ABAP Workbench screen, choose ABAP Editor. 5 4 4. In the Program field, enter RSTXLDMC. 5. Choose Execute.
36、 7 8 9 10 6. Determine the location of LOGO.TIF. 7. In the File name field, enter the file name with its location. Note: UNIX file names are case sensitive. 8. In the Type field, enter the appropriate type for the raster image. § BMON stands for a black and white raster image. Use BMON
37、for monochrome printers because these printers normally do not perform a gray-level conversion. § BCOL stands for a color raster image with up to 256 colors. For this example, use BMON. 9. In the Text name field, enter ZHEX-MACRO-LOGO. 10. Choose Execute. 11 12 The upload may take a while.
38、The result should be a protocol as shown. 11. At the end of the protocol, a Standard text ZHEX-MACRO-LOGO ID ST Language EN saved successfully message indicates that the standard text was created. 12. Choose Back four times to return to the SAP main menu. You can easily display the created
39、standard text. 1. Choose Tools ® Word processing ® Standard text. 2. In the Text name field, enter ZHEX-MACRO-LOGO. 3. Choose Display. For additional information about report RSTXLDMC, access the report documentation: 1. Choose Tools ® ABAP Workbench. 2. Choose ABAP Editor. 3. In the Prog
40、ram field, enter RSTXLDMC. 4. Select Documentation. 5. Choose Display. Step-by-Step Guide Task 2 Include the standard text ZHEX-MACRO_LOGO in the sales order confirmation form Z_9H_RVORDER01. 1. From the SAP main menu, choose Tools ® Word processing ® Form. 3 2 4 2. In the Form f
41、ield, enter Z_9H_RVORDER01, and in the Language field, enter EN. 3. In the Sub-objects section, select Page layout. 4. Choose Change. The synchronized screens of the Form Painter appear. 5. In the Design window5 , create a new window by choosing Create window form the form layout manipulatio
42、n menu. The new window is automatically named Window1. 6 6. Activate Window1 and choose Rename window from the form layout manipulation menu. 8 7 7. Rename Window1 as LOGO. 8. Choose Execute. 9 9. Define the position of the window LOGO using the graphical Form Painter. With graph
43、ics or macros the system considers only the window position but not the size. The Left margin must be specified in CH (characters) and the Upper margin must be specified in LN (line). 10 10. Activate the LOGO window and choose Edit window text from the form layout manipulation window. The P
44、C Editor for the LOGO window appears. 11 11. In the PC Editor choose the Insert command button. The Insert Additional Information screen appears. 14 13 12 12. Select Command. 13. Enter INCLUDE ZHEX-MACRO-LOGO OBJECT TEXT ID ST in the command line. 14. Choose Continue. 15 The new com
45、mand line (gray highlighted) appears in the PC Editor. 15. Choose Back. The window text is automatically saved by the system. 16. Confirm the information. 17 17. Activate the changed form. Your company logo appears on the first page of form Z_9H_RVORDER01 using the standard text Z
46、HEX-MACRO-LOGO and the window LOGO for the print output. If the company logo should be displayed on the subsequent pages, you must copy the window LOGO to page NEXT. You have to repeat the following procedure for all defined pages: 1. In the administrative screen, choose the window LOGO. 2. Co
47、py the window. 3. Choose page NEXT. 4. Insert the window. The position and size of the window LOGO defined for page FIRST apply to the other pages. 5. Activate the form. 注:关于如何在PCL-5打印机中打印公司logo,请参见相关资料,这里从略。 1.2.3.3在form中打印条形码 Step-by-Step Guide Task Define the material numbers on the s
48、ales order confirmation Z_9H_RVORDER01 as a ”3 of 9” bar code with a check digit. 1. From the SAP main menu, choose Tools ® Word processing® Form. 2 3 4 2. In the Form field, enter Z_9H_RVORDER01, and in the Language field, enter EN. 3. Select Character formats. 4. Choose Change. 9 1
49、0 5 6 7 8 5. In the String field, enter B3. 6. In the Description field, enter Bar code 3 of 9 w/check. 7. Choose Enter. The new character format appears in the character formats frame. 8. In the Bar code field, press the F4 help key and choose the appropriate bar code from the list of avai
50、lable bar codes. Choose BC_CD39C. 9. Save the new character format. The bar code is now defined and can be used. Next, we have to adjust the output of the Main window. 10. Choose Layout. 11 11. In the Design Window activate the Main window and choose Edit window text. 13 12 12. In the






