-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabapassign.html
309 lines (307 loc) · 16.9 KB
/
abapassign.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="EN">
<!-- ABAPASSIGN -->
<!-- Mirrored from help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapassign.htm by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 20 Jan 2022 17:39:25 GMT -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="author" content="SAP">
<meta name="description" content="ASSIGN">
<meta name="keywords" content="ABAP, ASSIGN">
<title>
ASSIGN - ABAP Keyword Documentation
</title>
<link rel="icon" href="ABAPIcon.ico" type="image/ico">
<link rel="shortcut icon" href="ABAPIcon.ico">
<LINK rel="stylesheet" href="abap_docu.css" type="text/css">
<script type="text/JavaScript">
function call_link(linked_file)
{
if(parent.frames.length>0){
parent.window.frames["basefrm"].window.location = linked_file;
parent.window.frames["treeframe"].window.location = "abap_docu_tree92bd.html?file=" + linked_file;}
else {
window.location = linked_file;}
}
function urlToClipboard(id){
try{ var loc = top.location.href;}
catch(e){ alert( "URL cannnot be determined" ); return; }
var field = document.getElementById(id);
field.focus();
if ( loc.search( ".htm" ) == -1 && loc.search( ".HTM" ) == -1 ){ loc = loc + "index.htm"; }
if ( loc.search( "index.html" ) != -1
|| loc.search( "INDEX-2.html" ) != -1 ){
var off = loc.search( "file=" );
if ( off == -1 ){
field.value = loc + "?file=abapassign.htm"; }
else {
field.value = loc.substring( 0, off ) + "file=abapassign.htm";
}
}
else {
field.value = loc; }
field.setSelectionRange(0, field.value.length);
var r = confirm( "Copy URL to clipboard?\n\n" + field.value + "\n\nCopy to clipboard does not work in all browsers." );
if (r == true) {
try{
document.execCommand("copy");
}
catch(e){ alert( "URL could not be copied to clipboard" ); }
}
window.scrollTo(0,0);
}
</script>
</head>
<body>
<div class="all">
<p class="copyright">SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
<input type="button" value="URL" style="font-size:8px; width:26px; height:16px; padding:0"
onclick="urlToClipboard('url')" title="Copy URL to Clipboard" >
</p>
<span class="path">
<a href="javascript:call_link('abenabap.html')" class="blue">ABAP - Keyword Documentation</a> →
<a href="javascript:call_link('abenabap_reference.html')" class="blue">ABAP - Reference</a> →
<a href="javascript:call_link('abenabap_data_working.html')" class="blue">Processing Internal Data</a> →
<a href="javascript:call_link('abenvalue_assignments.html')" class="blue">Assignments</a> →
<a href="javascript:call_link('abenreference_assignments.html')" class="blue">Assigning References</a> →
<a href="javascript:call_link('abenset_field_symbols.html')" class="blue">Setting Field Symbols</a> →
</span>
<A NAME="@@ASSIGN@@!ABAP_STATEMENT!@@"></A>
<A NAME="@@TO@@ASSIGN@@"></A>
<p><span class="h1">
ASSIGN <br><br>
</span></p>
<P>
<a href="javascript:call_link('abapassign_shortref.html')" class="blue">Quick Reference</a> <br><br>
</P>
<p><span class="h2">
<span class="bold">Syntax</span>
</span></p>
<P>
<span class="qtext">ASSIGN <a href="javascript:call_link('abapassign_mem_area.html')" class="blue">mem_area</a> TO <fs>
<a href="javascript:call_link('abapassign_casting.html')" class="blue">casting_spec</a> <a href="javascript:call_link('abapassign_range.html')" class="blue">range_spec</a>.</span> <br><br>
</P>
<p><span class="h4">
Effect
</span></p>
<P>
This statement assigns the memory area specified using <a href="javascript:call_link('abapassign_mem_area.html')" class="blue"><span class="qtext">
mem_area</span></a> to the field symbol <span class="qtext"><fs></span>. A data object or a memory
area calculated from the address of a data object can be assigned. 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.
</P>
<P>
The following can be specified for <span class="qtext"><fs></span>:
</P>
<ul class="disc">
<li>
An existing field symbol with appropriate typing.
<br><br></li>
<li>
An inline declaration <a href="javascript:call_link('abenfield-symbol_inline.html')" class="blue"><span class="qtext">FIELD-SYMBOL(<fs>)</span></a>.
The typing depends on the <a href="javascript:call_link('abapassign_mem_area.html')" class="blue"><span class="qtext">mem_area</span></a> specified.
<br></li>
</ul>
<P>
The data type with which the assigned memory area is handled depends on what is specified in <a href="javascript:call_link('abapassign_casting.html')" class="blue"><span class="qtext">casting_spec</span></a>. Either an explicit
<a href="javascript:call_link('abencast_casting_glosry.html')" class="grey" title="Glossary Entry">casting</a> can be performed or the field symbol uses the data type of the data object specified in the assignment. In both cases, the data type used must
<a href="javascript:call_link('abentyping_check_general.html')" class="blue">match</a> the
<a href="javascript:call_link('abentyping_glosry.html')" class="grey" title="Glossary Entry">typing</a> of the field symbol.
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.
</P>
<P>
The assigned memory area <span class="qtext">mem_area</span> must be at least as long as the data type specified in <span class="qtext">casting_spec</span> and must have at least the same
<a href="javascript:call_link('abenalignment_glosry.html')" class="grey" title="Glossary Entry">alignment</a>. If the data type determined in <span class="qtext">casting_spec</span> is
<a href="javascript:call_link('abendeep_glosry.html')" class="grey" title="Glossary Entry">deep</a>, the deep components with their type and position must appear in the assigned memory area exactly like this.
</P>
<P>
The information in <a href="javascript:call_link('abapassign_range.html')" class="blue"><span class="qtext">range_spec</span></a> is used to define the memory area that can be assigned to the field symbol. <br><br>
</P>
<P>
<span class="bold">System Fields</span> <br><br>The return value is set only for the
<a href="javascript:call_link('abapassign_mem_area_dynamic_dobj.html')" class="blue">dynamic variants</a> and the
<a href="javascript:call_link('abapassign_mem_area_writable_exp.html')" class="blue">table expression variant</a> of <a href="javascript:call_link('abapassign_mem_area.html')" class="blue">
<span class="qtext">mem_area</span></a>. If the constructor operator <span class="qtext">NEW</span> is used as a
<a href="javascript:call_link('abapassign_mem_area_writable_exp.html')" class="blue">writable expression</a>, this operator sets the return value. <br><br>
</P>
<table border>
<tr>
<td><span class="qtext"><span class="bold">sy-subrc</span></span></td>
<td><span class="bold">Meaning</span></td>
</tr>
<tr>
<td>0</td>
<td>Assignment completed.</td>
</tr>
<tr>
<td>4</td>
<td>Assignment not completed.</td>
</tr>
<tr>
<td>8</td>
<td>A <a href="javascript:call_link('abapassign_mem_area_writable_exp.html')" class="blue">table expression</a> was not assigned.</td>
</tr>
</table><br>
<P>
If a dynamic assignment or assignment of a table expression could not be performed, the field symbol
keeps its previous state. If the static assignment could not be performed, a memory is not assigned to the field symbol after the statement <span class="qtext">ASSIGN</span> and the assignment can be checked with the
<a href="javascript:call_link('abenpredicate_expression_glosry.html')" class="grey" title="Glossary Entry">predicate expression</a>
<a href="javascript:call_link('abenlogexp_assigned.html')" class="blue"><span class="qtext"><fs> IS ASSIGNED</span></a>. If
an assignment were to produce illegal memory accesses, an exception is raised in the case of both static and dynamic <span class="qtext">ASSIGN</span> statements. <br><br>
</P>
<p><span class="h4">
Notes
</span></p>
<ul class="disc">
<li>
If field symbols are set using <span class="qtext">ASSIGN</span>, permission to access the assigned
data object is only checked at the position of the statement. The field symbol can then be passed on
as required and used to access the assigned data object in any position. To prevent access to private
and read-only attributes using field symbols outside classes, field symbols for these attributes should
not be published externally. A constant or read-only input parameter, however, can never be made modifiable by passing a field symbol.
<br><br></li>
<li>
One obsolete form of the statement <span class="qtext">ASSIGN</span> is <a href="javascript:call_link('abapassign_local_copy.html')" class="blue"><span class="qtext">ASSIGN LOCAL COPY</span></a>. <br><br>
<br></li>
</ul>
<p><span class="h4">
Example
</span></p>
<p>
Three field symbols are assigned the subfields for year, month, and day of the system field <span class="qtext">sy-datlo</span>. The subfields can then be addressed using field symbols.
</p>
<p class="qtextml1">
<span class="qtext">
FIELD-SYMBOLS <year> TYPE n. <br>FIELD-SYMBOLS <month> TYPE n. <br>FIELD-SYMBOLS <day> TYPE n. <br>
<br>ASSIGN sy-datlo+0(4) TO <year>. <br>ASSIGN sy-datlo+4(2) TO <month>. <br>ASSIGN sy-datlo+6(2) TO <day>. <br>
<br>cl_demo_output=>new( <br> )->write( <year> <br> )->write( <month> <br> )->display( <day> ). <br><br>
</span>
</p>
<p><span class="h4">
<a href="javascript:call_link('abenabap_language_exceptions.html')" class="blue">Exceptions</a>
</span></p>
<P>
<span class="bold">Handleable Exceptions</span>
</P>
<P>
<span class="lnkgrey">CX_SY_ASSIGN_CAST_ILLEGAL_CAST</span>
</P>
<ul class="disc">
<li>
<span class="italic">Cause:</span> 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. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CASTING_ILLEGAL_CAST</span>
<br></li>
</ul>
<P>
<span class="lnkgrey">CX_SY_ASSIGN_CAST_UNKNOWN_TYPE</span>
</P>
<ul class="disc">
<li>
<span class="italic">Cause:</span> A type specified dynamically after <span class="qtext">CASTING</span> is unknown. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CASTING_UNKNOWN_TYPE</span>
<br></li>
</ul>
<P>
<span class="lnkgrey">CX_SY_ASSIGN_OUT_OF_RANGE</span>
</P>
<ul class="disc">
<li>
<span class="italic">Cause:</span> The data object in addition <span class="qtext">RANGE</span> does not contain the assigned data object. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_FIELD_NOT_IN_RANGE</span> <br><br>
<br></li>
</ul>
<P>
<span class="bold">Non-Handleable Exceptions</span>
</P>
<ul class="disc">
<li>
<span class="italic">Cause:</span> The field symbol is structured and the assigned field is shorter than the structure. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_BASE_TOO_SHORT</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The alignment for field <span class="qtext">f</span> is too short for the type of the field symbol. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_BASE_WRONG_ALIGNMENT</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> Only simple types can be specified for <span class="qtext">TYPE</span>. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CAST_COMPLEX_TYPE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The source field is longer than 16 bytes and cannot be interpreted as a type <span class="qtext">p</span> field. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CAST_P_TOO_LARGE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The alignment of field <span class="qtext">f</span> is too short for the type specified in <span class="qtext">TYPE</span>. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CAST_WRONG_ALIGNMENT</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The length of field <span class="qtext">f</span> does not match the type specified in <span class="qtext">TYPE</span>. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CAST_WRONG_LENGTH</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The type specified in <span class="qtext">TYPE</span> is unknown. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_CAST_WRONG_TYPE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> A maximum of 14 columns is permitted. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_DECIMALS_TOO_HIGH</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> Decimal places are allowed only for type <span class="qtext">p</span>. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_DECIMALS_WRONG_TYPE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> A length of 0 was specified for field <span class="qtext">f</span>. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_LENGTH_0</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> A length less than 0 was specified for field <span class="qtext">f</span>. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_LENGTH_NEGATIVE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> An offset less than 0 was specified for field <span class="qtext">f</span>. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_OFFSET_NEGATIVE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> An offset or length was specified for field <span class="qtext">f</span>
and the data type of the assigning field does not allow partial access. (This is the case for data types I, F, and P.) <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_OFFSET_NOTALLOWED</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The offset specified for field <span class="qtext">f</span> exceeds the range of the ABAP variable. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_OFFSET_TOOLARGE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> In the area addressed in the offset and length specifications for
field <span class="qtext">f</span>, deep components exist (data references, object references, strings, internal tables), which may not be overwritten. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_OFF+LENGTH_ILLEGAL_CAST</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> Offset and length specified for field <span class="qtext">f</span> exceed the range of the ABAP variable. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_OFFSET+LENGTH_TOOLARGE</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> Field <span class="qtext">f</span> is not a data reference. However, a data reference was expected. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_REFERENCE_EXPECTED</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> 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. <br>
<span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_STRUCTURE_ILLEGAL_CAST</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> Substrings cannot be assigned to a field symbol. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_SUBSTRING_NOT_ALLOWED</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The field symbol is typed and the type of the assigned field is incompatible with it. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_TYPE_CONFLICT</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The type of the source field contains strings, tables, or references. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_TYPE_ILLEGAL_CAST</span>
<br><br></li>
<li>
<span class="italic">Cause:</span> The type of the source field is a structure not compatible with the target type. <br><span class="italic">Runtime error:</span> <span class="qtext">ASSIGN_UC_STRUCT_CONFLICT</span>
<br></li>
</ul>
<br>
<br>
<!-- POSTFIX --><span class="h4">Continue</span><br>
<a href="javascript:call_link('abapassign_mem_area.html')" class="blue">ASSIGN - mem_area</a><br>
<a href="javascript:call_link('abapassign_casting.html')" class="blue">ASSIGN - casting_spec</a><br>
<a href="javascript:call_link('abapassign_range.html')" class="blue">ASSIGN - range_spec</a><br>
<br>
<br>
</DIV>
<fieldset style="opacity:0">
<input id="url" type="text" />
</fieldset>
</BODY>
<!-- Mirrored from help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapassign.htm by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 20 Jan 2022 17:39:29 GMT -->
</html>