Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

reg write statement

Former Member
0 Likes
1,716

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.

18 REPLIES 18
Read only

Former Member
0 Likes
1,692

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

Read only

alex_m
Active Contributor
0 Likes
1,692

Its like assignment.

target = name.

Read only

Former Member
0 Likes
1,692

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

Read only

0 Likes
1,692

The output will be SOURCE not ABAP.

How did you get ABAP as output?

Thanks

Read only

0 Likes
1,692

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?

Read only

0 Likes
1,692

hi

im getting output as ABAP.

Plz type d code and execute it.

Thanks,

Read only

0 Likes
1,692

Sandeep told you already,

using dynamic field source.

It will have ABAP ,so displayed ABAP.

Thanks

Read only

0 Likes
1,692

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.

Read only

Former Member
0 Likes
1,692

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.

Read only

0 Likes
1,692

hi sailaja,

Thanks for ur info.

but i cant understand.plz b clear

thanks,

Read only

0 Likes
1,692

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.

Read only

0 Likes
1,692

Hi,

My heartiest thanks for ur timely help.

ur answer has cleared my doubts.now im clear in that.

So thank u once again

Read only

0 Likes
1,692

Kumar,i guess other than sailaja

chandrasekhar,tushar and sandeep also had given correct answers ,i think they also deserve points.

Thanks

Read only

Former Member
0 Likes
1,692

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

Read only

Former Member
0 Likes
1,692

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.

Read only

Former Member
0 Likes
1,692

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

Read only

Former Member
0 Likes
1,692

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.

Read only

Former Member
0 Likes
1,692

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......