ABAP FULL Material
ABAP FULL Material
COURSE MATERIAL
of
SAP - ABAP
Chained statements.If consecutive statements have identical part at the beginning, then ABAP allows you to chain these
statements into a single statement. First write the identical part once and then place a colon (:). Then write the remaining
parts of the individual statements separated by commas.Normal Statements:
WRITE 'Hello'.
WRITE 'ABAP'.
Chained Statement:
Comments. If you want to make the entire line as comment, then enter asterisk (*) at the beginning of the line.
If you want to make a part of the line as comment, then enter double quote (―) before the comment.
On the logon pad select the system you want to login to and press log on button.
This is SAP easy access screen. All the tools required by ABAP developer is under the node Tools.
SAP Transaction code is a short cut key attached to a screen. Instead of using SAP easy access menu we can also
navigate to a particular screen in SAP by entering the transaction code (T-code for short) in the command field of the
standard toolbar.
T CODE DESCRIPTION
This is the ABAP editor‘s initial screen. Enter the name of the program you want to create and press create. All the
customer programs must begin with ―Y‖ or ―Z‖.
In the next popup screen(Program attributes) enter the title for your program, select Executable program as type and
press save.
This is the screen where you can write the ABAP code.
If there are any syntax errors, it ill be displayed at the bottom of the screen as shown above. Correct the errors and again
check the syntax.
Successful syntax check message will be displayed in the status bar. Then activate( Ctrl + F3 ) the program.
Data Type describes the technical characteristics of a Variable of that type. Data type is just the blue print of a
variable.
Predefined ABAP Types
DATA TYPE DESCRIPTION DEFAULT LENGTH DEFAULT VALUE
C Character 1 ‗‗
N Numeric 1 0
D Date 8 00000000
T Time 6 000000
I Integer 4 0
P Packed 8 0
F Float 8 0
Use the keywords BEGIN OF and END OF to create a structured data type.
Constants
Constants are used to store a value under a name. We must specify the value when we declare a constant and the value
cannot be changed later in the program.
ABAP Variables
ABAP Variables are instances of data types. Variables are created during program execution and destroyed after
program execution.
Use keyword DATA to declare a variable.
While declaring a variable we can also refer to an existing variable instead of data type. For that use LIKE instead
ofTYPE keyword while declaring a variable.
Structured Variable
Similar to structured data type, structured variable can be declared using BEGIN OFand END OF keywords.
We can also declare a structured variable by referring to an existing structured data type.
ABAP system variables are accessible from all ABAP programs. These fields are filled by the runtime environment.
The values in these fields indicate the state of the system at any given point of time.
The complete list of ABAP system variables is found in the SYST table in SAP. Individual fields of the SYST structure can
be accessed either using “SYST-” or “SY-”.
Output
Basic Operations
Assigning values to ABAP variables
Use „=‟ or MOVE keyword to assign a value to a variable.
DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.
a = 10.
b = a.
MOVE 20 TO c.
MOVE c TO d.
WRITE:/ a, b, c, d.
Output
DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.
*Using Keywords
add 10 to a.
subtract 5 from b.
multiply c by 2.
divide d by 2.
Output
DATA: a TYPE i,
b TYPE i.
a = 10 + 20.
b = 20 - 10.
clear: a, b.
Output
Control Statements
To control the flow of the ABAP program use the following statements.
IF – Branching Conditionally
IF statement – The code between IF and ENDIF is executed only if the condition is true.
DATA: a TYPE i VALUE 10. " We can assign a value in the declaration
IF a > 5.
WRITE:/ 'Condition True'.
ENDIF.
Output
IF-ELSE statement – The code between IF and ELSE is executed if the condition is true, the code
between ELSE andENDIF is executed if the condition is False.
Output
Output
CASE a.
WHEN 3.
WRITE:/ a, 'Equals', 3.
WHEN 4.
WRITE:/ a, 'Equals', 4.
WHEN OTHERS.
WRITE:/ 'Not Found'.
ENDCASE.
Output
Loops
DO 5 TIMES.
WRITE sy-index. " SY-INDEX (system variable) - Current loop pass
ENDDO.
Output
Output
DO 5 TIMES.
IF sy-index = 2.
CONTINUE.
ENDIF.
WRITE sy-index.
ENDDO.
Output
DO 5 TIMES.
CHECK sy-index < 3.
WRITE sy-index.
ENDDO.
Output
DO 10 TIMES.
IF sy-index = 2.
EXIT.
ENDIF.
WRITE sy-index.
ENDDO.
Output
WRITE / result1.
WRITE / result2.
Output
If the the concatenated string fits in the result string, then the system variable sy-subrc is set to 0. If the result has to be
truncated then sy-subrc is set to 4.
Output
If all target fields are long enough and no target fields has to be truncated then sy-subrc is set to 0, else set to 4.
SEARCH – Searches for a sub string in main string. If found then sy-subrc is set to 0, else set to 4.
Output
REPLACE – Replaces the sub string with another sub string specified, in the main string. If replaced successfully then sy-
subrc is set to 0, else set to 4.
Output
DDL part consist of commands like CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX etc. ABAP
Dictionary handles DDL part of SQL.
So ABAP Dictionary is used to create and manage data definitions (metadata). ABAP Dictionary is used to create
Tables, Data Elements, Domains, Views, Lock Objects etc.
In order to get the field labels use the menu in the ABAP editor GOTO->Text Elements->Selection Texts.
The Text ( Field Label ) will be automatically read from the Data Element. Now save, activate, go back and run the
program again.
Now place the cursor on the input field and press F1 key to get the documentation from the data element.
Actually this field label and documentation are maintained in the Data Element MATNR.
So if we want to create a table with two fields as ―FirstName‖ and ―SecondName‖, then only one domain is sufficient with
data type as ―CHAR‖ and length say 20. But we need two different data elements in order to display different field labels
and documentation for both the fields.
Create a Domain
Select the Domain radio button, enter the the name of the domain that you want to create and press create.
Enter the short description. Place the cursor in the data type and press F4 to get the list of SAP data types.
Enter the number of characters. Enter the decimal places if it applicable to data type that you have selected. Save and
activate the domain.
Select the Data type radio button, enter the name of the data element and press create.
Enter short description. Assign a domain to the data element. Press field label tab to maintain the field labels for the data
element.
Enter the field labels, Save and activate the data element.
Every table has a unique name and consists of rows and columns. The number of columns in a table is fixed but can have
any number of rows.
ABAP dictionary handles the DDL part of SQL in SAP. Go to ABAP dictionary (SE11) to create a SAP table. Enter the
name of the table to be created and press enter.
Enter a proper short description for the table and maintain delivery class as ‗A‘(Application Table). Now press on Fields
tab to maintain the fields of the table.
Enter the fields of the table and maintain the proper data elements for the table fields. You can use the standard data
elements or you can create your own data elements.
Maintain the primary key and press save. To maintain the technical attributes of table like tablespace, size etc. press the
Technical attributes button on application toolbar.
After creating a table you can test it by maintaining a couple of entries in the table. Follow the below mentioned procedure
to maintain entries in the table. But this procedure must be used only in testing or development environment not in
production environment.
Display the table in ABAP Dictionary(SE11). Use the menu path Utilities->Table Contents->Create Entries.
If this menu path is disabled then go to Delivery and Maintenance tab and
enter ―Display/Maintenance Allowed‖ in ―Data Browser/Table View Maint.‖ listbox.
Save and activate the table. Then go back to menu path Utilities->Table Contents->Create Entries.
Observe the message in the status bar. To display the values in the table go to Utilities->Table Contents->Display
In the selection screen enter the selection criteria if you want to filter the records you want to display and press execute.
A primary key is a field or group of fields that uniquely identify a record in a table. Primary key fields cannot be NULL and
cannot contain duplicate values.
If you want to link two tables, then primary key of one table will be added to another table where primary key of first table
will be become the foreign key of second table.
Consider the following two tables.
Department Table
01 Computers
02 Physics
03 Electronics
Employee Table
If you want to link department table and employee table, then add the primary key of department table i.e. Department_ID
to employee table. Department_ID becomes the foreign key of employee table and Department table becomes the check
table.
The main purpose of the foreign key is data validation. This will not allow entering a Department_ID in the employee table
that is not there in the department table. For example if you try to create a record in employee table with Department_ID
as ‘04′, it will throw an error.
Creation of a Foreign Key in SAP table
The purpose of the foreign key is to validate the data that is being entered into a table by checking entries in a check
table. Foreign keys are checked by the front end user interface only and it is not checked if you issue a direct a SQL
statement to update the database.
Follow the steps given below to create a foreign key in SAP table.
Step 1: Open the table in Data Dictionary (SE11) for which you want to create a foreign key. Select the field for which you
want to create the foreign key and press Foreign Keys button.
Step 2: In the popup window enter the check table name and press Generate proposal button.
Step 3: The system proposes the foreign key relation based on the domain. Check that the foreign key relationship
proposed by the system is correct and press copy.
Foreign key is created, now save and activate the table. To check the foreign key go to menu path Utilities->Table
Contents->Create Entries.
Observe the error message in the status bar. The user interface does the foreign key validation before creating the
entries.
OPEN SQL
Open SQL is a set of ABAP statements that performs operations like reads, modifies or deletes data in the SAP database.
Open SQL is independent of the database system, so the syntax of the open SQL is uniform for all the databases
supported by SAP.
All open SQL statements are passed to the database interface. The DB interface converts the open SQL to native SQL
and passes it on to the database.
All Open SQL statements fill the following two system fields:
SY-SUBRC – After every Open SQL statement, the system field SY-SUBRC contains the value 0 if the operation was
successful, a value other than 0 if not.
SY-DBCNT – After an open SQL statement, the system field SY-DBCNT contains the number of database lines
processed.
Reading Data using Open SQL
SELECT is the open SQL statement to read the data from the database. The general syntax for SELECT statement is as
follows.
SELECT <result>
INTO <target>
FROM <source>
[WHERE <condition>]
CLAUSE DESCRIPTION
INTO <target> Determines the target area into which the selected data is to be placed
FROM <source> Specifies the database table from which the data is to be selected
WHERE <condition> specifies which lines are to be read by specifying conditions for the
selection
WRITE:/1 'Emp ID' color 5,9 'Name' color 5,17 'Place' color 5,
27 'Phone' color 5,39 'Dept' color 5.
Report Output
In Reading Data using Open SQL we have read all the rows from the database. What if we want to read only certain
records that match a certain criteria? Then we need to use the where clause of the SELECT statement.
Report Output
What if we want to select only certain columns from the database table instead of all the columns? Then we need to
specify the field list(field names) in the SELECT statement instead of specifying ‗*‘.
Report Output
Only columns ID, PHONE and DEPT_ID were read from the database.
To select a single record from the database use SELECT SINGLE instead of SELECT statement. SELECT SINGLE picks
the first record found in the database that satisfies the condition in WHERE clause. SELECT SINGLE does not work in
loop, so no ENDSELECT is required.
Report Output
INSERT is the open SQL statement to add values to the database table. First declare a work area as the line structure of
database table and populate the work area with the desired values. Then add the values in the work area to the database
table using INSERT statement.
UPDATE is the open SQL statement to change the values in the database table. First declare a work area as the line
structure of database table and populate the work area with the desired values for a specific key in the database table.
Then update the values for the specified key in the database table using UPDATE statement.
We can also change certain columns in the database table using the following syntax
DELETE is the open SQL statement to delete entries from database table. First declare a work area as the line structure
of database table and populate the work area with the specific key that we want to delete from the database table. Then
delete the entries from the database table using DELETE statement.
We can also multiple lines from the table using the WHERE clause in the DELETE statement.
MODIFY is the open SQL statement to insert or change entries in the database table. If the database table contains no
line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added. If the
database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that
is, the line is changed.
Since there was no entry with the key 6, a new entry was added to the table.
Since there was an entry with the key 6, the values in the existing record were modified
A Termination The message appears in a dialog box, and the program terminates. When the user has
confirmed the message, control returns to the next-highest area menu.
E Error Depending on the program context, an error dialog appears or the program
terminates.
I Status The message appears in a dialog box. Once the user has confirmed the message, the
program continues immediately after the MESSAGE statement.
S Error The program continues normally after the MESSAGE statement, and the message is
displayed in the status bar of the next screen.
W Warning Depending on the program context, an error dialog appears or the program
terminates.
X Exit No message is displayed, and the program terminates with a short dump. Program
terminations with a short dump normally only occur when a runtime error occurs.
We can issue a status message as follows. Status message will be displayed in the status bar. After the message is
displayed the program continues after the MESSAGE statement.
Information message will be displayed in a dialog box. Once the user has confirmed the message, the program
continues immediately after the MESSAGE statement.
Error message in report programs will be displayed in the status bar and when the user press enter, the program
terminates.
Termination Message appears in a dialog box, and the program terminates. When the user has confirmed the message,
control returns to the next-highest area menu.
Instead of hardcode the message text in the program we can maintain the message text in text symbols. In order to
maintain text symbols use the menu path Goto->Text Elements->Text Symbols in ABAP editor.
We know that we can use MESSAGE statement to issue a message in ABAP. What if we want to issue the same
message in more than one program? Do we need to hard code the same message text or maintain the same text symbols
in all the programs? The answer is NO. Instead of maintaining the same message text in all the programs maintain the
message in a Message class and use it in all the programs.
What is a Message Class?
Message Class is a like a container which holds a number of different messages. Each message in the message class is
identified with unique message number. So when you call a message in a ABAP program, you need to specify the
message class and message number.
How to create a Message Class?
First go to t-code SE91 i.e. Message Maintenance, enter the name of the message class and click on create button.
MESSAGE s000(ztest).
Output
In the above code, the message number, message class and message type are specified in the MESSAGE statement.
We can also specify the message class in the REPORT statement as shown below, so that we can skip the message
class in the MESSAGE statements of the program.
REPORT zmessages
MESSAGE-ID ztest
MESSAGE s000.
In the above message ―&‖ is the placeholder. At runtime the placeholders (&) will be replaced by the variable values
specified in the MESSAGE statement.
Output
The values ―XYZ‖ and ―1000‖ replaces the placeholders in the actual message.
An Internal table is a temporary table gets created in the memory of application server during program execution and gets
destroyed once the program ends. It is used to hold data temporarily or manipulate the data. It contains one or more rows
with same structure.
An internal table can be defined using the keyword TABLE OF in the DATA statement. Internal table can be defined by
the following ways.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.
After the last APPEND statement in the above program, internal table ‗IT‘ has the following 3 entries. But the internal table
values are not persistent i.e. the internal table and its values are discarded once the program ends.
ID NAME
1 JOHN
2 JIM
3 JACK
Usually internal tables are used to hold data from database tables temporarily for displaying on the screen or further
processing. To fill the internal table with database values, use SELECT statement to read the records from the database
one by one, place it in the work area and then APPEND the values in the work area to internal table.
After ENDSELECT the internal table GT_EMPLOYEE contains all the records that are present in table ZEMPLOYEE.
Using INTO TABLE addition to SELECT statement we can also read multiple records directly into the internal table
directly. No work area used in this case. This select statement will not work in loop, so no ENDSELECT is required.
We can insert one or more lines to ABAP internal tables using the INSERT statement. To insert a single line, first place
the values we want to insert in a work area and use the INSERT statement to insert the values in the work area to internal
table.
The first INSERT statement without INDEX addition will simply add the record to the end of the internal table. But if we
want to insert the line to specific location i.e. if we want to insert it as second record then we need to specify 2 as the
index in the INSERT statement.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 3.
gwa_student-name = 'JACK'.
INSERT gwa_student INTO TABLE it.
SKIP.
WRITE:/ 'After using Index addition' COLOR 4.
gwa_student-id = 4.
gwa_student-name = 'RAM'.
INSERT gwa_student INTO it INDEX 2.
Output
INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO TABLE <itab2>.
OR
INSERT LINES OF <itab1> [FROM <index 1>] [TO <index 2>] INTO
<itab2> INDEX <index>.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student,
it2 TYPE TABLE OF ty_student,
it3 TYPE TABLE OF ty_student,
it4 TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 3.
gwa_student-name = 'JACK'.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
INSERT gwa_student INTO TABLE it.
SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT3' COLOR 4.
gwa_student-id = 4.
gwa_student-name = 'RAJ'.
INSERT gwa_student INTO TABLE it4.
SKIP.
WRITE:/ 'Inserting only lines 2 & 3 of IT to IT4 at 2' COLOR 4.
The last INSERT statement in the above program inserts the 2nd and 3rd line from IT at index 2 in IT4, so the new lines
inserted becomes the 2nd and 3rd line in IT4.
Output
MODIFY is the statement to change single or multiple lines in an internal table. Use the INDEX addition to change a single
line. If we use the INDEX addition and the operation is successful, SY-SUBRC will be set to zero and the contents of the
work area overwrites the contents of the line with the corresponding index.
Instead of changing all the values of a row we can specify the fields we want to change by specifying the fieldnames in the
TRANSPORTING addition.
We can also use the above MODIFY statement without INDEX addition inside LOOP. Inside LOOP if we do not specify
the INDEX, then the current loop line will be modified.
We can use the WHERE clause to change single or multiple lines. All the lines that meet the logical condition will be
processed. If at least one line is changed, the system sets SY-SUBRC to 0, otherwise to 4.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 3.
gwa_student-name = 'JACK'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 20.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 22.
INSERT gwa_student INTO TABLE it.
gwa_student-id = 9.
gwa_student-name = 'TOM'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 30.
*Change specific columns of row 4 with work
area values by
*using TRANSPORTING addition
MODIFY it FROM gwa_student INDEX 4
TRANSPORTING place.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place,
gwa_student-age.
ENDLOOP.
SKIP.
WRITE:/ 'Values in IT after MODIFY using
WHERE Clause' COLOR 4.
gwa_student-place = 'Mumbai'.
*Change multiple rows using WHERE clause
MODIFY it FROM gwa_student TRANSPORTING
place
WHERE place =
'Bangalore'.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18
'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name,
gwa_student-place,
gwa_student-age.
ENDLOOP.
Output
We can also use the above DELETE statement without INDEX addition inside LOOP. Inside LOOP if we do not specify
the INDEX, then the current loop line will be deleted.
We can use the WHERE clause to delete single or multiple lines. All the lines that meet the logical condition will be
deleted. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.
With WHERE clause we can also specify the lines between certain indices that we want to delete by specifying indexes in
FROM and TO additions.
SORT is the statement to sort an ABAP internal table. We can specify the direction of the sort using the additions
ASCENDING and DESCENDING. The default is ascending.
We can also delete the adjacent duplicates from an internal table by using the following statement.
COMPARING ALL FIELDS is the default. If we do not specify the COMPARING addition, then the system compares all
the fields of both the lines. If we specify fields in the COMPARING clause, then the system compares only the fields
specified after COMPARING of both the lines. If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to
4.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.
gwa_student-id = 1.
gwa_student-name = 'JOHN'.
gwa_student-place = 'London'.
gwa_student-age = 20.
APPEND gwa_student TO it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.
gwa_student-id = 4.
gwa_student-name = 'ROB'.
gwa_student-place = 'Bangalore'.
gwa_student-age = 22.
APPEND gwa_student TO it.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.
*SORT by name
SORT it BY name DESCENDING.
*Delete duplicates
SORT it.
DELETE ADJACENT DUPLICATES FROM it.
Output
We can exit out of LOOP/ENDLOOP processing using EXIT, CONTINUE and CHECK similar to all other LOOPS.
We can also initialize the internal table using FREE, CLEAR and REFRESH statements. CLEAR and REFRESH just
initializes the internal table where as FREE initializes the internal table and releases the memory space.
*--------------------------------------------------------------*
*Data Types
*--------------------------------------------------------------*
TYPES: BEGIN OF ty_student,
id(5) TYPE n,
name(10) TYPE c,
place(10) TYPE c,
age TYPE i,
END OF ty_student.
*--------------------------------------------------------------*
*Data Declaration
*--------------------------------------------------------------*
DATA: gwa_student TYPE ty_student.
DATA: it TYPE TABLE OF ty_student.
DATA: gv_lines TYPE i.
gwa_student-id = 2.
gwa_student-name = 'JIM'.
gwa_student-place = 'New York'.
gwa_student-age = 21.
APPEND gwa_student TO it.
*Initialize IT
CLEAR it.
SKIP.
WRITE:/ 'Values in IT before initializing' COLOR 4.
WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5,
37 'Age' COLOR 5.
LOOP AT it INTO gwa_student.
WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place,
gwa_student-age.
ENDLOOP.
*If no records are processed inside LOOP, then SY-SUBRC <> 0
IF sy-subrc <> 0.
WRITE:/ 'No records found.'.
ENDIF.
SKIP.
*We can also use IS INITIAL to check any records found in IT
IF it IS INITIAL.
WRITE:/ 'No records found in IT.'.
ENDIF.
Output
The code between AT LAST and ENDAT is executed only during the last loop pass. So it is used to write the totals or
some report footers.
AT FIRST.
WRITE:/ 'Start of Loop'.
WRITE:/ 'Flight Details'.
WRITE:/ 'Airline Code' COLOR 5,14 'Connection No.' COLOR 5,
29 'Departure City' COLOR 5, 44 'Arival City' COLOR 5.
ULINE.
ENDAT.
WRITE:/ gwa_spfli-carrid,14 gwa_spfli-connid,
29 gwa_spfli-cityfrom,44 gwa_spfli-cityto.
AT LAST.
ULINE.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.
Output
Between AT FIRST and ENDAT the work area will not contain any data. The default key fields are filled with asterisks(*)
and the numeric fields are filled with zeros. The ENDAT restores the contents to the values they had prior to entering the
AT FIRST. Changes to the work area within AT FIRST and ENDAT are lost. The same applies for AT LAST and ENDAT.
Output
AT NEW and ENDAT is used to detect a change in the value of the field between the loop passes. The field that is
specified in AT NEW is called control level. The code between AT NEW and ENDAT will be executed during the first loop
pass and every time the value of the control level changes or any other field left to the control level changes. Between AT
NEW and ENDAT all the fields in the work area that are right to the control level are filled with zeros and asterisks.
Similarly The code between AT END OF and ENDAT will be executed during the last loop pass and every time the value
of the control level changes or any other field left to the control level changes.
Output
In AT NEW and AT END OF event blocks SUM statement finds all the rows within the control level and calculates the
totals of numeric fields that are right to the control level and places the totals in the corresponding fields of work area.
SUM.
WRITE:/ 'Total',58 gwa_spfli-distance.
WRITE:/ 'End of Loop'.
ENDAT.
ENDLOOP.
Output
Output
Below table summarizes the differences between AT NEW and ON CHANGE OF statements.
AT NEW ON CHANGE OF
Values in the fields to the right of Values in the fields to the right of
control level contains asterisks control level contains original
and zeros. values.
MODULARIZATION IN ABAP
Modularization is breaking down the application code into smaller units, so that it is easy to maintain. Suppose if we want
to implement the same logic like adding two numbers in several places of the same program, then write the logic inside a
modularization unit and call the modularization unit where ever we want to add two numbers.
Even if we want to declare the same variables in multiple programs or use the same logic in different programs then code
the common part in the modularization unit and use it in different programs.
ABAP Macros
If we want to reuse the same set of statements more than once in a program, we can include them in a macro. We can
only use a macro within the program in which it is defined. Macro definition should occur before the macro is used in the
program.
...
END-OF-DEFINITION.
*Macro definition
DEFINE print.
write:/ 'Hello Macro'.
END-OF-DEFINITION.
Output
Output
Include programs are not standalone programs and cannot be executed independently. They can be used as a container
for ABAP source code. They are used to organize the ABAP source code into small editable units which can be inserted
at any place in other ABAP programs using the INCLUDE statement. Include programs can be used in different programs.
The include statement copies the contents of the include program into the main program.
Include programs have no parameter interface and they cannot call themselves.
While creating the INCLUDE program using the ABAP editor choose program type as "I" i.e. INCLUDE program in the
program attributes.
REPORT zmain_program.
INCLUDE zinclude_data.
INCLUDE zinclude_write.
Output
ABAP Subroutine
Subroutines are procedures that we define in an ABAP program and can be called from any program. Subroutines are
normally called internally, i.e. called from the same program in which it is defined. But it is also possible to call a
subroutine from an external program. Subroutines cannot be nested and are usually defined at the end of the program.
...
ENDFORM.
Example Program.
PERFORM sub_display.
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Inside Subroutine'.
ENDFORM. " sub_display
Output
Subroutines can call other subroutines and may also call themselves. Once a subroutine has finished running, the control
returns to the next statement after the PERFORM statement.
EXIT statement can be used to terminate a subroutine unconditionally. The control returns to the next statement after the
PERFORM statement.
PERFORM sub_display.
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Exit Statement'.
EXIT.
WRITE:/ 'After Exit Statement'. " This will not be executed
ENDFORM. " sub_display
Output
CHECK statement can be used to terminate a subroutine conditionally. If the logical expression in the CHECK statement
is untrue, the subroutine is terminated, and the control returns to the next statement after the PERFORM statement.
DO 2 TIMES.
PERFORM sub_display.
ENDDO.
*&---------------------------------------------------------------------*
*& Form sub_display
*&---------------------------------------------------------------------*
FORM sub_display.
WRITE:/ 'Before Check Statement'.
Output
Table: KNA1
Table: VBAK
Table: VBAP
Transaction codes:
Steps Action
1 SE37 (transaction code for Function-Builder)
2 On menu-bar , GoTo FunctionGroup CreateGroup
3 Function Group: ZmyGRP (give any name)
Short Description: my function group (enter any text)
4 click on continue(tick-mark)
5
LocalObject
6 Function Module: ZmyFUNC (give any name)
7 Create
8 Function Module: ZmyFUNC [see step-6]
Function Group: ZmyGRP [see step-3]
Short Description: my sample function (enter any text)
9 Save
** Import (TAB):
10 IMPORT(TAB)
Parameter names type associated type
X type i
Y type i
** Export (TAB):
11 EXPORT(TAB)
Parameter names type associated type
Z type i
** Source code (TAB):
12 SOURCE CODE(TAB)
…Enter the logic…
z = x + y.
13 Save , Check , Activate , Continue , Execute
14 Enter test data values for x , y
15 Execute
(1b) FUNCTION– Creation (WITH EXCEPTION)
Steps Action
1 SE37 (transaction code for Function-Builder)
2 On menu-bar , GoTo FunctionGroup CreateGroup
3 Function Group: ZmyGRP (give any name)
Short Description: my function group (give any description)
4 click on continue (tick-mark)
5 LocalObject
6 Function Module: ZmyFUNC (give any name)
7 Create
8 Function Module: ZmyFUNC, [see step-6]
Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyCallFunc (give any name)
3 Type: Executable Program
4 Save , LocalObject
5 Data: a type i, b type i, c type i.
(or)
Parameters: a type i, b type i.
Data: c type i.
a = 10. b = 5.
6 Place cursor where call-function code to be inserted.
Click on ‘Pattern’ to generate codes.
(select function name: ZmyFunc) *see ‘Function with exception’ step-6]
7 Continue
8 Exporting
X = a
Y = b
Importing
Z = c.
Write: / c.
9 Save , check, activate, Execute
(2a) FUNCTION – Creation (WITH TABLES)
Steps Action
Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyCallFunc
3 Type: Executable Program
4 Save, enter the following source codes
5 Tables: KNA1.
Data: cno type KNA1-kunnr.
Data: intab type KNA1 occurs 1 with header line.
cno = ‘1000’.
6 Click on ‘Pattern’ to generate function code at cursor position (select Function Name:
ZmyFunc) *see ‘Function with tables’ step-6]
7 Click on Continue (tick mark)
8 Exporting
custno = cno.
Tables
ITAB = intab.
Loop at intab.
Write: / intab-kunnr.
Endloop.
9 Save , check, activate, Execute
A) SALES ORDER
b) invoice
c) bill
d) purchase order
e) debit memo
f) credit memo
etc.
PROGRAM
Database
(Note: in general enterprise business more than 200+ business documents are used.)
ABAPer’s tasks:
Create Windows:
LOGO
HEADER
ADDRESS
MAIN (default )
FOOTER
Steps Action
1 SE71 (transaction code for Form-Painter)
2 Form: ZmySapScriptFORM (enter any name)
3 Create, Continue (tick mark) in pop up box
4 Description: my form (enter any text)
Translate: (Select radio-button) ‘Do not Translate’
5 Save, LocalObject
6 Click ‘Pages’ button (F6)
7 Page: Mypage (give any name)
8 Save
9 Next page: Mypage [see step-7]
Description: my page (enter any text)
** Pages: Create Windows:
10 Click on ‘Windows’ button (F7)
11 MAIN is default window
12 on menu-bar, EDIT CreateElement (or) (Shift+F6)
13 (Pop-up box to create LOGO window)
Window: LOGO
NOTE: in the ‘Name’ box, click icon at the right corner. Click on ‘Execute’(F8) to list out the
bitmap image names. Select any image. e.g. ‘ENJOY’. Click on ‘Copy’ (tick mark)
Continue(tick-mark)
53 Back(F3)
54 Dbl.click on ‘HEADER’ in the windows list box (or) select & rt-click choose (or) F2
55 Click on ‘Text Elements’ icon on top tool-bar (or F9)
56 (NOTE: write any text to appear in the header line e.g.)
LOGO
MAIN (created by default)
HEADER
FOOTER
Steps Action
1 SMARTFORMS (transaction code)
** Create Style:
2 Select radio-button, Style: ZmySmartSTYLE (enter any name)
3 Create
[ Screen divided into Left and Right panels ]
** Define Paragraph-Format:
4 On left-panel, Rt.-Click ParagraphFormat CreateNode
5 In the pop-up box, ParagraphFormat: P1 (enter any name e.g P1)
6 Enter (tick mark)
7 Description: my paragraph format (enter any text)
8 Font (TAB) : define font characteristics for ‘Paragraph format’
Font family:
Font size: 11
Font style: Bold
Color:
Underline:
** Define Character-Format:
9 On left-panel, Rt.-Click CharacterFormat CreateNode
10 In the pop-up box, CharacterFormat: C1 (enter any name e.g C1)
11 Enter (tick mark)
12 Description: my character format (enter any text)
13 Font(TAB) : define font characteristics for ‘Character format’
Font family:
Resolution: 100 (give any resolution, preferably 100DPI, dots per inch)
** Create window: HEADER:
26 On left-panel, Rt.-Click ‘%PAGE1 New page’
27 Create Window
28 Window: HEADER
Desccription: header window (enter any text or leave it blank)
(Press ‘ENTER’ key)
29 On left-panel, Rt.-Click ‘HEADER’
30 Create Text
(enter any text at the blinking cursor position, e.g. MY software technologies inc. USA)
** Create window: FOOTER:
31 On left-panel, Rt.-Click ‘%PAGE1 New page’
32 Create Window
33 Window: FOOTER
Description: footer window (enter any text or leave it blank)
(Press ‘ENTER’ key)
34 On left-panel, Rt.-Click ‘FOOTER’
35 Create Text
(enter any text at the blinking cursor position, e.g. YOUR future begins here)
** Define Window size, location:
&outtab-kunnr&
&outtab-land1&
&outtab-name1&
&outtab-ort01&
49 Save, Check, Activate, Test (F8)
50 Function module: is generated (e.g. /1BCDWB/SF00000024)
51 SingleTest (F8) , Execute (F8)
52 Output Device: LP01
53 Click on ‘Print Preview’ (F8) [to view the generated Form]
FORM: - Copy & Modify (STANDARD LAYOUT) [layout and print Program defined by SAP]
Steps Action
** view exising STANDARD Form-name:
1 NACE (transaction code to view Standard Layouts/applications)
2 Select any Application from the list e.g V1 (sales)
3 Click on ‘Output Types’ (F5)
4 On right panel, select BA00 (order confirmation)
5 On left panel, dbl. click on ‘Processing Routines’
6 Just remember the Form to modify (e.g. RVORDER01) from the right-side list
7 Go back to initial screen by pressing ‘Back’(F3) several times (normally 3 times)
** Copy the Form:
8 SE71 (transaction code for Form-Painter)
9 On menu-bar, UTILITIES COPY FROM CLIENT
10 Form Name: RVORDER01 [see step-6]
Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyPRG1 (give any name)
3 Create
4 Title: MY Form program (give any text)
Type: Executable Program
5 Save, ‘Local object’
** add following Sourse Codes:
6 REPORT ZMYPRG1.
Tables: KNA1.
Select-options: cno for KNA1-kunnr.
*-------------------------------
** insert function: OPEN_FORM:
7 Click ‘Pattern’ (or) Ctrl+F6 , Call function: OPEN_FORM , continue (tick mark)
8 (Un-comment the following 3 lines)
** SQL query:
9 (insert the following codes and place cursor after the last comment line)
*----------------------------------
Select * from KNA1 where kunnr in cno. [see step-4] (Note: not available in 4.6)
*---------------------------------
** insert function: START_FORM:
10 Ctrl+F6, Call function: START_FORM , continue (tick mark)
11 (Un-comment the following 5 lines)
EXPORTING
Form = ‘ZmySapScriptFORM’ *see ‘SAP script’ step-2]
Language = SY-LANGU
Start page = ‘Mypage’ *see ‘SAP script’ step-7]
Program = ‘ZmyPRG1’ [see step-2]
12 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: WRITE_FORM:
13 Ctrl+F6, Call function: WRITE_FORM , continue (tick mark)
14 (Un-comment the following 2 lines)
EXPORTING
Window = ‘ADDRESS’ *see ‘SAP script’ step-17]
15 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: WRITE_FORM:
16 Ctrl+F6 , Call function: WRITE_FORM , continue (tick mark)
17 (Un-comment the following 2 lines)
EXPORTING
Window = ‘MAIN’ *see ‘SAP script’ step-9]
18 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** insert function: END_FORM:
19 Ctrl+F6 , Call function: END_FORM , continue (tick mark)
20 (place cursor at the last line of program codes and add the following demarcation line)
*----------------------------------------
** END SELECT:
21 (place cursor at the last line and add the following codes..)
ENDSELECT.
*---------------------------------------
** insert function: CLOSE_FORM:
22 Ctrl+F6 , Call function: CLOSE_FORM , continue (tick mark)
23 Save
** Execute & Preview the Form:
24 Check , Activate , Execute (‘Direct processing’) F8
25 Cno: 1000 to 2000 (customer number: enter any range)
26 Execute (F8)
27 Output Device: LP01
28 Click on ‘Print preview’ *to display the Form output+
A) the most common use of LDBs is to read data from different database tables by linking them to executable ABAP
programs.
PRG 1
PRG 2 LDB
DATA BASE
PRG 3
instead of programs interacts directly with databases, they interacts with logical databases.
c) ldbs contain open sql statements that read data from the databases, so we there fore use sql statements in or
programs.
d) the ldb reads the program, stores in the program if necessary, and then passes them line by line to the application
program.
f) many tables in the r/3 system are linked to each other using foreign key relation ships.
h) logical databases read from database tables that are part of them structures.
- improving performance.
2* selections:.
the selections dfine a selection screen, which forms the user interface of the executable programs that use the logical
databases. it’s layout usually determined by a structure.
3* database program:
the data base program contains the abap statements used to read the data and pass it to the user of the logical database.
we need to define only structure, the rest of two (selections & database program) are auto-generated by the system.
Nodes:
KNA1
|--------- VBAK
|---------- VBAP
Steps Action
1 SE36 (transaction for LDB creation)
2 Logical database: ZmyLDB (give any name)
3 Create
4 (in the pop-up box)
Short text: (give any text)
5 Click on ‘Create’ icon, ‘Local object’
** define parent node KNA1:
6 (in the pop-up box)
Name of Root Node: KNA1
Text: customer master table (give any text)
Select radio-button, ‘Database Table’ : KNA1
Click on ‘Create’ icon
** create child node VBAK:
7 Structure(TAB)
Under ‘Node Name’,
Right-click KNA1 InsertNodes
8 (in the pop-up box)
nd
Node name: VBAK (2 level node name)
Text: sales order table (enter any text)
Hierarchically under: KNA1 (parent node, by default)
Select radio-button, ‘Database table:’ VBAK
9 Click on ‘Insert new node’ (or F5)
** create child node VBAP:
27 (NOTE: uncomment the following 3 lines only and put ‘.’ After cno)
Select * from kna1
Where kunnr in cno.
Endselect.
28 Save , Check , Activate , Continue (tick mark) , Back(F3)
** VBAK (SELECT statement):
29 Again double-click on ‘Include xxxxxxx VBAK’
30 (NOTE: uncomment the following 3 lines only and put ‘.’ After ono)
Select * from vbak
Where vbeln in ono.
Endselect.
31 Save , Check , Activate , Continue (tick mark) , Back(F3)
** VBAP (SELECT statement):
32 Again double-click on ‘Include xxxxxxx VBAP’
33 (NOTE: uncomment the following 3 lines only and put ‘.’ After vbak-vbeln)
Select * from vbap
Where vbeln = vbak-vbeln.
Endselect.
34 Save , Check , Activate , Continue (tick mark) , Back (F3)
Note: don’t click ‘Save’ again in the Node-Tree(KNA1, VBAK, VBAP) screen
** test newly created LDB and view data:
37 Select ‘Logical Database:’ ZmyLDB *see step-2] (displayed by default)
38 Click on ‘Test’ icon (F8) on tool-bar
39 cno: 1000 to 1001 (customer number, Enter values)
ono: ---- to ---- (order number, leave it blank)
40 Click on Execute (F8) on tool-bar
Note: it may take few minutes to display the LDB content
REPORTS:
b) using LDB
Steps Action
1 SE38
2 Program name: ZmyLDBPrg (give any name)
3 Create
4 Title: my LDB program (enter any text)
Type: Executable Program
Logical Database: ZmyLDB (which is already created) *see ‘create LDB’ step-2]
5 Save , ‘Local object’ , *write the following source codes..+
6 REPORT ZMYLDBPRG.
Nodes: KNA1, VBAK, VBAP.
*--- column headings
Write: /5 ‘cust no’,
20 ‘cust name’,
40 ‘country’,
60 ‘order no’,
80 ‘order value’,
90 ‘item no’.
Get KNA1.
Get VBAK.
Get VBAP.
*--- column/field contents
Write: /5 KNA1-kunnr color 6 inverse on,
20 KNA1-name1 color 4 inverse on,
40 KNA1-land1 color 3 inverse on,
SAP queries
ZGSRUSRGRP1
1
5
3 USER 1
QUERY 4 USER 2
USER 3
INFOSET USER 4
USER 5
USER 6
USER 7
USER 8
LOGICAL
DATABASE USER 9
DATABASE
DATABASE
REPORT: - SAP-QUERIES [report generation Tool] generates report without any ABAP coding.
Steps Action
1 SQ03 (transaction code) – create a usergroup
2 SQ02 (transaction code) – create a infoset
3 SQ03 (transaction code) – assign user and infoset to usergroup
4 SQ02 (transaction code) – assign usergroup to infoset
5 SQ01 (transaction code) – design the query layout , test/execute query
Steps Action
** create USERGROUP:
1 SQ03 (transaction code to create a usergroup)
2 User group: ZmyGrp (give any name)
3 Click ‘Create’
4 Short description: my group (enter any text)
5 Save , ‘Local object’ , Back
** create INFOSET:
6 SQ02 (transaction code to create a infoset)
7 Infoset: ZmyInfoset (give any name)
8 Create
9 Name: santanu’s infoset (give any text)
Authorization group: ZmyGrp [see step-2]
Select radio-button, ‘Logical Database’ : ZmyLDB
[see user defined table in LDB step-2]
10 Click on continue (tick mark)
11 New screen appears with TWO panels – Left and Right
** add Fields to FieldGroup: **
12 Select NODE ‘Customer Master Table’ from Right panel
13 In the Left panel , click on right-arrow icon beside ‘Customer Master Table KNA1’
14 right-click on field-name ‘Add field to field group’
(e.g. customerNumber KNA1-kunnr). And Follow the same procedure for other fields (KNA1-
name1, KNA1-land1, KNA1-ort01)
Note: Select the required fields
15 Select another NODE from right panel and follow the same procedure as mentioned above for
VBAK (fields: vbeln, erdat, netwr, kunnr) , VBAP (fields: posnr, arktx, werks, vbeln)
16 Save , ‘Local object’
17 On manu-bar, Click on ‘Generate’ icon (or shift-F6) to generate the infoset
18 Save , Back , click ‘Yes’ in the pop-up box , Back
** assign USER and INFOSET to USERGROUP:
19 SQ03 (transaction code to assign user and infoset to usergroup)
20 Click on ‘Assign Users & Infoset’
21 Users and Change authorization for query
User name: SAPUSER [in the top left box] (username while logging in)
22 Press ‘Enter’ , Save
23 Click on ‘Assign Infoset’ (F5)
24 Select the Infoset you have created ‘ZmyInfoset’ from the list *see step-7]
25 Save , Back , Back , Back
** assign USERGROUP to INFOSET:
Steps Action
1 SE38
2 Program name: ZmyALV (enter any name)
3 Create
4 Title: my report (enter any text)
Type: Executable Program
5 Save , ‘Local object’ , *enter the following source code+
6 REPORT ZMYALV.
REPORT: Hierarchial Sequential Report (using SELECT) [using 2 tables VBAK, VBAP]
Steps Action
1 SE38
2 Program name: ZmyHierALV (enter any name)
3 Create
4 Title: my report (enter any text)
Type: Executable Program
5 Save , LocalObject
6 REPORT ZMYHIERALV.
TYPE-POOLS: SLIS.
**--- constants
CONSTANTS: C_VBAK TYPE SLIS_TABNAME VALUE 'W_VBAK',
C_VBAP TYPE SLIS_TABNAME VALUE 'W_VBAP'.
**---- VBAP
W_FCAT-COL_POS = 1. “1st column
W_FCAT-FIELDNAME = 'POSNR'. “field name
W_FCAT-SELTEXT_M = 'ITEM NO'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------
W_FCAT-COL_POS = 2. “2nd column
W_FCAT-FIELDNAME = 'ARKTX'. “field name
W_FCAT-SELTEXT_M = 'ITEM DESC'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------
W_FCAT-COL_POS = 3. “3rd column
W_FCAT-FIELDNAME = 'WERKS'. “field name
W_FCAT-SELTEXT_M = 'PLANT CODE'. “column/field heading
W_FCAT-TABNAME = C_VBAP. “assign constant value
APPEND W_FCAT TO T_FCAT. “append work area value to internal table
*---------
IS_KEYINFO = W_KEYINFO
TABLES
T_OUTTAB_HEADER = T_VBAK
T_OUTTAB_ITEM = T_VBAP
10 Save , Check , Activate , Continue (tick mark)
11 Execute
12 Report is successfully generated.
(we can customize the report by selecting various icons on the tool-bar)
REPORT: Simple Interactive Report [demo without data]
Steps Action
1 SE38
2 Program name: ZmyInterReport (give any name)
3 Create
4 Short Desc: (write any text)
Type: Executable Program
5 Save , LocalObject , [enter the following source codes]
6 REPORT ZMYINTERREPORT.
*-- EVENT
Case SY-LSIND.
When ‘1’
Write: / ‘this is the second screen’ , SY-LSIND.
When ‘2’
Write: / ‘this is the third screen’ , SY-LSIND.
When others.
Write: / SY-LSIND.
Endcase.
7 Save , check , activate , continue
8 Execute
9 Double-click on the screen headings to move to the next level of screens
(upto 21 screens)
REPORT: Complex Interactive Report (using SELECT) [with hot-spot] with 3 tables KNA1, VBAK, VBAP. [using
selection screen for parameter input]
Steps Action
1 SE38
2 Program name: ZmyInterReportComplex1 (give any name)
3 Create
4 Title: my report (write any text)
Type: Executable Program
5 Save , LocalObject , [enter the following source codes]
6 REPORT ZMYINTERREPORTCOMPLEX1.
ULINE.
*--- column headings of table KNA1
Write: /5 ‘custno’,
20 ‘custname’,
40 ‘country’.
Hide KNA1-kunnr.
Endselect.
Case SY-LSIND.
When ‘1’. “1st level screen
Write: /30 ‘Sales order information list’.
ULINE.
*--- column headings of table VBAK
Write: /5 ‘order no’,
20 ‘order date’,
60 ‘order value’.
ULINE.
Hide VBAK-vbeln.
Endselect.
Endcase.
Case SY-LSIND.
When ‘2’. “2nd level screen
Write: /30 ‘Item information list’.
ULINE.
*--- column headings of table VBAP
Write: /5 ‘item no’,
21 ‘item description’,
61 ‘plant code’.
ULINE
Steps Action
1 SE38
2 Program name: ZmyComplexReport (give any name)
3 Create
4 Title: my report (write any text)
Type: Executable Program
5 Save , ‘Local object’ , *enter the following source codes+
6 REPORT ZMYCOMPLEXREPORT.
ULINE. "underline
*--- event
start-of-selection.
at end of kunnr.
sum.
write:/ 'sub total of order value' , 100 wtab-netwr.
endat.
endloop.
**---Event
end-of-page.
ULINE.
7 Save , check , activate , continue
8 Execute
9 Enter: Cno: 1000 to 1002
Cnt: DE (country code for Germany)
click ‘Execute’ F8
10 Report is generated with control breaks and sub-totals
Steps Action
w_itab-a = 10.
w_itab-b = 20.
c = w_itab-a + w_itab-b.
write: / c.
14 Save , check , activate , continue(tick mark)
15 Execute
ABAP DICTIONARY: create User Defined TABLE [ ZmyEMPt , ZmyDEPT ] see step-13,24
Steps Action
1 SE11
2 Select radio-button, ‘Data type:’ YmyTP , ‘Create’ (create data element to link 2 tables)
3 Select radio-button, ‘Data element’ , click on ‘Continue’ (tick-mark) in pop-up box
** DataType(TAB):
4 Short description: (enter any text)
DataType(TAB)
Select radio-button, ‘Built-in-type’
Data type: NUMC
Length: 10
** Field label(TAB):
6 Field label(TAB)
SCREEN: Simple Screen Program: (Executable Program) with inputBox, checkboxes, commandButton
Steps Action
1 SE38
2 Program: ZMYSCREEN (enter any name)
3 Create
4 Title: my screen program (enter any text)
5 Type: Executable Program
6 Save , LocalObject , continue
7 Enter the line call screen 100. after REPORT ZMYSCREEN
8 REPORT ZMYSCREEN.
CheckBox-1
Name: CB1
Text: SAP
CheckBox-2
Name: CB2
Text: ABAP
FctCode: EX2
17 Dbl. click on COMMAND-BUTTON (to enter properties)
PushButton
Name: CMD1
Text: EXIT
FctCode: EX
CASE SY-UCOMM.
WHEN 'EX'.
LEAVE PROGRAM.
WHEN 'EX1'.
IF CB1 = 'X'.
IO1 = 'SAP'.
ELSE.
IO1 = ' ' .
WHEN 'EX2'.
IF CB2 = 'X'.
IO1 = 'ABAP'.
ELSE.
IO1 = ' ' .
ENDIF.
ENDCASE.
26 Execute
SCREEN: Simple Screen Program: (Module Pool) with inputBox, checkboxes, commandButton
Steps Action
1 SE38
2 Program: ZMYSCREEN1 (enter any name)
3 Create
4 Title: (enter any text)
5 Type: Module Pool
6 Save, LocalObject, continue
7 Enter the line call screen 100. after PROGRAM ZMYSCREEN1.
8 PROGRAM ZMYSCREEN1.
CheckBox-1
Name: CB1
Text: SAP
FctCode: EX1
16 Dbl. click on 2nd CHECK-BOX (to enter properties)
CheckBox-2
Name: CB2
Text: ABAP
PushButton
Name: CMD1
Text: EXIT
FctCode: EX
CASE SY-UCOMM.
WHEN 'EX'.
LEAVE PROGRAM.
WHEN 'EX1'.
IF CB1 = 'X'.
IO1 = 'SAP'.
ELSE.
IO1 = ' ' .
ENDIF.
WHEN 'EX2'.
IF CB2 = 'X'.
IO1 = 'ABAP'.
ELSE.
IO1 = ' ' .
27 NOTE: you cannot Execute a ‘Module Pool’ program by clicking “Execute’ button.
You need to create a TRANSACTION-CODE to execute this program.
Transaction Code: creation
Steps Action
1 SE93
Transaction code: ZmyTrans1 (first letter must be Z or Y)
Create
Short text: (enter any text)
Select radio-button ‘Program and Screen (dialog transaction)’
Click ‘continue’ (enter)
Program: ZMYSCREEN1 (the module pool program name)
Screen number: 100 (same as module pool screen number)
Save, package: $TMP , localObject
Transaction code ZmyTrans1 is created
Enter ZmyTrans1 to execute the module pool program ‘ZMYSCREEN1’
Steps Action
1 REPORT ZSANSCREENPRG3 .
*REPORT demo_dynpro_tabcont_loop.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 101.
TABLES: demo_conn, spfli.
DATA: itab TYPE TABLE OF demo_conn,
fill TYPE i.
*&---------------------------------------------------------------------*
*& Module exit INPUT
ENDLOOP.
module exit.
** Layout:ctrl+F7
3 Table control
Name: FLIGHTS
Table-name: DEMO_CONN
Fileds:
CARRID
CONNID
CITYFROM
CITYTO
Steps Action
1 SE38
2 Program: zdemo_dynpro_tabstrip_local (enter any name)
3 Create
4 Title: (enter any text)
5 Type: Executable Program
6 Save
7
REPORT ZDEMO_DYNPRO_TABSTRIP_LOCAL.
mytabstrip-activetab = 'PUSH1'.
MODULE calculation.
CASE SY-UCOMM.
WHEN 'RADIO'.
IF ADD = 'X'.
ANS = NUM1 + NUM2.
mytabstrip-activetab = 'PUSH3'.
ENDIF.
ENDCASE.
ENDMODULE.
tabstrip control:
name: MYTABSTRIP
tab title: 3
(tab1)push-button:
name: PUSH1
text: Tab_page_1
fctCode: PUSH1
(tab2)push-button:
name: PUSH2
text: Tab_page_2
fctCode: PUSH2
(tab3)push-button:
name: PUSH3
text: Tab_page_3
fctCode: PUSH3
subscreen area(1):
name: SUB1
subscreen area(2):
name: SUB2
subscreen area(3):
name: SUB3
push-button:
name: BUTTON
text: Cont.
icon: ICON_OKAY
fctCode: OK
Text-field:
Name: TEXT1
Text: Subscreen 1
Text-field:
Name: LABEL1
Text: Number1:
Text-field:
Name: LABEL2
Text: Number2:
i/o-field:
Name: NUM1
i/o-field:
Name: NUM2
Text-field:
Name: TEXT2
Text: Subscreen 2
Radio-button:
name: ADD
text: Addition
fctCode: RADIO
Radio-button:
name: SUB
text: Subtraction
fctCode: RADIO
Radio-button:
name: MUL
text: Multiplication
fctCode: RADIO
Radio-button:
name: DIV
text: Division
fctCode: RADIO
module calculation.
25 Save, activate
Text-field:
Name: TEXT3
Text: Subscreen 3
Text-field:
Name: RESULT
Text: Result
i/o-field:
Name: ANS
remove Tick-mark from ‘input field’ to make it read only
SCREEN: Screen Program – data insert, update, delete in user defined table (using Table Control)
Steps Action
1 create an user-defined table ‘ZAJDEPT’
field type length key
DNO NUMC 10 tick
DNAME CHAR 10
Note: DNO is a primary key field
see ‘ABAP Dictionary - create user-defined tables’..
2
SE38
3 Program: ZSANDATAENTRYSCREEN (enter any name)
4
Create
5 Title: (enter any text)
6 Type: Executable Program
7 Save
** Program source code:
8 REPORT ZSANDATAENTRYSCREEN.
CONTROLS MY_TBL_CTRL TYPE TABLEVIEW USING SCREEN 100.
TABLES: ZAJDEPT.
DATA: itab TYPE TABLE OF ZAJDEPT,
fill TYPE i.
DATA: IO_DNO type ZAJDEPT-DNO,
IO_DNAME type ZAJDEPT-DNAME.
DATA: IO_STATUS(40) type C.
call screen 100.
*---[MODULE] STATUS_010
MODULE STATUS_0100 OUTPUT.
SELECT * FROM ZAJDEPT INTO CORRESPONDING FIELDS OF TABLE itab.
DESCRIBE TABLE itab LINES fill.
MY_TBL_CTRL-lines = fill.
ENDMODULE. " STATUS_0100 OUTPUT
*---[MODULE] FILL TABLE CONTROL
MODULE fill_table_control OUTPUT.
** Flow Logic:
10 *--- PBO
** Layout:
11 text-field:
name: LABEL_HEADING
text: DATA_management_in_table_ZAJDEPT-_by_Santanu
Box:
name: BOX_DATA_ENTRY
text: data_entry
Note: place the following 4 fields inside the rectangular BOX area BOX_DATA_ENTRY
text-field:
name: LABEL_DNO
text: Department_no:
i/o-field:
name: IO_DNO
format: NUMC
text-field:
name: LABEL_DNAME
text: Department_name:
i/o-field:
name: IO_DNAME
format: CHAR
i/o-field:
name: IO_STATUS
table-control:
name: MY_TBL_CTRL
enter ‘ZAJDEPT’ in the Table/Field name text-box and press ‘ENTER’ key.
push-button:
name: INSERT
text: Insert_data
fctCode: INSERT
push-button:
name: UPDATE
text: Update_data
fctCode: UPDATE
push-button:
name: DELETE
text: Delete_data
fctCode: DELETE
push-button:
name: EXIT
text: Exit
fctCode: EXIT
12 Save, activate
15 Now you can insert, modify , delete data in your table ZAJDEPT [see step-1]
BDC: (Batch Data Communication) is used to MIGRATE data from SAP to SAP system or from a non-SAP
legacy-system to SAP system.
In all the above methods you have to prepare a flat file containing the data in the required format to be uploaded to the
SAP system. You need to call the function ' UPLOAD' to do this. Then the contents of the flat file have to copied to your
internal table and then u need to call the transaction through which you want to update the database. You internal table
should also have the information relating to the structure BDCDATA which is having the details like the module pool
program name, screen no. The basic concept of updating the database is same in all the 3 methods but only the method
differs.
In session method after the data transfer program is coded, in order to process that particular session you have to go to
TC: SM 35 to process the session.
BDC: Call-Transaction – method (migrate data from text file ‘c:\my.txt’ to table LFA1)
Steps Action
Note: to avoid obstacle during data migration process remember the following points..
a) view the destination table(LFA1) data before data migration [using SE16. see step-37]
b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).
c) during recording process a set of data is entered through the screen, which also gets
inserted into the same table (LFA1). Ensure that LIFNR(vendor code) value during screen-
recording is given as 1601 (1600+1) [see step-6] and the same value does not exist in table
LFA1.
d) there should not be any duplicate data in LIFNR (it is a primary field with unique data)
** Recording:
2 SHDB (transaction code for) Transaction Recorder: recording overview
3 Click ‘New recording’ on tool-bar
4 (in pop-up window..)
Recording: ZmyRec (give any name)
SE16 (transaction code) to view newly migrated data from file ‘C:\my.txt’ [see step-1]
38 Table name: LFA1 , click on ‘Table Contents’ icon (F7)
Steps Action
Note: to avoid obstacle during data migration process remember the following points..
a) view the destination table(LFA1) data before data migration [using SE16]
b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).
c) during recording process a set of data is entered through the screen, which also gets
d) there should not be any duplicate data in LIFNR (it is a primary field with unique data)
*** Same as BDC-Call transaction. (just add the following steps) ***
2 SE38
3 Program: ZmySessionTrans (enter any name)
4 Create
5 Title: my BDC session transaction (enter any text)
Type: Executable Program
6 Save , LocalObject
7 Copy and paste entire Call-transaction program codes already done.
8 Place cursor just before the line ‘Loop at ITAB’
** call function BDC_OPEN_GROUP:
9 Ctrl+F6 or Click on ‘Pattern’ (to select the function name and generate codes)
10 Call function: BDC_OPEN_GROUP , click on continue (tick mark)
11 (Un-comment following 4 lines)
EXPORTING
Client = sy-mandt (Note: represents login ClientNumber. e.g. ‘800’)
EXPORTING
(Note: MK01 is the transaction-code for SAP standard data entry screen create vendor –
purchasing )
24 Click on ‘Start recording’
25 Vendor: 1601 (select a non-existing vendor code)
Purchase organization: 0001 (give any code)
Account group: 0001 (give any code)
Press ‘Enter’ key
Name: santanu
Search term: SN
Country: IN
Press ‘Enter’ key , ‘Enter’ key… to move to next page
Order Currency: INR
List of Radio-buttons:
Note: to avoid obstacle during data migration process remember the following points..
a) view the destination table(LFA1) data before data migration [using SE16. see step-95]
b) for example, if the last record data in table:LFA1, field:LIFNR(vendor code) is 1600, then the
first value of the same field in data file ‘C:\MY.TXT’ should be 1602 (1600+2).
c) during recording process a set of data is entered through the screen, which also gets
inserted into the same table (LFA1). Ensure that LIFNR(vendor code) value during screen-
recording is given as 1601 (1600+1) [see step-20] and the same value does not exist in table
LFA1.
(Note: MK01 is the transaction-code for SAP standard data entry screen create vendor –
purchasing )
19 Click on ‘continue’ (tick-mark)
20
Vendor: 1601 (select a non-existing vendor code)
Purchase organization: 0001 (give any code)
Account group: 0001 (give any code)
Name: santanu
Search term: SN
Country: IN
Note: for subsequent data migration from the same data file ‘C:\MY.TXT’(with different sets of data)
into the same destination table(LFA1), just follow the steps from step-74 onwards
Steps Action
1 SE37 (transaction code for Function-Builder)
2 GoTo (on menu bar)
3 Function Groups
4 Create Group
5 function group: zmygrp
short description: my function group
6 click on tick-mark
7 Local object
Steps Action
1 SE38 (transaction code for ABAP editor)
2 Program name: ZmyRFC
Create
3 Executable
Short description: santanu’s RFC
Type: executable program
4 Save , ‘Local object’
5 Data: a type i, b type i, c type i.
(or)
Parameters: a type i, b type i.
Data: c type i.
a = 10. b = 5.
6 Click on ‘Pattern’ ctrl+F6to generate function code
Select radio-button ‘Call function:’ and enter function name ZmyFunc [see RFC function
creation step-8]
7 Continue
8 Call function ‘Zmyfunc’ destination ‘NONE’
Exporting
X = a
Y = b
Importing
NOTE: add statement destination ‘NONE’ to test the remote function call in local system. In real
life use the remote computer name. e.g destination ‘HONGKONG’
9 Save , check, activate, execute
IDOC-TYPE (class)
IDOC (object)
Note: each field structure should not exceed 100 bytes. An IDOC can have any number of SEGMENTs, but atleast one
SEGMENT should be mandatory
IDOC-TYPE
|------ SEGMENT
Step2: create ‘IDOC TYPE’ and attach ‘SEGMENT’ (transaction code WE30)
Steps Action
1 WE31
2 Segment type: ZmySEG (give any name)
3 Click on ‘Create’ icon (F5)
4 Short description: (enter any text)
5 Field name data element
CustNo kunnr
CustName name1
OrderNo vbeln-va
OrderValue netwer
6 Press ‘Enter’ key
7 Right most column gets filled with Field-lengths
8 Save , continue(tick mark) , ‘Local object’ , Back , back
9 WE30
10 Object name: ZmyOBJ (give any name)
11 Click on ‘Create’ icon (F5)
12 Select radi-button ‘Create new’ (default)
Short description:
13 Click on ‘continue’ (tick mark)
14 Select ‘ZmyOBJ’ from the list
15 Click on ‘Create’ icon (shift+F6)
16 A pop-up window appears
17 Segment type: ZmySEG
Select check-box ‘Mandatory Seg’
Minimum number: 10
Maximum number: 100
18 Continue(tick mark) , Save , ‘Local object’ , Back , Back
19 WE31
20 On menu-bar, select: EDIT Set Release
21 Click on ‘Check’ (it will display segment consistency message)
22 Back , Back
23 WE30
24 On menu-bar, select: EDIT Set Release
25 Click ‘Yes’ in the pop-up box
26 Click on ‘Check’ (it will display message: ZmyOBJ is released)
IDOC: (sending/receiving)
Steps Action
1 On ‘source system’
goto an application e.g. SALE
2 Under ‘sending system’ and ‘receiving system’ define the logical system by entering the
DESTINATION system name & SOURCE system name. These names must be saved in a
‘development class’ e.g. ZmyDEV’
3 Assign clients to ‘Logical client’
4 Select the clients that are going to act as source and destination system and change their names
accordingly. (client: 800, 810)
5 ‘Logical client’ assignment – completed--
6 Set the RFC destination and configure it
7 Use the RFC destination, if it exists.
8 Create a new destination, if it doesn’t exist.
9 Modelling and implementing business process:
10 Under this, maintain distributed model & distributed views by creating MODEL –VIEW and
MESSAGE-TYPE
11 Transport the MODEL-VIEW that is developed into a MODEL-VIEW class
12 Generate ‘partner profile’ by giving the ‘Logical system name’
13 NOTE: carry out the same procedure for the other ‘client system’
Steps Action
1 WE21 (transaction code: to create a port)
2 Name:
Desc:
Function module:
Outbound file name:
RFC destination name:
Command file name: CONVERTER_SRART
3 WE41 (transaction code: for OUTBOUND process)
4 Process code: ZmyOUTPROCESS
Description: santanu’s outbound process
Steps Action
1 BAPI (transaction code)
2 1. Cross application components
2. Accounting - general
3. Financial accounting
4. Treasury
5. Controlling
6. Investment management
7. Enterprise controlling
8. Real estate management
9. Logistics – general
10. Sales & Distribution (SD) – basic functions, sales, billing, sales support
11. Materials management (MM)
12. Logistics execution
13. Quality management (QM)
14. Plant maintenance (PM)
15. Customer service
16. Production planning & Control
17. Project system
18. Environment, Health & Safety
19. Personnel management (HR)
20. Personal Time management (HR)
21. Pay roll (HR)
22. Training (HR)
23. Basic component service
3 NOTE: SPRO (transaction code) for entering into MM, FICO, etc.
IMG (transaction code) for implementation guide
4 SW01 (transaction code) to create an object