




已阅读5页,还剩59页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1. abap/4 introduction &introduction abap/4(advanced business application programming)是sap/r3目前唯一的系统发展工具, 属 4gl, 语法比较近似visual basic或java, 和传统third-generation 语言, 如c,pascal 有很大不同, 在程序模块(program structure module)可分以 下三个部分:1.sequential coding within processing block 与一般语言语法近似, 如if,while等, 但并没有goto叙述2.reports 呼叫一个独立的事件(depending event), 读取database 产生数据列表3.dialog 屏幕参数输入的对话框, 专门处理database 读取或异动的tranaction process &basic languange overview 1.data element 宣告方式, 如数值, 字符数据变量宣告 2.操作数(operate)使用, 如 + - * / 3.control element使用, 如boolean 值 4.特殊数据格式, 如日期与时间 5.字符串字料处理function, 如部分字符串的截取 6.子程序或自定函数的呼叫 7.sql语法使用 8.数据结构的使用, 如process internal table的宣告与使用&reports overview 1.reports task, 如报表屏幕预览或打印机打印的选择 2.reports 模块是一个stand-along 程序, 3.database读取方式, 如可定义logical database(与磁盘的physical storage对映) 4.报表数据的计算与产生 5.报表的输出&dialog overview 1.专处理database 的读取与异动, 如使用sql 指令2.dialog 不是一个stand-along progarm, 使用transaction code来产生屏幕对话框3.由flow logic 控制, flow logic分成pbo(process before output)与pai(process after input)2.begin to programming2.1 abap/4 editor&creating abap/4 program 使用abap workbench撰写程序(choose tools-abap/4 workbench, transaction code: s001), 萤 幕如下: 可分成:1.abap/4 editor :针对简单的报表或程序, 仅使用几个组件或不使用2.obiect browser :针对复杂的报表或程序, 如dialog transaction module 撰写&使用abap/4 editor 撰写程序 1.abap/4 editor 画面如下(transaction code:se38): 2.输入程序名称, 如果是新程序, 按下”create”, 如果修改已存在程序, 则按下”change”或f6键 在命名规则上, reports程序为 yaxxxxxx或zaxxxxxx, a表application module简称, 如s表sd dialog程序为sapmyxxx或sapmzxxx 3.输入程序attribute (1).title:程序描述或功能说明 (2).type:execute mode: 1: stand-along program 如reports i: include program m: module pool f: function group s: subroutine pool(3).status:program development status: p: sap standard production program k: customer production program s: system program t: test program(4).application: 程序所属的application module, 如f表 financeial acounting(5).development class: 用于同一系统中各个program, 如果不属任一class, 可使用$tmp 4.撰写source code program 之后接的是程序名称, write 是显示的意思, 会将所接的字符串在屏幕上显示, 注意每一行最后要有一个 . (点), 表示叙述的结束, 储存后回abap/4 editor画面 5. 执行程序 按”execute”或f8键, 屏幕可见执行所得的结果 &重要的编辑键 key function f8f5f11ctrl+f11执行程序复制游标所在列的内容储存档案删除游标所在列2.2 abap/4 data element&data type abap/4 的数据型态可分成: type length range initial value descriptionc 1 1-65535byte space 字符串数据, 如program d 8 8byte 00000000 日期数据, 格式为yyyymmddf 8 8byte 0 浮点数 i 4 -231至231-1 0 整数n 1 1-65535byte 000 数值所组成的字符串 p 8 1-16byte 0 packed 数, 用在小数点数 t 6 6byte 000000 时间数据, 格式为hhmmssx 1 1-65535byte x00 16进位数&变量宣告 变量宣告包含 name, type, length 和 structure四个部分, 使用 data 指令, 如 data: s1 type i, sum type i.&常数宣告 常数宣告使用 constants 指令, 如宣告 pi 是一个小数点5位的值 3.14159, constants pi type p decimals 5 value 3.14159. &系统所定义数据 这是由系统所定义的专有名辞, 如 space 空白字符串 sy-subrc 系统执行传回值, 0 表示成功 sy-uname logon 账号 sy-datum 系统日期 sy-uzeit 系统时间 sy-tcode 目前的transaction code&type 叙述 用来指定数据型态或宣告自定数据型态 example: types: begin of mylist, name(10) type c, number type i, end of mylist. data list type mylist.&like 叙述 跟type叙述使用格式相同, 如 data transcode like sy-tcode. 不同的是 like 用在已有值的数据项, 如系统变量, 而type叙述则是用 在指定数据型态。&data 叙述 语法: data : 变量名称, 最长30个字符, 不可含有 + . , : ( ) 等字符 : 数据型态及长度, 如 line(20) type c. myname like sy-uname. : 初值 : 小数位数 example: data: counter type p value 1, flag type c value is initial, weight type p decimals 2 value 1.25.字段变量的宣告: data: begin of address, name(10) type c , number type p, end of address.使用时用字段变量加上组件名称, 如 address-name&constants 叙述 用来宣告常数 语法: constants example: constants: cname(10) value 周庆日, birth_day type d value 19650201.&statics 叙述 宣告的变量仅在目前的程序中使用, 结束后会自动释放 语法: statics &tables 叙述 用来宣告 table work area 的数据, 对映至 abap/4 资料文件(dictionary object), 由sql 指令加载所需数据 语法: tables example: tables: spfl. select * from spfl. write: spfl-mandt, spfl-carrid,spfl-connection. endselect. 从abap/4 dictionary 的 spfl 档载入mandt,carrid,connection三个字段至 spfl 此table work area 2.3 outputting data to screen &write 叙述 abap/4 用来在屏幕上输出数据的指令是 write 指令 语法: write 资料项 数据项可以是常数或变量, 如: write this is sample. write: company:,stfl-carrid.&指定屏幕位置显示 语法: write at / () 资料项 / : 先往下一列 pos : 屏幕x轴坐标 (len): 显示资料的长度 example: write first line . write / 6 second line. 输出结果: first line second line data: number type i value 1234567890. text(10) value abcdefghij. write: (5) number, /(6) text. 输出结果: *7890 abcdef &指定显示格式 语法: write 资料项 显示格式参数: left-justified 资料靠左显示 centered 资料靠中间显示 right-justified 资料靠右显示 under 在资料项的x轴开始坐标显示 no-gap 紧接着显示, 不留空格 using edit mask 使用内嵌字符显示, 如 11:20:30 using no edit mask 不使用内嵌字符 no-zero 数字前面0 的部分不显示 no-sign 不显示正负号 decimals 显示 d 位小数字数 exponent f(浮点数) exponent 的值 round 四舍五入至小数位数下 r 位 currency 币别显示 dd/mm/yy 日期显示格式 mm/dd/yy dd/mm/yyyy mm/dd/yyyy ddmmyy mmddyy yymmdd example: data: x type i value 112030, a(5) value abcde. write x using edit mask _:_:_. 输出结果为 11:20:30 write x using edit mask $_,_ 输出结果为 $112,030&产生空白列 产生 n 个空白列 语法: skip example: write pass1. skip. write pass2. 输出结果为: pass1 pass2&显示图示 可以显示r/3 系统所提供的符号或图标 语法: write as symbol write as icon example: include include write: / phone symbol: , sym_phone as symbol. write: / alarm icon: , icon_alarm as icon. 执行结果: 要查看系统所提供有那些符号及图标, 可选择 “edit” 下的 “insert statement”, 选择 “write” 接下来选择要查的群组, 如symbol 或 icon, 按下 “display” 即可.&跳至指定列坐标 将坐标跳至指定的y轴列坐标 语法: skip to line example: skip to line 5. write pass1. &显示 check box 资料 以字符串数据内容的第一个字符为 check box的输出, 如果是空白, check box 显示 为空白, 相反则显示 x , 可用在逻辑判断检查 语法: write as checkbox. example: data: flag1 value . flag2 value x. write: / check flag 1: , flag1 as checkbox. write: / check flag 2: , flag2 as checkbox. 执行结果: 2.4 processing data&assign value 语法: move to 将f1的值存至变数 f2 中, 也可写成 f2 = f1 example: m_name = cher.&使用 offset 语法: move + to + example: data: f1(10) value abcdefghij. f2(5). f2 = f1+3(5). “自第4个位置开始取出5个字符 f2 的内容会变成 defgh &field string 组件的复制 语法: move corresponding to . 将strings1中的field组件的数据复制至string2中, 仅复制相同名称的组件 example: data: begin of address, firstname(10) value lulu, lastname(10) value chou, tel(12) value 4660570, end of address. data:begin of name, firstname(10), lastname(10), e_mail(30), end of name. move-corresponding address to name. name-firstname 变成 lulu, name-lastname 变成 chou, 而 name-e_mail 则不变&变量 call by value 的使用 在变量的使用上, 可以使用类似call by value 的方法 语法: write () to example: data: name(20) value source, source(10) value lily, target(10). write (name) to target. write / target. 屏幕可印出 lily&清除变量内容 语法: clear 清除变量现在内容, 恢复成初值 example: data n type i value 100. clear n. 变量 n 的内容变成 0 &算术符号 * 乘幂 * 乘 / 除 + 加 - 减 div 整数除法 mod 余数除法 &数值函数1. abs(n): 传回数值 n 的绝对值2. sign(n): 1 if n 0 0 if n = 0 -1 if n 03. ceil(n): 传回大于数值n的最小整数 example: write ceil(-5.65) 印出 5.00 write cell(4.54) 印出 5.004. floor(n): 传回小于数值n的最大整数 example: write floor(-5.65) 印出 6.00 write floor(4.54) 印出 4.005. trunc(n): 传回数值n的整数部分 example: write trunc(5.65) 印出 5.006. frac(n): 传回数值 n 的小数部分 example: write frac(5.65) 印出 0.657. cos(a),sin(a),tan(a): 传回三角函数 cos a, sin a, tan a 的值, a 为弪度量8.exp(n): 传回 en 值8. log(n): 传回 log en 值9. log10(n): 传回 log n值10.sqrt(n): 传回 n 的平方根值 &日期与时间运算 1.日期数据的运算 日期数据可以直接运算, 如加法与减法的运算 example: data: mdata type d. mdate = sy-datum. “ 如传回 19971015 mdate+6(2) = 01 “ mdate 变成 19971001 mdate = mdate - 1 “ mdate 变成 19970931 2.时间数据的运算时间格式为 hhmmss, 如 212030 表 21:20:30example: data: hours type i, minutes type i, t2 type t value 200000, t1 type t value 183000. hours = (t2 - t1) / 3600. “计算有几小时 minutes = (t2 t1) / 60. “计算几分钟&字符串数据处理1.字符串移位 语法: shift by places : (1).空白, 字符串往左移一位 (2).left, 字符串往左移 n 位 (3).right, 字符串往右移 n 位 (4).circular: 字符串以环状方式移位 example: data string(10) value abcdefghij. shift string. “得到 bcdefghi shift string by 2 places right. “得到 abcdefgh2.取代字符串内容 语法: replace with into 将字符串 中的 以 来取代 example: data: string(10) value abcdefghi, str1(3) value def, str2(3) value 123. replace str1 with str2 into string. write / string. “得到 abc123ghi3.大小写的转换 语法: translate to upper case. “转成大写 translate to lower case. “转成小写4.在字符串中寻找部分字符串 语法: search for example: data string(10) value abcdefghij. 会回存至两个变数, sy-subrc 和 sy-fdpos, 若找到则 sy-subrc 为 0 sy-fdpos 存开始位迭, 若找不到则 sy-subrc为 4, sy-fdpos为 05.字符串长度 strlen() example: int = strlen(xyzabc). “得到 6 int = strlen(abc ). “得到 36.取部分字符串 + example: data t(10) value abcdefghij. write / t+2(4). “得到 cdef 2.5 flow controlling&比较符号 1. = 或 eq : 等于 2. 或 或 ne : 不等于 3. 或 lt : 小于4. 或 gt : 大于6. = 或 ge : 大于等于7. and : 且8. or : 或9. not : 非&条件述叙 1. if 述叙 语法: if . elseif . elseif . . else. endif. (1).在每个判断叙述之后要加上 . (2).在巢状迥圈之中无法使用 else 叙述, else 叙述属 if 叙述 example: if 3 8. write / 3 is less than 8. endif. 2. case 叙述 语法: case . when . when . . when others. endcase. example: s = a. case s. when x. write / string is x. when others. write / string is not x. endcase. &迥圈叙述1.计次迥圈 语法: do n times varying from to . enddo. example: do 2 times. write / x. enddo. 执行结果: x x do varying i from1 to 10. s = s + i. enddo. write: / ,1+2+3+10=,s 执行结果: 1+2+3+10=55 2.条件迥圈语法: while . endwhile example: i = 1. s=0. while i = 10. s = s+i. i=i+1. endwhile. write: / 1+2+3+10=,s. 执行结果为: 1+2+3+10=55&迥圈控制叙述1. continue跳至迥圈的下一次example: do 3 times. if sy-index = 2. continue. write / sy-index. enddo. 执行结果: 1 32. check check 之后条件成立才继续往下执行迥圈 example: do 5 times. check sy-index between 2 and 4. write / sy-index. enddo. 执行结果: 2 3 43. exit跳离迥圈叙述example: do 10 times. if sy-index = 4. exit. endif write / sy-index. enddo. 执行结果: 1 2 3&无穷迥圈 do . enddo. 无穷迥圈必须配合 exit 叙述来执行2.6 processing internal table&internal table 的宣告 abap/4的 internal table 如同其它语言的数组结构, 在操作上可以有复制,删除,新增插入等功 能. 1.使用 type 叙述 语法: types occurs 宣告一个数组 , 型态为 , 长度为 example: types a type i occurs 10. a 是个10个元素的数值internal table example: types: begin of line, col1 type i, col3 type i, end of line. types itab type line occurs 10. 宣告一个internal table itab, 总共有10个元素, 其work area 名称 为 line 2.使用 data 叙述 若使用data叙述来宣告internal table, 可分成要不要有header line, header line 就 是所谓的 work area, 用在数据的存取上. 语法: data occurs with header line example: data vector type i occurs 10 with header line.3.直接宣告, 不使用 work area语法: data: begin of occurs , end of . example: data: begin of itab occurs 10, col1 type i, col2 type i, end of itab. 如此产生的internal table 不会有 work area, 也就是宣告时不会 reference 其它的 conponent 宣告&append line 语法: append to initial line to initial line to 为增加一预设初值的元素 example: 使用 work area data: begin of line, col1 type i, col2 type i, end of line. data itab like line occurs 10. do 2 times. line-col1 = sy-index. “sy-index为迥圈的 counter line-col2 = sy-index *2. append line into itab. “新增至 internal table中 enddo. loop at
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 餐饮企业员工培训与派遣合同
- 车祸保险理赔与第三方赔偿合同
- 儿童癫痫护理要点
- 中药中毒护理要点解析
- 护理模拟面试要点解析与实战准备
- 创口止血护理技术要点
- 高中生物必修二知识点总结
- 高考语文复习:文言文阅读之断句主观题填涂突破
- 《温室气体 产品碳足迹量化方法与要求 玻璃纤维纱产品》标准文本
- 肝炎治疗护理常规
- 艾里逊8000系列变速箱培训:《动力传递分析》
- 商务英语写作实践智慧树知到答案章节测试2023年中北大学
- 社会治安动态视频监控系统工程建设方案
- 脱硫塔玻璃鳞片胶泥衬里施工组织设计
- XB/T 505-2011汽油车排气净化催化剂载体
- GB/T 3672.2-2002橡胶制品的公差第2部分:几何公差
- GB/T 27744-2021异步起动永磁同步电动机技术条件及能效分级(机座号80~355)
- GB 8076-2008混凝土外加剂
- 宝盾转门故障代码
- 【课件】草原上的小木屋
- 医务人员违规行为与年度考核挂钩制度
评论
0/150
提交评论