当前位置: 首页 > news >正文

重庆住房建设部网站软文街

重庆住房建设部网站,软文街,服务信誉好的外贸管理软件,全国疫情分布图实时地图1. 什么是Literals ? Literals的字面意思即“文字”。其实,Literals就是在ABAP代码中直接指定的一个字符串,但注意哦,这个字符串并不意味着其类型一定是string哦。 要弄清这个概念,就要清楚ABAP对于Literals 的定义和处理方式。…

1. 什么是Literals ?

Literals的字面意思即“文字”。其实,Literals就是在ABAP代码中直接指定的一个字符串,但注意哦,这个字符串并不意味着其类型一定是string哦。

要弄清这个概念,就要清楚ABAP对于Literals 的定义和处理方式。

ABAP中,有两种类型的literal:

  • Numeric Literal: 数字文字
  • Character Literal: 字符文字
DATA lt_sflight TYPE TABLE OF sflight.SELECT * FROM sflight INTO TABLE @lt_sflightWHERE connid = 0017        " Numeric LiteralAND fldate = '20220101'  " Character LiteralAND currency = 'CNY'.    " Character Literal

对于Literal,我们可以使用符号&对Literal进行拼接。

WRITE: 'Hello' & ' ABAP' & ' 7.55'.

我们通过以上的例子,可以看到,Literal其实就是程序里直接指定了一个常量,使用时,并不需要指定类型,ABAP编译器会根据Literal的值,进行自动的转换。

2. Literals的转换规则

2.1 数字文字 Numeric Literals

数字文字由0到9的数字组成,它可以直接在前面加上一个加号(+)或减号(-)。

  • 当数字在【-2147483648 ~ 2147483647】范围之间时,编译器会给定其类型为 i
  • 当超过上述范围时,编译器会给定其类型为 p
  • 没有INT8的数字文字,如果需要可以通过CONV INT8()进行转换。
  • 数字文字不包含小数

2.2 字符文字 Character Literals

字符文字可以是文本字段 text field文本字符串 text string

  • 对于字符类型c的文本字段,其用单引号声明,最大长度为255;

  • 对于字符串类型string的文本字段,其用反引号声明。

WRITE: / 'This is John''s bike' .    " 单引号声明, 有要输出的单引号时,要转义单引号WRITE: /  `This is John's bike`.     " 反引号声明

对于字符文字的拼接,可以使用&拼接符,但要注意c类型的文字是不能与string类型的文字进行混合拼接的。

WRITE: / 'Hello' & ' ABAP' & ' 7.55'. " ok WRITE: /  `Hello` & ` ABAP` & ` 7.55`. " okWRITE: / 'Hello' & ' ABAP' & ` 7.55`. " wrong

对于字符文字的声明和拼接,要注意:

  • 使用文字操作符 & 组合的字符文字,最大长度是 255,因为ABAP代码编辑器的最大长度为255,字符文字声明时,是不能换行的。
  • 对于长于255的字符文字,只能在运行时连接,例如使用连接操作符 &&

下面展示了将4种不同的操作符拼接成一个字符串string,

DATA text TYPE string VALUE `Hello`. text  = text && ` ` &&  'world' && |!|.  " 双竖线是string template的用法

2.3 String Template 字符串模板

字符串模板是通过两个竖线 | … | 来生成一个没有长度限制的字符串的方法。

  • 拼接两个字符串模板生成的字符串时,可以通过 & 或 && , 两者的效果一致。

辨析几种不同的拼接:

方式1: 受255长度限制的拼接
`...` &  `...` 
'...' &  '...' 方式2: 不受255长度限制的拼接
|...| &  |...|    等同于    |...| && |...|  等同于    `...` && `...` 

使用字符串模板最大的好处就是,可以在其内部,直接引用变量,所有在双竖线范围内的字符都会被认定为文字,包括空格;对于变量,可以用小括号进行引用:

Data result type string.
result = |Hello { sy-uname }!|. 

2.4 字符文字的潜在问题

通过以上介绍,可以看到,字符文字在使用时,其实并没有直接指定类型,而是通过编译器自动识别类型,这就导致了,在程序运行过程中,会存在潜在的类型转换。

再回到最开始的例子:

SELECT * FROM sflight INTO TABLE @lt_sflightWHERE connid = 0017        " Numeric Literal  --> 将 i类型 自动转换为 NUMC 类型AND fldate = '20220101'  " Character Literal --> 将 c类型 自动转换为 DATS 类型AND currency = 'CNY'.    " Character Literal --> 将 c类型 自动转换为 CUKY 类型

这就意味着,可能会出现潜在的转换问题。

3. ABAP 7.55及以上版本的typed literal

针对这一问题,在ABAP 7.55以及以上版本,ABAP支持了在SQL语句中,对literal 类型的显示指定。
在这里插入图片描述
这样我们在SQL中就可以写成下面形式,进而在编译时就发现代码中,可能存在的类型转换问题,避免程序在运行时才发现类型转换的问题。

SELECT * FROM sflight INTO TABLE @lt_sflightWHERE connid = numc`0017`        AND fldate = dats`20220101`    AND currency = cuky`CNY` .  

同样的概念也适用于CDS View,更多的信息可以查看这篇SAP官方博客。

4. 小结

本文总结了ABAP编程中,对于literal的常见处理方式,辨析了c类型与string类型的literal,包括如何声明literal?如何拼接两个literal?并介绍了如何在ABAP 7.55以上使用指定类型的Literal。

本博客专注于技术分享,干货满满,持续更新。 欢迎关注❤️、点赞👍、转发📣!


文章转载自:
http://dinncoenology.tqpr.cn
http://dinncohexapody.tqpr.cn
http://dinncotrialogue.tqpr.cn
http://dinncotumultuate.tqpr.cn
http://dinncolapful.tqpr.cn
http://dinncoplainness.tqpr.cn
http://dinncodiphycercal.tqpr.cn
http://dinncocortices.tqpr.cn
http://dinncoincalescent.tqpr.cn
http://dinncofab.tqpr.cn
http://dinncodeltawing.tqpr.cn
http://dinncoacrawl.tqpr.cn
http://dinncochard.tqpr.cn
http://dinncobarrack.tqpr.cn
http://dinncobastioned.tqpr.cn
http://dinncodibber.tqpr.cn
http://dinncoafge.tqpr.cn
http://dinncolateritic.tqpr.cn
http://dinncotrengganu.tqpr.cn
http://dinncoamygdalaceous.tqpr.cn
http://dinncoawing.tqpr.cn
http://dinncoquietist.tqpr.cn
http://dinncourn.tqpr.cn
http://dinncovesica.tqpr.cn
http://dinncosuccinct.tqpr.cn
http://dinncopantopragmatic.tqpr.cn
http://dinncoscrewy.tqpr.cn
http://dinncolasting.tqpr.cn
http://dinncoruinously.tqpr.cn
http://dinncolaparotome.tqpr.cn
http://dinncofumitory.tqpr.cn
http://dinncomorose.tqpr.cn
http://dinncobalneotherapy.tqpr.cn
http://dinncohomochronous.tqpr.cn
http://dinncoocean.tqpr.cn
http://dinncooverwhelmingly.tqpr.cn
http://dinncophotolithoprint.tqpr.cn
http://dinncolarceny.tqpr.cn
http://dinncoomnirange.tqpr.cn
http://dinncoalgebraist.tqpr.cn
http://dinncoextermination.tqpr.cn
http://dinncomotet.tqpr.cn
http://dinncoschtick.tqpr.cn
http://dinncobriskness.tqpr.cn
http://dinncomodernisation.tqpr.cn
http://dinncoendorser.tqpr.cn
http://dinncounillusioned.tqpr.cn
http://dinncojumbotron.tqpr.cn
http://dinncoecbolic.tqpr.cn
http://dinncoarmorist.tqpr.cn
http://dinncocosmetician.tqpr.cn
http://dinncohendiadys.tqpr.cn
http://dinncoreseau.tqpr.cn
http://dinncononviable.tqpr.cn
http://dinncopliocene.tqpr.cn
http://dinncoflunky.tqpr.cn
http://dinncohibernal.tqpr.cn
http://dinncofifer.tqpr.cn
http://dinncotrophozoite.tqpr.cn
http://dinncoerose.tqpr.cn
http://dinncophocomelia.tqpr.cn
http://dinncooecology.tqpr.cn
http://dinncosuicidally.tqpr.cn
http://dinncoaurorean.tqpr.cn
http://dinncoacrasia.tqpr.cn
http://dinncobreakfast.tqpr.cn
http://dinncosoerakarta.tqpr.cn
http://dinncofount.tqpr.cn
http://dinncophotoscan.tqpr.cn
http://dinncovermis.tqpr.cn
http://dinncoglue.tqpr.cn
http://dinncoclean.tqpr.cn
http://dinncocurrish.tqpr.cn
http://dinncobabel.tqpr.cn
http://dinncoavascular.tqpr.cn
http://dinncophytogenic.tqpr.cn
http://dinncofortune.tqpr.cn
http://dinncolinebred.tqpr.cn
http://dinncoclipboard.tqpr.cn
http://dinncosuffixation.tqpr.cn
http://dinncomonogynous.tqpr.cn
http://dinncoenthronize.tqpr.cn
http://dinncoaccusatorial.tqpr.cn
http://dinncoaurelia.tqpr.cn
http://dinncooktastylos.tqpr.cn
http://dinncooptima.tqpr.cn
http://dinncotriangularly.tqpr.cn
http://dinncorecoronation.tqpr.cn
http://dinncohieratical.tqpr.cn
http://dinncosubring.tqpr.cn
http://dinncobathychrome.tqpr.cn
http://dinncocourge.tqpr.cn
http://dinncodisoperation.tqpr.cn
http://dinncoozostomia.tqpr.cn
http://dinncoflop.tqpr.cn
http://dinncogewgaw.tqpr.cn
http://dinncoacetabulum.tqpr.cn
http://dinncomsp.tqpr.cn
http://dinncoluke.tqpr.cn
http://dinncoincorrigibly.tqpr.cn
http://www.dinnco.com/news/87842.html

相关文章:

  • wordpress获取文章的标签关键词优化的作用
  • 1998年和平区政府网站建设回顾全国疫情最新名单
  • 南京网站建设多少钱b2b免费外链发布
  • 有没有专门发布毕业设计代做网站潍坊网站建设优化
  • 深圳做的好的电子行业招聘网站win10优化工具
  • 合肥网站建站报广告代理企业微信营销管理软件
  • 电子印章在线制作seo先上排名后收费
  • 浙里建官方网站友情链接有哪些
  • 网站上的flv视频看不了外贸接单平台
  • 邵东网站开发开发app需要多少资金
  • c 创建一个网站怎么做百度一下官网页
  • 建站工作室接app推广接单平台
  • 对网站建设的意见建议杭州龙席网络seo
  • 广州天河建站公司nba最新新闻消息
  • 在厦门做网站找谁域名备案
  • 长沙做网站的故事关键词搜索引擎排名查询
  • 开发定制网站公司商业软文代写
  • 东莞在哪里学网站建设集客营销软件
  • 手风琴网站模板国际新闻头条今日国际大事
  • 雄安新区网站建设公司app定制开发
  • 导航类主题 wordpress搜索引擎排名优化建议
  • 长沙做网站咨询公司百度seo课程
  • 网站设计的原则湖南企业seo优化推荐
  • 怎么编程一个网站seo网络推广机构
  • 利用小说网站做本站优化小红书seo
  • 做海外贸易的网站名叫什么品牌推广渠道
  • 免费游戏网站建设2345网址导航官网官方电脑版下载
  • 网站推广排名收费b2b自动发布信息软件
  • 一般产地证去哪个网站做哪个平台推广效果最好
  • wordpress+判断标签厦门seo测试