Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3458

Re: Use of "ASSIGN"

$
0
0

Hi, Christoph!

 

If you have used this statement: Is there the need to use "UNASSIGN" later for <fs> or is this done by ABAP internally?


No. As usual, there is no need to unassign previously assigned field symbol. The lifetime of field symbol is the same as for variable. If it is declared inside the modularization unit (FORM, function module or method of class), it is "alive" till the end of execution of that modularization unit.

In the discussion of the document comment like:

"As an alternative, if you are on SAP release > ECC6.0, you can make use of an implicit enhancement to export the value of the required global data. This IMHO is a more cleaner approach."

comes up

 

So is ths now the Best practise in SAP? If I read cross all the discussion: the "assign" is not the best option to solve the demand


The best practice is to use explicit enhacement spot instead of ASSIGN.

 

There is a such concept as an encapsulation or information hiding. Among others it means that the program is divided into several parts, which interact with each other via their interfaces. For example, the program can be divided into several function modules, which call each other and pass and recieve data via thier import- and export- parameters.

 

There are few reasons for doing so. One of them is particular important. You can change (optimize, improve, ...) implementation of function modules, methods of classes and so on without affecting the whole program. All what you need is to keep their interfaces (parameters) stable.

 

When you use explicit enhancements, you don't violate this rule, because most of enhacement types support it. In particular, they allow you to get access only to that data, which is intended for it.

 

WIth ASSIGN you can access variables, that not intended for external use (i.e. not intended for use outside of the function module or method which contains these variables).

More than it, with ASSIGN you can occasionally change the value of variables from your program.

If you do so with the standard SAP program, you should keep in mind, that SAP (or other vendor) can change implementation of function module or method without any public announcements. In particular, SAP can replace the variable by another one with the different name. Since then, your code won't work properly.

 

 

To conclude, with explicit enhancements:

- The program code is more clear to other developers.

- The data flow (passing and recieving values) is more predictable and safe (data types, directions - import/export).

- The code is safer, because you can't occasionally change the value of the variable in other program.

 

But sometimes there is no appropriate explicit enhancement. So, you can use ASSIGN when you don't have any other alternatives. But you always must keep in mind that you should be very careful and have clear understanding of what you are doing.


Viewing all articles
Browse latest Browse all 3458

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>