Documente Academic
Documente Profesional
Documente Cultură
Rajagopalan
ABAP General
ABAP currently stands for Advanced Business Application Programming; however the original meaning
was Allgemeiner Berichtsaufbereitungsprozessor, which is German for "generic report preparation
processor" A different explanation is Anfänger Basteln An Programmen, which is german for "beginners
tinker with programs"
There are three types of internal tables in ABAP, standard table, sorted table, and hashed table.
SAP Memory is a global memory area which all sessions within a SAPgui have access to. This allows for
passing data between sessions. The SET PARAMETER ID and GET PARAMETER ID statements are
used to manipulate the SAP Memory.
ABAP Memory is a memory area which all programs in the call stack within the same internal session can
access. The EXPORT and IMPORT statements are used here.
24/Oct/2007 1 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
Load-of-Program
Initialization
At Selection-Screen
At Selection-Screen on
At Selection-Screen on block
At Selection-Screen output
At Line-Selection
At User-Command
Start-of-Selection
End-of-Selection
Top-of-Page
End-of-Page
They are the same, except SELECT-OPTIONS will provide an interface on the selection screen for the
user to input data.
In regard to internal tables, header lines and the OCCURS extension are obselete. These are actually not
allow in the OO context. The correct way to define internal tables and work areas are to use a TYPE
statement to define the structure and the use a DATA statement to define the internal table and work
area.
OCCURS n is obsolete in OO Context and it is advisable to use INITIAL SIZE instead. The difference
between the two is that OCCURS n allocates memory to store specified number of rows in the internal
table and also creates a header line, whereas INITIAL SIZE allocates memory for the specified number of
rows without creating the header line.
24/Oct/2007 2 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma
seperated format then download this internal table using the Function Module GUI_DOWNLOAD.
TYPE-POOLS:truxs.
DATA: BEGIN OF itab OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF itab.
DATA: itab1 TYPE truxs_t_text_data.
SELECT
vbeln
posnr
UP TO 10 ROWS
FROM vbap
INTO TABLE itab.
24/Oct/2007 3 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Use the function module SAP_CONVERT_TO_XLS_FORMAT to download the internal table to an excel
file.
24/Oct/2007 4 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
You can use the Function module ALSM_EXCEL_TO_INTERNAL_TABLE to read the Excel file into the
internal table of type alsmex_tabline. From this internal table you can fill the target internal table.
LOOP AT itab.
CASE itab-col.
WHEN '0001'.
it_upload-field1 = itab-value.
WHEN '0002'.
it_upload-field2 = itab-value.
24/Oct/2007 5 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
WHEN '0003'.
it_upload-field3 = itab-value.
AT END OF row.
APPEND t_upload.
CLEAR t_upload.
ENDAT.
ENDLOOP.
How can I define my own F4 Input help processing for a field on the selection screen?
You can use the event AT SELECTION-SCREEN ON VALUE REQUEST FOR <fieldname> for defining
your own input help for selection screen fields.
PARAMETER: p(10).
Use the Function Module SPELL_AMOUNT to convert the integer into text.
The single quote character(') in character strings do not preserve white spaces at the end whereas the "`"
character preserves white spaces as it is.
Eg.:
24/Oct/2007 6 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
How can I set the initial values for SELECT OPTIONS at the start of the program?
In the event INITIALIZATION you could set the initial values for the selection screen fields. For SELECT
OPTIONS you should fill the SIGN, OPTION, LOW, HIGH fields.
Eg: Set the date field with starting day of the month to last day of the month.
INITIALIZATION.
s_date-sign = 'I'.
s_date-option = 'BT'.
date+6(2) = '01'.
s_date-low = sy-datum.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = sy-datum
IMPORTING
last_day_of_month = s_date-high
EXCEPTIONS
day_in_no_date = 1.
APPEND s_date.
I am using a SELECT query on a database table. Since the number of records in the table is very
large, the program dumps due to insufficient memory. How can I solve this?
In this case you could use the PACKAGE SIZE addition in the SELECT query to process in limited
amount of data, thus avoiding the memory overloads.
Eg:
SELECT *
FROM <table>
INTO TABLE itab
PACKAGE SIZE <n>.
24/Oct/2007 7 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
IF sy-subrc EQ 0.
*" Process the n records
ENDIF.
ENDSELECT.
"Macro definition
DEFINE add_macro.
sum = *&1 + &2*.
END-OF-DEFINITION.
START-OF-SELECTION.
add_macro 10 20.
WRITE sum.
SAPlink is an opensource community project that makes it easy to share ABAP developments between
programmers. It provides the ability to easily distribute and package custom objects.
ABAP Debugging
In transaction SM50 (process overview), you can select a background process and choose
Program/Mode -> Program -> Debugging from the menu.
An alternative workaround, which allows you to step into a particular piece of code is to place a piece of
code in a endless DO-ENDDO, where you can change a variable to step out of the DO at a particular
point in your code. This allows you to hold the process at that point and debug it from SM50 as described
above. An implementation of this exists in function module C160_HOLD_FOR_DEBUG, which will enter
the endless loop if a particular environment variable is set, thereby allowing you to control its behaviour.
(Further instructions are found in the comments in subroutine INC14Z_HOLD_FOR_DEBUG of include
LC14ZFCB).
24/Oct/2007 8 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
You can do this only after the job has finished execution. This will simulate the exact background scenario
with the same selection screen values as used in the job and sy-batch set to 'X'.
Use SM37 to get list of jobs , type 'JDBG' in the command line ( no '/' ), put the cursor on the job
and press ENTER
You are in debug mode now. Step through SAP program (press F7 couple of times) until you get
to code you need.
You can use the same techniques as described in How do I debug background Processes? above.
Both options are available from the menu in debugging. Choose Settings -> System/Update Debugging to
activate either before proceeding.
Why does it give a dump when I put a break-point in between SELECT and ENDSELECT?
A breakpoint in SELECT loops can cause an exception through loss of the database cursor. The reason
for this is that during debugging a database commit is triggered and hence the cursor is lost.
Approach 1:
Approach 2:
[FUNCTION]
Command=/H
Title=Debugger
Type=SystemCommand
Drag and drop this file to the modal window to set debugging on.
ALV
ALV stands for ABAP List viewer, although it is more recently reffered to as SAP List Viewer. It is a
technology for easy creation of report output, which provides a lot of functionality, like sorting, summation
etc., with very little programming effort.
24/Oct/2007 9 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
There are several function modules, the most common being REUSE_ALV_LIST_DISPLAY, which
provides for a simple list from one table of data. See function group SALV for a list of function modules.
(Note that these functions are not officially released by SAP for customer use, but are widely used).
ABAP Dictionary
Tables
Views
Data Elements
Structures
Table Types
Type Groups
Domains
Search Helps
Lock Objects
Transparent Tables
Pooled Tables
Cluster Tables
24/Oct/2007 10 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
The MANDT field of the table specifies whether the table is client independent or not.
Cluster tables and Pooled tables have many to one relationship with the underlying database.
A table pool corresponds to a table in the database in which all records from the pooled tables assigned
to it are stored. Several logical data records from different cluster tables can be stored together in one
physical record in a table cluster.
A pooled table cannot have the name having more than 10 characters.
All the key fields of the pooled table must be of character data type.
In pooled tables, the maximum length of the key field/data fields should not exceed the length of
varkey/vardata of the pool respectively.
In cluster table the records having the same key are stored in a single key in the cluster.
If there is an overflow of the data records a continuation record is created with the same table key.
The Table has a physical storage of data whereas views do not have physical storage of data.
The view is derived from one or more tables which is created only with the required fields from the
database table(s). It can also be created with table inner joins and specifying conditions for data retrieval.
No. You can use only projection view or database view in your ABAP program.
The Table Maintenance Generator is used to create table maintenance program to add, modify or delete
records in the database table. This can be accessed using transaction SE54 or in SE11 using the menu
Utilities->Table Maintenance Generator.
Single step: Only overview screen is created i.e. the Table Maintenance Program will have only one
screen where you can add, delete or edit records.
Two step: Two screens namely the overview screen and Single screen are created. The user can see the
key fields in the first screen and can further go on to edit further details.
24/Oct/2007 11 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
How do you activate the database table after making changes to it?
After making changes to the table, inorder to reflect the changes go to transaction SE14 and Choose Edit
and then choose Activate and Adjust Database.
The programs are stored in the table TADIR and the development class packages in TDEVC.
I have recently added a few fields to a custom table. But I don't get these fields in the table
maintenance program?
You have to delete and recreate your own existing table maintenance program to see your new fields.
Whenever you need to create new records in the database table use INSERT. Whenever using INSERT
be sure that a duplicate entry having the same values for the primary key fields are not present. Else it
may throw a dump.
When you use MODIFY it makes a check for the matching key field values. If present it modifies the
matching record, else it creates a new record in the database table.
Go to transaction SE11, open your database table. Choose the menu, Goto->Indexes to create index.
Give your index name and choose the fields of the table. Be careful, an additional index may vanish with
the next upgrade or hotpackage.
The Check Table is the dependent table to which the relationship is defined using foreign keys. The
contents of the check table field are shown in the input help for the referenced field.
The Value table is the table attached to a field at the domain level, where the entry to the field can be only
from the value table. They are not used in the Input Help.
The Domain specifies the Technical attributes of the field such as the data type, length and the value
range.
The data element is an elementary type defining the description/text for the field when displaying on the
screen and Parameter ID.
When I create new entries in the table the field values are always in Uppercase. How do I get the
data with mixed case?
The reason for this is that the Domain for the field in the table might have Lowercase checkbox
unchecked. Check the Lowercase checkbox to preserve the case of your data.
24/Oct/2007 12 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
What is the need of reference table and reference field in Currency/Quantity fields?
The reference table and reference field are the fields which specify the currency key or Unit of Measure.
Suppose if the user specifies a currency amount say 1000$, the currency amount field would indicate the
amount 1000 and the currency key indicates that the currency specified is in Dollars.
SAPScript
You can create Boxes in the SAPScript using the BOX command specifying the x,y co-ordinates and the
width and the height
BOX XPOS '0' CM YPOS '0.5' CM WIDTH '9.2' CM HEIGHT '3.5' CM FRAME 8 TW
In the Paragraph Format tab, create a new paragraph format. In the "Tabs" Tab, enter the tab position
and the alignment for the fields.
You can create standard texts using the transaction SO10. Then to insert these standard texts in the
SAPScript choose the menu, Insert->Text->Standard and choose the standard text that you want to
choose.
Alternatively, you can display standard texts in your SAP Scripts using the command:
INCLUDE ZSTEXT OBJECT TEXT ID ST LANGUAGE EN
24/Oct/2007 13 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
I have created a script in language DE. Now I need to translate it to EN. How could I do this?
Use the Function Module RKD_WORD_WRAP to wrap the text and use this for output.
<C1>&vbeln&</>
where C1 is the character format created and vbeln is the variable for which the barcode is to be
created.
In the transaction SE71, enter the Form name and choose the menu, Utilities->Copy from client to copy
SAPScripts from one client to another.
24/Oct/2007 14 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
Enclose the text that you want to prevent page-break in PROTECT... ENDPROTECT
SAPscript will ensure that each line of this text is printed together on the same page.
/: PROTECT
* Text
* Within
* The same page
/: ENDPROTECT
You can use the SET SIGN command to output the leading sign at the left or right.
&DATE& Currentdate
&DAY& Day
&MONTH& Month
&YEAR& Year
&HOURS& Hours
24/Oct/2007 15 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
&MINUTES& Minutes
&SECONDS& Seconds
&PAGE& Page
&SPACE& Blank
&ULINE& Underline
I have a smartform which works fine in DEV. After trasnsporting it to PROD, there is no Function
module generated for this smartform. As a result my program dumps in PROD?
The Smartform that is created in the Development may not have the same name in the Production server.
So it is always advised to use the Function Module SSF_FUNCTION_MODULE_NAME to get the
Function Module name by passing the Smartform name.
24/Oct/2007 16 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
In the CALL FUNCTION of the Smartform Function Module, set the output options parameter to set the
printer name.
The output options is of the type SSFCOMPOP which contains the field TDDEST. Set the TDDEST field
to your default printer name.
How can I make the Smartforms to display a print preview by default without displaying the popup
for print parameters?
control-preview = 'X'.
control-no_open = 'X'.
control-no_close = 'X'.
control-no_dialog = 'X'.
control-device = 'PRINTER'.
control_parameters-no_dialog = 'X'.
control_parameters-no_open = 'X'.
control_parameters-no_close = 'X'.
OUTPUT_OPTIONS-TDDEST = 'PRINTER NAME'.
24/Oct/2007 17 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
OUTPUT_OPTIONS-TDNOPRINT = 'X'.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Screen Painter
In ABAP code (PBO/PAI), you have to use SALV class to create the list in the container of dynpro.
It is much more effective than to use the type Pool SLIS and function REUSE_ALV_GRID_DISPLAY
For example, you can then properly connect the screens with levels of different details or make fields of
the list seizable by the users.
What is a BADI?
What is a BADI?
BADI stands for Business Add-In. These are like user exits but are implemented using ABAP Objects.
More information can be found here
24/Oct/2007 18 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
ST05 is the SQL Trace transaction and can be used to measure the performance of the select statements
of the program. SE30 is the Runtime Analysis transaction and can be used to measure the application
performance. It also gives some tips on how to improve the performance through efficient code.
One of the best tools for static performance analyzing is Code Inspector (SCI). There are many options
for finding common mistakes and possible performance bottlenecks.
1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
3. Use as much index fields as possible from left to right in your WHERE statement
4. Either enable buffering in your database table or create Indexes to speed up the query.
5. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
6. Avoid using nested SELECT statement, SELECT within LOOPs.
7. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
8. Avoid using SELECT * and Select only the required fields from the table.
9. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure
to sort the internal table before binary search.
10. Avoid nested loops when working with large internal tables.
11. Use assign instead of into in LOOPs for large internal tables
12. When in doubt call transaction SE30 and use the examples and check your code
What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?
SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there
are more matching rows for the given condition.
SELECT ... UP TO 1 ROWS retrieves all the matching records and applies aggregation and ordering and
returns the first record.
Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using
SELECT ... UP TO 1 ROWS since it uses low memory and has better performance.
When using FOR ALL ENTRIES the number of matching records is restricted to the number of records in
the internal table. If the number of records in the database tables is too large then join would cause
overheads in performance.
BDC
How do I record a Batch Input session for later playback and analysis?
What are the commands available in a batch input session?
24/Oct/2007 19 of 20
http://abaplearner.blogspot.com
QB-3 M. Rajagopalan
How do I record a Batch Input session for later playback and analysis?
Using transaction SHDB it is possible to record transactions as well as create skeleton programs that
contain all the necessary code for creating batch input sessions.
Note: These commands are only available in foreground mode! They are also accessible via the menu
under System -> Services -> Batch Input.
24/Oct/2007 20 of 20
http://abaplearner.blogspot.com