Sunday, 7 April 2013

SAP ABAP Interview Questions-usefull




Looking for ABAP interview questions? You have come to THE RIGHT place. I have planned to
continuously update this blog post. So if you have been appearing for interviews recently , share your experiences in the comments below:

Let’s make this list count and add some value to everyone.
All the best for your interview preparation . J Here you go!!


SAP ABAP interview questions: 


Important 

Question 1: What is the difference between User Exit and Function Exit?

User Exit
Customer Exit
User exit is implemented in the form of a Subroutine i.e. PERFORM xxx.
Example: INCLUDE MVF5AFZZ 
à
PERFORM userexit_save_document_prepare.  
A customer exit can be implemented as:
·         Function exit
·         Screen Exit
·         Menu Exit
·         Field Exit
Example: CALL Customer function ‘xxx’
INCLUDE xxx.
You modify this include.
In case of a PERFORM, you have access to almost all the data. So you have better control, but more risk of making the system unstable.
You have access only to the importing, exporting, changing and tables parameter of the Function Module. So you have limited access to data.
User exit is considered a modification and not an enhancement.
A customer exit is considered an enhancement.
You need Access Key for User Exit.
You do not need access key.
Changes are lost in case of an upgrade.
Changes are upgrade compatible.
User exit is the earliest form of change option offered by SAP.
Customer exits came later and they overcome the shortcomings of User Exit.
No such thing is required here.
To activate a function exit, you need to create a project in SMOD and activate the project.



  
 What is the difference between RFC and BAPI?
BAPI
RFC
Just as Google offers Image/Chart/Map APIs OR Facebook offers APIs for Comment/Like, SAP offers APIs in the form of BAPIs. BAPI is a library of function modules released by SAP to the public so that they can interface with SAP.
RFC is nothing but a remote enabled function module. So if there is a Function Module in SAP system 1 on server X , it can be called from a SAP system 2 residing on server Y.
There is a Business Object Associated with a BAPI. So a BAPI has an Interface, Key Field, Attributes, Methods, and Events.
No Business Object is associated with a RFC.
Outside world (JAVA, VB, .Net or any Non SAP system) can connect to SAP using a BAPI.
Non–SAP world cannot connect to SAP using RFC.
Error or Success messages are returned in a RETURN table.
RFC does not have a return table.



Question 3:
What is the difference between SAPSCRIPT and SMARTFORM? 
SAPSCRIPT
SMARTFORM
SAPSCRIPT is client dependent.
SMARTFORM is client independent.
SAPSCRIPT does not generate any Function module.
SMARTFORM generates a Function Module when activated.
Main Window is must.
You can create a SMARTFORM without a Main Window.
SAPSCRIPT can be converted to SMARTFORMS. Use Program SF_MIGRATE.
SMARTFORMS cannot be converted to SCRIPT.
Only one Page format is possible
Multiple page formats are possible.
Such thing is not possible in SCRIPT.
You can create multiple copies of a SMARTFORM using the Copies Window.
PROTECT … ENDPROTECT command is used for Page protection.
The Protect Checkbox can be ticked for Page Protection.

The way SMARTFORM is developed and the way in which SCRIPT is developed is entirely different. Not listing down those here. That would be too much. 


Question 4:What is the difference between Call Transaction Method and the Session method ?

Session Method
Call Transaction
Session method id generally used when the data volume is huge.
Call transaction method is when the data volume is   low
Session method is slow as compared to Call transaction.
Call Transaction method is relatively faster than Session method.
SAP Database is updated when you process the sessions. You need to process the sessions separately via SM35.
SAP Database is updated during the execution of the batch input program.
Errors are automatically handled during the processing of the batch input session.
Errors should be handled in the batch input program.


Question 5: What is the difference between BDC and BAPI?

BAPI
BDC
BAPI is faster than BDC.
BDC is relatively slower than BAPI.
BAPI directly updates database.
BDC goes through all the screens as a normal user would do and hence it is slower.
No such processing options are available in BAPI.
Background and Foreground processing options are available for BDC.
BAPI would generally used for small data uploads.
BDCs would be preferred for large volumes of data upload since background processing option is available.
For processing errors, the Return Parameters for BAPI should be used.This parameter returns exception messages or success messages to the calling program.
Errors can be processed in SM35 for session method and in the batch input program for Call Transaction method.


Question 6: What is the difference between macro and subroutine?

Macro
Subroutine
Macro can be called only in the program it is defined.
Subroutine can be called from other programs also.
Macro can have maximum 9 parameters.
Can have any number of parameters.
Macro can be called only after its definition.
This is not true for Subroutine.
A macro is defined inside:
DEFINE …
….
END-OF-DEFINITION.
Subroutine is defined inside:
FORM …..
…..
ENDFORM.
Macro is used when same thing is to be done in a program a number of times.
Subroutine is used for modularization.



Question 7: What is the difference between SAP memory and ABAP memory?

SAP Memory
ABAP Memory
When you are using the SET/GET Parameter ID command, you are using the SAP Memory.
When you are using the EXPORT IMPORT Statements, you are using the ABAP Memory.
SAP Memory is User Specific.
What does this mean?
àThe data stored in SAP memory can be accesses via any session from a terminal. 
ABAP Memory is User and Transaction Specific.What does this mean?à The data stored in ABAP memory can be accessed only in one session. If you are creating another session, you cannot use ABAP memory.


Important
Question 8:
 What is the difference between AT SELECTION-SCREEN and AT SELECTION-SCREEN OUTPUT?
AT SELECTION-SCREEN is the PAI of the selection screen whereas
AT SELECTION-SCREEN OUTPUT is the PBO of the selection screen.



Question 9: What is the difference between SY-INDEX and SY-TABIX?
Remember it this way 
à TABIX = Table.
So when you are looping over an internal table, you use SY-TABIX.
When you use DO … ENDDO / WHILE for looping, there is no table involved.
So you use SY-INDEX.

For READ statement, SY-INDEX is used.

Question 10: What is the difference between VIEW and a TABLE?A table physically stores data.
A view does not store any data on its own. It can contain data from multiple tables and it just accesses/reads data from those tables.

Question 11:
 What is the difference between Customizing and Workbench request?A workbench request is client independent whereas a Customizing request is client dependent.
Changes to development objects such as Reports, Function Modules, Data Dictionary objects etc. fall under Workbench requests.

Changes in SPRO / IMG that define system behavior fall under customizing requests.
An example would be ‘defining number ranges’ in SPRO.

In short, generally a developer would end up creating a Workbench request and a Functional Consultant would create a Customizing request.

Workbench vs Customizing work request

Question 12: What is the difference between PASS BY VALUE and PASS BY REFERENCE?These concepts are generally used for Function modules or Subroutines etc. and their meaning can be taken literally.

Say we are passing a variable lv_var:
CALL FUNCTION 'DEMO_FM'
   EXPORTING
     VAR  = lv_var.

When we PASS lv_var by VALUE , the actual value of lv_var is copied into VAR.
When we PASS lv_var by REFERENCE , the reference or the memory address of lv_var is passed to the Function module. So VAR and lv_var will refer to the same memory address and have the same value. 


Question 13: What is the difference between Master data and Transaction data?Master data is data that doesn’t change often and is always needed in the same way by business.
Ex: One time activities like creating Company Codes, Materials, Vendors, Customers etc.

Transaction data keeps on changing and deals with day to day activities carried out in business.
Transactions done by or with Customers, Vendors, and Materials etc. generate Transaction Data. So data related to Sales, Purchases, Deliveries, Invoices etc. represent transaction data

Some important transactions here for Master Data:
Material: MM01 MM02 MM03
Vendor: XK01 , XK02 , XK03
Customer: Xd01 , XD02 , XD03

Some Important transactions for Transaction data:
Purchase Order: ME21n , ME22n , ME23n
Sales Order: VA01 , VA02 , VA03
Goods Receipt: MIGO
Invoices: MIRO



Important
Question 14: What will you use SELECT SINGLE or SELECT UPTO 1 ROWS ?
What will you use SELECT SINGLE or SELECT UPTO 1 ROWS ?
There is great confusion over this in the SAP arena.
If you Google, you will see lots of results that will say SELECT SINGLE is faster and efficient than SELECT UPTO 1 ROWS.
But that is 100% incorrect.

SELECT UPTO 1 ROWS is faster than SELECT SINGLE.
If for a WHERE condition, only one record is present in DB, then both are more or less same.
However, If for a WHERE condition multiple records are present in DB, SELECT UPTO 1 ROWS will perform better than SELECT SINGLE. 

 
Question 15: What is the difference between .Include Structure and .Append structure? 
I have seen ridiculous answers for this at many places on the Web.
The true answer is this:

Let’s say you want to use the Structure X in your table Y.
With .Include X, you can include this structure in multiple tables.
With .Append X, you specify that structure X has been used in table Y and that this cannot be used in any other table now.  So you restrict structure X only to Table Y.

Important 
Question 16: Can you describe the events in ABAP?

LOAD-OF-PROGRAM:
INITIALIZATION: If you want to initialize some values before selection screen is called
AT SELECTION SCREEN OUTPUT: PBO for Selection Screen
AT SELECTION SCREEN: PAI for Selection Screen
START-OF-SELECTION
END-OF-SELECTION
TOP-OF-PAGE
END-OF-PAGE

AT USER-COMMAND: When user click on say buttons in application toolbar. SY-UCOMM
AT LINE SELECTION:
 Double click by user on basic list. SY-LISEL
AT PF##: When User Presses any of the Function Keys
TOP-OF-PAGE DURING LINE SELECTION


Question 17:

What events do you know in Module Pool Programming?
PBO:
 you know this . If not you should know this . That's basic.
PAI: You know this. If not you should know this . That's basic.
POV: Process on Value request … i.e. when you press F4.
POH: Process on help request … i.e. when you press F1.
Question 18: Can you show multiple ALVs on a Single Screen?
Yes, there are multiple ways of doing this:
·         If you are using OOALV, you can create multiple custom containers  
   (cl_gui_custom_container)
 & put an ALV control (cl_gui_alv_grid) in each of those.
·         You can even use a Splitter container control and place multiple ALVs in each of
    the split container.
·         If you are using Normal ALV, You can use the following FMS:
1.      REUSE_ALV_BLOCK_LIST_INIT
2.      REUSE_ALV_BLOCK_LIST_APPEND
3.      REUSE_ALV_BLOCK_LIST_DISPLAY

Question 19: A system has two clients 100 and 500 on the same application server. If you make changes to a SAPSCRIPT on client 100, will the changes be available in client 500?

No. SAPSCRIPT is client dependent. You will have to transport changes from client 100 to client 500. However, for SMARTFORMS, Changes will be made both for client 100 and client 500.

Question 20: There are 1000’s of IDOCs in your system and say you no longer need some of them? How will you get rid of those IDOCs?

One way is to archive the IDOCs using transaction SARA.
But what the interviewer was expecting was ‘How do you change IDoc Status’?
There are different ways of doing this:
A) Use FM IDOC_STATUS_WRITE_TO_DATABASE
B) USE FMs:
     EDI_DOCUMENT_OPEN_FOR_PROCESS and
     EDI_DOCUMENT_CLOSE_PROCESS


Question 21: What is the difference between CHAIN … ENDCHAIN and FIELD commands in Module Pool?

If you want to validate a single field in Module Pool, you use the FIELD Command.
On error, this single filed is kept open for input.

If you however want to validate multiple fields, you can use the CHAIN … ENDCHAIN command. You specify multiple fields between CHAIN and ENDCHAIN.
On error, all fields between CHAIN …… ENDCHAIN are kept open for input.



Question 22:
 What are the types of Function Modules? What is an UPDATE function module?There are three types of Function Modules: Normal , RFC , UPDATE.
The aim of the Update function module is either to COMMIT all changes to database at once or to ROLLBACK all the changes. By definition, an update function module is used to bundle all the updates in your system in one LUW (logical unit of work).

This FM is called whenever COMMIT WORK statement is encountered in the calling program and the way you call it is CALL FUNCTION XXX IN UPDATE TASK. 

Have a look at FM EDI_DOCUMENT_CLOSE_PROCESS_UPD and do a where used.
This FM is used as Update FM in case you make changes to IDoc contents/status via your program.

Question 23: How is the table sorted when you do not specify field name and Ascending or Descending? On what criteria will the table be sorted? Do internal table have keys?

Yes, internal table have keys.
The default key is made up of the non-numeric fields of the table line in the order in which they occur.



Question 24: Explain what is a foreign key relationship?Explain this with the help of an example.
Let’s discuss about tables EKKO (PO header) and EKPO (PO line item).
Can you have an entry in table EKPO without having an entry in table EKKO?
In other words can you have PO line items without the PO header?

How does this happen? The answer is foreign key relationship.
So foreign keys come into picture when you define relationship between two tables.


Foreign key relationship in ABAP

  
Foreign keys are defined at field level.
Check the foreign key relation for field EBELN of table EKPO.
The check table is EKKO. This just means that whenever an entry is made in EKPO, it is checked whether the entered value for EBELN already exists in EKKO. If not, entry cannot be made to EKPO table.
 

Question 25 : What is the difference between a value table and a check table?Check table is maintained when you define foreign key relationships.
For Check table, read question above.
.
Value table is defined and maintained at a domain level.
At a domain level, you can mention allowed values in the form of:
1) Single values
2) Ranges
3) Value table
For example, have a look at domain SHKZG. Only allowed values are S and H for Debit/Credit indicator. Whenever and wherever you use this domain, the system will force you to use only these two values: S and H.

Another example is domain MATNR. For this domain the value table is MARA.
So whenever and wherever, you use this domain the system will force you to use values for MATNR in table MARA.


Question 26: How do you find BAPI?Approach1:
You can go to Transaction BAPI and then search for your desired object.
Say you want to find a BAPI for creating users in the system, in such case you can search for the ‘User’ and find the relevant BAPIs.

Approach2:
Another way is to find a Business Object. Say you want to find a BAPI for creating Material in SAP and you know the BO for Material is BUS1001006. You can go to Transaction SWO1 and enter the BO BUS1001006 in the BOR. Then have a look at the methods for this BO.
How to Find a BAPI ?



Important 
Question 27: How do you find BADI?
Approach1: 

Go to Class CL_EXITHANDLER in SE24 ---> Put a breakpoint in method GET_INSTANCE.Now go and execute your transaction code for which you want to find BADI.
You will find the BADI in the changing parameter exit_name:

How to find a BADI in ABAP ?


Approach 2:
Go to Tcode SE84 à Enhancements àBADIs à Definitions.
Find the package for the Tcode for which you are finding the BADI.
Enter it as shown and hit execute:


How do you find a BADI ?

Find BADI in SAP
Are we done yet ? Definitely not !
Let the questions come and lets keep on updating this blog.

I will update the blog with the following questions soon:
Question: Synchronous and asynchronous methods in BDC ?
Question: What is the difference between inner joins and outer joins?
Question: What is the difference between INSTANCE methods and STATIC methods?
Question: What is the difference between Implicit Enhancements and Explicit Enhancements?
Question: What is the difference between Enhancement point and Enhancement Section?
Question: How do you find Function Exit?
Question: How do you activate a Function Exit?






Welcome to yet another post on ABAP interview questions. Here I have complied a list of interview questions on Smartforms in SAP. This list is quite comprehensive. Hope you find it useful. Cheers !!

Smartform is SAP's print form technology and is an alternative to SAP-Scripts. Whenever you activate a Smartform , a function module is generated for that Smartform. The program that calls this function module is called the Driver Program for Smartform. The T.code for Smartforms is SMARTFORMS.

Unlike SAP-Scripts, Smartforms are client independent.

Here we go:

*An SAP R/3 system has 2 clients 800 & 810. You create an SAP Script Z_Script and a Smartform Z_Smartform in client 800. Will both Z_Script and Z_Smartform be available in client 810 as well?
Client 200 will have just the Smartform Z_Smartform and not the SAP Script Z_Script.

SAP-Script is client dependent whereas SMARTFORM is client independent. Many people don't understand what this is all about. The above answer should suffice. However, if you still do not understand this, find an SAP system where you have 2 clients. Create a dummy Smartform / script in one client and check whether they exist in the other client.

*You have created a Smartform in DEV environment. Then you migrated the Smartform to PROD environment. Will the name of the function module be same in DEV and PROD?
Once you transport the Smartform from DEV to PROD environment, a new function module name for the Smartform in generated in the PROD environment. For a particular Smartform , generated function module names are different in different systems.One can get the name of the function module for Smartform by passing the Smartform name to FM SSF_FUNCTION_MODULE_NAME.

Hence in the driver program for Smartform, it is common practice to use FM SSF_FUNCTION_MODULE_NAME and then calling the Smartform Function Module.

CALL FUNCTION
 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Z_SMARTFORM'
IMPORTING
fm_name = lv_fm_name

CALL FUNCTION lv_fm_name

*How do you convert a Smartform Output to PDF output?
There is a tricky solution here.But let's keep that for the last. Let us first discuss the conventional way of getting a PDF output for Smartform. For that you need to keep in mind the following two function modules and their importing/exporting parameters:

CONVERT_OTF
CONVERT_OTF_2_PDF

In the Driver program, import the parameter 'job_output_info' from the Smartform FM and utilize that info in 'OTF' parameter of the two aforementioned function modules.

Here is one more and probably the easiest way to see PDF output for a Smartform.
Type PDF! in the command prompt and hit enter :).



To see the Smartform Print Preview output as list output,
Type SLIS in the command prompt and hit enter.



*How do you achieve Bar Code printing in Smartforms?
Step1: Use SE73 i.e. SAP-Script Font Maintenance and create a Bar code say ZDEMO.
Step 2: For Smartform, create a character format C1 and use the recently created Barcode ZDEMO.




It can be finally used to print Barcode as:
 

How do you add a Watermark Or a Background Image for Smartforms ?
If you go to the properties of a page in Smartform, you will find a tab for Background Image.
Specify the source of the image you need here and it can be used as background image / Watermark in Smartforms.

Graphics can be maintained using T.code SE78.
Background Image for Smartforms


How will you print on both sided of a Smartform?
At the Page level in Smartforms, you can find something called as Print Mode.
Set the Print mode to duplex to print on both sides of the Smartform.Duplex Print mode in Smartforms


What is the difference in a Table and a Template in Smartform?A Template has fixed number of Rows and Columns whereas a Table can have variable rows and columns i.e. you can have a internal table with contents associated to a Table element but not to a Template.

You should use a template when the tabular output is fixed!

How do you achieve Page Protection in Smartform ?While one can use the PROTECT ..... ENDPROTECT command for SAP-Scripts, for Smartforms the Page-Protection checkbox can be used to ensure page protection:
Page Protection in Smartforms
Note:  You have Page-protection property only for Text Elements in the Main Window.

Can you move a Smartform from one SAP system to another without using transports ?
Yes, this can be achieved using the Upload/Download feature for Smartforms.
One can download the Smartform from one system and save it as an XML file.
Once that is done, the XML file can be used to upload the Smartform in another system.
  
Upload / Download Smartform


Can you have a Smartform without a main window?
Yes, you can create a Smartform without a Main Window. But there is no need to do anything of such sort.
Whenever you create a Smartform, a main window is created by default. I can't think of a situation , where you will have a situation in which it is mandatory for you to remove the Main Window. But still I have seen this question in ABAP interviews. So I have put it here.

How do you find the name of the Function Module for a Smartform?
When is this function module created?
The function module for Smartform is created when the Smartform is activated.
You can find the name of the Function Module for a Smartform by going to
Environment --> Function Module Name.

What is a Copies Window?

What is a Final Window?
Final Window is called after all the other windows are called in a Smartform.

How do you pass data to Smartforms from the driver program?

How do you Debug Smartforms ?

How would you go about printing a logo in a Smartform?

How do you print address number in Smartforms ?

How do you print Symbols and Icons in Smartforms?

What are Basic Nodes and Auxiliary Nodes ?

What is the use of Folder in Smartforms ?


What is BDC and why do we use BDC ?
BDC ( Batch Data Communication ) also known as batch input is a technique by which large volumes of data can be transferred from Non Sap or Legacy systems to SAP systems.
BDC in SAP
Example:  A Legacy system that is to be replaced by SAP has say 1000 Customers , 2000 vendors and 3000 materials. All this data needs to be transferred to SAP . In such cases , We can use BDC.

If the old system is replaced by SAP, such a transfer is called Conversion.
If the old system runs along with SAP, in that case the transfer is called an Interface.

The two methods for BDC are:
  • Session Method
  • Call TRANSACTION Method
  • CALL DIALOG (Outdated)

ABAP interview questions on BDC:

Important:
Question 1:What is the difference between Call Transaction Method and the Session method ?

Session Method
Call Transaction
Session method id generally used when the data volume is huge.
Call transaction method is when the data volume is   low
Session method is slow as compared to Call transaction.
Call Transaction method is relatively faster than Session method.
SAP Database is updated when you process the sessions. You need to process the sessions separately via SM35.
SAP Database is updated during the execution of the batch input program.
Errors are automatically handled during the processing of the batch input session.
Errors should be handled in the batch input program.

Important:
Question 2: How do you do BDC for a table control?
With other things as usual, there is a special trick that you have to use while doing BDC for table control.
You need to use the BDC OKCODE '=P+'.
Its the BCD_OKCODE for Page down that can be used for scrolling down in table control.

Important:
Question3: Is there any method apart from BDC for data upload to SAP?
Apart from BDC and LSMW, you can use BAPIs to upload data into SAP.
BAPIs should be preferred over BDCs, because they process data faster than BDC.
A BAPI is faster since it updates Database "directly". Whereas BDC calls transaction and goes through the whole screen sequence as any user would do.

BAPI
BDC
BAPI is faster than BDC.
BDC is relatively slower than BAPI.
BAPI directly updates database.
BDC goes through all the screens as a normal user would do and hence it is slower.
No such processing options are available in BAPI.
Background and Foreground processing options are available for BDC.
BAPI would generally used for small data uploads.
BDCs would be preferred for large volumes of data upload since background processing option is available.
For processing errors, the Return Parameters for BAPI should be used.This parameter returns exception messages or success messages to the calling program.
Errors can be processed in SM35 for session method and in the batch input program for Call Transaction method.


Question 4: How do you process errors in Call Transaction method ?

Let's have a look at the syntax for CALL TRANSACTION method.
Sample code:
DATA: BEGIN OF G_T_MESSTAB OCCURS 0.
        INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF G_T_MESSTAB.

CALL TRANSACTION 'MB11'
    USING G_T_BDCDATA
          MODE 'E'
          UPDATE 'S'
          MESSAGES INTO G_T_MESSTAB.

All the error messages will be trapped inside G_T_MESSTAB.

Question 5: What is the use of program RSBDCSUB?
There are two ways to process the BDC sessions:
1) Go to SM35 ---> Choose session ---> hit process.
     Now See Question no. 10.
2) Use program RSBDCSUB.
     RSBDCSUB schedules the session to be processed in background.


Let's take an example to understand this.

The sessions are created at one point of time and processed at other point of time and this may create a problem: For example: a BDC program creates a session for updating 1500 customers in SAP. However , before this session is processed via SM35 , a user inserts 100 customers in the system manually. In this case , the session will have at least 100 errors when the session is processed from SM35.

One way to avoid this is to use the program "RSBDCSUB" in the batch input program itself so that the session is processed as soon as it is created.
RSBDCSUB schedules the session to be processed in background.

Question 6: What is the structure of the BDC table?

The BDCDATA consists of the following fields:
§  PROGRAM [CHAR 40] - Online program name.
§  DYNPRO [NUMC 4] - Screen number.
§  DYNBEGIN [CHAR 1] - Flag to indicate the start of a new screen.
§  FNAM [CHAR 132] - Field name of a screen field to be filled with data.
§  FVAL [CHAR 132] - The actual value to be filled into the specified screen field.

Sample Screenshot:
BDCDATA structure
BDCDATA table structure

Question 7: What is the difference between BDC_OKCODE and BDC_CURSOR?

BDC_OKCODE: is used for storing commands during the recording. like '/00' is the command for 'ENTER' Key.
BDC_CURSOR: contains the cursor position. it contians the field in which cursor will be.

Example code:
perform bdc_field       using 'BDC_CURSOR'
                                                'PROJ-PSPID'.
perform bdc_field       using 'BDC_OKCODE'
                                                '=BU'.

Question 8: What are the 3 methods that we use in sequence in a Batch input session method ?

1) BDC_OPEN_GROUP for opening the Batch Input Session
2) BDC_INSERT for inserting the transactional data into SAP
3) BDC_CLOSE_GROUP for closing the Batch Input Session

If there are n records , the BDC_INSERT method should be called n times.
BDC_OPEN_GROUP and BDC_CLOSE_GROUP are called only once.

General Information about a session is stored in table APQI.

Transaction data for a session is stored in table APQD.

Question 9: What is your approach for writing a BDC program?


Identify the Tcode and do the recording in SHDB to populate the BDCDATA.



Once the recording is done , one can Transfer it to the Batch input program.




In the batch Input program , The transactional data is read from the file to an internal table.

Then one can loop over the transactional data in the internal table and start uploading the data in SAP either by CALL TRANSACTION method or by creating sessions through the batch input program.

Question 10: How do you process errors in Session method ?
You can go to Transaction SM35 , Choose the session name and click on Process.
Question 11: What are the different modes of processing batch input sessions?  


The three modes are:

Foreground

Display Errors Only

Background

Question 12: What is the difference between Synchronous and Asynchronous Update ?
In Synchronous update , the database is updated before the next transaction is taken for processing in a batch input.
In Asynchronous update , the system doesn't wait for updating the database before the next transaction is taken for processing in a batch input.



Question 13: What is the transaction for Recording BDC ?
 
The Tcode is SHDB.

Question 14: How do you read files from the Application server ?
 
You can use the commands:
OPEN DATASET ---> opens the file(dataset) either in read /write mode.
READ DATASET ---> Read the file
CLOSE DATASET ---> Close the dataset once the date has been read .

Question 15: How do you read files from the presentation server ?
You can use the Function Modules :
GUI_UPLOAD --> To read data from file into an internal table
GUI_DOWNLOAD --> To write data from internal table to a file on presentation server


    ABAP Performance Standards


    ABAP Performance Standards


    Description
    Result (Y, N or N/A)
    Comments
    Run Extended syntax checks with character literals checkbox switched on & Code Inspector to rectify all relevant errors and warning (e.g. Use the results of the above checks to remove all variables/constants etc that are declared but are not used)  
    Transaction SE30 (ABAP Runtime Analysis) must be checked to measure/compare program performance/runtime if program has multiple inefficient databases selects or complicated internal table operations  
    Use transaction ST05 (SQL Trace) to see what indices your database accesses are using. Check these indices against your “where” clause to assure they are significant. Check other indices for this table and where you have to change your “where” clause to use it. Create new indices if necessary, but do not forget to check the impact by consulting onsite coordinator.  
    TYPE (data element) command is used while declaring the fields whenever feasible instead of LIKE. Remember not always the data element name matches with the table field name  
    Internal Table is defined with “TYPE STANDARD TABLE OF” & Work-Areas is used instead of header lines  
    Global variables are minimized by declaring local variables or by passing variables through parameters & arguments while creating internal subroutine(s)  
    In SELECT statement, only the required fields are selected in the same order as they reside on the database table/structure/view  
    For selecting single row from a database table, “SELECT UP to 1 Rows” is used. “Select Single” is used only when full primary key combination is known  
    No SELECT * is used  
    Use “SELECT INTO TABLE” rather than “SELECT INTO CORRESPONDING FIELDS OF TABLE”  
    Always specify as many primary keys as possible in WHERE clause to make the Select efficient  
    Always select into an internal table, except when the table will be very large (i.e., when the internal table will be greater than 500,000 records). Use “Up to N Rows” when the number of records needed is known  
    Select statement within a GET event is not used  
    Wild cards like ‘A%’ is avoided as much as possible  
    Nested Select is not used instead “Inner Join” and/or “For all Entries” is used. “For all Entries” is to be used over “Loop at ITAB / Select / ENDLOOP” (FOR ALL ENTRIES retrieves a unique result set so ensure you retrieve the full key from the database)  
    When creating joins over database tables there should be an index at least on the inner table for the fields in the join condition else use “ FOR ALL ENTRIES” select statement  
    Usage of JOIN is limited to a maximum of 2 i.e. not more than 3 database tables are joined at one time  
    CHECK that the internal table used in FOR ALL ENTRIES is NOT empty as this will retrieve all entries from the table  
    Delete adjacent duplicate entries from internal table before selection from database table using “ FOR ALL ENTRIES” statement  
    For copying internal tables use ‘=’ operator instead of Looping & Appending  
    SORT inside a LOOP is not used  
    Sort internal table by fields in the correct order, which are used in a READ TABLE statement using BINARY SEARCH. If the order of sorting is invalid the BINARY SEARCH will never work  
    For large internal tables where only some rows are to be processed, use SORT and then the READ TABLE command is used to set index to first relevant row before looping from that index. Use CHECK or IF…EXIT…ENDIF as appropriate to exit from the loop  
    Sort fields and Sort Order on the SORT statement should be mentioned explicitly (e.g. SORT ITAB BY FLD1 FLD2 ASCENDING)  
    Hashed table is used for processing large amount of data (provided that you access single records only, and all with a fully specified key)  
    DELETE or SORT is not used on a hashed table since it increases memory consumption  
    Sorted table is used for range accesses involving table key or index accesses  
    Fields specified in the WHERE condition with the critical operators NOT and <> (negative SQL statements) cannot be used for a search using database indexes. Whenever possible formulate SQL statements positively  
    When coding IF or CASE, testing conditions are nested so that the most frequently true conditions are processed first. Also CASE is used instead of IF when testing multiple fields “equal to” something  
    LOOP AT ITAB INTO WORKAREA WHERE K = ‘XXX’ should be used instead of LOOP AT ITAB INTO WORKAREA / CHECK ITAB-K = ‘XXX’.Also READ TABLE INTO WORKAREA should be used instead of only READ TABLE.  
    After the APPEND statement inside a loop, the work area that has been appended is cleared  
    Internal tables, Work areas & Global Variables are freed when no longer needed (e.g. using the FREE / REFRESH command), especially when the tables are large or the program is a batch program  
    Do not delete the records of internal table inside the Loop – End loop.
    Do not use: LOOP AT ITAB WHERE EQUNR = ‘00001011’.
    DELETE ITAB.
    ENDLOOP.
    Use: DELETE ITAB WHERE EQUNR = ‘00001011’. 
      
    Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... for single line, and MODIFY ITAB ... TRANSPORTING f1 f2 ... WHERE condition for a set of line, to accelerate the updating of internal table  
    If possible, Update/Insert statement is used instead of Modify  
    Is the following steps ensured during database updates?
    • Lock data to be edited
    • Read current data from the database
    • Process data and write it to the database
    • Release the locks set at the beginning
      
    Try to avoid logical databases. If your program uses a logical database, but does not require all fields belonging to a certain GET event, always use the FIELDS addition to reduce the amount of data selected by the logical database  
    Avoid the aggregate (Count, Max, Min) functions in the database selection  
    Use Parallel Cursor methods for nested loop into the internal tables if second internal table contains considerable number of records  
    In Smartform/ Sapscript do not make redundant data retrieval where data is available in interface  





    What is the need of optimizing performance?

    In SAP programming, ABAP is the language used. Most of the projects focuses on getting a team of ABAP programmers as soon as possible and handing over the technical specifications to them and asking them to make out the ABAP programs within the "given deadlines".
    Often due to this pressure of schedules and deliveries, the main focus of making a efficient program takes a back seat. An efficient ABAP program is one which delivers the required output to the user in a finite time as per the complexity of the program, rather than hearing the comment "I put the program to run, have my lunch and come back to check the results".
    Leaving aside the hyperbole, a performance optimized ABAP program saves the time of the end user, thus increasing the productivity of the user, and in turn keeping the user and the management happy.
    This tutorial focuses on presenting various performance tuning tips and tricks to make the ABAP programs efficient in doing their work. This tutorial also assumes that the reader is well versed in all the concepts and syntax of ABAP programming.
    Performance of a program is also often limited due to hardware restrictions, which is out of the scope of this article.

    Correct Way For Selection

    Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code. 
    Incorrect
                Select * from zflight.
                 Check : zflight -airln = 'LF' and zflight-fligh = 'BW222'.
                Endselect.
    Correct            Select * from zflight where airln = 'LF' and fligh = '222'.
                Endselect.
    One more point to be noted here is of the select *. Often this is a lazy coding practice. When a programmer gives select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary load on the entire system. When the application server sends this request to the database server, and the database server has to pass on the entire structure for each row back to the application server. This consumes both CPU and networking resources, especially for large structures.
    Thus it is advisable to select only those fields that are needed, so that the database server passes only a small amount of data back.
    Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the server. Instead attempt must be made to select the fields into an internal table.

    How To use aggregate functions

    Using the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP code.
    Incorrect             Maximum_numb = 0.
                Select * from zflight where airln = 'LF' and cntry = 'IN'.
                 Check zflight -fligh > maximum_numb.
                 Maximum_numb = zflight -fligh.
                Endselect.
    Correct             Select max( field ) from ztable into maximum_numb where airln = 'LF' and cntry = 'IN'.
    The other aggregate functions that can be used are min (to find the minimum value), avg (to find the average of a Data interval), sum (to add up a data interval) and count (counting the lines in a data selection).

    Using Views in place of tables


    Many times ABAP programmers deal with base tables and nested selects. Instead it is always advisable to see whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly, rather than specially coding for it.
    Incorrect
                Select * from zcntry where cntry like 'IN%'.
                 Select single * from zflight where cntry = zcntry-cntry and airln = 'LF'.
                Endselect. 
    Correct
                Select * from zcnfl where cntry like 'IN%' and airln = 'LF'.
                Endselect.

    Use of the into table clause of select statement

    Instead of appending one record at a time into an internal table, it is advisable to select all the records in a single shot.
     Incorrect
                Refresh: int_fligh.
                Select * from zflight into int_fligh.
                 Append int_fligh. Clear int_fligh.
                Endselect.
     Correct
                Refresh: int_fligh.
                Select * from zflight into table int_fligh.

    Modify cluster of lines

    Use the variations of the modify command to speed up this kind of processing.
     Incorrect
                Loop at int_fligh.
                 If int_fligh-flag is initial.
                            Int_fligh-flag = 'X'.
                 Endif.
                 Modify int_fligh.
                Endloop. 
    Correct
                Int_fligh-flag = 'X'.
                Modify int_fligh transporting flag where flag is initial.

    Binary Search

    When a programmer uses the read command, the table is sequentially searched. This slows down the processing. Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half. 
    Incorrect
                Read table int_fligh with key  airln = 'LF'. 
    Correct
                Read table int_fligh with key  airln = 'LF' binary search.

    Appending 2 internal tables

    Instead of using the normal loop-endloop approach for this kind of programming, use the variation of the append command. Care should be taken that the definition of both the internal tables should be identical. 
    Incorrect
                Loop at int_fligh1.
                 Append int_fligh1 to int_fligh2.
                Endloop. 
    Correct
                Append lines of int_fligh1 to int_fligh2.

    Table Buffering

    Use of buffered tables is recommended to improve the performance considerably. The buffer is bypassed while using the following statements
    1. Select distinct
    2. Select ... for update
    3. Order by, group by, having clause
    4. Joins
    Use the Bypass buffer addition to the select clause in order to explicitly bypass the buffer while selecting the data.

    FOR ALL Entries

    Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
    1. Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
    2. If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
    3. If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
    Incorrect
                Loop at int_cntry.
                 Select single * from zfligh into int_fligh
     where cntry = int_cntry-cntry.
     Append int_fligh.
                Endloop. 
    Correct
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.

    Structure of Where Clause

    When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. One more tip is that if a table begins with MANDT, while an index does not, there is a high possibility that the optimizer might not use that index.
    In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.

    Move Statement

    Instead of using the move-corresponding clause it is advisable to use the move statement instead. Attempt should be made to move entire internal table headers in a single shot, rather than moving the fields one by one.

    Inner Join

    When multiple SAP tables are logically joined, it is always advisable to use inner join to read the data from them. This certainly reduces the load on the network. 
    Let us take an example of 2 tables, zairln and zflight. The table zairln has the field airln, which is the airline code and the field lnnam, which is the name of the airline. The table zflight has the field airln, the airline code and other fields which hold the details of the flights that an airline operates.
    Since these 2 tables a re logically joined by the airln field, it is advisable to use the inner join.
                 Select a~airln a~lnnam b~fligh b~cntry into table int_airdet
                From zairln as a inner join zflight as b on a~airln = b~airln.
     In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.

    Using ABAP Sort in place of Order By

    The order by clause is executed on the database server, while the sort statement is executed on the application server. Thus instead of giving the order by in the select clause statement, it is better to collect the records in an internal table and then use the sort command to sort the resulting data set.



    Tools provided for Performance

    Following are the different tools provided by SAP for performance analysis of an ABAP object
    1. Run time analysis transaction SE30
    This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing. 
    1. SQL Trace transaction ST05
    The trace list has many lines that are not related to the SELECT statement in the ABAP program. This is because the execution of any ABAP program requires additional administrative SQL calls. To restrict the list output, use the filter introducing the trace list.
    The trace list contains different SQL statements simultaneously related to the one SELECT statement in the ABAP program. This is because the R/3 Database Interface - a sophisticated component of the R/3 Application Server - maps every Open SQL statement to one or a series of physical database calls and brings it to execution. This mapping, crucial to R/3s performance, depends on the particular call and database system. For example, the SELECT-ENDSELECT loop on the SPFLI table in our test program is mapped to a sequence PREPARE-OPEN-FETCH of physical calls in an Oracle environment.
    The WHERE clause in the trace list's SQL statement is different from the WHERE clause in the ABAP statement. This is because in an R/3 system, a client is a self-contained unit with separate master records and its own set of table data (in commercial, organizational, and technical terms). With ABAP, every Open SQL statement automatically executes within the correct client environment. For this reason, a condition with the actual client code is added to every WHERE clause if a client field is a component of the searched table.
    To see a statement's execution plan, just position the cursor on the PREPARE statement and choose Explain SQL. A detailed explanation of the execution plan depends on the database system in use.