简体   繁体   English

ABAP 域和数据类型理解

[英]ABAP Domain and Data Types Understanding

so my company wants me to learn ABAP for SAP and I have started on the road to learn this.所以我的公司想让我学习 SAP 的 ABAP,我已经开始学习这个。 My background is mainly VB.net and sqlserver with T-SQL but also have experience in c#.我的背景主要是 VB.net 和 sqlserver with T-SQL 但也有 c# 的经验。

With ABAP though I am needing some clarification or confirmation on the understanding of Data Types and Domain.使用 ABAP,虽然我需要对数据类型和域的理解进行一些澄清或确认。 If anyone can help.如果有人可以帮忙。

My understanding currently is we have a table, in the table we have fields and the fields have data types and lengths if needed.我目前的理解是我们有一个表,在表中我们有字段,如果需要,字段有数据类型和长度。 Example: We have a table Customer, I could have a customerNumber field with the data type of char(10) .示例:我们有一个表 Customer,我可以有一个数据类型为char(10)customerNumber字段。 To me this mean in the table customer we have a field called CustomerNumber that will have 10 characters.对我来说,这意味着在表 customer 中我们有一个名为CustomerNumber的字段,它将有 10 个字符。

However with ABAP we have Domains, Data elements then the field, does this mean we have a field named whatever we want.但是,对于 ABAP,我们有域、数据元素和字段,这是否意味着我们有一个可以随意命名的字段。 As the field could mean anything we assign a data element which has the descriptions of the sort of data stored within the field.由于该字段可以表示任何内容,因此我们分配了一个数据元素,该元素具有存储在该字段中的数据类型的描述。 However to store the format and data type we need to assign the Domain to the Data element.然而,为了存储格式和数据类型,我们需要将域分配给数据元素。

For example I call a field ZCUSNO , currently this means nothing however if I assign the ZCTNMR (with description of customer number) Data element this tells us that the field ZCUSNO is ZCTNMR so ZCUSNO is a customer number field.例如,我称一个字段ZCUSNO ,目前这没有任何意义,但是如果我分配ZCTNMR (带有客户编号描述)数据元素,这告诉我们字段ZCUSNOZCTNMR所以ZCUSNO是客户编号字段。

Now within the data elements we would have a domain and for our example ZCTNMR data element (the customer number) we could assign ZCTDOM as the domain which would be what I recognise as the data types so Char 20, Char 100 or integer field etc.现在在数据元素中,我们将有一个域,对于我们的示例ZCTNMR数据元素(客户编号),我们可以将ZCTDOM指定为域,这将是我认为的数据类型,例如 Char 20、Char 100 或整数字段等。

Is my understanding correct on this?我的理解是否正确? and could someone give me a clear indication of what the difference between a Domain > Data Element is against what I would know as data types in sqlserver.谁能给我一个明确的指示,说明域> 数据元素与我所知道的 sqlserver 中的数据类型之间的区别。

Thanks谢谢

I don't know if it's 100% correct, but that's is the way I use, like you say.我不知道它是否 100% 正确,但这就是我使用的方式,就像你说的。

You can reuse the Domain, If you don't plan to reuse you can use direct the Data Element and refer this to a built-in-type.您可以重用域,如果您不打算重用,则可以直接使用数据元素并将其引用到内置类型。

  • Data Element is to define semantic of the field, like label, translation, etc数据元素是定义字段的语义,如标签、翻译等
  • Domain is to define techinical info of the field, like Type, conversions, predefined Values,e tc是定义字段的技术信息,如类型、转换、预定义值等

EG例如

Domain:领域:

  • DOM_VALUE you define it's 10 position and 2 Decimals DOM_VALUE你定义了它的 10 个位置和 2个小数

Data Element:数据元素:

  • UNIT_VAL you refer it to DOM_VALUE and define label as "Unit Value" UNIT_VAL您将其引用到DOM_VALUE并将标签定义为“单位值”
  • TOTAL_VAL you refer it to DOM_VALUE and define label as "Total Value" TOTAL_VAL您将其引用到DOM_VALUE并将标签定义为“总价值”

Your understanding is pretty correct and not much can be added here.您的理解非常正确,这里不能添加太多。

You should clearly get the main thing.您应该清楚地了解主要内容。

  1. Domains store technical data (decimal points, length, type, predefined values and so on)域存储技术数据(小数点、长度、类型、预定义值等)
  2. Data elements store semantic data (labels, texts, search help binding, etc.)数据元素存储语义数据(标签、文本、搜索帮助绑定等)

Not every table field has data element (they can possess builtin type) but every field has type (either primitive or wrapped in data element).并非每个表字段都有数据元素(它们可以拥有内置类型),但每个字段都有类型(原始或包装在数据元素中)。

在此处输入图片说明

If you wanna use your field in screens (Dynpros), ALV grids or other reports, then create data elements that will bear business meaning of your field.如果您想在屏幕 (Dynpros)、ALV 网格或其他报告中使用您的字段,那么创建将承载您的字段的业务意义的数据元素。

If you use this field just for calculations or other utility internal tasks, then don't bother yourself.如果您仅将此字段用于计算或其他实用程序内部任务,请不要打扰自己。

  1. As usual table date field (type of variable) uses data element which uses domain.像往常一样,表格日期字段(变量类型)使用使用域的数据元素。
  2. When you create fields in table and use predefined types instead of data elements you will have some problems in future, when you'll need to see the data on alv_grid.当您在表中创建字段并使用预定义类型而不是数据元素时,您将来会遇到一些问题,当您需要查看 alv_grid 上的数据时。 Actually, you will see that you have some problems even before this (when you will try to make a maintenance view the header will have something like "+" symbol).实际上,在此之前您会发现您有一些问题(当您尝试制作维护视图时,标题将具有类似“+”符号的内容)。
  3. And of course we usually try to create 1 domain for 2 and more Data Elements.当然,我们通常会尝试为 2 个或更多数据元素创建 1 个域。
  4. In domain you talk about main logic.在领域中,您谈论主要逻辑。 In Data Element I always talk about Field label settings (how it'll show in future and some other things)在数据元素中,我总是谈论字段标签设置(将来如何显示以及其他一些内容)

Final: Actually, the good practice, as I think to create a domain for data element, it may help you in future.最后:实际上,好的做法,因为我认为为数据元素创建一个域,它可能在未来对您有所帮助。

I hope that it helps you.我希望它能帮助你。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM