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"
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
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.
fld1(10) type c,
fld2(10) type c,
end of ttab.
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.
END OF t_msg.
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.
END OF itab.
SELECT
vbeln
posnr
UP TO 10 ROWS
FROM vbap
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = itab
CHANGING
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
EXPORTING
filename = 'C:\TEMP\test.txt'
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.
RECEIVING
ip_address = ip_addr
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
DATA terminal LIKE USR41-TERMINAL.
EXPORTING
USERNAME = sy-uname
IMPORTING
TERMINAL = terminal.
EXPORTING
i_filename = p_file
TABLES
i_tab_sap_data = itab.
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.
field1(12),
field2(12),
field3(12),
END OF t_upload.
filename = filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 3
i_end_row = 65535
TABLES
intern = itab.
LOOP AT itab.
CASE itab-col.
WHEN '0001'.
it_upload-field1 = itab-value.
WHEN '0002'.
it_upload-field2 = itab-value.
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).
BREAK-POINT.
EXPORTING
AMOUNT = v_int
LANGUAGE = SY-LANGU
IMPORTING
IN_WORDS = words
WRITE words-word.
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.:
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.
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>
IF sy-subrc EQ 0.
ENDIF.
ENDSELECT.
"Macro definition
DEFINE add_macro.
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).
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.
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.
ABAP Dictionary
• What types of objects can be created in the ABAP Dictionary?
• What types of tables can be created in the ABAP Dictionary?
• Which field differentiates a table from client-dependent and client-independent?
• What is the difference between Pooled tables and Cluster tables?
• What is the difference between Database tables and Views?
• What are the different types of Views?
• Can I use all the views in the ABAP program ?
• What is Table Maintenance Generator?
• What is One step, two step in Table Maintenance Generator?
• How do you activate the database table after making changes to it?
• In which table are the programs stored in?
• I have recently added a few fields to a custom table. But I don't get these fields in the
table maintenance program?
• What is the difference between INSERT and MODIFY?
• How do I create index on a database table?
• What is the difference between Check Table and Value Table?
• What is the difference between Domain and Data Elements?
• When I create new entries in the table the field values are always in Uppercase. How do I
get the data with mixed case?
• What is the need of reference table and reference field in Currency/Quantity fields?
Tables
Views
Data Elements
Structures
Table Types
Type Groups
Domains
Search Helps
Lock Objects
Transparent Tables
Pooled Tables
Cluster Tables
The MANDT field of the table specifies whether the table is client independent or not.
What is the difference between Pooled tables and Cluster tables?
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.
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.
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
• How do I create Boxes in SAPScript?
• How do I set tabs between the fields in display?
• How do I create standard texts for the scripts?
• How can I debug my SAPScript?
• I have created a script in language DE. Now I need to translate it to EN. How could I do
this?
• How can I Word Wrap the text being displayed in SAPScript?
• How can I display barcodes in SAPScripts?
• How can I print logos in SAPScripts?
• How can I copy SAPScripts from one client to another?
• How can I trigger new page in SAPScripts?
• How can I prevent page-break in the message that is to be displayed?
• How can I set the position of the leading sign to left/right?
• What are the various text formatting options in SAPScript?
• Frequently Used System Variables in 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.
Alternatively, you can display standard texts in your SAP Scripts using the command:
INCLUDE ZSTEXT OBJECT TEXT ID ST LANGUAGE EN
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.
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
/: ENDPROTECT
You can use the SET SIGN command to output the leading sign at the left or right.
&DAY& Day
&MONTH& Month
&YEAR& Year
&HOURS& Hours
&MINUTES& Minutes
&SECONDS& Seconds
&PAGE& Page
&SPACE& Blank
&ULINE& Underline
Smartforms
• How can I insert symbols in Smartforms?
• 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?
• How can I make the Smartforms to choose a printer name by default?
• How can I make the Smartforms to display a print preview by default without displaying
the popup for print parameters?
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.
EXPORTING
formname = 'ZSMARTFORM'
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
ENDIF.
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
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-TDNOPRINT = 'X'.
EXPORTING
output_options = output_options
control_parameters = control
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
Screen Painter
To use ALV in dynpro, create only a container in the dynpro.
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
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?
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.