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

How to use a BAPI

Former Member
0 Likes
764

Hi experts,

I am asked to use the BAPI --> BAPI_SALESORDER_CHANGE to change the sales order line item. I am new to BAPI. i dont know what to do and how to proceed. Can you please give me some idea how to start with it.

If you have any sample codes, can you please post it so that it could help me..

POINTS PROMISED.

Regards,

Buvana

Hi experts,

I am asked to use the BAPI --> BAPI_SALESORDER_CHANGE to change the sales order line item. I am new to BAPI. i dont know what to do and how to proceed. Can you please give me some idea how to start with it.

If you have any sample codes, can you please post it so that it could help me..

POINTS PROMISED.

Regards,

Buvana

3 REPLIES 3
Read only

Former Member
0 Likes
731

Hi Buvana,

Check this info.

The steps to be followed are :

1. Find out the relevant BAPI (BAPI_SALESORDER_CHANGE for VA02).

[for VA01 use BAPI_SALESORDER_CREATEFROMDAT2]

2. Create a Z program and call the BAPi (same as a Funtion module call).

2. Now, if you see this BAPi, it has

-> Importing structures.

eg: SALESDOCUMENT: this will take the Sales order header data as input.

-> Tables parameters:

eg: ORDER_ITEM_IN: this will take the line item data as input.

Note :

Only specify fields that should be changed

Select these fields by entering an X in the checkboxes

Enter a U in the UPDATEFLAG field

Always specify key fields when changing the data, including in the checkboxes

The configuration is an exception here. If this needs to be changed, you need to complete it again fully.

Maintain quantities and dates in the schedule line data

Possible UPDATEFLAGS:

U = change

D = delete

I = add

Example

1. Delete the whole order

2. Delete order items

3. Change the order

4. Change the configuration

Notes

1. Minimum entry:

You must enter the order number in the SALESDOCUMENT structure.

You must always enter key fields for changes.

You must always specify the update indicator in the ORDER_HEADER_INX.

2. Commit control:

The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.

For further details... refer to the Function Module documentation for the BAPi.

Bapi to VB(Visual Basic)

Long back I had used the following flow structure to acheive the same.

Report -> SM59 RFC destination -> COM4ABAP -> VB.exe

my report uses the rfc destination to create a COM session with com4abap. com4abap calls the vb.exe and manages the flow of data between sap and vb exe.

You need to have com4abap.exe

If com4abap is installed you will find it in sapgui installatin directory , C:\Program Files\SAPpc\sapgui\RFCSDK\com4abap.

else refer OSS note 419822 for installation of com4abap

after making the settings in com4abap to point to the vb program and setting up rfc destination in sm59 to point to com4abap session , you can use the following function modules to call the vb code.

for setting up com4abap and rfc destination please refer to the documentation for com4abap.

  • Invoke NEW DCOM session

call function 'BEGIN_COM_SESSION'

exporting

service_dest = service_dest "(this will be a RFC destination created in SM59)

importing

worker_dest = worker_dest

exceptions

connect_to_dcom_service_failed = 1

connect_to_dcom_worker_failed = 2

others = 3.

call function 'create_com_instance' destination worker_dest

exporting

clsid = g_c_clsid

typelib = g_c_typelib

importing

instid = g_f_oid

exceptions

communication_failure = 1 message g_f_msg

system_failure = 2 message g_f_msg

invalid_instance_id = 3

others = 4.

call function 'com_invoke' destination worker_dest

exporting

%instid = g_f_oid

%method = 'UpdatePDF'

sntemp = g_v_const_filent

snsysid = sy-sysid

snflag = 'N'

tables

rssaptable = g_t_pdfdetail1

%return = g_t_pdfdetail1 "t_test

exceptions

communication_failure = 1 message g_f_msg

system_failure = 2 message g_f_msg

invalid_instance_id = 3

others = 4.

then close the com session , using

FM delete_com_instance

FM END_COM_SESSION

BAPI-step by step

http://www.sapgenie.com/abap/bapi/example.htm

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

former_member125661
Contributor
0 Likes
731

Check the program below. I have used the same BAPI

*&---------------------------------------------------------------------*
*& Report  ZTEST1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST1
        NO STANDARD PAGE HEADING
        LINE-SIZE  132
        LINE-COUNT 65(0)
        MESSAGE-ID ZZ.

TABLES: VBAP.

DATA: V_VBELN LIKE VBAP-VBELN.

DATA: ORDERHEADERINX LIKE BAPISDH1X.
*DATA: ORDERHEADERIN LIKE BAPISDH1.

*DATA: BEGIN OF ORDERITEMIN OCCURS 0.
*        INCLUDE STRUCTURE BAPISDITM.
*DATA: END OF ORDERITEMIN.
*
*DATA: BEGIN OF ORDERITEMINX OCCURS 0.
*        INCLUDE STRUCTURE BAPISDITMX.
*DATA: END OF ORDERITEMINX.
*
DATA: BEGIN OF IT_EXTENSIONIN OCCURS 0.
        INCLUDE STRUCTURE BAPIPAREX.
DATA: END OF IT_EXTENSIONIN.

DATA: BEGIN OF RETURN OCCURS 0.
        INCLUDE STRUCTURE BAPIRET2.
DATA: END OF RETURN.

DATA: BEGIN OF BAPIRETURN OCCURS 0.
        INCLUDE STRUCTURE BAPIRET2.
DATA: END OF BAPIRETURN.

DATA:      l_zavbak          TYPE bape_vbak,
      l_zavbakx         TYPE bape_vbakx.

* POPULATE BAPI DATA AND RUN BAPI
*  CLEAR: ORDERHEADERINX, ORDERITEMIN, ORDERITEMINX,
*         RETURN, BAPIRETURN.
*
*  REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.




V_VBELN = '0000000153'.
ORDERHEADERINX-UPDATEFLAG = 'U'.

*ORDERHEADERIN-


IT_EXTENSIONIN-STRUCTURE = 'BAPE_VBAK'.
  l_zavbak-vbeln         = V_VBELN.
  l_zavbak-zzplant       = '0020'.
IT_EXTENSIONIN-valuepart1 = l_zavbak.
APPEND IT_EXTENSIONIN.


IT_EXTENSIONIN-STRUCTURE = 'BAPE_VBAKX'.
  l_zavbakx-vbeln         = V_VBELN.
  l_zavbakx-zzplant       = 'X'.
IT_EXTENSIONIN-valuepart1 = l_zavbakx.
APPEND IT_EXTENSIONIN.


      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
           EXPORTING
                SALESDOCUMENT    = V_VBELN
*                ORDER_HEADER_IN = ORDERHEADERIN
                ORDER_HEADER_INX = ORDERHEADERINX
                 behave_when_error = 'P'
           TABLES
                RETURN           = RETURN
*                ORDER_ITEM_IN    = ORDERITEMIN
*                ORDER_ITEM_INX   = ORDERITEMINX
                EXTENSIONIN = IT_EXTENSIONIN.

      LOOP AT RETURN.
        WRITE: / RETURN-TYPE, RETURN-ID, RETURN-NUMBER, RETURN-MESSAGE,
        RETURN-LOG_NO, RETURN-LOG_MSG_NO, RETURN-MESSAGE_V1, RETURN-MESSAGE_V2,
        RETURN-MESSAGE_V3, RETURN-MESSAGE_V4.
      ENDLOOP.

      Write: / 'BEFORE COMMITT'.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
                WAIT   = '1'
           IMPORTING
                RETURN = BAPIRETURN.

      Write: / 'AFTER COMMITT'.
            LOOP AT RETURN.
        WRITE: / RETURN-TYPE, RETURN-ID, RETURN-NUMBER, RETURN-MESSAGE,
        RETURN-LOG_NO, RETURN-LOG_MSG_NO, RETURN-MESSAGE_V1, RETURN-MESSAGE_V2,
        RETURN-MESSAGE_V3, RETURN-MESSAGE_V4.
      ENDLOOP.
** WRITE OUT RETURN
      LOOP AT BAPIRETURN.
        WRITE: / BAPIRETURN-TYPE, BAPIRETURN-ID, BAPIRETURN-NUMBER, BAPIRETURN-MESSAGE,
        BAPIRETURN-LOG_NO, BAPIRETURN-LOG_MSG_NO, BAPIRETURN-MESSAGE_V1, BAPIRETURN-MESSAGE_V2,
        BAPIRETURN-MESSAGE_V3, BAPIRETURN-MESSAGE_V4.
      ENDLOOP.
**      WRITE: / BAPIRETURN.