08-31-2020 5:53 PM
Hi ABAP Experts,
Good day!
I have a test code to update a database table dynamically. (Currently, values are in strings since this is only a test code and my actual code is in a class. Unfortunately, I am unable to test it as I am still missing some logic.). My problem here is I actually see the correct values in <ls_hyper_update_log> that will be used to update the database table. However, the update statement returns a sy-subrc of 4, which means table was not updated. May you please check on what's wrong with the below code? Thank you very much.
Regards,
Katherine Darunday
FIELD-SYMBOLS:
<ls_hyper_update_log> TYPE any,
<ls_update> TYPE any.
DATA:
lv_field1 TYPE /txn/de_hyper_gen_fld_name,
lv_field2 TYPE /txn/de_hyper_gen_fld_name,
lv_field3 TYPE /txn/de_hyper_gen_fld_name,
lv_field4 TYPE /txn/de_hyper_gen_fld_name,
lv_field5 TYPE /txn/de_hyper_gen_fld_name,
im_field_1 type CHAR20,
im_field_2 type CHAR20,
im_field_3 type CHAR20,
im_field_4 type CHAR20,
im_field_5 type CHAR20,
DATA: DYN_WA TYPE REF TO DATA.
CREATE DATA DYN_WA TYPE /txn/t_hyper_log.
ASSIGN DYN_WA->* TO <ls_hyper_update_log>.
lv_field1 = 'HYPER_TEAM'. "im_s_hyper_tsk-field_name1.
lv_field2 = 'HYPER_TASK'. "im_s_hyper_tsk-field_name2.
lv_field3 = 'TASK_CLASS'. "im_s_hyper_tsk-field_name3.
lv_field4 = 'MONI_DATE'. ".m_s_hyper_tsk-field_name4.
lv_field5 = 'MONI_TIME'. "im_s_hyper_tsk-field_name5.
im_field_1 = 'LOGISTICS'.
im_field_2 = 'DYNAMIC'.
im_field_3 = 'TEST'.
im_field_4 = SY-DATUM.
im_field_5 = SY-UZEIT.
ASSIGN COMPONENT lv_field1 OF STRUCTURE <ls_hyper_update_log> TO <ls_update>.
IF sy-subrc EQ 0.
<ls_update> = im_field_1.
ENDIF.
ASSIGN COMPONENT lv_field2 OF STRUCTURE <ls_hyper_update_log> TO <ls_update>.
IF sy-subrc EQ 0.
<ls_update> = im_field_2.
ENDIF.
ASSIGN COMPONENT lv_field3 OF STRUCTURE <ls_hyper_update_log> TO <ls_update>.
IF sy-subrc EQ 0.
<ls_update> = im_field_3.
ENDIF.
ASSIGN COMPONENT lv_field4 OF STRUCTURE <ls_hyper_update_log> TO <ls_update>.
IF sy-subrc EQ 0.
<ls_update> = im_field_4.
ENDIF.
ASSIGN COMPONENT lv_field5 OF STRUCTURE <ls_hyper_update_log> TO <ls_update>.
IF sy-subrc EQ 0.
<ls_update> = im_field_5.
ENDIF.
UPDATE /txn/t_hyper_log FROM <ls_hyper_update_log>.
08-31-2020 6:10 PM
08-31-2020 6:05 PM
It means that there's no line in the database table for the key fields in <ls_hyper_update_log>, or the update is impossible because the table has one or more unique indexes and the values would make a duplicate key for these indexes.
See ABAP doc: UPDATE
08-31-2020 6:10 PM
09-01-2020 5:55 AM
Hi Sandra,
Yes, I know meaning of sy-subrc 4 in Update statement. The table I am trying to update is actually new and only has one entry. The values I am trying to insert have different primary keys with that of the existing entry. Which is why I was wondering why sy-subrc is being encountered.
Thank you.
Regards,
Kath
09-01-2020 6:09 AM
Hi Sandra,
"It means that there's no line in the database table for the key fields in <ls_hyper_update_log>"
Thank you very much for this. I just realized I should have used insert since it's a new entry and will not update any lines in the database table.I am now able to insert the new entry.
Again, thanks for the assistance.
Regards,
Kath