SAP ABAP Interview Q&A - Part I
SAP ABAP Interview Q&A - Part I
Technical Q&A:
1. Types of Function Modulesl
2. What is RFC function module
3. What is update FM
4. How to debug update FM
5. Difference between classic Badi & Kernel Badi
6. Difference Between Pooled Table & Transparent Table
7. What is the singleton method?
8. What is an instance of a class?
9. What is private,public,protected visibility in class?
10. Difference between instance and static method
11. What is polymorphism?
12. What is inheritance?
13. What is a constructor?
14. How to retrigger the failed IDOCs?
15. How to check the status of the outbound IDOCs?
16. What are the three major components of the IDOC?
17. Transaction for assigning message,port,distribution model in IDOC?
18. What is the difference between join & association
19. How will you map the CDS to the oData(mapping CDS view as data source in oData)
20. How to trigger the workflow using the Event?
21. How to retrigger the failed workflow?
22. How to debug the workflow in the production system on any issue?
23. How user exits are found?
24. How to find and implement Badi?
25. PO related Badi’s available in SAP
26. What are customer exits?how to find and implement?
27. What is lock Object and what are its types?
28. New ABAP syntax
29. What are CDS views?What are its types?
30. How to upload the long text using infotype in HR ABAP
Answers:
1. Types of Function Modules
3 types of function modules
1. Start Immediately
2. Immediate Start ( Not Updateable )
3. Start Delayed
4. Collective Run
There is now a whole series of different RFC variants, each of which has different properties
and is used for a specific purpose
1.Synchronous RFC
2.Asynchronous RFC
3.Transactional RFC
4.Queued RFC
5.Background RFC
Apart from Classic BADI’s which have been called by Proxy class cl_exithandler, Kernel BADI’s
are called directly with the reference to the BADI definition via GET BADI and CALL BADI
statements. That is one of the reasons why Kernel BADI is faster than classic BADI. Also in
Classic BADI, while we call it via cl_exithandler, we use the reference to the interface rather
than BADI definition.
Exists with the same structure both in dictionary as well as in database exactly with the same
data and fields.
2. Pooled Table
Pooled tables are logical tables that must be assigned to a table pool when they are defined.
Pooled tables are used to store control data. Several pooled tables can be combined in a table
pool. The data of these pooled tables are then sorted in a common table in the database.
3. Cluster Table
Cluster tables are logical tables that must be assigned to a table cluster when they are defined.
Cluster tables can be used to store control data. They can also be used to store temporary data
or texts, such as documentation.
The major difference between transparent tables, pooled tables and cluster Tables are:
A transparent table is a table that stores data directly. You can read these tables directly on the
database from outside SAP with for instance an SQL statement.
Transparent table is a one to one relation table i.e. when you create one transparent table then
exactly the same table will be created in the database and if it is basically used to store
transaction data.
A clustered and a pooled table cannot be read from outside SAP because certain data are
clustered and pooled in one field.
One of the possible reasons is for instance that their content can be variable in length and build
up. Database manipulations in Abap are limited as well.
But the pool and cluster table is a many to one relationship table. This means many pool table
store in a database table which is known as table pool.
All the pool tables stored in table pool do not need to have any foreign key relationship but in
the case of cluster tables it is a must. And pool and cluster tables are basically used to store
application data.
Table pool can contain 10 to 1000 small pool tables which have 10 to 100 records. But cluster
tables can contain very big but few (1 to 10) cluster tables.
For pool and cluster tables you can create a secondary index and you can use select distinct
groups for pool and cluster tables. You can use native SQL statements for pool and cluster
tables.
A structure is a table without data. It is only filled by program logic at the moment it is needed
starting from tables.
A view is a way of looking at the contents of tables. It only contains the combination of the
tables at the basis and the way the data needs to be represented. You actually call directly upon
the underlying tables.
You need to specify the creation of the instance is private, otherwise, someone will use the
statement NEW zcl_temp_singleton_001().
The example:
PUBLIC SECTION.
CLASS-METHODS get_instance
RETURNING
VALUE(ro_instance) TYPE REF TO zcl_temp_singleton_001.
METHODS set_data
IMPORTING
iv_valeur TYPE string.
METHODS get_data
RETURNING
VALUE(rv_valeur) TYPE string.
PRIVATE SECTION.
CLASS-DATA go_instance TYPE REF TO zcl_temp_singleton_001.
DATA gv_valeur TYPE string.
ENDCLASS.
METHOD get_data.
rv_valeur = gv_valeur.
ENDMETHOD.
METHOD get_instance.
ro_instance = COND #( WHEN go_instance IS BOUND
THEN go_instance
ELSE NEW zcl_temp_singleton_001( ) ).
go_instance = ro_instance.
ENDMETHOD.
METHOD set_data.
gv_valeur = iv_valeur.
ENDMETHOD.
ENDCLASS.
an example how to use this code:
REPORT ztest_fred_003.
DATA(mon_singleton) = zcl_temp_singleton_001=>get_instance( ).
mon_singleton->set_data( p_valeur ).
FORM p_display_parameter.
DATA(mon_singleton) = zcl_temp_singleton_001=>get_instance( ).
WRITE /1 mon_singleton->get_data( ).
ENDFORM.
Protected: Means you can access the attribute or method from the same class or from the sub
class you have inherited
Private: Means you can access the attribute or method from only to the same class.
11.What is polymorphism?
Using inheritance, the methods in the super class can be redefined in the subclass by using a
reference variable that addresses the superclass objects. The redefined methods can have
different implementations in subclass from base class. When the super class is addressed, the
method has an original implementation. When the subclass is addressed, the method has a new
and different implementation. Using a single reference variable to call the same named methods
that are behaving differently is called polymorphism.Polymorphism is a concept of assigning
additional or different behavior or value to the inherited component from the superclass that is in
the subclass.
Example : DPC_EXT class will be generated for each oData project which is a subclass of DPC
class.The entity method in the DPC_EXT has to be redefined to meet the business need.The
entity method in the Super class refers to different code .
This behavior of the same method taking many forms is called Polymorphism.
12.What is inheritance?
Inheritance
The concept of inheritance allows you to derive new classes from existing classes. To do this,
you use the INHERITING FROM addition of the CLASS ... DEFINITION. The new class adopts
or inherits all components of the existing class. The new class is called subclass, and the
existing class is called superclass.
13.What is a constructor?
Constructors are special methods that produce a defined initial state for objects and classes.
The state of an object is determined by its instance attributes and static attributes. Content can
be assigned to attributes using the additional VALUE of the statement DATA. Constructors are
necessary when the initial state of an object is to be defined dynamically.
Like normal methods, there are two types of constructor: instance constructors and static
constructors.
Special rules apply to constructors in inheritance. These rules are not described in this
document, but can be found here.
Instance Constructors
Static Constructors
Step 3:
1. Then go to the Transaction “SE37” and enter the function module name found in the above
step and put a breakpoint in the function module as shown in the below.
Step 4:
1.Go the Transaction “BD20“, enter the newly generated IDOC and execute.
2. After clicking on the execute button, it will trigger into the function module as shown in the
below.
3.By debugging the function module,we are able to figure out the issue, why the Idoc is not
processed.
Conclusion:
After triggering into the Function module by giving the newly generated IDOC number, then we
can debug that function module, at some point we are able to figure out the issue with the
below messages and status.
Association:
ASSOCIATIONS are kind of Joins to fetch data from multiple tables on Join Conditions but
these are ‘JOINS ON-DEMAND’ i.e. they will only be triggered when a user would access the
required data which needs the Association of tables. For example, your CDS view has 4
Associations configured and user is fetching data for only 2 tables, the ASSOCIATION on other
2 tables will not be triggered and the system would return the results quickly, so it enables really
high turn-around time as compared to regular SQL JOINS.
Associations are defined with ‘Cardinality’. Syntax : association[<cardinality>]
The Cardinality concept is not new and holds the same concept with CDS views as well. There
are 4 types of Cardinality possible based on the data and relationship in the tables joined;
0..1
0..n or 0..*
1..0
1..n or 1..*
19.How will you map the CDS to the oData(mapping CDS view as data source in oData)
There are 3 different ways you can expose CDS views as OData service:
1. Import DDIC structure using SEGW Netweaver Gateway service builder transaction.
2. Reference Data Source using SEGW Netweaver Gateway service builder transaction.
3. Using Generic Annotations. (@Odata.publish:true)
First way is supported from SAP ABAP NW 7.40 SP5, Second and third ways are supported
from SAP ABAP NW 7.50 and above. For the first two ways SAP NW Gateway is used and for
the third type without use of SAP NW Gateway odata services can be created using
annotations. Gateway is used only to add the service created using annotations.
After opening ABAP perspective, In project explorer right click in the context menu select
New->ABAP Project. A popup appears asking for ABAP system details which you need to add
to create CDS views. Details like System-ID, Username, Password have to be given and click
on OK to add the system to eclipse. Note that the ABAP system which you add should support
SAP ABAP NW 7.40 package. find the attachment for how to add ABAP system to eclipse.
Once after adding the ABAP system project explorer looks like below:
Expand $TMP package, Select and right click on Dictionary folder in the context menu to create
DDL source ABAP Repository Object
Select DDL source, click on next and give below details to create sample CDS view:
Without clicking on finish, on click on next CDS view ask for transport:
since CDS view is create in local object no transport is required, click on next then sample
templates are populated to select:
You can use any of the templates as shown above to create a CDS view. Template helps you to
create different types of CDS views with syntax auto populated on selecting the type of view. Here I
am creating a simple CDS view so I select define view template and click on finish.
In the define view template core annotations are populated with basic syntax to create view,
define the view as below:
Here I defined the sql view name as ‘CDS_DDL_SAMPLE1’ and selected data from “snwd_so”
sales order data source with some columns. After defining the view, Activate the view as shown
above. On Activation two objects are created:
CDS Database view can be accessed using SE11 ABAP Dictionary as shown below:
Give CDS Database View name as shown above and click on display.
DDL SQL view is created in ABAP Dictionary. Here you can identify MANDT field in the view
definition though we didnt mention it explicitly while defining the view. CDS views are default
client dependent no need to mention client field while defining the view.
Right click on CDS View created to preview the data as shown below:
Generate OData service using CDS View:
Save project in local object. Expand project node, right click on data model->import->DDIC structure:
Create entity type by importing ABAP structure. Here give CDS Dabase view
‘CDS_DDL_SAMPLE1’, select create default entity set flag and click on next:
follow the wizard where you select parameters and key fields respectively:
click on finish, then entity, entity set and corresponding properties are created. Expand node
service implementation right click on SalesOrderSet->Map to Data Source
click on OK.
click on OK. Drag and drop properties to map fields or click on generate mapping to
automatically map the fields.
After mapping is done save the changes and click on the generate icon as shown below to generate
run time artifacts.
Step6. In the Events section, define an event. Now the goto methods section.
Step19. Here initially we triggered a business object event. Now we have to change with the
Class event.
Step20. provide the class, event and activate it. Go Back.
Step22. Create a report and call the method to raise the Class event.
Step23. So here is the report output.
Here we got an error in the execution of a background task because of a syntax error in the
method of a class.
This situation is not desired and workflow hangs out with error. It’s possible to fix programming
errors for future runs of the workflow but what about the current erroneous ones? SAP provides
transaction SWPR in order to recover workflows that have errors.
In SWPR it’s possible to search by workflow definition or workitemid or by date
When we run the report in the second screen we see the list of workflows that got error
We can select the workflow instance(s) that we want to restart. When we click on “Restart
Workflow” workflow the workflows we selected are executed.
The good thing is that workflow is not started from the beginning. Only the step that got the error
is executed. This avoids the previous steps to be executed again and undesired result as a
result of repeated execution of steps.
Method 1
First Pick one Workflow Method that is executed in Background and pick the Respective Method that
is getting called and put the External Debug Point as mentioned below.
Go to Utilities->Settings
For SAP S/4HANA put the User id as SAP_WFRT and for SAP ECC provide WF-BATCH
Now go to the Workflow Log and Execute a step that will trigger the Background method
Method 2:
Most ABAPers are dependent on debuggers more than code editors . In the same way when I
learnt workflow, I was wondering if I can debug workflow like R3 report/WDA. There are some
situations while executing the workflow where we need to check container values on runtime
and the data flow through the workflow.
So for all the ABAPers, refer below steps. This is the magic trick to debug workflow
1. Open the BOR method which you want to debug. Put below code in it. Save and
generate the BOR.
This is infinite loop code.
4. Select that record and click Administration from the menu bar.
Go to Program and then click on Debugging, this will open a new session for debugger.
Method 1:
● Enter the transaction code in the command bar, for which you would like to
search for an user exit and then click on enter, so that it would take you to the
initial screen of the transaction.
● Go to Menu bar – Click on ‘System‘ and then click on ‘Status‘ as shown in the
below screenshot.
○ Once you click on the ‘Status‘ below the screen will pop up. Here, double click
on the program name.
○ Once the program window is open, go to Menu Bar –> click on ‘Goto‘ and then
click on ‘Object Directory Entry‘.
○ The above step would take you to a pop up window and here copy the Package
Name as shown in the below screenshot.
○ Once you get the package number, execute the transaction code SE80 (We can
also try with SE84) and then click on ‘Repository Information System’.
○ As soon as you are done with the above step the system would display the
respective Objects list, here drill down Enhancements and then Customer
Exists.
○ Now, double click on Enhancements, which is under Customer Exists, so that
the selection screen would get displayed on the right side.
○ Here go to package field and paste the copied package number from the
previous step (program) and then execute the transaction as shown in the below
screenshot.
○ As soon as you execute the above step, it would display the list of user exits for
the relevant transaction / package number.
In order to find out the relevant BADi for a transaction code, follow the above steps but instead
of expanding Customer exits, expand Business Add-ins as shown below.
○ Drill down Business Add-ins and then double click on Definitions, so that the
selection window would open on the right side of the screen. Here enter the
copied package number in the Package field and then execute the transaction as
shown below.
○ As soon as you execute the above step, it would display the list of BADi’s for the
relevant transaction / package number.
Method 2:
○ Execute the transaction code SE93 –> enter the desired transaction code in
Transaction Code field and then click on Display button as shown in the below
screen shot.
○ Once you click on the Display button it would show the below screen, double
click on the program name.
○ Once the above step is done, go to Menu Bar–> click on ‘Goto‘ and then click on
‘Object Directory Entry‘.
○ As soon as you are done with the above step, the system would pop up with a
window as shown below, copy the Package name for the further process.
○ Once you get the package number execute the transaction code SMOD –> place
cursor on Enhancement field and then press F4.
○ It would take you to the below screen (Repository Info Systems). Enter the
package number, which has been copied from the previous step. And then click
on the enter button.
○ As soon as you execute the above step, it would display the list of user exits for
the relevant transaction / package number.
Method 3:
Along with above methods I would like to show the ways to find the Exist / BADi’s at
configuration / SPRO as well.
Example: If you would like to know the relevant user exits at the functionality level like,
‘Logistics Invoice Verification’, follow the below steps.
○ Execute the transaction code SPRO and click on SAP Reference IMG –> drill
down Materials Management –> Logistics Invoice Verification –> Maintain
Customer Exits and Business Add-Ins –> click on IMG Activity Document on
Maintain Customer Exits for Invoice Verification, so that it would show the list of
Customer / User Exits for the functionality.
In order to find out the relevant BADi at the functionality level, follow the above steps but
instead of clicking on click on IMG Activity Document for Maintain Customer Exits for Invoice
Verification, click on IMG Activity Document for Maintain Business Add-Ins for Invoice
Verification, so that it would display the , so that it would show the list of BADi’s for the
functionality.
Method 4:
If you find difficulty in finding the exact node, follow the below steps
○ Execute the transaction code SPRO and click on SAP Reference IMG–> click on
Find button or press Ctrl+F.
○ Once you click on the find button the below pop up window gets displayed –>
enter Customer Exits in the Search Term field and then press enter button.
Once you hit enter, the system would provide you the list of results for the search term, which
you have entered. You should be very patient in finding the right node as the list would be very
big. You can take the ‘In Area’ reference as that would provide the information about the
functionality of the node. Refer to the below screenshot for your info.
As soon as you find the right node, double click on it and it will take you to the configuration
node, for which it belongs.
● Now you can click on the IMG Activity Document for Maintain Customer Exits for
Invoice Verification to display the relevant Exits.
2. Follow the same steps to get relevant BADi’s.
Why BADI?
In contrast to the earlier enhancement techniques, BADI follows an Object Oriented approach to
make them reusable. A BADI can be used any number of times whereas standard enhancement
techniques can be used only once.
For example if we assign an enhancement to one custom project, then that enhancement
cannot be assigned to any other custom projects. To overcome this drawback SAP has provided
a new enhancement technique called BADI.
SE18
When you create a BAdI definition, a class interface will be automatically created and you can
define your methods in the interface. The implementation of the methods can be done in SE19
transaction.
When a BAdi is created following are automatically generated:
● An interface with 'IF_EX_' inserted between the first and second characters of the BAdi
name
● An adapter class with 'CL_EX_' inserted between the first and second characters of the
BAdi name.
SE19
Types of BADI's:
While creating a BADI using the T-code SE18, it provides the pop-up screen to select the type
of BADI to be used as shown below.
With this option, any number of active implementations can be assigned to the same definition
BADI. By default this option is checked.
If we want the BADI for multiple use
If you have multiple-use BADI definitions, the sequence must not play any role.
The drawback in Multiple use BADI is, it is not possible to know which BADI is active especially
in country specific versions.
Using this option we can define the BADI's according to the filter values to control the add-in
implementation on specific criteria.
Method 1:
4. Run any transaction on which we want to find the BADI's say VA01.
Method 2:
Go to transaction SE84 and click on Enhancements. Then double click on Business Add-Ins.
For example, if you want to find the BADI's for the standard transaction ME22n, the procedure is
as follows. This example shows finding the way of BADI names by providing the Package of
ME22n.
1) Go to transaction ME22n. Select the System option from the menu and then click on
Status. It displays the following information.
2) Double click on the program name i.e. SAPLMEGUI. It will take you into the program
and click on Go to tab from the Menu. There we can find the package name of the standard
transaction ME22n.Copy and paste it in the package field.
3) Now Press F8, a list of BADI names will be displayed as shown below. Select the
appropriate BADI name and implement it based on the business requirement using the
transaction SE19.
Method 3:
3) A list of BADI names will be displayed for the transaction VA02. Select the appropriate
BADI name and implement it using T-code SE19.
Go to system -Status.
Check and click on the program and open it.
Click on Find
Put the package as VB (which we got from the program) and execute.
Below is the list of different enhancements which are available for this Tcode
We have double-clicked on the SAPLV01Z here we get 2 function modules where we need to
check the documentation if available or we need to apply break-point and try to check if it is
getting triggered.
Double click on the Include and hit enter to get it into the include… and here you can write and
do the customization.
Conclusion:
By this way, we can find the right enhancement to enhance the SAP standard Tcode / Code.
The database system automatically sets database locks when it receives change statements
(INSERT, UPDATE, MODIFY, DELETE) from a program. Database locks are physical locks on
the database entries affected by these statements. You can only set a lock for an existing
database entry, since the lock mechanism uses a lock flag in the entry. These flags are
automatically deleted in each database commit. Database locks are therefore never available
longer than for only one database LUW. That means that in ABAP application programming,
database locks can no longer exist for the duration of one dialog step.
Lock Types
There are four types of locks in the SAP System:
● Shared lock
● Exclusive lock
● Exclusive but not cumulative lock
● Optimistic lock
Core Data Service (CDS) Views are virtual data models of SAP HANA which allows direct
access to underlying tables of the HANA database. SAP CDS Views came into being with SAP’s
new programming model. SAP CDS Views aim to push logic from the application server to the
client-side and database. This is defined by SAP as ‘Code -to-Data’ or ‘Code Pushdown’. An
SAP CDS View is what performs the ‘Code-to-Data’ or ‘Code Pushdown’. The SAP CDS View
picks up the logic from the ABAP application and executes it on the database rather than the
application server.
SAP CDS Views are of 2 types:
1,HANA CDS Views
2.ABAP CDS views.
Associations: These define the relationships between SAP CDS Views and annotations and
direct the use of CDS artifacts on specific domains. On a conceptual level, joins are replaced
with simple path expressions in queries. About SAP SLT Replication
Expressions: These are used in situations where specific CDS attributes are considered as
values to be aggregated. In the data model they are used for calculations and queries. SAP
ECC and Data Extraction from an LO Data Source
Annotations: These are code snippets for enabling specific functions or for adding metadata
that is component-specific to a CDS View. Depending on their placement, annotations can be
Header annotations (affect the entire view and placed in the header of the file) or Body
annotations (affect only the line of code in front of which they are placed) Annotations provide
domain-specific metadata to enhance the data models.
try.
lr_container_temp_0194 ?= ls_container.
ls_container ?= lr_container_temp_0194->modify_text_tab( lt_text_194 ).
catch cx_hrpa_violated_assertion into ls_exp.
lw_message = ls_exp->get_text( ).
endtry.
*Modify the record -After this method check PA0194 for specific record ITXEX should be ‘X’
try.
lo_0194->if_hrpa_infty_bl~modify(
exporting
old_container = lr_container_temp_0194
massn = space
massg = space
update_mode = lw_update_mode
no_auth_check = ”
message_handler = fr_msg_handler “Message handler
importing
is_ok = lw_ok “Ok flag
changing
container = ls_container ).“Infty Container.
catch cx_hrpa_violated_assertion into ls_exp.
lw_message = ls_exp->get_text( ).
endtry.
if lw_ok ne gc_true and lw_message is not initial.
try.
cl_hrpa_masterdata_bl=>get_instance(
importing
masterdata_bl = lw_masterdata_buffer ).