Powered By

Free XML Skins for Blogger

Powered by Blogger

Showing posts with label SAP ABAP DEVELOPMENT. Show all posts
Showing posts with label SAP ABAP DEVELOPMENT. Show all posts

Wednesday, February 4, 2009

SAP ABAP4 Tuning Checklist

ABAP/4 Tuning Checklist

General Considerations:

1. Is the program YEAR 2000 compliant ?
check date logic and make sure there are not any 2 digit year fields

2. Is the program US ready ?

taking into consideration the US volumes, will the program ever finish? Can data be selected for just the US - selection parameters at company code level, plant, purch org, sales div, etc...

SQL SELECT statements:

3. Is the program using SELECT * statements ?

Convert them to SELECT column1 column2 or use projection views

4. Are CHECK statements for table fields embedded in a SELECT ... ENDSELECT loop, or in a LOOP AT ... ENDLOOP ?

Incorporate the CHECK statements into WHERE clause of the SELECT statement, or the LOOP AT statement

5. Do SELECTS on non-key fields use an appropriate DB index or is table buffered ?

Create an index for the table in the data dictionary or buffer tables if they are read only or read mostly

6. Is the program using nested SELECTs to retrieve data ?

Convert nested selects to database views, DB joins (4.0) or SELECT xxx FOR ALL ENTRIES IN ITAB Nested open select tatements are usually bad, and unless the amount of data is enormous, these types of reads should be avoided. They are usually used as they are the safest way to program - you will never have any memory issues. The technical explanation as to why this is bad follows - feel free to tune out for the remainder of the paragraph. Open selects read just one record from the database at a time. Each time you do this, the app server and database server need to communicate. The packet size of this communication is typically much larger than the size of the record, so most of the packet is waisted with this type of read. When system load is heavy, this can slow performance. Combine this with the overhead of accessing the database many times vs just once.

7. Are there SELECTs without WHERE condition against files that grow constantly (BKPF/BSEG,MKPF/MSEG,VBAK/VBAP...) ?

Program design is wrong - back to drawing board

8. Are SELECT accesses to master data files buffered (no duplicate accesses with the same key) ?

Buffer accesses to master data files by storing the data in an internal table and filling the table with READ TABLE...BINARY SEARCH method

9. Is the program using SELECT ...APPEND ITAB ...ENDSELECT techniques to fill internal tables ?

Change processing to read the data immediately into an internal table (SELECT VBELN AUART ... INTO TABLE IVBAK...)

10. Is the program using SELECT ORDER BY statements ?

Data should be read into an internal table first and then sorted, unless there is an appropriate index on the order by fields

11. Is the programming doing calculations/summations that can be done on the database via SUM, AVG, MIN or MAX functions of the SELECT statement?

use the calculation capabilities of the database via SELECT SUM...

12. Do any SELECT statements contain fully-qualified keys (all keys are specified to match a single value in the WHERE clause) but not the keyword SINGLE?

the syntax checker won't catch this & neither does the database optimizer! such an "incorrect" statement can take 5x longer

13. Are there any SELECT or LOOP AT structures that are only attempting to retrieve the first match on a generic key lookup?

use the EXIT statement, or UP TO 1 ROWS option in the case of SELECT, to break the loop & avoid unnecessary iterations

14. Do UPDATE/INSERT/DELETE statements occur inside loops?

save all accumulated changes in an internal table and then use the SQL array statements to perform the updates: INSERT FROM TABLE .

15. Are only a few fields being changed by an UPDATE statement?

use the SET = clause of the UPDATE statement rather than updating the entire record

16. Is the program inserting/updating or deleting data in dialog mode (not via an update function module) ?

Make sure that the program issues COMMIT WORK statements when one or more logical units of work (LUWS) have been processed

Internal Table Processing:

(also see 4 & 13 above)

17. Are internal tables processed using READ TABLE itab WITH KEY ... BINARY SEARCH technique ?

Change table accesses to use BINARY SEARCH method. Note that this is ONLY possible if the table is sorted by the access key! Add a SORT if not already there.

18. Is a semi-sequential scan of a large, sorted internal table being performed by a LOOP AT ... WHERE, or LOOP AT ... with CHECK statements to continue/terminate the loop ?

Use a READ TABLE with BINARY SEARCH to retrieve first record in the sequence matching the lookup keys, then LOOP AT ... FROM SY- TABIX + 1 until one of the key field values changes; this way you get only the records you need, rather than reading up to the starting point

19. Is a condensed, summary internal table being built by READ TABLE... BINARY SEARCH and then sum, INSERT or APPEND?

Use the COLLECT statement, and SORT the result after the table is complete

20. Is a COLLECT statement being used simply to avoid duplicate entries in an all-character fields - no numeric fields: types I, P or F - internal table ?

Use the READ TABLE ... WITH KEY ... BINARY SEARCH with an INSERT ... INDEX SY-TABIX to build the table

21. Are internal tables being SORTed without any field qualifiers?

Specify the actual fields to be used: SORT BY ... The fewer fields, the better!

22. Are internal tables being copied or compared record-by-record?

Use the "[]" option to refer to the entire table in one line of code:

- TAB2[] = TAB1[] - copy TAB1 to TAB2

- IF TAB1[] EQ TAB2[] - compare TAB1 to TAB2


String Processing:

23. Are strings being built up/broken down manually with code fragments?

use the new CONCATENATE/SPLIT statements, with the SEPARATED BY SPACE option of CONCATENATE if desired

24. Are the older, obsolete string handling functions for finding string length, or centering/right-justifying strings being called?

use the newer "strlen( )", "WRITE...TO...CENTERED", "WRITE...TO...RIGHT-JUSTIFIED" statements

25. Are field strings (records) being set to a special character, other than SPACE, via a CLEAR and then a TRANSLATE instruction?

use the new CLEAR WITH statement (esp. useful with standard SAP batch input generation programs to set the "no value for this field" indicator, which has a default symbol of "/")

Miscellaneous:

26. Is an internal table filled with a massive amount of data (approx. 5000 to 10000 records or more, depending on record length), sorted and processed?

- instead, use the FIELD-GROUPS declaration, and the INSERT, EXTRACT, SORT and LOOP instructions to define, create, sort and process such large volumes of data more efficiently

27. Is a logical database-driven program taking too long to select data?

- convert the program to specific SELECT statements, with more appropriate index usage and a minimized sequence of nested SELECTs; don't forget to remove the 'Logical database' name/application from the program's attributes

28. Is a MOVE-CORRESPONDING statement used when it's not needed?

- if moving a complete record with same structure, just use the simple assignment statement: XVBAP = VBAP or MOVE VBAP TO XVBAP

and if moving only a handful of fields, use specific assignments

29. Are there no OBLIGATORY specifications on the key PARAMETERS and/or SELECT-OPTIONS declarations?

- enforce user entry of key fields, thus limiting database accesses to some degree. To read everything, however, the user could still enter "1" -"99999999..." (see next item though), but at least they start to think about what they really need to see.

30. Are SELECT-OPTIONS fully open to the most complex searches even when they need not be?

- Use the keywords NO-EXTENSION and/or NO INTERVALS of the SELECT-OPTIONS declaration, if possible, to limit the number of ranges to only 1 (NO-EXTENSION), or limit the entry to single values only (NO INTERVALS) if that's all that is really needed for the application, so that the SELECT statement's "IN" operation is less complex

31. Producing information messages about "long run-times" can also be beneficial in reducing run-times

-the user will think twice and hopefully re-starts the program with a smaller range; or in extreme situations, an error message preventing generic input or complete range input on a key field

32. In especially difficult cases, where no amount of specific statement re- writing, indexing, or buffering increases performance enough, consider re- structuring the main SELECT sequence, if possible, to reduce the total number of records to a manageable size.

- this technique is only possible with certain table sequences that are related via both forward and backward pointing foreign key relationships, and then only makes sense when reversing the logic will definitely reduce the total read accesses, and does not require a complete program re-write of all related routines, etc.

Friday, October 10, 2008

SAP ABAP Class ALV

Class ALV Specification

Classes used:

CL_GUI_ALV_GRID

Example of ALV using Classes

DATA: lcl_alv TYPE REF TO cl_gui_alv_grid,
t_flights TYPE STANDARD TABLE OF FLIGHTS.

SELECT * FROM flights INTO TABLE t_flights.

CREATE OBJECT lcl_alv
EXPORTING I_PARENT = cl_gui_container=>screen0.

CALL METHOD lcl_alv->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME = 'FLIGHTS'
CHANGING
IT_OUTTAB = t_flights.

CALL SCREEN 100.

Example Details

This is a simple example of the class ALV, we do not need to create, in this case, a field catalog because we are using the whole table of FLIGHTS and we will show all the fields that this table contains, we do this at the I_STRUCTURE_NAME = 'FLIGHTS' statement.
The CL_GUI_ALV_GRID constructor needs the I_PARENT parameter to define where it will be show, in the example we set the entire screen to place the ALV.

SAP ABAP ALV Articles

* "An Easy Reference For ALV Grid Control", Serdar Simsekler
* "Using ALV for List Display", Barbara Neumann
* "ALV Object Model - Simple 2D Table - The Basics", Rich Heilman
* "ALV Object Model - Simple 2D Table - Event Handling", Rich Heilman

SAP ABAP ALV Pdf books

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907


https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4544e790-0201-0010-c29c-e46c389f5a96

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/ALV%20Object%20Model%20-%20Simple%202D%20Table%20-%20The%20Basics.pdf

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cda3992d-0e01-0010-90b2-c4e1f899ac01

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4544e790-0201-0010-c29c-e46c389f5a96

SAP ABAP Acronyms

Some of the commonly used acronyms in NetWeaver ABAP :

ABAP - Advanced Business Application Programming
ALE - Application Link Enabling
ALV - ABAP List Viewer
BAdI - Business Add In
BAPI - Business Application Programming Interface
BDC - Batch Data Conversion
BPEL - Business Process Execution Language (for Web Services)
BPM - Business Process Management

BSP- Business Server Page
CAF - Composite Application Framework
CCMS - Computing Center Managemet System
EAI - Enterprise Application Integration
EDI - Electronic Data Interchange
ETL - Extract Transform and Load
IDoc - Intermediate Document
JCA - J2EE Connector Architecture
JCo - Java Connector
LDB- Logical Database

LSMW - Legacy System Migration Workbench
LUW- Logical Unit Of Work
NW - NetWeaver
RFC - Remote Function Call
SLD - System Landscape Directory
SMTP - Simple Mail Transfer Protocol
SOAP - Simple Object Access Protocol
TCODE - Transaction code
TMS - Transport Management System
UCCnet - Uniform/Universal Code Council network
UDDI - Universal Description, Discovery and Integration
WSDL - Web Services Description Language (XML format for describing network services)
XML - eXtensible Markup Language

SAP ABAP Transport Guide

Tips for Different SAP Objects

Question: How can I transport certain SAP objects?

Here are tips for different objects:

LSMW: There are 2 ways for transporting LSMW data from a system to another.

  1. Export/import this method gives you the opportunity to select the subprojects or objects you want to transfer. LSMW -> Extras -> Export project
  2. Transport request with this method, you can transport a LSMW project in full (you can not select the objects you want). With this method, the project will be transported as any other SAP object in a transport order. LSMW -> Extras -> Create change request

Program variants

If you have several program variants in a development system that you want to transport, use the following method to transport them:
Execute program 'RSTRANSP' (via se38) and inform the program and/or variant names (you can transport variant of several programs in one shot).

Layout In some transactions, one can save layout of the screen (sort, filter, ... criteria).

These layouts can be transported: In the required transaction, when your layouts have been saved, go to Settings -> Layout -> Layout Management. Select the desired layouts and go to Layout -> Transport... There you can add your layouts in existing TO or create a new one.

Database data

In some unusual cases, you might have to transport data of a SAP table.
Go to transaction SE16, select your entries and go to Table entry -> Transport entries. It's only possible for some tables...
If you cannot do it that way,you have to create a Workbench transport order with transaction SE10. When created, click on it, go in menu Request/task -> Object list -> Display object list.

Go in modification mode and add a new line with:

PgmID = R3TR
Obj = TABU
Object name = Name of your table

Double-click on the created line and, depending on your need, put '*' in the key field or double-click on it and select the key you need to transport.

Queries

Queries, datasets and user groups can be exported/imported between the systems using the Program RSAQR3TR.

Report template (ALV variants)

There is a button or somewhere in the menu Change/Select/Save/Manage Layout.
Go to Manage Layout, than Layout menu/ Transport.

SAPSCRIPT Files Transport

Use the program RSTXSCRP to upload and Download the SAPSCRIPT files to different systems

Transport SAPSCRIPT

Use the Program RSWBO052 to create the Transport Request for a SAPSCRIPT, In the Selection screen of the program, give R3TR – FORM – Give the Form name and press Execute button, it will ask the Development Class and the transport Request No.

Standard texts

Standard texts used in SAPScript(created with transaction SO10) can be included in transport orders. You have to create a Workbench transport order with transaction SE10. When created, click on it, go in menu Request/task -> Object list -> Display object list. Go in modification mode and add a new line with:

PgmID = R3TR
Obj = TEXT
Object name = TEXT,,ST,

Example :
R3TR / TEXT / TEXT,YMM_MEDRUCK_MAIN_16_EC,ST,F

SAP ABAP XML XSLT with ABAP

Create ABAP coding

At first we create the internal table TYPES and DATA definition, we want to fill with the XML data. I have declared the table "it_airplus" like the structure from XML file definition for a better overview, because it is a long XML Definition (see the XSD file in the sample ZIP container by airplus.com)

*the declaration
TYPES: BEGIN OF t_sum_vat_sum,
a_rate(5),
net_value(15),
vat_value(15),
END OF t_sum_vat_sum.

TYPES: BEGIN OF t_sum_total_sale,
a_currency(3),
net_total(15),
vat_total(15),
vat_sum TYPE REF TO t_sum_vat_sum,
END OF t_sum_total_sale.

TYPES: BEGIN OF t_sum_total_bill,
net_total(15),
vat_total(15),
vat_sum TYPE t_sum_vat_sum,
add_ins_val(15),
total_bill_amount(15),
END OF t_sum_total_bill.TYPES: BEGIN OF t_ap_summary,
a_num_inv_det(5),
total_sale_values TYPE t_sum_total_sale,
total_bill_values TYPE t_sum_total_bill,
END OF t_ap_summary.TYPES: BEGIN OF t_ap,
head TYPE t_ap_head,
details TYPE t_ap_details,
summary TYPE t_ap_summary,
END OF t_ap.DATA: it_airplus TYPE STANDARD TABLE OF t_ap
...
...
*call the transformation
CALL TRANSFORMATION ZFI_AIRPLUS
SOURCE xml l_xml_x1
RESULT xml_output = it_airplus
.

SAP ABAP Create XSLT program

There are two options to create a XSLT program:

  1. Tcode: SE80 -> create/choose packet -> right click on it | Create -> Others -> XSL Transformation
  2. Tcode: XSLT_TOOL

For a quick overview you can watch at the SXSLTDEMO* programs.

In this example we already use the three XSLT options explained later.
As you can see we define a XSL and ASX (ABAP) tags to handle the ABAP and XML variables/tags. After "" we create the XML_OUTPUT tag, but in this case we also could speak about a container. In fact the XML_OUTPUT tag comprise the structure of the internal table "it_airplus" which where moved by the CALL TRANSFORMATION in the report.

See the whole XSLT program here: Snippets:XSLT sample to encode, decode XML file

"http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">

"INVOICES_BTM">
"http://www.sap.com/abapxml" version="1.0">


for-each select="INVOICE_BTM">


"head" select="INVOICE_HEAD" />
"$head/@LANGUAGE" />
"$head/@DIRECT_DEBIT_QUALIFIER" />
"$head/INVOICE_DATE"/>

"number" select="$head/INVOICE_NUMBER" />
"$number/NUMBER"/>
"$number/EXTENSION"/>
"$number/SEQUENCE"/>

"$head/CREDIT_DEBIT_QUALIFIER"/>
"$head/CREDIT_DEBIT_LABEL"/>
"$head/BILLING_CURRENCY"/>
"$head/BASE_CURRENCY"/>
"$head/DUE_DATE"/>


"inv_parties" select="$head/INVOICE_PARTIES" />

"payee" select="$inv_parties/PAYEE" />
"$payee/PARTYCODE"/>

"address" select="$payee" />

for-each select="$address/ADDRESSLINE">
"."/>
for-each>
"INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/POST_CODE"/>
"INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/CITY"/>
"INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/STATE_CODE"/>
"INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/COUNTRY_CODE"/>
"INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/COUNTRY"/>


...
...

"summary" select="INVOICE_SUMMARY" />
"$summary/@NUMBER_OF_INVOICE_DETAIL" />

for-each select="$summary/TOTAL_SALE_VALUES">

"total_sale_values" select="$summary" />
"$total_sale_values/@CURRENCY"/>
"$total_sale_values/NET_TOTAL"/>
"$total_sale_values/VAT_TOTAL"/>

for-each select="INVOICE_SUMMARY/TOTAL_SALE_VALUES/VAT_SUMMARY">

"vat_sum" select="$total_sale_values/VAT_SUMMARY" />
"$vat_sum/@RATE" />
"."/>
"."/>
for-each>


for-each>



"INVOICE_SUMMARY/TOTAL_BILLING_VALUES/NET_TOTAL"/>
"INVOICE_SUMMARY/TOTAL_BILLING_VALUES/VAT_TOTAL"/>


"INVOICE_SUMMARY/TOTAL_BILLING_VALUES/VAT_SUMMARY/@RATE" />

for-each select="INVOICE_SUMMARY/TOTAL_BILLING_VALUES/VAT_SUMMARY/NET_VALUE">
"."/>
for-each>
for-each select="INVOICE_SUMMARY/TOTAL_BILLING_VALUES/VAT_SUMMARY/VAT_VALUE">
"."/>
for-each>



"INVOICE_SUMMARY/TOTAL_BILLING_VALUES/ADDITIONAL_INSURANCE_TOTAL"/>


"INVOICE_SUMMARY/TOTAL_BILLING_VALUES/TOTAL_BILLING_AMOUNT"/>







for-each>

SAP ABAP XSLT options

Here are the relevant XSLT elements in order of you could need it in your own program. For a good XSLT reference look at W3Schools.com - reference. In a XSLT program it is also possible to to write comments with the standard HTML commentfunction "- your comment here ->".
">

to catch the value from the element/attribute and move it to the ABAP variable


"INVOICE/PARTNER/ADDRESS/street" />

">

use this element to make loops over your XML Tags, maybe if you have more than one XML tag (street) in your XML-File

for-each select="INVOICE/PARTNER/ADDRESS/street">
"." />
for-each>

">

create a variable for access to the XML element. It is just a nice shortcut. Note that you can close this XSL element it self, look at the slash before the >

"var1" select="the_xml_element" />

continuative the "for-each" element you can write it like this:

"address" select="INVOICE/PARTNER/ADDRESS" />for-each select="$address/street">
"." />
for-each>

SAP ABAP XML sample file

We take the sample file from Airplus. You can load the sample ZIP container by Airplus at: airplus.com -> products -> pay -> airplus electronic billing -> XML.

"1.0" encoding="ISO-8859-1"?>


"text/xsl" href="invoice_btm.xsl" ?>
"http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="invoice_btm.xsd">

"DE" DIRECT_DEBIT_QUALIFIER="NO">
20040112

0306299999
0
0

R
Rechnung
EUR
"1.00000">EUR
20040201


LASG

"1">Lufthansa AirPlus Servicekarten GmbH
"2">Postfach 1552
63235
Neu-Isenburg
D
Deutschland



122000201089999
DTA9999

"1">Test Company GmbH
"2">Frau Verthika Kaur
"3">Frankfurter Str. 9
63233
Oberursel



TEST


"1" TYP="HOTEL">

122000201089999
Test Company GmbH


Steigenberger Mannheimer Hof
Augustaanlage 4 - 8
Mannheim
114216731


XX9823483
20031230

20031230
20040108
no
"1.00000">
EUR
235.55
88.33
980.50
"16.00">
616.16
016.32

"32.00">
632.32
032.48



845.25
135.25
980.50
0.00
980.50
"11.00">
111.11
011.22

"22.00">
222.22
022.33

"33.00">
333.33
033.44


"5">
"1">
"1.00000">
180.17
28.83
209.00
"16.00">
180.17
28.83



20031211
00255999
00204999
V
"1">Restaurant Avalon Getränk
"2">Rechnung#000400010999

20031211
20031212
9



"2">
"1.00000">
172.41
27.59
200.00
"16.00">
172.41
27.59



20031211
00255999
00204999
V
"1">Restaurant Avalon Speisen
"2">Rechnung#000400010999

20031211
20031212
9



"3">
"1.00000">
95.26
15.24
110.50
"16.00">
95.26
15.24



20031211
00255999
00204999
V
"1">Restaurant Avalon Getränk
"2">Rechnung#000400010999

20031211
20031212
9



"4">
"1.00000">
25.00
4.00
29.00
"16.00">
25.00
4.00



20031212
00255999
00204999
V
"1">Restaurant Avalon Getränk
"2">Rechnung#000500009999

20031211
20031212
9



"5">
"1.00000">
372.41
59.59
432.00
"16.00">
372.41
59.59



20031220
00255894
00204401
V
"1">Tagespauschale
"2">12.12.03

20031211
20031212
9






"00001">
"EUR">
845.25
135.25
"16.00">
845.25
135.25

"15.00">
745.15
035.15



845.25
135.25
"16.00">
845.25
135.25

980.50


SAP ABAP User Profile Parameters

This function enables you to make specific system settings for specific users.

Editing User Parameters

  1. Choose System => User profile => Own data.
    The Maintenance screen appears.
  2. Choose the Parameters tab page.

Some useful user parameters along with explaination of valid values :

Parameter ID Parameter Value Short Description
ADDRESS_SCREEN 004 Country specific address layout - 001 = Europe; 004 = US
BUK
Company code
CAC
Controlling area
EKG
Purchasing group
EKO
Purchasing organization
EVV
Sales price calculation: Sales price determination sequence
FWS
Currency unit
GR8 X Local file Download path
GR9 X Local file Upload path
KGK
Vendor account group
LE_SHP_DEL_MON_LISTT
Delivery Monitor: List Type
LIV
Sales price calculation: list variant
NDR X Print via output control in MM - Inventory management
RBU
Reference Company Code
SCL "X" = Lower; "" for Upper; "G" for Key word Upper Upper/Lower case in source code
SD_SWU_ACTIVE X Activate Workflow Box
SXV
SAPconnect administration
VKO
Sales organization
VTW
Distribution channel
WLC X X XX X Workflow: User-specific settings

Note:
Table TPARA details the available Parameter IDs.

SAP ABAP Report Tree Using SARP and SERP

Applies to:

SAP R/3 4.6C and more- SERP, SARP.

Document Available Here

Archives