Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Commit work on table using UPDATE statement not working

Former Member
0 Likes
4,445

I have problem regarding the ABAP update statement. I am using the 'Commit work' on one update table statement but it is not working properly sometime it is work and sometime it is not work.

Check the statements :


UPDATE mara

     SET

          zzmanu = wa-sales_data2-zzmanu

          zzmatnr_sf = wa-sales_data2-zzmatnr_sf

     WHERE matnr = wa-basic_data1-matnr.

if sy-subrc eq 0.

commit work.

wait up to 2 seconds.

ENDIF.

Will that above Commit work causing any problem or what is the reason it is not updating table. Please give some suggestion in this case.

8 REPLIES 8
Read only

former_member184158
Active Contributor
0 Likes
2,418

Hello Samith,

firstly, you are not allowed to update sap table with this way, it is really dangerous, you can use BAPI, even if you have custom-fields. SAP provides BAPI to update also your  Zfields.

Any how, if you want update table why you don't use work area, or table

update mara from wa_mara,

or updata mara from table lt_mara.

as I have mentioned, try to use BAPI for this action.

Regards

Ebrahim

Read only

0 Likes
2,418

Hi Ebrahim Hatem,

Thank you for your reply. if there any BAPI for update z fields and how to do it please explain.

Thank you.

BR,

Samith Peiris,

Read only

0 Likes
2,418

Hi Samith,

You can use the BAPI : BAPI_MATERIAL_SAVEDATA to update the material master. Populate the custom fields in the extension parameter.


bapi extension problem | SCN

Thanks,

Karthikeyan

Read only

0 Likes
2,418

Hi Samith

of course there is BAPI "BAPI_MATERIAL_SAVEDATA" and tables, you have to use EXTENSIONIN to refer to your custom fields, for more information, just read the document of this BAPI.

This will help you in the future how you can update custom field in SAP-Table.

if the customer has custom fields in AUFK, or MARA, and you want to use BAPI to update the table, you can not update the custom fields until you use this structure( EXTENSIONIN ) wihch refers to your custom fields

     CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

        EXPORTING

          headdata                   = BAPIMATHEAD

          CLIENTDATA                 = BAPI_MARA

          CLIENTDATAX                = BAPI_MARAX

          PLANTDATA                  = BAPI_MARc

          PLANTDATAX                 = BAPI_MARcx

       IMPORTING

         RETURN                      = IT_RETURN2

       TABLES

          MATERIALDESCRIPTION        = IT_MATERIALDESC

          EXTENSIONIN                = IT_BAPIPAREX

          EXTENSIONINX               = IT_BAPIPAREXX.

Regards

Ebrahim

Read only

0 Likes
2,418

Thank you for details.

but I'm stuck on this, I put the "EXTENSIONIN" and "EXTENSIONINX" to " BAPI_MATERIAL_SAVEDATA" this is filled like this

DATA : ls_bapi_te_mara TYPE bapi_te_mara.

   DATA : ls_bapi_te_marax TYPE bapi_te_marax.

ls_bapi_te_mara-material  = 'NL01IOBK1-012XA21'

ls_bapi_te_mara-ZZMANU = '0000002020'.

ls_bapi_te_mara-ZZMATNR_SF = .....


ls_bapi_te_marax-material  = 'NL01IOBK1-012XA21'

ls_bapi_te_marax-ZZMANU = 'X'.

ls_bapi_te_marax-ZZMATNR_SF = 'X'.

EXTENSIONIN-structure         = 'BAPI_TE_MARA'.

extensionin-valuepart1        = ls_bapi_te_mara.

EXTENSIONIN-valuepart1+0(18= ls_bapi_te_mara-material.

extensionin-valuepart1+18(10= ls_bapi_te_mara-ZZMANU.

extensionin-valuepart1  = ls_bapi_te_mara-ZZMATNR_SF.

APPEND ls_bapi_te_mara to extensionin.

EXTENSIONINX-structure         = 'BAPI_TE_MARAX'.

extensioninx-valuepart1        = ls_bapi_te_marax.

EXTENSIONINX-valuepart1+0(18= ls_bapi_te_mara-material.

extensioninx-valuepart1+18(10= ls_bapi_te_marax-ZZMANU

extensioninx-valuepart1  = ls_bapi_te_marax-ZZMATNR_SF.

APPEND ls_bapi_te_marax to extensioninx.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

     EXPORTING

     .......

    

     IMPORTING

       ...

     TABLES

     ....

       extensionin          = extensionin.

       extensioninx         = extensioninx.


WRITE /: headdata-material, ' - 'p_return-message.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      wait          = 'X'

*   IMPORTING

*     RETURN        =

             .



READ TABLE returnmessages WITH KEY type = 'E' TRANSPORTING NO FIELDS.

   IF sy-subrc <> 0.


ENDIF.





But this material not update z fields.


And "Assign Fields to Field Selection Groups" are configured correctly.









Read only

SwadhinGhatuary
Active Contributor
0 Likes
2,418

Hi Samith,

Code wise everything is well and good .

just put  a break point in sy-subrc check and check the value of SY-DBCNT this say no of record impacted for that open SQL if this is 1 then  1record is changed and if 0 then no record changed.

have a look what is the SY-DBCNT values for this Update.

Read only

former_member184158
Active Contributor
0 Likes
2,418

Hi Samith,

try to refer to this post, may it help you.

BAPI_MATERIAL_SAVEDATA with custom z-fields | SCN

Regards

Ebrahim

Read only

Former Member
0 Likes
2,418

If sy-subrc = 0, then the commit will work, but you haven't checked if it is not 0. So it's not the commit that's not working, it's the update.

MATNR has a conversion exit. You'll probably find that the data you are passing is missing leading zeroes or something like that.

Rob