Professional Documents
Culture Documents
Abap Code & Concepts
Abap Code & Concepts
say zdept
say zemp
client dependent tables: mandt -- dataelement = mandt , data type = clnt , lengt
h = 3
dataelement
index
*9)What are the types of repository objects in abap?
a)executable programs
b)Include programs
c)Module pool programs
d)Function group.
e)subroutine pool.
f)Interface pool
g)class pool
h)type pool
i)XSLT programs
c)structures
d)data elements
e)domains
f)type-groups
g)search help (obsolete in 6.0 is Match codes)
h)lock objects
i)table types.
j)Foreign keys
A table is a dictionary object which is a collection of fields.It is used for st
oring the data in the form of records(rows).
SAP package contains many built-in tables related to different modules.
Every table contains a client field which ranges from 000 to 999.
9.
7)In data class if the size category specified is from 0 to 14,000 then what hap
pens if we insert more than 14,000 records.
Ans.The memory size is automatically doubled when we try to insert more than 14,
000 records.
IF WE CREATE TABLE WITH DIRECT APPROACH, THEN IN THE TECHNICAL SETTINGS TAB, WE
CANNOT CREATE THE SIZE CATEGORY. SO WE CANNOT ACTIVATE THE TABLE.
ALSO WE CANNOT CREATE THE PRIMARY AND FOREIGN KEY.
BUT IF WE CREATE A TABLE USING BOTTOM APPROACH THEN WE CAN ACTIVATE THE TABLE.
12) In how many ways can we create data types for a field.
ans: We can create data types for fields in 2 ways a)Predefined type (Here I don
't require a domain) and b) data element(by creating
a domain)
Creating a domain is preferred because we can use it accross several tables and
13) Can you create a field without using Data Element and Domain?
Yes. Using Predefined Type
But they cannot be reused accross several tables and also I cannot create prima
ry-foreign keys.
type
type
type
type
type
type
ebeln,
bukrs,
esart,
elifn,
ekorg,
ekgrp,
end of ty_purchase.
Data : lt_pur type standard table of ty_purchase,
wa_pur type ty_purchase.
clear : lt_pur[],
wa_pur.
if lt_pur[] is initial.
select ebeln bukrs bsart lifnr ekorg ekgrp into table lt_pur[]
from ekko.
if sy-subrc eq 0.
read table lt_pur[] into wa_pur with key bsart = 'NB'.
if sy-subrc eq 0.
write : / wa_pur-ebeln,
wa_pur-bsart.
endif.
20)what is the exact usage of secondary index in abap? when do we go for it.
ans: there are 2 types of secondary indexes a) unique index (doesn't allow dupl
icate values) and b) non unique index(accepts
duplicate values)
if a table does not have primary keys and if we use a where clause then a full t
able scan is performed to search the required entires.
So in such a case we create a secondary index so then we can restrict the table
entries thus improving the performance.
secondary indexes have to be created on columns which are used more often.
But creating too many primary key or secondary key indexes increases load on the
system because whenever the table contents change the indexes have to be update
d.
i.e
--se38
DATA : lt_author TYPE TABLE OF zauthor,
ls_author TYPE zauthor.
SELECT * INTO TABLE lt_author
FROM zauthor
%_HINTS ORACLE 'INDEX("ZAUTHOR" "ZAUTHOR~NME")'.
OR
SELECT * INTO TABLE lt_author
FROM zauthor
orderby authfname authlname.
23) I create a table and mention the primary key fields at the end or in the mid
dle? will the table activate
ans: NO. It will not activate because the primary key fields always have to be d
efined at the beginning of the table.
1-32) clear : it will clear the contents of work area , individual fields and
body of internal table.
If clear stmt is applied to Body of internal table, then all re
cords of Body are cleared but this does not clear the work
area.
for e.g clear ls_emp , clear lt_emp[] , clear p_empno.
refresh : it deletes all the records from the body and retains the last r
ecord in the header.
it can be applied only to internal table.
The statements clear lt_emp[] and refresh lt_emp[] achieve the
same output.
append :
it adds the record from the header to the end of the internal t
able
loop
:
it will read the current record from the body and place the sam
e into the header.
read
ork area)
it will read the current record from the body into the header(w
read TABLE lt_dept into ls_dept INDEX 3.
read TABLE lt_dept into ls_dept WITH KEY deptno = 101 BINARY SE
ARCH.
Move :
It checks for the data types . The two structures or internal
tables can have different field names but data types should
be
same.
Move-Corresponding : It only checks for fieldnames and not the data type. If
the field names match then it copies the data also.
It is suggested not to use Move-Corresponding due to the
following reasons.
a)It decreases the performance because each field of sou
rce structure is compared with all the fields of the
target structure.
This comparison is a time consuming process.
b)It may lead to run-time errors because it only checks
for the field names but not for the data types.
consider the following example
MOVE-CORRESPONDING emp to dept. "emp is source struct
ure and dept is target structure
1-33) how to read the first and last record from the internal table?
end
* while defining the sorted internal table we must
specify unique / non unique key.
If the unique key is specified, duplicate entrie
s will not be stored even if they are inserted.
================================================
===============================================
data : lt_dept TYPE SORTED TABLE OF ty_dept WITH
UNIQUE key deptno. "cannot insert duplicate records
data : lt_dept TYPE SORTED TABLE OF ty_dept WITH
NON-UNIQUE key deptno,dname. "can insert duplicate records.
advantage :
carded.
In the resultset if there are duplicate records then they are dis
Disadvantage : If the internal table in FOR ALL ENTRIES IN < ITAB> is empty th
en all rows of the database table are returned.
If there are internal table in FOR ALL ENTRIES IN < ITAB> conta
ins a large number of records then this results in
performance issue.
1-36) Difference between modify and insert. (IT IS ALWAYS SUGGESTED TO USE MODI
FY INSTEAD OF INSERT)
a) Insert stmt only inserts record into the database. But if a record with the s
ame key already exists then it generates a run time error.
Modify stmt inserts record into the database and also updates existing records
with the same key.
example on inserting 5th record in internal table.
types : BEGIN OF nametab,
slno type i,
name(30) type c,
END OF nametab.
DATA : itab_emp TYPE STANDARD TABLE OF nametab,
wa_emp TYPE nametab.
wa_emp-slno = 56.
wa_emp-name = 'radha'.
INSERT wa_emp INTO itab_emp[] INDEX 3.
1-37) Difference between modify stmt and modify with transporting option.
ans : When we use modify stmt without transporting keyword then all fields of w
orkarea is compared with every corresponding row of
internal table.
But using transporting keyword with modify stmt eliminates this drawback
.
for e.g
1-38) What are the difference between select option & ranges ?
(IMP)
--select-options implicitly creates an internal table with the fields SIGN , OP
TION , LOW , HIGH.
But While using RANGES keyword we must explicitly create an internal table.
-- select-options we require to create a work area explicitly.
RANGES keyword also we require to explicitly create an work area.
for e.g in case of select-options keyword.
Tables emp. "AN WORK AREA IS EXPLICITLY CREATED
select-options so_empno for zemp-empno.
append sp_empno.
NOTE: SIGN [ e (exlcusive) , i (inclusive) ]. Default is I.
select single:
-------------as told by chandra , it will the db directly and put all records into work area
only once.
UNLIKE SELECT UPTO 1 ROW, IT WILL NOT ACT AS A LOOP.
-- It retrieves the first record which matches the condition in where clause. IF
THE WHERE CLAUSE RESULTSET CONSIST OF MULTIPLE RECORDS ONLY THE FIRST RECORD IS
RETRIVED WHICH MAY NOT BE UNIQUE.
-- used in conjunction with work area only and not with internal table.
-- Where clause is mandatory.
-- cannot use order by clause.
for e.g select SINGLE deptno dname country city
from ydept
into CORRESPONDING FIELDS OF ls_customer
where deptno = p_deptno.
select . upto 1 row
-----------------as told by chandra it works like a loop.
if u say select upto 1 row, then it will hit the db and put the records in work
area and again it will hit the db . it works like a loop.
-- it will scan all the records and then display the record which satisfies the
condition.
-- Where clause is not mandatory. But while using the where clause unlike select
single , it will apply any ordering , aggregate or grouping functions.
-- we can use orderby clause.
PERFORMANCE WISE IT IS SUGGESTED TO USE SELECT UPTO N ROWS .
Now inside Table B, position the mouse on field deptno and click Foreign Key
button.
check table --> Table A
Then click on generate proposal.
Then add for Table B , select zdeptno
Now in domain zdeptno of Table B, go to Value Range Tab --> Value Table --> Tab
le A.
subroud
1-57-a)subroutine
: A subroutine is a block which consists of statements whi
ch can be repeated. A subroutine has to be defined only
once and can be called 'N' number of times.
A subroutine can be defined with / without parameters.
external subroutine : they are defined in the subroutine pool and they can be ca
lled externally from the external programs.
A subroutine pool is a repository object which is a collection of one or more ex
ternal subroutines.
subroutine pool
1-57) subroutine pool is created under se38 and it is a collection of subrouti
nes.
WRITE : / p_x,
p_y.
ENDFORM.
GT_KNA1
I_LAND1.
" Mysub
-->The parameters defined in fn.module are importing parameters which become exp
orting parameters in the program.
Similarly the exporting parameters become importing parameters in the program
.
-->The EXPORT TAB can export 'N' no. of parameters.
tcode se80 --> select package from dropdownlist --> provide name --> press enter
button --> then click YES
similary create a function group from the above tcode.
every function module needs to be placed inside a function group.
tcode -- se37
IMPORT TAB:
---------Parameter Name: i_x
i_y
Type spec:
Type
Associated Type : I
EXPORT TAB:
---------Parameter Name: e_add
e_sub
e_div
e_mult
Type spec:
Type
Type
Type
Type
Associated Type : I
I
I
I
save and activate the function module. If u want u can test it with dummy data.
se38
parameters : p_x type i,
p_y type i.
data : add type i,
sub type i,
div type i,
mult type i.
"Click on Pattern button in Application Tool Bar
CALL FUNCTION 'YFUNC_MODULE'
EXPORTING
I_X
I_Y
IMPORTING
E_ADD
E_SUB
E_DIV
E_MULT
write
write
write
write
:
:
:
:
/
/
/
/
= p_x
= p_y
=
=
=
=
add
sub
div
mult.
The parameters defined in fn.module are importing parameters which become export
ing parameters in the program.
Similarly the exporting parameters inside the fun.module become importing parame
ters in the program.
NOTE: SO WHAT IS THE SIGNATURE OF THE FN. MODULE.?
IT IS 2 IMPORT PARAMETERS AND 4 EXPORT PARAMETERS.
11)