Application Development 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: 

Fill in structure values of a Record

Former Member
0 Kudos

Hi all,

I have two records of same type MSEG.Each are having values for different fields.How to get one composite structure which will have all the values.

My Condtion is to fill in structure values from Record A (only from certain fields) to the same fields in record B.

thanks,

dan

Edited by: Dan cosio on Jan 16, 2008 3:28 AM

6 REPLIES 6

Former Member
0 Kudos

move corresponding

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

There is a number of ways to handle this, maybe the best approach is to have an intermediate structure with only the fields that you want to move, and then use the MOVE-CORRESPONDING to move these values.

Here xmseg is the intermediate structure. aMseg and bMseg have the structure MSEG.




data: begin of xmseg,
          matnr type mseg-matnr,
          werks type mseg-werks,
          lgort type mseg-lgort,
         end of xmseg. 

data: amseg type mseg.
data: bmseg type mseg.

move-corresponding amseg to xmseg.
move-corresponding xmseg to bmseg.

Using this intermediate structure with only the fields that you want to update will ensure that these are the only fields that will be overwritten in BMSEG.

Regards,

Rich Heilman

0 Kudos

Hi Rich

move-corresponding amseg to xmseg , will give xmseg same as amseg and move-corresponding xmseg to bmseg will

overwrite bmseg with amsseg values.

so in the end bmseg will become amseg and bmseg values are lost.And xmseg will be amseg.How to merge into one structure.

thanks,

dan.

0 Kudos

Hi all,

Here's the code that i'm trying to explain.

data : amseg like mseg,

bmseg like mseg.

data : begin of xmseg,

matnr type mseg-matnr,

werks type mseg-werks,

lgort type mseg-lgort,

charg type mseg-charg,

end of xmseg.

amseg-matnr = 'mat1'.

amseg-lgort = 'lgort1'.

bmseg-werks = 'werks'

bmseg-charg = 'charg'.

move-corresponding amseg to xmseg.

*Now the value of xmseg would be like this

  • xmseg-matnr = 'mat1'.

  • xmseg-werks = BLANK.

  • xmseg-lgort = 'lgort1'.

  • xmseg-matnr = BLANK.

move-corresponding xmseg to bmseg.

*Now the value of bmseg would be like this

  • bmseg-matnr = 'mat1'.

  • bmseg-werks = BLANK

  • bmseg-lgort = 'lgort1'.

  • bmseg-charg = BLANK

(original bmseg values are overwriten )

I'm trying to get all values from amseg and bmseg to onse structure of type mseg with all values.

Any help guys....

thanks,

dan

Former Member
0 Kudos

Hi Dan,

use the 'move corresponding' statement which will copy only certain fields of ur table to another.

cheers,

hema.

Former Member
0 Kudos

Hi Dan,

also pls check out this:

Move corresponding statement moves value from one structure to another structure

MOVE-CORRESPONDING struc1 TO struc2.

Structures must be specified for struc1 and struc2. All components with the same name are searched for in struc1 und struc2 and the content of components in struc1 is assigned to the components with the same name in struc2. All other components are not affected.

Nested structures are fully expanded. The names of the components are compared to the lowest common level. For each comp component pair with the same name, the

MOVE struc1-comp TO struc2-comp.

Example

DATA: BEGIN OF struc1,

comp TYPE c LENGTH 1 VALUE 'U',

BEGIN OF struci,

comp1 TYPE c LENGTH 1 VALUE 'V',

BEGIN OF comp2,

col1 TYPE c LENGTH 1 VALUE 'X',

col2 TYPE c LENGTH 1 VALUE 'Y',

END OF comp2,

END OF struci,

END OF struc1.

DATA: BEGIN OF struc2,

BEGIN OF struci,

comp1 TYPE string,

comp2 TYPE string,

comp3 TYPE string,

END OF struci,

END OF struc2.

MOVE-CORRESPONDING struc1 TO struc2.

If you want to pass the data from one internal table to another internal table, then if the structure of both the table will be same then you can assign directly like that

it_tab1 = it_tab2.

or

it_tab1[] = it_tab2.

pls reward if helpful.

cheers,

Hema.