2007 Dec 10 5:14 AM
Hi,
I have a doubt regarding the field symbol assignment.
In my program, I have logic as below.
<b> W_1STCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP1'.
W_2NDCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP2'.
ASSIGN (W_1STCNTFLD) TO <FS1>.
ASSIGN (W_2NDCNTFLD) TO <FS2>.</b>
While debugging, when I see the values of the Field Symbols <b><FS1></b> and <b><FS2></b> after assignment, they are <b>0, 0</b>. Why is it like that..?
In general, what does a Field Symbol hold..? the value of the variable being assigned or the Memory location of that variable..?
When I remove the paranthesis while assigning like below,
<b>ASSIGN W_1STCNTFLD TO <FS1>.</b>
it is storing the value of the variable(<b>E_INV_AGING_STRU-PDISCCNTP1</b>) to <b><FS1></b> instead of '0'.
And what is the difference between <b>ASSIGN (W_1STCNTFLD) TO <FS1></b> and <b>ASSIGN W_1STCNTFLD TO <FS1></b>..? I mean, when we put paranthesis to the variable and when we remove the paranthesis.
Please clarify my doubts. Thanks in advance.
Thanks & Regards,
Paddu.
Hi,
I have a doubt regarding the field symbol assignment.
In my program, I have logic as below.
<b> W_1STCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP1'.
W_2NDCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP2'.
ASSIGN (W_1STCNTFLD) TO <FS1>.
ASSIGN (W_2NDCNTFLD) TO <FS2>.</b>
While debugging, when I see the values of the Field Symbols <b><FS1></b> and <b><FS2></b> after assignment, they are <b>0, 0</b>. Why is it like that..?
In general, what does a Field Symbol hold..? the value of the variable being assigned or the Memory location of that variable..?
When I remove the paranthesis while assigning like below,
<b>ASSIGN W_1STCNTFLD TO <FS1>.</b>
it is storing the value of the variable(<b>E_INV_AGING_STRU-PDISCCNTP1</b>) to <b><FS1></b> instead of '0'.
And what is the difference between <b>ASSIGN (W_1STCNTFLD) TO <FS1></b> and <b>ASSIGN W_1STCNTFLD TO <FS1></b>..? I mean, when we put paranthesis to the variable and when we remove the paranthesis.
Please clarify my doubts. Thanks in advance.
Thanks & Regards,
Paddu.
2007 Dec 10 5:30 AM
Hi Paddu,
W_1STCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP1'.
W_2NDCNTFLD = 'E_INV_AGING_STRU-PDISCCNTP2'.
ASSIGN (W_1STCNTFLD) TO <FS1>.
ASSIGN (W_2NDCNTFLD) TO <FS2>.
if you do not use the paranthesis the value in the variable is assigned to the fieldsymbol.
if you use the paranthesis it will take the value of the variable E_INV_AGING_STRU-PDISCCNTP1 and it will assign the value of the E_INV_AGING_STRU-PDISCCNTP1 to the field symbol.
check the value of the E_INV_AGING_STRU-PDISCCNTP1.
Reward points if this helps.............
Regards,
Ravi G
2007 Dec 10 5:36 AM
when you use the paranthesis,(W_1STCNTFLD) actually equals to ('E_INV_AGING_STRU-PDISCCNTP1'),and the 'E_INV_AGING_STRU-PDISCCNTP1' must be the label of a data object,it can't be a string!
please refer to the following document(coming from sap abap keywords document):
Alternative 2
... [TABLE FIELD] (name)
Alternative 3
... oref->(attr_name)
Alternative 4
... {class|(class_name)}=>{attr|(attr_name)}
Effect
There are three dynamic variants for mem_area, where the storage area is not specified directly, but as the content of character/type data objects enclosed within parentheses.
In the first variant (name), the label in name is built exacltly like the direct specification. When the statement is executed, the content of name must be the label of a data object that can contain offset/length specifications, strucuture component selectors, and component selectors for the assignment of attributes in classes or objects (since Release 6.10). The content of name must be specified in uppercase letters.
The optional addition TABLE FIELD before (name) is only possible outside of classes. This addition limits the search area - where the data object specified in (name) is searched for (see below) - to the interface work areas for the current program group declared using TABLES. If TABLE FIELD is specified, casting_spec and range_spec cannot be specified explicitly.
If the label in name is a field symbol or a form parameter with an unstructured type, components can be addressed, as of Release 6.10, through structure component selectors. The components must exist when the statement is executed.
The second variant oref->(attr_name) is a special case of the first variant for the assignment of an instance attribute to a field symbol - where the object reference variable oref is specified statically. The label of the attribute is specified dynamically in the character-type field attr_name and must not be specified in uppercase letters.
The third variant {class|(class_name)}=>{name|(attr_name)} is a special case of the first variant for the assignment of a static attribute to a field symbol where the class name class and the name of the attribute name can be specified both directly and dynamically in character-type fields class_name or attr_name. The contents of attr_name and class_name do not have to be in uppercase letters. If the class name is specified dynamically and the attribute is specified directly, no offset/length specifications can be made for the attribute.
If a data object is specified dynamically, this is searched for in accordance with the following hierarchy.
Within the local data objects of the current procedure
Within the attributes, visible in a method, of the actual class, where , in instance methods, the self reference me-> is set explicitly before the label
Within the global data of the current program
Within the interface work areas of the main program of the current program group declared with TABLES
Within the attributes of the object to which oref refers, if the label has the expression oref-> (as of Release 6.10)
Note
Only for internal use can the label in name also have the form (PROG)DOBJ, whereby PROG is the name of an ABAP program and DOBJ is the name of a global data object of this program. If the program PROG is loaded during execution of the statement ASSIGN in the same internal mode as the current program is loaded, the data object (PROG)DOBJ in this program is searched for and the field symbol points to this data object after successful assignment.
Example
Dynamic access to an attribute of an object (Dynamic Access) through a field symbol.
CLASS c1 DEFINITION.
PUBLIC SECTION.
METHODS m1 IMPORTING oref TYPE REF TO object
attr TYPE string.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
FIELD-SYMBOLS <attr> TYPE ANY.
ASSIGN oref->(attr) TO <attr>.
WRITE <attr> ...
ENDMETHOD.
ENDCLASS.
2007 Dec 10 5:36 AM
Hi,
If you are assigning some value in paranthesis, that means the value of the variable which is in paranthesis will be taken. This works on the same principle like USE by VALUE and USE by REGERENCE. In case you are assigning some value directly, then it works as USE by VALUE else if the value is passed in brackets then it works as USE by REFERCNCE.
Hope this would clarify your doubt.
Reward if helpful!
Regards,
Lalit
2007 Dec 10 5:39 AM
Hi,
<b>Static ASSIGN</b>
If you already know the name of the field that you want to assign to the field symbol when you write a program, use the static ASSIGN statement:
ASSIGN <f> TO <FS>.
Ex.
<b>REPORT demo_field_symbols_stat_assign .
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i.
DATA: text(20) TYPE c VALUE 'Hello, how are you?',
num TYPE i VALUE 5,
BEGIN OF line1,
col1 TYPE f VALUE '1.1e+10',
col2 TYPE i VALUE '1234',
END OF line1,
line2 LIKE line1.
ASSIGN text TO <f1>.
ASSIGN num TO <f2>.
DESCRIBE FIELD <f1> LENGTH <f2>.
WRITE: / <f1>, 'has length', num.
ASSIGN line1 TO <f1>.
ASSIGN line2-col2 TO <f2>.
MOVE <f1> TO line2.
ASSIGN 'LINE2-COL2 =' TO <f1>.
WRITE: / <f1>, <f2>.</b>
The output is:
Hello, how are you? has length 20
LINE-COL2 = 1,234
The example declares two field symbols <F1> and <F2>. <F2> has the type I, which means that only type I fields may be assigned to it. <F1> and <F2> both point to different fields during the program.
-
<b>Dynamic ASSIGN</b>
If you do not know the name of the field that you want to assign to the field symbol when you write a program, you can use a dynamic ASSIGN statement:
ASSIGN (<f>) TO <FS>.
Ex.
<b>REPORT demo_field_symbols_dynami_as_1.
TABLES sbook.
sbook-fldate = sy-datum.
PERFORM form1 IN PROGRAM demo_form1.
The other two programs are:
REPORT demo_form1.
FORM form1.
PERFORM form2 IN PROGRAM demo_form2.
ENDFORM.
and
REPORT demo_form2.
FORM form2.
DATA name(20) TYPE c VALUE 'SBOOK-FLDATE'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN (name) TO <fs>.
IF sy-subrc EQ 0.
WRITE / <fs>.
ENDIF.
ENDFORM.</b>
The output looks something like this:
02.06.1998
hope this helps.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |