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: 

BAPI Q uestion

Former Member
0 Kudos

Hi

Hi All

Could anyone give me an idea of how to use a BAPI instead of a BDC, I have been asked to use a BAPI to creat PO's. I usually use BDC can you tell me first the advantage of using a BAPI and also as specific instructions as possible in using the BAPI? I am also reading as much as I can but the info seems quite scattered

Thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi George,

This link will definitely clear all the doubts that you have

Check this out

http://www.sap-img.com/bapi.htm

regards,

Santosh

6 REPLIES 6

Former Member
0 Kudos

hi George,

This link will definitely clear all the doubts that you have

Check this out

http://www.sap-img.com/bapi.htm

regards,

Santosh

former_member188685
Active Contributor
0 Kudos

Hi,

you can use BAPI_PO_CREATE1. read the documenation for better understanding.

check the sample code..

REPORT  ZVIJ_TEST                                .


*DATA DECLARATION
CONSTANTS : C_X VALUE 'X'.

*Structures to hold PO header data
DATA : HEADER LIKE BAPIMEPOHEADER ,
HEADERX LIKE BAPIMEPOHEADERX .

*Structures to hold PO account data
DATA : ACCOUNT LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE ,
ACCOUNTX LIKE BAPIMEPOACCOUNTX OCCURS 0 WITH HEADER LINE .

*Internal Tables to hold PO ITEM DATA
DATA : ITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,
ITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,

*Internal table to hold messages from BAPI call
POCONTRACTLIMITS LIKE BAPIESUCC OCCURS 0 WITH HEADER LINE.

DATA : W_HEADER(40) VALUE 'PO Header',
PURCHASEORDER LIKE BAPIMEPOHEADER-PO_NUMBER,
DELIVERY_DATE LIKE BAPIMEPOSCHEDULE-DELIVERY_DATE.

DATA : WS_LANGU LIKE SY-LANGU.

*text-001 = 'PO Header' - define as text element
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : COMPANY LIKE HEADER-COMP_CODE DEFAULT '122' ,
DOCTYP LIKE HEADER-DOC_TYPE DEFAULT 'NB' ,
CDATE LIKE HEADER-CREAT_DATE DEFAULT SY-DATUM ,
VENDOR LIKE HEADER-VENDOR DEFAULT '2000000012' ,
PUR_ORG LIKE HEADER-PURCH_ORG DEFAULT 'PU01' ,
PUR_GRP LIKE HEADER-PUR_GROUP DEFAULT '005' .
*sociedad like HEADER-COMP_CODE default '122' ,
*vendedor like HEADER-SALES_PERS default 'sale person'.


SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS : ITEM_NUM LIKE ITEM-PO_ITEM DEFAULT '00010',
MATERIAL LIKE ITEM-MATERIAL DEFAULT '12000000' ,
TIPO_IMP LIKE ITEM-ACCTASSCAT DEFAULT 'K' ,
*pos_doc like ITEM-ITEM_CAT default 'F' ,
SHORTTXT LIKE ITEM-SHORT_TEXT DEFAULT 'PRUEBA BAPI' ,
GRUP_ART LIKE ITEM-MATL_GROUP DEFAULT '817230000' ,
PLANT LIKE ITEM-PLANT DEFAULT '3001' ,
MPE LIKE ITEM-TRACKINGNO DEFAULT '9999' ,
*contrato like ITEM-AGREEMENT default '4904000003' ,
*quantity like ITEM-QUANTITY default 1 .
PO_UNIT LIKE ITEM-PO_UNIT DEFAULT 'EA'.

SELECTION-SCREEN END OF BLOCK B2.

* Par?mnetros de imputaci?n
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-004.
PARAMETERS : CENTRO LIKE ACCOUNT-COSTCENTER DEFAULT '1220813150',
CUENTA LIKE ACCOUNT-GL_ACCOUNT DEFAULT '6631400' ,
NUM_POS LIKE ACCOUNT-PO_ITEM DEFAULT '10' ,
SERIAL LIKE ACCOUNT-SERIAL_NO DEFAULT '01' ,
IND_IMP LIKE ACCOUNT-TAX_CODE DEFAULT 'I2' .

SELECTION-SCREEN END OF BLOCK B3.


*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*DATA POPULATION
*&---------------------------------------------------------------------*
  WS_LANGU = SY-LANGU. "Language variable

*POPULATE HEADER DATA FOR PO
*HEADER-COMP_CODE = sociedad .
  HEADER-DOC_TYPE = DOCTYP .
  HEADER-VENDOR = VENDOR .
  HEADER-CREAT_DATE = CDATE .
  HEADER-CREATED_BY = 'TD17191' .
  HEADER-PURCH_ORG = PUR_ORG .
  HEADER-PUR_GROUP = PUR_GRP .
  HEADER-COMP_CODE = COMPANY .
  HEADER-LANGU = WS_LANGU .
*HEADER-SALES_PERS = vendedor .
*HEADER-CURRENCY = 'DOP' .
*HEADER-ITEM_INTVL = 10 .
*HEADER-PMNTTRMS = 'N30' .
*HEADER-EXCH_RATE = 1 .


*&---------------------------------------------------------------------*
*POPULATE HEADER FLAG.
*&---------------------------------------------------------------------*
  HEADERX-COMP_CODE = C_X.
  HEADERX-DOC_TYPE = C_X.
  HEADERX-VENDOR = C_X.
  HEADERX-CREAT_DATE = C_X.
  HEADERX-CREATED_BY = C_X.
  HEADERX-PURCH_ORG = C_X.
  HEADERX-PUR_GROUP = C_X.
  HEADERX-LANGU = C_X.
*HEADERX-sales_pers = c_x.
*HEADERX-CURRENCY = c_x.
*HEADER-ITEM_INTVL = c_x.
*HEADER-PMNTTRMS = c_x.
*HEADER-EXCH_RATE = c_x.
*HEADER-EXCH_RATE = c_x.

*&---------------------------------------------------------------------*
*POPULATE ITEM DATA.
*&---------------------------------------------------------------------*
  ITEM-PO_ITEM = ITEM_NUM.
  ITEM-QUANTITY = '1'.
*ITEM-MATERIAL = material .
  ITEM-SHORT_TEXT = 'prueba bapi_po_create1'.
*ITEM-TAX_CODE = ''.
  ITEM-ACCTASSCAT = 'K' .
*ITEM-ITEM_CAT = 'D' .
  ITEM-MATL_GROUP = '817230000' .
  ITEM-PLANT = '3001' .
  ITEM-TRACKINGNO = '99999'.
  ITEM-PREQ_NAME = 'test'.
*ITEM-AGREEMENT = '' .
*ITEM-AGMT_ITEM = ''.
  ITEM-QUANTITY = '1' .
  ITEM-PO_UNIT = 'EA'.
*ITEM-ORDERPR_UN = 'EA'.
  ITEM-CONV_NUM1 = '1'.
  ITEM-CONV_DEN1 = '1'.
  ITEM-NET_PRICE = '1000000' .
  ITEM-PRICE_UNIT = '1'.
  ITEM-GR_PR_TIME = '0'.
  ITEM-PRNT_PRICE = 'X'.
  ITEM-UNLIMITED_DLV = 'X'.
  ITEM-GR_IND = 'X' .
  ITEM-IR_IND = 'X' .
  ITEM-GR_BASEDIV = 'X'.
*ITEM-PCKG_NO = '' .


  APPEND ITEM. CLEAR ITEM.

*&---------------------------------------------------------------------*
*POPULATE ITEM FLAG TABLE
*&---------------------------------------------------------------------*
  ITEMX-PO_ITEM = ITEM_NUM.
  ITEMX-PO_ITEMX = C_X.
*ITEMX-MATERIAL = C_X.
  ITEMX-SHORT_TEXT = C_X.
  ITEMX-QUANTITY = C_X.
*ITEMX-TAX_CODE = C_X.
  ITEMX-ACCTASSCAT = C_X.
*ITEMX-ITEM_CAT = c_x.
  ITEMX-MATL_GROUP = C_X.
  ITEMX-PLANT = C_X.
  ITEMX-TRACKINGNO = C_X.
  ITEMX-PREQ_NAME = C_X.
*ITEMX-AGREEMENT = C_X.
*ITEMX-AGMT_ITEM = c_x.
  ITEMX-STGE_LOC = C_X.
  ITEMX-QUANTITY = C_X.
  ITEMX-PO_UNIT = C_X.
*ITEMX-ORDERPR_UN = C_X.
  ITEMX-CONV_NUM1 = C_X.
  ITEMX-CONV_DEN1 = C_X.
  ITEMX-NET_PRICE = C_X.
  ITEMX-PRICE_UNIT = C_X.
  ITEMX-GR_PR_TIME = C_X.
  ITEMX-PRNT_PRICE = C_X.
  ITEMX-UNLIMITED_DLV = C_X.
  ITEMX-GR_IND = C_X .
  ITEMX-IR_IND = C_X .
  ITEMX-GR_BASEDIV = C_X .
  APPEND ITEMX. CLEAR ITEMX.

*&---------------------------------------------------------------------*
*POPULATE ACCOUNT DATA.
*&---------------------------------------------------------------------*
  ACCOUNT-PO_ITEM = ITEM_NUM.
  ACCOUNT-SERIAL_NO = SERIAL .
  ACCOUNT-CREAT_DATE = SY-DATUM .
  ACCOUNT-COSTCENTER = CENTRO .
  ACCOUNT-GL_ACCOUNT = CUENTA .
  ACCOUNT-GR_RCPT = 'tester'.
  APPEND ACCOUNT. CLEAR ACCOUNT.

*&---------------------------------------------------------------------*
*POPULATE ACCOUNT FLAG TABLE.
*&---------------------------------------------------------------------*
  ACCOUNTX-PO_ITEM = ITEM_NUM .
  ACCOUNTX-PO_ITEMX = C_X .
  ACCOUNTX-SERIAL_NO = SERIAL .
  ACCOUNTX-SERIAL_NOX = C_X .
  ACCOUNTX-CREAT_DATE = C_X .
  ACCOUNTX-COSTCENTER = C_X .
  ACCOUNTX-GL_ACCOUNT = C_X .
  ACCOUNT-GR_RCPT = C_X.
  APPEND ACCOUNTX. CLEAR ACCOUNTX.


*&---------------------------------------------------------------------*
*BAPI CALL
*&---------------------------------------------------------------------*
  CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

  CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      POHEADER         = HEADER
      POHEADERX        = HEADERX
    IMPORTING
      EXPPURCHASEORDER = PURCHASEORDER
    TABLES
      RETURN           = RETURN
      POITEM           = ITEM
      POITEMX          = ITEMX
      POACCOUNT        = ACCOUNT
      POACCOUNTX       = ACCOUNTX.


*&---------------------------------------------------------------------*
*Confirm the document creation by calling database COMMIT
*&---------------------------------------------------------------------*
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
  WAIT = 'X'
* IMPORTING
* RETURN =
  .

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*Output the messages returned from BAPI call
*&---------------------------------------------------------------------*
  LOOP AT RETURN.
    WRITE / RETURN-MESSAGE.
  ENDLOOP.

Regards

vijay

Former Member
0 Kudos

Hi

Use the link below.

http://www.allsaplinks.com/bapi_example.html

hope it could help you

regs

Rakesh

Former Member
0 Kudos

George,

SAP will change screens as they create new versions of R/3, etc.

When you use BDCs and your company does an upgrade, these screen changes can have a direct impact on your BDCs. You may find that the BDC no longer works after the upgrade. You will need to invest time to find the differences from old to new. And then, you make the appropriate changes in your BDC for the new system.

With a BAPI, you do not need to change anything after an upgrade. If the BAPI fails to work after the upgrade, you can simply contact SAP to investigate why the BAPI is failing. It is now (more) their issue than yours to resolve... as long as you have implemented the BAPI properly.

Simply put - That is why you ALWAYS want to use BAPIs whenever possible.

Don't forget those points for helpful answers.

Former Member
0 Kudos

Hi George,

SAP created the Business Framework to allow the technical integration and exchange of business data among SAP components and between SAP and non-SAP components. Important components of the Business Framework are the Business Application Programming Interfaces (BAPI’s), which represent visible interfaces at the component boundaries and whose properties serve to integrate these components.

BAPI’s allow integration at the business level, not the technical level. This provides for greater stability in the link, and independence from the underlying communication technology.

<b>Advantages using Bapi’s</b>

•BAPI’s represent well-defined, internally consistent units that always represent business facts and leave a consistent database state behind.

•<b>The business contents can be standardized</b>, since BAPI’s not only allow the integration of the SAP system and other software components at a technical level, but also at the business level.

<b>•BAPI’s have become a communication standard between business systems</b>. Access is possible through object-oriented interface technologies (such as COM/DCOM from Microsoft). The SAP business objects conform to the guidelines of the OAG (Object Application Group), and meet the CORBA standard from the OMG (Object Management Group).

<b>•Stability and compatibility</b>

Once SAP has released a BAPI, its interface definitions and parameters will remain stable in the long term, which means application programs will not be affected by changes to the underlying SAP software or data. If upward-compatible enhancements are made to the BAPI’s, the stability of the existing applications is not affected.

<b>•Openness</b>

BAPI’s can be accessed from any widespread development platform.

Now about your problem.

Check this link and your problem will be solved .

http://www.sappoint.com/abap/its2.pdf

Yes you have to use the Bapi, <b>BAPI_PO_CREATE.</b>.

You only go thru step 1 of this pdf and your problem will be solved

In THE STEP 1 OF THIS PDF a complete description is given of creating POs using this Bapi.

Thanks and Regards.

Pawan Khilari

*Mark useful answers

close the thread if ur problem is solved.

0 Kudos

Hi All

I am trying to follow an example for a BAPI, There is something I don't understand in the example . You are in se38 entering your code, then he tells you to create screen 1000 for a table control. I have created screens before but not for a control, The instruction I don't understand is as follows

BEGIN OF INSTRUCTION

Now we have to create screen 1000

To place the vendor input on the screen use the function GOTO->DICT./PROGRAM FIELDS in the screenpainter menu.

Enter the data field name into the text box for example bapiekkoc

then use function GET FROM DICT

END OF INSTRUCTION

Does anyone know what is meant and how to do it, I looked in screenpainter and there is no GOTO->DICT./PROGRAM FIELDS OR GET FROM DICT. I also looked from se38 and it is not there as well. I am using 4.7