2009 Sep 21 2:44 PM
Hi
i need to update stru new with new and old fieds .
the stru_new is coming with new fields before the select and can have just 2 or 3 fields to update what i want that stru new be like stru old but with the new fields in it .
i.e. if stru new is like
CARRID
CONNID 0000
FLDATE 00000000
PRICE 1.00
CURRENCY
PLANETYPE newvalue
SEATSMAX 0
SEATSOCC 0
PAYMENTSUM 0.00
SEATSMAX_B 0
SEATSOCC_B 0
SEATSMAX_F 0
SEATSOCC_F 0
and sutu old is like
CARRID AC
CONNID 0820
FLDATE 20021220
PRICE 1222.00
CURRENCY CAD
PLANETYPE A330-300
SEATSMAX 320
SEATSOCC 12
PAYMENTSUM 0.00
SEATSMAX_B 20
SEATSOCC_B 1
SEATSMAX_F 0
SEATSOCC_F 0
"i want in the end the stru new be like
CARRID AC
CONNID 0820
FLDATE 20021220
PRICE 1.00"update
CURRENCY CAD
PLANETYPE newvalue"update
SEATSMAX 320
SEATSOCC 12
PAYMENTSUM 0.00
SEATSMAX_B 20
SEATSOCC_B 1
SEATSMAX_F 0
SEATSOCC_F 0the placing on the code is just an example ,
it can be any fields taht change sometims it can be planetype and other time it can be 3 fields
like price seatmax etc
this is sample of the code :
TABLES: sflight.
FIELD-SYMBOLS: <fs_old>, <fs_new>.
DATA: stru_old TYPE sflight.
DATA: stru_new TYPE sflight.
*
START-OF-SELECTION.
stru_new-planetype = 'newvaulue'.
stru_new-price = 1.
***
SELECT SINGLE * FROM sflight INTO stru_old.
Regards
Nina
2009 Sep 21 2:51 PM
There are several approaches.
DATA: wa_mara_old TYPE mara,
wa_mara_new TYPE mara.
FIELD-SYMBOLS: <fs_old> TYPE any,
<fs_new> TYPE any.
clear: wa_mara_old, wa_mara_new.
wa_mara_new-ersda = sy-datum.
SELECT * INTO wa_mara_old
FROM mara
UP TO 1 ROWS.
ENDSELECT.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_old TO <fs_old>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_new TO <fs_new>.
if not <fs_new> is initial.
IF <fs_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
endif.
ENDDO.
wa_mara_new = wa_mara_old.
2009 Sep 21 2:51 PM
There are several approaches.
DATA: wa_mara_old TYPE mara,
wa_mara_new TYPE mara.
FIELD-SYMBOLS: <fs_old> TYPE any,
<fs_new> TYPE any.
clear: wa_mara_old, wa_mara_new.
wa_mara_new-ersda = sy-datum.
SELECT * INTO wa_mara_old
FROM mara
UP TO 1 ROWS.
ENDSELECT.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_old TO <fs_old>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_new TO <fs_new>.
if not <fs_new> is initial.
IF <fs_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
endif.
ENDDO.
wa_mara_new = wa_mara_old.
2009 Sep 21 2:55 PM
Alternatively:
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_old TO <fs_old>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_mara_new TO <fs_new>.
if <fs_new> is initial.
<fs_new> = <fs_old>.
endif.
ENDDO.
2009 Sep 21 3:14 PM
Hi Maen
what is the use for
if <fs_new> is initial. ??
Regards
nina
2009 Sep 21 3:22 PM
2009 Sep 21 3:24 PM
hI
I know what is doing in general but why i need it in the code ?
regards
Nina
2009 Sep 21 3:35 PM
Hi Nina,
i think the problem is which fields of stru_new shell be update by stru_old and which fields of stru_new
shell not be ubdated by stru_old because they have some values.
To identify this you can use initial, or is there another way to check if some fields of stru_new
shell NOT be updated?
Regards, Dieter
2009 Sep 21 3:37 PM
If ASSIGN statement doesn't assign any value to <fs_new> then you want to retrieve the old value for that field.
IF <FS_NEW> IS INITIAL checks the same.
regards,
Aabhas
2009 Sep 21 3:06 PM
Hi Nina,
you can use inital like this:
DO 1000 TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE stru_old TO <fs_old>.
ASSIGN COMPONENT sy-index OF STRUCTURE stru_new TO <fs_new>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF <fs_new> is initial.
<fs_new> = <fs_old>.
ENDIF.
ENDDO.
Hope this will solve your problem.
Regards, Dieter
2009 Sep 21 3:13 PM
I followed your previous query and I have one question. Let us say I declare a UPD_STRUC and move OLD_STRUC to it and then move NEW_STRUC to it, will it(UPD_STRUC) look like the way you want it to look like? Why are trying to figure out individual field changes, when all you want is the old structure take the new values for whatever fields that changed? If I have fields 1, 2, 3, 4 and 5 on this structure and only 2 and 5 changed, how does it matter if I move just those two fields to the UPD_STRUC or all 5 fields to UPD_STRUC. End result will be the way wanted isn't it?