ABAP新手资料-[SAP Script 编程指南-DOC].docx

上传人:小飞机 文档编号:1662026 上传时间:2022-12-13 格式:DOCX 页数:56 大小:766.27KB
返回 下载 相关 举报
ABAP新手资料-[SAP Script 编程指南-DOC].docx_第1页
第1页 / 共56页
ABAP新手资料-[SAP Script 编程指南-DOC].docx_第2页
第2页 / 共56页
ABAP新手资料-[SAP Script 编程指南-DOC].docx_第3页
第3页 / 共56页
ABAP新手资料-[SAP Script 编程指南-DOC].docx_第4页
第4页 / 共56页
ABAP新手资料-[SAP Script 编程指南-DOC].docx_第5页
第5页 / 共56页
点击查看更多>>
资源描述

《ABAP新手资料-[SAP Script 编程指南-DOC].docx》由会员分享,可在线阅读,更多相关《ABAP新手资料-[SAP Script 编程指南-DOC].docx(56页珍藏版)》请在三一办公上搜索。

1、SAP Script 编程指南1 SAPscript Forms31.1 SAPscript的组成31.2 Forms: 组件和技术31.2.1 概念31.2.1.1修改SAP Forms31.2.1.2 Forms:概念41.2.1.3 Client和语言版本:概念41.2.2 组件41.2.2.1 Header Data41.2.2.2 Paragraph Formats and Attributes61.2.2.3 Character Formats and Attributes81.2.2.4 Windows81.2.2.5 Pages(页面)101.2.2.6 Pages windo

2、w(页面窗口)111.2.2.7 Text Elements (文本元素)121.2.3 技术151.2.3.1在Form中包含图形151.2.3.2在FORM中包含公司logo171.2.3.3在form中打印条形码241.2.3.4 Using Boxes, Lines, and Shading272.SAPscript Control Commands302.1 Control Commands语法302.2 Control Commands 种类302.2.1 显示分页:NEW-PAGE302.2.2 限制分页:PROTECT312.2.3 下一个main window命令:NEW-W

3、INDOW312.2.4 给文本symbol分配值:DEFINE312.2.5 格式化日期字段:SET DATE MASK322.2.6 格式化Time字段:SET TIME MASK332.2.7 设置与国家相关的格式:SET COUNTRY332.2.8 设置symbol位:SET SIGN342.2.9 Initializing Numbered Paragraphs:RESET342.2.10包含其他文本:INCLUDE352.2.11改变样式:STYLE352.2.12格式化地址:ADDRESS352.2.13在main window中设置Header Text:TOP372.2.1

4、4在main window中设置Footer Text:BOTTOM372.2.15条件文本:IF372.2.16条件文本:CASE382.2.17调用ABAP子程序:PERFORM382.2.18合计:SUMMING403.SAPscript Symbols403.1Syntax of Symbols403.2System Symbols413.3Program Symbols423.4Standard Symbols433.5Text Symbols434.Formatting Options434.1Offset(偏移量)434.2Output Length444.3 Omitting

5、the Leading Sign444.3 Omitting Leading Zeros454.4 Space Compression454.5 Number of Decimal Places454.6 Omitting the Separator for Thousands464.7 Specifying an Exponent for Floating Point Numbers464.8 Right-Justified Output464.9 Fill Characters474.10 Suppressing Output of Initial Values474.11Local Da

6、tes(Currently Only for Japan)474.12Changing the Value of a Counter474.13Preceding and Subsequent Texts(Pre-Text/Post-Text)485.SAPscript Function Modules495.1OPEN_FORM515.2CLOSE_FORM525.3WRITE_FORM526一个完整的例子531 SAPscript Forms1.1 SAPscript的组成SAPscript由下面五个部分组成:1)编辑器用来编辑一行文本。如果用户决定维护与应用程序相关的文本,应用程序事务会

7、自动调用这个文本编辑器,2)styles和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 Formsl 拷贝你需要的标准SAP Forms到你的开发环境中l

8、重新命名,最好以Y或者Z开头l 为了使更改生效,需要修改相关的SAP 打印程序使用经过你修改后的Forms,可以使用SAP IMG来进行。1.2.1.2 Forms:概念Forms用来控制文档中的页面layout和文本格式。在将某一文档输出到打印机或者屏幕的时候,必须将一个Form分配给该文档。如果没有指定,就使用系统默认的Form。在SAP应用中,通常利用Forms来定制诸如发票、支票之类的特殊文档的layout。这些Forms用来描述文档页面中的信息结构,比如地址抬头、item行、页脚等等。有两种方法来格式化Forms中的的文本:l 在标准的SAPscript文本处理器中(Tools Wo

9、rd processing Standard text),可以为一个文档选择一Form。然后在Form的Main窗口中输入文本并格式化。例如,我们为信件选择一个Form,然后在Main窗口中输入信件内容,当打印该信件时,信件内容随同其他信息一并打印出来(比如抬头、页脚等等)。l 通过SAP应用中的打印程序生成文档。该打印程序使用一个Form,并提示用户输入相关文本信息。1.2.1.3 Client和语言版本:概念Forms和Styles是与客户端相关的,也就是说,在哪一个客户端创建的Form和Styles只能在这个客户端使用。同样的,Forms和Styles也是语言相关的,在Forms和Sty

10、les中的定义的文本只能用一种语言来进行定义。可以用SAP翻译工具来翻译这些Forms和StylesClient 000缺省:SAPscript给在client000中的Forms和Styles赋予一种特殊状态。如果在打印一个文档的时候,文档中定义的Forms和Styles在当前客户端不可用,则SAPscript就在client000中检查所定义的Forms和Styles,如果找到,就利用client000中的来进行打印。SAP标准Forms和Styles总是存储在client000中。可以通过拷贝这些标准Forms和Styles到当前客户端并重新以YXXX或者ZXXX命名加以使用。Langu

11、age 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 SAPs translation tools. If a form or style is needed on

12、ly 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 language version, changes to a form or style are limite

13、d only to translation of texts. No changes to definitions and attributes are permitted. 1.2.2 组件1.2.2.1 Header DataHeader Data由全局数据,比如page格式、page方向、初始字体等组成。在Header Data的Basic settings标签中可以对这些数据进行维护。Header Data还包括form的名字、描述、类以及状态。Header Data的操作画面如下:一个例子:下图是简单的发票的例子,是利用SAPscript Form创建的。每一个form由一个star

14、t page和任意数量的subsequent pages组成,这依赖于字符文本的长度。在这个例子中,start page由地址栏窗口、包含参考消息的信息窗口、包含公司相关数据的窗口以及包含真正业务数据的窗口(业务数据也显示在subsequent page中)和包含页码的窗口组成。 包含业务数据的窗口不同于其他窗口。无论什么时候,只要一页数据显示不下时,会自动显示在subsequent中。因而,这个窗口控制换页,而且这种窗口只能有一个,在SAPscript form中称这种窗口为main window.如下图所示:1.2.2.2 Paragraph Formats and Attributes在

15、SAPscript中,Paragraph(段落)就是使用某种格式和相应属性的一种格式设置。通过应用不同的段落属性组来简化文本处理,这些属性组包括:l 标准属性l 字体l Tabsl Outline对一个段落标志命名有下面的约定束成:l 段落名由一到两个字符组成;l 第一个字符必须是字母,第二个字符可以是字母、数字或者空格;特殊字符无效;l 段落格式在Description域中必须进行标识。段落格式设置画面如下:下面分别对前面的属性组加以说明:1) 标准属性在标准属性组中,可以设置在段落格式中需要用到的通用属性,包括:描述信息(Description)左边右边距(Left margin, Rig

16、ht margin)第一行的缩进(indent 1st line)前后空格(Space before, Space after)对齐方式(Alignment)行间距(Line spacing)是否空行(No blank lines)是否页面保护(Page protection)同一页上是否有下一个段落(Next paragraph same page)2) Font 属性可以为段落格式指定字体属性,用来控制文本中的字体。字体属性包括字体、大小、黑体/粗体/斜体、下划线等等。、3) Tabs in Paragraph Formats可以根据需要为每个段落格式定义tabs的位置,在pc edito

17、r中两个”,”symbol代表段落中的一个tabs。可以使用下面的度量单位来定义tabs的位置:CH (字符)CM (厘米)MM(毫米)PT(点阵)TW(1/20 点)4) Outline用来指定文档中的层次和目录结构。具体请参见sap online help1.2.2.3 Character Formats and AttributesCharacter formats and Attributes可以用来格式段落中的一段文字。命名方式与段落一样。字符属性组可以是:l Standardl FontStandard 属性包括marker(标记或者超连接)、Barcode、Protected、H

18、idden、Superscript等。Font属性与段落中的Font属性一样使用。1.2.2.4 WindowsWindows在Form维护中定义。代表页面中的一个区域(Page Window),每一个Form中至少定一个window,否则,SAPscript不能格式化文本。可以为window定义类型和名字,注意在每一个Form中只能有一个Main window。在定义一个Form Window的时候,必须选择一个窗口类型。下面是可以使用的窗口类型:l Main Window每一个Form必须有一个MAIN类型的窗口,这样的窗口叫做Main Window。在SAPscript中主窗口具有下面的

19、意义:1) 控制换页;2) 包含可以跨越多个pages的内容;3) 可以在page window中固定文本元素,比如列标题。一旦main window内容填满后,就会自动换页,在下一页的main window中继续输出余下的内容。而且格式保持不变。注意:如果page中没有main window,系统会隐含处理page中的其他window以及subsequent page,在这种情况下,SAPscript会在处理完(最多)三个subsequent pages后终止处理。为了输出header line或者totals,需要指定main window中的输出区域(output area)。为了在页面

20、(page)中的main window中进行文本输出,可以选择三种类型的区域之一。Main window中的顶层区域叫TOP Area;下层区域叫BOTTOM Area;它们之间的区域叫做BODY Area。TOP Area和BOTTOM Area的大小依赖于各自的文本内容,BODY Area的大小相应的发生变化。如下图所示: 在Form输出时,可以对这三个区域的内容进行动态修改。SAPscript在包含main windwo的Form的每一页上自动输出这些区域。当在调用函数模块WRITE_FORM或者WRITE_FORM_LINES时,TYPE参数决定在哪一个区域输出文本,如果在调用时,没有

21、指定TYPE参数,系统默认输出BODY区域的内容。 比如下面的图示以及代码:l VAR Window(可变窗口)可变窗口的内容在每一个page中都要处理一次。系统输出仅仅适合窗口尺寸,超出窗口的文本被自动截掉;可变窗口也不会触发换页处理。不象CONST Window,page window如果声明为VAR Window,意味着在不同的Form pages中可以有不同的尺寸。注意:在窗口内容处理方面,系统并不区分CONST Window和VAR Window,唯一的区别就是在全部Form中具有同样尺寸。l CONST window(常量窗口)从版本4.0开始,在系统内部处理中,并不区分CONST

22、 Window和VAR Window,所以,如果创建一个新的window,总是使用VAR类型的。1.2.2.5 Pages(页面)对每一个Form必须定义至少一个page,而且必须在Form的header属性标签中指定“first” page。否则,不能进行文本格式化。另外,应该指定当到达第一页的末尾的时候,接下来的一页是哪页。如果没有指定的话,输出就在当前页的末尾终止。为了定义一个page,需要为它指定名字和属性:l 下一页的名字l page的计数模式l page数的数字类型l 资源名字l 打印模式文档的单个pages通常有不同的layouts:发票的第一页与接下来的页不一样,在这些页上不需

23、要重复通用信息,比如地址或者客户数据,象窗口中的文本元素一样,page也有名字,在有需要换页的情况下,需要通过这些名字来指定下一页,如果想文档的样式变化越多,就需要在SAPscript中定义越多的page。下图说明如何利用事务代码SE71维护一个page。在WIN32操作系统中可以利用Form Painter。1.2.2.6 Pages window(页面窗口)Pages window就是定义在页面中的窗口,这里的页面和窗口都是已经预先定义好的,定义pages window的主要任务就是将窗口和页面关联起来,一个页面中可以有多个窗口。 在定义pages windows时,窗口的名字与page的

24、名字关联起来。必须指定分配给page的窗口的位置和大小。 通过指定左边和上边距来定义窗口的位置,指定其高度和宽度来定义窗口的大小。 注意:1)在所有pages中的main window的宽度必须相同。其他的窗口类型在不同的pages中可以有不同的尺寸和位置。2)为了打印多列,需要在一个page中定义多个main window。因为文本条目是连续的,一旦第一个main window被写满之后,输出可以在第二个窗口继续。当定义windows和pages的时候,可以不必指定位置和输出的文本间隔。为了指定这些值,可以直接创建一个page window。l 当定义page window时,需要指定:l

25、显示在page上的windowl window的尺寸(包括大小、宽度、高度)l 页面中各个window的位置如下图所示:1.2.2.7 Text Elements (文本元素)SAPscript将form中的单个文本组件称之为Text Elements(文本元素),为了获得较好的结构和可读性,可以为form中的每一个Text Elements分配一个固定的名字,打印程序通过这些定义的名字来访问Text Elements。Text Elements与window相关,就是说,打印程序仅仅能够调用定义在窗口中的文本元素。下图显示了定义在main window中的HEADING和FLIGHTIST两

26、个Text Elements。可以将这里定义的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 El

27、ements。1) 有名Text Elements通过段落格式“/E”来识别有名Text Elements,在行编辑器中,看起来象这样:字符串代表Text Elements的名字,名字可以有30个长度,而且可以包含字母、数字、特殊字符。名字后面接下来就是这个Text Elements的文本行。一个Text Elements在下一个Text Elements开始处结束。注意:Text Elements的名字仅仅在本地有效(LOCAL),即不同的窗口可以包含相同的Text Elements的名字。为了输出有名Text Elements,必须在程序中(ABAP)使用函数模块WRITE_FORM。下图

28、说明了发票中的列头Text Elements。2) 无名Text Elements无名Text Elements或者叫做缺省文本元素是这样的一些文本行和控制语句,它们显示在相应window contents的起始处,没有“/E”段落格式。包括所有的行直到出现“/E” 段落格式,或者直到末尾,如果中间没有其他“/E”标志出现,因此,在一个window中只能包括一个无名Text Elements。这两种Text Elements之间的区别在于:l 对于有Text Elements来说,只有当系统显示调用函数模块WRITE_FORM时,才被输出;而对名Text Elements,系统会自动处理。l

29、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当函数模块WRITE_FORM的时候,可以通过设置FUNCTION参数的值在打印程序中激

30、活窗口中的Text Elements,FUNCTION可以是下面的值:l SET用当前的值代替所有window中激活的文本元素l APPEND将当前的Text Elements追加到激活的Text Elementsl DELETE 从激活的Text Elements列表中删除当前的Text Elements注:激活Text Elements是指当当前page调用时,系统准备输出的window Text Elements。在main window BODY域中,APPEND和SET具有相同的效果,DELETE对其没有影响,在TOP和BOTTOM域中,与上面描述的相同。1.2.3 技术1.2.3.

31、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 在其他任何情况下,将公司logo包含在form中。如果在打印公司logo的时候,正确的参照了这里的说明,但还是没有能够正确打印出公司的logo,可能是因为你

32、提供的logo的图形格式不是基于TIF6.0的,如果文件格式不正确,SAP并不给出任何错误信息。下面介绍在form中包含公司logo的步骤:1.2.3.2在FORM中包含公司logoStep-by-Step GuideTask 1Convert your company logo into a SAPscript standard text. 1. Create your company logo with a graphic program and save it in the Baseline TIFF 6.0 format.In this guide, the filename is L

33、OGO.TIF.2. From the SAP main menu, choose Tools ABAP Workbench.33. On the ABAP Workbench screen, choose ABAP Editor.544. In the Program field, enter RSTXLDMC.5. Choose Execute. 789106. Determine the location of LOGO.TIF.7. In the File name field, enter the file name with its location.Note: UNIX file

34、 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 for monochrome printers because these printers normally do not perform a gray-level conversion. BCOL stands for a color raster image with up to 25

35、6 colors.For this example, use BMON.9. In the Text name field, enter ZHEX-MACRO-LOGO.10. Choose Execute.1112The upload may take a while. 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 tha

36、t the standard text was created.12. Choose Back four times to return to the SAP main menu.You can easily display the created 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

37、, access the report documentation:1. Choose Tools ABAP Workbench.2. Choose ABAP Editor.3. In the Program field, enter RSTXLDMC.4. Select Documentation.5. Choose Display.Step-by-Step GuideTask 2Include the standard text ZHEX-MACRO_LOGO in the sales order confirmation form Z_9H_RVORDER01. 1. From the

38、SAP main menu, choose Tools Word processing Form.3242. In the Form field, 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

39、 choosing Create window form the form layout manipulation menu.The new window is automatically named Window1.66. Activate Window1 and choose Rename window from the form layout manipulation menu.877. Rename Window1 as LOGO.8. Choose Execute.99. Define the position of the window LOGO using the graphic

40、al Form Painter.With graphics 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). 1010. Activate the LOGO window and choose Edit window text from the form layout manipulati

41、on window. The PC Editor for the LOGO window appears.1111. In the PC Editor choose the Insert command button.The Insert Additional Information screen appears.14131212. Select Command.13. Enter INCLUDE ZHEX-MACRO-LOGO OBJECT TEXT ID ST in the command line.14. Choose Continue.15The new command line (g

42、ray highlighted) appears in the PC Editor.15. Choose Back.The window text is automatically saved by the system. 16. Confirm the information.1717. Activate the changed form.Your company logo appears on the first page of form Z_9H_RVORDER01 using the standard text ZHEX-MACRO-LOGO and the window LOGO f

43、or 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. Copy the window.3. Choose page NEXT.4. Insert

44、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 GuideTaskDefine the material numbers on the sales order confirmation Z_9H_RVORDER01 as a “3 of 9” bar code wit

45、h a check digit. 1. From the SAP main menu, choose Tools Word processing Form.2342. In the Form field, enter Z_9H_RVORDER01, and in the Language field, enter EN.3. Select Character formats.4. Choose Change.91056785. In the String field, enter B3.6. In the Description field, enter Bar code 3 of 9 w/c

46、heck.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 available 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.1111. In the Design Window activate the Main window and choose Edit window text.131212. In the text editor, scroll down until you see /E I

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号