In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use the ABAP keywords IS BOUND, IS NOT INITIAL and IS ASSIGNED". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use the ABAP keywords IS BOUND, IS NOT INITIAL and IS ASSIGNED.
The keywords IS BOUND, IS NOT INITIAL and IS ASSIGNED in ABAP can easily be understood as specious if you don't pay attention to them. Today we are going to talk about the difference between them.
Copy the SAP help documentation first:
IS BOUND
It checks whether a reference variable contains a valid reference. A data reference variable that contains a stack reference, on the other hand, can become invalid even if the reference data object is removed from the stack.
IS INITIAL
Checks whether the operand operand is initial. The expression is true, if the operand contains its type-friendly initial value.
IS ASSIGNED
Checks whether a memory area is assigned to a field symbol. The expression is true if the field symbol points to a memory area.
Simply translated into Chinese:
IS BOUND: used to check whether a reference variable points to a valid reference. The help documentation specifically mentions that if a reference points to a variable requested on the stack, the variable will be destroyed with the destruction of the stack, so the reference to it is no longer valid.
IS INITIAL: used to check whether the value of a variable is the initial value corresponding to its data type.
For example, if I define a reference variable but do not assign a value to it, IS INITIAL determines that it must be abap_true.
IS ASSIGNED: for the detected field symbol, this keyword determines whether the field symbol has a memory area allocated.
These three keywords are intertwined to form some interesting permutations and combinations.
For example, is there a variable that NOT INITIAL but also NOT BOUND? Is there a field symbol that satisfies both IS INITIAL, NOT BOUND and IS ASSIGNED? Let's study these permutations and combinations with a simple ABAP report.
The complete test code:
Reference variables that satisfy both NOT INITIAL and NOT BOUND
In the main method below, line 15 defines an integer variable number on the stack and assigns its reference to the member variable dref of the class. After the execution of the main method, the stack frame in which number exists is destroyed, so the reference pointed to by dref is no longer valid, which is displayed in the debugger as: FREED STACK.
Now dref does not point to any reference, but to an invalid reference, so dref satisfies both IS NOT INITIAL and IS NOT BOUND.
IS ASSIGNED
After a field symbol definition, if no memory region is allocated to it, IS ASSIGNED returns abap_false.
The following code, if you comment out the IF condition on line 27:
The runtime throws a GETWA_NOT_ASSIGNED error: Field symbol has not yet been assigned.
In other words, whether it is reading the specific contents of field symbol or checking whether its contents are initial values, in order to avoid GETWA_NOT_ASSIGNED errors, we must use IS ASSIGNED to determine whether the field symbol is allocated a memory area before IS INITIAL judges.
Is there a NOT BOUND, IS INITIAL but IS ASSIGNED field symbol?
The answer is yes.
The field symbol defined in line 37 above is called field symbol, and all three conditions are met after the CLEAR operation on line 45 is completed. The area of memory allocated to the field symbol is not the integer itself, but a reference to the integer variable.
The report printout is as follows:
The area of memory allocated by line 40 code through ASSIGN is not freed by UNASSIGN, so IS ASSIGNED always returns abap_true. On the other hand, although this memory area has not been freed, the reference variables stored in it no longer point to any valid variables, so IS BOUND returns abap_false. Finally, because the CLEAR operation was imposed and returned to the initialization state, IS INITIAL returned abap_true.
At this point, I believe you have a deeper understanding of "how to use the ABAP keywords IS BOUND, IS NOT INITIAL and IS ASSIGNED". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.