Saturday, December 16, 2006

Performance Tips - Netsed Loops

Performance tuning is they key concept in ABAP programming. In real time, we could find large amount of data. Today we will discuss the worse effect of nested loops and what are the alternate ways to handle nested loops.
If the amount of data is large, nested loops are fully avoided due to performance issues. If your program is extracting small amount of data, then focus on SELECT statements than nested loops.
See below program where you can find three methods:
1) Nested Loop
2) Indexed Loop
3) Parallel Cursor

The indexed loop is the best method to avoid performance issues. Read statement by using binary search inside a loop works well.

The above three methods are depicted in the following program:

report ztest_nested_loop.

data: bkpf type bkpf,
bseg type bseg.

select-options: s_bukrs for bseg-bukrs memory id buk obligatory,
s_gjahr for bseg-gjahr memory id gjr obligatory,
s_lifnr for bseg-lifnr memory id lif obligatory.

data: bkpf_tab type standard table of bkpf,
bkpf_lin like line of bkpf_tab,
bseg_tab type standard table of bseg,
bseg_lin like line of bseg_tab.

data: start_time type sy-uzeit,
end_time type sy-uzeit,
difference type sy-uzeit,
bkpf_entries type sy-tabix,
bseg_entries type sy-tabix,
bkpf_reads type sy-tabix,
bseg_reads type sy-tabix.

start-of-selection.
perform unindexed_select.
perform nested_loop.
perform indexed_loop.
PERFORM parallel_cursor.

*&---------------------------------------------------------------------*
*& Form unindexed_select
*&---------------------------------------------------------------------*
form unindexed_select.

get time field start_time.

select * from bseg
into table bseg_tab
where bukrs in s_bukrs
and gjahr in s_gjahr
and lifnr in s_lifnr.

if sy-subrc <> 0.
message id '00' type 'E' number '001' with 'No entries selected'.
endif.

select * from bkpf
into table bkpf_tab
for all entries in bseg_tab
where bukrs = bseg_tab-bukrs
and belnr = bseg_tab-belnr
and gjahr = bseg_tab-gjahr
and bstat = space.

clear bseg_tab.
refresh bseg_tab.
select * from bseg
into table bseg_tab
for all entries in bkpf_tab
where bukrs = bkpf_tab-bukrs
and belnr = bkpf_tab-belnr
and gjahr = bkpf_tab-gjahr.

get time field end_time.
difference = end_time - start_time.
describe table bkpf_tab lines bkpf_entries.
describe table bseg_tab lines bseg_entries.

write: /001 'Time for unindexed select:', difference,
/005 'Number of BKPF entries:', bkpf_entries,
/005 'Number of BSEG entries:', bseg_entries.
skip 1.

endform. " unindexed_select

*&---------------------------------------------------------------------*
*& Form nested_loop
*&---------------------------------------------------------------------*
form nested_loop.

get time field start_time.

loop at bkpf_tab
into bkpf_lin.
bkpf_reads = bkpf_reads + 1.
loop at bseg_tab
into bseg_lin where
bukrs = bkpf_lin-bukrs and
belnr = bkpf_lin-belnr and
gjahr = bkpf_lin-gjahr.
bseg_reads = bseg_reads + 1.
endloop.
endloop.

get time field end_time.
difference = end_time - start_time.

write: /001 'Time for nested loop:', difference,
/005 'Number of BKPF reads:', bkpf_reads,
/005 'Number of BSEG reads:', bseg_reads.
skip 1.

endform. " nested_loop

*&---------------------------------------------------------------------*
*& Form indexed_loop
*&---------------------------------------------------------------------*
form indexed_loop.

data: bkpf_index like sy-tabix,
bseg_index like sy-tabix.

clear: bkpf_reads,
bseg_reads.

get time field start_time.

sort: bkpf_tab by bukrs belnr gjahr,
bseg_tab by bukrs belnr gjahr.

loop at bkpf_tab
into bkpf_lin.
read table bseg_tab
into bseg_lin
with key
bukrs = bkpf_lin-bukrs
belnr = bkpf_lin-belnr
gjahr = bkpf_lin-gjahr
binary search.
bkpf_reads = bkpf_reads + 1.
bseg_index = sy-tabix.
while sy-subrc = 0.
bseg_index = bseg_index + 1.
bseg_reads = bseg_reads + 1.
read table bseg_tab
into bseg_lin
index bseg_index.
if bseg_lin-bukrs <> bkpf_lin-bukrs or
bseg_lin-belnr <> bkpf_lin-belnr or
bseg_lin-gjahr <> bkpf_lin-gjahr.
sy-subrc = 99.
else.
endif.
endwhile.
endloop.

get time field end_time.
difference = end_time - start_time.

write: /001 'Time for indexed loop:', difference,
/005 'Number of BKPF reads:', bkpf_reads,
/005 'Number of BSEG reads:', bseg_reads.
skip 1.

endform. " indexed_loop

*&---------------------------------------------------------------------*
*& Form parallel_cursor
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM parallel_cursor.

DATA: bkpf_index LIKE sy-tabix,
bseg_index LIKE sy-tabix.

CLEAR: bkpf_reads,
bseg_reads.

GET TIME FIELD start_time.

SORT: bkpf_tab BY bukrs belnr gjahr,
bseg_tab BY bukrs belnr gjahr.

bseg_index = 1.
LOOP AT bkpf_tab
INTO bkpf_lin.
bkpf_reads = bkpf_reads + 1.
LOOP AT bseg_tab INTO bseg_lin FROM bseg_index.
IF bseg_lin-bukrs <> bkpf_lin-bukrs OR
bseg_lin-belnr <> bkpf_lin-belnr OR
bseg_lin-gjahr <> bkpf_lin-gjahr.
bseg_index = sy-tabix.
EXIT.
ELSE.
bseg_reads = bseg_reads + 1.
ENDIF.
ENDLOOP.
ENDLOOP.

GET TIME FIELD end_time.
difference = end_time - start_time.

WRITE: /001 'Time for parallel cursor :', difference,
/005 'Number of BKPF reads :', bkpf_reads,
/005 'Number of BSEG reads :', bseg_reads.

ENDFORM. " parallel_cursor

Overview

Hi All,
As many readers of this blog are requesting about SAP R/3 and ABAP overview concepts. Today we will see overview of SAP R/3 and ABAP.

SAP R/3 is the market leader for integrated business administration systems. It integrates all business processes of a company and provides modules for finance, human resources, material management, etc. SAP R/3 is based on a (second party) relational database system which serves as an integration platform for all components of SAP R/3. The database system manages the SAP database which stores all business data of a company (e.g., customer and supplier information, orders,), all of SAP R/3-internal control data, an SAP R/3 data dictionary, and the code of all application programs. Virtually no data are stored outside this SAP database, thereby avoiding the use of a _le system. Describing the whole system in detail is beyond the scope of this paper. In the following, we will focus on the properties of SAP R/3 which are most relevant for performance tuning. In particular, we focus on the SAP R/3 interface to the relational database system back-end.

Architecture of SAP R/3

SAP R/3 is based on a three-tier Client/server-architecture with the following layers

1. The presentation layer. It provides a graphical user interface (GUI) usually running on PCs that are connected with the application servers via a local (LAN) or a wide-area network (WAN).

2. The application layer. It comprises the business administration \know-how" of the system. It processes pre-defined and user-defined application programs such as OLTP and the implementation of decision support queries. Application servers are usually connected via a local area network (LAN) with the database server.

3. The database layer. It is implemented on top of a (second party) commercial database product that stores all data of the system, as described above. In a small company that uses SAP R/3, the application servers and the database system could be installed on the same middle-range machine and users would enter business transactions or issue decision support queries using their PCs. Such a configuration, however, is not practical for large companies with a very high volume of data and transactions. In such companies, all application servers and the database system would be installed on separate dedicated machines. To this end, SAP R/3 has been ported to a large variety of hardware and operating system platforms, and it is also operational on a number of commercial RDBMSs.

ABAP4 Overview

Applications of the SAP R/3 system are coded in the programming language ABAP/4 (Advanced Business Application Programming Language)

Except for a small kernel, actually the entire R/3 system is coded in ABAP/4. ABAP/4 is a so-called Fourth Generation Language (4GL) whose origins can be found in report/application generator languages. For this reason, ABAP/4 programs are often called reports. In the course of the R/3 evolution, ABAP/4 was augmented with procedural constructs in order to facilitate the coding of more complex business application programs. For example,ABAP/4 contains language constructs to program so-called \Dynpros" which are dialog programs with a graphical user interface including the logic for validating and processing user entries. Recently, SAP has extended its ABAP programming language with object-oriented features, sometimes referred to as ABAP Objects.

ABAP/4 is an interpreted language, which makes it very easy to integrate new ABAP/4 application programs into the system. Like ordinary data, all ABAP/4 application programs are managed by the R/3 data dictionary and the program code is stored in the SAP database. Also, SAP R/3 includes a

Software development workbench for developing new application code.

As sketched in Figure 2, ABAP/4 provides commands that allow accessing the database via two different interfaces: Native SQL and Open SQL.

The Native SQL interface can be addressed by so-called EXEC SQL commands. It allows the user to access the SAP database directly without using the SAP-internal data dictionary. The advantage is, that the database system-specific properties and services (e.g., non-standard SQL statements like optimizer hints or specialized operators like cube) can be fully exploited and additional overhead by SAP R/3 is avoided. However, using the Native SQL interface incurs some severe drawbacks:

(1) The EXEC SQL commands may be database system specific which renders non-portable ABAP/4 programs.

(2) By circumventing the SAP-internal data dictionary, EXEC SQL commands cannot access encapsulated relations (containing encoded/clustered

data that can only be interpreted using the transformations maintained in the data dictionary).
(3)Native SQL reports are potentially unsafe because Native SQL directly reads database relations, and the implementer of a Native SQL report might overlook intrinsic business process interpretations which are otherwise carried out implicitly by SAP R/3's application programs; that is, bypassing SAP R/3's data dictionary requires expert knowledge about the rules and dependencies of the system. Safe and portable ABAP/4 reports can be written by relying exclusively on ABAP/4's Open SQL commands. Consequently, with very few exceptions the entire R/3 system shipped by SAP is programmed using Open SQL.


Friday, December 15, 2006

Job notifications EDS

EDS (www.eds.com) have an urgent requirement for the Pune Facility

Skills : SAP ABAP

Location : 3+ Years

Location : PUNE


If you`re interested please send your updated resume to us ASAP and also please refer some of your friends and colleagues who are interested to apply for this openings


Thanks & regards

Lizy Jemima
Quality Zone Consultancy Services
Chennai
Tele : 91-044-22436842/42036842
Mobile : 91-9381035950
Mail to : lizy@qzcs.net

Tuesday, December 12, 2006

Roles and Responsibilities of a Technical consultant

The most common question being asked in interviews is ' What are your roles and responsibilities?'.
Before answering the above question, let me explain the difference between Functional consultant and Technical consultant.
Roles and responsibilities differ from functional consultant to Technical consultant.
Functional Consultant:

  • Functional consultants are responsible for designing the SAP implementation solution based on the requirements of your company.
  • Functional consultants are business process experts.
  • Functional consultants normally use their process knowledge to calculate the impact of the SAP implementation on the company's processes.
  • Functional consultants are thus concerned with SAP functions and processes that will generate the data and output for business.
  • Functional consultants interact with end users of the company to gather requirements and based on the requirements they customize the SAP implementation.
Technical Consultant:
  • Technical consultants are experts in information technology.
  • Technical consultants normally assist in configuration of the SAP R3 installation. In many SAP implementations, technical consultants help in designing interfaces and customizations in R3. Finally, the SAP R3 technical consultants would be responsible for migration of data from the legacy system to the new SAP ERP implementation.
  • Here i will discuss major roles and responsibilities of a technical consultant:

1) Designing technical specification by looking at the functinal specification you have recieved.
Usually senior developers having 3 years or more than 3 years of experience involves in preparing technical specifications.

2) Developing objects using ABAP workbench tools. That may be a report program or an on-line program or a custom table.
Remember the development work starts after the technical specification is approved by your team leader.

3) Preparing the Unit test case document.
In unit test case document, we document the results and test cases performed on the developed object.

4) Peer Review
if you are a senior developer you can perform peer review. I.e review the code written by your peers.

5) Working on Problem Tickets
If you are working in a support project, you should solve the tickets assigned to you. Tickets are nothing but the problems occured in production environment.

The above mentioned are the major roles and responsibilities for a technical consultant.

Monday, December 11, 2006

How to attach transaction codes to Area Menu

We know how to create transaction codes. We can use the transaction code SE93 ( Maintain Transaction).
Module pool programs/On-line programs must be attached to a transaction code to execute them.
Report programs (executable programs) can be executed directly without attaching them to the transaction codes.
But in real time, we do create custom transaction codes both for module pool programs/On-line programs and report programs.
Module pool programs and on-line programs are one and the same, where we do create screens using screen painter (SE51).
In real time business scenarios, after creating transaction codes, we need to attach them to Area Menu. End users can easily access the transaction codes if they are attached to Area Menu.
Area Menu is nothing but starting screen where in the left hand side we find menu.
The transaction code to maintain area menu is SE43.
using SE43, we can attach our custom transaction codes to the area menu. Please explore how to create nodes and subnodes under menu using SE43.

Blogger template 'YellowFlower' by Ourblogtemplates.com 2008