Abap - All Interview Questions
Abap - All Interview Questions
Introduction
Customers often have to change the standard SAP objects in order to meet their own specific
requirements. This might involve passing some additional information by adding few extra fields to the
standard SAP table. These fields might get updated in underlying Standard SAP tables or customer
database table and ultimately serve the business purpose.
Business Scenario
For example, assume that there is extra information that we want to save to the database while
creating a new purchase order. I.e. Prepared By, Checked By, Approved By.
An extension parameter (ExtensionIn) in the BAPI interface is used to pass on the enhancements
to the BAPI in container format. This extension parameter is always based on data
structure BAPIPAREX. Using this parameter BAPI understands the format of the data to be passed.
Here, the STRUCTURE refers to the name of the BAPI table extension though which extra
information is to be sent whereas VALUEPART1 to VALUEPART4 are the values that will be
inserted in the additional table fields along with the table key field. Key field, here,
purchase_order_no is the extra information that needs to be passed to know the line in the database
table where the data record needs to be written.
So extension container could look like
.
..
Here, ‘3300000180’ is the key field for EKKO table specifying which row to be updated. And
“Nikhil Pravin Parvati” is the extra fields of EKKO specified in BAPI_TE_MEPOHEADER.
Source Code
Once the BAPI Extension Table and Extension Container are filled, Execute the BAPI by passing
Extension Container as an table type argument.
How to add push button on selection screen?
TYPE-POOLS: icon.
TABLES sscrfields.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
SELECTION-SCREEN:
PUSHBUTTON /2(40) button1 USER-COMMAND but1,
PUSHBUTTON /2(40) button2 USER-COMMAND but2.
*--------------------------------------------------------------*
*At Selection-Screen
*--------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sscrfields.
WHEN 'BUT1'.
MESSAGE 'Button 1 was clicked' TYPE 'I'.
WHEN 'BUT2'.
MESSAGE 'Button 2 was clicked' TYPE 'I'.
ENDCASE.
*--------------------------------------------------------------*
*Initialization
*--------------------------------------------------------------*
INITIALIZATION.
button1 = 'Button 1'.
button2 = 'Button 2'.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = icon_okay
text = 'Continue'
info = 'Click to Continue'
IMPORTING
RESULT = button1
EXCEPTIONS
OTHERS = 0.
Ans: Error are trapped in Returning parameters in BAPI. Please check below code for your reference.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gmhead
goodsmvt_code = gmcode
IMPORTING
goodsmvt_headret = mthead
TABLES
goodsmvt_item = itab
return = errmsg.
CLEAR errflag.
LOOP AT errmsg.
IF errmsg-type EQ 'E'.
WRITE:/'Error in function', errmsg-message.
errflag = 'X'.
ELSE.
WRITE:/ errmsg-message.
ENDIF.
ENDLOOP.
// After 7.40
// Before 7.40
// After 7.40
// Before 7.40
READ TABLE lt_itab INDEX lv_index USING KEY lv_key INTO ls_itab.
// After 7.40
DATA(gt_citys) = VALUE ty_citys( FOR ls_ship IN gt_ships ( ls_ship–city ) ).
SELECT *
FROM MARA
INTO TABLE @DATA(IT_MARA)
UP TO 50 ROWS
WHERE MTART = 'FERT'.
TRY .
DATA(wa_mara) = it_mara[ matnr = '0001' mtart = 'FERT' ].
CATCH CX_SY_ITAB_LINE_NOT_FOUND.
WRITE:/ 'Error Reading Record'.
ENDTRY.
WRITE:/ wa_mara-matnr.
Note: As we know if ABAP 7.4, new read syntax we can not use sy-
subrc, so in that case we use exception class CATCH
CX_SY_ITAB_LINE_NOT_FOUND. In TRY-ENDTRY block , if not
record found.
Append syntax in ABAP 7.4
TYPES:
BEGIN OF ty_data,
kunnr TYPE kunnr,
name1 TYPE name1,
ort01 TYPE ort01,
land1 TYPE land1,
END OF ty_data.
TYPES: tt_data TYPE STANDARD TABLE OF ty_data
WITH DEFAULT KEY.
* classical : Before ABAP 7.4
DATA: itab_multi_c TYPE tt_data.
FIELD-SYMBOLS: <fs> LIKE LINE OF itab_multi_c.
APPEND INITIAL LINE TO itab_multi_c ASSIGNING <fs>.
<fs>-kunnr = '123'.
<fs>-name1 = 'ABCD'.
<fs>-ort01 = 'LV'.
<fs>-land1 = 'NV'.
APPEND INITIAL LINE TO itab_multi_c ASSIGNING <fs>.
<fs>-kunnr = '456'.
<fs>-name1 = 'XYZ'.
<fs>-ort01 = 'LA'.
<fs>-land1 = 'CA'.
* With ABAP 7.4
DATA(itab_multi_comp) =
VALUE tt_data( ( kunnr = '123' name1 = 'ABCD' ort01 = 'LV' land1 = 'NV' )
( kunnr = '456' name1 = 'XYZ' ort01 = 'LA' land1 = 'CA' )
ENDLOOP.
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.
Macro Subroutine
Macro can be called only in the program where it Subroutine can be called from other
is defined.
programs also. To call subroutine we
use statement : PERFORM <f_select_data>
IN PROGRAM <program_b>. here f_select_data
is the subroutine name and program_b is
the program name in which we are calling
subroutine.
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: Subroutine is defined inside:
DEFINE … FORM …..
…. …..
END-OF-DEFINITION. ENDFORM.
Macro is used when same thing is to be done in a Subroutine is used for modularization.
program a number of times.
Question 7: What is the difference between SAP memory and ABAP memory?
Sy-tabix: Sy-tabix return current loop pass. For example a loop trigger 10 times then sy-tabix will return
value from 1 to 10. it is used in internal table loops. it gets the no. of records in the internal table. But sy-
index always return value as “0 “ inside loop end loop . Check below program for your reference.
TABLES: pa0002.
data: itab type TABLE OF pa0002,
wa type pa0002.
select pernr nachn name2 from pa0002
into CORRESPONDING FIELDS OF TABLE itab UP TO 10 ROWS ..
loop at itab into wa.
write: / wa-pernr, wa-nachn, wa-name2.
write: sy-index.
write: sy-tabix.
endloop.
Sy-index: Inside do enddo ,sy-index return value of loop pass but sy-tabix always return value 1 inside
do enddo. In below example sy-index return value 1 to 5 and sy-tabix returns value 1.
REPORT ZINDEX_TABIX.
do 5 times.
if sy-index = 2.
CONTINUE.
endif.
write /: sy-index.
WRITE : sy-tabix.
ENDDO.
Output:
Sy-index Sy-tabix
Note: In case of loop endloop sy-tabix will return current loop pass value
but sy-index will return value as 0 for loop pass. But in case of do enddo sy-
tabix always return value as 1 but sy-index return value of current loop pass.
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.
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.
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
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
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?
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.
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?
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?
Check table is maintained when you define foreign key relationships. Check Table is defined at field
level.
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. 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 , you use this domain the system will force you to use values for MATNR in table MARA.
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 Business Object 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.
Ans: Each menu function, push button, or function key has an associated function code of length FOUR
(for example, FREE), which is available in the system field SY-UCOMM after the user action.
Ans: Include structure allows to add one or more structure into structure or table. Also placed
positioning anywhere. Upto 6 include structure can be used in a table.
Append structure can be placed only at the end of a structure or table which also stops further insertion
of fields. Only one append structure can be used.
Ans: Only One. Append structure can not be reusable, we can not use it for multiple tables.
2. One the report selection screen, click on the ‘Disp. stored job’ button
The user can then execute any of the foreground ALV functions such as custom buttons / hotspots.
You can Run alv in Background but make sure it is alv list, not alv Grid FM. if you are alv list not
problem , but if you are using alv grid then you can code like this.
if sy-batch = ' '.
call 'REUSE_ALV_GRID_DISPLAY'.
else.
call 'REUSE_ALV_LIST_DISPLAY'.
endif.
Resolution – We’ll see, step by step, what all needs to be done in order to fulfill the mentioned
requirement.
Steps:
1. To begin with Authorization Object, we’ll enter the Tcode: SU21. Here, we will create the following, in
the order shown:
I. Object Class
II. Authorization Object
2. On clicking the Object Class (as shown in the above screen shot), you’ll see the window shown
below. Enter the Object class name, description & click on SAVE. You can also use available objects,
to create your Authorization Object. Like in scase of HR module, you can make use of Object Class
“HR”, then you need not create
one.
3. Once you create Object class (E.g. Test), you’ll see a folder with that name in the list. Now your
object class is ready. We will need this Object class to encapsulate the Authorization object that we
will be creating. Click on the Object created, and then click on “Create - Authorization Object” (shown
in the figure step 1). On clicking, you’ll see the below shown
screen.
Give respective field name, in our case, PERNR (Employee Number), as shown in the above
diagram. We will be keeping a check on the employee number, and see if the employee has
authorization to access the report (made to view z-tables) or not.
4. Now, we need to create a Role, inside which we will attach our Authorization Object. Enter
Transaction code: PFCG to create a role.
Select the “Authorizations” tab. And Click on the icon next to “profile name”, as shown in the figure
above. On the click of that icon, the system will generate a Profile name and a description for the
same.
You’ll see a new screen with the Role Name on top left. Here you will have to add your ‘Authorization
Object’ that was created in SU21.
6.Click on the “Manually” button shown in the toolbar, to add the Authorization object, as shown in the
figure below. Here you can add your Authorization object in the list and press enter.
7. Now you need to add values (Employee numbers) in your object, for those who would be given
authorization. In our case, we will put a “*” symbol (to allow the system to provide access to any
employee, which is Assigned this role).
8. Press Save and then Generate the profile by clicking on ‘generate’ icon.
9. Finally you come out of the screen pressing back button. And you will see the Authorizations tab
with a Green symbol, meaning, Authorization object has been assigned and the role can be
used.
10. After these steps, if you want to give authorizations to say Employee No.: 96. Go to
Transaction SU01, click on the Roles tab and assign our role name, in our case : test_role.
This way, you can assign this role to all those users, who are supposed to be authorized to access
the report (for data entry in the table).
11. Finally, in the main program, which has been created, we need to write a small code, as shown
below, which will decide if that employee is authorized or not:
REPORT ZCHECK_AUTH.
DATA : L_PERNR TYPE PERNR_D.
SELECT SINGLE PERNR INTO L_PERNR FROM PA0105
WHERE UNAME EQ SY-UNAME AND USRTY EQ '0001' AND
BEGDA LE SY-DATUM AND ENDDA GE SY-DATUM.
AUTHORITY-CHECK OBJECT 'Z_OBJECT1'
ID 'PERNR' FIELD L_PERNR.
IF sy-subrc <> 0.
MESSAGE 'No authorization' TYPE 'E'.
ELSE.
**** Here you can have the Query to view the table or perform any
**** action related to the Z-tables
MESSAGE 'Congrats! You are authorized' TYPE 'I'.
ENDIF.
If the user passes this authorization check, the return code SY-SUBRC is set to 0. Hence, users who are
not assigned the Role, if they try to access this report; they’ll not be able to do the same.