My Book
My Book
My Book
Data Dictionary
Table definition.
Display table definition.Go to Transaction Code SE11, enter table name (example:
SFLIGHT), click Display.
You can assign the data type, length and short text in different ways:
1. You directly assign the field a data type, field length (and if necessary decimal
places) and short text in the table definition.
2. You can assign the field a data element. The data type, field length (and decimal
places) are determined from the domain of the data element. The short description of
the data element is assigned to the field as a short text. In above case, all fields refer
to data element (Field CARRID refer to date element S_CARR_ID). We will explain
about data element in Type Definition below.To toggle beetween data element /
direct type method click button "Data Element/Direct type".
To display table content, click Utilities -> Table Contents -> Display, then click
Execute (F8).
Type DefinitionWe can define type as reusable object. It means that when we create
new table, we can create field refer to data element. These type attributes can
either be defined directly in the data element or copied from a domain. Data element
is an object where we put short text for field, and domain is an object where we
store information like data type (CHAR, NUMC) and its length. We can see relation
beetween table field, data element and domain in figure below.
Benefit of using this hierarchy is when you change domain, for example change field
length, it will change all field length for all table using this domain.
To open a data element, go to TCode SE11, select data type, and enter data element
name (for example S_CARR_ID). You will see in this screen that data element
S_CARR_ID refer to domain S_CARR_ID ( in this case, data element and domain have a
same name), and also display field label tab, it contain short text that appear in short
text of table field.
To open a domain, go to TCode SE11, select domain, and enter domain name (for
example S_CARR_ID), you will see that this domain have CHAR (character) data type
and field length 3.
My First program
I assume you already familiar with data dictionary. For an example, we have a table
"SFLIGHT", with following fields:
1. CARRID (Airline carrier ID)
2. CONNID (Flight connection Id)
3. FLDATE (Flight date).
4.SEATSMAX (Maximum capacity).
We wan to create a report that can be filtered based on Airline carrier ID and Flight
connection Id.
Go to transaction code SE38 (SAP Menu->Tools>ABAP Workbench->Development->ABAP
Editor), enter program name with prefix Z, for example ZTEST0001, then choose
"Create" button.
Then, enter title for program, and choose 1 "Executable Program" for program type. If
screen input for development class appear, click "Local Object".
TABLES: sflight.
2. Selection screen
4. Write data
LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.
The result :
Here is the complete program:
REPORT ZTEST0001 .
*Data Declaration
tables: sflight.
*Selection Screen
SELECT-OPTIONS s_carrid FOR sflight-carrid.
SELECT-OPTIONS s_connid FOR sflight-connid.
*Get Data
SELECT * FROM sflight
WHERE carrid IN s_carrid AND
connid IN s_connid.
t_report-carrid = sflight-carrid.
t_report-connid = sflight-connid.
t_report-fldate = sflight-fldate.
t_report-seatsmax = sflight-seatsmax.
APPEND t_report.
ENDSELECT.
IF sy-subrc NE 0.
WRITE 'Data not found'.
ENDIF.
*Write Data
LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.
Data types:
C (character)
N (numeric)
D (date)
T (Time)
X (byte / hexadecimal)
I (integer)
P (packed number)
F (floating point number)
Internal Table
Internal tables provide a means of taking data from a fixed structure and storing it in
working memory in ABAP. The data is stored line by line in memory, and each line has
the same structure. In ABAP, internal tables fulfill the function of arrays.
DATA: BEGIN OF t_report OCCURS 10,
field1 LIKE customer-customerno,
field2 TYPE I,
field3(20) TYPE C,
END OF t_report.
In above example, we define internal table contatin 3 fields, field-1 refer to field
customer-customerno, field-2 type Integer, field-3 type character with field length 10
character. OCCURS 10 means that it reserve 10 line of memory at initialization, in run
time memory will expand automatically when data exceed the limit.
TUESDAY, JULY 17, 2007
Internal Table is a main part of ABAP programming. In ABAP, internal tables fulfill the
function of arrays. It is a data that have a structure and could contain more than one
row.
3. Modify
3.1. Modify in a LOOP.
LOOP AT inttab.
MOVE ... TO inttab-field1.
MODIFY inttab.
ENDLOOP.
4. Insert / Append
APPEND inttab.
5. Delete
Delete have variant similar to modify, delete in a loop, delete by index, and delete by
criteria.
What is BDC
BDC ( Batch Data Communication ) is used for uploading mass data into SAP system. In
SAP system BDC also referred to batch input or data tranfer.
Typical Uses
Typical uses of batch input include the one-time import of data from a legacy system
into a newly installed R/3 System. Another typical use is for periodic transfers of data
from external systems or legacy systems that are still in use into SAP.
Background of BDC
To ensure data consistency in SAP system, we must not update SAP data directly from
ABAP program. We must upload data through similar program flow compared to
manual input by user. SAP provide this by BDC. BDC works by simulating the user input
from transactional screen via an ABAP program. This means that you do not bypass
any of the standard SAP consistency checks, authorisations, update conjunction
tables, etc.
How it works
Data input entered by user simulated in BDC by data packet. The transaction then
started using this internal table as the input and executed in the background.
To accomodate you to build data packet, SAP provide BDC recording in tcode SHDB.
Do following action:
1. Go to tcode SHDB
2. click "New recording", enter recording name to identified your record, and TCode
to be recorded.
3. You will enter recording mode of the transaction, simulate action you want to
perform in this transaction
4. At the end it will result internal table ready to upload to data transfer methods
(Call transaction or BDC sessions).
After internal table created then we pass this to data transfer methods. There are
two alternatives of data transfer methods, using Call Transaction or BDC session.
Call transaction performed by calling command ‘Call Transaction’. ABAP program
must do the error handling based on returning table from call transaction command.
It is used for real-time interfaces and custom error handling & logging features. This is
suitable when processing sequential update, it means, next data will depend on
previous data.
In BDC Sessions, the ABAP program creates a session with all the transactional data,
and this session can be viewed, scheduled and processed (using Transaction SM35) at
a later time. The latter technique has a built-in error processing mechanism too.
To go to ABAP debugging mode, activate ABAP debuggin then press enter. In ABAP
report, usually debuggin mode started from selection screen, just before we enter
execute command (F8).
In ABAP debugger we can view and change data. It also allow you to execute your
program line by line.
FRIDAY, AUGUST 10, 2007
Event in ABAP report determine process flow of a program. The events are triggered
depended on the way the output is generated. They begin after event keyword and
end when the next event reached.
Event keyword:
INITIALIZATION.
Occurs when report initialized.
We can use it to check user authorization or prepare output for selection screen.
AT SELECTION-SCREEN OUTPUT :
Occurs each time selection screen about to generated.
We can use it to modify selection screen, for example hide / unhide parameter.
AT SELECTION-SCREEN.
Occurs each user command in selection screen. we can use it to perform checking on
user input.
START-OF-SELECTION
Occurs after the standard selection screen has been processed.,
data is read in this event.
END-OF-SELECTION
Occurs after start-of-selection.
TOP-OF-PAGE
Occurs when a new page starts.
Use it for write report header.
END-OF-PAGE
Occurs when a page ends.
Use it for write report footer.
AT LINE-SELECTION
Occurs when the user double-click on report.
AT USER-COMMAND
Occurs when the user push toolbar button.
*http://abap-gallery.blogspot.com
TABLES: sflight.
INITIALIZATION.
*begin initialization
MOVE sy-datum TO p_datum.
*end initialization
AT SELECTION-SCREEN.
*begin at selection-screen
MESSAGE I888(sabapdocu) WITH 'At selection-screen'.
IF p_check = 'X'.
MESSAGE E888(sabapdocu) WITH 'Clear checkbox'.
ENDIF.
*end at selection-screen
AT SELECTION-SCREEN OUTPUT.
*begin at selection-screen output
MESSAGE I888(sabapdocu) WITH 'At selection-screen output'.
*end at selection-screen output
START-OF-SELECTION.
*begin start-of-selection.
MESSAGE I888(sabapdocu) WITH 'start-of-selection'.
SELECT * FROM sflight.
MOVE sflight-carrid TO t_report-carrid.
MOVE sflight-connid TO t_report-connid.
APPEND t_report.
ENDSELECT.
*end start-of-selection.
END-OF-SELECTION.
*begin end-of-selection.
MESSAGE I888(sabapdocu) WITH 'end-of-selection'.
FORMAT COLOR col_normal.
DO 30 TIMES.
LOOP AT t_report.
WRITE / t_report-carrid.
WRITE t_report-connid.
ENDLOOP.
ENDDO.
*end end-of-selection.
TOP-OF-PAGE.
FORMAT COLOR col_heading.
WRITE 'This is header'.
END-OF-PAGE.
FORMAT COLOR col_total.
WRITE 'This is footer'.
AT LINE-SELECTION.
WRITE: / 'Cursor Row:', sy-curow.
WRITE: / 'Cursor Col:', sy-cucol.
Screen Painter
Screen Painter is an ABAP Editor tools allowed us to create dialog screen. Dialog
screen usually created as a screen to catch user input. It can be accessed by tcode
SE51.
2. Flow logic
Flow logic control flow of program. The event block is introduced by the
corresponding keyword statement, and it concludes either when the next block is
introduced, or at the end of the program.
There are four event blocks, each of which is introduced with the screen keyword
PROCESS:
PROCESS BEFORE OUTPUT.
...
PROCESS AFTER INPUT.
...
PROCESS ON HELP-REQUEST.
...
PROCESS ON VALUE-REQUEST.
Flow logic structured on event, in above example we can see there are two event
involved, "process before output" (PBO) and "process after input" (PAI).
PBO processed before the screen is displayed. It allow us to define toolbar and title,
positioning the cursor, showing and hiding fields and changing field attributes
dynamically.
PAI processed after user command (double click, push button). It is allow us to
validate user input, and determine next process based on user command.
In flow logic, we only define module name to define program flow, to create "real
code", double click on module name to create it, then write program in it.
3. Layout Editor
We use layout editor to place screen element in screen layout. There are two modes
in editing layout: Graphical and alphanumeric. Both modes offer the same functions
but use different interfaces. In graphical mode, you use a drag and drop interface
similar to a drawing tool. In alphanumeric mode, you use your keyboard and menus. It
is easier to work in graphical mode, to toggle beetween this mode, in SE51 go to:
Utilities->Settings: in screen painter tabs check graphical layout editor.
Layout editor containing this tools:
i. Element pallete
On left screen you will find list of element (textbox, label, checkbox) you can use.
Drag and drog element to put it on screen.
ii. Name & Text
Aftef put element on screen, write its name and text (in textbox, text will set default
value).
iii. Attributes Window
Double click the element to display its attributes, or select it then click :Goto-
>Secondary window->attributes. For example, in textbox element, we can set its
length, read only mode, in this window.
iv. Dictionary/program field.
If we want to create a field refer to field in data dictionay or field already declared in
program, use this menu to create text field with the same type compared to its
referral.
4. Element list.
Element list shown all element in screen. We rarely use this menu, because it easier
to maintain element in layout editor.