Function Module to pull in variables based on a source variable
Hi,
I am new to user exits and function modules and don't know any ABAP, but I need to make use of a user exit to pull in 4 cost center values (0COSTCENTER) based on a single profit center (0PROFIT_CTR) value. For example, in the planning layout users will select a profit center from the variable screen. Based on that profit center selection, I want to populate 4 cost centers values that correspond to the following:
- a "Pproduction" cost center value
- a "Level 2 R&D" cost center value
- a "Level 2 Selling" cost center value
- a "Level 2 Admin" cost center value
I know I need to create a mapper table that shows what production and level 2 cost centers are to be associated with what profit centers, but I'm not sure how, or where to do that (obviously I have the mapper data already, I just don't know how to set it up in a table that can be read by a function module). And then I think I need to make use of a user exit (function module) to look up the values in that table so the correct cost center values are pulled in based on the profit center selection.
Can anyone offer any advice, and/or provide sample code where I could easily replace the values that are relevant to my situation. Again, I don't know any ABAP, but clearly I need to learn, so I'm not sure if this is even feasible for me to do.
Any advice is appreciated.
//HC
Hi,
You need to create BPS variable of type exit. You can learn it easily. See the following document and you can also search this forum for relevant threads.
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/650ee690-0201-0010-4bb7-83c3e2a74039
Similar Messages
-
Function Module to get pernr number based on first name and last name
Hi All,
What is the Function Module to get pernr number based on first name and last name.
Could you please help me.
T@R.
Vidyahi Vidya,
you can get perner from PA0002 based on firs name and last name.
use select query and get perner. -
Function Module to Delete ODS Data based on Request
Hi All,
Is there any specific function module to delete ODS data based on Request.
I found the program RS_DEL_ODS_1 which is using the FM RSAR_ODS_API_DEL.
But this FM is deleting the request at PSA level.
Is there any alternate FM?Or is there any ABAP Program or so?Hi,
Deletion of specific request is not perimitted for ODS objects. You can delete the most recent request, but if you delete any previous requests, all the requests up to that request will also be deleted.
You can do it by write an ABAP program to identify the specific requests to be deleted for ODS.
Regards
CSM Reddy -
Function Module to get PO details based on Plant and PO date
Hi
1. Is there any Function Module to get PO details based on Plant and PO date?
2. Is there any Function Module to get Material document details based on PO number?
Thanks
Narendrahi,
check these standard reports.
ME2L - By vendor
ME2M - By material
MSRV3 - By service
ME2K - By account assignment
ME2C - By material group
ME2B - By tracking number
ME2N - By PO number
ME2W - By supplying plant
also chck this func module.
REPL_LIST_PURCHASE_ORDER_READ
reward if hlpful. -
For a function module how can I find its assigned data source name?
Hi BW Gurus,
If i know the data source name then the assigned fn. module/Table/Infoset I could find from RSO2. But for function module How do I know its assigned data source name?
Thanks a lot for the response.
Regards
VenHi Ram,
In SE16, enter the table name as ROOSOURCE and in contents choose field EXTRACTOR for selection and enter the name of the function module.
It will return the list of datasources where the function module has been used.
Best Regards,
Ankit Agrawal -
Function Module - Calculate 5 weeks lookup based on -7 increments from the Key Date
Hi Guys,
I am looking to create a variable on Fiscal Period/Year, that automatically populates the variable with the previous 5 weeks based on -7 increments from the key date , when the user runs the query .
For Example: If key date is 03/11/2014 need to get previous 5 weeks 03/04/2014, 02/25/2014, 02/18/2014, 02/11/2014, 02/04/2014. mm/dd/yyyy.
Is there any Function Module available/ please provide the logic code - can anyone help?
Thanks,
Suresh NarayanHi suresh,
Please once try with this approach,
Create a variable with variable represents : multiple input value, Processing type : customer exit ; variable is ready for input.
and write the below code :
if i_step = 1.
data : fdate type d ,
wa1 like line of e_t_range,
n1 type i.
n1 = 1.
if n1 <= 5.
wa1-opt = 'EQ'.
wa1-sign = 'I'.
wa1-low = fdate.
append wa1 to e_t_range.
fdate = fdate - 7.
endif.
endif.
Hope you got it, -
Function module to give a date based on a particular date and interval.
Hi there,
I am writing a code where I need to to find another date
based on a key date and and an interval.
Is there any function module where I pass the date and the interval
(say 30) and it gives me a new date after subtracting 30 from it.
Or is there any piece of code which does it?
Thanks in advance.
Regards,
Katehi Kate,
you can try ?
data : date2 like sy-datum.
date2 = yourdate - 30.
hope this helps. -
Any functional module to get financial document based on billing document
hi all,
do we have any functional module to get accounting document (bseg-BELNR) based on billing document (bseg-VBELN)?
i have a requirement to retrieve the clearing document (bseg-augcp) & date(bseg-augdt) from BSEG with billing document.
billing document is not a key, so i would like to retrieve the accounting document from any function module and use that to get clearing document (bseg-augcp) & date(bseg-augdt).
thanks.hi all,
i got other option to get this....thanks.
select single * from bkpf
where bukrs = <data>-werks
and AWTYP = 'VBRK'
and AWKEY = billing doc.
if sy-subrc EQ 0.
select single * from bseg
where bukrs = bkpf-bukrs
and belnr = bkpf-belnr
and gjahr = bkpf-gjahr.
if sy-subrc EQ 0.
<data>-AUGDT = bseg-augdt.
<data>-AUGBL = bseg-augbl.
endif. -
Function module to retrive material quantity based
Is there any function module which can help me retrieve material quantity for a particular material where i pass material number, plant, storage location and start date and end dates(posting period) for which i require the material quantity.
Hi Kaushal,
Check this lnik out...
http://www.geocities.com/victorav15/sapr3/abapfun.html
Regards,
Santosh -
Function module for Delivery and billing based on sales order
Hi Friends
I am developing an object which has to create the sales order, delivery for that sales order and billing for it at the same time.
I have tried for few function modules to create the delivery and billing but I am not able to achieve.
Would you please help me by providing the correct function modules for these 2 activities?
Thanks
PraveenHi Nikhil
Thanks for reply,
i am creating the sales order using the BAPI "BAPI_SALESORDER_CREATEFROMDAT1" only, but the billing document bapi
"BAPI_BILLINGDOC_CREATE" is for online creation, it will call the t-code 'VF01'.
I need to create the billing document with out calling the t-code like using bapi for sales order. Please suggest me if there are function modules to achieve this.
Thanks
Praveen -
BAPI or Function Module to get MSEG table data based on PO Number (EBELN)
Hi
1. Is there any BAPI / Function Module to get PO details based on Plant and PO date?
2. Is there any BAPI / Function Module to get Material document details(MSEG data) based on PO number?
Thanks
NarendraHi,
check the Bapis Givem below
BAPI_PO_GETITEMS
http://abap.wikiprog.com/wiki/BAPI_PO_GETDETAIL1
you will get the detail.
Regards -
EXtraction through function module
Hello
I have craeted generic extractor which is using function module for pulling sales document data..
Here is the code
UNCTION ZRSAX_BIW_GET_DATA_SIMPLE.
""Local interface:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZBWPRICING OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
Example: DataSource for table SFLIGHT
tables: vbak, vbap, konv.
Auxiliary Selection criteria structure
data: l_s_select type srsc_s_select.
Maximum number of lines for DB table
statics: s_s_if type srsc_s_if_simple,
ls_s_if type srsc_s_if_simple,
counter
s_counter_datapakid like sy-tabix,
cursor
s_cursor type cursor.
Select ranges
ranges: l_r_vbeln for vbak-vbeln,
l_r_erdat for vbak-erdat,
l_r_kschl for konv-kschl,
l_r_posnr for vbap-posnr.
break-point.
data:
gv_tabix type sytabix,
gs_order type gts_order,
gs_konv_hold type gts_konv,
gs_konv type gts_konv,
gt_konv type gtt_konv.
statics: gt_order type gtt_order.
Initialization mode (first call by SAPI) or data transfer mode
(following calls) ?
if i_initflag = sbiwa_c_flag_on.
Initialization: check input parameters
buffer input parameters
prepare data selection
Check DataSource validity
case i_dsource.
when 'ZPRICING'.
when others.
if 1 = 2. message e009(r3). endif.
this is a typical log call. Please write every error message like this
log_write 'E' "message type
'R3' "message class
'009' "message number
i_dsource "message variable 1
' '. "message variable 2
raise error_passed_to_mess_handler.
endcase.
append lines of i_t_select to s_s_if-t_select.
Fill parameter buffer for data extraction calls
s_s_if-requnr = i_requnr.
s_s_if-dsource = i_dsource.
s_s_if-maxsize = i_maxsize.
clear: gt_order, gt_order[].
Fill field list table for an optimized select statement
(in case that there is no 1:1 relation between InfoSource fields
and database table fields this may be far from beeing trivial)
append lines of i_t_fields to s_s_if-t_fields.
else. "Initialization mode or data extraction ?
Data transfer: First Call OPEN CURSOR + FETCH
Following Calls FETCH only
First data package -> OPEN CURSOR
if s_counter_datapakid = 0.
Fill range tables BW will only pass down simple selection criteria
of the type SIGN = 'I' and OPTION = 'EQ' or OPTION = 'BT'.
loop at s_s_if-t_select into l_s_select where fieldnm = 'VBELN'.
move-corresponding l_s_select to l_r_vbeln.
append l_r_vbeln.
endloop.
loop at s_s_if-t_select into l_s_select where fieldnm = 'ERDAT'.
move-corresponding l_s_select to l_r_erdat.
append l_r_erdat.
endloop.
loop at s_s_if-t_select into l_s_select where fieldnm = 'POSNR'.
move-corresponding l_s_select to l_r_posnr.
append l_r_posnr.
endloop.
loop at s_s_if-t_select into l_s_select where fieldnm = 'KSCHL'.
move-corresponding l_s_select to l_r_KSCHL.
append l_r_KSCHL.
endloop.
Determine number of database records to be read per FETCH statement
from input parameter I_MAXSIZE. If there is a one to one relation
between DataSource table lines and database entries, this is trivial.
In other cases, it may be impossible and some estimated value has to
be determined.
select avbeln bposnr aerdat aknumv aauart avkorg
from vbak as a
inner join vbap as b on bvbeln eq avbeln
appending table gt_order
where a~vbeln in l_r_vbeln and
a~erdat in l_r_erdat and
b~posnr in l_r_posnr.
Delete Extra fields.
move: s_s_if-t_fields to ls_s_if-t_fields.
delete ls_s_if-t_fields
where fieldnm eq 'VBELN' or
fieldnm eq 'POSNR' or
fieldnm eq 'ERDAT' or
fieldnm eq 'AUART' or
fieldnm eq 'VKORG'.
open cursor with hold s_cursor for
select (ls_s_if-t_fields) from konv
for all entries in gt_order
where knumv eq gt_order-knumv and
kposn eq gt_order-posnr. "jlm
kposn eq gt_order-posnr and "jlm
kschl in l_r_kschl. "jlm
endif. "First data package ?
Fetch records into interface table.
named E_T_'Name of extract structure'.
fetch next cursor s_cursor
appending corresponding fields
of table e_t_data
package size s_s_if-maxsize.
if sy-subrc <> 0.
close cursor s_cursor.
loop at e_t_data.
move: sy-tabix to gv_tabix.
read table gt_order into gs_order
with key knumv = e_t_data-knumv
posnr = e_t_data-kposn.
check sy-subrc is initial.
move: gs_order-vbeln to e_t_data-vbeln,
gs_order-posnr to e_t_data-posnr,
gs_order-erdat to e_t_data-erdat,
gs_order-auart to e_t_data-auart,
gs_order-vkorg to e_t_data-vkorg .
modify e_t_data index gv_tabix.
clear: gs_order, gv_tabix.
endloop.
raise no_more_data.
endif.
s_counter_datapakid = s_counter_datapakid + 1.
loop at e_t_data.
move: sy-tabix to gv_tabix.
read table gt_order into gs_order
with key knumv = e_t_data-knumv
posnr = e_t_data-kposn.
check sy-subrc is initial.
move: gs_order-vbeln to e_t_data-vbeln,
gs_order-posnr to e_t_data-posnr,
gs_order-erdat to e_t_data-erdat ,
gs_order-auart to e_t_data-auart,
gs_order-vkorg to e_t_data-vkorg .
modify e_t_data index gv_tabix.
clear: gs_order, gv_tabix.
endloop.
endif. "Initialization mode or data extraction ?
loop at e_t_data.
move: sy-tabix to gv_tabix.
read table gt_order into gs_order
with key knumv = e_t_data-knumv
posnr = e_t_data-kposn.
check sy-subrc is initial.
move: gs_order-vbeln to e_t_data-vbeln,
gs_order-posnr to e_t_data-posnr,
gs_order-erdat to e_t_data-erdat ,
gs_order-auart to e_t_data-auart,
gs_order-vkorg to e_t_data-vkorg .
modify e_t_data index gv_tabix.
clear: gs_order, gv_tabix.
endloop.
It works ok if I give selection ERDAT or KSCHL but when I enter ERDAT & KSCHL value it only filters data based on ERDAT.
I debugged but everything looks OK..
can anyone Pls tell me whats is missing here in above code
Thanks for help
Regards
DougHi Nishu,
For this u have to write user exit in enhancement RSAP0001.
A sampe code for that is:
WHEN '2LIS_11_VAITM'.
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE c_t_data .
TABLES : vbak.
*DATA : I_AUDAT LIKE VBAK-AUDAT,
I_VBELN LIKE VBAK-VBELN occurs 0 with header line.
*DATA : I_EXT LIKE MC11VA0ITM OCCURS 0 WITH HEADER LINE.
DATA : i_t_tab LIKE mc11va0itm OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF it_vbak OCCURS 0,
vbeln TYPE vbak-vbeln,
audat TYPE vbak-audat,
END OF it_vbak.
i_t_tab[] = c_t_data[].
BREAK-POINT.
SELECT vbeln
audat
INTO TABLE it_vbak
FROM vbak
FOR ALL ENTRIES IN i_t_tab
WHERE vbeln = i_t_tab-vbeln.
LOOP AT i_t_tab.
READ TABLE it_vbak WITH KEY
vbeln = i_t_tab-vbeln.
IF sy-subrc = 0.
i_t_tab-zzaudat = it_vbak-audat.
MODIFY i_t_tab.
CLEAR : i_t_tab,it_vbak.
ENDIF.
ENDLOOP.
c_t_data[] = i_t_tab[].
REFRESH : i_t_tab,it_vbak.
I think u know where to write this.
Vinod.
Assign points if helpful. -
Different types of function module
hi,
When we create a function module : in one of the tabs we can find
1 general function module
2. remote function module
3. update function module.
What is meant by update function module and remote function module. can anyone explain me with an example and when shd we opt for 2 and 3.
thanxs
hariFunction Modules:
Function modules allow you to encapsulate and reuse global functions in the R/3 System.
They are stored in a central library. The R/3 System contains a wide range of predefined
function modules that you can call from any ABAP program.
Unlike subroutines, you do not define function modules in the source code of your program.
Instead, you use the Function Builder. The actual ABAP interface definition remains hidden
from the programmer. You can define the input parameters of a function module as optional.
You can also assign default values to them. Function modules also support exception handling.
This allows you to catch certain errors while the function module is running. You can test
function modules without having to include them in a program using the Function Builder.
Function Groups:
Function groups are containers for function modules. You cannot execute a function group.
When you call a function module, the system loads the whole of its function group into the
internal session of the calling program.
Calling Function Modules in ABAP:
To call a function module, use the CALL FUNCTION statement:
CALL FUNCTION <module>
[EXPORTING f1 = a 1.... f n = a n]
[IMPORTING f1 = a 1.... f n = a n]
[CHANGING f1 = a 1.... f n = a n]
[TABLES f1 = a 1.... f n = a n]
[EXCEPTIONS e1 = r 1.... e n = r n [ERROR_MESSAGE = r E]
[OTHERS = ro]].
You can specify the name of the function module <module> either as a literal or a variable.
Each interface parameter <fi> is explicitly assigned to an actual parameter <a i>. You can
assign a return value <r i> to each exception <e i>. The assignment always takes the form
<interface parameter> = <actual parameter>. The equals sign is not an assignment operator
in this context.
After EXPORTING, you must supply all non-optional import parameters with values
appropriate to their type. You can supply values to optional import parameters if you
wish.
[email protected]
34
After IMPORTING, you can receive the export parameters from the function module by
assigning them to variables of the appropriate type.
After CHANGING or TABLES, you must supply values to all of the non-optional
changing or tables parameters. When the function module has finished running, the
changed values are passed back to the actual parameters. You can supply values to
optional changing or tables parameters if you wish.
You can use the EXCEPTIONS option to handle the exceptions of the function module. If an
exception <e i > is raised while the function module is running, the system terminates the
function module and does not pass any values from the function module to the program,
except those that were passed by reference. If <e i > is specified in the EXCEPTION option,
the calling program handles the exception by assigning <r i > to SY-SUBRC. <r i > must be a
numeric literal.
If you specify of ERROR_MESSAGE in the exception list you can influence the message
handling of function modules. Normally, you should only call messages in function modules
using the MESSAGE ... RAISING statement. With ERROR_MESSAGE you can force the system
to treat messages that are called without the RAISING option in a function module as follows
for various FM's
http://www.erpgenie.com/abap/functions.htm
Calling Function Modules
http://help.sap.com/saphelp_46c/helpdata/en/9f/db98ef35c111d1829f0000e829fbfe/content.htm
remote enabled fm's are BAPI's
refer
Introduction to BAPIs:
Definition
The SAP Business Objects held in the Business Object Repository (BOR) encapsulate their data
and processes. External access to the data and processes is only possible by means of specific
methods - BAPIs (Business Application Program Interfaces).
A BAPI is defined as a method of a SAP Business Object.
For example, the functionality that is implemented with the SAP Business Object type
"Material" includes a check for the materials availability. Thus, the Business Object type
"Material" offers a BAPI called "Material.CheckAvailability".
Use
To use a BAPI method, an application program only needs to know how to call the method;
that is, it needs to know the methods interface definition. Therefore, when including a BAPI
invocation in your application program, you only need to supply the appropriate interface
information.
A BAPI interface is defined by:
Import parameters, which contain data to be transferred from the calling program to
the BAPI
Export parameters, which contain data to be transferred from the BAPI back to the
calling program
Import/export (table) parameters for both importing and exporting data
Structure
The BAPIs in the R/3 System are currently implemented as function modules, all of which are
held in the Function Builder. Each function module underlying a BAPI:
Supports the Remote Function Call (RFC) protocol
Has been assigned as a method to an SAP Business Object in the BOR
Is processed without returning any screen dialogs to the calling application
Integration
The architecture enables SAP to change the details of a BAPIs implementation without
affecting external applications, which are using the BAPI.
Advantages of Using BAPIs
BAPIs are standardized methods of SAP Business Objects that enable customers and third
parties to integrate their software components with the R/3 System and the Business
Framework.
Business Standard
SAP Business Objects and their BAPIs provide a business content standard, rather than a
technical interoperability standard; that is, they enable the integration of R/3 and other
software components on a business level, not on a technical level.
[email protected]
97
Standards Conformance
BAPIs are being developed as part of the SAP joint initiative with customers, partners, and
leading standards organizations. BAPIs are becoming a communication standard between
business systems.
You can access SAP Business Objects and their BAPIs by using object-oriented interfacing
technologies such as Microsofts COM/DCOM (Component Object Model/Distributed Component
Object Model).
The SAP Business Objects already comply with the Open Applications Group (OAG)
specifications, and, in conjunction with ObjectBridge from VisualEdge, conform to the Object
Management Groups CORBA (Common Object Request Broker Architecture) guidelines.
Stability and Downward Compatibility
Once a BAPI is implemented and released by SAP, its interface definition and parameters
remain stable in the long term, thus ensuring that your application program remains
unaffected by any changes to the underlying R/3 software and data.
SAP can make any necessary extensions to the BAPIs, for example, additional optional
parameters, without destabilizing the operation of existing applications and, at the same time,
can offer the enhanced functionality to new applications.
Object Orientation
As methods of the SAP Business Objects, BAPIs provide access to R/3 data and processes
following an object-oriented programming model. BAPIs can be called using object-oriented
interfacing technologies, such as COM/DCOM, thus enabling software components from SAP
and third parties to interact freely.
Openness
You can access BAPIs from all development platforms that support the SAP Remote Function
Call (RFC) protocol.
BAPI Definition
A Business Application Programming Interface (BAPI) is a precisely defined interface providing
access to processes and data in business application systems such as R/3. BAPIs are defined
as API methods of SAP Business Objects. These business objects and their BAPIs are described
and stored in the Business Object Repository (BOR).
A BAPI is implemented, however, as a function module, that is stored and described in the
Function Builder.
BAPIs can be called within the R/3 System from external application systems and other
programs. BAPIs are the communication standard for business applications. BAPI interface
technology forms the basis for the following developments:
R/3 satellite systems
Isolating components within the R/3 System in the context of Business Framework
Distributed R/3 scenarios using Application Link Enabling (ALE)
Connecting R/3 Systems to the Internet using Internet Application Components (IACs)
Visual Basic programs as front-end to R/3 Systems
Workflow applications that extend beyond system boundaries
Customers and partners own developments
Connections to non-SAP software
Connections to legacy systems
[email protected]
98
Standardized BAPIs
Some BAPIs and methods provide basic functions and can be used for most SAP Business
Objects. Such BAPIs are known as "standardized" BAPIs.
Using the descriptions below as a guide, verify whether you can implement the BAPI as a
standardized BAPI.
Features
BAPIs for Reading Data
The following BAPIs provide you with read-only access to data in the associated business
object:
GetList
With this BAPI you can select a range of object key values, for example, company
codes and material numbers. To specify appropriate selection requirements the calling
program must pass the relevant parameters to the interface. The key values selected
by the BAPI GetList are returned to the calling program in a table, together with other
useful information, for example, short texts. The key values can then be passed on to
another BAPI for further processing, for example, the BAPI GetDetail, as listed below.
GetDetail
The BAPI GetDetail uses a key to retrieve details about an instance(s specific
occurrence) of a business object and returns this data to the calling program.
GetStatus
The BAPI GetStatus is used to query the status of an SAP Business Object, for
example, to display the processing status of a sales order. This BAPI is used only for
displaying the status of an object and does not retrieve full details like the BAPI
GetDetail.
ExistenceCheck
The BAPI ExistenceCheck checks, whether an entry exists for an SAP Business Object,
for example, whether the customer master has been created. You should implement
this method as a workflow method and not as a BAPI (RFC capable function module).
The method CompanyCode.ExistenceCheck of the business object CompanyCode
(BUS0002) is an example of this. This workflow method is indirectly invoked when the
calling program instantiates an object, for example, by using
GetSAPObject("CompanyCode") from within Visual Basic.
BAPIs for Creating or Changing Data
The following BAPIs can create, change or delete instances of a business object: If required,
you can implement these BAPIs so that, several instances of a business object can be created,
deleted or modified simultaneously in the same call. In such cases "multiple" is added to the
method name, for example ChangeMultiple.
BAPIs that can create, change or delete instances are:
Create or CreateFromData
The BAPI Create or CreateFromData creates an instance of an SAP Business Object,
for example, a sales order. Create is the preferred name for this BAPI. Use the name
CreateFromData only when a workflow method called Create already exists for the
business object in question.
[email protected]
99
Change
The BAPI Change changes an existing instance of a SAP Business Object, for example,
a sales order.
Delete
The BAPI Delete deletes an instance of a SAP Business Object, for example, sales
order.
BAPIs for Replicating Business Object Instances
The BAPIs below can be implemented as methods of business objects that can be replicated.
They enable specific instances of an object type to be copied to one or more different systems.
These BAPIs are used mainly to transfer data between distributed systems within the context
of Application Link Enabling (ALE).
The method below must be implemented for each business object to be replicated.
Replicate
The BAPI Replicate is called in the system, which contains the originals of the business
object instances to be replicated. It is used to:
Identify the business objects to be replicated and to organize the required data.
Call the clone methods described below in the receiving system
Moreover, at least one of the clone methods below must be implemented for each business
object to be replicated.
Clone
The BAPI Clone is used by a system to replicate one business object on another
system or to modify one business object that has already been cloned.
CloneMultiple
The BAPI CloneMultiple is used by a system to replicate several business objects on
another system or to modify several business objects that have already been cloned.
Defining and Implementing the BAPI
Purpose
Various components of the ABAP Workbench are used when you define and implement a BAPI.
A BAPI is an API method of a business object and is defined as such in the Business Object
Repository (BOR). However, a BAPI is implemented as an RFC capable function module, which
is maintained in the Function Builder. The definitions and descriptions of the data structures
used by the BAPI are stored in the ABAP Dictionary.
For function modules that implement BAPIs, certain standards and rules must be adhered to
over and above the standard programming rules for function modules. For example, COMMIT
WORK commands must not be used in the function modules that a BAPI is based on.
The following sections guide you through the steps involved in developing a BAPI. The sections
contain information about the guidelines and conventions that you should adhere to when
defining and implementing a BAPI. When implementing BAPIs follow the requirements below
to ensure you achieve consistent behavior and representation of BAPIs as object oriented
methods of SAP Business Objects.
[email protected]
100
BAPI Programming
BAPI Definition
A Business Application Programming Interface (BAPI) is a precisely defined interface providing
access to processes and data in business application systems such as R/3.
BAPIs are defined as API methods of SAP Objects. These objects and their BAPIs are described
and stored in the BOR (BOR).
Use
BAPIs can be called within the R/3 System from external application systems and other
programs. A BAPI call can either be made as an object oriented method call or as a remote
function call (RFC).
BAPIs are a global communication standard for business applications.
Examples of what BAPIs can be used for include:
R/3 satellite systems
Distributed R/3 scenarios using Application Link Enabling (ALE)
Connecting R/3 Systems to the Internet using Internet application components (IACs)
Visual Basic programs as front-end to R/3 Systems
Workflow applications that extend beyond system boundaries
Customers and partners own developments
Connections to non-SAP software
Connections to legacy systems
BOR Definition
The Business Object Repository (BOR) is the object-oriented repository in the R/3 System. It
contains, among other objects, SAP Business Objects and their methods. In the BOR a
Business Application Programming Interface (BAPI) is defined as an API method of an SAP
Business Object. Thus defined, the BAPIs become standard with full stability guarantees as
regards their content and interface.
Use
With regard to SAP Business Objects and their BAPIs, the BOR has the following functions:
Provides an object-oriented view of R/3 System data and processes.
R/3 application functions are accessed using methods (BAPIs) of SAP Business
Objects. Implementation information is encapsulated; only the interface functionality
of the method is visible to the user.
Arranges the various interfaces in accordance with the component hierarchy, enabling
functions to be searched and retrieved quickly and simply.
Manages BAPIs in release updates.
BAPI interface enhancements made by adding parameters are recorded in the BOR.
Previous interface versions can thus be reconstructed at any time. When a BAPI is
created the release version of the new BAPI is recorded in the BOR. The same applies
when any interface parameter is created.
The version control of the function module that a BAPI is based on is managed in the
Function Builder.
Ensures interface stability.
Any interface changes that are carried out in the BOR, are automatically checked for
syntax compatibility against the associated development objects in the ABAP
Dictionary.
[email protected]
101
Integration
You should only define a BAPI as a SAP Business Object method in the BOR if the function
module that the BAPI is based on has been fully implemented. Full access to the BOR is
restricted to the persons responsible for the objects involved and for quality control.
BOR-BAPI Wizard
The BOR-BAPI Wizard assists with creating new BAPI methods in the BOR. It takes you
through the creation process step by step.
Transaction Model for Developing BAPIs Purpose
The transaction model in which BAPIs are used determines how you have to program BAPIs.
The transaction model described here has been used to develop BAPIs for R/3 Releases 3.1
and 4.0A.
Logical Unit of Work (LUW) and Statelessness
Within the context of this transaction model a transaction represents one processing step or
one logical unit of work (LUW). When a transaction is called, database operations are either
fully executed or not at all. The whole transaction must be programmed to be stateless.
This transaction model requires that:
No data is imported that may indirectly affect the result. If a transaction is called more
than once, each call must have the same result. For BAPIs this means, for example,
that Set or Get parameters cannot be used. However, you can keep Customizing data
in a global memory, as this data remains unchanged even if transaction calls are
repeated.
There must be no functional dependencies between two transactions.
Either all relevant data has to be changed in the database or none at all.
Determining the SAP Business Object and Its Key Fields
You have to identify the relevant SAP Business Object in the Business Object Repository (BOR)
and determine whether the key fields of the Business Object are relevant for your BAPI.
A key is defined in the BOR for most SAP Business Objects. This key can consist of several key
fields. The content of these key fields uniquely identifies one individual instance of an SAP
Business Object.
You can differentiate between instance-dependent and instance-independent BAPI methods.
Unlike instance-independent methods, instance-dependent methods relate to one instance
(one specific occurrence) of an SAP Business Object type, for example to one specific sales
order.
In the case of instance-dependent BAPIs, the key fields of the corresponding SAP Business
Object must be used as parameters in the function module the BAPI is based on so that the
associated object instance can be identified. The names of the key fields in the SAP Business
Object and the corresponding parameters in the BAPI function module must be the same,
because the name links the key fields to the parameters.
All the key fields defined in the BOR for the SAP Business Object in question must be used as
the parameters in the function module.
Example
SAP Business Object Creditor has a key field named CreditorId.
This key field must be defined as a parameter with the name CREDITORID in the function
modules of the instant-dependent BAPIs for this Business Object.
[email protected]
102
To display the Business Object and its key fields follow the steps below:
1. Select Tools -> ABAP Workbench -> Overview -> Business Object Browser . The
business objects are displayed in the order of the R/3 application hierarchy.
2. Select the required SAP Business Object in the application hierarchy and double click it
to open it.
3. To display the Business Objects key fields, expand the node Key fields.
Defining the Interface Structure of the BAPI
In this step you are going to define the BAPI interface, that is, the individual import, export
and table parameters required for calling the BAPI.
Caution
You cannot use Changing and Exception parameters in a function module which implements a
BAPI.
Process Flow
To define the interface parameters, proceed as follows:
1. Check whether the key fields of the SAP Business Object are required in the interface. The
key fields of the SAP Business Object are some of the most important BAPI parameters.
If a key value is to be passed to the BAPI by the calling program, the key field must be set as
an import parameter in the function module of the BAPI. That way a specific instance of the
Business Object is identified.
For example, this could be a customer number (CustomerNo) in the BAPIs Customer.GetDetail
and Customer.CheckPassword, or the number of a sales document in the BAPI
SalesOrder.GetStatus.
For BAPIs that generate instances, for example, the BAPIs Create or CreateFromData, the key
field of the Business Object should be set as an export parameter in the BAPI function module.
These BAPIs return one key value, for example, an order number in the BAPI
SalesOrder.CreateFromData.
For BAPIs that are class methods a key field is neither set as an import nor as an export
parameter in the BAPI function module. Class methods are instance-independent and are
called without the use of key values. Usually they return a table with a selection of key values.
2. Specify what other data is relevant as import, export or table parameters for the BAPI.
Every BAPI must have an Export parameter return that reports messages back to the calling
program.
Example
The BAPI to be developed is to read data from the SAP Business Object Creditor. To read
creditor details, the calling program has to pass the ID of the creditor and the company code.
The creditor data returned is to include general details, specific details and bank details.
To map these requirements onto the BAPI interface, the following parameters must be set in
the function module which the BAPI is based on:
The key field CreditorID of the SAP Business Object as an import parameter
An import parameter for the company code
A Return parameter that reports messages back to the calling program
A parameter for general details of the creditor
A parameter for specific details of the creditor
A parameter for bank details of the creditor
for BAPI list
refer www.sapbapi.com
for FM's refer www.se37.com
regards
srinivas
<b>*reward for useful answers*</b> -
Pushing data in packets from Function Module to BW
Hi All,
I have been struggling with a problem for about a week and a half and I find myself at an in-pass. I firstly created a function module to pull data from SAP and join multiple tables so I could use it to report in Crystal. The problem was that it was so much data that I received errors due to processing time.
Thus to solve this problem I now use the function module to push data into a datasource so that it executes in the background.
The main problem I am experiencing is how to code a function module so that it will retrieve the data in segments then commit then retrieve next segment. At the moment the program works but if the data increases like it should I will run into the no more space in the internal table error.
Example of my code below. (much simplified to just demonstrate functionality). Sorry that it is still long but didn't want to leave out parts that might be important.
So how would one get the data to retrieve from the SAP tables and commit to BW in segments instead of like I do to retrieve all the data then pump into BW in segments.
FUNCTION ZBOBJ_COMMISSION.
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" VALUE(I_REMOTE_CALL) TYPE SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZDGB_COMMISION_REPORT OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
STATICS : counter type i.
** Example: DataSource for table SFLIGHT
TABLES: ZDGB_COMMISION_REPORT.
** Auxiliary Selection criteria structure
DATA: L_S_SELECT TYPE SRSC_S_SELECT.
** Maximum number of lines for DB table
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
** counter
S_COUNTER_DATAPAKID LIKE SY-TABIX,
** cursor
S_CURSOR TYPE CURSOR.
** Initialization mode (first call by SAPI) or data transfer mode
** (following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
** Check DataSource validity
CASE I_DSOURCE.
WHEN 'ZBOBJ_COMMISSION'.
WHEN OTHERS.
IF 1 = 2. MESSAGE E009(R3). ENDIF.
** this is a typical log call. Please write every error message like this
LOG_WRITE 'E' "message type
'R3' "message class
'009' "message number
I_DSOURCE "message variable 1
' '. "message variable 2
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
* Fill parameter buffer for data extraction calls
S_S_IF-REQUNR = I_REQUNR.
S_S_IF-DSOURCE = I_DSOURCE.
S_S_IF-MAXSIZE = I_MAXSIZE.
APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
ELSE. "Initialization mode or data extraction ?
STATICS: st_itab TYPE ZDGB_COMMISION_REPORT OCCURS 0 WITH HEADER LINE.
IF S_COUNTER_DATAPAKID = 0.
ORIGINAL - DIRECT CUSTOMER**********************************************************
Select
VBPA~KUNNR
VBRK~VBTYP
INTO CORRESPONDING FIELDS OF TABLE itab1
FROM
VBRK
INNER JOIN VBRP ON VBRK~VBELN = VBRP~VBELN
INNER JOIN MARA ON VBRP~MATNR = MARA~MATNR
INNER JOIN ZCUWE ON ZCUWE~BOT_MAN = MARA~ZZBOTTMANU
INNER JOIN VBPA ON VBPA~VBELN = VBRP~AUBEL
WHERE VBPA~PARVW in s_parvw.
SORT ITAB1 BY KUNNR.
LOOP AT itab2.
st_itab-BUKRS = itab2-BUKRS.
ENDLOOP.
endif.
INSERT LINES OF st_itab TO S_S_IF-MAXSIZE INTO TABLE e_t_data.
DELETE st_itab TO S_S_IF-MAXSIZE.
IF lines( st_itab ) IS INITIAL.
counter = counter + 1.
if counter = 2.
RAISE NO_MORE_DATA.
endif.
ENDIF.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF.
ENDFUNCTION.I'm not sure, but I think there's something wrong with your select instruction
Select
VBPA~KUNNR
VBRK~VBTYP
INTO CORRESPONDING FIELDS OF TABLE itab1
FROM
VBRK
INNER JOIN VBRP ON VBRKVBELN = VBRPVBELN
INNER JOIN MARA ON VBRPMATNR = MARAMATNR
INNER JOIN ZCUWE ON ZCUWEBOT_MAN = MARAZZBOTTMANU
INNER JOIN VBPA ON VBPAVBELN = VBRPAUBEL
WHERE VBPA~PARVW in s_parvw.
You're making a join within vbrk vbrp mara zcuwe and vbpa using a non-key field such vbpa-parvw. Are you sure we're talking about an over-size problem?
You should separate INNER JOIN, using FOR ALL ENTRIES instruction, with range datas. -
Populate a variable based on input (Customer Request Ship date)
Hi Gurus,
I have a requirement to code on a custom variables.
Created two Customer Exit Variables: "ZCRD" AND "ZFYPRD."
Variable one - "ZCRD" - customer requested ship date. ( input) variable.
Populate a variable - "ZFYPRD" based on users input - "ZCRD."
Please provide me if function module exist / how to code a new FM and code to populate the value on variable ZYPRD.
For Instance:
if user's input is "ZCRD = 05/30/08".
Populate the value in the variable (custom) "zfyprd" = 005/2008.
How would I code in ABAP If this is the condition.
Please help.
Thanks in advance.
BWHi Ramesh,
Thank you for the response. Your input is valuable. For this requirement its a BPS Planning Layout.
Do I need a function module to work this code? The (key date) customer requested ship date (variable) is an input from users through planning area. If function module requires please give me the code for the function module.
Users enter = customer requested ship date.
Variable for this fiscal yr/period should populate/ convert it to the period.
I used the function module convert it to period. But which function module is to use to connect it to the variable for customer requested ship date in bps?
I created a variable (customer exit) for period in the query. I referred the code given in the document to convert it to period from key date. But while testing the variable customer requested ship date is coming as initial. what is it that I am missing here? Please help
Thanks in advance,
Maybe you are looking for
-
Thunderbolt drive ejects when computer asleep
This is an issue with a 3.5 GHz Core i7 iMac running 10.9.4 and a Lacie 5 disc Thunderbolt external with a RAID 0 (3x 2TB drives) and a RAID 1 (2x mirrored 2TB drives). At least once a week, and sometimes more, I wake my computer from sleep to discov
-
Ipod won't recognize ipod nano
I've never had a problem with my ipod before but now whenever I plug in my ipod to my computer it lights up then does nothing. It doesn't connect or anything. I thought it might be a problem with my computer but my computer still recognizes my sister
-
I have N86 8MP s/w rev 2.1.006 and I am trying to sync contacts, calendars podcasts, photos etc using Ovi Suite rev 2.2.123 running on pc with Windows 7. Ovi has never really worked properly so I have deleted all Nokia programs using Control Panel in
-
How To Change LIV account Structure
Dear Expert, We have a problem in LIV. We have journal in MIRO Doc Type RE Cr. AP Vendor Db. GR/IR Db. Forex and Doc type ML Db. inventory Cr. Forex Our user want to delete the Doc Type ML in the structure (ML still need to activated),
-
Run Microsoft Fix It tool from the cmd line?
I have a rampant issue across the network I manage where Java installations have been corrupted. The only way that I can seem to remove the corrupted installation is to run the Microsoft Fix It tool. Since it's somewhat impractical to do this manuall