‎2007 May 22 11:00 AM - last edited on ‎2024 Feb 04 6:17 AM by postmig_api_4
Hi
the below code produes d output as ABAP.
DATA: name(10) TYPE c VALUE 'SOURCE',
source(10) TYPE c VALUE 'ABAP',
target(10) TYPE c.
WRITE (name) TO target.
WRITE target.
what is d logic behind d code?
write (name) to target. what this line of code does?.plz let me know
Thanks in advance.
‎2007 May 22 11:02 AM
varaible 'name' is containg value 'source'.
so the first write statement transfers the vaiable with name 'source' to the variable target.
second write statement writes the variable target.
operator - () acts like referencing operator thats all.
Hope this will solve ur problem..
<b><u>Dont forget to reward all the useful replies</u></b>
Sudheer
‎2007 May 22 11:02 AM
‎2007 May 22 11:03 AM
hi,
its same as this.
DATA: name(10) TYPE c VALUE 'SOURCE',
source(10) TYPE c VALUE 'ABAP',
target(10) TYPE c.
*MOVE name TO target
*target = name.
WRITE (name) TO target.
WRITE target.Rgds
Reshma
‎2007 May 22 11:05 AM
The output will be SOURCE not ABAP.
How did you get ABAP as output?
Thanks
‎2007 May 22 11:12 AM
hi reshma.
*MOVE name TO target
*target = name.
the variable name contains d value source. if v MOVE name to target means,source is moved.then how abap?
‎2007 May 22 11:15 AM
hi
im getting output as ABAP.
Plz type d code and execute it.
Thanks,
‎2007 May 22 11:15 AM
Sandeep told you already,
using dynamic field source.
It will have ABAP ,so displayed ABAP.
Thanks
‎2007 May 22 11:16 AM
When you specify braces (name) , this will hole the value of name which is SOURCE, so the first is equavalent to
WRITE (name) TO target. ===== WRITE SOURCE TO target.
SOURCE contains the value ABAP , so ABAP is moved to target
WRITE target.
‎2007 May 22 11:04 AM
Hi,
whenever we want to write dynamic code, we make use of such statements.
In your case,<b> name</b> can hold the name of any variable by the time it reached the statement.
WRITE (name) TO target.At runtime, the value in the variable name is replaced by (name) when we place the variable in parantheses.
Regards
Sailaja.
‎2007 May 22 11:13 AM
hi sailaja,
Thanks for ur info.
but i cant understand.plz b clear
thanks,
‎2007 May 22 11:21 AM
Hi Kumar,
When we are placing a variable in parantheses, it means that we expect it to be replaced by its value at runtime.
write (name) to target.
At runtime, it is considered as
write source to target.This is because, name is having value 'SOURCE'. So, it got changed as above.
Now, value in source variable is moved to target variable.
Suppose, if we have not used parantheses and directly written the variable.
write name to target.Then value in name variable is moved to target variable.
Regards
Sailaja.
‎2007 May 22 11:26 AM
Hi,
My heartiest thanks for ur timely help.
ur answer has cleared my doubts.now im clear in that.
So thank u once again
‎2007 May 22 11:36 AM
Kumar,i guess other than sailaja
chandrasekhar,tushar and sandeep also had given correct answers ,i think they also deserve points.
Thanks
‎2007 May 22 11:08 AM
Hi,
Here a dynamic source field specification (name) is being used. In this case, the contents of the field name is interpreted as the source field name at runtime and the contents are formatted accordingly.
Thanks
sandeep
Reward if helpful
‎2007 May 22 11:17 AM
hi,
name is the source field which has value SOURCE.
WRITE (name) TO target.
means transferring data from source to target.
so that new value can be loaded to source.
Reward with points if helpful.
‎2007 May 22 11:27 AM
Read this you will get EXACT info..(You will get this info when you press F1 on "Write To " in ABAP editor)
Instead of specifying a static source field f, you can also specify a source field (name) dynamically. In this case, the content of the field name is interpreted as the source field name at runtime. The content of this named field is then formatted accordingly.
You can identify the target field g more precisely by specifying the offset and/or length in the form g+off(len). Both the offset and the length specifications off and len can also be dynamic.
In the WRITE name TO g variant, the return code is set as follows:
SY-SUBRC = 0:
Contents of name are valid, statement executed.
SY-SUBRC = 4:
Contents of name are invalid, statement could not be executed, and contents of g remain unchanged.
In other cases, the return code is undefined.
Example
WRITE ... TO with dynamic source field specification and dynamic offset and length specification for the target field:
DATA: NAME(5) VALUE 'FIELD',
FIELD(5) VALUE 'Harry',
DEST(18) VALUE 'Robert James Smith',
OFF TYPE I,
LEN TYPE I.
OFF = 7.
LEN = 8.
WRITE (NAME) TO DEST+OFF(LEN).
The field DEST now contains the value "Robert Harry ith".
Hope it Helps..Mark if useful
Regards
Tushar Mundlik
‎2007 May 22 11:38 AM
hi kumar,
its just like assignment statement as
target = name or move name target.
the o/p is target : source.
if helpful reward some points.
with regards,
suresh babu aluri.
‎2007 May 22 11:52 AM
Hi!
It is acting as a dereferencing pointer in c language.
As per the result u r getting .......
name is the placeholder for SOURCE name--->SOURCE
source is holding value ABAP
Now analyse the statement
WRITE (name) TO target.
source--Contains----> ABAP
name----Contains---->SOURCE
name refers to source
(name) refers to the content containing in the source address . This concept is called dereferencing in C language.
(name) refers to address source it inturn refers to the content of source ie ABAP.
name source
[SOURCE] [ABAP]
name -- [SOURCE]
(name) -- ([SOURCE]) ([SOURCE]) refers to 'source' ie content of source....ABAP
Therefore (name) becomes ABAP .
Reward points if found useful...
regards......