Saturday, January 5, 2013

Implicit Enhancement in SAP ABAP ( New Enhancement Framework ) with Tutorial

Introduction: Implicit enhancement is an enhancement option which is provided in new enhancement framework .
Requirement is to remove Reconstruct tab from WPDTC Transaction.:
There is something called transaction variant and screen variant .to solve this problem .But it has it’s own disadvantages like You can’t submit that Report using SUBMIT statement as it will not consider the changes done on screen using the variant.
Step 1:
Go to system status of transaction WPDTC and check the program name it is PDTC_REPORT.
Here you can see many Explicit enhancement (Source code plug-ins options).
To hide a screen element code can be done in AT SELECTION-SCREEN OUTPUT event.
There is a form named  pdtc_screen_output.
Step 2:
To see the Explicit enhancement option click on the spiral symbol on the top.
As we don’t have any explicit enhancement options the only possibility left is implicit enhancement.
To see the implicit Enhancement Go to menu path:
EDIT->Enhancement operations->Show implicit Enhancement Points.
As you know implicit enhancement options are provided at beginning and end of every method, function module and in subroutine.
Select the Enhancement mode as CODE.
The next pop up will show u the available Enhancement done in this Report, You can merge your enhancement in one of the available Enhancement or you can create your own. To create a new one click on the create icon.
Step 3:
Provide the Enhancement Implementation name and short text to it.
(Note: No need for composite enhancement implementation).
Click on the continue. It will again take you to the Select Enhancement popup. Select your created enhancement and continue.
Step 4:
Now you can see some space in standard code to put your own code.
As per the requirement we need to de-activate the last tab.
Go to layout of the screen 1000, and find the name of the third tab. To make your work easy the third tab name is : TABSTR_4.
Here is the simple code which can loop at the screen and deactivate the third tab.
loop at screen.
if screen-name = ‘TABSTR_4′.
screen-active = 0.
Put the above code inside the Enhancement and activate it.
Step 5:
Go to Transaction WPDTC and check that the third tab is invisible or not. ( if not don’t look puzzled just check whether you have followed the steps properly or not ).

SAP’s New Enhancement and Switch FrameWork

Get bored of using Old Customer Exits, User Exits ?????
Here comes The New Enhancement Framework to make it Easy for you to do customization in Standard SAP Applications.
This New Enhancement frame work provides all new enhancement technologies such as new business add-ins ( BAdIs ) and source code plug-ins.

Kernel BADIs
New BADIs are also Known as Kernel BADIs , These BADIs are object-oriented enhancement options (or plug-ins). These BAdIs are based on interfaces that may be implemented by classes that may then be transported.
You can see Kernel BADIs from the transaction code Se18:
(Note :Technically badis are link with the Enhancment Spot) check the Below screen shot for more details.
Source code plug-ins
In Source code plug-ins we have many options like Explicit Enhancement and Implicit Enhancement Developers (both SAP and non-SAP) may provide special hooks or portions in their code where enhancements may be applied. These are known as explicit enhancement options, and are mostly created by SAP at specific points of standard programs.
Explicit Enhancement:
In simple word explicit enhancement is provided by SAP, It is predefined location or plugs where you can put your code and enhance the standard. To see the explicit enhacement options in the object it requires to click on the spiral button which is given in the top tool bar.
Supported Enhancement Technologies
The Enhancement Framework supports a number of different enhancement technologies, including:
• Class Enhancements. Class enhancement lets you add new methods to a class. Moreover, you may also
add optional parameters to existing methods.
• Function Group Enhancements. You may add new parameters to a function module via function group
• Source Code Enhancements. These may be enhancement points in the source code where source
code plug-ins may be attached. These plug-ins contain the code that enhances the given program, and
are treated as an addition to the original code of the program in question. On the other hand, the code
with the enhancement section may be substituted with the source code plug-in code used.
This plug-ins in the source code is called as Enhancement SPOTS.
SPOTS can be categorised in :
  1. Enhancement POINTS
  2. Enhancement SECTION
In simple words When you want to add your extra logic over the existing one use POINTS while when you want to replace the existing one use SECTION. When a SPOT is static it is used for data declaration while Dynamic SPOTS are used for coding.
Enhancement POINTS and SECTION are looks like as mentioned Below:
ENHANCEMENT-POINT <name> SPOTS <spot1> [<spot2>] [STATIC] …
ENHANCEMENT-SECTION <name> SPOTS <spot1> [<spot2>] [STATIC]
Implicit Enhancement:
In last if nothing works , like you don’t have any Explicit enhancement or you don’t have any BADIs, Do implicit enhancement .
This is easiest enhancement you can ever find.
Implicit enhancement options are provided internally in the beginning and end of every subroutine , Function module and methods. Where you can put your own code. Check the article

Tutorial on Implicit Enhancement.
Switch Frame Work:
Each Enhancement package contains a set of business functions. Each “business function” are optionally implemented and activated. Switch frame work is something using which you can deactivate certain Business functionality depending on the client requirement. You can also assign switch to your implemented enhancements so if required you can de activate all of them in single go.

Webdynpro ABAP application to locate Employee’s location into google map

Webdynpro ABAP application to locate Employee’s location into google map.Follow the below 10 easy steps to create this application.
in last you can able to locate your employee on google map.
Step 1:
Go to Se80 create a Webdynpro comp name ZTEST_LOCATE_EMP.
Step 2:
Create a node into your main windo with name EMP. Dictionary strcuture as PA0006.Click on the button “ADD attriubute from structure” and select the perner from it.
Step 3:
Go to layout tab into MAIN view and create an input field with name EMP_ID.
Step 4:
Double click on the EMP_ID.
You can see the value property for it.Bind this to the context attribute you have created.
Step  5:
Create a Button with name LOCATE.
Step 6:
Double click on it, you can see On action propery. Just click on the create button right side of it.
Create a ACTION name LOCATE .no need to give any outbound plug name.
Step 7 :
When you create an action it automatically a Method name ONACTION<your acion name>.
Step 8.
Put the below code inside your method :
data : v_pernr type pa0006-pernr.
data : v_street type pa0006-STRAS.
data : v_city type pa0006-ORT01.
data : lr_node type ref to if_wd_context_node.
data:  lo_window_manager type ref to if_wd_window_manager.
data:  lo_api_component  type ref to if_wd_component.
data:  lo_window         type ref to if_wd_window.
data:  ld_url type string.
lr_node = wd_context->get_child_node( ‘EMP’ ).
lr_node->GET_ATTRIBUTE( exporting NAME = ‘PERNR’
select SINGLE STRAS ORT01 from pa0006 into (v_street,v_city) where
PERNR eq v_pernr.
lo_api_component  = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
*FINAL_URL = ‘’.
ld_url = FINAL_URL.
EXPORTING     URL                = ld_url
RECEIVING    WINDOW         = lo_window.
lo_window->open( ).

Step 9:
Create a Webdynpro application
Step 10:
Execute the application and give the perner which have the address data updated in PA0006. Take pernr 00000003 if you dont get any.

Call SAP Tcode using Webdynpro for ABAP

If you have a requirement to Call SAP standard Transaction code from Webbrowser in your webdynpro Application than check it out this article to know how can achive this.

Problem Description
It will help to call SAP Tcode from the Webbrowser using webdynpro for ABAP.
Solution Description
SAP Internet Transaction Server (ITS) – The ITS is the interface between the Internet and R/3  and is the runtime engine that links Web server to the R/3 Application server. So to display a standard tcode in your webdynpro application you can use ITS.
Setting needs to be Done.
Go to SE80 : In the top menu choose “Utilities(M)” –> “settings”. Right-click on the tab-arrow until you come to tab “Internet Transaction Server”.
Make sure that “Publish” tabe and check mark “Integrated ITS” is selected.
Start transaction “SE80″. Choose “Internet Service” from the first drop down box  Enter “SYSTEM” in the input field.  You will see the ITS service SYSTEM and its components in a tree structure. Right click on “SYSTEM” in the tree and select “Publish” –> “Complete Service” to publish the service.  once the publishing is completed the system will issue a message “Object published successfully; site INTERNAL”.
Repeat the previous step with “SHUFFLER” and “WEBGUI” instead of “SYSTEM” to publish both, too.
How to test it::
Enter Tcode SICF.
Select the path as : /sap/bc/gui/sap/its/webgui
Right click on webgui and click on “test” to execute the will open the sap screen in web browser.
Now it’s time for some coding. create LINK to URL or LINK TO ACTION according to requirement.  the code below is develop having scinario ::
Users are displyed creating link to userid coloumn. Whenever end user click on the any of the user id.  on_click method will be called wih open the user details in SU01D  Befor that get the path of the application server. you can find it in webdynpro application. doble clcik on webdynpro application in that you can find the URL  in Administrative data.
data: lr_node type ref to if_wd_context_node,
lt_event_properties type table of IF_MAIN=>element_event_properties,
ls_event_properties type IF_MAIN=>element_event_properties.

data:  lo_window_manager type ref to if_wd_window_manager.
data:  lo_api_component  type ref to if_wd_component.
data:  lo_window         type ref to if_wd_window.
data:  ld_url type string.

field-symbols: <l_value> type any.
*fill internal table
ls_event_properties-name = ‘COLUMN_ID’.
ls_event_properties-value = r_param->column.
append ls_event_properties to lt_event_properties.

ls_event_properties-name = ‘INDEX’.
ls_event_properties-value = r_param->index.
append ls_event_properties to lt_event_properties.

ls_event_properties-name = ‘ATTRIBUTE’.
ls_event_properties-value = r_param->attribute.
append ls_event_properties to lt_event_properties.

assign r_param->value->* to <l_value>.
ls_event_properties-name = ‘VALUE’.
ls_event_properties-value = <l_value>.
append ls_event_properties to lt_event_properties.

* navigate to context node EVENT_PROPERTIES
lr_node = wd_context->get_child_node( ‘EVENT_PROPERTIES’ ).

* bind internal table to context node
lr_node->bind_table( lt_event_properties ).

FINAL_URL = ‘http://<url>:portno/sap/bc/gui/sap/its/webgui?~TRANSACTION=SU01D%20USR02-BNAME=’.
CONCATENATE  FINAL_URL ls_event_properties-value INTO FINAL_URL.

lo_api_component  = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).

ld_url = FINAL_URL.
EXPORTING     URL                = ld_url
RECEIVING    WINDOW         = lo_window.
lo_window->open( ).

Working with A BADI which does not contain proper import data

How can you use a BADI which does not contain  desire import or export data ?
Many time such condition occurs  when you find a perfect BADI for your requirement but As the BADI does not contains proper import data you cant use it.
Lets take an example for BADI Delivery_publish.
This BADI gets trigger when you do the POST Goods issue.
Now this BADI does not contain any input parameter.So ideally it is of no use if you want to perform a particular task on that delivery,
So what can be done!!!!!!!!!!!!
SAP has given a unique solution for this kind of problem.
See the below code:::

I can able to find the material Document No. Here..
Here we have use field symbols for reading a global variable EMKPF. Which is there in main program SAPMV50A.
(Note : It is not mandatory that you can access this program’s global variable only.You can access all the program’s global variable which are initialised in the current call sequence.
Note : if you don’t know the main program name you can find it from system table SYST and field CPROG.Now go to this program and check the top include where u will find the EMKPF table .So here is the guess that this variable might have the data initialize by Standard SAP before calling this BADI.u can see this variable in debugging mode by  (SAPMV50A)emkpf-MBLNR.
Note : Don’t ever change value As it may effect the standrad SAP codes.

MVC Architecture for Webdynpro for ABAP

To understand the Webdynpro for ABAP let us use the same methodology which we used during our school days, splitting the word “Webdynpro for ABAP”.
Web + dynpro + ABAP.
“ A Web application which can be accessed via internet which has a capability of dynamic UI  and build using ABAP is we called Webdynpro for ABAP Application.”
Now you will look puzzled if you already know about ITS.
Why we need it if we already have ITS?
ITS-> internet transaction server.
What ITS does is, it converts all the sap gui screen into HTML pages. This can be viewed from the browser. So it was SAP’s baby steps towards the web application. But if you Google it you will find many disadvantages.
You can refer the —————————-Article to know about how it works and can be used.
After ITS it was time for BSP (Business Server Pages)
If you are a JAVA Guy you will be surprised by name as we already have something called JSP (Java server pages).
BSP is also used to develop the web application it has its own tags which makes the UI element on the browser. You can code in Object oriented programming at technology end to implement the business logic.
If you compare BSP and Webdynpro for abap.
Of course winner will be Webdynpro for abap.
Webdynpro for ABAP is based on the MVC architecture. To explain it in simple way let’s start with
Traditional application
Browser directly accesses the required page.
Let’s say if user types
And the server will return the page to the user as response.

MVC application
Browser directly accesses Controller
So now Mr. Controller comes in between which help us to segregate the business logic and View part.
What is MVC
  • MVC is an architectural Design pattern
  • MVC separates the web application into three different modules
To better understand MVC architecture let take a simple example
Let’s say tomorrow is Your brother or sister’s birthday. So you decided to buy a cake and visit a Bakery Shop.
You request the baker to make a wonderful cake and the Baker collects all the ingredients to make the cake.
After collecting all the ingredients the baker decides on how the cake should look like and selects the
appropriate pan(it may be square, circle etc.).When the cake is ready the Baker responds i.e.
gives you back the cake to celebrate your sisters or brothers birthday. I hope this example makes you clear view on how MVC architecture works.
MVC is a collection of Model/View/Controller
Benefits of MVC
  • It keeps your business logic separate from your (HTML-based) views
  • Keeps your code clean and neat in one place
  • Represents the information and the data from the database
  • Validation of the data
  • Data presentation and user data
  • Rendering  models into one or more formats, such as HTML,XHTML, XML, or even Javascript
  • Dispatches requests and control flows
  • connects the model with the view
  • Process the data that comes from the model.
I think you would have got a clear idea about MVC which is the base of the WebDynpro For ABAP.

Regular Expressions (Regex) and its use in ABAP

Supported as of Release 7.00 Regular Expressions (Regex) are rarely found in ABAP. Have you ever heard something about Regex? We believe so. This article will give you a brief overview and present very good articles from SDN.

Even in ABAP Regular Expressions (Regex) is not a new issue. ABAP supports regular expressions as of Release 7.00, released to customers on Oct 24, 2005. Although not so new its use is rarely found in ABAP. One of reasons is that SAP has already provided other ways to search for patterns e.g. SEARCH txt FOR pattern and IF txt CP pattern.
But what is Regex after all?
“In computing, a regular expression, also referred to as regex or regexp, provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.”
There is a very good tutorial about Regex at We will skip the basics of Regex and go directly to its use in ABAP.
Using Regex in ABAP
Regex is more powerful than traditional SAP patterns and is commonly used for searching and validating text. ABAP supports Regex in the statements FIND and REPLACE and via the the classes CL_ABAP_REGEX and CL_ABAP_MATCHER.  There is an excellent article at SDN produced by Shaira Madhu with many more details of Regex in ABAP.
Let’s see some examples.
Example 1 – Tests if text starts with Hello (case sensitive)
DATA text TYPE string.
DATA moff TYPE i.
DATA mlen TYPE i.
text = `Hello World example`.
IF sy-subrc = 0.
WRITE / text+moff(mlen).
Example 2 – Removes example from the text only if it is the last word
DATA text TYPE string.
text = `Hello World example`.
REPLACE REGEX 'example$' IN text WITH ''.
IF sy-subrc = 0.
WRITE / text.
Example 3 – Validates e-mail using the class CL_ABAP_MATCHER
DATA email   TYPE string VALUE `webmaster@sapignite`. "missing .com
DATA matcher TYPE REF TO cl_abap_matcher.
matcher = cl_abap_matcher=>create(
pattern = `\w+(\.\w+)*@(\w+\.)+(\w{2,4})`
text    = email ).
IF matcher->match( ) IS INITIAL.
MESSAGE 'Invalid e-mail' TYPE 'I' DISPLAY LIKE 'E'.
Tip: For testing Regex without coding you can use the ABAP program DEMO_REGEX_TOY.
DEMO_REGEX_TOY screenshot
DEMO_REGEX_TOY screenshot
ABAP Geek 14 – Regular Expressions Made Easy