Application Development 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: 

Important points to be cautios of when updating a standard table

Former Member
0 Kudos

Dear SDNers,

Based on the check on the selection screen for the field xerwrt, I am using the below code to modify/update the contents of the standard table ANLA.

meaning:

If the user selects the check for the field xerwrt, then the corresponding field of the record from the table ANLA has to get updated with a check(yes) too.

Kindly let me know what are the things that i need to be cautions of since i am updating the standard table ANLA.

REPORT ZAUPDATE_MEMO_VALUE .
*TABLE Declarations*
TABLES : ANLA.
 
*Internal table declarations
DATA: W_ANLA LIKE ANLA.
 
*Selection Screen*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_BUKRS LIKE ANLA-BUKRS OBLIGATORY,
            P_ANLN1 LIKE ANLA-ANLN1 OBLIGATORY,
            P_ANLN2 LIKE ANLA-ANLN2 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK BLK1.
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-002.
PARAMETERS: P_XERWRT LIKE ANLA-XERWRT.
SELECTION-SCREEN END OF BLOCK BLK2.
 
*at selection-screen.
AT SELECTION-SCREEN.
  SELECT SINGLE *
                FROM ANLA INTO W_ANLA
                WHERE BUKRS = P_BUKRS
                AND ANLN1 = P_ANLN1
                AND ANLN2 = P_ANLN2.
  IF NOT SY-SUBRC IS INITIAL.
    MESSAGE E001(ZZ)."No data found for search criteria
  ENDIF.
 
  IF P_XERWRT = 'X'.
    W_ANLA-XERWRT = 'X'.
    UPDATE ANLA FROM W_ANLA .
    CLEAR W_ANLA.
     ENDIF.

Regards,

SuryaD.

15 REPLIES 15

Former Member
0 Kudos

Hello,

What I clearly miss in your code is a logical lock (enqueue).

This prevents another user via a standard SAP transaction to modify the same record.

It also prevents your program to overwrite data from a user that is currently editing the same record via a standard transaction.

This should absolutely be added.

Check via SE11 to see which enqueue object you can use.

Examples:

EANLA - Block object for assets table ANLA (via Function Modules ENQUEUE_EANLA and DEQUEUE_EANLA)

Second.

It is always best to search for standard SAP functions or BAPIs to update data in stead of writing the update/insert statements yourself.

Example FM : BAPI_FIXEDASSET_CHANGE

I hope this is usefull.

Wim

0 Kudos

Hi wim,

thanks for your time and response.

I so much over looked that aspect of lock!!!!

Thanks for bringing it to my notice. I will include the same.

In fact this is a small requirement wherein, i had to just write a program with this selection screen and update the field

of ANLA table based on users input/entry on the field "update memo field".


Company code  [       ]
Asset         [       ]
Sub-number    [       ]

check to update memo field check box [ ]     

I will check if there is any bapi or FM available to update the anla table.

Any other inputs/feedback on my code, please correct me.

Regards,

SuryaD.

Edited by: SuryaD on Dec 22, 2009 8:35 PM

Edited by: SuryaD on Dec 22, 2009 8:41 PM

matt
Active Contributor
0 Kudos

Important point is

NEVER write code to update a standard SAP table directly, unless you are a SAP employee of you have SAP's blessing to do so. If your client is asking you to do it, you must warn them that they are violating the terms of their license.

Former Member
0 Kudos

Hi Matt,

Thanks for the caution.

I posted the above and then saw your reply...so replying to you now.

Matt, since this was the standard table, i was sceptical to write the code since it was giving way to change the contents of the standard table so easily and ""this should NOT be the case anytime""

This is a business requirement for which i have been asked to do code so.

by altering the contents of the filed xewrt, they are able to do some posting which otherwise is hindered.

What are the steps that i need to take or communicate as of now.

Kindly guide.

Regards,

SuryaD.

Edited by: SuryaD on Dec 22, 2009 8:43 PM

Former Member
0 Kudos

Hello,

That's exactly the reason why you should try to perform the update via a BAPI.

Then there is nothing to explain.

The BAPI will make sure that you do not create inconsistencies in the database.

It will also check the values that you pass as parameters before performing the update.

There is always a parameter called RETURN that gives you feedback about the update performed by the BAPI

Success.

Wim

Former Member
0 Kudos

Thanks again Wim

I will put this across and lets see what the business has to say.

Regards,

SuryaD.

Edited by: SuryaD on Dec 22, 2009 8:59 PM

0 Kudos

Hello All,

I was also banking on BAPI_FIXEDASSET_CHANGE to do the job. But i donot find any field in the i/p params for the BAPI which modifies the ANLA-XERWRT

Let's see if Matt or Wim can point it out

Cheers,

Suhas

ThomasZloch
Active Contributor
0 Kudos

you should contact your consultant, see SAP note [32901|https://service.sap.com/sap/support/notes/32901]

> 1. In fixed assets with a lower book value, the memo value is deactivated. A field is provided in asset master record XERWRT

> to do this. In the standard system, this field can only be passed on by the asset class at the time when the fixed asset is

> created. To set this indicator later, you must create a separate program which sets the contents of field XERWRT to 'X'. As a

> result, the memo value is deactivated for this fixed asset. You should contact your consultant prior to creating such a

> program.

Thomas

Edited by: Rob Burbank on Dec 22, 2009 1:03 PM

matt
Active Contributor
0 Kudos

>

> Thanks again Wim

> I will put this across and lets see what the business has to say.

>

>

> Regards,

> SuryaD.

>

> Edited by: SuryaD on Dec 22, 2009 8:59 PM

The business may have a requirement for this to be done, but they also have a requirement to have a running non-corrupted system, that is supported by the vendor... at the very least a comprehensive risk analysis should be carried out.

I would expect the decision to be taken somewhere around program management / CIO level.

To Thomas

I love those kind of notes. At least - it helps with the risk analysis!

matt

Former Member
0 Kudos

Hi Thomas and Matt,

Please guide me as to what i am supposed to do now

Thomas, in response to

>To set this indicator later, you must create a separate program which sets the contents of field XERWRT to 'X'. As a result, the memo value is deactivated for this fixed asset. You should contact your consultant prior to creating such a program.

... in response to the marked contents where it says " you must create a separate program which sets the contents of field XERWRT....". the program that i am coding now is what is mentioned in the content marked as code.

Please correct me if i am wrong.

Regards,

SuryaD.

Edited by: SuryaD on Dec 22, 2009 11:10 PM

Edited by: Rob Burbank on Dec 22, 2009 1:06 PM

matt
Active Contributor
0 Kudos

Easy. Tell your line manager your concerns. If he tells you just to get on and do it, then you do what your told. Also get your resumé updated and look for work at a more responsible, ethical company.

0 Kudos

Just loved this reply Matt.

prasenjit_sharma
Active Contributor
0 Kudos

wrong thread.

Edited by: Prasenjit Sharma on Dec 22, 2009 4:12 PM

Former Member
0 Kudos

Hi all,

I guess , you can update that particular filed through a BDC program also. The BDC program will update all relevant tables with out data inconsistencies. After fetching records to be updated ,write code for BDC to update data in no-Dialog mode. Catch the errors and display them. If i am wrong , Please correct me.

Regards,

Ravi.

Former Member
0 Kudos

One more point is that using direct update of databsae table, you will miss the standard functionality which is perfomed intenally (automatically) based on the flag value which you are going to update so check this first and then take decision accordingly.