Skip to Content
author's profile photo Former Member
Former Member

Inserting records into Custom table

Hi Friends,

I have created a custom table without table maintainence. I need to insert records into this custom table using abap coding only. When a run a download program an excel file is generated. from that excel file i have to summarise the data and upload the summary to Ztable.

Problem is am getting 3 records in summary but only one record is updated into Ztable. Some times total 3 records updated. i dont understand this strange behaviour.

FORM f_update_report_log.

  • Report log: sum of Document currency Amt & local currency Amt

  • for all document currency keys

SORT it_data BY waers.

LOOP AT it_data.

ON CHANGE OF it_data-waers.

IF sy-tabix NE 1.

zdmaplog-dmdate = sy-datum.

zdmaplog-dmtime = sy-uzeit.

zdmaplog-dmtyp = 'D'.

zdmaplog-sbukrs = p_bukrs.

zdmaplog-tbukrs = p_bukrst.

zdmaplog-items = v_lines.

zdmaplog-wrbtr = v_wrbtr.

zdmaplog-dwaers = v_waers.

zdmaplog-dmbtr = v_dmbtr.

zdmaplog-lwaers = 'SGD'.

zdmaplog-userid = sy-uname.

  • update db table zdmaplog

INSERT zdmaplog.

v_subrc = sy-subrc.

COMMIT WORK AND WAIT.

IF v_subrc NE 0.

WRITE: / v_waers, 'Zdmaplog not updated'.

ENDIF.

CLEAR: v_lines, v_wrbtr, v_dmbtr, v_subrc.

ENDIF.

ENDON.

v_waers = it_data-waers.

v_lines = v_lines + 1.

IF it_data-shkzg = 'H'. "credit

v_wrbtr = v_wrbtr - it_data-wrbtr.

v_dmbtr = v_dmbtr - it_data-dmbtr.

ELSEIF it_data-shkzg = 'S'. "Debit

v_wrbtr = v_wrbtr + it_data-wrbtr.

v_dmbtr = v_dmbtr + it_data-dmbtr.

ENDIF.

ENDLOOP.

  • update DB table zdmaplog

zdmaplog-dmdate = sy-datum.

zdmaplog-dmtime = sy-uzeit.

zdmaplog-dmtyp = 'D'.

zdmaplog-sbukrs = p_bukrs.

zdmaplog-tbukrs = p_bukrst.

zdmaplog-items = v_lines.

zdmaplog-wrbtr = v_wrbtr.

zdmaplog-dwaers = v_waers.

zdmaplog-dmbtr = v_dmbtr.

zdmaplog-lwaers = 'SGD'.

zdmaplog-userid = sy-uname.

INSERT zdmaplog.

v_subrc = sy-subrc.

COMMIT WORK AND WAIT.

IF v_subrc NE 0.

WRITE: / v_waers, 'Zdmaplog not updated'.

ENDIF.

ENDFORM. " f_report_log

Its urgent, please help me. i wil reward good points.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 30, 2008 at 10:38 AM

    Hey Fren,

    Try this....

    FORM f_update_report_log.

    • Report log: sum of Document currency Amt & local currency Amt

    • for all document currency keys

    SORT it_data BY waers.

    LOOP AT it_data.

    AT NEW it_data-waers.

    IF sy-tabix NE 1.

    zdmaplog-dmdate = sy-datum.

    zdmaplog-dmtime = sy-uzeit.

    zdmaplog-dmtyp = 'D'.

    zdmaplog-sbukrs = p_bukrs.

    zdmaplog-tbukrs = p_bukrst.

    zdmaplog-items = v_lines.

    zdmaplog-wrbtr = v_wrbtr.

    zdmaplog-dwaers = v_waers.

    zdmaplog-dmbtr = v_dmbtr.

    zdmaplog-lwaers = 'SGD'.

    zdmaplog-userid = sy-uname.

    • update db table zdmaplog

    MODIFY zdmaplog from zdmaplog.

    v_subrc = sy-subrc.

    COMMIT WORK AND WAIT.

    IF v_subrc NE 0.

    WRITE: / v_waers, 'Zdmaplog not updated'.

    ENDIF.

    CLEAR: v_lines, v_wrbtr, v_dmbtr, v_subrc.

    ENDIF.

    ENDAT.

    v_waers = it_data-waers.

    v_lines = v_lines + 1.

    IF it_data-shkzg = 'H'. "credit

    v_wrbtr = v_wrbtr - it_data-wrbtr.

    v_dmbtr = v_dmbtr - it_data-dmbtr.

    ELSEIF it_data-shkzg = 'S'. "Debit

    v_wrbtr = v_wrbtr + it_data-wrbtr.

    v_dmbtr = v_dmbtr + it_data-dmbtr.

    ENDIF.

    ENDLOOP.

    On Change of and INSERT dbtab are obsolete statements...

    .

    Please dont use it in ur Reports.....

    Thank you..

    Regards,

    Abhinay

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hey Fren,

      Thank you for rewarding....and ofcourse inspiring...

      So,

      Regarding usage of Control Break Statements..

      Its like this..

      SAP stores data internally like the Array.

      for example...

      AT NEW it_data-waers.
      zdmaplog-dmdate = sy-datum.
      zdmaplog-dmtime = sy-uzeit.
      zdmaplog-dmtyp = 'D'.
      zdmaplog-sbukrs = p_bukrs.
      zdmaplog-tbukrs = p_bukrst.
      zdmaplog-items = v_lines.
      zdmaplog-wrbtr = v_wrbtr.
      zdmaplog-dwaers = v_waers.
      zdmaplog-dmbtr = v_dmbtr.
      zdmaplog-lwaers = 'SGD'.
      zdmaplog-userid = sy-uname.
      ENDAT.

      will get stored in single array format internally...

      In the above case,

      the data will be stored as follows,

      -dmdate-dmtime-dmtyp-sbukrs-tbukrs-items-wrbtr-dwaers-dmbtr-lwaers-userid-

      here, the data is stored in digital format... so

      AT NEW statement will compare the previous Array with the current record....

      in this case if u give

      AT NEW dmdate

      ....

      it'll check for the change in ' dmdate ' field....and proceed as per the logic....

      Not necessary to be the first field...if u want the data in this format..

      1 Table_1-Field_A Table_1-Field_B.

      __________________________1 Table_2-Field_A Table_2-Field_B

      __________________________2 Table_2-Field_A Table_2-Field_B

      __________________________3 Table_2-Field_A Table_2-Field_B

      __________________________4 Table_2-Field_A Table_2-Field_B

      2 Table_1-Field_A Table_1-Field_B.

      __________________________1 Table_2-Field_A Table_2-Field_B

      __________________________2 Table_2-Field_A Table_2-Field_B

      __________________________3 Table_2-Field_A Table_2-Field_B

      __________________________4 Table_2-Field_A Table_2-Field_B

      So,

      if u give

      AT NEW sbukrs

      ......

      it'll check for all the fields till ' sbukrs ' ...i e -dmdate-dmtime- dmtyp-sbukrs- if any one field changes AT NEW will be true...

      Mostly we use AT NEW on CHARACTER FIELD TYPES >..

      C N D T

      Inspire if needful..

      Thank you,

      Warm Regards,

      Abhi...

  • author's profile photo Former Member
    Former Member
    Posted on Mar 30, 2008 at 10:41 AM

    Check sy-subrc eq 0. just after your each update statement.

    if its not eq 0, update is getting failed.

    this can happen it the record you want to update is locked by some other program.

    you can use lock object to remove such things.

    create lock objects ( SE11) for the table/s you are using then use it in the program and update / modify your table in side enqueue-Dequeue.

    reward points it helpful.

    Rgs,

    Ashok

    Edited by: Ashok Gupta on Mar 30, 2008 4:12 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 14, 2008 at 04:15 AM

    Thankyou Naga Pavan and Abaper007. I have rewarded you good points.

    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.