abap code & concepts.txt

23
1) how to create a custom table 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 2)client independent tables and client independent  There are 2 types of tables in sap  a)Client Dependant table b)Client Independent table. Client Dependent table:If the table contains a client field then it is called cl ient dependent table. The records in these tables are specific to the client. The data type for client field is CLNT with a size of 3. e.g table kna1. It has the client field mandt with a size of 3. Client Independent table:If the table doesn t contain a client field then it is ca lled client independent table.The records in these fields are not specific to an y client. For e.g. custom tables NOTE: IN ABAP WE CANNOT CREATE A TABLE WITHOUT PRIMARY KEY BECAUSE ALL TABLES AR E NORMALIZED BY DEFAULT. I.E IT IS COMPULSORY TO CREATE PRIMARY KEY. 3) what are the main objects in sap abap? Dictionary objects are used to store permanent data into the database. They are created using the transaction codes se11.  a)tables  b)views

Upload: simpleheart23

Post on 14-Apr-2018

232 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 1/23

1) how to create a custom table

say zdept

say zemp

client dependent tables: mandt -- dataelement = mandt , data type = clnt , length = 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

2)client independent tables and client independent

 There are 2 types of tables in sap  a)Client Dependant tableb)Client Independent table.

Client Dependent table:If the table contains a client field then it is called client dependent table. The records in these tables are specific to the client.

The data type for client field is CLNT with a size of 3.e.g table kna1. It has the client field mandt with a size of 3.

Client Independent table:If the table doesnt contain a client field then it is called client independent table.The records in these fields are not specific to any client. For e.g. custom tables

NOTE: IN ABAP WE CANNOT CREATE A TABLE WITHOUT PRIMARY KEY BECAUSE ALL TABLES ARE NORMALIZED BY DEFAULT. I.E IT IS COMPULSORY TO CREATE PRIMARY KEY.

3) what are the main objects in sap abap?

Dictionary objects are used to store permanent data into the database.They are created using the transaction codes se11.

 a)tables b)views

Page 2: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 2/23

 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 storing 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.

4)How many primary keys can we create on a table in abap?

  ans : We cannot create more than 16 primary keys.

5) What are the various data types available in abap?

  Char  Clnt  Cuky  Curr  Dats  FLTP  INT4  TIMS  PREC

6)What is Data Class in abap?

Data class specifies the schema in which the table has to be stored.The schema is a partition in the db.

The basis consultant creates a database and partitions it into 3 different schemas.

a)Master schemab)Transaction schemac)Organization schema

The data class has got the following entries:

APPLO : Master Data,Transparent TablesAPPL1 : Transaction data, transparent Tables

The Size category can range from 0  9.

0 --> 0 to 51000 records

1 --> 51000 to 200000 records

Page 3: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 3/23

7)In data class if the size category specified is from 0 to 14,000 then what happens 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.

8) what is a view and its types?

a view represents snapshot of table. It is a virtual table. It is not stored physically.

a)Database view b)Projection view c)Maintenance view d)Help view.

 Database View:

 ============ *It can be created either on a single table or multiple tables.*It supports both projection view and selection view.

*A database view create on a single table can be read or changed mode.

* A database view created on multiple tables is always ReadOnly.

i.e in MaintainStatus Tab --> Table View Maintenance --> Display maintenance allowed with restrictions.

i.e we cannot edit a database view created on multiple tables.

*In a database view created on multiple tables, if you dont specify the join condition then the output results in an Cartesian product.i.e if table A has 9 records and table B has 11 records then total 99 records are displayed.

Projection View:================

* It is always created on single table.It supports only projection but not selection.* It can be read and change.

Maintenance View.===============* It is used to create multiple views at a time.* We can insert,delete,edit records in a maintenance view.

For a Maintenance view by default the following is set:

Delivery Class: A

Page 4: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 4/23

 Table Maint: Display/Maintenance allowed

9) A structure is a user defined data type which is a collection of different fields.

The size of the structure is equal to the sum of the sizes occupied by structure fields.

A structure can hold a single record at a given point of time.

Syntax 1:

Data : begin of <structure name>  Field1,  Field2,  Fieldn  End of <structure name>

For e.g

 Data : begin of emp,  empno type i.  ename(20) type c.  end of emp.

  Write : / emp-empno,  emp-ename. 

Syntax 2:

Data <structure> like <existing structure>

For e.g data emp25 like emp.

This syntax only copies the fields but not the values of the previous structure.

Note: memory is automatically allocated to structure.

8)In how many ways can a table be created in sap?

  A table can be created in 2 ways.

a)direct approach : we specify the fields first and domain and data element arecreated later.

b)Bottom approach : First the domain and data element are created then the fields.

Page 5: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 5/23

IF WE CREATE TABLE WITH DIRECT APPROACH, THEN IN THE TECHNICAL SETTINGS TAB, WECANNOT 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.

9)what is a data element?

ans: a data element is a dictionary object which provides the description for the field.

  it is a reusable component.

  A data element can be created either by referring to an direct data type or to a domain.

 

10)what is the exact use of data element?

ans. To establish a primary-foreign key relationship. Without it we cannot create primary foreign key relationship.

11) what is a domain?

ans: A domain will contain the data type,sizes,value,range and value table. i.edomain contains the technical properties of a field.

The data element and the domain will have the same name.

Note: The same Domain and data element can be used across several tables.

Note: If we don't want to create the data element, then we create the predefined type. But it cannot be used across several tables. 

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

Page 6: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 6/23

also I can create primary-foreign keys.

13) Can you create a field without using Data Element and Domain?

Yes. Using Predefined TypeBut they cannot be reused accross several tables and also I cannot create primary-foreign keys.

14)Can you create a Data Element without using Domain?

ans : Yes using Predefined typeBut they cannot be reused accross several tables.

9) example on internal table.

types : begin of ty_purchase,

  ebeln type ebeln,  bukrs type bukrs,  bsart type esart,  lifnr type elifn,  ekorg type ekorg,  ekgrp type 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.

Page 7: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 7/23

loop at lt_pur[] into wa_pur where bsart = 'NB'.

  write :/ wa_pur-ebeln,  wa_pur-bukrs,  wa_pur-bsart,  wa_pur-lifnr,  wa_pur-ekorg,  wa_pur-ekgrp.

endloop.

endif.endif.

19)what is index? where it is stored?

ans. Index is basically a table. Index is stored at database level.

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 duplicate 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 table scan is performed to search the required entires.

So in such a case we create a secondary index so then we can restrict the tableentries 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 updated.

21)How to create a secondary index in abap?

ans : se11 --> zauthor.

assume the zauthor table has following fields i.e mandt , isbn , authlname , authfname.

Goto-->Indexes--> Create Index. say nme.

note: we can create only 3 character index

Now specify the field names : authlname , authfname

Page 8: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 8/23

--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.

22)Only Primary index is unique index for a table.

But a secondary index can contain duplicate entries.

there can be 16 primary indexes and 9 secondary indexes on a table.

23) I create a table and mention the primary key fields at the end or in the middle? will the table activate

ans: NO. It will not activate because the primary key fields always have to be defined at the beginning of the table.

24) Difference between type Vs Like.

 * TYPE : refers to an existing data type.

  * LIKE : Like is a keyword used to copy the existing properties of an already existing data object. The data type is referenced

indirectly.

  for e.g data : cust like kna1 occurs 2 with header line.

  data : gt_primary like lt_primary.

1-31) internal table(VVVIMP)

Page 9: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 9/23

-- it is a temporary table created in appln server used to temporarily store the records.

-- data : begin of emp occurs 10,

  end of emp.

This declares an internal table with header.

consider another syntax.

data : begin of emp occurs 10 with header line

  end of emp. 

internal tables. (always displayed on LIST PROCESSING SCREEN)

An header is like a work area or structure which can process the internal tablerecords.It can handle only a single record.

The body of an internal table can store multiple records.

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 records 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 record 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 table

loop : it will read the current record from the body and place the same into the header. 

read : it will read the current record from the body into the header(work area)

  read TABLE lt_dept into ls_dept INDEX 3.  read TABLE lt_dept into ls_dept WITH KEY deptno = 101 BINARY SEARCH.

Page 10: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 10/23

 read table lt_emp into ls_emp where deptno = ls_dept-deptno.

  Move : It checks for the data types . The two structures or internaltables can have different field names but data types should be same.

  Move-Corresponding : It only checks for fieldnames and not the data type. Ifthe 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 source 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 checksfor the field names but not for the data types.

  consider the following example

  MOVE-CORRESPONDING emp to dept. "emp is source structure and dept is target structure

  Delete adjacent duplicates : deletes duplicate entries from the internal table

  for example: 

delete ADJACENT DUPLICATES FROM lt_itab[].

 

WRITE stmt : it always refers to the header area.

 Index of internal table always starts from 1.

 In internal data --pass by reference

- data : cust like kna1 occurs 0 with header line.

1-33) how to read the first and last record from the internal table?

Page 11: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 11/23

  sort lt_emp empno ascending.  read table lt_emp into ls_emp index 1. "<--- this gives the first record.

  Now to find the last record.

  consider the following example.

DATA: itline TYPE i.

DATA: BEGIN OF it1 OCCURS 10,  key1(10),  key2(10),  a TYPE i,END OF it1.it1-key1 = '10001'.it1-key2 = '20002'.it1-a = 250.APPEND it1 TO it1.it1-key1 = '30003'.it1-key2 = '40004'.it1-a = 300.APPEND it1 TO it1.

DESCRIBE TABLE it1 LINES itline.

READ TABLE it1 into it1 INDEX itline.WRITE: / it1-key1, it1-key2, it1-a.

output : 30003 40004 300

standard internal tables : * uses linear search and binary search  ---------------------- * we cannot define unique keys

  * explicit sort statement is required.  * records are read based on the index.  * WE USE APPEND

  sorted internal table: * supports linear search and binary search  --------------------- * explicit use of sort stmt not required  * we have to use 'insert' statement instead of append  * while defining the sorted internal table we must specify unique / non unique key.  If the unique key is specified, duplicate entries will not be stored even if they are inserted.

  ===============================================================================================

  data : lt_dept TYPE SORTED TABLE OF ty_dept WITHUNIQUE key deptno. "cannot insert duplicate records 

data : lt_dept TYPE SORTED TABLE OF ty_dept WITHNON-UNIQUE key deptno,dname. "can insert duplicate records. 

Page 12: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 12/23

 hashed internal table: * supports only linear search. doesn't support bin

ary search.  --------------------- * we have to use 'insert' statement instead of append  * we cannot use the option NON-UNIQUE KEY while defining the internal table  * since records are searched based on key, indexing is slower when compared to sorted table.  ========================================================================================

* while defining the hashed internal table we must specify unique key option.

  *hashed tables always run a full table scan because entries are not sorted and each key is compared.  ----------------------------------------------------------------------------------------------------

  * for e.g the following stmts will throw error if u

sed with hashed table.

  read table lt_emp into ls_emp index 2. "ERROR because indexing is not supported in hash table  read table lt_emp into ls_emp WITH KEY deptno = 101 BINARY SEARCH "ERROR

 BUT THE FOLLOWING STATEMENT IS SUPPORTED WITH HAS

HED TABLE.

  read table lt_emp into ls_emp with key empno = 6789

1-34)FOR ALL ENTRIES : For all entries statement is used between databasetable and internal table provided there exists one

field in common between db table and internal table.

THE ADVANTAGE OF USING "FOR ALL ENTRIES" IS THAT WE NEED NOT CREATE AN EXPLICIT WORK AREA.

consider the following example:

 select vbeln posnr matnr netwr FROM vbap INTO CORRESPONDING FIELDS OF TABLE lt_vbap[]  FOR ALL ENTRIES IN lt_vbak[]  where vbeln = lt_vbak-vbeln.

Page 13: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 13/23

advantage : In the resultset if there are duplicate records then they are discarded.

Disadvantage : If the internal table in FOR ALL ENTRIES IN < ITAB> is empty then all rows of the database table are returned.

  If there are internal table in FOR ALL ENTRIES IN < ITAB> contains a large number of records then this results in

performance issue.

1-35) Difference between insert and insert accepting duplicate keys.

For e.g insert <tablename> from Table <itab[]>. This stmt generates a runtime error if a record already exists with the same key.

But insert zemp from Table lt_emp[] accepting duplicate keys statement will not generate a runtime error but simply set the value of sy-subrc to 4.

1-36) Difference between modify and insert. (IT IS ALWAYS SUGGESTED TO USE MODIFY INSTEAD OF INSERT)

a) Insert stmt only inserts record into the database. But if a record with the same 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 workarea is compared with every corresponding row of

internal table.

Page 14: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 14/23

  But using transporting keyword with modify stmt eliminates this drawback.

for e.g modify lt_cust from ls_cust transporting mgr 

MODIFY lt_comp FROM <fs> TRANSPORTING compaddr

1-38) What are the difference between select option & ranges ?(IMP)

--select-options implicitly creates an internal table with the fields SIGN , OPTION , 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.

 

for e.g in case of RANGES keyword.

TABLES YTXLFA1.

RANGES: VENDOR FOR YTXFLA1-LIFNR.

begin of bukrs occurs 0,SIGN(1) type c,OPTION(2) type c,LOW like bukrs,HIGH like bukrs,

end of bukrs.

http://www.sapdev.co.uk/tips/tips_range.htm

1-39) difference between select single and select upto 1 row.(VVIMP)

Page 15: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 15/23

select single:--------------

as told by chandra , it will the db directly and put all records into work areaonly 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 ydeptinto 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 workarea 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 thecondition.

-- 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 .

1-40) will the following statement work?

  select single * from mara where matnr = '<some material number>'.

ans: No. we explicitly need to define work area by using the TABLES statement.

Page 16: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 16/23

consider the correct scenario:

Tables : maraselect single * from mara where matnr = '<some material number>'.

NOTE: WHEN WE USE select-options keyword also then we need to use explicit workarea by defining TABLES statement.

1-41) Joins in abap.

In abap there are only two types of joins a)Inner join b)left outer join.

Inner join:==========

In inner join if the corresponding row is not available in base table B then at

output that row is completely ignored.

select carrname connid INTO TABLE lt_flight[]  FROM scarr as c  INNER JOIN spfli as p  on p~carrid = c~carrid.

Left Outer Join:===============

In left outer join if the corresponding row in base table B has no values then at output, the row is filled with zeros and NULLS.

here field carrid is primary key field.

SELECT s~carrid carrname connid INTO TABLE lt_flight[]  FROM scarr as s  left OUTER JOIN spfli as p  on s~carrid = p~carrid  and p~cityfrom = p_cityfr.

1-46) How to create foreign key in abap?  ----------------------------------

ans :

a)create table A with primary key say zdeptno

b)create table B . Table B should contain zdeptno.

Page 17: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 17/23

Now inside Table B, position the mouse on field deptno and click Foreign Keybutton.

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 --> Table A.

15)What are the modularization techniques in abap?

ans. subroutines

  Includes

function modules

macros

subroud1-57-a)subroutine : A subroutine is a block which consists of statements which 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.

1-57) what is the keyword used to pass parameters to subroutines?

ans : USING keyword

1-57) subroutine and subroutine pool

ans:

There are 2 types of subroutines.a)Internal subroutineb)External subroutine

internal subroutine : Perform <subroutine Name>

Page 18: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 18/23

external subroutine : they are defined in the subroutine pool and they can be called externally from the external programs.

A subroutine pool is a repository object which is a collection of one or more external subroutines. 

1-57) How do we return multiple values from subroutine?

ans: CHANGING keyword

perform add using p_x p_y changing res1 res2.

subroutine pool1-57) subroutine pool is created under se38 and it is a collection of subroutines.

example on creating subroutine.================================parameters : p_x type i,  p_y type i.

 data : z type i.

 start-of-selection.

  perform abc.

  write : / 'Value of z after subroutine call is ',z.

  Form abc .

  z = p_x + p_y.

  endform.

2a)Passing parameters to subroutines.

PARAMETERS: p_x TYPE i,  p_y TYPE i.

START-OF-SELECTION.PERFORM abc USING p_x p_y. "actual parameters

FORM abc USING P_X "formal parameters  P_Y.

Page 19: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 19/23

WRITE : / p_x,  p_y.ENDFORM.

4a)Returning multiple values from subroutine. (Internal subroutine)

NOTE: WE MUST USE THE CHANGING KEYWORD.=======================================

parameters : p_x type i default 670 obligatory,  p_y type i default 670 obligatory.

data : res1 type i,  res2 type i.

perform add using p_x p_y changing res1 res2.

write : / 'Addition Is',res1 left-justified.

write : / 'Multiplication Is',res2 left-justified.

 form add using x y changing z1 z2.

  z1 = x + y.

  z2 = x * y.

 endform.

**7a) Passing internal tables as parameters to subroutines.

parameters : p_land1 type kna1-land1.

types : begin of ty_kna1,  kunnr type kna1-kunnr,  land1 type kna1-land1,  name1 type kna1-name1,  end of ty_kna1.

data : lt_kna1 type STANDARD TABLE OF ty_kna1.

PERFORM Mysub TABLES lt_kna1 USING p_land1.

describe table lt_kna1.

write :/ 'No of records after subroutine call',sy-tfill.

FORM Mysub TABLES GT_KNA1  USING I_LAND1.

IF i_land1 is NOT INITIAL.

select kunnr land1 name1  from kna1  into table GT_KNA1

Page 20: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 20/23

  where land1 = I_LAND1.

endif.

ENDFORM. " Mysub

1-27) performance tuning in sap abap

  OR

  You are running a report and it is taking a long time for execution . what steps will u do to reduce the execution time?

ans : -- switch on buffering if uing custom tables

  -- minimize the number of loops

  -- avoid using order by clause

  -- avoid extra joins

  -- use FOR ALL ENTRIES

  -- avoid using Move-Corresponding statement

  -- do not call function module inside loop statements. 

-- do not sue nested loops.

10) function modules with example.

FUNCTION MODULES:=================

 -->when we create a function module under an function group we get an message saying "Function Module is reserved for

sap".It means that the function module is unique to every client system i.e it is client independent.

-->By default when we create an function module then it is Normal function module.

-->BY DEFAULT IN ABAP, PARAMETERS TO FUNCTION MODULES PARAMETERS ARE PASSED BY REFERENCE.  =====================================================================================

Page 21: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 21/23

-->The parameters defined in fn.module are importing parameters which become exporting parameters in the program.  Similarly the exporting parameters become importing parameters in the program.

-->The EXPORT TAB can export 'N' no. of parameters.

Function modules are of types:a)Normal Function modules.b)Remore function modules.

Normal function Module:By default these are client independent.i.e a function module created in one client can be accessed from any of the other clients within the same server.

Remote Function Module:They can be called remotely from the server.

23b)What is function group?A function group is a repository object which is a collection of different types

 of objects like include prgms,function modules,subroutines,modules,screens,dictionary objects etc.

Whenever a new function group is created two include programs will be created.a)Include ending with TOP: It is used for global declarations.b)Include ending with UXX:It is a collection of sub includes.

Whenever a function module is created inside a function group,a sub include will be generated for every function module.Each sub include is a pointer to the function module.

Syntax for calling Normal Remote Function module:==================================================

Call function <function module> [parameter list].

Syntax for defining functional modules.

Function <function module>.  Statements.Endfunction.

1)Create a fn.module which accepts 2 inputs and performs addition,multiplication,division and subtraction.Note: before creating a fn.module we must create a fun.group.

How to create a package and then function group:?=================================================

Page 22: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 22/23

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

Page 23: Abap Code & concepts.txt

7/27/2019 Abap Code & concepts.txt

http://slidepdf.com/reader/full/abap-code-conceptstxt 23/23

  I_X = p_x  I_Y = p_y  IMPORTING  E_ADD = add  E_SUB = sub  E_DIV = div  E_MULT = mult.

  write : / 'Addition Is', add left-justified.  write : / 'Subtraction Is', sub left-justified.  write : / 'Division Is', div left-justified.  write : / 'Multiplication Is', mult left-justified.

The parameters defined in fn.module are importing parameters which become exporting parameters in the program.Similarly the exporting parameters inside the fun.module become importing parameters in the program.

NOTE: SO WHAT IS THE SIGNATURE OF THE FN. MODULE.?  IT IS 2 IMPORT PARAMETERS AND 4 EXPORT PARAMETERS.

11)