Documents 3357-ABAP+NOTES
Documents 3357-ABAP+NOTES
Documents 3357-ABAP+NOTES
ABAP is not case sensitive. We can use upper case or lower case or combination
also. But is space sensitive. All user defined object names in SAP should start with either
‘Z’ or ‘Y’. If we don’t start object name with either ‘Z’ or ‘Y’ it will ask for access key.
Hence we can say that as a user we don’t have the access to create an object name
without starting with ‘Z’ or ―Y’.
All statements in ABAP should be terminated with a period (full stop or dot). There
are 5 types of programs available in ABAP. They are….
1) Executable Program
2) Function Group
3) Modulepool Program
4) Include Program
5) Subroutinepool Program.
To create all these programs T-Code is SE38. It is also called ABAP Editor.
EXECUTABLE PROGRAM:- A program which takes input from the user and gives
output is called Executable Program or Report Program. Input screen of report program is
called SELECTION-SCREEN. Output screen of report program is called LIST. By
default for every report program Selection-screen number will be 1000.
Whenever you login into SAP first screen you get is called SAP Easy access
screen. In that screen top one is called Menu bar. After that we have standard Tool bar
and after Application tool bar. On Standard tool bar we have command filed where we
enter Transaction code.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
WRITE 'HELLO'.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
WRITE 'HELLO'.
WRITE 'HAI'.
In this output we are getting HELLO and HAI in the same line. But my
requirement is that I should HAI in the next line. For that we have to use new line
character ‘/’. In ABAP / is called new line character.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
WRITE 'HELLO'.
WRITE / 'HAI'.
The above program can be written like this with combination of statements.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
WRITE: 'HELLO',
/ 'HAI'.
The syntax is ……
PARAMETERS A TYPE I.
Here A is a variable name. I stands for integer type variable. That means A is a
variable that is going to hold integer type variable. When ever integer type variable is
declared system automatically allocates 14 digits memory.
When you execute the program you will get the selection –screen. The screen shot
is as follows.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
PARAMETERS A TYPE I.
WRITE: / 'ENTERED NUMBER IS',A.
One more important thing you have to remember in this write statement is that the
hard coded text (i.e. ENTERED NUMBER IS) should be in codes and the declared
variable (i.e.A) should not be in codes. That you have to keep in mind.
Let us see how we can declare character type data. For declaring character type
data we have to use C.
PARAMETERS A TYPE C.
C stands for character type variable. When ever character type variable is
declared system allocates single character memory. If many characters are needed to be
given as input specify the length.
Syntax is ……
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
PARAMETERS A(10) TYPE C.
WRITE: / 'ENTERED STRING IS', A.
Syntax is………..
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
PARAMETERS A(10) TYPE C LOWER CASE.
WRITE: / 'ENTERED STRING IS', A.
In other programming languages if data type is not mentioned system gives error.
But in ABAP if no data type is mentioned system allows you input character type data.
That means if no data type is mentioned the default data type assigned is Character type
data.
REPORT ZSAMPLE .
PARAMETERS A(10).
WRITE: / 'ENTERED STRING IS', A.
And one more important to remember is character type data in ABAP can also
hold numeric values and we can do all mathematical operations with those variables.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
PARAMETERS: A TYPE I,
B TYPE I.
DATA C TYPE I.
C = A + B.
WRITE: / 'THE SUM OF TWO NUMBERS IS', C.
In the above program I have used one more keyword DATA to declare the
variable.
DATA:- It is a keyword used to declare a variable of particular type which allows the
user to pass the variables that are generated by system at run time. But user is not allowed
to input the data using key board.
You can clearly see on the selection-screen that what ever variables that I have
declared in the program using Parameters keyword are coming directly on selection-
screen. But in real time developer develops the program end user will use the application
or program. If variables names are directly coming on the selection-screen, the end user
will not be knowing what to enter there. So I want to have meaningful description to the
selection-screen fields. This is done using selection-texts.
Come back to the program by pressing back button or F3 and execute the
program. Now selection-screen looks like this.
When ever a line is commented in any programming language, the line will not be
checked for errors and that line will not be executed while execution.
If you want to comment whole line you have to keep * (start) in the first position
or first column of the line. If you want to comment from particular position of a line you
have to use “(double quotes) and write the comment. You see the syntax present in the
bottom.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
If your control is present in the easy access screen and if it is needed to move to a
transaction we directly type transaction code in command field and press enter to move to
the transaction. If your control is not present in the easy access screen (let us say if it is
present in ABAP editor screen) and if it is needed to go to another transaction , if we
directly type transaction code in the command field system will prompt you saying
Function code xyz is not supported. Actually that Transaction code exits in SAP. To
solve this or over come this we have to either use /n or /o before the T-code.
1. sy-datum -- Date
2. sy-uzeit -- Time
3. sy-mandt -- Logon client number
4. sy-uname -- Logon user name
5. sy-repid -- Report program name
6. sy-cprog -- Current program name
7. sy-dynnr -- Screen number
8. sy-tcode -- Transaction code
9. sy-pagno -- Page number
REPORT ZSAMPLE .
write / sy-datum.
write / sy-uzeit.
write / sy-uname.
write / sy-repid.
write / sy-cprog.
write / sy-mandt.
write / sy-dynnr.
write / sy-pagno.
Write / sy-tcode.
CONTROL STATEMENTS
Control statements are nothing but loops. The property of the loop is to rotate by
it self until loop is terminated. There are 4 types of control statements in SAP. They are
1. DO.
………..
………..
ENDDO.
2. DO N TIMES.
………..
………..
ENDDO.
3. WHILE <CONDITION>.
………..
………..
ENDWHILE.
4. CASE <VARIABLE>.
WHEN <VALUE1>.
………..
………..
WHEN <VALUE2>.
………..
…………
WHEN OTHERS.
………..
…………
ENDCASE.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
DO.
WRITE / SY-INDEX.
IF SY-INDEX EQ 10.
EXIT.
ENDIF.
ENDDO.
In this program the control comes out of the program when sy-index value
becomes 11. That means at 11th iteration the control comes out of the loop.
For aligning the program lines use PRETTY PRINTER button present on the
application tool bar of the ABAP editor.
Good I have written the above program and I will get the following output and I
am happy.
To keep the break point in the program at particular line, keep the cursor on that
particular line and press STOP button. That line immediately turns to yellow color and
at the status bar you will get a message saying that Breakpoint set. When you execute the
program the control goes to that particular line and program execution is stopped there.
To execute the program further you have to use the following keys.
Maximum number of break points allowed are 30. Sap has given option to
keep these many break points to easily debug a program which is having many lines.
When you execute the program in debugging mode the screen will be in this format.
If you want to delete the break point that is set, keep cursor on the line where
break point is set and once again press STOP button. The break point will be deleted.
One more thing you have to remember is break points can be set in a program if program
is active. That means we can not keep break point in a program if program is inactive.
The break points that are set using Stop button are automatically deleted when you
logout. You cannot see those break points once you login.
If you want to keep permanent break points use keyword BREAK-POINT. This
keyword is used to keep permanent break points. Where you want to stop the control
before that line use this break-point key word.
Sometimes a requirement may come to set the break point for a particular user. In
that case BREAK <USER NAME> key board. Let us assume that you have logged in
with sapuser and if you want to set break point to that particular use only then syntax will
be …….
BREAK SAPUSER.
From now onwards what ever the program you write you try to execute the
program in debug mode. So that you will understand the program well.
One more thing you have to remember is that whenever do loop is used it is
mandatory to use Exit statement. Other wise the program will be in infinite loop and you
never get the output.
= EQ
< LT
> GT
<= LE
>= GE
<> NE
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
DO 10 TIMES.
WRITE / SY-INDEX.
ENDDO.
The output of this program will also be the same as above i.e. 1 to 10. In Do n
times loop there is need to use Exit statement because the loop will be rotated for those
many times and then the control comes out of the loop.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
The output of this program is also same as above two programs i.e. 1 to 10.
Now we discuss about the differences between DO loop and WHILE loop a
famous question in C language.
In Do loop we enter into the loop and check the condition, but in While loop first we
check the condition then only we enter in to the loop.
Minimum number of number of times Do loop executed is one time, but while loop
minimum number of times executed is Zero. If condition is wrong the control will
not enter into the loop.
*&---------------------------------------------------------------------*
*& Report ZSAMPLE *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZSAMPLE .
PARAMETERS Z.
CASE Z.
WHEN 'A'.
WRITE / 'YOU ENTERED A'.
WHEN 'B'.
WRITE 'YOU ENTERED B'.
WHEN OTHERS.
WRITE 'YOU ENTERED OTHER ALPHABIT'.
ENDCASE.
REPORT ZSAMPLE .
PARAMETERS Z.
CASE Z.
WHEN 'a'.
WRITE / 'YOU ENTERED A'.
WHEN 'B'.
WRITE 'YOU ENTERED B'.
WHEN OTHERS.
WRITE 'YOU ENTERED OTHER ALPHABIT'.
ENDCASE.
Here in this program in when condition ‘A’ is changed to ’a’. What will be the out
if enter a in the selection-screen. Think it and read the following lines.
The output will be YOU ENTERED OTHER ALPHABIT. But why? Because
the input characters in the selection-screen are automatically converted to upper case.
This we have discussed earlier. This is the property of selection-screen. Here my
intension is to specify that what ever you give in the case statement in when condition,
give with in quotes only upper case letters. Other wise you get abnormal results. That you
have to remember it. You can try this thing.
EXIT
STOP
CONTINUE
CHECK
1. EXIT :- We have already discussed about it. Exit statement is used to terminate
the loop. The statements after the loop will be executed normally. Let us analyse
the following program.
*&---------------------------------------------------------------------*
*& Report ZLOOPS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZLOOPS .
do.
write / sy-index.
if sy-index eq 10.
exit.
endif.
enddo.
write / 'HELLO'.
When sy-index becomes 11 the loop will be terminated and we are having a write
statement after the loop. That will be executed normally. That is the reason why we
are getting HELLO in the output along with the numbers.
2. STOP:- Whenever stop statement is used in the program, immediately after the
execution of the STOP statement the whole program will be terminated. That
means no statement after execution of STOP will be executed. STOP statement
completely terminates the program.
REPORT ZLOOPS .
do.
write / sy-index.
if sy-index eq 10.
stop.
endif.
enddo.
write / 'HELLO'.
REPORT ZLOOPS .
do.
if sy-index eq 2.
continue.
endif.
write / sy-index.
if sy-index eq 10.
exit.
endif.
enddo.
3. CHECK:- This statement returns true or false. If check returns true the
statements after it will be executed. If it returns false the statements after it will
not be executed. Even though check returns false value the loop will be continued.
Analyze this following example.
REPORT ZLOOPS .
do.
write / sy-index.
if sy-index eq 10.
exit.
endif.
check sy-index eq 2.
write / sy-index.
enddo.
Let us assume that the CHECK statement is written outside the loop and it is
writtening false value. Then all the statements written after it will not be executed. That
means it acts like STOP. That is If CHECK is written outside the loop and if it
returns false value it acts like STOP.
STRING OPERATIONS
TRANSLATE:- This keyword is used to convert character type variables from one case
to another case.
Syntax is …….
PARAMETERS A(10).
TRANSLATE A TO LOWER CASE.
If RAMESH is given as input to this program output will be ramesh. You can
also use upper case key word with translate. But there is no use because what ever we
give in selection-screen will be automatically converted to upper case by default.
REPORT ZLOOPS .
parameters: a(20).
data len type i.
len = strlen( a ).
write len.
REPORT ZLOOPS .
parameters: a(10),
b(10).
data c(20).
concatenate a b into c.
write c.
REPORT ZLOOPS .
parameters: a(10),
b(10).
data c(20).
concatenate a b into c separated by space.
write c.
If I use this line in the program I will get comma between the strings.
When ever we are giving space in the concatenate syntax it should not be in the
quotes, because space is a key word. If any other character is required between the
strings other than space that character should be given in the quotes.
Sample program is ……
REPORT ZLOOPS .
parameters: a(20).
data: b(10),
c(10).
split a at ',' into b c.
write : / b,
/ c.
Sample program can be seen below. This program is used to replace all characters
present in a string A with space.
do.
if a ca ','.
replace ',' with space into a.
else.
exit.
endif.
enddo.
write a.
Here in the above program we used a keyword CA which means contains any.
You can debug the program you will understand better about the logic.
If you want to see documentation for any keyword present in ABAP just type the
keyword in ABAP editor and keep cursor on the keyword and press F1. It will open
beautiful documentation regarding the keyword.
R A M E S H
0 1 2 3 4 5
Instead of starting from 1 system gives the positions from 0. That means if I want
3 character physically I should search for the 2nd character as per system representation.
rd
Consider the following example. I give the input as RAMESH into variable A. I
want to move 3rd character from this variable into B variable.Then
A = RAMESH
B = A+2(1).
Then M will be move to B.
If I want 3rd and 4th characters into B, Then I have to change above statement as ….
B = A+2(2). Both ME will be moved into B.
REPORT ZLOOPS .
parameters: a(20).
data b(20).
b = a+2(1).
write b.
REPORT ZLOOPS .
parameters: a(20).
data len type i.
data b.
len = strlen( a ).
len = len - 1.
b = a+len.
write b.
SY-FDPOS:- It is a system variable used to find the position where the search is
successful. Let us assume that you are searching for a comma in a string and you want to
find out the position where comma is present in the string. Then we can use this system
variable. But it acts abnormally. If string is not containing the particular character for
which you are searching sy-fdpos system variable takes the declared length of a
string which you are searching.
You can execute the following program and see the results.
REPORT ZLOOPS .
parameters: a(30).
if a ca ','.
write sy-fdpos.
else.
write sy-fdpos.
endif.
1. Customized data
2. Master data
3. Transactional data.
CUSTOMIZED DATA:- The data which never changes is called Customised data. This
data is not created but configured by functional consultant using SPRO tranction.
MASTER DATA: The data which changes very rarely is called Master data.
TYPES OF TABLES
TRANSPARENT TABLES:- For every table created in Data dictionary (DDIC) there
will be table created in database with same name, same no of fields, fields having same
names and the order of the fields will be same. That means for every same replica of table
or mirror image will be created in Data base. That means it is having one to one relation.
By default every table created will be Transparent Table.
CLUSTERED TABLES:- Many tables created in DDIC are stored in single table in data
base called table cluster. That means it is having many to one relation. All the tables
present in table cluster will have primary key in common.
POOLED TABLES:- In case also many tables created in DDIC are stored in single
table in database called table pool. Hence it also having many to one relation. Here the
tables present in table pool many have primary key in common.
SE11 T-Code is used to create data base objects which includes tables.
A table can be client dependent or client independent. Table data only client dependent or
client independent, but table structure is client independent.
CLIENT:- Client is SAP specific which contains it’s own master data and it’s own set of
records. All SE38 programs are client independent programs. That means if a program is
written in one client it can be seen all the clients present in the system.
If first field of the table is MANDT the table becomes client dependent table,
otherwise it becomes client independent table. If the table is client dependent table the
data that you enter in one client can not be seen in other clients. If the table is client
independent table the data that is entered in one client can be seen all other clients. That
means if the table is client independent all table in all clients contain same data.
Every table should have at least one primary key or foreign key. All primary key
fields and foreign key fields of a table should be declared first.
DOMAIN:- It gives technical attributes of the table fields. Domain is the more reusable
component than data element.
Eg:- Type of data it is going to hold.
DATA BROWSERS
These are set of Transaction codes used to main data base objects. The T-codes are.
SE11
SE12
SE16
SE17
SM30
SE54
All these T-codes are used to maintain data base objects. But some of the options
may be present in one T-code and some of the options may not be present in other T-
codes. You can use any of them.
All report programs are stored in TRDIR table. All tables are stored in
DD02L Table. It is table of tables.
Now we discuss about the programs to get the data from Data base tables. Now I take
MARA (Material master table) table as example to get the data. Practice only getting
data from standard tables.
Important fields in MARA table are.
1. MATNR ---- MATERIAL NUMBER
2. MBRSH ---- INDUSTRY SECTOR
3. MTART ---- MATERIAL TYPE
4. MEINS ---- UNIT OF MEASURE
5. NTGEW---- NET WEIGHT
6. BRGEW---- GROSS WEIGHT
My requirement is here I want to give MATNR as input to the program and I
want to get MATNR,MBRSH,MTART,MEINS for the particular material number I give
as input. We see how to declare the variables and How to write the select query.
When ever some input is needed to be given into a program we have to use the
PARAMETERS keyword. Here in this program I want to give material number i.e.
MATNR as input to the program. So I have to go to data base table MARA where
MATNR field is present and I have to find out the data type from there and I have to give
in the program. It is a big process. If want to declare many fields I have to go to many
times into the table and see the data type and I have to give in the program. I don’t want
to follow all this lengthy process. Only with the single statement the data type should be
assigned to the variable from data base field and with this statement The F1 and F4 helps
should be assigned to the variable.
Give assign the data type to a variable we have to refer to table name and field name.
Here in this example p_matnr is a variable which will take the characteristics from mara
table and matnr field. Instead of P-matnr we can give any name what ever we want. But
here I want to follow industry notation. Where p Stands for Parameters and matnr stands
REPORT YSELECT9 .
PARAMETERS P_MATNR TYPE MARA-MATNR.
DATA: D_MATNR TYPE MARA-MATNR,
D_MBRSH TYPE MARA-MBRSH,
D_MTART TYPE MARA-MTART,
D_MEINS TYPE MARA-MEINS.
SELECT MATNR
MBRSH
MTART
MEINS
FROM MARA
INTO (D_MATNR,D_MBRSH,D_MTART,D_MEINS)
WHERE MATNR EQ P_MATNR.
ENDSELECT.
WRITE: / D_MATNR,
D_MBRSH,
D_MTART,
D_MEINS.
In this above program I am able to give single material number as input. But my
requirement is I want to give range of materials as input and I want to get the records in
that range. For that we have to use the keyword SELECT-OPTIONS.
SELECT-OPTIONS:- It allows you to input multiple values or range of values into the
program. But when ever select-options is used the program syntax changes like this.
REPORT YSELECT9 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
DATA: D_MATNR TYPE MARA-MATNR,
D_MBRSH TYPE MARA-MBRSH,
D_MTART TYPE MARA-MTART,
D_MEINS TYPE MARA-MEINS.
SELECT MATNR
MBRSH
MTART
MEINS
FROM MARA
INTO (D_MATNR,D_MBRSH,D_MTART,D_MEINS)
WHERE MATNR IN S_MATNR.
WRITE: / D_MATNR,
D_MBRSH,
D_MTART,
D_MEINS.
ENDSELECT.
Some times I may get a requirement to get single record from data base for the
given input. That means I want to get first single matching record for the input what ever
I give. For that use select single.
Select single is used to get fetch first single matching record for the given
input. when ever select single is used you should not use end select.
WRITE: / D_MATNR,
D_MBRSH,
D_MTART,
D_MEINS.
Some times a requirement may come where I need to fetch n no of records from
data base. For that we use select up to n rows. It should contain endselect. The program
is as follows
If I write select up to 1 rows it will fetch single record from data base. This is
what is done when we write select single also. Then what is the difference between
select single and select up to 1 rows. The differences are
1. Select single doesn’t require endselect but select up to 1 rows requires endselect.
2. Use select single when all the primary key fields of a table are used in the select
query where condition. Otherwise use select up to 1 rows. Performance wise SAP
is recommending you to use this way. Even though you use interchangingly
nothing will happen but performance comes down.
SELECT MATNR
MBRSH
MTART
MEINS
FROM MARA
INTO (D_MATNR,D_MBRSH,D_MTART,D_MEINS)
UP TO 10 ROWS
WHERE MATNR IN S_MATNR.
WRITE: / D_MATNR,
D_MBRSH,
D_MTART,
D_MEINS.
ENDSELECT.
This program will fetch first 10 matching records from database for the given
input. If there are no 10 records to be fetched for the given input system fetches what ever
the records that are there for the given input.
In the above program we are getting the data record by record only. That means if
we want 1 lakh records from data base we are hitting data base 1 lakh times. The
performance of the program is low and the network traffic as also high. So my
requirement is I want to get all the matching records from data base in single shot and I
want to place it in the memory. The memory that we have created in the above programs
by those declarations can only hold single record at a time. To over come these problems
SAP has come up with a concept of internal tables.
INTERNAL TABLES
Header of the internal table can contain only single record and body can contain
multiple records. If we are writing the logic to move record by record by record from DB
table to header of internal table, after record comes into header it has to be moved to
body of internal table by saying append <table name>. If it is needed to write the
records present in the body of internal table into list, record by record has to be moved to
header and written out. For this we have to write loop at <internal table>. When ever it
is needed to make the changes in the records present in the body of internal table, every
record has to be moved to header and modified. We can not do any operations on the
records directly present in the body of the internal table. These things we have to keep in
mind.
REPORT YSELECT9 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into itab
where matnr in s_matnr.
append itab.
endselect.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart.
endloop.
REPORT YSELECT9 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab
where matnr in s_matnr.
*append itab.
*endselect.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart.
endloop.
In the above select query I have used select into table. Into table statement
fetches all the matching required records from database in single shot and directly places
into the body of internal table. Hence in the above program I have commented append
and endselect. Always when ever you use internal tables try to use into table which
improves the performance of the program.
Begin of itab occurs 0 statement creates an internal table with name itab with
header line.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
if sy-subrc eq 0.
write: / 'no of records fetched from db', sy-dbcnt.
loop at itab.
write: / sy-tabix,
itab-matnr,
itab-mbrsh,
itab-mtart.
endloop.
else.
write: / 'no data to display'.
endif.
FORMATTING TECHNIQUES
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
loop at itab.
write: / itab-matnr input,
itab-mbrsh,
itab-mtart.
endloop.
My requirement is I want to make all fields in the output as editable. After each
and every field I have to write input keyword. That unnecessarily increases the code. My
requirement is with single statement every field should become editable. For that use
FORAMT INPUT ON before write statement.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
HOTSPOT: - This keyword is used to display hand symbol when ever cursor is
placed on a particular field in the output.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
loop at itab.
write: / itab-matnr hotspot ,
itab-mbrsh,
itab-mtart.
endloop.
To display hand symbol when ever cursor is placed on any field of output use
FORMAT HOTSPOT ON.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
COLORS:- For giving color to any field present in the output after the write statement
give color <color name/color number>. No direct colors like red, blue, green etc in SAP.
We are having following colors.
You can use the color names or the numbers present beside the color name in the
above list.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
loop at itab.
write: / itab-matnr color col_heading ,
itab-mbrsh color col_positive ,
itab-mtart color col_negative .
endloop.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
loop at itab.
write: / itab-matnr ,
itab-mbrsh ,
itab-mtart .
endloop.
skip 5.
write / 'hai'.
BACK:- This keyword is used to move the control to first line first column of the output
list. Let us assume the requirement. I have displayed around 10 lines in the output and the
REPORT ZINTERNAL .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
select matnr
mbrsh
mtart from mara
into table itab where matnr in s_matnr.
loop at itab.
write: / itab-matnr ,
itab-mbrsh ,
itab-mtart .
endloop.
back.
write /45 'hai'.
When ever begin of <internal table name> occurs 0 is used to create an internal table
system by default allocates 8KB of memory. If no of records fetched from database table
are more, that memory system initially allocated may not be sufficient. Hence system will
allocate extra memory. The extra memory allocated will be in multiples of 8KB only.
Hence in this case there is a possibility that memory may be wasted. Since memory is
allocated in pockets of 8KB the performance of the program comes down. To avoid all
these problems SAP has come up with a concept of internal tables without header line. In
this case internal table directly contains body without header. When ever internal table is
created without header line we have to create a work area. Here work area acts like a
header which can contain single record. The condition is the structure of work area and
internal table should be same or at least it should be compatible.
When ever it is needed to create an internal table without header line we use
REPORT YSELECT9 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
types: begin of ty_itab,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of ty_itab.
select matnr
mbrsh
mtart from mara
into wa where
matnr in s_matnr.
append wa to itab.
endselect.
In this above program first I have created a structure ty_itab using types statement
( Structure internally contains fields). Using this structure I have created an internal table
(ITAB) and as well as work area (WA). When ever type standard table of syntax is used
it creates an internal table. If we use only type in the syntax it creates work area. But in
the above program first record by record is coming into work area and then it is appended
into the body of the internal. This program is not good performance wise. Because we
have to get the records in single shot from database and have to place directly into the
body of internal table. For that purpose we can write the program like this which
improves the performance.
REPORT YSELECT9 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
types: begin of ty_itab,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of ty_itab.
select matnr
mbrsh
mtart from mara
into table itab where
matnr in s_matnr.
CLEAR:- This keyword clears/deletes the contents from the header of internal table or
from the variable memory.
REFRESH:- This keyword deletes the contents from the body of the internal table.
FREE:- This keyword is used to deallocate the memory allocated for internal table as
well as any variable .
Till now we are only getting the data from single table. If I want to get the data
from multiple tables, we have to go for joins. There are two types of joins available in
SAP. They are…
1. Inner join
2. Left outer join
It is very important to remember that when ever you want to join the tables it is
mandatory that there should be at least one common field between them. Without a
common field between the tables we can’t join the tables. For taking the common field
we should not consider MANDT field. Common field may be primary key field or other
field.
INNER JOIN:- It is exactly like intersection or logical AND operator. This inner join
will fetch the data from the tables if the record is available in all the tables that you are
joining. If it is not available in one of the tables, the data will not be fetched.
LEFT OUTER JOIN:- It is like union. But it is not exactly like union. When ever left
outer join is used in select query, it will fetch all the records from left side table and the
common records from right side table.
Table 1 Table 2
|----|----|----|----| |----|----|----|----|----|
| A | B | C | D | | D | E | F | G | H |
|----|----|----|----| |----|----|----|----|----|
| a1 | b1 | c1 | 1 | | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | | 3 | e2 | f2 | g2 | h2 |
| a3 | b3 | c3 | 2 | | 4 | e3 | f3 | g3 | h3 |
| a4 | b4 | c4 | 3 | |----|----|----|----|----|
|----|----|----|----|
\ /
\ /
\ /
\ /
\/
Inner Join
|----|----|----|----|----|----|----|----|----|
| A | B | C | D | D | E | F | G | H |
|----|----|----|----|----|----|----|----|----|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|----|----|----|----|----|----|----|----|----|
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
Table 1 Table 2
|----|----|----|----| |----|----|----|----|----|
| A | B | C | D | | D | E | F | G | H |
|----|----|----|----| |----|----|----|----|----|
| a1 | b1 | c1 | 1 | | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | | 3 | e2 | f2 | g2 | h2 |
| a3 | b3 | c3 | 2 | | 4 | e3 | f3 | g3 | h3 |
| a4 | b4 | c4 | 3 | |----|----|----|----|----|
|----|----|----|----|
\ /
\ /
\ /
\ /
\/
See the sample program to join two tables using inner join..
REPORT ZJOINS1 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
WERKS TYPE MARC-WERKS,
END OF TY_MARA.
SELECT MARA~MATNR
MARA~MBRSH
MARA~MTART
MARC~WERKS
INTO TABLE IMARA
FROM MARA INNER JOIN MARC
ON MARA~MATNR EQ MARC~MATNR
WHERE MARA~MATNR IN S_MATNR.
REPORT ZJOINS1 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
WERKS TYPE MARC-WERKS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MARA.
SELECT MARA~MATNR
MARA~MBRSH
MARA~MTART
MARC~WERKS
MAKT~MAKTX
INTO TABLE IMARA
FROM MARA INNER JOIN MARC
ON MARA~MATNR EQ MARC~MATNR
INNER JOIN MAKT
ON MARA~MATNR EQ MAKT~MATNR
WHERE MARA~MATNR IN S_MATNR
AND MAKT~SPRAS EQ 'EN'.
See the sample program joining two tables using left outer join.
REPORT ZJOINS1 .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
WERKS TYPE MARC-WERKS,
END OF TY_MARA.
SELECT MARA~MATNR
MARA~MBRSH
MARA~MTART
MARC~WERKS
INTO TABLE IMARA
FROM MARA LEFT OUTER JOIN MARC
ON MARA~MATNR EQ MARC~MATNR
WHERE MARA~MATNR IN S_MATNR.
Joining of many tables decreases the performance of the program. In real time you
will not be allowed to join more than 4 or 5 tables. FOR ALL ENTRIES is used as
substitute for joins. When ever for all entries is used it is needed to declare separate
internal tables for each data base table. After getting the data from each data base table
into respective internal tables move the records into another internal table which is
containing the fields from both the tables.
REPORT ZFORALL .
tables mara.
select-options s_matnr for mara-matnr.
loop at final.
write: / final-matnr,
final-mbrsh,
final-mtart,
final-werks.
endloop.
else.
write: / 'no data to display'.
endif.
While using for all entries it is mandatory to check whether base internal table is
empty or not.. If base internal table is empty the second select query where for all entries
is used will fetch all the data from data base table for which select query is written. In the
above program if I don’t check the condition whether IMARA is empty or not , if
IMARA is empty the complete data from MARC table will come into IMARC internal
To check whether base internal table is empty or not use this syntax
See the sample program where we need not use third internal table and as
well as how to change or modify the existing records of the internal table.
REPORT ZFORALL2 .
tables mara.
select-options s_matnr for mara-matnr.
types: begin of ty_mara,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
werks type marc-werks,
end of ty_mara.
types: begin of ty_marc,
matnr type marc-matnr,
werks type marc-werks,
end of ty_marc.
MODULARIZATION
It is a technique of splitting larger code into smaller block of code. It is done for
easy understanding, easy debugging and to decrease the code. We can achieve this in
SAP using 4 concepts.
1. Events
2. Subroutines
3. Include programs
4. Function modules
5. Macros.
TYPES OF REPORTS
1. Classical Reports
2. Interactive Reports
3. Drill down Reports
CLASSICAL REPORT:- A report which can generate only one list, that is Basic List,
is called classical report. First List of a report is called BASIC LIST.
INTERACTIVE REPORT:- A report which can generate one basic list and upto 20
interactive lists is called an interactive report. First list is called Basic List and
Interactive lists are called Secondary Lists.
DRILL DOWN REPORTS:- In these reports the output will be in tree format.
1. INITIALIZATION
2. AT SELECTION-SCREEN
(a) AT SELECTION-SCREEN ON <FIELD>
(b) AT SELECTION-SCREEN OUTPUT
(c) AT SELECTION-SCREEN ON VALUE-REQUEST FOR <FIELD>
3. START-OF-SELECTION
4. TOP-OF-PAGE
5. END-OF-PAGE
6. END-OF-SELECTION
INITIALIZATION:- This is the first event to be triggered. This event is triggered before
the selection-screen is displayed. This event is used to give default vales to selection-
screen fields.
TOP-OF-PAGE:- This event is used to write something on top of every page. The first
write statement or output statement (SKIP) of a page triggers this event.
END-OF-PAGE: - This event is used to write something at end of every page. Last line
of the page triggers this event. We have to allocate the line for end of page.
See the following sample program which uses initialization event and write statement.
REPORT ZSAMPLE .
parameters p_matnr type mara-matnr.
initialization.
write : 'HELLO'.
I have written write statement in Initialization event and the program is having
selection-screen. The write statement can not be seen. Actually HELLO will be written
but that is immediately overwritten by selection-screen. That is the reason why we can
not see the write in output.
REPORT ZSAMPLE .
Initialization.
write : 'HELLO'.
If I execute the above program HELLO will be seen because this program is not
having selection-screen.
Now see the following program which is having all the above events.
end-of-page.
write: /45 'page number: ', sy-pagno.
MESSAGE CLASS:- Its is a collection of messages. Each message class can hold 1000
messages. (000 to 999). T-code for creation of message class is SE91.
There are 5 types of messages in SAP.
1. Error Message (E).
2. Warning Message (W).
3. Information Message (I).
4. Success Message (S).
5. Abend Message (A).
A Message created in a message class can be used as any of the above 5 types.
What ever the letter I have given in the brackets after each type of message should
be used to specify the system about which type message you are going to raise.
Error Message temporarily halts the program. That means once the errors
are corrected the control moves forward. But Abend message completely
terminates the program.
Information and Success messages give the message and move forward.
They won’t stop the control.
Warning message also temporarily terminates the program.
When ever you go for validations better you use Error message.
Now we look into statements that are new in the above program.
SY-LILLI:- It is a system variable which gives clicked line number in the list.
SY-LISEL:- It is a system variable which contains whole contents of clicked line.
1. INITIALIZATION
2. AT SELECTION-SCREEN
a. AT SELECTION-SCREEN ON <FIELD>
b. AT SELECTION-SCREEN OUTPUT
c. AT SELECTION-SCREEN ON VALUE-REQUEST FOR <FIELD>
3. START-OF-SELECTION
4. TOP-OF-PAGE
AT USER-COMMAND:- This is used to handle user action on the screen when ever
standard menu bar and application tool are changed.
In these interactive lists we take the help of HIDE table. Hide is an intermediate
memory area which is used to hold the values that are used for generation of next
secondary list. Hide statement should be used after write statement. Then only you will
get correct results. Other wise you will get wrong values. Hide table values you can’t see
even in debug mode.
SY-LSIND:- This is also a system variable which gives present processing list number.
It’s value will be 0 for basic list and 1 to 20 for secondary lists. We will make use of this
sy-lsind in our next program to tell the system about which logic should be executed
while going to a particular list..
SY-LILLI:- This is a system variable which will hold the clicked line number.
SY-LISEL:- This is also a system variable which will hold all the contents of clicked
line.
SY-UCOMM:- This system variable is used to hold the function code that is triggered
for the user actions on the screen.
start-of-selection.
select matnr
mbrsh
mtart from mara
into table itab
where matnr in s_matnr.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart.
HIDE ITAB-MATNR.
endloop.
AT LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
SELECT MATNR
WERKS FROM MARC
INTO TABLE ITAB1
WHERE MATNR EQ ITAB-MATNR.
LOOP AT ITAB1.
WRITE: / ITAB1-MATNR,
ITAB1-WERKS.
HIDE ITAB1-MATNR.
ENDLOOP.
WHEN 2.
select MATNR
MAKTX FROM MAKT
INTO TABLE ITAB2
WHERE MATNR EQ ITAB1-MATNR.
LOOP AT ITAB2.
WRITE: / ITAB2-MATNR,
ITAB2-MAKTX.
ENDLOOP.
ENDCASE.
TOP-OF-PAGE.
WRITE / 'DATA FROM MARA TABLE'.
TOP-OF-PAGE DURING LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
WRITE ' DATA FROM MARC TABLE'.
WHEN 2.
WRITE 'DATA FROM MAKT TABLE'.
ENDCASE.
SE41 T-code is used to create user defined GUI status or PF status for a program.
See the following program which is written to handle the user actions on the screen for
user defined GUI status.
start-of-selection.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart.
endloop.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'TCODE'.
CALL TRANSACTION 'SE11'.
WHEN 'DISPLAY'.
WRITE: 'LIST NUMBER IS', SY-LSIND.
WHEN 'WRITE'.
WRITE 'HELLO'.
ENDCASE.
SUBROUTINES
When ever same logic is needed to be executed many times in a program, create a
subroutine and call the subroutine when ever the logic is needed to be executed.
Perform statement is used to create the subroutine and to call the subroutine.
A subroutine can be created with passing the variables and without passing the variables.
The logic of the subroutine is written between form and endform. It is not required to
start the subroutine name with Z OR Y.
The variables that are passed into subroutine are called global variables or actual
variables. The variables that are used to receive the values in subroutine from main
program are called local variables or formal variables.
There are 3 ways to pass the variables into subroutine.
CALL BY VALUE:- In this new memory area is allocated for the local variables
between form and endform. When the values of local variables are changed , they are
changed in only or reflected in only newly created memory area. The original values of
corresponding global variables are not changed.
CALL BY REFERENCE:- In this no new memory area is created for the local variables
between form and endform. They make use of memory of the corresponding global
variables. Hence when the values of local variables are changed between form and
endform immediately the corresponding global variables values are changed.
CALL BY VALUE AND RESULT:- In this new memory area is created for local
variables. When ever the values of local variables are changed between form and
endform, the changes are reflected in only newly created memory area. But when the
control is moving back from subroutine to main program, the values present in local
memory are copied back to the corresponding global variables memory area.
Hence we can say that in CALL BY VALUE the values of global variables are
never changed when corresponding local variables values are changed, in CALL BY
REFERENCE the values of global variables are changed immediately. In CALL BY
VALUE AND RESULT the values of corresponding global variables are changed
control moves from subroutine to main program.
First we will see how to create the subroutine with passing the variables.
REPORT ZSELECT20 .
parameters: a type i,
b type i.
data c type i.
c = a + b.
ENDFORM. " add
No need to write the form and endform manually. When you double click the
perform name written in perform statement (ADD) automatically system will create form
and endform. Between the form and endform write the logic what ever you want.
Now we will see how to create a subroutine without passing the variables.
REPORT ZSELECT20 .
tables mara.
select-options s_matnr for mara-matnr.
data: begin of itab occurs 0,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
end of itab.
perform select.
perform display.
*&---------------------------------------------------------------------*
*& Form select
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM select .
select matnr
mbrsh
mtart from mara
into table itab
where matnr in s_matnr.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart.
endloop.
ENDFORM. " display
start-of-selection.
write 'hello'.
Usually subroutines are local to a program. They are not stored in database. They
are not self executable. If you want to call a subroutine ADD (say) created in some X
program from Y program , you have to write this syntax in Y program
INCLUDE PROGRAMS
These programs are also used for reusability. Include program name should start with
either Z or Y. There are two ways to create include programs.
1. Directly from SE38 we can create include program. Here we have to choose
program type as include program.
FUNCTION MODULES.
Uxx include contains source code of the function modules. For each function
module one include will be added in Uxx include. On seeing the no of includes in Uxx
include we can know how many function modules are present in a particular function
group.
SE37 T-code is used to create a function module. Function module name need not
start with z or y. The variables that are needed to be sent from program or the variables
that are needed to be populated at run time should be given under Import. The values that
are needed to be sent from function modules to program should be given under export or
changing. When want to move the internal table data from function module to program or
vice versa it should be taken in tables. Exceptions can be written under exceptions. The
logic of the function module should be written under source code.
See the following function module which is written to add two numbers.
If you want to call the function module from a program you have to use pattern
button which is present on application tool bar.
You see this sample program which is calling the previous function module
written.
REPORT ZADDITION .
parameters: x type i,
y type i.
data z type i.
One thing you have to remember is that the left hand side variables data types and
right hand side variables data types should be same in call function. Otherwise system
gives type conflict error (Short dump). If a variable is not given as optional in function
module, it is mandatory to pass the value into the variable in call function. Other wise
system gives runtime error saying Incorrect parameter with call function. These two
things you have o keep in mind.
The output of the normal report and ALV will be same content wise. But after
getting the output in ALV we can interact with the list and we can perform many
operations on the output. The operations are like sorting the list, calculating totals and sub
totals, exporting list to excel sheet and text document, suppressing a particular field and
many more.
SLIS is an important type-pool used in ALVs for getting the output. This SLIS
type-pool is containing many structures internally. These structures will have fields.
These fields will have certain properties. If these fields are used in the program the
property assigned to that field will come to the program output.
1. Normal display
(a) Grid display
(b) List display
2. Block display
3. Hierarchical display
SELECT MATNR
MBRSH
MTART
NTGEW
BRGEW FROM MARA
INTO TABLE ITAB
WHERE MATNR IN S_MATNR.
REPORT ZALV1 .
TYPE-POOLS SLIS.
DATA FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
NTGEW TYPE MARA-NTGEW,
BRGEW TYPE MARA-BRGEW,
END OF ITAB.
SELECT MATNR
MBRSH
MTART
NTGEW
BRGEW FROM MARA
INTO TABLE ITAB
WHERE MATNR IN S_MATNR.
REPORT ZALV .
TYPE-POOLS SLIS.
DATA FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA EVENT TYPE SLIS_T_EVENT WITH HEADER LINE.
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
END OF ITAB.
SELECT MATNR
MBRSH
MTART FROM MARA
INTO TABLE ITAB
WHERE MATNR IN S_MATNR.
EVENT-NAME = 'TOP_OF_PAGE'.
EVENT-FORM = 'TOP'.
APPEND EVENT.
FORM TOP.
DATA HEADER TYPE SLIS_T_LISTHEADER WITH HEADER LINE.
HEADER-TYP = 'S'.
HEADER-INFO = 'DATA FROM MARA TABLE'.
HEADER-KEY = 'ALV REPORT'.
APPEND HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEADER[]
I_LOGO = 'ZSAP8'
* I_END_OF_LIST_GRID =
.
ENDFORM.
BLOCK DISPLAY
REPORT ZALV .
TYPE-POOLS SLIS.
DATA FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA FCAT1 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
SELECT MATNR
MBRSH
MTART FROM MARA
INTO TABLE ITAB
WHERE MATNR IN S_MATNR.
SELECT MATNR
WERKS
FROM MARC
INTO TABLE ITAB1
WHERE MATNR IN S_MATNR.
FCAT1-SELTEXT_L = 'PLANT'.
FCAT1-COL_POS = '2'.
FCAT1-TABNAME = 'ITAB1'.
FCAT1-FIELDNAME = 'WERKS'.
APPEND FCAT1.
CLEAR FCAT1.
LAYOUT-ZEBRA = 'X'.
1. REUSE_ALV_BLOCK_LIST_INIT
2. REUSE_ALV_BLOCK_LIST_APPEND
3. REUSE_ALV_BLOCK_LIST_DISPLAY
These function modules should be used in the same order. Based on the no of
internal tables that are needed to be displayed those many times
REUSE_ALV_BLOCK_LIST_APPEND function module should be used.
HIERARCHIAL DISPLAY
REPORT ZALV .
TYPE-POOLS SLIS.
DATA FCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA KEY TYPE SLIS_KEYINFO_ALV.
TABLES VBAK.
SELECT-OPTIONS S_VBELN FOR VBAK-VBELN.
DATA: BEGIN OF ITAB OCCURS 0,
CH(1),
VBELN TYPE VBAK-VBELN,
ERDAT TYPE VBAK-ERDAT,
ERZET TYPE VBAK-ERZET,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
END OF ITAB1.
SELECT VBELN
SELECT VBELN
POSNR
MATNR FROM VBAP
INTO TABLE ITAB1
WHERE VBELN IN S_VBELN.
FCAT-REF_TABNAME = 'VBAK'.
FCAT-COL_POS = '1'.
FCAT-TABNAME = 'ITAB'.
FCAT-FIELDNAME = 'VBELN'.
APPEND FCAT.
CLEAR FCAT.
FCAT-REF_TABNAME = 'VBAK'.
FCAT-COL_POS = '2'.
FCAT-TABNAME = 'ITAB'.
FCAT-FIELDNAME = 'ERDAT'.
APPEND FCAT.
CLEAR FCAT.
FCAT-REF_TABNAME = 'VBAK'.
FCAT-COL_POS = '3'.
FCAT-TABNAME = 'ITAB'.
FCAT-FIELDNAME = 'ERZET'.
APPEND FCAT.
CLEAR FCAT.
FCAT-REF_TABNAME = 'VBAP'.
FCAT-COL_POS = '1'.
FCAT-TABNAME = 'ITAB1'.
FCAT-FIELDNAME = 'VBELN'.
APPEND FCAT.
CLEAR FCAT.
FCAT-REF_TABNAME = 'VBAP'.
FCAT-COL_POS = '2'.
FCAT-TABNAME = 'ITAB1'.
FCAT-FIELDNAME = 'POSNR'.
APPEND FCAT.
CLEAR FCAT.
FCAT-REF_TABNAME = 'VBAP'.
FCAT-COL_POS = '3'.
FCAT-TABNAME = 'ITAB1'.
FCAT-FIELDNAME = 'MATNR'.
APPEND FCAT.
CLEAR FCAT.
KEY-HEADER01 = 'VBELN'.
LAYOUT-EXPAND_FIELDNAME = 'CH'.
Control break statements are usually used to find out totals and subtotals. The
control break statements are…
1. AT FIRST.
………..
………..
ENDAT.
2. AT LAST.
………..
………..
ENDAT.
4. AT END OF <FIELD>
………..
………..
ENDAT.
Pre-requisites for using Control break statements Control break statements should be
used in side the loop but on change of can be used outside the loop. Before using the
control break statement the internal table should be sorted by the field on which control
break statement is going to be used.
AT FIRST:- This is triggered at the first record of the internal table. This is triggered
only once. It is usually used to write the heading to columns while displaying the records
of internal table.
AT LAST:- This is also triggered only once at the last record of the internal table. This is
used to find out grand totals of numeric values.
AT NEW <FIELD>:- This is triggered at the starting of every new record based on a
particular field. It is used to calculate sub totals.
AT END OF <FIELD>:- This is triggered at the end of every new record based on a
particular field. It is also used to find out sub totals.
Both are used to find out subtotals but the difference is point of triggering.
1. At new is triggered at the starting of new record, but at last is triggered at the end
of the record.
2. At new checks previous record, but at last checks next record.
1. At new should be used inside the loop, but on change of can be used outside the
loop also.
2. At new takes only one field, but on change of can take multiple fields.
3. Let us assume that an internal table is having f1, f2, f3 , f4 and f5 fields and if at
new is applied on f3 field it will be triggered for every change in f1, f2 and f3
fields, but on change of will be triggered for only changes in f3.
Dialogue program is a screen with flow logic. Module pool program is used to
declare the variables that are needed in dialogue program and it is also used to write the
flow logic to handle user actions on the screen. For designing the screens the T-code is
SE51. For writing the module pool program the T-code is SE38, here the program type
should be chosen as module pool program. In module pool program it is mandatory that
the Module pool program name and dialogue program name should be same. Module
pool programs are not self executable. They should be executed using T-code. To create a
T-code we have to use T-code SE93.
PROCESS BEFORE OUTPUT:- This event is triggered before the screen is displayed.
This event is used to assign some default values to screen fields. With those values the
field will be displayed.
PROCESS AFTER INPUT:- This event is triggered after giving input to the screen
fields. This is used to handle user action actions on the screen.
The in the module pool program should be written between module and
endmodule.
SY-UCOMM:- It is a system variable used to catch the function code that is triggered
for user actions on the screen.
BDC programs are used to move the data from legacy system to SAP system. Old
system or non-SAP system is called legacy system. Most of the cases old data is used for
business analysis purpose, for taking intelligent business decisions. Some times it may be
used for reference purpose like paying taxes to the government or for paying dividends to
the share holders user etc.
Usually BDC programs are run in background. BDC programs take much time for
the execution which depends on the data to be uploaded. Basis people set the time for the
execution of a program. The program should be executed in the stipulated time set by the
basis people. If it is not executed in stipulated time the program goes to short dump. So
BDC programs can not be executed in the stipulated time set by basis people. By default
the standard time for the execution will be 10 minutes. There is no time constraint for
background jobs.
Second thing is BDC programs are not urgent programs. They are scheduled to
run at the time when server is usually free. Because of these two reasons BDC programs
are run in back ground.
SM36 T-code is used to run the programs in back ground. SM37 T-code is used
to see the output of back ground jobs. The output of back ground jobs is stored in spool
request number. SP01 T-code is used to see spool request numbers. Back ground jobs are
run at server level.
To create a variant for a program , enter the data in selection-screen fields and
press save button. System asks for name and description, give them and press save
button.
There are 5 steps for uploading the data from legacy system to SAP system.
1. Identify the file to be uploaded.
2. Move the data from flat file to internal table
3. Move data from internal table to data sets or application layer
4. Move data from data set to internal table
5. Move data from internal table to database.
Steps 3 and 4 are used when the BDC program is scheduled in back ground. Other
wise directly 1, 2 and 5th step.
Usually what ever the data that is needed to be uploaded will come to the desk
top. From there we try to upload the file into SAP database. Background jobs can not
recognize user’s desk top area, because they run at server level. Because of this reason
The logic will change based on the file to be upload. We have to remember that the
internal table used in BDC programs to get the data from flat file ( The uploading file)
should have all the fields declared as character type only. Otherwise junk values will
be uploaded. System will take care of conversion of data while uploading into data
base.
First we see the program to upload DAT file into internal table.
REPORT ZBDC .
parameters p_file type rlgrap-filename.
start-of-selection.
data p_file1 type string.
p_file1 = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = p_file1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart,
itab-maktx,
itab-meins.
endloop.
In this program I am trying to upload 5 fields into internal table. My input to this
program is file path. For declaration of file path variable I have used RLGRAP-
FILENAME as reference. RLGRAP is a structure and FILENAME is the filed present
in that structure which is 128 characters long. You can directly declare it as 128
characters variable. Why I am saying only 128 characters is in the function module
F4_FILENAME the file_name filed is declared as 128 characters field. Son the
receiving variable in the program should also be of 128 characters. Otherwise system
gives short dump saying type conflict error.
F4_FILENAME:- This function module is to get the file path directly from any part of
the computer by double clicking the file name. If this function module is not used we
have to give the file path manually.
GUI_UPLOAD:- This function module is used to upload the DAT file and comma
separated file into internal table.
The following file I have prepared as DAT file to upload into internaltable.
REPORT ZBDC .
parameters p_file type rlgrap-filename.
DATA: BEGIN OF ITAB1 OCCURS 0,
TEXT(70),
END OF ITAB1.
data: begin of itab occurs 0,
matnr(18),
mbrsh(1),
mtart(4),
maktx(35),
meins(3),
end of itab.
start-of-selection.
data p_file1 type string.
p_file1 = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = p_file1
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = itab1
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ITAB1.
SPLIT ITAB1 AT ','
INTO ITAB-MATNR ITAB-MBRSH ITAB-MTART ITAB-MAKTX ITAB-MEINS.
APPEND ITAB.
CLEAR ITAB.
clear ITAB1.
ENDLOOP.
loop at itab.
write: / itab-matnr,
itab-mbrsh,
itab-mtart,
itab-maktx,
itab-meins.
endloop.
SEQUENTIAL FILES.
Application layers files are called data sets or sequential files. All the application
layer files can be seen in AL11 Transaction code. If no path is given in the creation of
datasets the data will be stored in SAPUSERS directory. If path is given the data will be
stored in that path.
For moving the data or retrieving the data the sequential file or data set has to be
opened. The opened data set has to be close. For opening the data set the syntax is…
FOR OUTPUT:- If data set is opened in this mode we can send the data from internal
table to data set. If file is opened in this mode and if it is already present in application
layer the existing data in that file or dataset will be deleted and new data from internal
table goes into it.
FOR APPENDING:- In this mode also we can send the data from internal table to data
set. But the difference is if dataset is already present in application layer and if it is
containing data in it that will not be deleted . New records from internal table are added
or appended at the bottom of the data set.
FOR INPUT:- The dataset has to be opened in this mode to move the data from dataset
to internal table.
REPORT ZBDC .
parameters p_file type rlgrap-filename.
start-of-selection.
data p_file1 type string.
p_file1 = p_file.
LOOP AT ITAB.
TRANSFER ITAB TO 'TEST'.
CLEAR ITAB.
ENDLOOP.
DO.
READ DATASET 'TEST' INTO ITAB.
IF SY-SUBRC EQ 0.
APPEND ITAB.
CLEAR ITAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
LOOP AT ITAB.
WRITE: / ITAB-MATNR,
ITAB-MBRSH,
ITAB-MTART,
ITAB-MAKTX,
ITAB-MEINS.
ENDLOOP.
In this above program I did not give the file path for storing in application layer.
Hence it is stored in SAPUSERS directory.
If dataset is not closed and if it is opened in another mode the system goes to short
dump. Hence it is required to close the dataset after required operation is over. Then only
open in another mode.
Now we will see how to move the data into database.
There are 2 methods to upload the data into SAP.
Direct iput method
Batch input recording
BATCH INPUT RECORDING:- In this method we write our own programs to upload
the data into SAP.
For creation of any data in SAP, SAP has given standard transaction codes. Some
them are….
So we run the required transaction to create any thing in SAP. In these transaction
codes we will be entering the data into screen fields. Once you save the transaction the
data entered into screen fields will go and sit in the respective tables where they are
needed to be saved.
Let us analyze with MM01 transaction code. Once you enter into MM01
transaction code in the first screen you can see material number, Industry
sector(MBRSH) and Material type(MTART). Material number is not mandatory. If you
give the material number with that material number material will be created. Other wise
system generates material number. So give mechanical engineering in industry sector
filed and finished product in material type filed.
We know that MBRSH, MTART and MEINS fields are present in MARA table.
When you open the MARA table, against material 743 we can find the data entered in
MBRSH, MTART and MEINS fields. But MAKTX is present MAKT table. If you open
the MAKT table, the description that I have given for the material i.e. TATA SAFARI
can be seen there against the material number 743.
For this we require to know the program name of the T-code, Screen name and
filed name. If we know these things we can the send the data present in internal table into
screen fields. Finding all these things for individual fields to be uploaded is very difficult.
Because of this reason SAP has come up with a concept of recording. T-code for
recording is SHDB. Recording records every thing what we do on the screen. Recording
gives Program name, Screen number, Beginning of new screen indicator, Field name
and Field value. There should be a structure which is present with us which is containing
these 5 fields so that we can fill the values into those fields and send into recording steps.
The standard structure is BDCDATA.
There are 2 methods to upload the from legacy system to sap system.
1. Direct input method
2. Batch input recording
In each of these methods we are having internally 3 methods.
1. Call transaction method
2. Session Method
3. LSMW (Legacy System Migration Workbench)
1. SHDB
2. Press New Recording
3. Giving recording name
4. Give T-code to be recorded
5. Press start recording
6. Execute the T-code until save
7. Save the tabular format generated
8. Back
9. Select the recording name
10. Press program button
11. Give program (System will generate the program with that name)
12. Select radio button transfer from recording
13. Enter
14. Give Title
15. Press source code
16. Give package and save
17. Enter (You can see the program generated)
18. Select the program from the line after perform open_group.
19. Till a line above transaction code and copy
20. Paste it between loop at endloop in the program which you have written for
uploading the data from flat file to internal table.
21. Copy the from the include present in the recorded program and paste at the
bottom of the program.
CALL TRANSACTION
In this method we use one statement between loop and endloop after recording
steps.
In all screen mode we can see all the screens in front of us with fields filled in with
values. In every screen we have to presenter. In Error screen mode we can see only error
screens. Correct the errors and press enter. In NO screen mode we can’t see any screen in
front of us.
1. Synchronous (S).
2. Asynchronous (A)
3. Local (L)
Synchronous:- In this update mode for every the control will wait until all the main
tables and child tables are updated. Then only next starts moving into database.
Asynchronous:- In this mode the next record starts moving into database after previous
record is updated into some of the tables. The control will not wait until all the main
tables and child tables are updated for every record.
Local:- In this data is stored in local work process and then it is later updated into
database.
In call transaction method the user has to handle the errors while uploading the
data into database. You can see the following program with call transaction.
report ZBDC100 .
START-OF-SELECTION.
DATA P_FILE1 TYPE STRING.
P_FILE1 = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = P_FILE1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = ITAB
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* OTHERS = 17
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ITAB.
INDEX = SY-TABIX.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MBRSH'
ITAB-MBRSH.
perform bdc_field using 'RMMG1-MTART'
ITAB-MTART.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
ENDIF.
REFRESH BDCDATA.
ENDLOOP.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM.
When ever there is an error in the record the call transaction statement written will
be failed. That is the reason I have used there sy-subrc.
SESSION METHOD.
In session method the data will be stored intermediately in session. After processing
the session only the data will be moved into data base. For processing the session the
T-code is SM35.
SESSION:- It is an intermediate memory area where data with flow logic is stored. It is
intermediate between internal table and data base table. A session can not be processed
on the date on which it is created. A session can not be processed if it is processed
successfully. If session is having error it can be processed any number of times.
BDC_INSERT:- This function module is used to move flow logic and data into session.
This function module should be called between the loop and endloop after recording
steps.
start-of-selection.
data p_file1 type string.
p_file1 = p_file.
DATE = SY-DATUM - 1.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'ZUSA'
HOLDDATE = DATE
* KEEP = 'X'
USER = SY-UNAME
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
* EXCEPTIONS
* CLIENT_INVALID = 1
* DESTINATION_INVALID = 2
* GROUP_INVALID = 3
* GROUP_IS_LOCKED = 4
* HOLDDATE_INVALID = 5
* INTERNAL_ERROR = 6
* QUEUE_ERROR = 7
* RUNNING = 8
* SYSTEM_LOCK_ERROR = 9
* USER_INVALID = 10
* OTHERS = 11
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ITAB.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
* ENDIF.
ENDFORM.
If you want to move the data into database you have to go to sm35 T-code and
process the session ZUSA. Then only the data will be moved into data base.
This is the tool given by SAP to upload the data from legacy system to SAP
system. There are 4 methods available in this LSMW.
1. Direct input method
2. Batch input method
3. Business document method (BAPI)
4. Intermediate document method (IDOC)
In LSMW we have different steps. We have to run the steps sequentially
so that the data will move into data base. The below example will give you clear cut idea
about the steps present in LSMW, How to run them. In this example I have used direct
input method to upload customer master data into database using SAP standard program.
Note! For the Demo example 2, I will list only those steps that are different from the first
demo example.
You will be updating the customer master records with the help of Standard Batch Input;
therefore, choose radio-button Standard Batch/Direct Input as shown in Figure 21.
Enter Object ‘0050’ for Customer Master records and default method ‘0000’ and click on
Save.
In this step, you need to list what fields are present in the source structure. The easiest
way is to click on ‘Table Maintenance’ icon to enter Fieldname, Type and Length for
each field as shown in Figure 9.
Note that your input file will have four fields as key fields and you need to update three
fields in the system.
Sales view of Customer Master is stored in table KNVV. Accordingly, you need to
update structure BKNVV. However, in addition, the Standard Object ‘0050’ also requires
updates to BGR00, BKN00 and BKNA1 structures. (If you do not maintain Structure
relations for mandatory entries, you might get a message such as ‘Target structure
BKNA1 needs a relation to a source structure’.)
Even though you don’t want to update any fields in these structures, you need to create a
relationship with source structures. In all, you need to create relationship for four target
structures.
Create relationship between source structures XD02S with these target structures with
icon ‘Create Relationship’
Keep Cursor on these four target structures and click on icon ‘Create Relation’ and
structure relations are maintained as shown in Figure 22.
-- Keep your cursor on ‘TCODE’ field and click on ‘Insert Rule’ icon
Choose radio button ‘Constant’ (Figure 23) to enter value ‘XD02’ transaction code.
-- Keep your cursor on field ‘KUNNR’ and click on ‘Assign source field’
icon
Choose source field ‘Customer’ from source structure ‘XD02S’. (See Figure 24.)
-- Similarly, choose source fields for Sales Organization, Distribution Channel, and
Division. (See Figure 25.)
-- Scroll down to structure BKNVV fields and assign source fields to three fields Sales
Office, Sales Group, and Customer Group (Figure 26).
You can also maintain re-usable translations and user-defined routines, which can be
used across conversion tasks. In this case, that step is not required.
In this step, we define how the layout of the input file is. The input file is a [Tab]
delimited with the first row as field names. It is present on my PC (local drive) as
C:\XD02.txt. (See Figure 13.)
Create an Excel file (Figure 14) with your data and save it as a Tab-delimited text file on
your local drive (C:\) and name it XD02.txt.
Execute step ‘Assign Files’ (Figure 15) and the system automatically defaults the
filename to the source structure.
In this step, LSMW reads the data (Figure 16) from the source file (from your PC’s local
drive). You have the option to read only selected rows and convert data values to Internal
format.
This step (Figure 17) is optional. If required, you can review the field contents for the
This is the step that actually converts the source data (in source format) to a target format.
Based on the conversion rules defined, source fields are mapped to target fields.
When you convert data, LSMW automatically converts into the appropriate structure
layouts, as required by Standard program (RFBIDE00). (See Figure 27).
Note that if you had only one record in source file, the converted file has four records.
Once source data is converted in internal format, you can create a BDC session to process
the updates (Figures 28 and 29).
You can execute the BDC session by Run Batch input session. Executing a batch input
session is a standard SM35 transaction for managing BDC sessions. Once you have
successfully executed the batch input session, the customer master records are updated in
the system. You can confirm this by viewing the customer master records (XD03).
No where in LSMW steps system asked for package. If package is asked , if we give the
package name system gives Transport request number (TRN). Using this TRN we can
move the object from one server to another server. But for LSMW we have to create
TRN manually. For that we have to follow the following path.
It is the integrated text management system of SAP. The output of scripts and
normal report will be same. But formatting is very easy using scripts. Usually scripts are
used for external purpose and reports are used for internal purpose. When specific format
is required in output we go for scripts.
In scripts we require layout set and print program. Layout set is used for
designing the output. That is page designing is done here. For this Transaction code is
SE71 (form painter).
Print program is used for writing the logic to get the data from data base. It is an
executable program which is written in SE38 T-code.
WINDOWS:- I t is a place on the page where output or data is formatted. Page has to be
divided into windows in order to hold the output. We can’t format the output outside the
windows. Windows is repository of windows.
Paragraph formats and Character formats are used for alignment or beautifying the
output.
TYPES OF WINDOWS
MAIN WINDOW:- The window which can hold continuous text or which can call
page break is called main windows. When ever you are not sure of how much data you
are going to get into a window that window has to be created as main window.
CONSTANT WINDOW:- A window whose size and contents will not change from
page to page is called Constant window.
VARIABLE WINDOW:- A window whose size or contents will change from page to
page is called variable window.
1. T-code SE71
2. Give form name
3. Give language
4. Press create button
5. Give description
6. Press page button
7. Give page name
8. Press enter
9. Give page description
10. Give next page name
This is how we have to design the page. The no of windows in the page depends
on page layout. Now I want to keep a logo in one of the windows of page. For that we
first have to upload the logo into sap. For uploading logo into sap the T-code is SE78.
It is used to upload only Bitmap images.
The image will be uploaded into SAP with the name you have given in 7th step.
1. Go to Se71
2. Open the form in change mode
3. Select the window where you need to insert the logo ( for selecting double click)
4. Press text elements button
5. Insert Graphics
6. Press tab stored on document server
7. Give the logo name
8. Choose Black and white or color
9. Enter
10. System by default gives this code
11. BITMAP 'ENJOY' OBJECT GRAPHICS ID BMAP TYPE BCOL
12. Here enjoy is the logo name I have given
Now we will discuss how to write the print program. Print program is used to get
the data from data base and move the page windows of the form. In writing the print
program we have to take the help of 3 function modules.
REPORT ZFORM .
TABLES MARA.
SELECT-OPTIONS S_MATNR FOR MARA-MATNR.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MARA-MATNR,
MBRSH TYPE MARA-MBRSH,
MTART TYPE MARA-MTART,
NTGEW TYPE MARA-NTGEW,
BRGEW TYPE MARA-BRGEW,
END OF ITAB.
SELECT MATNR
MBRSH
MTART
NTGEW
LOOP AT ITAB.
In the above program I have used element in write_form function module. When
we are moving the data into form windows there should be something to receive it. We
are sending using element ELE. The receiving element name should be ELE. The code
that is to be written in form window text element where it is needed to be printed is…..
We see the detailed use of standard text. Let us assume that my company wants to
give 10% discount on sales. In my implementation let us assume that I am having
100 forms. In these 100 forms I want DISCOUNT ALLOWED 10% at the bottom
of every form. So I write this statement in every form. Let us assume that the discount
is now changed to 20% instead of 10%. So now I have to go to every form and I have
to change discount 20%. But this is a laborious job. If you insert the standard text in
100 forms instead of hard coding., we can simply change the standard text when ever
the text is changed. The changes will be reflected in every form where the standard
text is used.
1. T-code SO10
2. Give name and press create
3. Give the text
4. Press save
1. Go to Se71
2. Open form in change mode
3. Select the window where standard text is needed to be inserted
4. Press Text elements button
5. Insert text standard
6. Give text name
7. Press enter
1. Scripts are client dependent but smart forms are client independent.
2. Scripts are not self executable i.e. print program is compulsory, but smart forms
are self executable. On executing the smart form system generates function
module.
3. We can not write the logic in scripts but we can write the logic in smart forms.
4. Main window is compulsory in scripts but it is optional in smart forms.
5. Background logo is not possible in scripts but it is possible in smart forms.
6. There are character and paragraph formats in scripts but there are no character and
paragraph formats in smart forms
7. Labels are present in scripts but no labels in smart forms.
When ever you enter into smartforms under global settings you get three things.
1. Form attributes
2. Form interface
3. Global definitions
FORM INTERFACE: - The variables that are needed to be populated at run time should
be declared here.
GLOBAL DEFINITIONS:- The variables that are needed in the smart form should be
declared here.
1. T-code smartforms
2. Press create button
3. To create logo window right click o page create Graphic
4. Give the logo name
5. The variables that are needed to be populated at run time should be declared under
form interface
6. The variables that are needed to be populated at run time should be declared under
Global definitions.
7. To write the select query or logic select the window right click create flow
logic program lines
8. It is mandatory to give input parameters and output parameters
9. To write loop select the code Right click create flow logic - loop
10. To write the output select loop Right click Create Text
11. Check for errors
12. Activate and Execute
13. Function module will be generated. Execute it
14. Give printer name LP01 (Default Printer)
15. Press print preview to see output
ENHANCEMENTS
These are used to add extra intelligence to SAP standard programs to suit the
business requirements. If we want to add extra code to SAP standard programs, if we go
for change mode system asks for access key. Instead of this, SAP has provided hooks
where we can write the code. These hooks are enhancement spots. If a code is written in
theses spots along with the normal program the code written in these spots is also
executed. There are two ways to enhance the SAP standard code.
1. User Exits
2. BADIS (Business Addins)
If user exits are used one time in any project it can not be reused. But Badis can
be used any no of times.
Exits are defined at package level. So we want to enhance any T-code first we
have to find out the package for that T-code. Then we have to find out the exits present in
that package. For finding the exits present in a package we have to use SMOD T-code.
After finding the suitable exit for writing the code we have to use CMOD T-code.
STEPS IN SMOD
1. T-code SMOD
2. Press F4
3. Press information system
4. Give the package name found out previously
5. Press enter
6. Based on the description choose the relevant Exit
STEPS IN CMOD
1. T-code CMOD
2. Give project name
3. Press create button
4. Give description
5. Press enhancement Assignments button
6. Give the exit name you have found in SMOD
7. Press components button
8. Double click exit
9. Double click include starting with Z
10. Press enter
11. Write the logic
12. check for errors and activate
13. Come back to the first screen of CMOD and activate the project.
Badis are also used to enhance SAP standard programs. These are based on OOPs
concepts. In these BADIs we take the help of SE18 and SE19 T-codes.
SE18 T-code is like SMOD which is used to find out the relevant BADI and SE19
T-code is used to write the logic. Like user exits BADIs are also defined at package level.
If you want to find out the BADI for any program first we have to find out the package in
which the program is stored, as we have found out in our exits.
STEPS IN SE18
1. T-code SE18
2. Press F4
3. Press In formation system
4. Give the Package
5. Press enter
6. Choose the relevant BADI.
STEPS IN SE19
1. T-code SE19
2. Give some implementation name
3. Press create button
4. Under definition give the BADI name found out in SE18
5. Give description
6. Press interface Tab
7. Double click method
8. Write the code between method and endmethod and save
9. Press back
10. Double click name of implementation class
11. Activate
12. Press back
13. Active the Implementation
ALE:- It is set of configurations made to transfer data from one system to another
system. Actually ALE forms a route between two systems. In that route Idoc will
travel.
STRUCTURE OF IDOC
CONTROL RECORD:- It is like address on the post card which gives the information
about sender, receiver and type of data the idoc is holding. It will be always single record.
STATUS RECORDS:- It specifies about the actual position of the idoc. As idoc travels
different mile stones system gives different statuses. Using the status of the idoc we can
find out the position of the idoc.
MASTER IDOC: - The data that is to be transferred is fetched from data base and
formatted into Idoc format. This Idoc is called master Idoc. This Idoc is not stored in data
base. This Idoc is not transferred. It’s life span is until communication Idocs are created.
MESSAGE TYPE:- This specifies about the type of data the Idoc is holding. The
standard message types are …
1. MATMAS Material master data
2. CREMAS Vendor master data
3. DEBMAS Customer master data
PORT:- it specifies about how the data should be transferred from source system to
destination system. Transaction code for Port creation is WE21.Two important ports are..
1. T-RFC Port (Transactional RFC Port)
2. File Port
In T-RFC port the data will be moved in the form of memory buffers. In file port the
data will be transferred in the form of files.
For generation of Idocs SAP has given standard T-codes based on the type of data
you are going to transfer. The important T-codes are.
1. BD10 Material master push
2. BD11 Material master pull
3. BD12 Customer master push
4. BD13 Customer master pull
5. BD14 Vendor master push
6. BD15 Vendor master pull
You have to either run push or pull T-code. No need to run both the programs. If
you want to send the data from source system run push T-code. If you want to get the
data from destination system run pull T-code.
To view the idocs use either WE02 or WE05 T-codes. T-code WE19 is the
testing tool for Idoc. T-code BD87 for mass processing of Idocs.