Skip to Content

Update a database table dynamically

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>.
Add a comment
10|10000 characters needed characters exceeded

  • 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

  • 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

  • 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

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Aug 31 at 05:10 PM
    -1

    Can u check if any entry exists with the specified key field in the database? sy-subrc 4 will usually come if no entry is available in the data base with the specified primary key

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.