2009 Sep 21 8:28 AM
HI ALL ,
I have functionality which i want to update some data but alwayes just one or more fields if somethig was cahged i.e.
if i have structure on the with
userid 1234
name Jhon
language EN
timezone UTC
adress Australia
mail www.sdn.com...and in this structure i want to update just the language or other fields how i can do so
the language is just example it can be any fields and can be more then one field for instance
adress and mail .
userid 1234
name Jhon
language DE
timezone UTC
adress Australia
mail www.sdn.com...when i try with modify
MODIFY ms_user FROM ls_user .
i get this error
"MS_USER" is not an internal table "OCCURS n" specification is missing.
but ms_user is in the method signature and type data base structure from se 11 .
how can solve this issue , i try also with update but noting ...
Thanks
Nina
Edited by: Nina C on Sep 21, 2009 9:28 AM
2009 Sep 21 8:33 AM
Hi,
if you only use a structure you can simly do this:
wa_struc-language = 'DE'.
wa_struc i your structurename.
Regards, Dieter
If you want to update only the changed fields, you will need to compare each field (old vs. new value).
This example should give you an idea to work with.
DATA: wa_mara_old TYPE mara,
wa_mara_new TYPE mara.
FIELD-SYMBOLS: <fs_old> TYPE any,
<fs_new> TYPE any.
SELECT * INTO wa_mara_old
FROM mara
UP TO 1 ROWS.
ENDSELECT.
wa_mara_new = wa_mara_old.
wa_mara_new-ersda = sy-datum.
write: / 'MARA old ersda', wa_mara_old-ersda.
write: / 'MARA new ersda', wa_mara_new-ersda.
uline.
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_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
ENDDO.
write: / 'MARA old ersda', wa_mara_old-ersda.
write: / 'MARA new ersda', wa_mara_new-ersda.This only works if both structures have the same definition!
2009 Sep 21 8:33 AM
Hi,
if you only use a structure you can simly do this:
wa_struc-language = 'DE'.
wa_struc i your structurename.
Regards, Dieter
2009 Sep 21 8:41 AM
Hi Dieter Gröhn ,
thanks but This is not my question ,
i want to update structure from other structure and i don't know which fields gonna be changed and i don't want to touch the fields that not changed so
how i can do so ?
Thanks
Nina
2009 Sep 21 8:43 AM
if the two structure are of same type:
then just use:
ws_ma = ls_ma.
if they are not same,
you need to use
MOVE-CORRESPONDING gs_wa to ms_wa.
2009 Sep 21 8:47 AM
2009 Sep 21 9:06 AM
Hi Dieter Gröhn ,
it's not that simple ,
the problem is i am on update process ( i get structure with data ) and i do select singe from the DB to another structure (read before update ) and after i do some compering with the structure fields if somethig is diffrent
I can get for instance the fields to update (just userid is the key)
userid 1234
name Jhon
language EN
timezone
adress USA
and in the DB i have
userid 1234
name Jhon
language DE
timezone UTC
adress Australia
mail www.sdn.com.
i dont want to overwrite the field that already exist i just want to update the fields that i get for update and dont touch the other fields ?
Regards
Nina
Edited by: Nina C on Sep 21, 2009 10:11 AM
2009 Sep 21 9:28 AM
Hi,
Is this what you are looking for?
select single * from db into itab where (any conditions)
loop at MS_USER.
read table itab with key userid = MS_USER-userid.
if sy-subrc = 0.
modify MS_USER from itab.
endif.
endloop.
Regards,
Vikranth
2009 Sep 21 9:38 AM
hI Vikranth,
Thanks but how i can know if one fields is changed language or adress or email ?
Reagrds
Nina
2009 Sep 21 9:38 AM
If you want to update only the changed fields, you will need to compare each field (old vs. new value).
This example should give you an idea to work with.
DATA: wa_mara_old TYPE mara,
wa_mara_new TYPE mara.
FIELD-SYMBOLS: <fs_old> TYPE any,
<fs_new> TYPE any.
SELECT * INTO wa_mara_old
FROM mara
UP TO 1 ROWS.
ENDSELECT.
wa_mara_new = wa_mara_old.
wa_mara_new-ersda = sy-datum.
write: / 'MARA old ersda', wa_mara_old-ersda.
write: / 'MARA new ersda', wa_mara_new-ersda.
uline.
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_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
ENDDO.
write: / 'MARA old ersda', wa_mara_old-ersda.
write: / 'MARA new ersda', wa_mara_new-ersda.This only works if both structures have the same definition!
2009 Sep 21 9:53 AM
Hi
you must compare field by field.
You can do it like this:
TABLES: MARA.
FIELD-SYMBOLS: <FS_OLD>, <FS_NEW>.
DATA: STRU_OLD TYPE MARA.
DATA: STRU_NEW TYPE MARA.
*
START-OF-SELECTION.
*
SELECT SINGLE * FROM MARA.
*
STRU_OLD = MARA.
STRU_NEW = MARA.
*
STRU_NEW-BISMT = 'newvaulue'.
* Now the structures are different.
*
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 <> 0. EXIT. ENDIF.
IF <FS_OLD> <> <FS_NEW>.
<FS_OLD> = <FS_NEW>.
ENDIF.
ENDDO.
*
END-OF-SELECTION.
Regards, Dieter
2009 Sep 21 10:04 AM
Hi,
You can just use the simple assignment to check if there is any change in the fields.
For eg,
select single * from db into itab where (any conditions)
loop at MS_USER.
read table itab with key userid = MS_USER-userid.
if sy-subrc = 0.
if MS_USER NE itab. "Comparing the header items of both the internal tables.
modify MS_USER from itab. "Modify only if there is any change in the fields
endif.
endif.
endloop.
Regards,
Vikranth
2009 Sep 21 10:16 AM
HI Dieter ,
The problem is that the when one fields are equal the going to the exit
and not compare all other fields why ?
Regards
Nina
2009 Sep 21 10:24 AM
Hi,
do you set the DO - loop like i have mentioned?
The exit will be executed if the assign gets an error, because there isn't an structure field.
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>.
* here the exit
IF SY-SUBRC 0. EXIT. ENDIF.
*
IF <FS_OLD> <FS_NEW>.
<FS_OLD> = <FS_NEW>.
ENDIF.
ENDDO.
regards, Dieter
Edited by: Dieter Gröhn on Sep 21, 2009 11:25 AM
2009 Sep 21 10:30 AM
Thanks ,
i try your code and its not working ,
basically what i expect is at the end wa_mara_new will have the old fields that are not
changed and the new fields that change and with all this field i can update the DB .
but its not working like that .
Regards
Nina
2009 Sep 21 10:44 AM
Thanks ,
i try your code and its not working ,
baisicliy what i expect is at the end STRU_OLD will have the old fields that are not
changed and the new fields that change and with all this field i can update the DB
Regards
Nina
2009 Sep 21 10:44 AM
Thanks ,
i try your code and its not working ,
baisicliy what i expect is at the end STRU_OLD will have the old fields that are not
changed and the new fields that change and with all this field i can update the DB
Regards
Nina
2009 Sep 21 10:48 AM
2009 Sep 21 12:16 PM
hi Dieter ,
the logic is exactly like u write but its not working
Thanks Nina
2009 Sep 21 12:23 PM
Hi,
i don't where is the mistake, it's really better to show the code.
Regards, Dieter
2009 Sep 21 12:44 PM
HI Dieter,
The program is exactly like this :
please see that the new structure is coming with just 2 fields to update
i want that all other fields that are don't need to update also be in new structure include the new one .
TABLES: sflight.
FIELD-SYMBOLS: <fs_old>, <fs_new>.
DATA: stru_old TYPE sflight.
DATA: stru_new TYPE sflight.
*
START-OF-SELECTION.
*
SELECT SINGLE * FROM sflight INTO stru_old.
stru_new-planetype = 'newvaulue'.
stru_new-price = 1.
Now the structures are different.
*
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_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
ENDDO.
CHECK sy-subrc = 0.
thanks for your time
regards
Nina
*
2009 Sep 21 12:55 PM
Hi Nina
change you code like this:
TABLES: sflight.
FIELD-SYMBOLS: <fs_old>, <fs_new>.
DATA: stru_old TYPE sflight.
DATA: stru_new TYPE sflight.
*
START-OF-SELECTION.
*
SELECT SINGLE * FROM sflight INTO stru_old.
please insert this line before you change stru_new
stru_new = stru_old.
stru_new-planetype = 'newvaulue'.
stru_new-price = 1.
Now the structures are different.
*
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_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
ENDDO.
CHECK sy-subrc = 0.
Regards, Dieter
2009 Sep 21 1:13 PM
Hi
my code is like this :
the stru_new is coming with new fields before the select
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.
please insert this line before you change stru_new
*
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_old> NE <fs_new>.
<fs_old> = <fs_new>.
ENDIF.
ENDDO.
Regards
Nina
2009 Sep 21 1:20 PM
Hi,
Why did you first post another code?
What about the other fields of str_new? are they inital?
Why don't you post the real whole code?
Regards, Dieter
2009 Sep 21 1:33 PM
HI Dieter ,
this is really complex code with lot of methods (and it's not mine ;( ) ,
what i write in the last post this is exactly the same logic which i need to develop
the fields in the new structure coming to the method form other method (doing select ...) .in the code example
i need to update the data on the new structure with the fields form the old structure but not
touch the new fields that was in the new structure .
I know that my request is little bit complex to do without a spaghetti code ,
do u have an idea please ?
Regards
Nina
maybe this message are little bit confused i open new one for this issue
Thanks any way .
Edited by: Nina C on Sep 21, 2009 3:00 PM
Edited by: Nina C on Sep 21, 2009 3:15 PM
2009 Sep 21 2:21 PM
Hi Nina,
here an example where can change the values by knowing the fieldnames:
TABLES: MARA.
FIELD-SYMBOLS: <FS_OLD>, <FS_NEW>.
DATA: STRU_OLD TYPE MARA.
DATA: STRU_NEW TYPE MARA.
*
DATA: GO_STRUCT TYPE REF TO CL_ABAP_STRUCTDESCR,
GT_COMP TYPE ABAP_COMPDESCR_TAB,
GS_COMP TYPE ABAP_COMPDESCR.
START-OF-SELECTION.
*
SELECT SINGLE * FROM MARA.
*
STRU_OLD = MARA.
*
STRU_NEW-ZEINR = 'NewZEINR'.
STRU_NEW-BISMT = 'NewBISMT'.
*
GO_STRUCT ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( 'MARA' ).
GT_COMP[] = GO_STRUCT->COMPONENTS[].
*
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 <> 0. EXIT. ENDIF.
READ TABLE GT_COMP INDEX SY-INDEX INTO GS_COMP.
IF GS_COMP-NAME <> 'BISMT' AND GS_COMP-NAME <> 'ZEINR'.
<FS_NEW> = <FS_OLD>.
ENDIF.
ENDDO.
*
Hope it helps.
regards, Dieter
2009 Sep 21 2:43 PM
hi Dieter
THANKS ,
I try it and it's close but stil dont work ,
i'll open a new post and try to explain myself better i think this is my fault .
Hope u can help there to
best Regards and thanks again
Nina
2009 Sep 21 8:38 AM
Hi,
Try using the transporting option of the modify statment.
MODIFY ms_user FROM ls_user transporting language.
Regards,
Vikranth
2009 Sep 21 8:43 AM
hi
thanks but the language is just example
it can be any other fields so what is the best way to handle it ?
the problem is that i don't know which fields is chanced
Regards
Nina
Edited by: Nina C on Sep 21, 2009 9:44 AM
2009 Sep 21 8:41 AM
as its a structure, no need of MODIFY. modify is for tables.
you can simply use :
ms_user-language = 'DE'.
this wont change anything else except the language.. other fields will be there as usual..
2009 Sep 21 9:01 AM
Hi,
If MS_USER is the original structure name, declare a reference structure and modify it.
data: it_ms_user type standard table of ms_user with header line.
loop at it_ms_user.
move-corresponding ls_user to it_ms_user.
modify it_ms_user.
endloop.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |