Sunteți pe pagina 1din 8

Transfermation Routines

->Field level, Start routine, End routine, Expert routine


Dynamic selection in IP(Variable, olap variable)
Data source enhancement
Function module
BADI

ABAP Performance Issues:


=======================
===>Cleare Wa -- the work are evey time look running
===>Intial -- we use intial if database in empty
===>For all entries -- we use this when to read data from more than TWO tables
===>

Break Point:
===========
==>We use break point for debugger of code
==>Session Break Point -- this valid in that session alown
==>Defaut break point: This will valid 2 hr only

FIELD leve routine


================
==> Field level routine is execuited record by record.
==>If u having 20 record in source symbol it will execuit 20 and hit database so
this causes performance down

DATA: LV_SORG TYPE /BIC/OIZS_SORG.

SELECT SINGLE /BIC/ZS_SORG


FROM /BIC/PZM_SORG
INTO LV_SORG
WHERE /BIC/ZM_SORG = SOURCE_FIELDS-SALESORG
AND OBJVERS = 'A'.
IF SY-SUBRC = 0.

RESULT = LV_SORG.
ELSE.
RESULT='1010'.

ENDIF.

NOTE: IF YOU ARE USING SELECT SINGLE , SO ALL THE PRIMARIY keys SHOULD INCLUED IN
CODE
OTHER WISE IT WILL NOT WORK.

READ Statement: It is used to read data from internal table into WA


===============
DATA: LV_SORG TYPE /BIC/OIZS_SORG.

READ TABLE LT_SORG INTO LWA_SORG


WITH KEY /BIC/ZM_SORG = SOURCE_FIELDS-SALESORG
OBJVERS = 'A'.
IF SY-SUBRC = 0.
RESULT = LWA_SORG-/BIC/ZS_SORG.
ELSE.
RESULT = 'ZZZZ'.
ENDIF.

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

SELECT statement: It is also used to read data from tables into IT . i.e VBAK
ABUP
================ We use SELECT to read data from stanard data base tables.
select
vbeln
eardat
netwer
kunnar
matnr
from VBAK into table it_vbak .

SELECT SINGLE SELECT UP TO 1 ROWS


==>It is used to read data for a perticular record by using key.
==>Used to read exact record from database table. ==>Used to
read appropriate record from database table
==>To read exact record from database table we need to provide all keys
==>We can read appropriate record from database table, we may not need to
provide all key
==>It is very fast when compare to SELECT UPTO ==> It is slow.
Syntax :SELECT SINGLE * FROM DATABASETABLE -->Syntax: SELECT
* FROM DATABASETABLE INTO WA UP TO 1 ROWS WHERE ALL KEY FIELDS/SOME FIELDS.
INTO WA WHERE ALL KEY FIELDS end select.

SELECT FOR ALL ENTRIES:


==>It is used when we are reading data from multiple table

Eg:
Data:it_mara type table of mara.
Data:it_makt type table of makt.
select * from mara into table it_mara
where matnr = '100'.
Sort it_mara Ascending.
delete adjacent duplicates from it_mara comparing all fields.
If it_mara not intial
select * from makt into table it_makt
for all entries in it_mara
where matnr = '100'.
endif.
NOTE:
==>Parent internal table must not be empty ( If it is empty, where condition fails
and it will get all records from
database). IF IT_MARA NOT INTIAL.
==>Remove all duplicate entries in parent internal table.(DEL ADJACENT DUPLICATES)
==>Befour deleting duplicates you should do SORT in ASCENDING order.
SELECT INTO CORROSPONDING FIELDS :

==>Select into corresponding is used to get data from a data base table into a user
de??ned internal table or work area
with out specifying the list of fields.

Syntax: SELECT * FROM <DATABASE TABLE>


INTO CORRESPONDING FIELDS OF TABLE <INTERNAL TABLE> .

Eg:
Types:begin of ty_mara,
matnr type mara-matnr,
mtart type mara--mtart,
mbrsh type mara-mbrsh,
meins type mara-meins,
end of ty_mara.
Data: it_mara type standard table of ty_mara.
wa_mara type ty_mara .
SELECT * from mara into corresponnding fields of table it_mara upto 50 rows.
if sy-subrc = 0.
loop at it_mara into wa_mara
write:/wa_mara-matnr , wa_mara-mtart.
end loop.
End if.
NOTE:
==>As per SAP standards select into corresponding statement is not advisable as it
effects the performance of an
application because it has to compare each ??eld with database.
-----------------------------------------------------------------------------------
----------------------------------------------------

FIELD SYMBOL:
=============
====> If you are using fields symbol we don't need to write MODIFIE statement ,
automaticaly the records in internal tabel changed.
====> We use ASSIGNING to assigning data to inernal table
====> UNASSIGN to cleare the data in field symbol

WORK AREA:
===========
====> If you are using WA so we need to write modifie statement
===> If it WA we use INTO key word (it_mara into wa_mara)
===> IF it WA we use CLEARE stamenent to cleare the work are.

-----------------------------------------------------------------------------------
------------------------------------------------------------
FOR ALL ENTRIES

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

Internal tables and work area:


-------------------------------------------Internal Tables and Work Areas are
temporary memory locations which are used to store the data of a database tables at
run time and in other way we can call them as instances of database tables.

Internal Tables Work Areas


Internal table is an instance of database table. Temporary
memory locations which are used to store the data of database table.

By default 8kb memory will be allocated and it increases dynamically( +8kb +8kb).
Work area is an instance of database table.
Temporary memory locations which are used to store the data of database table.

Internal tables can store multiple records. Work areas


can store only one record.

General Syntax : General Syntax:


DATA : <ITAB> TYPE TABLE OF <DBTABLE> . DATA : <WA> TYPE
<DBTABLE> .

READING DATA FROM DATABASE TABLES:


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

==>INTO TABLE ITAB ==>Means getting data into an internal tableITAB from
database table
eg: data : it_mara type table of mara . " Declare internal table of type MARA
Select * from MARA into table it_mara . " Read all records from MARA table
and store in it_mara internal table

==>INTO WA ==>Means getting data into WAa work area ( Work area can
store only one record )
eg: data : wa_mara type mara . " Declare work area of type MARA, because we are
getting only one record
Select single * from MARA into wa_mara where matnr = '00001' . " Read one
records from MARA table and store in wa_mara work area
OR
data : it_mara type table of mara . " Declare internal table of type MARA
select * from MARA into table it_mara where matnr = '00001' . " Read all
records from MARA table where MATNR is 00001, MATNR is a key field .

==>INTO CORRESPONDING FIELDS OF TABLE ITAB ==>Means getting data of common


fields of data base table and user defined internal tableITAB( Here ITAB is a user
defined internal table )
eg: TYPES : BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MBRSH TYPE MARA-MBRSH,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA . "Declare internal table of type user
defined table.

SELECT * FROM MARA INTO CORRESPONDING FIELD OF TABLE IT_MARA . " Here we are
getting data from <code>MARA</code> table into internal table <code>IT_MARA
</code> which contains only four fields.

==>INTO CORRESPONDING FIELDS OF WA ==>Means getting data of common fields of data


base table and work areaWA( Here WA is a work area )

eg:TYPES : BEGIN OF TY_MARA,


MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
MBRSH TYPE MARA-MBRSH,
END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA. " Declare a Internal table of user
defined type
SELECT MATNR, MTART, MEINS, MBRSH FROM MARA INTO TABLE IT_MARA. " Get list of
fields Data Into internal table
" Now data of four fields is available in IT_MARA .

Types of Internal Tables:


====================
==>Standard internal tables
==>Sorted : In sorted internal table the data will be sorted as Ascending order or
Descending order.
data: it_vbap type sorted table of ty_vbap.
==>Hashed :

REPORT Y170DM40.Internal Table without a Header Line


-----------------------------------------------------------------------------------
---
A TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
ID LIKE EMPLOYEE-ID,
NAME1 LIKE EMPLOYEE-NAME1,
COUNTRY LIKE EMPLOYEE-COUNTRY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 ,
B EMPTAB_WA TYPE EMP.
SELECT * FROM EMPLOYEE.
MOVE-CORRESPONDING EMPLOYEE TO EMPTAB_WA.
APPEND EMPTAB_WA TO EMPTAB.
ENDSELECT.

Internal Table with a Header Line


--------------------------------------------------------------------------------
REPORT Y170DM38.
TABLES: EMPLOYEE.
TYPES: BEGIN OF EMP,
ID LIKE EMPLOYEE-ID,
NAME1 LIKE EMPLOYEE-NAME1,
COUNTRY LIKE EMPLOYEE-COUNTRY,
END OF EMP.
DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.

1 SELECT * FROM EMPLOYEE.


2 MOVE-CORRESPONDING EMPLOYEE TO EMPTAB.
3 APPEND EMPTAB.
ENDSELECT.

To create an internal table without a header line, the programmer must:


Create an internal table data type with the TYPES statement. This type will
become the structure of the internal table.
Once the TYPE is created, a DATA statement is coded to identify the actual
internal table object with a name and an INITIAL SIZE clause. The internal table
inherits the fields and attributes from the TYPES statement defined earlier.
In addition to the internal table definition with the INITIAL SIZE clause,
the programmer must also define an internal table work area (staging area). This
work area is defined using the same format as the table. It uses the same
user-defined data type as the internal table.
The work area is loaded programmatically (i.e., MOVE-CORRESPONDING EMPLOYEE
TO EMPTAB_WA), then appended to the internal table.
To load an internal table without a header line, the following APPEND
statement is used: APPEND <work area> to <internal table>.

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
A work area (staging area) is required when working with an internal table
without a header line. This work area is defined as a Structure with the same
structure as the internal table. The work area is loaded and the table is
processed from the work area.

A summary of the statements used for internal tables without header lines is #the
following:
==>APPEND <work area> TO <internal table>
Appends the contents of the work area to the end of the internal table
==>COLLECT <work area> INTO <internal table>
Accumulates the values on a field into the table
==>INSERT <work area> INTO <internal table>
Inserts a new line with the contents of the work area before the #current
line
==>MODIFY <internal table> FROM <work area>
Overwrites a line in the table with the contents of the work area
==>READ TABLE <internal table> INTO <work area>
Reads a line from the table into the work area
==>LOOP AT <internal table> INTO <work area>
Processes an internal table. On each loop pass, a table entry is placed in the work
area.
==>The CLEAR <internal table> statement initialises all single fields in the header
line of an internal table according to type.
==>The REFRESH <internal table> statement deletes all table lines. The table
storage space is not released. The header line remains unchanged.
==>The FREE <internal table> statement releases the storage space required for a
table. The header line remains unchanged.
This statement is particularly useful for very large internal tables. You can
improve a program�s performance by �freeing� the memory space allocated for the
internal table.
Internal tables that are local to a subroutine are automatically �freed� upon
leaving the subroutine.

WARNING: If you are working with an internal table with a separate work area, and
you accidentally say CLEAR <internal table>rather than CLEAR <internal table work
area >, you will delete all the table lines. Use REFRESH to achieve this instead.

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

===>Why would we choose to use an internal table without a header line when it is
easier to code one with a header line?
Separate Internal Table Work Area: The work area (staging area) defined for the
internal table is not limited to use with just one internal table.
Suppose you want two internal tables for EMPLOYEE � one to contain all records and
one to contain only those records where country = �USA�. You could create both of
these internal tables without header lines and use only one work area to load data
into both of them. You would append all records from the work area into the first
internal table. You would conditionally append the �USA� records from the same
work area into the second internal table.
Performance Issues: Using an internal table without a header line is more
efficient than one with a header line (see how to test this below).
Nested Internal Tables: If you want to include an internal table within a
structure or another internal table, you must use one without a header line.
Performance Tips:
To test efficiency issues, go to SYSTEM ? UTILITIES ? RUNTIME ANALYSIS and click on
the �Tips & Tricks� push-button. Here you can test various internal table
performance issues. The one dealing with header line versus no header line is
entitled �Using explicit work areas�. Within this area, you can measure the runtime
to see that internal tables without header lines are more efficient.

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------

TOP 10 TECHNIQUES :

=>When reading data from database table, never use SELECT *, always use select with
list of fields.
=>Always specify key fields in where conditions of SELECT statements, because these
will have primary index.
=>Sometimes we may need to use non-key fields in where conditions of SELECT
statements, in that case create secondary indexes and use.
=>Never use select with corresponding in SELECT statements.
=>Always use read table with binary search and make you have sorted the internal
table in ascending order before using read table binary search.
=>Never use select joins for more than 3 tables.
=>Always use select for all entries for more than 3 tables.
=>Always check whether the parent internal table is initial or not before using for
all entries.
=>Never use nested loops, instead use parallel cursor .
=>Never use select statements inside loops, instead use for all entries.

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
BADI:
BADI (Business Add-in)
BADI is another way of implementing enhancements to the standard programs without
modifying the original code.
BADI's are implemented using Object Oriented Programming technique, Technically a
BADI is nothing but an interface.
Each BADI consists of the method without implementation called as BADI definition.
We need to create classes to write the abap code by implementing the methods called
as BADI implementation.
SE18 is the T-Code for BADI definition, SE19 is the T-Code for BADI implementation.

Advantages of BADI

The main advantage of using BADI is , we can create multiple implementations for a
single BADI definition.
Where as with the exits, we can create a single implementation.i.e a single project
for an enhancement.
We cannot create another project (implementation) for enhancement which is already
used. That is why we go for

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

S-ar putea să vă placă și