Anthony Cecchini is the President of Information Technology Partners (ITP), an SAP consulting company headquartered in Pennsylvania. ITP offers comprehensive planning, resource allocation, implementation, upgrade, and training assistance to companies. Anthony has over 17 years of experience in SAP R/3 business process analysis and SAP systems integration. His areas of expertise include SAP NetWeaver integration; ALE development; RFC, BAPI, IDoc, Dialog, and Web Dynpro development; and customized Workflow development. You can reach him at firstname.lastname@example.org.
The SAP IDoc Technology
In this month we will continue our look at SAP IDocs and the IDoc Technology by exploring how we can use the new custom IDoc extension we created in the last blog. If you need a refresher on how to extend an IDoc CLICK HERE
If you recall from last month’s blog, the Function Module we are using follows a naming convention “IDOC_<OUTPUT / INPUT >_NAME OF MESSAGE TYPE”. For our example the delivered Message Type for an Invoice is INVOIC and this is an Outbound scenario, so the function module will be “IDOC_OUTPUT_INVOIC”.
The User Exit for the transaction can be found using the transaction SMOD. Here we need to give the package to find the exact enhancement and the respective function module which will serve our purpose. The steps are as follows…
Go to SE37 to find the package of “IDOC_OUTPUT_INVOIC” and click on Display.
After clicking on display. Go to the “Attributes” tab and look for the package name.
Here we get the Package as “VED”, Use this Package name in SMOD to find the respective user exit function module.
Go to Transaction SMOD and give the value of Package we got (here “VED” ) in F4 help or utilities-> Find.
Hit the green check and we get the set of User Exit Names. One way to find the most suitable exit could be by the short text description. Sometimes you have to read the documentation for each exit, and sometimes it’s plain old trial and error using the debugger and breakpoints. You can scroll through the Exits using the up and down arrows.
The short text for EXIT_SAPLVEDF_002 is “User_Exit Customer Enhancement in Data Segments for billing Docu”. This sounds like us. Lets talk through the business requirement.
“We have to add a custom segment ZE1EDK01 as a child of standard segment E1EDK01 when creating the OUTBOUND IDoc for a billing document.”
OK, this looks promising. I usually double click into the User Exit Function and examine the Import/Export and tables parameters so I know I can get at the data I need, and update the structure or tables I need.
I can see in tables section of the “Formal” Parameters that I have access to INT_EDIDD and is typed to EDIDD. This is good as this is the IDocs segments. All I need to do is read this table looking for the segment E1EDK01, USE OPEN SQL to get the data I need and build and APPEND my custom Segment ZE1EDK01. This is a perfect place to do this.
Using Transaction CMOD to Build a Project and User Exit
First we need to create a project that will hold our enhancement. Execute transaction CMOD (Customer MOD) and fill in a project name and click create. I will use the name ZBILL as my project name.
Fill in some descriptive text and click on Enhancement Assignments.
You can add the enhancement LVEDF001 that we found using SMOD and hit enter. You will most likely get the following error.
This means the enhancement is ALREADY in a project and can’t be added to this one. The project is BPID. If we look at project BPID we will see it is already there.
Adding your Custom Code to the CMOD Function Exit
Double Click on Components and you will see the exit EXIT_SAPLVEDF_002 we found using SMOD. Now all we have to do is add the code and make sure we activate the project and our code will be used when the IDocs are generated for outbound processing.
Double click into the exit and add the following code…
TYPES : BEGIN OF ty_vbrk, ktgrd TYPE ktgrd, mansp TYPE mansp, END OF ty_vbrk. DATA : wa_edidd TYPE edidd, v_lines TYPE i, wa_e1edk01 TYPE e1edk01, wa_ze1edk01 TYPE ze1edk01, wa_vbrk TYPE ty_vbrk. READ TABLE int_edidd INTO wa_edidd WITH KEY segnam = 'ZE1EDK01'. IF sy-subrc NE 0. READ TABLE int_edidd INTO wa_edidd WITH KEY segnam = 'E1EDK01'. IF sy-subrc = 0. wa_e1edk01 = wa_edidd-sdata. SELECT SINGLE ktgrd mansp FROM vbrk INTO wa_vbrk WHERE vbeln = wa_e1edk01-belnr. IF sy-subrc = 0. wa_ze1edk01-ktgrd = wa_vbrk-ktgrd. wa_ze1edk01-mansp = wa_vbrk-mansp. int_edidd-segnam = 'ZE1EDK01'. MOVE wa_ze1edk01 TO int_edidd-sdata. APPEND int_edidd. CLEAR int_edidd. ENDIF. ENDIF. ENDIF.
We have now populate our two new fields KTGRD and MANSP of our new custom segment ZE1EDK01. If you need a refresher on how we created this custom segment and added these fields CLICK HERE
So in summary, We used transaction SMOD to view the enhancements available for a package. We chose an enhancement suitable for our requirement and created or modified a PROJECT to include this enhancement. We then chose the correct component and added our custom code and activated the Project.
This was a very rudimentary example of how to enhance the supplied solution using Customer Exits (CMOD). I chose this method over BAdi’s and other enhancement techniques as it lends it self nicely as an introduction for beginners. For a detailed and in-depth study of all the possible Enhancement techniques available in SAP, I would ask you to read our blogs on “The New Enhancement Framework”.
To read the part 1 of this Blog click HERE
To read the part 2 of this Blog click HERE
To read the part 3 of this Blog click HERE
To read the part 4 of this Blog click HERE