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

Former Member
0 Likes
14,748

Hi all. I am new to bapi's. i want to know about bapi. what is th purpose of those of BAPI.

7 REPLIES 7
Read only

Former Member
0 Likes
14,476

check this link -

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

reward if helpfull

Read only

former_member404244
Active Contributor
0 Likes
14,476

hi,

Please go through the below link..

/message/2711273#2711273 [original link is broken]

regards,

nagaraj

Read only

Former Member
0 Likes
14,476

Hi Dinesh,

Please go through the following information regarding BAPI's.

<b>Purpose</b>

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 (BAPIs), which represent visible interfaces at the component boundaries and whose properties serve to integrate these components.

The integration can include both components within a local network and components that are connected with one another through the Internet.

BAPIs 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>Integration</b>

BAPIs can be used for the following types of integration:

Connecting R/3 Systems to the Internet using the SAP Business Connector or Internet Application Components (IACs)

BAPIs also allow the creation of true component software, as they enable standardized communication between SAP components. The aim is to encapsulate the functions of the SAP system in independent business components that are integrated through a common interface (the BAPIs).

The integration of new SAP components (such as Advanced Planner and Optimizer (APO) and Business Information Warehouse (BW)), non-SAP software, and legacy systems

Implementation of distributed R/3 scenarios with asynchronous connections using Application Link Enabling (ALE)

Using PC programs as frontends to the R/3 System These can be developed with Visual Basic (Microsoft), for example, or with Visual Age for Java (IBM)

Workflow applications that extend beyond system boundaries

Customers’ and partners’ own developments

Please reward if you find it useful.

Thanks & Regards

Sadhu Kishore

Read only

kiran_k8
Active Contributor
0 Likes
14,476

Hi,

BAPI is an method to define a SAP Business Object.

It let's us integrate all the other external components to R/3.

It provides us an access externally to extract the data.

An alternative to BDC.

A Function Module which is RFC enabled is called as BAPI.

All errors will be captured in RETURN structure as BAPI won't return any sy-subrc value.Hence,not all Functional Modules which are RFC enabled can be termed as BAPI.

K.Kiran.

K.Kiran.

Read only

Former Member
0 Likes
14,476

hi,

REPORT z_po_create NO STANDARD PAGE HEADING

MESSAGE-ID z0lo_scm

LINE-SIZE 220

LINE-COUNT 65 .

TABLES : ekko,

ekpo.

*----


D A T A D E C L A R A T I O N S

*----


*--Type declaration to store data read from table EKKO.

TYPES : BEGIN OF t_ekko,

ebeln TYPE ekko-ebeln,

bukrs TYPE ekko-bukrs,

bsart TYPE ekko-bsart,

aedat TYPE ekko-aedat,

ernam TYPE ekko-ernam,

lifnr TYPE ekko-lifnr,

ekorg TYPE ekko-ekorg,

ekgrp TYPE ekko-ekgrp,

spras TYPE ekko-spras,

werks TYPE ekpo-werks,

END OF t_ekko.

*--Type declaration to store data read from table EKPO.

TYPES : BEGIN OF t_ekpo,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

matnr TYPE ekpo-matnr,

werks TYPE ekpo-werks,

lgort TYPE ekpo-lgort,

menge TYPE ekpo-menge,

knttp TYPE ekpo-knttp,

matkl TYPE ekpo-matkl,

bednr TYPE ekpo-bednr,

afnam TYPE ekpo-afnam,

meins TYPE ekpo-meins,

bpumz TYPE ekpo-bpumz,

bpumn TYPE ekpo-bpumn,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

webaz TYPE ekpo-webaz,

END OF t_ekpo.

TYPES : BEGIN OF t_head_item,

ebeln TYPE ekko-ebeln,

bukrs TYPE ekko-bukrs,

bsart TYPE ekko-bsart,

aedat TYPE ekko-aedat,

ernam TYPE ekko-ernam,

lifnr TYPE ekko-lifnr,

ekorg TYPE ekko-ekorg,

ekgrp TYPE ekko-ekgrp,

spras TYPE ekko-spras,

pincr TYPE ekko-pincr,

zterm TYPE ekko-zterm,

waers TYPE ekko-waers,

inco1 TYPE ekko-inco1,

inco2 TYPE ekko-inco2,

bedat TYPE ekko-bedat,

ebelp TYPE ekpo-ebelp,

txz01 TYPE ekpo-txz01,

matnr TYPE ekpo-matnr,

werks TYPE ekpo-werks,

lgort TYPE ekpo-lgort,

menge TYPE ekpo-menge,

knttp TYPE ekpo-knttp,

matkl TYPE ekpo-matkl,

bednr TYPE ekpo-bednr,

afnam TYPE ekpo-afnam,

meins TYPE ekpo-meins,

bpumz TYPE ekpo-bpumz,

bpumn TYPE ekpo-bpumn,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

webaz TYPE ekpo-webaz,

mwskz TYPE ekpo-mwskz,

adrn2 TYPE ekpo-adrn2,

END OF t_head_item.

TYPES : BEGIN OF t_sucess,

ebeln TYPE ekko-ebeln,

END OF t_sucess.

TYPES : BEGIN OF t_ekko_ekpo,

ebeln TYPE ekko-ebeln,

lifnr TYPE ekko-lifnr,

inco1 TYPE ekko-inco1,

inco2 TYPE ekko-inco2,

zterm TYPE ekko-zterm,

ebelp TYPE ekpo-ebelp,

matnr TYPE ekpo-matnr,

END OF t_ekko_ekpo.

TYPES: BEGIN OF t_err_log,

ebeln TYPE ebeln, " Purchase order no.

bstpo TYPE bstpo, " Purchase order line item

etenr TYPE etenr, " Schedule line

err_val(20) TYPE c, " Error value

err_msg(100) TYPE c, " Error message

pogr_err(1) TYPE c, " If 'X' indicates PO creation error,

" else, indicates GR creation error

END OF t_err_log.

Variables declarations.

DATA : v_ebeln TYPE ekko-ebeln, "PO Number

v_bsart TYPE ekko-bsart,

v_ekorg TYPE ekko-ekorg, "Purchasing Organization

v_ekgrp TYPE ekko-ekgrp, "Purchasing group

v_lifnr TYPE ekko-lifnr, "Vendor Number

v_werks TYPE ekpo-werks, "Plant

v_matnr TYPE ekpo-matnr, "Material Number

v_infnr TYPE ekpo-infnr. "Agreement

Constants declarations.

CONSTANTS: c_bstyp TYPE ekpo-bstyp VALUE 'K',

c_bstyp1 TYPE ekpo-bstyp VALUE 'F',

c_x VALUE 'X'.

*----


D A T A D E C L A R A T I O N S FOR BAPI

*----


**-BAPI structure for Purchase Order Header Data

DATA : x_poheader TYPE bapimepoheader,

**-BAPI structure for Purchase Order Header Data (Change Toolbar)

x_poheaderx TYPE bapimepoheaderx,

**-BAPI structure for Purchase Order Item Data

x_poitem TYPE bapimepoitem,

**-BAPI structure for Purchase Order Item Data (Change Toolbar)

x_poitemx TYPE bapimepoitemx,

**-BAPI structure for messages

x_return TYPE bapiret2,

**-Structure for the error log

x_err_log TYPE t_err_log,

**-BAPI structure for Purchase Order Account assignment Data

x_poaccount TYPE bapimepoaccount,

**-BAPI structure for Purchase Order Account assignment

**-Data (Change Toolbar)

x_poaccountx TYPE bapimepoaccountx,

*ADDRESS

x_deliveryaddr TYPE bapimepoaddrdelivery.

**-BAPI internal table containing purchase order item

DATA : it_poitem TYPE STANDARD TABLE OF bapimepoitem,

**-BAPI internal table containing PO item data (Change Toolbar)

it_poitemx TYPE STANDARD TABLE OF bapimepoitemx,

**-BAPI Return table containing messages

it_return TYPE STANDARD TABLE OF bapiret2,

**-BAPI internal table containing Account Assignment Fields for PO

it_poaccount TYPE STANDARD TABLE OF bapimepoaccount,

**-BAPI internal table containing Account Assignment Fields

**-in Purchase Order (Change Toolbar)

it_poaccountx TYPE STANDARD TABLE OF bapimepoaccountx,

it_deliveryaddr TYPE STANDARD TABLE OF bapimepoaddrdelivery.

*----


I N T E R N A L T A B L E D E C L E R A T I O N S

*----


DATA: it_ekko TYPE STANDARD TABLE OF t_ekko WITH HEADER LINE,

it_ekko_dest TYPE STANDARD TABLE OF t_ekko WITH HEADER LINE,

it_ekpo TYPE STANDARD TABLE OF t_ekpo WITH HEADER LINE,

it_head_item TYPE STANDARD TABLE OF t_head_item WITH HEADER LINE,

it_ekko_ekpo TYPE STANDARD TABLE OF t_ekko_ekpo WITH HEADER LINE,

it_sucess TYPE STANDARD TABLE OF t_sucess WITH HEADER LINE,

it_contract TYPE STANDARD TABLE OF t_sucess WITH HEADER LINE,

**-Internal table containing error messages

it_err_log TYPE STANDARD TABLE OF t_err_log.

*----


S E L E C T I O N S C R E E N

*----


Selection criteria

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS:s_ebeln FOR ekko-ebeln, "PO Number

s_bsart FOR ekko-bsart DEFAULT 'ZHBV', "PO Type

s_aedat FOR ekko-aedat DEFAULT sy-datum, "Creation Date

s_ekorg FOR ekko-ekorg, "Purchasing Organization

s_ekgrp FOR ekko-ekgrp, "Purchasing group

s_lifnr FOR ekko-lifnr, "Vendor Number

s_werks FOR ekpo-werks, "Plant

s_matnr FOR ekpo-matnr, "Material Number

s_infnr FOR ekpo-infnr. "Agreement

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS :p_bukrs LIKE ekko-bukrs DEFAULT '9040', "Company Code

p_werks LIKE ekpo-werks DEFAULT '7040', "Plant

p_ekorg LIKE ekko-ekorg DEFAULT '9040', "Purchasing Organization

p_ekgrp LIKE ekko-ekgrp DEFAULT '031', "Purchasing group

p_bsart1 LIKE ekko-bsart DEFAULT 'ZHIH'. "PO Type

SELECTION-SCREEN END OF BLOCK b2.

-


A T S E L E C T I O N - S C R E E N

-


AT SELECTION-SCREEN.

Validating the Selection Screen inputs.

PERFORM validate_user_input.

-


S T A R T - O F - S E L E C T I O N

-


START-OF-SELECTION.

Getting data from table EKKO.

PERFORM get_purchase_order.

Getting data from table EKKO

PERFORM get_po_created.

Getting data from table EKKO & EKPO

PERFORM get_contract_num.

Creating the PO.

PERFORM create_po.

-


E N D - O F - S E L E C T I O N

-


END-OF-SELECTION.

Display PO which are already created

PERFORM display_createdpo_rept.

Display PO which doesnt have contract numbers

PERFORM display_contract_rept.

TOP-OF-PAGE.

PERFORM page_heading.

&----


*& Form VALIDATE_USER_INPUT

&----


Form to validate user inputs at Selection Screen.

-


FORM validate_user_input .

Validating Purchasing Document Number

IF NOT s_ebeln[] IS INITIAL.

SELECT ebeln

INTO v_ebeln

FROM ekko

UP TO 1 ROWS

WHERE ebeln IN s_ebeln.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Purchasing Document Number'(004).

ENDIF.

ENDIF.

Validating Purchasing Document Type

IF NOT s_bsart[] IS INITIAL.

SELECT bsart

INTO v_bsart

FROM t161

UP TO 1 ROWS

WHERE bsart IN s_bsart.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Purchasing Document Type'(005).

ENDIF.

ENDIF.

Validating Purchasing org

IF NOT s_ekorg[] IS INITIAL.

SELECT ekorg

INTO v_ekorg

FROM t024e

UP TO 1 ROWS

WHERE ekorg IN s_ekorg.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Purchasing Organization'(006).

ENDIF.

ENDIF.

Validating Purchasing group

IF NOT s_ekgrp[] IS INITIAL.

SELECT ekgrp

INTO v_ekgrp

FROM t024

UP TO 1 ROWS

WHERE ekgrp IN s_ekgrp.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Purchasing Group'(007).

ENDIF.

ENDIF.

Validating Vendor's account number

IF NOT s_lifnr[] IS INITIAL.

SELECT lifnr

INTO v_lifnr

FROM lfa1

UP TO 1 ROWS

WHERE lifnr IN s_lifnr.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Vendor account number'(008).

ENDIF.

ENDIF.

Validating Plant

IF NOT s_werks[] IS INITIAL.

SELECT werks

INTO v_werks

FROM t001w

UP TO 1 ROWS

WHERE werks IN s_werks.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Plant'(009).

ENDIF.

ENDIF.

Validating Material

IF NOT s_matnr[] IS INITIAL.

SELECT matnr

INTO v_matnr

FROM mara

UP TO 1 ROWS

WHERE matnr IN s_matnr.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid Material Number'(010).

ENDIF.

ENDIF.

Validating info record(Agreement)

IF NOT s_infnr[] IS INITIAL.

SELECT infnr

INTO v_infnr

FROM eina

UP TO 1 ROWS

WHERE infnr IN s_infnr.

ENDSELECT.

IF sy-subrc 0.

MESSAGE e000 WITH 'Invalid purchasing info record'(011).

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_USER_INPUT

&----


*& Form GET_PURCHASE_ORDER

&----


Form to fetch data required from table EKKO & EKPO into internal table.

-


FORM get_purchase_order.

REFRESH it_head_item.

Getting data from table EKKO & EKPO.

SELECT a~ebeln

a~bukrs

a~bsart

a~aedat

a~ernam

a~lifnr

a~ekorg

a~ekgrp

a~spras

a~pincr

a~zterm

a~waers

a~inco1

a~inco2

a~bedat

b~ebelp

b~txz01

b~matnr

b~werks

b~lgort

b~menge

b~knttp

b~matkl

b~bednr

b~afnam

b~meins

b~bpumz

b~bpumn

b~netpr

b~peinh

b~webaz

b~mwskz

b~adrn2

INTO TABLE it_head_item

FROM ekko AS a

INNER JOIN ekpo AS b

ON aebeln = bebeln

WHERE a~ebeln IN s_ebeln

AND a~bsart IN s_bsart

AND a~aedat IN s_aedat

AND a~ekgrp IN s_ekgrp

AND a~ekorg IN s_ekorg

AND a~lifnr IN s_lifnr

AND a~loekz c_x

AND b~werks IN s_werks

AND b~matnr IN s_matnr

AND b~infnr IN s_infnr

AND b~loekz c_x.

IF sy-subrc = 0.

SORT it_head_item BY ebeln.

LOOP AT it_head_item.

it_head_item-ebeln+0(1) = 'I'.

MODIFY it_head_item INDEX sy-tabix.

ENDLOOP.

ELSE.

MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).

STOP.

ENDIF.

ENDFORM. " GET_PURCHASE_ORDER

&----


*& Form GET_PO_CREATED

&----


Form to fetch data required from table EKKO into internal table.

Delete those records which are already created

-


FORM get_po_created .

*--fetch data from table EKKO into internal table

*--Where Docu type = 'ZHIH'

IF NOT it_head_item[] IS INITIAL.

SELECT a~ebeln

a~bukrs

a~bsart

a~aedat

a~ernam

a~lifnr

a~ekorg

a~ekgrp

a~spras

b~werks

INTO TABLE it_ekko_dest

FROM ekko AS a

INNER JOIN ekpo AS b

ON aebeln = bebeln

FOR ALL ENTRIES IN it_head_item

WHERE a~ebeln = it_head_item-ebeln

AND a~bsart = p_bsart1

AND a~bukrs = p_bukrs

AND b~werks = p_werks

AND b~bstyp = c_bstyp1

AND a~ekorg = p_ekorg

AND a~ekgrp = p_ekgrp.

IF sy-subrc = 0.

SORT it_ekko_dest BY ebeln.

ENDIF.

ENDIF.

*--Move all the PO numbers into sucess internal table

*--if the PO was already created

LOOP AT it_ekko_dest.

MOVE it_ekko_dest-ebeln TO it_sucess-ebeln.

APPEND it_sucess.

CLEAR it_sucess.

DELETE it_head_item WHERE ebeln = it_ekko_dest-ebeln.

ENDLOOP.

CLEAR it_head_item.

IF it_head_item[] IS INITIAL.

MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).

STOP.

ENDIF.

ENDFORM. " GET_PO_CREATED

&----


*& Form GET_CONTRACT_NUM

&----


text

-


FORM get_contract_num .

*--Select the data to get contract number

IF NOT it_head_item[] IS INITIAL.

SELECT a~ebeln "contract numbers

a~lifnr

a~inco1 "Incoterm1

a~inco2 "incoterm2

a~zterm

b~ebelp

b~matnr

INTO TABLE it_ekko_ekpo

FROM ekko AS a

INNER JOIN ekpo AS b

ON aebeln = bebeln

FOR ALL ENTRIES IN it_head_item

WHERE b~matnr = it_head_item-matnr

AND a~bukrs = p_bukrs " Company code

AND a~ekorg = p_ekorg " Purchase org

AND a~loekz c_x " Deletion indicator for header data

AND a~kdatb <= sy-datum " Validity period start

AND a~kdate >= sy-datum " Validity period end

AND b~loekz <> c_x " Deletion indicator for item data

AND b~bstyp = c_bstyp. " Purch. doc. category

IF sy-subrc = 0.

SORT it_ekko_ekpo BY matnr.

ENDIF.

LOOP AT it_head_item.

READ TABLE it_ekko_ekpo WITH KEY matnr = it_head_item-matnr

BINARY SEARCH.

IF sy-subrc 0.

move the data to the internal table

which doesnt have contract number

it_contract-ebeln = it_head_item-ebeln.

APPEND it_contract.

CLEAR it_contract.

Deleting the record

which doesnt have any contract number

DELETE it_head_item WHERE ebeln = it_head_item-ebeln.

ENDIF.

ENDLOOP.

CLEAR it_head_item.

ENDIF.

IF it_head_item[] IS INITIAL.

MESSAGE i000 WITH 'No Purchase Order is possible for creation'(003).

STOP.

ENDIF.

ENDFORM. " GET_CONTRACT_NUM

&----


*& Form CREATE_PO

&----


CREATE PURCHASE ORDER

-


FORM create_po .

DATA: l_ret_msg(1000) TYPE c. " Success/Error message from BAPI

CLEAR: x_poheader, x_poheaderx.

SORT it_head_item BY ebeln.

LOOP AT it_head_item.

AT NEW ebeln.

READ TABLE it_head_item WITH KEY ebeln = it_head_item-ebeln.

IF sy-subrc = 0.

**-Populate PO Header structure

x_poheader-po_number = it_head_item-ebeln. " PO no.

x_poheader-comp_code = p_bukrs. " Company code

x_poheader-doc_type = p_bsart1. " Document type

x_poheader-creat_date = it_head_item-aedat. " Date created

x_poheader-created_by = it_head_item-ernam. " Created by

READ TABLE it_ekko_ekpo WITH KEY matnr = it_head_item-matnr

BINARY SEARCH.

IF sy-subrc = 0.

x_poheader-vendor = it_ekko_ekpo-lifnr. " Vendor no.

x_poheader-incoterms1 = it_ekko_ekpo-inco1. " Incoterms1

x_poheader-incoterms2 = it_ekko_ekpo-inco2. " Incoterms2

x_poheader-pmnttrms = it_ekko_ekpo-zterm. " Payment terms

ENDIF.

x_poheader-langu = sy-langu. " Language key

x_poheader-langu_iso = sy-langu. " Language key iso

x_poheader-purch_org = p_ekorg. " Purchasing org.

x_poheader-pur_group = p_ekgrp. " Purch. Group

x_poheader-currency = it_head_item-waers. " currency

x_poheader-currency_iso = it_head_item-waers. " currency iso

x_poheader-doc_date = it_head_item-bedat. " Doc date

**-Populate PO Header 'X' structure

x_poheaderx-po_number = c_x.

x_poheaderx-comp_code = c_x.

x_poheaderx-doc_type = c_x.

x_poheaderx-creat_date = c_x.

x_poheaderx-created_by = c_x.

x_poheaderx-vendor = c_x.

x_poheaderx-langu = c_x.

x_poheaderx-langu_iso = c_x.

x_poheaderx-pmnttrms = c_x.

x_poheaderx-purch_org = c_x.

x_poheaderx-pur_group = c_x.

x_poheaderx-currency = c_x.

x_poheaderx-currency_iso = c_x.

x_poheaderx-doc_date = c_x.

x_poheaderx-incoterms1 = c_x.

x_poheaderx-incoterms2 = c_x.

ENDIF.

ENDAT.

READ TABLE it_ekko_ekpo WITH KEY matnr = it_head_item-matnr

BINARY SEARCH.

IF sy-subrc = 0.

x_poitem-po_item = it_ekko_ekpo-ebelp. " PO Item no.

x_poitem-agreement = it_ekko_ekpo-ebeln. " Agreement NO

ENDIF.

x_poitem-short_text = it_head_item-txz01. " Item description

x_poitem-material = it_head_item-matnr. " Material no.

x_poitem-plant = p_werks. " Plant

x_poitem-stge_loc = p_werks. " Storage Loc

x_poitem-matl_group = it_head_item-matkl. " Material group

x_poitem-quantity = it_head_item-menge. " Ordered qty.

x_poitem-po_unit = it_head_item-meins. " Order unit

x_poitem-po_unit_iso = it_head_item-meins. " Order unit

x_poitem-net_price = it_head_item-netpr. " Net price

x_poitem-price_unit = it_head_item-peinh. " price per unit

x_poitem-tax_code = it_head_item-mwskz. " Tax Code

x_poitem-acctasscat = it_head_item-knttp. " Account ass cata

APPEND x_poitem TO it_poitem.

CLEAR x_poitem.

**-Populate PO Item 'X' structure

x_poitemx-po_item = it_ekko_ekpo-ebelp. " PO Item no.

x_poitemx-po_itemx = c_x.

x_poitemx-short_text = c_x.

x_poitemx-material = c_x.

x_poitemx-plant = c_x.

x_poitemx-stge_loc = c_x.

x_poitemx-agreement = c_x.

x_poitemx-matl_group = c_x.

x_poitemx-quantity = c_x.

x_poitemx-po_unit = c_x.

x_poitemx-po_unit_iso = c_x.

x_poitemx-net_price = c_x.

x_poitemx-price_unit = c_x.

x_poitemx-tax_code = c_x.

x_poitemx-acctasscat = c_x.

APPEND x_poitemx TO it_poitemx.

CLEAR x_poitemx.

x_deliveryaddr-po_item = it_ekko_ekpo-ebelp.

x_deliveryaddr-addr_no = it_head_item-adrn2.

APPEND x_deliveryaddr TO it_deliveryaddr.

CLEAR x_deliveryaddr.

AT END OF ebeln.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = x_poheader

poheaderx = x_poheaderx

TABLES

return = it_return

poitem = it_poitem

poitemx = it_poitemx

poaddrdelivery = it_deliveryaddr.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

REFRESH : it_poitemx,it_poitem.

WRITE 😕 x_poheader-po_number.

LOOP AT it_return INTO x_return.

WRITE 😕 x_return-type,

20 x_return-message.

ENDLOOP.

REFRESH : it_poitemx,it_poitem,it_deliveryaddr,it_return.

CLEAR: x_poheader,x_poheaderx,x_poitem,x_poitemx,x_deliveryaddr.

ENDAT.

ENDLOOP.

ENDFORM. " CREATE_PO

&----


*& Form display_createdpo_rept

&----


text

-


FORM display_createdpo_rept .

**-Column headings

FORMAT COLOR COL_HEADING.

WRITE:/1(100) sy-uline.

WRITE:/1 sy-vline,

30 'List of PO already created',

100 sy-vline.

FORMAT INTENSIFIED OFF.

FORMAT RESET.

WRITE:/1(100) sy-uline.

Display PO created sucess report

LOOP AT it_sucess.

WRITE:/1 sy-vline,

15 'Purchase Order NO:',

40 it_sucess-ebeln,

100 sy-vline.

ENDLOOP.

WRITE:/1 sy-vline,

2(99) sy-uline,

100 sy-vline.

ENDFORM. " display_createdpo_rept

&----


*& Form display_contract_rept

&----


text

-


FORM display_contract_rept .

SKIP 3.

**-Column headings

FORMAT COLOR COL_HEADING.

WRITE:/1(100) sy-uline.

WRITE:/1 sy-vline,

30 'List of Contract Numbers',

100 sy-vline.

FORMAT INTENSIFIED OFF.

FORMAT RESET.

WRITE:/1(100) sy-uline.

LOOP AT it_contract.

WRITE:/1 sy-vline,

15 'Purchase Order NO:',

40 it_contract-ebeln,

100 sy-vline.

ENDLOOP.

WRITE:/1 sy-vline,

2(99) sy-uline,

100 sy-vline.

ENDFORM. " display_contract_rept

*&----


**& Form RETURN_MESSAGES

*&----


text

*----


*FORM return_messages .

*

*

*ENDFORM. " RETURN_MESSAGES

&----


*& Form PAGE_HEADING

&----


text

-


FORM page_heading .

**-List heading

FORMAT COLOR COL_HEADING.

WRITE:/1(100) sy-uline.

WRITE:/1 sy-vline,

40 'Summary Report',

100 sy-vline.

FORMAT INTENSIFIED OFF.

FORMAT RESET.

WRITE:/1(100) sy-uline.

SKIP 5.

ENDFORM. " PAGE_HEADING

Read only

Former Member
0 Likes
14,476

Hi Sir ,

Please have a look below .Hope it is suitable and simpler solution for your question.

Please do reward if useful.

Thankx.

what is BAPI?

BAPI stands for Business API(Application Program Interface).

A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..

You can make your function module remotely enabled in attributes of Function module but

A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:

Reading instances of SAP business objects

GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.

GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

Create( ) and CreateFromData! ( )

The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )

The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing object inst! ance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.

BAPI-step by step

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

just refer to the link below

http://www.sapmaterial.com/?gclid=CN322K28t4sCFQ-WbgodSGbK2g

list of all bapis

http://www.planetsap.com/LIST_ALL_BAPIs.htm

for BAPI's

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

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

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

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

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

http://service.sap.com/ale

http://service.sap.com/bapi

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE8/BCFESDE8.pdf

http://www.planetsap.com/Bapi_main_page.htm

http://www.topxml.com/sap/sap_idoc_xml.asp

http://www.sapdevelopment.co.uk/

http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf

Also refer to the following links..

www.sap-img.com/bapi.htm

www.sap-img.com/abap/bapi-conventions.htm

www.planetsap.com/Bapi_main_page.htm

www.sapgenie.com/abap/bapi/index.htm

Checkout !!

http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html

http://techrepublic.com.com/5100-6329-1051160.html#

Example Code

U need to give the step_nr, item_nr, cond_count and cond_type so the correct conditon will be updated. If no condition exists for the given parameters, a new condition will be created.

U can find these parameters for a particular condition type in table KONV.

&----


*& Form saveTransactionJOCR

&----


text

-


--> p1 text

<-- p2 text

-


FORM saveTransactionJOCR .

data: salesdocument like BAPIVBELN-VBELN,

order_header_inx like bapisdh1x,

order_header_in like bapisdh1,

return type standard table of bapiret2 with header line,

conditions_in type standard table of bapicond with header line,

conditions_inx type standard table of bapicondx with header line,

logic_switch like BAPISDLS,

step_nr like conditions_in-cond_st_no,

item_nr like conditions_in-itm_number,

cond_count like conditions_in-cond_count,

cond_type like conditions_in-cond_type.

salesdocument = wa_order_information-VBELN.

LOGIC_SWITCH-COND_HANDL = 'X'.

order_header_inx-updateflag = 'U'.

conditions

clear conditions_in[].

clear conditions_inx[].

clear: step_nr,

item_nr,

cond_count,

cond_type.

step_nr = '710'.

item_nr = '000000'.

cond_count = '01'.

cond_type = 'ZCP2'.

CONDITIONS_IN-ITM_NUMBER = item_nr.

conditions_in-cond_st_no = step_nr.

CONDITIONS_IN-COND_COUNT = cond_count.

CONDITIONS_IN-COND_TYPE = cond_type.

CONDITIONS_IN-COND_VALUE = 666.

CONDITIONS_IN-CURRENCY = 'EUR'.

append conditions_in.

CONDITIONS_INX-ITM_NUMBER = item_nr.

conditions_inx-cond_st_no = step_nr.

CONDITIONS_INX-COND_COUNT = cond_count.

CONDITIONS_INX-COND_TYPE = cond_type.

CONDITIONS_INX-UPDATEFLAG = 'U'.

CONDITIONS_INX-COND_VALUE = 'X'.

CONDITIONS_INX-CURRENCY = 'X'.

append conditions_inx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = salesdocument

ORDER_HEADER_IN = order_header_in

ORDER_HEADER_INX = order_header_inx

LOGIC_SWITCH = logic_switch

TABLES

RETURN = return

CONDITIONS_IN = conditions_in

CONDITIONS_INX = conditions_inx

.

if return-type ne 'E'.

commit work and wait.

endif.

ENDFORM. " saveTransactionJOCR

Bdc to Bapi

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

cheers,