Upload
sapabapsap
View
215
Download
0
Embed Size (px)
Citation preview
7/31/2019 Cross Apps
1/192
1 | P a g e S a n t o s h P
RFC
REMOTE FUNCTION CALL
Class 1: 28.07.2011
A Function module is the set of statements which has to be defined once & can be called any number of times. There are twotypes of function modules.
1).Normal Function Module.
2).Remote Function Module.
Normal Function Module: It is client Dependent object which can be called any number of times and any client in the same server.
Remote Function Module: This function module can be accessed from remote SAP Server.
RFC is the process of executing a function module existing on remote SAP Server. It is similar to RMI Technology in JAVA.
RMI: Remote Method Invocation.
As the part of RFC process there are two parts involved RFC CLIENT & RFC SERVER.RFC SERVER: Is the system where the remote function module is stored.
RFC CLIENT: System where the function module is called.
As a part of RFC Client System we need to create an object called RFC DESTINATION.RFC DESTINATION: Is the object which is always created in RFC Client System, Which stores the physical details of remote system.
This physical details include IP Address (Host Name) of the remote server, system number of remote server and Log Oncredentials of remote server (Client, User Name, Password).
SM59: T-Code for Creating RFC Destination.
RFCDES is the table which stores the RFC Destinations.
7/31/2019 Cross Apps
2/192
2 | P a g e S a n t o s h P
Remote function module can be called in three ways or (three types)1) Synchronous RFC2) Asynchronous RFC3) Transactional RFC
Note: In Case of Synchronous and Asynchronous RFC the remote SAP Server should be available to receive the request.
In case of Transactional RFC the remote server need not to be available at the time of Communication. In this case the request to the remote function module is executed as background job.
Syntax for Synchronous RFC:
Call function Destination [Parameters List].
Syntax for Asynchronous RFC:
Call function Destination Starting New Task Performing
On End Of Task[Exporting Parameters].
Note: In Case ofAsynchronous RFC Results from the remote function module should be received separately in subroutine.
Syntax for Receiving Results From ARFC:
Form Using Receive Results From function [Importing Parameters].
Syntax for Transactional RFC:
Call function In Background Task Destination [Exporting Parameters].
Note:
It is recommended to call only those function module in Transactional RFC mode which doesnt return any value, Because inTransactional RFC mode it is executed in background.
In Transactional RFC mode when we sent the request to the remote function module since the remote server is notavailable the request will be saved in the following tables of RFC Client System.
1).ARFCSSTATE.
2).ARFCSDATA.
To execute the Transactional RFC request SAP has provided an executable program RSARFCSE.which will be executing
7/31/2019 Cross Apps
3/192
3 | P a g e S a n t o s h P
For every 15minuts, to check whether the remote server is available to process the request by default it executes for
20Attempts.
SE58: T-Code for checking the status of Transactional RFC.
Steps in RFC Server:
Create a remote function module.Note: The parameters to the remote function module are always passed by value.
Steps in RFC Client:
Create a RFC Destination Storing the details of remote SAP Server. Create an executable program to call the remote function module.
STARTING PROGRAM:
IN 6.0:
SM59: Create an FRC Destination.
In Technical Settings Tab:
7/31/2019 Cross Apps
4/192
4 | P a g e S a n t o s h P
In Logon & Security Tab:
Remote Logon: If all the details given are correct it will take you to 4.7 Logon.
IN 4.7:
SE37:
Create a function Module: Z915FM1
7/31/2019 Cross Apps
5/192
5 | P a g e S a n t o s h P
Source Code:
FUNCTION Z915FM1.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(I_X) TYPE I
*" VALUE(I_Y) TYPE I
*" EXPORTING
*" VALUE(E_Z) TYPE I
*"----------------------------------------------------------------------
E_Z = I_X + I_Y.
ENDFUNCTION.
IN 6.0:
SE38:
Create an Executable Program: ZCALL_915FM1
REPORT ZCALL_915FM1.
parameters : p_x typei,
p_y typei.
data lv_z typei.
callfunction 'Z915FM1'
destination '915DEST'
7/31/2019 Cross Apps
6/192
6 | P a g e S a n t o s h P
exporting
i_x = p_x
i_y = p_y
importing
e_z = lv_z.
write :/ 'sum is ',lv_z.
OUTPUT:
Press Enter
7/31/2019 Cross Apps
7/192
7 | P a g e S a n t o s h P
Class 2: 29.07.2011
Note:
In Synchronous RFC whenever the execution of the RFC Client program starts.SAP creates a Main Thread. This thread isresponsible for calling the remote function module.
When the remote function module is under execution the main thread will be suspended. During this time the CPU of RFC Client will be idle state.
When the remote function module finishes the execution the control will return back to RFC Client. Now the main thread resumes the execution & executes the remaining statements of RFC Client Program. It Means in Synchronous RFC. The idle time of CPU is more, It is not used Efficiently.
Asynchronous RFC:
In asynchronous RFC when we call the remote module. We need to explicitly create the thread (TASK). This thread isresponsible for executing the remote function module.
When the new thread is under execution the main thread will continue the execution i.e. bout the threads will be executingparallel.
It means main thread doesnt wait for called thread to finish the execution. This is called as parallel processing. We go for ARFC mode. When the RFC Client program doesnt depend up on result of the RFC Service.
Note: In case of Synchronous and Asynchronous if the remote server is not available at the time of communication. It leads to run
time error.
PROGRAM:
IN 6.0:
ZCALL_915FM2:
CASE 1:
REPORT ZCALL_915FM2.
parameters : p_x typei,
p_y typei.
data lv_z typei.
7/31/2019 Cross Apps
8/192
8 | P a g e S a n t o s h P
callfunction'Z915FM1'
destination '915DEST'
startingnewtask'T1'
performing getdata onendoftask
exporting
i_x = p_x
i_y = p_y.write :/ 'sum is ',lv_z.
write :/ 'End of rfc client program'.
form getdata using T1.
receive results fromfunction'Z915FM1'
importing
e_z = lv_z.
endform.
OUTPUT:
7/31/2019 Cross Apps
9/192
9 | P a g e S a n t o s h P
CASE 2:
REPORT ZCALL_915FM2.
parameters : p_x typei,
p_y typei.
data lv_z typei.
callfunction'Z915FM1'
destination '915DEST'
startingnewtask'T1'
performing getdata onendoftask
exporting
i_x = p_x
i_y = p_y.
waitupto20 seconds.
write :/ 'sum is ',lv_z.
write :/ 'End of rfc client program'.
form getdata using T1.
receive results fromfunction'Z915FM1'
importing
e_z = lv_z.
endform.
7/31/2019 Cross Apps
10/192
10 | P a g e S a n t o s h P
7/31/2019 Cross Apps
11/192
11 | P a g e S a n t o s h P
IN 4.7:
SE11:
TABLE: ZDEPT.
SE37:
Z915FM2:
7/31/2019 Cross Apps
12/192
12 | P a g e S a n t o s h P
Source Code:
FUNCTION Z915FM2.*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING*" VALUE(I_DEPT) TYPE ZDEPT
*"----------------------------------------------------------------------
IF I_DEPT IS NOT INITIAL.
INSERT ZDEPT FROM I_DEPT.
ENDIF.
ENDFUNCTION.
IN 6.0:
ZCALL_915FM3:
REPORT ZCALL_915FM3.
data : beginof ls_dept,
deptno typei,
dname(20) typec,
loc(30) typec,
endof ls_dept.
ls_dept-deptno = 69.
ls_dept-dname = 'Finance'.
ls_dept-loc = 'Vizag'.
callfunction'Z915FM2'
in background task
destination '915DEST'
exporting
i_dept = ls_dept.
COMMIT WORK.
OUTPUT: There will be no output because it will be run in background.
NOTE:
If the remote server is available the data will be reflected in Database table ZDEPT.
ELSE
7/31/2019 Cross Apps
13/192
13 | P a g e S a n t o s h P
COMMIT WORK: Key work which is used for saving the data permanently in Database Table.
Note:
In Transactional RFC mode when we sent the request to the remote function module since the remote server is notavailable the request will be saved in the following tables of RFC Client System.
1).ARFCSSTATE.
2).ARFCSDATA.
To execute the Transactional RFC request SAP has provided an executable program RSARFCSE.which will be executingFor every 15minuts, to check whether the remote server is available to process the request by default it executes for
20Attempts.
SE58: T-Code for checking the status of Transactional RFC.
Class 3: 01.08.2011
Calling RFC Back:
7/31/2019 Cross Apps
14/192
14 | P a g e S a n t o s h P
Note:
As part of RFC communication we can refer back to the calling system. By using the keyword BACK.
PROGRAM:
IN 4.7:
SE37: Z915FM1
7/31/2019 Cross Apps
15/192
15 | P a g e S a n t o s h P
SOURCE CODE:
FUNCTION Z915FM1.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING*" VALUE(I_X) TYPE I
*" VALUE(I_Y) TYPE I
*" EXPORTING
*" VALUE(E_Z) TYPE I
*" EXCEPTIONS*" EXCEPTION1*"----------------------------------------------------------------------
E_Z = I_X + I_Y.
call function 'ZFM50'
destination 'BACK'
exporting
x = e_z.
ENDFUNCTION.
IN 6.0:
SE37:ZFM50
7/31/2019 Cross Apps
16/192
16 | P a g e S a n t o s h P
SOURCE CODE:
REPORT ZCALLRFCBACK.
datamtypei.
callfunction'Z915FM1'destination '915DEST'
exportingi_x = 10i_y = 20
importinge_z = m.
IN 6.0:
CALL PROGRAM:
REPORT ZCALLRFCBACK.
datamtypei.
callfunction'Z915FM1'
destination '915DEST'
exporting
i_x = 10i_y = 20
7/31/2019 Cross Apps
17/192
17 | P a g e S a n t o s h P
importing
e_z = m.
OUT PUT:
7/31/2019 Cross Apps
18/192
18 | P a g e S a n t o s h P
ALE/IDOCSALE: Application Link Enabling.
IDOCS: Intermediate Document.
ALE is a technology of SAP used for implementing Distributed Process.Distributed Process: It is the process in which a process of a task is performed in multiple systems. By using ALE we can configuredistribute & post the IDOCS to multiple receivers from SAP system. These receivers can be either SAP (OR) NON-SAP systems.
IDOCS: It is a container of data which can carry the data from one system to another. IDOC is SAPs own format of data which can be
understood only by SAP system.
7/31/2019 Cross Apps
19/192
19 | P a g e S a n t o s h P
XI: Exchange Infrastructure.
IDOCS Related Objects:
1) Logical Systems.2) RFC Destination.3) Port Number.4) Message Type.5) IDOC Type.6) Partner Profile.7) Outbound Parameter.8) Inbound Parameter.9) Selection Program.10) Inbound Program.11) Process Code.
Logical Systems:
It is the unique name assigned for a sender & receiver system involved ALE communication. It can also be called Alias providedfor IP Address.
Logical System is client independent object. Logical System is stored in the table TBDLS & TBDLST. T-Code for creating Logical System SALE, BD54.
RFC Destination:
It stores the Physical details of receiver system. RFC Destination is stored in the table RFCDES. T-Code for creating RFC Destination SALE, SM59.
Port Number:
It is unique number used for identifying a Resource on the system. A resource can be a file , Input (OR) output device. Port Number is stored in the table EDIPO. T-Code for creating Port NumberWE21.
Message Type:
It indicates the type of data stored in the IDOC. Message type is client Independent. Message type is stored in the table EDMSG
7/31/2019 Cross Apps
20/192
20 | P a g e S a n t o s h P
T-Code for creating Message typeWE81.
IDOC Type:
IDOC Types is a collection of segments. Segment is a structure which is a collection of fields. T-Code for SegmentsWE82. IDOC Type doesnt hold any data it only provides template. The instance of IDOC Type is IDOC.
Partner Profile:
It holds the details of the partner system. A partner profile is client dependent object. Partner Profile is stored in the table EDPP1. T-Code for creating Port NumberWE20.
Outbound Parameters:
It is always created in sender system and it is a collection of message type, Receiver Port & IDOC Type.Inbound Parameters:
It is always created AT THE Receiver side and it is a collection of message type & Process Code.
Selection Program:
7/31/2019 Cross Apps
21/192
21 | P a g e S a n t o s h P
It is also called as outbound program. It is responsible for retrieving the data from sender system database, generating theIDOCS & Distributing the IDOCS.
It always executes in sender system.
Inbound Program:
It is also called as posting program it is always executed in receiver system. It is responsible for reading the incoming IDOC Data & Updating the data to the receiver Database.
Process Code:
It is an identifier for inbound program. It is usually the first four characters ofMessage Type. T-Code for creating Process Code WE41 Outbound Process Code.
WE42 Inbound Process Code.
Note:
Inbound is generally a function module (OR) A workflow Task.
Class 4: 02.08.2011
Requirement: Distribute materials from one client to another Client.
SENDER: 800 RECIVER: 811
Steps at sender side (800).
1) Create two Logical Systems.2) Assign Logical system to clients.3) Create RFC Destination.4) Create Port.5) Identify the Message type and IDOC Type.6) Create Model view.7) Assign Message type to Model view.8) Create partner Profile for Sender.9) Assign outbound parameters.
Steps at sender side (811).
10) Create Partner profile for receiver.11) Assign inbound Parameters.
7/31/2019 Cross Apps
22/192
22 | P a g e S a n t o s h P
Steps at sender side (800).
12) Identify the Objects to be distributed.13) Run the selection program.14) Check the IDOCS generated.15) Process the IDOCS if any errors in Distribution.
Steps at sender side (811).
16) Check the IDOCS Received.17) Process the IDOCS if any errors in Posting.
Model view: An object which encapsulates the sender and receiver information along with the message type.
PROGRAM: IN Client (800)
1) Create two Logical Systems.
2) Assign Logical system to clients.
7/31/2019 Cross Apps
23/192
23 | P a g e S a n t o s h P
7/31/2019 Cross Apps
24/192
24 | P a g e S a n t o s h P
SAVE.
3) Create RFC Destination.
7/31/2019 Cross Apps
25/192
25 | P a g e S a n t o s h P
7/31/2019 Cross Apps
26/192
26 | P a g e S a n t o s h P
4) Create Port.WE21:
7/31/2019 Cross Apps
27/192
27 | P a g e S a n t o s h P
Note: Transactional RFC Port is always create on top of RFC Destination.
5) Identify the Message type and IDOC Type.Identify the Message Type and IDOC Type.
6) Create Model view.
7/31/2019 Cross Apps
28/192
28 | P a g e S a n t o s h P
7) Assign Message type to Model view.In the same screen.
7/31/2019 Cross Apps
29/192
29 | P a g e S a n t o s h P
CONTINUE.
SAVE.
8) Create partner Profile for Sender.Note: Partner profile is created on top of Logical system.
WE20:
7/31/2019 Cross Apps
30/192
30 | P a g e S a n t o s h P
9) Assign outbound parameters.
SAVE--------BACK--------SAVE--------BACK
IN Client (811):
Steps at sender side (811).
10) Create Partner profile for receiver.
7/31/2019 Cross Apps
31/192
31 | P a g e S a n t o s h P
WE20:
11) Assign inbound Parameters.
IN Client (800):
Steps at sender side (800).
Note: Check the Materials if available (OR) Create New Materials.
12) Identify the Objects to be distributed.
13) Run the selection program.
7/31/2019 Cross Apps
32/192
32 | P a g e S a n t o s h P
Hear we will get Messages.
14) Check the IDOCS generated.
7/31/2019 Cross Apps
33/192
33 | P a g e S a n t o s h P
15) Process the IDOCS if any errors in Distribution.Check for the errors. In the current program there are no errors.
Steps at sender side (811).
16) Check the IDOCS Received.
7/31/2019 Cross Apps
34/192
34 | P a g e S a n t o s h P
17) Process the IDOCS if any errors in Posting.Hence there are no errors in the current program no need of this step.
Class 5: 03.08.2011
Note:Every IDOC is a 16Degit Number associated with 3 records.
1) Control Record.2) Data Record.3) Status Record.
Control Record:
A control record is like a envelope of a letter which contains Sender and Receiver Information.
7/31/2019 Cross Apps
35/192
35 | P a g e S a n t o s h P
This includes Sender and Receiver Logical System, Port Number, IDOC Type, Message Type and Direction. Control Record Information is stored in the table EDIDC.
Data Record:
It contains the actual data ofIDOC. It is associated with two Sections.1) Administration Section.2) Data Section.
Administration Section: Administration Section contains segment information like Segment Name and Segment Number.
Data Section: Contains the actual section of the IDOC.
Data record information is stored in the table EDID2. The actual contents of the IODC are stored in the field SDATA it is of type LCHR.
Status Record:
It contains the status of the IDOC during its journey from sender to receiver. Status Record information is stored in the table EDIDS. For every status there is an associated status code. The status code can be accessed using the T-Code WE47.
Processing the error IDOC:
Whenever an IDOC is generated (OR) receive is error status. As a developer we need to analyze the error and identify. Weatherit us functional issue (OR) Technical issue.
If it is a functional issue the functional consultant need to configure functional settings and after this ABAP-consultant isresponsible for processing the error IDOC by using the T-Code BD87 (OR) WE19.
T137: Table which stores the Industrial Sector.
BD87: This T-Code Process the existing IDOC, without generating the new IDOC.
WE19: Ignores the error IDOC & generates new IDOC.
PROGRAM:
IN Client 800:
Create a material in (800) with material type which does not exist in (811).
915MA4
BD10:
7/31/2019 Cross Apps
36/192
36 | P a g e S a n t o s h P
WE02:
7/31/2019 Cross Apps
37/192
37 | P a g e S a n t o s h P
IN Client 811:
Double Click on the IDOC.
7/31/2019 Cross Apps
38/192
38 | P a g e S a n t o s h P
Double Click on Status 51.
To check the error Click on Application Log
7/31/2019 Cross Apps
39/192
39 | P a g e S a n t o s h P
To solve this error go to SPRO
7/31/2019 Cross Apps
40/192
40 | P a g e S a n t o s h P
BD87 (OR) WE19.
BD87:
Choose the node and Execute.
7/31/2019 Cross Apps
41/192
41 | P a g e S a n t o s h P
The status of the errors will change from 51 to 53.
IDOC Filtering: It is the Process of filtering IDOCS at various levels, IDOC filters are of3 types.
1) Data Level Filtering.2) Segment Level Filtering.3) IDOC Reduction.
Data Level Filtering: This is configured at sender level at Model View Level.
Note:
Whenever a selection Program is executed depending on the range of the objects given. The selection program returns thecorresponding data from sender database and generates the Application Number of Master IDOC.
This Master IDOCS are stored at Operating System Level and they are sent to ALE Layer. ALE Layer executes the data filter conditions maintained at Model View Level and generates the appropriate number of
Communication IDOC.
These Communication IDOCS stored at database level, which are then distributed to the communication Layer. This Communication Layer is responsible for distributing the communication IDOCS.
Data Level Filtering:PROGRAM:
Create Some Materials.
7/31/2019 Cross Apps
42/192
42 | P a g e S a n t o s h P
BD64
Select the Particular Model View, Expand it and Double Click on No Filter Set.
7/31/2019 Cross Apps
43/192
43 | P a g e S a n t o s h P
Click Create filter group.
7/31/2019 Cross Apps
44/192
44 | P a g e S a n t o s h P
Double Click on Material Type
Continue.
Continue.
Save.
BD10:
7/31/2019 Cross Apps
45/192
45 | P a g e S a n t o s h P
Hear we can see only 3 IDOCS are created and 2 IDOCS are communicated.
7/31/2019 Cross Apps
46/192
46 | P a g e S a n t o s h P
IN Client 811:
Check the receiver status.
WE02:
7/31/2019 Cross Apps
47/192
47 | P a g e S a n t o s h P
We can check in it in SE11 in MARA TABLE
7/31/2019 Cross Apps
48/192
48 | P a g e S a n t o s h P
Class 6: 04.08.2011
Segment Level Filtering: It is the Process of filtering a Segment whenever a IDOC is generated between Sender and Receiver. T-code is
BD56:
Pre-requisites :
Sender and Receiver Partner Profile should be available at the sender system. Mandatory Segments cannot be filtered. A segment filtering is always configured at Sender side.
PROGRAM:
BD56:
Continue.
New Entries.
7/31/2019 Cross Apps
49/192
49 | P a g e S a n t o s h P
Sender and Receiver Partner Profile should be available at the sender system, so we must create the partner profile.
WE20:
7/31/2019 Cross Apps
50/192
50 | P a g e S a n t o s h P
SAVE.
BD56.
7/31/2019 Cross Apps
51/192
51 | P a g e S a n t o s h P
Now the Segment filter is Created.
BD10.
WE02:
7/31/2019 Cross Apps
52/192
52 | P a g e S a n t o s h P
Double Click on the error and check the status of the error.
7/31/2019 Cross Apps
53/192
53 | P a g e S a n t o s h P
Click on status record 29.
By observing the above Process we came to know that Segment filtering cannot be done on mandatory segments, so we can do the
segment filtering only on Non-Mandatory fields.
To know the status of the segments go to SW30.
7/31/2019 Cross Apps
54/192
54 | P a g e S a n t o s h P
BD10:
7/31/2019 Cross Apps
55/192
55 | P a g e S a n t o s h P
Execute.
WE20.
7/31/2019 Cross Apps
56/192
56 | P a g e S a n t o s h P
Change Pointer: Change Pointers are used for tracking the changes made to master data. To track these changes, change pointer must
be activated at 3 levels.
1) Globally (BD61).2) Message Type Level (BD50).3) Field Level (BD52).
Once the change pointers are activated the changes made to master data will be tracked in fallowing tables.
1) CDHDR2) CDPOS3) BDCP4) BDCPS
We can distribute the changes in two ways.
1) Using Program RBDMIDOC.2) Using T-Code BD21.
PROGRAM:
Globally: BD61
7/31/2019 Cross Apps
57/192
57 | P a g e S a n t o s h P
Message Type Level: BD50
Field Level: BD52
7/31/2019 Cross Apps
58/192
58 | P a g e S a n t o s h P
BD21:
Once again check the status by T-Code.
7/31/2019 Cross Apps
59/192
59 | P a g e S a n t o s h P
Now create some materials and make changes in some materials.
Made Changes in 800MAT10
BD21:
Change Pointer at Field Level:
7/31/2019 Cross Apps
60/192
60 | P a g e S a n t o s h P
Then make changes at the field level in the Material field MAKTX.
BD21:
Class 7: 05.08.2011
CUSTOM IDOCS:
We go for custom IDOCS whenever we want to distribute custom specific data to the receiver, This customer specific
data will be stored in custom tables.
7/31/2019 Cross Apps
61/192
61 | P a g e S a n t o s h P
Sender ------800 Receiver -----------811
Steps for creating the custom IDOCS:
Sender Side Client (800):
1) Create two logical systems.BD54 (0R) SALE.
7/31/2019 Cross Apps
62/192
62 | P a g e S a n t o s h P
2) Assign Logical System to client.SCC4 (OR) SALE.
7/31/2019 Cross Apps
63/192
63 | P a g e S a n t o s h P
3) Creating RFC Destination.SM59 (OR) SALE.
7/31/2019 Cross Apps
64/192
64 | P a g e S a n t o s h P
SAVE.
4) Create TRFC Port.WE21.
SAVE.
As in the above figure we must create Segment, IDOC Type and Message Type.
5) Create Segment. (7 Characters)WE31.
7/31/2019 Cross Apps
65/192
65 | P a g e S a n t o s h P
SAVE.
Qualified Segment:
If this checkbox is selected, the segment will prefix with value of the primary key field when the IDOCS are displayed.
Back to initial Screen.
7/31/2019 Cross Apps
66/192
66 | P a g e S a n t o s h P
After selecting Set Release.
6) Create IDOC Type. (8 Characters)WE30.
7/31/2019 Cross Apps
67/192
67 | P a g e S a n t o s h P
Now put the cursor on IDOC Type and Create Segment.
7/31/2019 Cross Apps
68/192
68 | P a g e S a n t o s h P
SAVE.
Back to initial screen.
Yes.
7) Create Message type.(6 Characters)WE81.
7/31/2019 Cross Apps
69/192
69 | P a g e S a n t o s h P
CONTINUE.
SAVE.
8) Link Message Type to IDOC Type.WE82.
7/31/2019 Cross Apps
70/192
70 | P a g e S a n t o s h P
SAVE.
9) Create Model View.BD64 (OR) SALE.
CONTINUE.
10) Assign Message Type to Model View.
7/31/2019 Cross Apps
71/192
71 | P a g e S a n t o s h P
CONTINUE.
SAVE.
11) Create Partner profile for Sender.WE20.
12) Assign the outbound parameter.In The Same Screen.
7/31/2019 Cross Apps
72/192
72 | P a g e S a n t o s h P
SAVE.
7/31/2019 Cross Apps
73/192
73 | P a g e S a n t o s h P
Receiver Side Client (811):
1) Create Partner profile for Receiver.WE20.
SAVE.
2) Assign Inbound Parameters.Note: To receive a profile we must assign inbound parameters at receiver side, to assign the inbound parameters we need message
type and process code.
Process code is assigned with function module IDOC_INPUT_MATMAS01.this function module is responsible to read the message type.
by reading the message type the receiver it will decrypt the idoc(segments)
In the current we are creating custom idoc so we need custom function module.
a) Creating the custom function module.SE37.
Note: Function module is not client dependent so we can create it anywhere.
7/31/2019 Cross Apps
74/192
74 | P a g e S a n t o s h P
Copy.
Delete the total source code.SAVE.
b) Linking the function module with message type & IDOC Type.WE57.
7/31/2019 Cross Apps
75/192
75 | P a g e S a n t o s h P
c) Registering Function Module as Inbound Parameter.Note: If we forget to register the function module with inbound parameter, this function module is not available to link with the
process code.
BD51.
7/31/2019 Cross Apps
76/192
76 | P a g e S a n t o s h P
d) Creating inbound process code and Link with inbound function module.WE42.
7/31/2019 Cross Apps
77/192
77 | P a g e S a n t o s h P
7/31/2019 Cross Apps
78/192
78 | P a g e S a n t o s h P
Note: Now we are eligible to assign the inbound parameters to receiver system.
Assign Inbound Parameters.
WE20.
Class 8: 06.08.2011
Note: At the Sender side create a database table for storing the customer specific data.
7/31/2019 Cross Apps
79/192
79 | P a g e S a n t o s h P
Sender Objects:
Logical System : METSEND
RFC Destination : METDEST
Segment : ZMETSEG
IDOC Type : ZMETIDOC
Message Type : METMSG
Port Number : A000000264
Model View : METMODEL
Partner Profile : METREC
Receiver Objects:
Logical System : METREC
Partner Profile : METSEND
Function Module : ZMET_READ_DEPARTMENT
Process Code : METM
Sender Side Client (800):
Process for Selection Program:
1) Generate the selection screen for accepting the range of business objects, Message and receiver logical system.2) Prepare the control Record.3) Prepare the Data Record.4) Generate and Distribute the IDOC by calling the Function Module MASTER_IDOC_DISTRIBUTE.13) Create selection program.
ZMATSENDERDEPT :( Program)
REPORT ZMATSENDERDEPT.
DATA : P_DEPTNO TYPE Z915DEPT-DEPTNO. " SELECTION SCREE FOR ACCEPTING THE INPUT
SELECTION-SCREENBEGINOFBLOCK B1 WITHFRAMETITLETEXT-001.
SELECT-OPTIONS : SO_DEPNO FOR P_DEPTNO.
PARAMETERS : P_MESTYP LIKE EDMSG-MSGTYP OBLIGATORY DEFAULT'METMSG',
P_LOGSYS LIKE TBDLST-LOGSYS.
SELECTION-SCREENENDOFBLOCK B1.
* PREPARING CONTROL RECORD
DATA : LS_CONT_REC TYPE EDIDC.
IF P_LOGSYS = SPACE.
LS_CONT_REC-RCVPRT = SPACE.
ELSE.
LS_CONT_REC-RCVPRT = 'LS'.
ENDIF.
LS_CONT_REC-RCVPRN = P_LOGSYS.
LS_CONT_REC-MESTYP = P_MESTYP.
LS_CONT_REC-IDOCTP = 'ZMETIDOC'.
* END OF CONTROL RECORD
7/31/2019 Cross Apps
80/192
80 | P a g e S a n t o s h P
* PREPARING DATA RECORD
TYPES : BEGINOF TY_DEPT.
INCLUDESTRUCTURE Z915DEPT.
TYPES ENDOF TY_DEPT.
DATA : LT_DEPT TYPESTANDARDTABLEOF TY_DEPT,LS_DEPT TYPE TY_DEPT.
DATA : LS_DEPT_SEG TYPE ZMETSEG.
DATA : LT_DATA_REC TYPESTANDARDTABLEOF EDIDD,
LS_DATA_REC TYPE EDIDD.
DATA : LT_COMM_IDOC TYPESTANDARDTABLEOF EDIDC,
LS_COMM_IDOC TYPE EDIDC.
*READING THE APPLICATION DATA FROM ADATBASE
SELECT * FROM Z915DEPT
INTOTABLE LT_DEPT
WHERE DEPTNO IN SO_DEPNO.
IF SY-SUBRC EQ0.
LOOPAT LT_DEPT INTO LS_DEPT.
" PREPARING MASTER IDOC
LS_DEPT_SEG-DEPNO = LS_DEPT-DEPTNO.
LS_DEPT_SEG-DEPNAME = LS_DEPT-DNAME.
LS_DEPT_SEG-DEPLOC = LS_DEPT-LOC.
LS_DATA_REC-SEGNAM = 'ZMETSEG'.
LS_DATA_REC-SDATA = LS_DEPT_SEG.
APPEND LS_DATA_REC TO LT_DATA_REC."TRANSFERING THE CONTROL RECORD AND CONTROL RECORD TO ALE SERVICE LAYER
CALLFUNCTION'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = LS_CONT_REC
tables
communication_idoc_control = LT_COMM_IDOC
master_idoc_data = LT_DATA_REC.
IF SY-SUBRC EQ0.
COMMITWORK.
REFRESH LT_DATA_REC.
ENDIF.
ENDLOOP.
ENDIF.
IF LT_COMM_IDOC ISNOTINITIAL.
LOOPAT LT_COMM_IDOC INTO LS_COMM_IDOC.
WRITE :/ LS_COMM_IDOC-DOCNUM.
ENDLOOP.
ENDIF.
EXECUTE.
7/31/2019 Cross Apps
81/192
81 | P a g e S a n t o s h P
MESSAGE.
Process of Inbound Program:
As Part of the inbound program. We need to use the parameter IDOC_DATA. This parameter carries the actual data of theIDOC.
We need to use the internal table parameter, Extract the data stored in SDATA field and update the same to correspondingdatabase table.
Writing the code in Function Module: (ZMET_READ_DEPARTMENT)
Source Code:
FUNCTION ZMET_READ_DEPARTMENT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" VALUE(NO_APPLICATION_LOG) LIKE SY-DATAR OPTIONAL*" VALUE(MASSSAVEINFOS) LIKE MASSSAVINF STRUCTURE MASSSAVINF
*" OPTIONAL
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
7/31/2019 Cross Apps
82/192
82 | P a g e S a n t o s h P
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------
DATA : WA_DATA TYPE EDIDD,
WA_STATUS TYPE BDIDOCSTAT,
WA_DEPT_SEG TYPE ZMETSEG,
WA_DEPT_TABLE TYPE Z915DEPT.LOOPAT IDOC_DATA INTO WA_DATA.
CASE WA_DATA-SEGNAME.
WHEN'ZMETSEG'.
WA_DEPT_SEG = WA_DATA-SDATA.
MOVE-CORRESPONDING WA_DEPT_SEG TO WA_DEPT_TABLE.
ENDCASE.
ENDLOOP.
MODIFY Z915DEPT FROM WA_DEPT_TABLE.
IF SY-SUBRC EQ0.
WA_STATUS-DOCNUM = WA_DATA-DOCNUM.
WA_STATUS-STATUS = 53.
WA_STATUS-MSGTY = 'METMSG'.
APPEND WA_STATUS TO IDOC_STATUS.
ELSE.
WA_STATUS-DOCNUM = WA_DATA-DOCNUM.
WA_STATUS-STATUS = 51.
WA_STATUS-MSGTY = 'METMSG'.
APPEND WA_STATUS TO IDOC_STATUS.
ENDIF.
ENDFUNCTION.
WE19:
7/31/2019 Cross Apps
83/192
83 | P a g e S a n t o s h P
BAPI
BUSINESS APPLICATION PROGRAMING INTERFACE
BAPI:
BAPI is a remote function module for an ABAP Consultant and API METHOD for a Legacy programmer.API: Application Programming Interface.
BAPIs are used for accessing the SAP business objects from ABAP Application as well as from Legacy Application. All thebusiness objects are stored in BOR.
BOR: Business objects Repository.
BAPI: Is the T-Code. Every business object is associated with remote function module and an API Method. As long as we access business objects from legacy Application we us API Method and if the access in from SAP. We use BAPI
function module.
All the BAPI function modules start with naming convention BAPI_.
TOPICS:
Standard BAPIs. Enhance Standard BAPIs. BAPI Modification. Custom BAPI Creation and Access from SAP / NONSAP. LSMW using BAPI. Transporting LSMW.
7/31/2019 Cross Apps
84/192
84 | P a g e S a n t o s h P
BAPI
7/31/2019 Cross Apps
85/192
85 | P a g e S a n t o s h P
In SAP FI/CO, SD, MM data is stored in the form of header data and item data. IN SAP HR in the form of Infotypes and they are stored in the table T777D.
Time Constraints:
Xyz-
12th
August 2011 to 20th
June 2012---------------Project1
29th
July 2011 to 30th
September 2012---------------Project2
No Overlapping No Gaps. No Overlapping gaps are allowed No gaps and Overlapping is allowed
7/31/2019 Cross Apps
86/192
86 | P a g e S a n t o s h P
PA30: T-Code Used for maintaining HR Master Data.
P0006: Table which captures the employee addresses details.
USRID_LONG --- CHAR (241): It stores the Email ID.
Flat File :( With tabbed space)
7/31/2019 Cross Apps
87/192
87 | P a g e S a n t o s h P
Requirement:
Uploading Employee Communication details to SAP using BAPI.BAPI:
Business Object Name : EmplCommunication.
Object Type : EMPLCOMM.
Note: Every business object will be associated with different types of operations.
Create Change, Delete and Retrieval.
Method : Create.
Function Module : BAPI_EMPLCOMM_CREATE.
7/31/2019 Cross Apps
88/192
88 | P a g e S a n t o s h P
Note:
If an ALV Message Type is associated with BAPI. Then we can use that BAPI with LSMW integration. Every BAPI is a Remote Function Module. But every remote function module may not be a BAPI.
Note: Every BAPI function module contains a returning parameter of type BAPIRETURN1 (OR) BAPIRETURN (OR) BAPIRET1 (OR)
BAPIRET2.
7/31/2019 Cross Apps
89/192
89 | P a g e S a n t o s h P
PROGRAM:
REPORT ZCNUBAPI1.
*PROGRAM : ZCNUBAPI1
*AUTHOR : CNU
*START DATA : 12.08.2011
*PURPOSE : Bapi To Upload Employee Communication Details.
*OPERATION : BAPI TO UPLOAD EMPLOYEE COMMUNICATION DETAILS.
*COPIED FROM : NA (or) REF.PROGRAM
********************************************************************************************
DATA : LT_FILETABLE TYPE FILETABLE,LV_FILETABLE TYPE FILE_TABLE.
DATA : LV_RC TYPEI.
DATA : FNAME TYPE STRING.
TYPES : BEGINOF TY_COMM,
PERNR TYPE PA0105-PERNR,
BEGDA TYPE PA0105-BEGDA,
ENDDA TYPE PA0105-ENDDA,
USRID_LONG TYPE PA0105-USRID_LONG,
ENDOF TY_COMM.
DATA : LT_COMM TYPESTANDARDTABLEOF TY_COMM,LS_COMM TYPE TY_COMM.
DATA : LS_RETURN TYPE BAPIRETURN1.
CALLMETHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = LT_FILETABLE
rc = LV_RC.
IF LT_FILETABLE[] ISNOTINITIAL.
READTABLE LT_FILETABLE INTO LV_FILETABLE INDEX1.
IF SY-SUBRC EQ0.
FNAME = LV_FILETABLE-FILENAME.
CALLMETHOD cl_gui_frontend_services=>gui_upload
EXPORTING
FILENAME = FNAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
CHANGING
data_tab = LT_COMM[].
ENDIF.
ENDIF.
IF LT_COMM ISNOTINITIAL.LOOPAT LT_COMM INTO LS_COMM.
PERFORM LOCKEMPLOYEE.
7/31/2019 Cross Apps
90/192
90 | P a g e S a n t o s h P
IF LS_RETURN-TYPENE'E'.
PERFORM CREATEEMAIL.
WRITE :/'Employee No:',LS_COMM-PERNR,
/ LS_RETURN-TYPE,
/ LS_RETURN-MESSAGE.
SKIP2.
PERFORM UNLOCKEMPLOYEE.ENDIF.
ENDLOOP.
ENDIF.
form CREATEEMAIL .
CLEAR LS_RETURN.
CALLFUNCTION'BAPI_EMPLCOMM_CREATE'
EXPORTING
employeenumber = LS_COMM-PERNR
subtype = '0010'
validitybegin = LS_COMM-BEGDA
validityend = LS_COMM-ENDDA
COMMUNICATIONID = LS_COMM-USRID_LONG
IMPORTING
RETURN = LS_RETURN.
endform. " CREATEEMAIL
form LOCKEMPLOYEE .
CLEAR LS_RETURN.
CALLFUNCTION'BAPI_EMPLOYEET_ENQUEUE'
EXPORTING
number = LS_COMM-PERNRvaliditybegin = '19000101'
IMPORTING
RETURN = LS_RETURN.
endform. " LOCKEMPLOYEE
form UNLOCKEMPLOYEE .
CALLFUNCTION'BAPI_EMPLOYEET_DEQUEUE'
EXPORTING
number = LS_COMM-PERNR
validitybegin = '19000101'
IMPORTING
RETURN = LS_RETURN.
endform. " UNLOCKEMPLOYEE
7/31/2019 Cross Apps
91/192
91 | P a g e S a n t o s h P
OUTPUT:
Uploading the bank details using BAPI.
BAPI_TRANSACTION_COMMIT: Execute external Commit when using BAPIs.
PROGRAM:
*PROGRAM : ZCNUBAPI2
*AUTHOR : CNU
*START DATA : 13.08.2011
*PURPOSE : Uploading Bank Details Using BAPI.*OPERATION : UPLOADING BANK DETAILS USING BAPI.
*COPIED FROM : NA (or) REF.PROGRAM
********************************************************************************************
REPORT ZCNUBAPI2.
PARAMETERS : P_BCTRY TYPE BAPI1011_KEY-BANK_CTRY,
P_BKEY TYPE BAPI1011_KEY-BANK_KEY.
DATA : LS_BADDR TYPE BAPI1011_ADDRESS.
DATA : LS_RETURN TYPE BAPIRET2.
CLEAR LS_BADDR.
LS_BADDR-BANK_NAME = 'SBI571 bank'.
7/31/2019 Cross Apps
92/192
92 | P a g e S a n t o s h P
LS_BADDR-REGION = '01'.
LS_BADDR-STREET = 'MALAKPET'.
LS_BADDR-CITY = 'HYDERABAD'.
CALLFUNCTION'BAPI_BANK_CREATE'
EXPORTING
bank_ctry = P_BCTRYBANK_KEY = P_BKEY
bank_address = LS_BADDR
IMPORTING
RETURN = LS_RETURN.
CALLFUNCTION'BAPI_TRANSACTION_COMMIT'.
WRITE:/ LS_RETURN-TYPE,
LS_RETURN-MESSAGE.
Note: Before executing the Program check number of entries in the table.
Execute.
7/31/2019 Cross Apps
93/192
93 | P a g e S a n t o s h P
Note: Check number of entries in the table.
Check For the entry.
7/31/2019 Cross Apps
94/192
94 | P a g e S a n t o s h P
Changing the Bank Details.
Note:
Some of the Change BAPIs are associated with the Update flag Parameter. This parameters ends with X. As part of these parameters we need to set the flag for the field which needs to be updated.
PROGRAM:
REPORT ZCNUBAPI3.
*PROGRAM : ZCNU_ALV2
*AUTHOR : CNU
*START DATA : 18.07.2011
*PURPOSE : Using BAPI To Update Bank Details.
*OPERATION : USING BAPI TO UPDATE BANK DETAILS.
*COPIED FROM : NA (or) REF.PROGRAM
********************************************************************************************
DATA : LV_BCTRY TYPE BAPI1011_KEY-BANK_CTRY VALUE'IN',
LV_BKEY TYPE BAPI1011_KEY-BANK_KEY VALUE'CBB',
LS_BADDR TYPE BAPI1011_ADDRESS,
LS_BADDRX TYPE BAPI1011_ADDRESSX,
LS_RETURN TYPE BAPIRET2.
LS_BADDR-BANK_NAME = 'Central Bank of Bodhan'.
LS_BADDR-STREET = 'Bodhan'.
LS_BADDRX-BANK_NAME = 'X'.
LS_BADDRX-STREET = 'X'.
CALLFUNCTION'BAPI_BANK_CHANGE'EXPORTING
bankcountry = LV_BCTRY
bankkey = LV_BKEY
bank_address = LS_BADDR
bank_addressx = LS_BADDRX
IMPORTING
RETURN = LS_RETURN.
CALLFUNCTION'BAPI_TRANSACTION_COMMIT'.
WRITE : / LS_RETURN-TYPE,LS_RETURN-MESSAGE.
Execute.
7/31/2019 Cross Apps
95/192
95 | P a g e S a n t o s h P
Check number of entries in the table.
Uploading the master data using BAPI:
1) Accepting the parameter of type IBIPPARMS-PATH.
PARAMETERS : P_FILE TYPE IBIPPARMS-PATH.
Execute and check.
2) Getting the F4 Help Functionality for the field P_FILEin the Program.
7/31/2019 Cross Apps
96/192
96 | P a g e S a n t o s h P
PARAMETERS : P_FILE TYPE IBIPPARMS-PATH.
AT SELECTION-SCREENONVALUE-REQUEST FOR P_FILE.
CALLFUNCTION'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROGDYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
Execute and check.
Flat File: Data.
7/31/2019 Cross Apps
97/192
97 | P a g e S a n t o s h P
3) Extracting data from flat file.PARAMETERS : P_FILE TYPE IBIPPARMS-PATH.
DATA : FNAME TYPE STRING.
TYPES : BEGINOF TY_LEGACY,
STR(100) TYPEC,
ENDOF TY_LEGACY.
DATA : LT_LEGACY TYPESTANDARDTABLEOF TY_LEGACY,
LS_LEGACY TYPE TY_LEGACY.
START-OF-SELECTION.
FNAME = P_FILE.
CALLFUNCTION'GUI_UPLOAD'
EXPORTING
filename = FNAME
FILETYPE = 'ASC'
tables
data_tab = LT_LEGACY[].
AT SELECTION-SCREENONVALUE-REQUEST FOR P_FILE.
CALLFUNCTION'F4_FILENAME'EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
4) Split the data in to the local table.TOTAL CODE:
REPORT ZCNUBAPI4.
*PROGRAM : ZCNUBAPI4
7/31/2019 Cross Apps
98/192
98 | P a g e S a n t o s h P
*AUTHOR : CNU
*START DATA : 13.08.2011
*PURPOSE : Upload Material Data Using BAPI.
*OPERATION : UPLOAD MATERIAL DATA USING BAPI.
*COPIED FROM : NA (or) REF.PROGRAM
********************************************************************************************
PARAMETERS : P_FILE TYPE IBIPPARMS-PATH.
DATA : FNAME TYPE STRING.
TYPES : BEGINOF TY_LEGACY,
STR(100) TYPEC,
ENDOF TY_LEGACY.
DATA : LT_LEGACY TYPESTANDARDTABLEOF TY_LEGACY,
LS_LEGACY TYPE TY_LEGACY.
TYPES : BEGINOF TY_MATERIAL,
MATERIAL TYPE BAPIMATHEAD-MATERIAL,
IND_SECTOR TYPE BAPIMATHEAD-IND_SECTOR,
MATL_TYPE TYPE BAPIMATHEAD-MATL_TYPE,
MATL_GROUP TYPE BAPI_MARA-MATL_GROUP,
BASE_UOM TYPE BAPI_MARA-BASE_UOM,
LANGU TYPE BAPI_MAKT-LANGU,
LANGU_ISO TYPE BAPI_MAKT-LANGU_ISO,
MATL_DESC TYPE BAPI_MAKT-MATL_DESC,
ENDOF TY_MATERIAL.
DATA : LT_MATERIAL TYPESTANDARDTABLEOF TY_MATERIAL,
LS_MATERIAL TYPE TY_MATERIAL.
DATA : LS_MATHED TYPE BAPIMATHEAD,
LS_BAPI_MARA TYPE BAPI_MARA,
LA_BAPI_MARAX TYPE BAPI_MARAX,
LS_RETURN TYPE BAPIRET2.
DATA : LT_MAKT TYPETABLEOF BAPI_MAKT,
LS_MAKT TYPE BAPI_MAKT .
START-OF-SELECTION.
FNAME = P_FILE.
CALLFUNCTION'GUI_UPLOAD'
EXPORTING
filename = FNAME
FILETYPE = 'ASC'
tables
data_tab = LT_LEGACY[].
IF LT_LEGACY[] ISNOTINITIAL.
LOOPAT LT_LEGACY INTO LS_LEGACY.
SPLIT LS_LEGACY-STR AT','INTO
LS_MATERIAL-MATERIAL
LS_MATERIAL-IND_SECTORLS_MATERIAL-MATL_TYPE
LS_MATERIAL-MATL_GROUP
7/31/2019 Cross Apps
99/192
99 | P a g e S a n t o s h P
LS_MATERIAL-BASE_UOM
LS_MATERIAL-LANGU
LS_MATERIAL-LANGU_ISO
LS_MATERIAL-MATL_DESC.
APPEND LS_MATERIAL TO LT_MATERIAL.
ENDLOOP.
ENDIF.
IF LT_MATERIAL[] ISNOTINITIAL.
LOOPAT LT_MATERIAL INTO LS_MATERIAL.
LS_MATHED-MATERIAL = LS_MATERIAL-MATERIAL.
LS_MATHED-IND_SECTOR = LS_MATERIAL-IND_SECTOR.
LS_MATHED-MATL_TYPE = LS_MATERIAL-MATL_TYPE.
LS_MATHED-BASIC_VIEW = 'X'.
LS_BAPI_MARA-MATL_GROUP = LS_MATERIAL-MATL_GROUP.
LS_BAPI_MARA-BASE_UOM = LS_MATERIAL-BASE_UOM.
LA_BAPI_MARAX-MATL_GROUP = 'X'.
LA_BAPI_MARAX-BASE_UOM = 'X'.
REFRESH LT_MAKT.
LS_MAKT-LANGU = LS_MATERIAL-LANGU.
LS_MAKT-LANGU_ISO = LS_MATERIAL-LANGU_ISO.
LS_MAKT-MATL_DESC = LS_MATERIAL-MATL_DESC.
APPEND LS_MAKT TO LT_MAKT.
CALLFUNCTION'BAPI_MATERIAL_SAVEDATA'
EXPORTINGheaddata = LS_MATHED
CLIENTDATA = LS_BAPI_MARA
CLIENTDATAX = LA_BAPI_MARAX
IMPORTING
RETURN = LS_RETURN
TABLES
MATERIALDESCRIPTION = LT_MAKT.
CALLFUNCTION'BAPI_TRANSACTION_COMMIT'.
WRITE : / LS_MATERIAL-MATERIAL,
/ LS_RETURN-TYPE,
/ LS_RETURN-ID,
/ LS_RETURN-NUMBER,
/ LS_RETURN-MESSAGE.
ENDLOOP.
ENDIF.
AT SELECTION-SCREENONVALUE-REQUEST FOR P_FILE.
CALLFUNCTION'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNRIMPORTING
FILE_NAME = P_FILE.
7/31/2019 Cross Apps
100/192
100 | P a g e S a n t o s h P
OUTPUT:
CUSTOM BAPIs:
PROCEDURE:
1) Develop a function module by fallowing BAPI standards.2) Release the function module.3)
Create the business object referring to BAPI function module.
BAPI FUNCTION MODULE STANDARDS:
1) Function module should be remote enabled.2) The Parameters to the function module must be passed by value.3) Function module mane must start with BAPI_.4) The return type of the function module should be of type structure BAPIRETURN (OR) BAPIRET2 (OR) BAPIRET1.5) The parameter references of the function must start with BAPI.6) Commit & Rollback statement should not be used; instead we need to use the function modules
BAPI_TRANSACTION_COMMIT (OR) BAPI_TRANSACTION_ROLLBACK.
REQUIRMENT:
7/31/2019 Cross Apps
101/192
101 | P a g e S a n t o s h P
IN 4.7 Server Client (800):
SE11:
PROGRAM:
1) Create a Database table.SE11.
2) Create a function Module.SE37.Attributes Tab:
7/31/2019 Cross Apps
102/192
102 | P a g e S a n t o s h P
Import Tab:
Export Tab:
Source Code:
7/31/2019 Cross Apps
103/192
103 | P a g e S a n t o s h P
Save.
Activate.
Releasing the Function Module.
SWO1: T-code for creating the business object builder.
7/31/2019 Cross Apps
104/192
104 | P a g e S a n t o s h P
7/31/2019 Cross Apps
105/192
105 | P a g e S a n t o s h P
7/31/2019 Cross Apps
106/192
106 | P a g e S a n t o s h P
Note: The Colure of the method will change.
7/31/2019 Cross Apps
107/192
107 | P a g e S a n t o s h P
Same step for other method also. After redefining all the methods, Choose the method and CLICK on PROGRAM
7/31/2019 Cross Apps
108/192
108 | P a g e S a n t o s h P
[
SAVE.
Same process for all the methods.
Choose each method and implement.
7/31/2019 Cross Apps
109/192
109 | P a g e S a n t o s h P
Same process for all the methods.
Choose each method and Release.
Same process for all the methods.
Choose the method and object type component Implemented.
Choose the method and object type component release.
7/31/2019 Cross Apps
110/192
110 | P a g e S a n t o s h P
Same process for all the Methods.
Note: We must get tick marks for all the methods.
Save and back to initial Screen.
Implement.
7/31/2019 Cross Apps
111/192
111 | P a g e S a n t o s h P
Release.
Calling a function module in the program.
ZCALLCUSTOMBAPI:
REPORT ZCALLCUSTOMBAPI .
data : ls_dept type zbapidept,
ls_return type bapireturn.
ls_dept-deptno = 1.ls_dept-dname = 'Sales'.
ls_dept-loc = 'Hyderabad'.
CALL FUNCTION 'ZBAPI_INSERTDEPT'EXPORTING
I_DEPT = ls_deptIMPORTING
RETURN = ls_return.
if ls_return-type = 'S'.
message 'Inserted' type 'I'.
7/31/2019 Cross Apps
112/192
112 | P a g e S a n t o s h P
else.message 'Failed' type 'I'.
endif.
Note:
Once a business object is developed we need to prepare a Technical Spec. Which contains information of the business Objects. This information includes name of the business Object. APT Methods, Method Parameters List, Name of the function Module. To invoke the business object from Legacy Application. The Legacy program makes use of technical spec & develop the
Application.
As the part of this Application, the legacy program invokes the API Method which internally calls BAPI Function module. Class X: 17.08.2011
LSMW Using BAPI:
Requirement: Migrating Bank details from file to SAPusing LSMW Tool.
DIM: Declaring Memory.
Note: In LSMW Using BAPI we require only one set of object which are specific to receiver.
Steps:
1) Creating Logical System.BD54:
7/31/2019 Cross Apps
113/192
113 | P a g e S a n t o s h P
SAVE.
2) Assign Client to Logical System.
3) Create file Port.
7/31/2019 Cross Apps
114/192
114 | P a g e S a n t o s h P
EDI_PATH_CREATE_MESTYP_DOCNUM:It generates a file which is for SAP purpose we never use this file.
SAVE.
4) Create Partner Profile.
7/31/2019 Cross Apps
115/192
115 | P a g e S a n t o s h P
5) Assigning Inbound Parameters.
SAVE.
Starting LSMW.
7/31/2019 Cross Apps
116/192
116 | P a g e S a n t o s h P
1) Maintain Object Attributes.
SAVE.
7/31/2019 Cross Apps
117/192
117 | P a g e S a n t o s h P
Back.
2) Maintain Source Structures.
SAVE.
3) Maintain Source Fields.
7/31/2019 Cross Apps
118/192
118 | P a g e S a n t o s h P
SAVE.
4) Maintain Structure Relations.
5) Maintain Field Mapping and Conversion Rules.
7/31/2019 Cross Apps
119/192
119 | P a g e S a n t o s h P
7/31/2019 Cross Apps
120/192
120 | P a g e S a n t o s h P
perform ur_CHECKBANKKEY
using ZBANKSTR-BANKK
changing E1BANK_CREATE-BANK_KEY.
end perform.
SAVE.
SAVE.
BACK.
6) Maintain Fixed Values, Translations, User-Defined Routines.
7/31/2019 Cross Apps
121/192
121 | P a g e S a n t o s h P
SAVE.
BACK.
7) Specify Files.
7/31/2019 Cross Apps
122/192
122 | P a g e S a n t o s h P
SAVE.
8) Assign Files.
7/31/2019 Cross Apps
123/192
123 | P a g e S a n t o s h P
9) Read Data.
7/31/2019 Cross Apps
124/192
124 | P a g e S a n t o s h P
BACK.
10) Display Read Data.
ENTER.
7/31/2019 Cross Apps
125/192
125 | P a g e S a n t o s h P
BACK.
11) Convert Data.
7/31/2019 Cross Apps
126/192
126 | P a g e S a n t o s h P
12) Display Converted Data.
7/31/2019 Cross Apps
127/192
127 | P a g e S a n t o s h P
ENTER.
7/31/2019 Cross Apps
128/192
128 | P a g e S a n t o s h P
13) Start IDoc Generation.
7/31/2019 Cross Apps
129/192
129 | P a g e S a n t o s h P
14) Start IDoc Processing.
7/31/2019 Cross Apps
130/192
130 | P a g e S a n t o s h P
Check whether the records are updated (or) not.
WE02:
7/31/2019 Cross Apps
131/192
131 | P a g e S a n t o s h P
Class 1: 18.08.2011
7/31/2019 Cross Apps
132/192
132 | P a g e S a n t o s h P
Integrating BAPI with ALE:
Open the required Method in Business object.BAPI:
ZDEPTOBJ:
7/31/2019 Cross Apps
133/192
133 | P a g e S a n t o s h P
CONTINUE.
7/31/2019 Cross Apps
134/192
134 | P a g e S a n t o s h P
CONTINUE.
7/31/2019 Cross Apps
135/192
135 | P a g e S a n t o s h P
BAPI MODIFICATION:
It is the process of enhancing the standard BAPI by adding additional functionality. This additional functionality is
achieved by adding additional parameters to the standard BAPI function module (or) API method.
BAPI:
Business Object : Company Code
7/31/2019 Cross Apps
136/192
136 | P a g e S a n t o s h P
APT Method : GetList
BAPI Function Module : BAPI_COMPANYCODE_GETLIST
Procedure:
1) Copy the Standard BAPI function module to custom function module.SE37
IMPORT SECTION.
Declare some importing parameters.
7/31/2019 Cross Apps
137/192
137 | P a g e S a n t o s h P
We must make some changes in the Source Code, Need to write the new selection statement and create and internal table ofsame table type in the TOP INCLUDE Program.
FUNCTION GROUP: ZCROSS
INCLUDE: LZCROSSTOP
TYPES : BEGINOF TY_COMPANYCODE_LIST.
INCLUDESTRUCTURE bapi0002_1.
TYPESENDOF TY_COMPANYCODE_LIST.
DATA : LM_COMPANYCODE_LIST TYPESTANDARDTABLEOF TY_COMPANYCODE_LIST WITHHEADERLINE.
SAVE, CHECK, ACTIVATE.
IN top include declare.
TABLES : T001.
FUNCTION MODULE: SOURCE CODE
SELECT BUKRS BUTXT
FROM T001
INTO CORRESPONDING FIELDSOFTABLE
LM_COMPANYCODE_LIST
WHERE BUKRS >= I_LBUKRS AND
BUKRS
7/31/2019 Cross Apps
138/192
138 | P a g e S a n t o s h P
DATA : BEGIN OF MESSAGE,
msgty like sy-msgty,
msgid like sy-msgid,
msgno like sy-msgno,
msgv1 like sy-msgv1,
msgv2 like sy-msgv2,
msgv3 like sy-msgv3,
msgv4 like sy-msgv4,
END OF MESSAGE.
SAVE, CHECK, ACTIVATE.
INCLUDE: LZCROSSTOP
form check_authority_t001 changing return like bapireturn.
tables: tddat.
data: activity(2) type c value '03'.
select single * from tddat where tabname = 'V_T001'.
7/31/2019 Cross Apps
139/192
139 | P a g e S a n t o s h P
if sy-subrc ne 0 or tddat-cclass eq space.
tddat-cclass = '&NC&'. " 'non classified table'
endif.
authority-check object 'S_TABU_DIS' "check by class
id 'ACTVT' field activity
id 'DICBERCLS' field tddat-cclass.
if sy-subrc ne 0. "no authority
clear message.
message-msgty = 'E'.
message-msgid = 'FN'.
message-msgno = 000.
perform set_return_message using message
changing return.
if 1 = 2. " Fr Verwendungsnachweis Messages
message e000(fn).
* Keine Berechtigung, Buchungskreise anzuzeigen
endif.
endif.
endform. " CHECK_AUTHORITY_T001
SAVE, CHECK, ACTIVATE.
7/31/2019 Cross Apps
140/192
140 | P a g e S a n t o s h P
form set_return_message using value(p_message) like message
changing p_return like bapireturn.
check not message is initial.
call function 'BALW_BAPIRETURN_GET'
exporting
type = p_message-msgty
cl = p_message-msgid
number = p_message-msgno
par1 = p_message-msgv1
par2 = p_message-msgv2
par3 = p_message-msgv3
par4 = p_message-msgv4
* LOG_NO = ' '
* LOG_MSG_NO = ' '
importing
bapireturn = p_return
exceptions
others = 1.
endform. " SET_RETURN_MESSAGE
SAVE, CHECK, ACTIVATE.
Note: We must release the function module.
Go to initial Screen of function module.
7/31/2019 Cross Apps
141/192
141 | P a g e S a n t o s h P
2) Creating Business Object from the standard business object.SWO1:
7/31/2019 Cross Apps
142/192
142 | P a g e S a n t o s h P
7/31/2019 Cross Apps
143/192
143 | P a g e S a n t o s h P
7/31/2019 Cross Apps
144/192
144 | P a g e S a n t o s h P
7/31/2019 Cross Apps
145/192
145 | P a g e S a n t o s h P
7/31/2019 Cross Apps
146/192
146 | P a g e S a n t o s h P
Redefine existence check.
Put cursor on existence check and click on Program.
7/31/2019 Cross Apps
147/192
147 | P a g e S a n t o s h P
Save Back.
Generate.
7/31/2019 Cross Apps
148/192
148 | P a g e S a n t o s h P
7/31/2019 Cross Apps
149/192
149 | P a g e S a n t o s h P
7/31/2019 Cross Apps
150/192
150 | P a g e S a n t o s h P
7/31/2019 Cross Apps
151/192
151 | P a g e S a n t o s h P
Back to initial Screen.
7/31/2019 Cross Apps
152/192
152 | P a g e S a n t o s h P
BAPI:
7/31/2019 Cross Apps
153/192
153 | P a g e S a n t o s h P
ENHANCEMENTSEnhancements: It is a process of enhancing the SAP Transaction without disturbing the SAP functionality. There are 4 Types of
Enhancements Techniques.
1) User Exits ----- Process Oriented Approach (Subroutines).2) Customer-Exit ----- Process Oriented Approach (Function Modules).3) BADIS ----- Object Oriented Approach (Methods).4) Enhancement Frameworks.
Role of ABAP Consultant in Enhancing Standard SAP Transactions:
1) Identifying the suitable Enhancement (Customer-Exit / BADI) in the standard Transaction.2) Identifying the required components of the Enhancement (CMOD --- Customer-Exit, SE18 --- BADIS).3) Read the document (If provided) to understand the process of implementing the Enhancement (CMOD --- Customer-Exit, SE18--- BADIS).4) Implement the Enhancement Accordingly.
Types of Customer-Exits:
1) Function Exits.2) Menu Exits.3) Screen Exits.
Function Exits: They are used for providing customer specific validation in a standard SAP Transaction.
7/31/2019 Cross Apps
154/192
154 | P a g e S a n t o s h P
Menu Exits: Menu Exits are used for adding the additional menu item in the standard SAP menu.
For this additional menu items the function codes are provided by SAP itself. Which start with naming convention +. The base for the menu exit is function exit. I.e. the implementation for the additional menu item is done inside a function exit.
Screen Exits: It is used for adding additional customer specific fields in standard SAP Transaction.
These additional fields should be first added in the corresponding base tables of the transaction. The base for the screen exit if function exit. I.e. the validation specific to the additional fields is implemented in the
corresponding function exit.
In general a screen exit is associated with two corresponding function exits. 1) PBO Function exit.2) PAI Function exit.
PBO Function exit: Is used for transferring the default values from program to screen.
PAI Function exit: Is used for transferring data from screen to program.
Procedure for identifying the Customer-Exits in standard SAP Transactions:
Procedure 1:
1)
Identify the main program of the Transaction.
2) Identify the package of the main program.3) Identify the Customer-Exits in the package by using SE84 (OR) SMOD.
Procedure 2:
1) Identify the main program of the Transaction.2) Search for the string CALL CUSTOMER_FUNCTION in the main program.
Function Exits:
TASK: While creating the customer in XD01. If the country field is IN the industry field must be MANDATORY.
7/31/2019 Cross Apps
155/192
155 | P a g e S a n t o s h P
Procedure 1:
SE93:
It will take you to program.
7/31/2019 Cross Apps
156/192
156 | P a g e S a n t o s h P
Program Name:SAPMF02D
Package:VS
Using SE84: (Identifying the Customer-Exit)
7/31/2019 Cross Apps
157/192
157 | P a g e S a n t o s h P
Using SMOD: (Identifying the Customer-Exit)
7/31/2019 Cross Apps
158/192
158 | P a g e S a n t o s h P
7/31/2019 Cross Apps
159/192
159 | P a g e S a n t o s h P
Procedure 2:
SE93:
SE38:
7/31/2019 Cross Apps
160/192
160 | P a g e S a n t o s h P
7/31/2019 Cross Apps
161/192
161 | P a g e S a n t o s h P
7/31/2019 Cross Apps
162/192
162 | P a g e S a n t o s h P
We will write the code in INCLUDE.
Note 1:
Every function exit is associated with a function module which contains a customer specific include. As part of this include we need to provide the customer specific implementation.
Note 2:
Customer exits are implemented inside a project as part of a project. We can implement any number ofenhancements related to different transaction.
CMOD:
7/31/2019 Cross Apps
163/192
163 | P a g e S a n t o s h P
7/31/2019 Cross Apps
164/192
164 | P a g e S a n t o s h P
7/31/2019 Cross Apps
165/192
165 | P a g e S a n t o s h P
Activate Enhancement.
After Activation.
XD01:
7/31/2019 Cross Apps
166/192
166 | P a g e S a n t o s h P
So we must give the Industry.
7/31/2019 Cross Apps
167/192
167 | P a g e S a n t o s h P
Class 1: 20.08.2011
7/31/2019 Cross Apps
168/192
168 | P a g e S a n t o s h P
BADIS
BUSINESS ADDINNSBADIS:
Is the enhancement technique used for enhancing the SAP Transactions in object oriented methodology (OR)approach.
A BADI is associated with Definition & Implementation. Definition of BADI contains fallowing components.1) BADI Interface:
It starts with naming convention (IF_EX_).It is collection of methods which contains null
implementation as a developer we need to identify the appropriate methods & provide the
implementation.
2) BADI Class:It starts with naming convention (CL_EX_). This class is initially used by SAP and it contains the list
of active and inactive implementation.
3) It contains the implementation link weather a BADI is single used BADI (OR) multiple used BADI. A single used BADI can contain any number of implementations but only one active
implementation.
Multiple used BADI can contain any number of active implementations.4) Filter Types:
A BADI can be filtered dependent (OR) Independent.
BADI Implementation: It starts with naming convention (CL_IM_).It is associated with the implementation class and it is
responsible for implementing the BADI interface method.
Note: Whenever a BADI is triggered SAP executes all BADIs active implementations one after the other.
Procedure for identifying BADIS in a Transaction:
Technique 1:
1) Identifying the main program in SAP Transaction.2) Identifying the package in the main program.3) In the main program search for (CL_EXITHANDLER=>GET_INSTANCE).4) It displays the lines where the above method is called, Identify the value of the parameter INSTANCE.
Technique 2:
1) Identifying the main program in SAP Transaction.2) Identifying the package in the main program.3) Using the T-Code SE84 to identify the BADIS in the package.
Technique 3:
1) Using the T-Code ST05 (SQL Trace).2) Switch on the buffer trace in ST05 and activate the trace.3) In another session make the changes in the transaction.4) Come back to ST05 session switch off the trace.5) Search for the BADIS in the run time view (V_EXT_IMP and V_EXT_ACC).
TASK: Enhancing the Transaction (XD01).
7/31/2019 Cross Apps
169/192
169 | P a g e S a n t o s h P
Technique 1:
SE38:
Global Search: search for (CL_EXITHANDLER=>GET_INSTANCE).
7/31/2019 Cross Apps
170/192
170 | P a g e S a n t o s h P
Double click on 14.
Double click on G_ADDITIONAL_DATA.
7/31/2019 Cross Apps
171/192
171 | P a g e S a n t o s h P
To check whether CUSTOMER_ADD_DATA is a BADI (OR) NOT go to SE18.
SE18:
Double click on IF_EX_CUSTOMER_ADD_DATA.
7/31/2019 Cross Apps
172/192
172 | P a g e S a n t o s h P
It will take u to BADI INTERFACE.
Double click on 67.
Double click on G_ADDITIONAL_DATA_CS.
7/31/2019 Cross Apps
173/192
173 | P a g e S a n t o s h P
SE18:
Double click on IF_EX_CUSTOMER_ADD_DATA_CS.
It will take u to BADI INTERFACE.
7/31/2019 Cross Apps
174/192
174 | P a g e S a n t o s h P
Double click on 84.
Double click on G_ADDITIONAL_DATA_CS.
SE18:
7/31/2019 Cross Apps
175/192
175 | P a g e S a n t o s h P
Double click on IF_EX_CUSTOMER_ADD_DATA.
It will take u to BADI INTERFACE.
7/31/2019 Cross Apps
176/192
176 | P a g e S a n t o s h P
Technique 2:
SE38:
7/31/2019 Cross Apps
177/192
177 | P a g e S a n t o s h P
SE84:
7/31/2019 Cross Apps
178/192
178 | P a g e S a n t o s h P
Technique 3:
ST05:
7/31/2019 Cross Apps
179/192
179 | P a g e S a n t o s h P
Open new Session and make changes in the Transactions.
T-Code: XD01
7/31/2019 Cross Apps
180/192
180 | P a g e S a n t o s h P
Enter.
7/31/2019 Cross Apps
181/192
181 | P a g e S a n t o s h P
Back to ST05 Session.
7/31/2019 Cross Apps
182/192
182 | P a g e S a n t o s h P
7/31/2019 Cross Apps
183/192
183 | P a g e S a n t o s h P
Note: Before BADI implementation. We must check for any active implementation.
7/31/2019 Cross Apps
184/192
184 | P a g e S a n t o s h P
SE18:
Implementing Standard BADIs:
IN 4.7:
7/31/2019 Cross Apps
185/192
185 | P a g e S a n t o s h P
BADI Definition : CUSTOMER_ADD_DATA
BADI Interface : IF_EX_CUSTOMER_ADD_DATA
BADI Class : CL_EX_CUSTOMER_ADD_DATA
We go through the Documentation.
7/31/2019 Cross Apps
186/192
186 | P a g e S a n t o s h P
7/31/2019 Cross Apps
187/192
187 | P a g e S a n t o s h P
SE19: BADI Implementation.
7/31/2019 Cross Apps
188/192
188 | P a g e S a n t o s h P
In Interface Tab.
Double click on CHECK_ALL_DATA.
BACK.
ACTIVATE.
7/31/2019 Cross Apps
189/192
189 | P a g e S a n t o s h P
XD01:
7/31/2019 Cross Apps
190/192
190 | P a g e S a n t o s h P
Enter.
7/31/2019 Cross Apps
191/192
191 | P a g e S a n t o s h P
Note:
If the T-code has Customer-Exits & BADI, First Customer-Exit will execute. Whenever a BADI is triggered SAP makes use of BADI Class to identify the list of active and inactive
implementation.
Based on this information SAP execute all the active implementation one after the other.
7/31/2019 Cross Apps
192/192