‎2008 Jul 10 7:04 AM
Can anyone tell me what does this statement do?
assign component <var> of structure <internaltable> to <field_label>.
Thanks
Nazmul
‎2008 Jul 10 7:08 AM
Consider the following example :
ASSIGN COMPONENT 1 OF STRUCTURE <wa_dyn> TO <fs>.
<fs> = p_werks.
Here in WA_dyn contains some n number of fields,after this statement the value what ever saved in <fs> will be automatically saved in field 1 of structure <WA_DYN>.
‎2008 Jul 10 7:08 AM
Consider the following example :
ASSIGN COMPONENT 1 OF STRUCTURE <wa_dyn> TO <fs>.
<fs> = p_werks.
Here in WA_dyn contains some n number of fields,after this statement the value what ever saved in <fs> will be automatically saved in field 1 of structure <WA_DYN>.
‎2008 Jul 10 7:10 AM
hi,
This statement assigns the memory area specified using mem_area to the field symbol <fs>. You can assign a data object or a memory area calculated from the address of a data object. After the assignment, the field symbol refers to the assigned memory area and can be used in operand positions. When used in a statement, it behaves like a dereferenced data reference, meaning that the statement works with the content of the memory area.
The data type with which the assgigned memory area is treated, depends on the specifications in casting_spec. You can either execute an explicit casting or the field symbol takes on the data type of the data object specified in the assignment. A field symbol to which a memory area is assigned, has this data type after the assignment and behaves like a data object of this type.
The assigned memory area mem_area must be at least as long as the data type specified in casting_spec and must have the same alignment. If the data type determined in casting_spec is deep, the deep components with their type and position must appear in the assigned memory area exactly like this.
Use the specifications in range_spec to restrict the memory area that can be assigned to the field symbol.
System Fields
The return value is set only for the dynamic variants of mem_area.
sy-subrc Meaning
0 Assignment successful.
4 Assignment not successful.
After an unsuccessful dynamic assignment, the field symbol keeps its previous state.
Note
Obsolete Form: ASSIGN LOCAL COPY
Exceptions
Catchable Exceptions
CX_SY_ASSIGN_CAST_ILLEGAL_CAST
Cause: The type of the source field and the target type do not exactly match in offset and type in those components that are strings, tables, or references.
Runtime Error: ASSIGN_CASTING_ILLEGAL_CAST (catchable)
CX_SY_ASSIGN_CAST_UNKNOWN_TYPE
Cause: A type specified dynamically after CASTING is unknown.
Runtime Error: ASSIGN_CASTING_UNKNOWN_TYPE (catchable)
CX_SY_ASSIGN_OUT_OF_RANGE
Cause: The data object in addition RANGE does not contain the assigned data object.
Runtime Error: ASSIGN_FIELD_NOT_IN_RANGE (catchable)
Non-Catchable Exceptions
Cause: The field symbol is structured and the assigned field is shorter than the structure.
Runtime Error: ASSIGN_BASE_TOO_SHORT
Cause: The alignment for field f is too short for the type of the field symbol.
Runtime Error: ASSIGN_BASE_WRONG_ALIGNMENT
Cause: For TYPE, you can specify only simple types.
Runtime Error: ASSIGN_CAST_COMPLEX_TYPE
Cause: The source field is longer than 16 bytes and can, therefore, not be interpreted as a type P field.
Runtime Error: ASSIGN_CAST_P_TOO_LARGE
Cause: The alignment of field f is too short for the type specified at TYPE.
Runtime Error: ASSIGN_CAST_WRONG_ALIGNMENT
Cause: The length of field f does not match the type specified in TYPE.
Runtime Error: ASSIGN_CAST_WRONG_LENGTH
Cause: The type specified at TYPE is unknown.
Runtime Error: ASSIGN_CAST_WRONG_TYPE
Cause: Only up to 14 decimal places are allowed.
Runtime Error: ASSIGN_DECIMALS_TOO_HIGH
Cause: Decimal places are allowed only for type P.
Runtime Error: ASSIGN_DECIMALS_WRONG_TYPE
Cause: For field f, a length of 0 was specified.
Runtime Error: ASSIGN_LENGTH_0
Cause: For field f, a length less than 0 was specified.
Runtime Error: ASSIGN_LENGTH_NEGATIVE
Cause: For field f, an offset less than 0 was specified.
Runtime Error: ASSIGN_OFFSET_NEGATIVE
Cause: For field f, offset or length was specified and the data type of the assigning field does not allow partial access. (This is the case for data types I, F, and P.)
Runtime Error: ASSIGN_OFFSET_NOTALLOWED
Cause: The offset specified for field f exceeds the range of the ABAP variable.
Runtime Error: ASSIGN_OFFSET_TOOLARGE
Cause: In the area addressed in the offset and length specifications for field f, deep components exist (data references, object references, strings, internal tables), which may not be overwritten.
Runtime Error: ASSIGN_OFF+LENGTH_ILLEGAL_CAST
Cause: Offset and length specified for field f exceed the range of the ABAP variable.
Runtime Error: ASSIGN_OFFSET+LENGTH_TOOLARGE
Cause: Field f is not a data reference. However, a data reference was expected.
Runtime Error: ASSIGN_REFERENCE_EXPECTED
Cause: The type of the source field and the target type do not match exactly in offset and type in those components that are strings, tables, or references.
Runtime Error: ASSIGN_STRUCTURE_ILLEGAL_CAST
Cause: You cannot assign substrings to a field symbol.
Runtime Error: ASSIGN_SUBSTRING_NOT_ALLOWED
Cause: The field symbol is typed and the type of the assigned field is incompatible to it.
Runtime Error: ASSIGN_TYPE_CONFLICT
Cause: The type of the source field contains strings, tables, or references.
Runtime Error: ASSIGN_TYPE_ILLEGAL_CAST
Cause: The type of the source field is a structure and, under Unicode, not compatible to the target type.
Runtime Error: ASSIGN_UC_STRUCT_CONFLICT
hope this might be helpful.
reward points if useful.
regards,
siri.
‎2008 Jul 10 7:29 AM
Hi Nazmul,
ASSIGN mainly comes under the concept called Field-Symbols.
Syntax goes something like this :
ASSIGN COMPONENT idx OF STRUCTURE struc TO <fs>.
ASSIGN COMPONENT name OF STRUCTURE struc TO <fs>.
Extras:
1. ... CASTING ... or
2. ... TYPE type
3. ... DECIMALS dec
4. ... RANGE r
Effect
If the field name or idx has the type C or is a substructure that does not contain an internal table, it is regarded as a component name, otherwise is is regarded as a component number. The corresponding component of the structured field struc is assigned to the field symbol <fs>.
The Return Code is set as follows:
SY-SUBRC = 0:
Assignment successful.
SY-SUBRC = 4:
The system could not assign the field to the field symbol.
Note
If idx has the value 0, the entire structure is assigned to the field symbol.
Before Release 6.10, assigning structure components to field symbols was the only way of accessing components of formal parameters or field symbols if these were typed unstructured. Since Release 6.10, you can also specify componenents of unstructured typed field symbols and formal parameters. when specifying a data object dynamically.
Example
PROGRAM P1MAIN.
DATA: BEGIN OF STR,
A VALUE 'a',
B VALUE 'b',
C VALUE 'c',
D VALUE 'd',
END OF STR,
CN(5) VALUE 'D'.
FIELD-SYMBOLS <FS> TYPE ANY.
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF
STRUCTURE STR TO <FS>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE <FS>.
ENDDO.
ASSIGN COMPONENT CN OF STRUCTURE STR TO <FS>.
WRITE <FS>.
Output:
a b c d
To need more information on this please refer the following link :
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/frameset.htm
Regards,
Swapna.
‎2008 Jul 10 7:31 AM
hi,
Plz refer to this link.
[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm]
This will help.
Regards
Sumit Agarwal
‎2008 Jul 10 7:33 AM
assign component <var> of structure <internaltable> to <field_label>.
This statement will assign the field VALUE of the field <VAR> of structure <internal table> to field symbol variable <field_label>
Before assigning similar to clear, you should unassign <field_label>