01-16-2008 2:28 AM
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
01-16-2008 2:37 AM
01-16-2008 2:41 AM
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
01-16-2008 5:04 PM
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.
01-17-2008 11:32 PM
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
01-16-2008 3:18 AM
Hi Dan,
use the 'move corresponding' statement which will copy only certain fields of ur table to another.
cheers,
hema.
01-16-2008 3:20 AM
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.