Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

what are enhancements? and what are user-exits?

Former Member
0 Kudos

pls give me answer to this mail srinuapr15@gmail.com

1. what are enhancements?

2. what are user-exits?

3. You are running a report. It is taking long time for

execution. What steps will you do to reduce the

execution time.

4. how do you get functional specs when you are

assigned some object? (specs through email..??)

3 REPLIES 3

Former Member
0 Kudos

WELCOME TO SDN!!!!!!!

1. Enhancements

The standard applications do not offer some of the functionality you need. The R/3 enchancement concept allows you to add your own functionality to SAP's standard business applications.

Different types of enhancements

Enhancements using customer exits

Customers' potential requirements which are not included in the standard software are incorporated in the standard as empty modification 'shells'. Customers can then fill these with their own coding. Enhancements can relate to programs, menus and screens. Upward compatibility is assured. In other words, SAP guarantees that the jump from the standard software to the exit and the interface which call the exit will remain valid in future releases.

Enhancements to ABAP/4 Dictionary elements

These are ABAP/4 Dictionary enhancements (creation of table appends), text enhancements (customer-specific key words and documentation for data elements) and field exits (creation of additional coding for data elements).

Advantages of enhancements

Do not affect standard SAP source code

Do not affect software upgrades

2.Userexits are predefined places in the SAP standard coding where customer can put their own logic in order to adjust standard processes to customer requirements. These places are predefined by SAP.

Transaction SMOD shows you which enhancements SAP has provided and of which components they consist of .

If you want to implement a userexit then you have to define an enhancement project (transaction CMOD), assign all enhancements (e.g. CATS0001, CATS0002, etc.) you need an then implement them.

Finally, you have to activate your project in order to activate the userexits.

Types of Exits

There are several different types of user exits. Each of these exits acts as hooks where you can attach or "hang" your own add-ons.

Menu Exits

Menu exits add items to the pulldown menus in standard SAP applications. You can use these menu items to call up your own screens or to trigger entire add-on applications.

SAP creates menu exits by defining special menu items in the Menu Painter. These special entries have function codes that begin with "+" (a plus sign). You specify the menu item?s text when activating the item in an add-on project.

Screen Exits

Screen exits add fields to screens in R/3 applications. SAP creates screen exits by placing special subscreen areas on a standard R/3 screen and calling a customer subscreen from the standard screen?s flow logic.

Function Module Exits

Function module exits add functions to R/3 applications. Function module exits play a role in both menu and screen exits.

When you add a new menu item to a standard pull down menu, you use a function module exit to define the actions that should take place once your menu is activated.

Function module exits also control the data flow between standard programs and screen exit fields. SAP application developers create function module exits by writing calls to customer functions into the source code of standard R/3 programs.

Field Exits

Field exits allow you to create your own programming logic for any data element in the Dictionary. You can use this logic to carry out checks, conversions, or business-related processing for any screen field. Example: The data element BBBNR identifies a company?s international location number. You might want to set up your R/3 System so that all international location numbers are larger than 100.

The field exit concept lets you create a special function module that contains this logic.

You assign the special function module to the data element BBBNR. You then assign the module to any programs and screens in which users can add new international location numbers. When you activate your field exit, the system automatically triggers your special routine whenever a user enters a company location number.

In 4.6c, you can use "RSMODPRF" program to create field exits.

3. To reduce the execution time,

Run SQL trace using ST05 transaction.

You have to open two SAP screen.Open ST05 transaction in One and make Trace on ,Run the report in another screen.

Once report run is over. End the trace process and click on display trace in same ST05 transaction.

This will give you all database fetch which is time consuming.

Try to modify SQL statements by devising some efficient SQL statement.

Never process SQL in loop.

These will enhance performace.

Also check this links..It has an excellent collection of performance tuning techniques.

4.Functional Specs

Functional specs is like a templeate document which a functional consultant prepares to be given to Abaper. This Document contains details like Tables & fields name, Table joints, Logic for development, along with test case in sand box / test server to verify the development.

Check these threads for sample Functional spec.

Former Member
0 Kudos

hi,

1. what are enhancements?

2. what are user-exits?

Follow the link for complete details.

https://www.sdn.sap.com/irj/sdn/nw-development?rid=/webcontent/uuid/2342e1f3-0b01-0010-a186-fdd40488... [original link is broken]

3. You are running a report. It is taking long time for

execution. What steps will you do to reduce the

execution time.

Steps to optimise the ABAP Code?

Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.

Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.

Design your Query to Use as much index fields as possible from left to right in your WHERE statement

Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.

Avoid using nested SELECT statement, SELECT within LOOPs.

Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.

Avoid using SELECT * and Select only the required fields from the table.

Avoid nested loops when working with large internal tables.

Use assign instead of into in LOOPs for table types with large work areas When in doubt call transaction SE30 and use the examples and check your code

Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.

Use "CHECK" instead of IF/ENDIF whenever possible.

Use "CASE" instead of IF/ENDIF whenever possible.

Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING", creates more coding but is more effcient.

TABLE BUFFERING : This can help in improving the performance but this has to be used with caution. Buffering of tables leads to data being read from the buffer rather than from table. Buffer sync with table happens periodically. If this table is a transaction table chances are that the data is changing for a particular selection criteria. Using table buffering in such cases is not recommended. Use Table Buffering for Master Data or data which is having low transaction. Also, when using a table with buffering ensure that the general criteria which is used for buffering is also being used. If the criteria of buffering is not same as the one used in your code, it has no effect and buffering will not be useful instead it will cause a overhead on performance since evrytime it will fill the buffer. In such cases use 'BYPASSING BUFFER' to speed up the SQL's.

INDEX: Creation of Index for improving performance should not be taken without thought. Index speeds up the performance but at the same time adds two overheads namely; memory and insert/append performance. When INDEX is created, memory is used up for storing the index and index sizes can be quite big on large transaction tables! When inserting new entry in the table, all the index's are updated. More index more time. More the amount of data, bigger the indices, larger the time for updating all the indices.

PERFORM : When writing a subroutine, always provide type for all the paramters. This reduces the overhead which is present when system determines on it's own each type from the formal parameters that are passed.

Updating/Modifying internal tables: In case the amount of entries are more than 200 in an internal table and some field's are being manipulated or some column of the internal table being filled based on some logic, usage of FIELD-SYMBOLS is recommended. This removes the overhead of moving the operation via a seperate memory area (work area).

4. how do you get functional specs when you are

assigned some object? (specs through email..??)

Your Functional guy would provide you with the functional spec.

Hope this is helpful, Do reward.

Former Member

HI

The enhancement concept allows you to add your own functionality to SAP’s standard business applications without having to modify the original applications. SAP creates customer exits for specific programs, screens, and menus within standard applications. These exits do not contain any functionality. Instead, the customer exits act as hooks. You can hang your own add-on functionality onto these hooks.

If you want to enhance the functionality of your SAP System, you should take advantage of the exits available in standard applications. There are two main reasons why you should use exits rather than modifying SAP software yourself. Add-ons attached to exits have the advantage that:

They do not affect standard SAP source code.

When you add new functionality to your SAP System using SAP’s exits, you do not alter the source code of standard SAP programs in any way. The code and screens you create are encapsulated as separate objects. These customer objects are linked to standard applications, but exist separately from SAP’s standard software package.

They do not affect software updates.

When you add new functionality to your SAP System using SAP’s exits, your objects (called customer objects) must adhere to strict naming conventions. When it comes time to upgrade a to a new software release, customer objects’ names ensure that they will not be affected by any changes or new additions to the standard software package.

Customer exits are not available for all programs and screens found in the SAP System. You can only use customer exits if they already exist in the SAP System.

USER-EXIT

Overview

R/3 provides three "customization spots" that allow you to enhance FI/CO features without modifying the standard code. Although often collectively referred to as "user exits," two of the three have different names. SAP Enhancements are used to expand the standard functionality within SAP. Enhancements use function modules and are called from the standard SAP code. Each module in the system has a set of delivered enhancements that help companies expand the standard functionality where they need it. Enhancements were new in release 3.0.

The Open FI Interfaces or Business Transaction Events are also used to expand the standard functionality within SAP. These events are defined in the IMG. Business Transaction Events were new in release 4.0. They are not available for all modules and are not called on all integrated transactions into FI as of release 4.5B. This will change with each release and should be retested.

The older User Exits in FI/CO are "Z" programs that are defined in table T80D for client-dependent user exits, and in table T80I for client-independent user exits. These are also used to expand the standard functionality within the FI/CO modules. These User Exits have been available since the early releases of SAP. All of these FI/CO User Exits are listed in this document in the Configuring User Exits (Older). The list is included because these User Exits are not a part of the Enhancements or Business Transaction Events and do not have an Info System for searching.

Benefits• Standard SAP functionality can be enhanced without modification to the standard code.

• Upgrades do not erase the functionality and it does not have to be re-transported or re-entered into the system. The enhancements should be thoroughly tested when upgrading to ensure the system will still work as implemented.

Configuring SAP Enhancements

Basic Steps in Configuring an Enhancement

• Find the appropriate Enhancement.

• Enter the ABAP code in the "Z" program within the function module.

• Create a project.

• Add the Enhancement to the project.

• Activate the project.

Example Business Scenario for Enhancements

Company A has a requirement to validate all customer master records created with a U.S. address. The U.S. entity reports on the industry field on the customer master. This is only a U.S. requirement and should not be required for the other countries, so the field status would not work. To accomplish this requirement, Company A will need to set up an Enhancement for the customer master transaction. The necessary steps are detailed below with screenprints. This example was configured in a 4.6C system.

Detailed Steps

1. Tools ABAP Workbench Utilities Enhancements Definition Utilities List Enhancements

2. Do not execute this without any parameters! There are too many Enhancements and it will probably time out. You’re searching for a customer master exit. Enter mast in the short text (see Figure 1). You’ll start there. Searching for an exit can be tricky, so make sure you try several things before giving up.

3. Execute the search.

Start Your Search for a Master Exit Here

4. Look through the list until you find the Enhancement for User exits: Customer Master Data.

5. Double-click on the enhancement SAPMF02D. This will take you to the details of the Enhancement and list the function modules included in the Enhancement.

6. To continue, double-click on the function module EXIT_SAPMF02D_001

7. This will take you to the source code for the function module. Click on the Import tab to review the tables/fields that are available for the Enhancement

The Tables That Are Available for the Enhancement

8. To view the tables/fields that can be changed in the function module, click on the Export and Changing tabs. For this function module, these tabs are empty because you can only validate data. You cannot change any fields in this enhancement.

9. Return to the Source Code tab.

10. Scroll down until you see the Include statement in the program. The "Z" program listed after the Include is where your code will be written

Your Program Will Begin After the Include Statement

11. Double-click on the Include. You will be prompted to create the include. Click on Yes to create.

12. At this point you will be prompted to enter a development class and to create a transport request. If you do not know which development class to use, please contact your technical team.

13. Enter the following ABAP code into the program

*

User exit to ensure that all US customers have a group key

entered on the customer master.

*

if i_kna1-land1 = 'US' and

i_kna1-brsch = ' '.

message e001(F2).

endif.

The ABAP Code You Need to Enter

14. Note that the table name matches the table name in the import tab tables.

15. In this example you are using the standard message class F2 with message number 001. Normally, you will create your own message within your own message class. All customer message classes must begin with a "Z" and are created in transaction SE91.

16. Save the program.

17. The next step is to create the project. Go to transaction code CMOD or follow menu path: Tools ABAP Workbench Utilities Enhancements Project Management.

18. Enter the project name; begin the name with a "Z."

19. Click on the Create button.

Click on Create After You Type in the Project Name

20. Enter in a description for the project.

21. Click on the Enhancement Assignments button.

22. You will be prompted to save the enhancement. Click on Yes.

23. At this point you will be asked for a development class and to create a transport for the project. You may use the same one created when adding the ABAP code to the function module.

24. Enter the name of the enhancement SAPMF02D (see Figure 6).

Enter the Name of the Enhancement Here

25. Save the project.

26. Back out of the enhancement assignment.

27. Activate the project by hitting the Activate button.

The SAP Enhancement is ready to be tested! Try creating a customer with U.S. as the country and a blank group key. Be sure to test one with a group key to make sure the message is not displayed in error as well.

Configuring Business Transaction Events

Basic Steps in Configuring an Event

• Make sure the application is active for Business Transaction Events.

• Copy the sample interface function module into a "Z" function module.

• Enter the ABAP code into the source code section of the new "Z" function module. You may choose to create a "Z" program to enter the code into and then insert the "Z" program into your function module source code.

• Activate the function module.

• Assign the function module to the event, country and application.

Example Business Scenario for Business Transaction Events

Company A would like to copy the group key field from the vendor master into the allocation field on all the line items within a vendor invoice and payments, including the vendor lines. This requirement assumes only one vendor is posted to in a document.

To accomplish this requirement, Company A will use the Business Transaction Event 1130, Post Document: SAP Internal Field Substitution.

1. IMG Menu Path: Financial Accounting Financial Accounting Global Settings Use Business Transaction Events Environment Infosystem (Processes).

2. Find the correct Business Event. You are updating a field, so you select the Processes Info System instead of the Publish and Subscribe Info System.

3. Execute the search with the defaults.

4. Find the correct interface for updating a document: Post Document: SAP- Internal Field Substitution

Find the Correct Interface for the Business Event

5. Put your cursor on the event and click on the Sample Function Module button.

6. You are now in transaction SE37 – Function Builder. This is the function module (sample_process_00001130) you will need to copy into a "Z" name function module for your coding

Figure 8. This Is the Function Module You Need to Copy Your "Z" Name Function Module

7. Click on the Copy button.

8. Enter the "Z" function module name in the To Function Module field

9. Enter a Function Group. If you need to create a "Z" function group, go to transaction code SE37 and follow menu path: Go to Function Groups Create Group. A function group is a logical grouping of function modules, and the ABAP code is generated for function groups. You will be prompted for a development class and transport when creating the function group.

Enter Your "Z" Function Module Name Here

10. In Function Builder (transaction SE37), enter the new "Z" function module. Click on the Change button.

11. The system will default into the source code screen where you may enter your ABAP code.

12. Notice the tables available for the code. Additional tables may be declared if necessary.

13. Enter the following source code

tables: lfa1.

data: z_groupkey like lfa1-konzs.

z_groupkey = ' '.

loop at t_bseg.

check for vendor lines. If one is found, read the vendor master and

retrieve the group key field.

if t_bseg-koart eq 'K'.

select single konzs from lfa1 into z_groupkey

where lifnr = t_bseg-lifnr.

endif.

Move the group key field into all line items allocation field.

loop at t_bsegsub.

t_bsegsub-zuonr = z_groupkey.

modify t_bsegsub index sy-tabix.

endloop. "t_bsegsub

endloop. "t_bseg

The Screen Where You Enter Your Source Code

14. Save the function module.

15. Back out to the main Function Builder screen by clicking on the green arrow button.

16. Activate the function module by clicking on the Activate button

. Activate the Function Module from This Screen

17. Assign the function module to the event in the IMG: Financial Accounting Financial Accounting Global Settings Business Transaction Events Settings Process Function Modules of an SAP Appl.

18. Hit enter past the warning messages that this is SAP data.

19. Click on the New Entries button.

20. Enter the process for your interface. In your example it is 00001130.

21. Enter the country the interface is valid for. If it is valid for all countries, leave this field blank.

22. Enter the application the interface should be called for. If it should be called for all applications, leave this field blank. Please note that not all integrated transactions are programmed to go through these interfaces! You will need to test to find out!

23. Enter the new "Z" function module

Enter Your New "Z" Function Module Here

24. Save the settings. At this point you will be prompted for a CTS number for the configuration change.

25. The Business Transaction Event is complete! You are ready for testing.

Configuring User Exits (Older)

Basic Steps in Configuring an User Exit

• Create a "Z" program for the User Exits and enter the necessary ABAP code.

• Enter the new program name into table T80D.

• Configure the application to call the User Exit.

List of User Exits

• Variable Field Movements

• Substitutions in FI, CO, PCA

• Validations in FI, CO, PCA

• Rollups in SPL

• Fixed Field Movements in SPL

• Cost Center Summarization on Detail Screen

• Sets Formula Variables

Example Business Scenario for User Exits

Company A would like to add a "Z" field in the Special Purpose Ledger to capture a Business Unit field for reporting. They have used all the standard SAP fields such as Business Area and Profit Center. The field will only be used for reporting and is only needed in the Special Purpose Ledger. You created a special ledger table (ZZSPL1) with field Z_BUNIT and need to populate this field based on a combination of G/L account, fund and functional area.

To accomplish this requirement, Company A will use the Variable Field Movement User Exit. To make maintenance easier, table ZZBUSUNIT was created with the G/L account, fund and functional area fields as key fields, and the business unit field as a non-key field. You generated the table maintenance so the table could be updated using transaction SM30. SAP users update the business unit determination rules in table ZZBUSUNIT by entering the G/L account, fund and functional area, and then the business unit that combination should be posting to. The User Exit will read table ZZBUSUNIT using the G/L account, fund and functional area from the posting transaction and determine the business unit. The steps for using the user exit are detailed below. This example was created on a 4.6C system.

1. Copy the delivered template User Exit program RGIVU000_TEMPLATE into a "Z" program. Follow menu path Tools ABAP Workbench Development ABAP Editor (transaction code SE38). In early releases, the delivered program was RGIVU000.

2. You will be prompted for a development class and a transport. Please check with the technical team for the correct development class.

3. At the initial ABAP Editor screen, enter your new "Z" program name, select the Source Code button and click on Change

To Enter Your New Code, Select Source Code and Click on the Change Button

4. Enter the following code in the User Exit (Figure 14):

FORM E01_MVC USING FROM_FIELD TO_FIELD.

to_field = 'CORP'. "Set a default business unit.

read table zzbusunit to determine the business unit field.

select single z_bunit from zzbusunit into to_field

where hkont = accit_glx-hkont and

geber = accit_glx-geber and

fkber = accit_glx-fkber.

ENDFORM.

Figure 14. Enter Your New Code at This Screen.

5. Activate the program by clicking on the Activate button.

6. Change the configuration in the User Exit table to point to your new "Z" program.

7. Follow the IMG menu path: Financial Accounting Special Purpose Ledger Basic Settings User Exits Maintain Client Specific User Exits.

8. The entry to maintain is application area GIMV: Variable Field Movement. Enter your "Z" program

Enter Your "Z" Program in the Application Area GIMV: Variable Field Movement

9. Save the changes.

10. The final configuration step is to assign the User Exit in the variable field movement for your special ledger table. In the IMG: Financial Accounting  Special Purpose Ledger  Basic Settings  Master Data  Maintain Field Movements. Field movements control how the fields in a special ledger table are populated. They can be populated straight from other fields in a posting or through User Exits.

After You Assign the Business Unit Field and the G/L Account, the Exit Field Should Contain U01.

11. Assign the business unit field as a receiver and the G/L account as the sender. The Exit field should contain U01 (see Figure 16).

12. The User Exit number U01 calls User Exit E01_MVC form in the "Z" program.

13. Save the field movement.

14. You are ready to test your User Exit!

Ways of Performance Tuning

1. Selection Criteria

2. Select Statements

• Select Queries

• SQL Interface

• Aggregate Functions

• For all Entries

Select Over more than one internal table

Selection Criteria

1. Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement.

2. Select with selection list.

SELECT * FROM SBOOK INTO SBOOK_WA.

CHECK: SBOOK_WA-CARRID = 'LH' AND

SBOOK_WA-CONNID = '0400'.

ENDSELECT.

The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list

SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK

WHERE SBOOK_WA-CARRID = 'LH' AND

SBOOK_WA-CONNID = '0400'.

Select Statements Select Queries

1. Avoid nested selects

SELECT * FROM EKKO INTO EKKO_WA.

SELECT * FROM EKAN INTO EKAN_WA

WHERE EBELN = EKKO_WA-EBELN.

ENDSELECT.

ENDSELECT.

The above code can be much more optimized by the code written below.

SELECT P~F1 P~F2 F~F3 F~F4 INTO TABLE ITAB

FROM EKKO AS P INNER JOIN EKAN AS F

ON P~EBELN = F~EBELN.

Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.

2. Select all the records in a single shot using into table clause of select statement rather than to use Append statements.

SELECT * FROM SBOOK INTO SBOOK_WA.

CHECK: SBOOK_WA-CARRID = 'LH' AND

SBOOK_WA-CONNID = '0400'.

ENDSELECT.

The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table

SELECT CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK

WHERE SBOOK_WA-CARRID = 'LH' AND

SBOOK_WA-CONNID = '0400'.

3. When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.

To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields. In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.

4. For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit.

SELECT * FROM SBOOK INTO SBOOK_WA

UP TO 1 ROWS

WHERE CARRID = 'LH'.

ENDSELECT.

The above code is more optimized as compared to the code mentioned below for testing existence of a record.

SELECT * FROM SBOOK INTO SBOOK_WA

WHERE CARRID = 'LH'.

EXIT.

ENDSELECT.

5. Use Select Single if all primary key fields are supplied in the Where condition .

If all primary key fields are supplied in the Where conditions you can even use Select Single.

Select Single requires one communication with the database system, whereas Select-Endselect needs two.

Select Statements SQL Interface

1. Use column updates instead of single-row updates

to update your database tables.

SELECT * FROM SFLIGHT INTO SFLIGHT_WA.

SFLIGHT_WA-SEATSOCC =

SFLIGHT_WA-SEATSOCC - 1.

UPDATE SFLIGHT FROM SFLIGHT_WA.

ENDSELECT.

The above mentioned code can be more optimized by using the following code

UPDATE SFLIGHT

SET SEATSOCC = SEATSOCC - 1.

2. For all frequently used Select statements, try to use an index.

SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA

WHERE CARRID = 'LH'

AND CONNID = '0400'.

ENDSELECT.

The above mentioned code can be more optimized by using the following code

SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA

WHERE MANDT IN ( SELECT MANDT FROM T000 )

AND CARRID = 'LH'

AND CONNID = '0400'.

ENDSELECT.

3. Using buffered tables improves the performance considerably.

Bypassing the buffer increases the network considerably

SELECT SINGLE * FROM T100 INTO T100_WA

BYPASSING BUFFER

WHERE SPRSL = 'D'

AND ARBGB = '00'

AND MSGNR = '999'.

The above mentioned code can be more optimized by using the following code

SELECT SINGLE * FROM T100 INTO T100_WA

WHERE SPRSL = 'D'

AND ARBGB = '00'

AND MSGNR = '999'.

Select Statements Aggregate Functions

• If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.

Some of the Aggregate functions allowed in SAP are MAX, MIN, AVG, SUM, COUNT, COUNT( * )

Consider the following extract.

Maxno = 0.

Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.

Check zflight-fligh > maxno.

Maxno = zflight-fligh.

Endselect.

The above mentioned code can be much more optimized by using the following code.

Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.

Select Statements For All Entries

• The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.

The plus

• Large amount of data

• Mixing processing and reading of data

• Fast internal reprocessing of data

• Fast

The Minus

• Difficult to program/understand

• Memory could be critical (use FREE or PACKAGE size)

Points to be must considered FOR ALL ENTRIES

• Check that data is present in the driver table

• Sorting the driver table

• Removing duplicates from the driver table

Consider the following piece of extract

Loop at int_cntry.

Select single * from zfligh into int_fligh

where cntry = int_cntry-cntry.

Append int_fligh.

Endloop.

The above mentioned can be more optimized by using the following code.

Sort int_cntry by cntry.

Delete adjacent duplicates from int_cntry.

If NOT int_cntry[] is INITIAL.

Select * from zfligh appending table int_fligh

For all entries in int_cntry

Where cntry = int_cntry-cntry.

Endif.

Select Statements Select Over more than one Internal table

1. Its better to use a views instead of nested Select statements.

SELECT * FROM DD01L INTO DD01L_WA

WHERE DOMNAME LIKE 'CHAR%'

AND AS4LOCAL = 'A'.

SELECT SINGLE * FROM DD01T INTO DD01T_WA

WHERE DOMNAME = DD01L_WA-DOMNAME

AND AS4LOCAL = 'A'

AND AS4VERS = DD01L_WA-AS4VERS

AND DDLANGUAGE = SY-LANGU.

ENDSELECT.

The above code can be more optimized by extracting all the data from view DD01V_WA

SELECT * FROM DD01V INTO DD01V_WA

WHERE DOMNAME LIKE 'CHAR%'

AND DDLANGUAGE = SY-LANGU.

ENDSELECT

2. To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.

SELECT * FROM EKKO INTO EKKO_WA.

SELECT * FROM EKAN INTO EKAN_WA

WHERE EBELN = EKKO_WA-EBELN.

ENDSELECT.

ENDSELECT.

The above code can be much more optimized by the code written below.

SELECT P~F1 P~F2 F~F3 F~F4 INTO TABLE ITAB

FROM EKKO AS P INNER JOIN EKAN AS F

ON P~EBELN = F~EBELN.

3. Instead of using nested Select loops it is often better to use subqueries.

SELECT * FROM SPFLI

INTO TABLE T_SPFLI

WHERE CITYFROM = 'FRANKFURT'

AND CITYTO = 'NEW YORK'.

SELECT * FROM SFLIGHT AS F

INTO SFLIGHT_WA

FOR ALL ENTRIES IN T_SPFLI

WHERE SEATSOCC -FLAG = 'X'.

ENDIF.

ENDLOOP.

The above code works faster as compared to

LOOP AT ITAB INTO WA.

I = SY-TABIX MOD 2.

IF I = 0.

WA-FLAG = 'X'.

MODIFY ITAB FROM WA.

ENDIF.

ENDLOOP.

8. If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.

LOOP AT ITAB1 INTO WA1.

READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.

IF SY-SUBRC = 0.

ADD: WA1-VAL1 TO WA2-VAL1,

WA1-VAL2 TO WA2-VAL2.

MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.

ELSE.

INSERT WA1 INTO ITAB2 INDEX SY-TABIX.

ENDIF.

ENDLOOP.

The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by

LOOP AT ITAB1 INTO WA.

COLLECT WA INTO ITAB2.

ENDLOOP.

SORT ITAB2 BY K.

COLLECT, however, uses a hash algorithm and is therefore independent

of the number of entries (i.e. O(1)) .

9. "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”

APPEND LINES OF ITAB1 TO ITAB2.

This is more optimized as compared to

LOOP AT ITAB1 INTO WA.

APPEND WA TO ITAB2.

ENDLOOP.

10. “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.

This is much more optimized as compared to

READ TABLE ITAB INDEX 1 INTO PREV_LINE.

LOOP AT ITAB FROM 2 INTO WA.

IF WA = PREV_LINE.

DELETE ITAB.

ELSE.

PREV_LINE = WA.

ENDIF.

ENDLOOP.

11. "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “ DO -DELETE-ENDDO”.

DELETE ITAB FROM 450 TO 550.

This is much more optimized as compared to

DO 101 TIMES.

DELETE ITAB INDEX 450.

ENDDO.

12. Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.

ITAB2[] = ITAB1[].

This is much more optimized as compared to

REFRESH ITAB2.

LOOP AT ITAB1 INTO WA.

APPEND WA TO ITAB2.

ENDLOOP.

13. Specify the sort key as restrictively as possible to run the program faster.

“SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”

Internal Tables contd…

Hashed and Sorted tables

1. For single read access hashed tables are more optimized as compared to sorted tables.

2. For partial sequential access sorted tables are more optimized as compared to hashed tables

Hashed And Sorted Tables

Point # 1

Consider the following example where HTAB is a hashed table and STAB is a sorted table

DO 250 TIMES.

N = 4 * SY-INDEX.

READ TABLE HTAB INTO WA WITH TABLE KEY K = N.

IF SY-SUBRC = 0.

" ...

ENDIF.

ENDDO.

This runs faster for single read access as compared to the following same code for sorted table

DO 250 TIMES.

N = 4 * SY-INDEX.

READ TABLE STAB INTO WA WITH TABLE KEY K = N.

IF SY-SUBRC = 0.

" ...

ENDIF.

ENDDO.

Point # 2

Similarly for Partial Sequential access the STAB runs faster as compared to HTAB

LOOP AT STAB INTO WA WHERE K = SUBKEY.

" ...

ENDLOOP.

This runs faster as compared to

LOOP AT HTAB INTO WA WHERE K = SUBKEY.

" ...

ENDLOOP.

how do you get functional specs when you are

assigned some object? (specs through email..??)

your team leader will send a mail to you saying that so and so OBJECT is assigned for you and mostly he will send FS to you

other wise he will tell you where exactly that FS is located