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

Difference between Writeto and Move

Former Member
0 Likes
1,514

Hi Experts,

Can any one tell me the differnce between writeto and move statements,thanks in advance.

Regards,

Swrana.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,158

Hello Swarna-

Find below the differnece between both statements with example.

data:v_p(16) type p decimals 2 ,

v_c(16) type c.

v_p = 123456.

move v_p to v_c.

write v_p to v_c.

The output for move will be 1234.56

The output for write to will be 1234,56.

The differnce is move will not change the target data type only moves the value whereas write to converts the datatype in the target field dynamically.

Cheers,

~Srini...

7 REPLIES 7
Read only

Former Member
0 Likes
1,158

MOVE converts the value of the source field into the data type of the target field,WRITE TO converts the contents of the source field into a field with type C.

Read only

Former Member
0 Likes
1,158

Hi,

MOVE- is used to copy entire contents of one table into another in one execution

Syntax

MOVE <itab1> To <itab2>.

OR

<itab1> = <itab2>.

Note:

Copies the entire contents of one table into another in one execution.

Original data in target table overwritten.

For tables with header line use [] to distinguish it from work area since both have the same name.

Syntax

MOVE-CORRESPONDING <itab1> TO <itab2>.. - Executes the statement for their header lines. Searches for the sub-fields which occur both in itab1 and itab2 and

then generates, for all relevant field pairs which correspond to the

sub-fields ni , statements of the form MOVE itab1-ni TO itab2-ni. The other fields remain unchanged.

WRITE TO statement-

WRITE <f1> TO <f2> [<format>].

Converts the contents of a data object <f1> to type C, and assigns the resulting string to the variable <f2>. You can use the same formatting options available in the WRITE statement

Read the write to statement as well..

Thanks

PLz reward points if useful

Edited by: Malvika Sharma on May 29, 2008 7:42 AM

Edited by: Malvika Sharma on May 29, 2008 7:47 AM

Edited by: Malvika Sharma on May 29, 2008 7:48 AM

Read only

Former Member
0 Likes
1,158

Hi swarna,

1. This can be best understood with one example.

suppose we have two variables.:

data : datum type sy-datum.

data : var (15) type c.

suppose datum contains the date 29-may-2008

so it will contain the value in YYYYMMDD format.

ie. 20080529

2. Now

Move datum to var : then var will contain 20080529

Write datum into var: then var will contain 29.05.2008

3.

So WRITE will put the data

in the format it will normally display, in the users format.

regards,

amit m.

Read only

Former Member
0 Likes
1,158

hi,

Assigns the contents of the source field f to the target field

g as a new value.

In contrast to MOVE, the format of the target field g is the

same as when outputting to a list with WRITE. The field type C

is always used, regardless of the actual data type.

In case of write to , Other formatting options are also possible with list output.

In case of write to ,Instead of specifying a static source field f, you can make adynamic source field specification (name). In this case, the contents of the field name is interpreted as the source field name at runtime and the contents are formatted accordingly.

Read only

Former Member
0 Likes
1,158

The statement WRITE TO has the same effect as the statement WRITE for lists. This statement formats the content of source or the source field specified in source_name as described in the field. It does not, however, store the result in an output area of a list in the list buffer, but instead stores it in a variable. The output length is determined by the length of the variable.

move statement will move the record .....

if it is usefull Plz Rewards

Regards

Anbu

Read only

Former Member
0 Likes
1,158

Hi swarna,

MOVE f TO g.

Effect

Moves the contents of field f to field g.Field f remains unchanged.

This statement is equivalent to:

g = f.

Write TO

Effect

Assigns the contents of the source field f to thetarget field g as a new value.

In contrast to MOVE, the format of thetarget field g is the same as when outputting to a list withWRITE. The field type C isalways used, regardless of the actual data type.

As with list output, the settings in the user's master record fordecimal point (period or comma) and date format are taken into account.

Other formatting options are also possiblewith list output.

Instead of specifying a static source field f, you can make adynamic source field specification (name). In this case, thecontents of the field name is interpreted as the source fieldname at runtime and the contents are formatted accordingly.

You can identify the target field g more precisely by specifyingthe offset and/or length in the form g+off(len). Both the offsetand the length specifications off and len can also bedynamic.

In the WRITE name TO g variant, the returncode is set as follows:

SY-SUBRC = 0:

Contents of name are valid, statementexecuted.

SY-SUBRC = 4:

Contents of name are invalid, statementcould not be executed, and contents of g remain unchanged.

In other cases, the return code is undefined.

Example

WRITE ... TO with dynamic source fieldspecification and dynamic offset and length specification for thetarget 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 noew contains the value "Robert Harry ith".

Notes

Only values between 0 and the length of the target fieldg are allowed as offset specifications. Any other offsetspecifications result in a runtime error.

Only values >= 0 are allowed as length specifications. Negativelength specifications result in a runtime error. Excessive lengthspecifications are automatically truncated.

If you specify the field length as the offset or the value 0 as thelength, the target field is blank. In this case, the statement has noeffect.

Addition

... option

Effect

Modifies the output format with the aid of specialformatting options.

Variant 2

WRITE f TO itab[+off][(len)] INDEX idx.

Additions like variant 1.

This variant is not allowed in an ABAP Objectscontext. See WRITE TO not allowed withinternal tables.

Effect

Like variant 1, except that output is to the idx-th line of the internal table itab.

Any offset and/or length specifications refer to the table line usedfor output.

The return code is set as follows:

SY-SUBRC = 0:

Valid index specification, i.e. the internal tableitab contains a line with the index idx.

SY-SUBRC = 4:

Index specification is too large, i.e. the internaltable itab contains fewer than idx entries.

Note

Invalid index specifications, i.e. idx <= 0, resultin a runtime error.

Note

The runtime of WRITE ... TO corresponds with that of theWRITE statement. However, considerable extra runtime is requiredif you specify the source field dynamically.

Specifying the target field using offset and length increases theruntime slightly.

WRITE ... TO with a dynamically-specified source field takesaround 40 msn (standardmicroseconds). If you specify the source field statically, the runtimeis around 6 msn, or 8 msn if you specify offset and length.

Thanks,

Sujith

Read only

Former Member
0 Likes
1,159

Hello Swarna-

Find below the differnece between both statements with example.

data:v_p(16) type p decimals 2 ,

v_c(16) type c.

v_p = 123456.

move v_p to v_c.

write v_p to v_c.

The output for move will be 1234.56

The output for write to will be 1234,56.

The differnce is move will not change the target data type only moves the value whereas write to converts the datatype in the target field dynamically.

Cheers,

~Srini...