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

BAPI wrapper

Former Member
0 Likes
1,334

one of my friend wrote a statement

the basic purpose of the bapi is to update the data directly into the database.......and the call transaction is to update the data through the screens (BDC)

another friend say

update should be only done by BDC...this is the norm practising by all the sap abaper

which one is true ?

..........pls advice

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,286

UPDATE/INSERT/MODIFY inside a BAPI is something which is provided by SAP.

When i say direct update, it means we should not create a program and simple write

UPDATE MARA using table itab.

Instead of above statement a suitable BAPI should be used.

The reason is :

When there is version upgrade, SAP modifies the BAPI accordingly & any change in version takes care of changes in BAPI. So we need not explicity change the programs. The programs using BAPI will automatically be taken care of with new version of sap.

11 REPLIES 11
Read only

Former Member
0 Likes
1,286

Hi,

BDC is old technology and doesn't work with a lot of the new SAP Enjoy transactions anyway.

You should always try to use a BAPI to perform an update to data if you can find a suitable one - a BDC is always a last resort and should only be used if there is no other way to update the data.

Gareth.

Read only

0 Likes
1,286

what you mean is direct call the

MODIFY TABLE...

.....

this is direct update....to the table ?

someone say direct update to the table is not encourage by SAP...

Read only

0 Likes
1,286

Hi,

I'm not sure I understand what you are asknig about MODIFY TABLE...

But yes, you should never perform direct updates of standard SAP database tables. BAPI's are created to ensure that when you perform an update, all tables are updated correctly to ensure referential integrity (spelling?!) between tables is maintained. If you wrote ABAP to directly update a field on MARA say, you may cause problems as table MARM should also be updated for example.

So if you wanted to create a Purchase Order in code, you wouldn't simply insert entries into table EKKO, EKPO, etc - instead you would use the function module BAPI_PO_CREATE1 and pass in all data.

I'm pretty sure some standard SAP BAPI's just perform a Call Transaction in the background anyway but it is hidden from you in your code...

Gareth.

Read only

0 Likes
1,286

Meaning inside Bapi we call update statement is not direct update.

It is update thru BAPI.

Read only

0 Likes
1,286

Hi,

Right. No, you wouldn't have a direct update/insert inside a BAPI. Typically, standard BAPI's will have some direct updates buried deep down inside their logic but there is so much else going on it isn't always obvious and there likely to be a lot of calls to other function modules performing small amount of updates to different aspects of the data.

Are you creating a custom BAPI as a wrapper around a standard BAPI by any chance?

Is there a specific piece of data you are trying to update? Someone may be able to give you some more infor around BAPI's for that particular piece of data then.

Also, its worth mentioning that if you are updating custom tables (i.e. Z tables) then it is ok to perform direct manipulation of the database tables as you would know exactly what tables need to be updated to ensure the data is correct.

Possibly the only time it is normal to perform direct manipulation is in a user-exit or BADI when you are adding extra data into an append structure against a standard table.

Gareth.

Read only

0 Likes
1,286

updating asset

anla, anlz , anlh


CHANGE BAPI WRAPPER

FUNCTION zemi_am_p2p_v1.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(AM_DATA) LIKE  ZASTMS STRUCTURE  ZASTMS
*"  EXPORTING
*"     VALUE(RETURN) LIKE  BAPIRET2 STRUCTURE  BAPIRET2
*"  TABLES
*"      AM_DETAILS STRUCTURE  ZASTMS OPTIONAL
*"----------------------------------------------------------------------


  DATA : v_date LIKE sy-datum,
         var1 LIKE  balm-msgv1,
         var2 LIKE  balm-msgv2.

  REFRESH : bdcdata, messtab.
  CLEAR : bdcdata, messtab, v_date.
*v_msg,

  CONCATENATE am_data-anln1 am_data-werks am_data-stort sy-datum sy-uzeit INTO zztable-char100
  SEPARATED BY space.
  INSERT zztable.

  SELECT SINGLE * FROM anla WHERE anln1 = am_data-anln1
                              AND bukrs = '1000'.

  SELECT SINGLE * FROM anlz WHERE anln1 = am_data-anln1
                              AND bukrs = '1000'.

  SELECT SINGLE * FROM anlh WHERE anln1 = am_data-anln1
                              AND bukrs = '1000'.

  CONCATENATE   anla-aktiv+6(02)  anla-aktiv+4(02) anla-aktiv(04) INTO v_date.

call function 'ZBAPI_AM_P2P'
   exporting
     v_anln    = anla-anln1
     v_stort   = am_data-stort
      v_txt50   = anla-txt50
      v_anlhtxt = anlh-anlhtxt
      v_kostl   = anlz-kostl
      v_werks   = anlz-werks
      v_date    = v_date.
*    importing
*v_msg     = v_msg.

  APPEND am_data TO am_details.


ENDFUNCTION.







FUNCTION zbapi_am_p2p.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(V_ANLN) LIKE  ANLA-ANLN1 OPTIONAL
*"     VALUE(V_STORT) LIKE  ANLZ-STORT OPTIONAL
*"     VALUE(V_TXT50) LIKE  ANLA-TXT50 OPTIONAL
*"     VALUE(V_ANLHTXT) LIKE  ANLH-ANLHTXT OPTIONAL
*"     VALUE(V_KOSTL) LIKE  ANLZ-KOSTL OPTIONAL
*"     VALUE(V_WERKS) LIKE  ANLZ-WERKS OPTIONAL
*"     VALUE(V_DATE) LIKE  SY-DATUM OPTIONAL
*"  EXPORTING
*"     VALUE(V_MSG) TYPE  STRING
*"----------------------------------------------------------------------

  DATA :  var1 LIKE  balm-msgv1,
          var2 LIKE  balm-msgv2.

  PERFORM open_group.

  PERFORM bdc_dynpro      USING 'SAPLAIST' '0100'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=MAST'.
  PERFORM bdc_field       USING 'ANLA-ANLN1' v_anln.
  PERFORM bdc_field       USING 'ANLA-ANLN2' '0'.
  PERFORM bdc_field       USING 'ANLA-BUKRS' '1000'.

  PERFORM bdc_dynpro      USING 'SAPLAIST' '1000'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=TAB02'.
  PERFORM bdc_field       USING 'ANLA-TXT50' v_txt50.
  PERFORM bdc_field       USING 'ANLH-ANLHTXT' v_anlhtxt.
  PERFORM bdc_field       USING 'ANLA-AKTIV' v_date.

  PERFORM bdc_dynpro      USING 'SAPLAIST' '1000'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=BUCH'.
  PERFORM bdc_field       USING 'ANLZ-KOSTL' v_kostl.
  PERFORM bdc_field       USING 'ANLZ-WERKS' v_werks.
  PERFORM bdc_field       USING 'ANLZ-STORT' v_stort.

  PERFORM bdc_dynpro      USING 'SAPLAIST' '3020'.
  PERFORM bdc_field       USING 'BDC_OKCODE' '=YES'.


  CALL TRANSACTION 'AS02' USING bdcdata MODE 'N'
                                        UPDATE 'S'
                                        MESSAGES INTO messtab.

  PERFORM close_group.

  READ TABLE messtab INDEX 1.
  MOVE messtab-msgv1 TO var1.
  MOVE messtab-msgv2 TO var2.


  CLEAR v_msg.
  CALL FUNCTION 'MESSAGE_PREPARE'
       EXPORTING
           language               = 'E'
            msg_id                 = messtab-msgid
            msg_no                 = messtab-msgnr
            msg_var1               = var1
            msg_var2               = var2
*         MSG_VAR3               = ' '
*         MSG_VAR4               = ' '
      IMPORTING
           msg_text               = v_msg
       EXCEPTIONS
            function_not_completed = 1
            message_not_found      = 2
            OTHERS                 = 3.


ENDFUNCTION.

Message was edited by:

yzme yzme

....................

Message was edited by:

yzme yzme

Read only

0 Likes
1,286

Hi yzme,

I'm not familiar with assets and updating them so can't suggest a BAPI to use. Have you looked through transaction BAPI to see if there is something suitable? Or searched on here to see if someone else has suggested one before?

Your code looks ok to be honest - you've used BDC which isn't great and as has already been mentioned isn't the recommended way but if you can't find a standard update function module then you may have no other choice.

Gareth.

Read only

0 Likes
1,286

thanks for suggestion....

try hard to find one

Read only

Former Member
0 Likes
1,286

Hi,

Direct update to SAP Standard table is a strict NO & not recommended by SAP. SAP has provided several BAPI's to update standard SAP tables. So those BAPI's should be used.

BDC is also not recommended by SAP bcz it doesnt support when you upgrade your SAP Version. Instead of BDC go for BAPI's

Best regards,

Prashant

Read only

Former Member
0 Likes
1,289

UPDATE/INSERT/MODIFY inside a BAPI is something which is provided by SAP.

When i say direct update, it means we should not create a program and simple write

UPDATE MARA using table itab.

Instead of above statement a suitable BAPI should be used.

The reason is :

When there is version upgrade, SAP modifies the BAPI accordingly & any change in version takes care of changes in BAPI. So we need not explicity change the programs. The programs using BAPI will automatically be taken care of with new version of sap.

Read only

0 Likes
1,286

very clear.....thanks.....at least get a fundamental concept..........