SlideShare a Scribd company logo
1
ABAP…
2
Sap architecture
 If you use the possibilities of the distributed R/3 system according to the client/server
methodology, then the R/3 components are spread across a three-tier CPU hierarchy.
The database server is installed on a central computer, which means the processes
representing the database service run here. This computer also houses at least the R/3
update service, that is, this CPU is responsible for all database changes. Multiple application
servers can be connected to the dabase server. The application servers process the actual
application logic.
Multiple front-ends (workstation, PC) on which the users are working can then connect to
each application server. The individual front-ends handle all presentation tasks.
 SAP AG
Central DB
(stores all data and
application programs)
R/3 Client/Server – Three-Level Computer
Hierarchy
User interaction
Application logic
Database update
Central DB
buffer
Input data
from the user
Output data to
the user
Read database and
update buffers
Object-
oriented
change
requests
(asynchronous)
3
 R/3 Basis configurations:
A: Central system with centrally installed presentation software
B: Two-tier client/server system with distributed presentation software
C: Two-tier client/server system; presentation and application run on the same computer
D: Three-tier client/server system; presentation, application, and database each run
on their own computer
 The central process of the application server is the SAP dispatcher as central control. The
SAP dispatcher, together with the specific operating system, manages the resources for the
R/3 applications
 The main tasks of the dispatcher include:
 S A P A G
R / 3 C l i e n t / S e r v e r C o n f i g u r a t i o n s
T h r e e - t i e r
c l i e n t / s e r v e r
D i s t r i b u t e d
p r e s e n t a t i o n
T w o - t i e r
c l i e n t / s e r v e r
S A P R / 3 S y s t e m
P r e s e n t a t i o n A p p l i c a t i o n D a t a b a s e
C e n t r a l s y s t e m
 SAP AG
The SAP Dispatcher
Presentation
Application
Buffer
Database
Communication
SAPGUISAPGUI SAPGUISAPGUI
Work
process
Work
process
Work
process
Dispatcher
4
evenly distributing the transaction load among the work processes, interfacing with the
presentation level, organizing the communication activities.
 The dispatcher carries out the following tasks during initialization
reading profile parameters, creating and initializing semaphores, generating roll areas,
starting work processes, logging on to the message server.
 The user entries on the screen are received by the SAP presentation program SAPGUI which
converts it into its own format and sends it to the dispatcher.
 The dispatcher manages the information exchange between the SAPGUI and the work
processes, whereby all users share a few work processes.
 The dispatcher first stores the processing requests in request queues and then processes
them.
 The dispatcher dispatches the requests one after the other to free work processes. The
actual processing is done by the work processes.
 At end of processing, the dispatcher returns the results of a work process back to the SAPGUI
who interprets the data and generates the output screen.
 SAP AG
Dialog Step Dataflow
Application
Presentation
Database
Relational
database system
Request queues
SAPGUI
ROLL
222
444
555
Terminal
process
Dialog object
333
666
111
777
Work
process
5
DATA DICTIONARIES
6
Table Types
DATA BASE : Store the data base permanently until deleted. These tables are classified into 3
types
1.) Transparent Table
2.) Pooled Table
3.) Clustered Table
7
Transparent Table: Exists with the same structure both in dictionary as well as in database exactly
with the same data and fields.
Pooled Table: Pooled tables are logical tables that must be assigned to a table pool when they are
defined. Pooled tables are used to store control data. Several pooled tables can be combined in a
table pool. The data of these pooled tables are then sorted in a common table in the database.
EG: All Condition tables i.e., Annn tables (pricing/discounts etc.,) belong to the table Pool KAPOL
(Condition Pool) as the underlying concept is same across different condition tables, but, they have
different Key (primary) fields.
Cluster Table: Cluster tables are logical tables that must be assigned to a table cluster when they
are defined. Cluster tables can be used to store control data. They can also be used to store
temporary data or texts, such as documentation.
EG: Accounting Document Segment (Line Item records) BSEG is a cluster table that belongs to the
table cluster RFBLG. Also, other tables such as BSEC, BSED, BSES, BSET also come under the same
table cluster as all of them possess the common Key i.e., BUKRS/BELNR/GJAHR. And CDPOS
(CDCLS)
BSEC - One-Time Account Data Document Segment, BSED- bill of exchange Fields Document
Segment
BSEG-Accounting Document Segment, BSES-Document Control Data, BSET-Tax Data Document
Segment
Pooled and Cluster Tables Differences
Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The
data from several different tables can be stored together in a table pool or table cluster. Tables
assigned to a table pool or table cluster are referred to as pooled tables or cluster tables.
A table pool or table cluster should be used exclusively for storing internal control information
(screen sequences, program parameters, temporary data, continuous texts such as
documentation). All data of commercial relevance is stored exclusively in transparent tables!
Table Pools
A table in the database in which all records from the pooled tables assigned to the table pool are stored
corresponds to a table pool.
The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument
field (Vardata). A pool has the following structure:
Field Data type Meaning
Tabname CHAR(10) Name of pooled table
Varkey CHAR (n) Contains the entries from all key fields of the pooled table record
as a string, max. length for n is 110
Dataln INT2(5) Length of the string in Vardata
8
Vardata RAW (n) Contains the entries from all data fields of the pooled table record
as a string, max. length n depends on the database system used
If a pooled table record is saved, it is stored in the table pool assigned. The name of the pooled table is
written to the field Tabname. The contents of all key fields of the pooled table are written as a string to
field Varkey and the contents of all data fields as a string to field Vardata. The length of the string stored
in Vardata is entered in field Dataln by the database interface
Due to the
structure of a table pool, there are certain restrictions on the pooled tables assigned to it. The name of a
pooled table may not exceed 10 characters. Since Varkey is a character field, all key fields of a pooled
table must have character data types (for example, CHAR, NUMC, CLNT). The total length of all key
fields or all data fields of a pooled table must not exceed the length of the Varkey or Vardata field of the
assigned pool.
Table Clusters
Several logical data records from different cluster tables can be stored together in one physical record in
a table cluster.
A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing
continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data
fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are
created. Control information on the structure of the data string is still written at the beginning of the
Vardata field. A table cluster has the following structure:
Field Data type Meaning
CLKEY1 * First key field
CLKEY2 * Second key field
... ... ...
CLKEYn * nth key field
9
Pageno INT2(5) Number of the continuation record
Timestamp CHAR(14) Time stamps
Pagelg INT2(5) Length of the string in Vardata
Vardata RAW (n) Contains the entries from the data fields of the assigned cluster
tables as a string, max. length n depends on the database system
used
The records of all cluster tables with the same key are stored under one key in the assigned table
cluster. The values of the key fields are stored in the corresponding key fields of the table cluster. The
values of all data fields of the assigned cluster tables are written as a string to the Vardata field of the
table cluster. Besides the actual data values, the data string contains information on the structure of the
data and which table it comes from. If the string exceeds the maximum length of the Vardata field, a
continuation record is written with the same key values. The continuation records for a key are
distinguished by their value in field Pageno. The actual length of the string in the Vardata field is stored
in the Pagelg field by the database interface.
You need the structural information stored in the ABAP Dictionary to read the data from a pooled table or
cluster table correctly. These tables can therefore only be processed using Open SQL with the cluster
interface, and not with Native SQL directly in the database.
10
Transparent Pool Cluster
Contain a single table.
Used to store master
data
They are used to hold
a large number of
very small
tables(stores
customizing data or
system data)
They are used to hold
data from a few
number of large
tables.(stores system
data)
It has a one-to-one
relationship with a
table in the database
It has a many-to-one
relationship with a
table in the database
It has a many-to-one
relationship with
table in the database
For each transparent
table there is one
associated table in
the database
It is stored with other
pooled tables in a
single table called
table pool in the
database
Many cluster tables
are stored in a single
table in the database
called a table cluster
The database table
has the same name,
same number of fields
and the fields have
the same names
The database table
has different name,
different number of
fields and fields have
different names
The database table
has different name,
different number of
fields and fields have
different names
There is only a single
table
Table pools contain
more tables than
table clusters
Contains less tables
than table pools
Single table can have
one or more primary
key
Primary key of each
table does not begin
with same fields or
fields
Primary key of each
table begins with
same fields or fields
Secondary indexes
can be created
Secondary indexes
cannot be created
Secondary indexes
cannot be created
They can be accessed
using open and native
SQL
They can be accessed
using open SQL only
They can be accessed
using open SQL only
USE: They are used to
hold master data e.g.
Table vendors or
table of customers.
Example of
transaction data is
orders placed by
customers
USE: They reduce the
amount of database
resources needed
when many small
tables have to be
opened at the same
time
USE: They would be
used when the tables
have primary key in
common and data in
these tables are all
accesses
simultaneously
11
IMPORTANT CONTROL PROPERTIES OF TABLE
1) Delivery class: The delivery class controls the transport of table data when installing or
upgrading, in a client copy and when transporting between customer systems. The delivery class is
also used in the extended table maintenance.
Example
A: Application table (master and transaction data). C: Customer table, data is maintained by
the customer only.
L: Table for storing temporary data.
2.) Data class in technical settings: The data class defines the physical area of the database
(for ORACLE the TABLESPACE) in which your table is logically stored. If you choose a data class
correctly, your table will automatically be assigned to the correct area when it is created on
the database.
Important table spaces are:-
 APPL0 --- Master data
 APPL1 --- Transaction data
 APPL2 --- Organizational and customizing data
3.) Size category: The size category determines the probable space requirement for a table in
the database.(0 to 9).
Example: If size category 0 means 100 records. Then as a group sap stores a max of 100
records. If this is filed one more space equivalent to 100 records will be allocated
Note: if we store the records in too many places retrieving the records will be slower, so
choose appropriate size category
4.) Display Maintenance:
12
This property Defines if the user can manipulate / Display the data directly on the table level
 Allowed :- the user can directly manipulate(Create / Modify) directly on the table.
 with Restriiction:- The user is not allowed to manipulate but he can only display .
 Not Allowed:- The user can not manipulate or display the records. The separate program
should control the display and manipulation.
5.) Buffering status: Buffering specifies whether the records 1.) Buffering not allowed,
2.)Buffering allowed but not activated and 3.) Buffering Switched on.
Single-record buffering
With this kind of buffering, only the records of a table which are actually accessed are loaded
into the buffer.
This kind of buffering requires less storage space in the buffer than full buffering. However,
greater organization is necessary and considerably more database accesses are necessary for
loading.
ABAP Program
Select Query
Database interface
R/3 Database
table buffer
Database
buffer
Application
Server
Database
Server
Database
Fig.1. Database Table buffering
13
If an as yet unbuffered record is accessed with SELECT SINGLE, a database access occurs to
load the record. If the table does not contain a record for the specified key ('no record found'),
this record is noted as nonexistent in the buffer. If a further attempt is made to access this
record, a renewed database access can be avoided.
When should single-record buffering be selected?
 For large tables where there are frequent single-record accesses (with SELECT SINGLE
...). The size of the records being accessed should be between 100-200 KB.
 For comparatively small tables for which the access range is large, it is normally
advisable to opt for full buffering. Only one database access is required to load such a
table for full buffering, whilst single-record buffering calls for a very large number of
table accesses.
Generic buffering
In a read access to a record of a generically buffered table, all the records whose left-justified
part of the key (generic area) corresponds are loaded into the buffer.
If this type of buffering is selected, the generic area must be defined by specifying a number n
of key fields. The first n key fields of the table then define the generic key.
The number of key fields to be entered must lie between 1 and the number of key fields -1. For
example, only values between 1 and 5 are permitted for a table with 6 key fields.
When should generic buffering be selected?
 A table should be buffered generically if usually only certain areas of the table are
required. The individual generic areas are treated like independent tables which are
fully buffered. Please also read the text about full buffering.
 The generic key area should be selected so that the generic areas are not too small to
prevent too may generic areas being produced. If there are only a few records per
generic area, it is more efficient to use full buffering.
 Generic buffering only makes sense if the table is accessed by a specified generic key.
If, when an access takes place, a field of the generic key is not supplied with a value,
the buffer is ignored and the records are read directly from the database.
 Language-specific tables are an example of a good use of generic buffering (with the
language key field as generic key area).
Full buffering
With full buffering, either the complete table or none of the table is in the buffer. If a read
access is made to a record, all records of the table are transferred to the buffer.
When should you select full buffering?
14
 For tables up to 30 KB in size. If a table is accessed frequently, but all accesses are read
accesses, this value can be exceeded.
 For larger tables where large numbers of records are frequently accessed. However, if
the application program is able to formulate an extremely selective WHERE condition
using a database index, it may be advisable to dispense with full buffering.
 For tables with frequent accesses to data not contained in the table. Since all records
are contained in the buffer, a quick decision can be made as to whether or not the
table contains a record for a specific key.
When considering whether a table should be fully buffered, you should take three aspects into
account: the size of the table, the number of read accesses, and the number of write accesses.
Tables best suited to full buffering are small, frequently read, and rarely updated.
Buffering of database tables is a technique in which the data from database table is copied
into the local storage place in application server, known as buffers. Hence the subsequent
requests for data is instead fetched from the buffered tables rather than actually accessing the
database tables. This in turn increases the performance by reducing the database hit time.
Database table buffering:
For the first time when data from a DB Table is requested, database interface hit the database
to fetch the data. However if the table is buffered one then the data from the table is filled
into the buffer also. Hence for all subsequent requests of data from the same table the data is
fetched from buffer.
Limitations:
Only transparent table and pooled tables can be buffered. Clustered tables can not be
buffered. The key fields of the buffered tables need to be mapped to one of the ABAP types C,
N, D or T.
Table buffering types:
Three types of buffering are allowed for any table.
 Full table Buffering.
 Generic Buffering with no of keys
 Single record Buffering
Implementing Table buffer
Different types of buffering are explained with example below:
15
Full table Buffering:
Full table buffering as the name suggest is to get all the data of a table into the buffer space.
When a SELECT statement is executed on the given table for the first time it hits the database
to get the data and also fills the table buffer in the application server. But all the select
statements requesting the data from this table will fetch it from the buffer.
Example:
Fig.2. the table ZZZ_EMP_PROJ
Let the table zzz_emp_proj be a database table that is not buffered.
Then for the select query of simple type that selects all the values from this table will
directly hit the database to fetch the data.
The following SQL trace list shows how much duration it takes to get the data from the
database.
Fig.3. SQL trace list showing database fetch time when table is not buffered
16
Now let us change the technical settings of the table to Full Table Buffering. Then for all the
select statements which do a select on the table zzz_emp_proj we will have the following
characteristics, i.e. for the first time it will fetch from the database. Then it will buffer the
whole table data, so for subsequent requests data is fetched from the buffer. That reduces the
fetch time drastically. We can see from bellow screen shot of the SQL trace list the yellow lines
are for database hit. The rest are within application server only.
Fig.4. Technical Setting for Full Table Buffer
Fig.5. SQL Trace showing the duration of select statement executed first time in a fully
buffered table
17
Fig.6. SQL trace showing data fetched from buffer for subsequent select statement
18
Full buffering is preferred in the following cases.
 If a table is accessed frequently for read purpose mostly then it is advisable to go for
full table buffering
 If a table is accessed more often to check whether an entry is available or not, those
kinds of tables could be fully buffered so that it will be checked in the buffer without
going into the database
 Primarily small tables with frequent read access and with very less probability of
written on to, are best suited for full table
 SAP suggests tables of size below 30 KB should be fully buffered. However this could be
applied to larger tables depending on number of read and write attempt.
 Sometimes it is also advisable to avoid buffers if a well formulated WHERE statement
could be written based on the indices of the db table.
Generic table Buffering:
When a table is buffered generically based on certain keys then the records containing the
given values for these keys are copied into the buffer. So for those select statements with fully
specified generic keys it gets the data from Buffer. If the key is not assigned a value in the
select statement then the statement will bypass the buffer and select it from the database. It is
always an important factor to decide the key of generic buffering. If we chose a key with small
variation then while buffering large amount of data will come into the buffer. This in turn will
increase the fetch time of data.
Example:
Let us again take the same database table zzz_emp_proj and which is buffered generically on
the first key that is project.
Fig.7. Here we can see the table we used
for our example for full table buffering
zzz_emp_proj. This table will get
buffered totally as we have maintained
full table buffer in the technical settings
of this table
19
Fig.8. Table is Generic Area buffered with no of key fields 1
Then for the select query with certain value of project it will select those part of data for which
the key contains the given value from database and put them in buffer. For all subsequent
queries where the key value does not change it will go to the same place and get the data
without hitting the database.
Suppose we select all entries from this table
zzz_emp_proj where project is ‘DCSAPMNT’
and location is ‘Bangalore’ then it gets the
data from database for the first time and
populate the buffer with the values where
project is ‘DCSAPMNT’. As we have
maintained the technical settings of this
table as ‘generic buffer with no of keys 1’.
Hence for next time whenever it goes to get
the data with the same key value it will be
fetched from the buffer itself Hence you can
see the difference of time in following two
screen shots.
Fig.9. data that will be buffered for the given table
20
Fig.10. Shows the db hit time for execution of select for the first time
Fig.11. Shows the decrease in total duration for fetch data as it is being fetched from buffer.
From these two SQL trace list above we can understand how drastically the fetch time
decreases if fetched from the buffer. The yellow lines indicate the database hit and light blue
lines indicates that the data is fetched from buffer.
21
Single record Buffering:
Single record buffering will buffer only one
record in the application server. Hence for
the first selection statement it buffers the
records selected. And in case of
subsequent selections it gets the value
from the buffer. If you change the select
query in order to get some different lines
then it will fetch the data from database.
Similarly if the select query selects more
than one line then the buffer is overlooked
and data is fetched from the database
table.
Example:
The select query selecting one record from
table zzz_emp_proj which is not buffered
presently.
Fig.12. example of data selected in table
for single record buffering
Fig.13. Technical settings for single record buffering
22
Fig.14- zzz_emp_proj table Without Buffering.
Fig.15. after buffering first time selection
Fig.16. After buffering subsequent time selection data fetched from buffer.
These SQL trace lists show how the duration has decreased in the buffering of the table.
Technically single-record buffer contains central administrative structure, a table directory and
the data area. The table names are stored in alphabetical order and the data area is organized
in frames of fixed size. While searching the buffer a binary search is done in the table directory
then in the corresponding frames to get the records. Single record buffering also stores
information about the nonexistent record of database table, by using a flag. So single record
buffering is advisable when again and again we are accessing nonexistent records of data base.
However depending upon our requirement we can chose our buffering so that it will increase
the performance of the program as a whole.
23
24
Synchronization Issue:
The buffer is present in the application server. The data is copied into the buffer and for
subsequent selection it fetches the data from this storage. However any modification to the
database has to be reflected onto these buffers in application servers. Therefore we have
following two ways in which the buffer is synchronized.
Synchronous scenario: Whenever the database is updated corresponding to some buffered
table it floods the information across the applications servers those have buffered the values
of tables. This might lead to inconsistency of the data as this process is highly dependant on
the network’s reliability.
Asynchronous Scenario: the data is modified in the database table but is not updated to the
corresponding buffers in the application server. However a table DDLOG in the central
database is updated with these modifications. The application servers holding the buffers poll
at this table in certain time intervals. If it finds the modification in the given table relevant to
its buffers then it clear the corresponding buffer. So next time the select query executes the
data is fetched from the database table and buffered.
Avoiding Buffer:
In certain cases we might need to avoid buffers and directly fetch the data from database
table which might be more time effective. The following select queries do not make use of
the buffer even if the corresponding table is buffered.
i. SELECT... BYPASSING BUFFER
ii. SELECT with aggregate function (COUNT, MIN, MAX, SUM, AVG)
iii. SELECT DISTINCT
iv. SELECT... WHERE... IS NULL
v. ORDER BY (with the exception of PRIMARY KEY)
vi. SELECT FOR UPDATE
vii. All access through the Native SQL also by pass the buffer
25
Domain: A domain describes the technical attributes of a field, such as the data type or the
number of positions in a field. The domain defines primarily a value range describing the valid data
values for the fields referring to this domain.
Different technical fields of the same type can be combined in a domain. Fields referring to the
same domain are changed at the same time when a domain is changed. This ensures the
consistency of these fields.
Data elements : (elementary types)
Elementary types have no structure. They describe the data type attributes (such as given
Dictionary data type, number of places) and information that is relevant for the screen (such as
title) of unstructured data objects (variables/fields).
Creation of Transparent Table
1. Enter the table name and press Create
2. Enter the description, Delivery class and check on table maintenance allowed. Then click on the
tab Fields.
26
3. Enter the ZCHAR in fields tab and ZCHAR_DE in field type tab.
4. Double click on ZCHAR_DE. Then it will ask for Save. Press ‘YES”.
27
5. Save it as a local object on pressing Local object button
6. Now it will ask for the creation of the data element. Press Yes.
28
7. Click on the Field label tab and enter the lengths and descriptions accordingly.
8. Then press Definition tab and enter the domain.
29
9. Double click on that zchar_d to create domain, then it will ask for save before going next screen.
Press Yes.
10. Save it as a local object.
30
11. Now it will ask for domain creation. Press Yes.
12. Give short description for that domain which you are creating. And mention the data type in data
type field and length in no. characters field an press ENTER.
31
13. Then press Ctrl+F3. It will ask for save before activation. Save it as a local Object.
14. Press Enter.
32
15. Then the following screen appears. Press on back button.
16. Press Ctrl+F3. You will get the following screen. Press Back button.
33
17. You will get the following screen.
34
18. Create one more field ZNUM and give data element name as ZNUM_DE. And double click on
‘ZNUM_DE’
19. Save it by pressing Yes.
20. Now it will ask for the data element creation. Press Yes.
21. Give short description of the data element. And give the lengths and field labels accordingly in
Field label tab.
35
22. Press on Definition tab and give the domain name in Domain field. Double click on ZNUM_D.
23. It will ask for save. Press Yes.
36
24. Save it as a local Object.
25. Now it asks for Domain creation. Press Yes.
26. Give short description in short text field. Enter the data type and no. characters, Press Enter.
Then Press on Activate button or Press Ctrl+F3.
37
27. Save this as a local object.
28. Press enter.
38
29. Now you will get the following screen. Press Back button.
39
30. Activate the data element By pressing Activate button or Pressing Ctrl+F3.
31. Press enter.
40
32. Press Back button.
41
33. Now we created two fields. And Data elements and Domain for these two fields.
Now we have to maintain the technical settings. Press on Technical settings button.
42
34. Give the data class and size category of the table as per the requirement.
And press the back button.
35. Now activate the table by pressing the activate button or CTRL+F3.
36. Press enter.
43
37. Now you will get the following screen.
44
38. Now enter the data into table. Go to Utilities Table contents  Create Entries.
39. Now enter the data in the fields and Save it.
45
40. You will get the following screen after clicking the Reset Button.
41. Enter the data for the second entry into the table.
42. Save it and press reset.
46
43. You will get the following screen.
44. Again enter the data for the third entry.
47
45. Press save, Reset (Optional) and Back button.
46. Now you will get the following screen.
48
47. To see the table contents go to Utilities  Table contents  Display. Or press Ctrl+Shift+F10.
48. You will get the following screen.
49
49. Press on run button or press F8. Now it will display the table contents.
Creation of a table pool and pool table
Step 1:
Go to transaction SE11. Go to Utilities  Other Dictionary Objects
50
Step 2:
Select Radio button Table pool/Cluster Give table Pool Name: ZTBL_POOL.
Then press F5 or choose Create.
Step 3:
Then Select Radio button Table Pool. Press Enter.
51
Step
4:
Then you go to maintain Poll Screen there give Short Description.
Step 5:
Then go to Technical settings.
52
Step 6:
In the “Maintain technical Settings” screen Provide Size category.
Save and activate the table Pool. Go back to SE11.
Step 7:
Go to SE11 ABAP Dictionary: Initial Screen.
Create a Z table.
53
Step 8:
Maintain Delivery and Maintenance attributes for the Z table.
Add fields to the Z table.
Maintain Technical settings and Enhancement Category.
54
Step 9:
Then Go to Extras Change table category
Step 10:
Choose Table type.
In our Example it is Pooled table.
55
Step 11:
Go back to Delivery and Maintenance tab and provide Pool/Cluster value.
We have successfully created Table pool and Pooled table.
56
views
57
VIEW: Is a imaginary database which does not really exist
 Projection View
Database View
 Maintenance View
Help View
 Database View (SE11)
Database views are implement an inner join, that is, only records of the primary table (selected
via the join operation) for which the corresponding records of the secondary tables also exist
are fetched. Inconsistencies between primary and secondary table could, therefore, lead to a
reduced selection set.
In database views, the join conditions can be formulated using equality relationships between
any base fields. In the other types of view, they must be taken from existing foreign keys. That
is, tables can only be collected in a maintenance or help view if they are linked to one another
via foreign keys.
58
 Help View ( SE54)
Help views are used to output additional information when the online help system is called.
When the F4 button is pressed for a screen field, a check is first made on whether a matchcode
is defined for this field. If this is not the case, the help view is displayed in which the check
table of the field is the primary table. Thus, for each table no more than one help view can be
created, that is, a table can only be primary table in at most one help view.
 Projection View
Projection views are used to suppress or mask certain fields in a table (projection), thus
minimizing the number of interfaces. This means that only the data that is actually required is
exchanged when the database is accessed.
A projection view can draw upon only one table. Selection conditions cannot be specified for
projection views.
 Maintenance View ( SE54 )
Maintenance views enable a business-oriented approach to looking at data, while at the same
time, making it possible to maintain the data involved. Data from several tables can be
summarized in a maintenance view and maintained collectively via this view. That is, the data
is entered via the view and then distributed to the underlying tables by the system.
Creating a projection view:-
We use projection view to mask unwanted fields and display only relevant fields in a table. Basically
View acts like a database table only, the difference is view will not occupy storage space.
1. Creating Projection View
59
2. Choose Projection View in the pop up which appears when you click on create
3. Give Description & base Table name(In this example we have taken KNA1)
60
4. After giving table name click on Table fields button
5. Choose the fields which you want to be displayed in output and click copy
61
6. Now Save, Activate & execute it, output will be
62
Summary
In standard SAP tables we will have many fields, of which we will use only few fields. whenever we go
and view the data we have to come across unwanted data, to avoid this and get display of field which
relevant to scenario we use this projection view.
63
Structures
Structure:- Structure is a user defined group of variables which can hold 1 record during time
Go to transaction SE11 and select the radio button “Data type”. Enter a structure name starting with Y or
Z.
64
Press create button.
A pop-up screen appears with 3 different options. Select the radio button structure.
The screen will be displayed like this.
Provide the description and also components.
65
Then press SAVE, CHECK and ACTIVATE.
Structure Created Successfully.
66
Search helps
67
Introduction
Search helps are data selection methods used to provide the possible value list for a screen
field. I.e. Search helps are used to provide F4 help for screen fields. The selection logic for the
data to be displayed can be to show the entries from a single table (no coding required) or
even can be complex ABAP code to select the data from different tables which are related or a
combination of both. Thus search helps can be used to show very specific information that
would be required by the user to select an entry from the possible value list.
There are two types of search helps.
1) Elementary search helps: Elementary search help defines a specific search path. The
following components need to be defined for an elementary search help
a) Where to pick the data from (Selection method)
b) What fields have to be considered while selecting the data and what are fields
to be displayed (Search help parameters)
Dialog box of elementary search help
68
An Elementary search help is a search help that describes an input help process in which it is not
possible to select one of a number of search paths.
The online behavior of an elementary search help is controlled by defining the dialog type and by
specifying the fields to be displayed in the dialog box for restricting values or in the dialog box for
displaying the hit list (including the order in these dialog boxes). These fields must be defined as
parameters of the search help.
For data collection, a database table or a view is normally defined and the possible values are
selected here. This table/view is called the selection method of the search help. If the selection
method is a table, a text table can also be used for collecting data if one exists. In the selection,
those fields of the selection method (and possibly of the text table) which have parameters with
the same names in the search help are used.
If the standard options for describing the online behavior or data collection for the search help are
not sufficient, you can define its behavior more flexibly by using a search help exit.
2) Collective Search helps: Collective search helps are a collection of elementary search
helps, thereby providing multiple search paths for a particular field on the screen.
The user can select the required search path and use it to get the desired list. Here too
we can define the input parameters and the output parameters for the search help.
Necessary mapping between the collective search help and the included elementary
search help has to be provided.
Dialog box of Collective search help
69
A Collective search help describes an input help process in which the user
can choose one of several alternative search paths. Each alternative search
path corresponds to an elementary search help, i.e. a collective search help
contains several elementary search helps.
Both elementary search helps and other collective search helps can be
included in a collective search help. if a collective search help contains
other collective search helps, they are resolved down to the level of the
elementary search helps when the input help is called.
Like an elementary search help, a collective search help has an interface of
import and export parameters. The data is exchanged between the screen
template and the parameters of the elementary search helps contained in it
using this interface. The parameters of the search helps included in a
collective search help must be assigned to the parameters of the collective
search help.
During the input help process, the collective search help only controls the
user's selection of the required search path. The rest of the dialog and data
collection is controlled by the selected elementary search help. If selection
of the required elementary search help should be made flexible (e.g. with
context-specific definition of the set of available search paths), the
collective search help must be assigned a search help exit.
Creating Elementary Search Helps:
In SE11 give the search help name and click the create button. Choose “Elementary search
help” in the pop up that follows. This takes you to the screen where you enter the details of
the search help.
In the Definition tab you have to enter the following details:
1) Selection method: The table from which the data is to be selected by the search help
for display of possible value list is to be entered here. This is not a mandatory field. If
the selection method is not entered then the data selection (from displaying the
possible value list) will have to be done in the search help exit (explained later).
2) Text Table: This field is non editable. If a text table exists for the selection method
(table) entered then this field is populated automatically.
70
3) Dialog type: The dialog type defines the steps that are followed by the search help
through the process of displaying the search help. You can select from the following
dialog types:
a) Immediate value display: The possible value list is displayed immediately on
calling the search help.
b) Dialog with value restriction: On calling the search help a dialog box for
restricting the values (Just like a selection screen) selected is displayed first.
This dialog box will have those parameters, which are defined as the import
parameters in the search help parameters.
c) Dialog depends on value set: If the possible value list contains less than 100
entries then the list is displayed immediately. If not then this behaves similar to
dialog with value restriction.
As a convention, if the possible value list has very less number of entries we would be
using the first (a) and if the list will have large volume of data we would use options (b)
and (c).
4) Hot key: Hot key (short cut) can be assigned to elementary search help. This can be
any character or digit. This will be used when this elementary search help is used as a
part of the collective search help. (To call a specific elementary search help from a
collective search help enter the following in the field to which the collective search help
is attached “ =<Hot key of the elementary search help> “ and do an F4. For e.g. =A and
press F4, where A is the hotkey for a specific elementary search help).
5) Search help exit: Search help exit is a function module, which is used to modify and
manipulate with the data selection procedure and the selected data. The function
module should have the same interface as the function module
F4IF_SHLP_EXIT_EXAMPLE.
The function module defined as the search help exit will be called at different time
points during the process of data selection by the search help. The different time
points at which this function module is called and the manipulations that are possible
at each time point are explained in detail in a later section.
71
6) Parameters: Here you define the search help parameters. You can define import
parameters and export parameters for the search help. Following are the
characteristics of the parameters that you would have to define.
a) Checkbox ‘IMP’: If the parameter is an import parameter then check this
checkbox.
b) Checkbox ‘EXP’: If the parameter is an export parameter then check this
checkbox.
(Note: A parameter can be both import as well as export parameter depending
on the requirement. See the section Value transfer for input help for knowing
how the import and export parameters transfer values to and from the field to
which the search help is attached).
c) LPOS: This is the position of the parameter in the hit list. If a parameter need
not appear in the hit list then leave this field blank. Note that same position
number cannot occur more than once in a search help.(This will set postion on
the box which is displayed after F4 is pressed)
d) SPOS: This is the position of the parameter in the dialog box for value
restriction. (Selection screen). If a parameter need not appear in the dialog box
then leave this field blank. If no dialog box appears for value restriction then
this field can be left blank for all the parameters. Note that same position
number cannot occur more than once in a search help.
e) SDIS: If this check box is checked then in the dialog box for value restriction,
the parameter will appear as a display only field. The user will be able to see
the value restriction for this field but will not be able to modify the value.
f) Data Element and Checkbox ‘Modified’: A search help parameter should have
an associated data element. This data element will define the output attributes
for the parameter and the help functions (F4 help) for the parameter on the
dialog box for value restriction.
If a table is entered in the “Selection method’ of the search help then the data
element is picked up from the field of the table having the same name. All the
changes that you perform on this field in the database table, those get reflected
in the search help too.
72
If you want to assign a different data element other than that is defined in the
database table then check the checkbox ‘Modified” for the parameter. Now the
data element field becomes editable and you can enter any required data
element. The new data element should have same data type, length and the
number of decimal places as the previous one. Only difference would be that
the changes that you make to the field in the ‘Selection method’ would not get
reflected in the search help.
g) Default Value: You can enter the default value for the parameter in this field.
Once these details are defined, activate the search help. We can test the search help by
doing an ‘F8’ on the maintain search help screen or the display search help screen.
Creating Collective Search Helps:
In SE11 give the search help name and click the create button. Choose “Collective search help”
in the pop up that follows. This takes you to the screen where you enter the details of the
search help.
In the definitions tab enter the following details:
73
1) Search Help Exit: The use of the search help exit is the same as that in an elementary
search helps. In case of collective search helps the time points at which the exit (FM) is
called is slightly different than in case of elementary search helps.
The different time points at which this function module is called and the manipulations
that are possible at each time point are explained in detail in a later section.
2) Parameters: Just like elementary search helps collective search also has the import and
export parameters. See the section Value transfer for input help for knowing how the
import and export parameters transfer values to and from the field to which the search
help is attached.
In the included search helps tab define the following.
1) List down the elementary search helps that are going to be the part of this collective
search help.
2) Do the parameter assignment for each of the elementary search helps listed. This
procedure actually does a mapping between the parameters of the collective search
help and the individual elementary search helps. The mapping is automatically
proposed by the system but can be changed manually.
Once done, activate the search help. The collective search help also can be single tested from
the maintain search help screen or the display search help screen using the ‘F8’ functionality.
Attaching search helps to fields
1) Attaching the search help to a data element.
For attaching the search help to a data element go to further characteristics tab of the
data element through SE11 and enter the search help name in the field provided. Then
map an export parameter of the search help to the data element.
When input help is asked for any field using this data element, the corresponding
search help is triggered. If the user selects a line of the hit list in the input help, the
74
contents of this parameter are returned to the corresponding screen field. It is not
possible to return several values when the search help is attached to a data element.
2) Attaching the search help to a check table
If a field has check table then the possible values for this field is defined by the contents
of the check table. The key fields of the check table will be automatically present in the
possible value list. If a text table is assigned to the check table then the text will also be
present in the hit list.
Attaching a search help to the check table can again modify the hit list obtained from
the check table. Assigning a search help to the check table field can do this. (Through
SE11)
75
(Place the cursor on the field to which the search help has to be assigned and click on the
button “Search help”)
3) Attaching the search help to a table field
Assign a search help to the table field through SE11 (Refer the above screen shot)
4) Attaching the search help to a screen field
Search help can be assigned to a screen field. In this case the search help assignment is
valid only for that screen.
For dialog screens the assignment can be done through the Screen Painter in the
attributes for the field.
In the selection screen of the executable programs the search helps can be assigned to
the parameters and select-options as follows:
Parameter : <PAR> like <field name> matchcode object
<Search help>.
Select-Options:<SEL> for <fieldname> matchcode object
<Search help>.
Value Transport for input helps
76
If a search help is attached to a screen field directly or through a data element then
only one search help parameter can be assigned to the field. The value transport takes place
between this field and the export parameter of the search help attached to the field.
(Even in this case the search help can have more than one export parameter. The search help
will transfer that field which is the first export parameter defined in the search help)
If the search help is attached to a table field or a check table then the value transport
can take place for more than one field that are linked to the search help through its
parameters. The import parameter of the search help picks up data from that field of the
screen, which has the same name as the search help parameter. If such a field is found then it
copies the data into the respective parameter and if not found then it leaves the parameter
blank. Mapping of the output parameters to the screen fields is similar to the input
parameters. The values are transported to the fields having the same name. Thus data can be
transferred to more than one fields.
Using Search help Exits
Search help Exit is just like any other function module and is used to modify the input help
process of any search help. Doing so we can provide very specific information required by the
user for choosing from the hit list. As mentioned earlier search help exits are called at specific
time points of the input help process. The current time point can be obtained from the
Function module parameter callcontrol-step.
Some of the time points at which manipulations with the data will be required most of the
time are:
1) SELONE
This time point occurs (only for collective search helps) before the dialog box for
entering the import parameters are displayed. This can be used for selecting an
77
elementary search help in the collective search help. This time point occurs only once in
the entire search help process.
The parameter SHLP_TAB has one entry each for all the possible elementary search
helps. If an entry for a specific search help is deleted from SHLD_TAB that search help
will not be offered in the dialog box for selection.
If there is only one entry remaining in SHLP_TAB, then the dialog box for selection can
be skipped by setting the parameter CALLCONTROL-STEP to either ‘PRESEL’ or ‘SELECT’.
2) PRESEL1
Once the search help is selected this event occurs before the interface of the selected
search help is entirely copied. So at this time point you can change the properties of
the interface parameters of the selected search help by changing the Function module
parameter SHLP-INTERFACE.
The properties like the screen field to which the search help parameter is attached, the
output field for which the input help is asked etc can be changed at this stage.
3) PRESEL
This time point occurs before the dialog box for value restriction is displayed. At this
time you can predefine the value restriction. This can be done by populating the
function module parameter SHLP-SELOPT.
e.g.
DATA: l_selopt LIKE ddshselopt.
l_selopt-shlpfield = <Name of any import parameter of the search help>.
l_selopt-sign = 'I'.
l_selopt-option = 'EQ'.
l_selopt-low = <Value for the field>.
l_selopt-shlpname = <Search help name>.
APPEND l_selopt TO shlp-selopt.
78
In the dialog box that appears the above restriction would already be
present. Use can enter any further selections if required.
4) SELECT
This is the time point where the actual selection of the data takes place. If you do not
want the default selection to take place, do the data selection that is required and
populate the same into the function module parameter RECORD_TAB.
For this first select the required data into an internal table and then use the FM
‘F4UT_RESULTS_MAP’.
Pass the following parameters in the above function module.
APPY_RESTRICTIONS = If you have not already applied the value restrictions then the
FM will do it if you pass this parameter as ‘X. SHLP_TAB = This is available in
the exit . Pass the same
RECORD_TAB = This is available in the exit . Pass the same
SOURCE_TAB = The internal table into which you have selected the data
Now to skip the standard selection set the function module parameter CALLCONTROL-
STEP to ‘DISP’. If this is not set then the default selection will over ride your data
selection.
5) DISP
This time point occurs before the data is displayed as the hit list. So here you can
manipulate with the parameter RECORD_TAB to change the values to be displayed.
Once you are done with the manipulations with the data if you want to display the data
then do not change CALLCONTROL-STEP.
If you do not want to display the hit list and select one value directly then keep only
that value in the table RECORD_TAB and set the CALLCONTROL-STEP as ‘RETURN’.
79
If you input help request should be aborted then set the CALLCONTROL-STEP as ‘EXIT’.
If you want to re initiate the whole selection process starting from the dialog box for
value restriction then set CALLCONTROL-STEP as ‘PRESEL’.
Note: Function modules are provided in the function library for operations that are
frequently executed in search help exits. The names of these function modules begin
with the prefix F4UT_. The use of each of these function modules are available in
the documentation of each of these Function modules.
An Append search help is used for modification-free enhancement of a
collective search help (that is not the original in the current system) with
further search help inclusions. This technique can be used for example in
special developments and country versions, and by SAP partners and
customers to add further search paths to a collective search help of the
standard system.
An append search help has a fixed assignment to a collective search help (its
appending object). This appending object is enhanced with the append
search help.
The structure of an append search help corresponds to that of a collective
search help, but the append search help takes on the parameters of its
appending object so that it cannot be maintained separately any longer.
Furthermore, an append search help cannot be assigned a search help exit.
An append search help is automatically included in its appending object. The
parameters of the two search helps having the same name are assigned to
each other.
Note: You can also hide modification-free search helps from a collective
search help with an append search help. You have to insert the search help
to be hidden in the append search help and then hide the inclusion there.
The search path(s) defined by this search help are no longer offered in the
appending search help. To cancel this, remove the hidden inclusion again
from the append search help.
Note: Append search helps can also be used themselves to describe an input
help. They are treated like collective search helps.
Note: If the parameters of the appending object change, this change is not
automatically made in the append search help. Instead, you are informed
80
that the parameters of the append search help should be adjusted. In this
case you should check if you want to change the assignments between the
parameters of the append search help and the search helps included in
them.
Procedure: Proceed as follows to enhance a collective search help of the
standard system with your own search paths:
1. For each search path, create an elementary search help in your namespace
and activate these search helps.
2. In display mode, go to the maintenance screen for the collective search help
and choose Goto -> Append search helps. Create the append search help in your
namespace.
3. Include the elementary search help defined in the first step in the append
search help. Maintain the parameter assignments between the parameters of
the append search help and the parameters of the included search helps.
4. Activate the append search help. The append search help is automatically
added to your appending object. The search paths inserted in the append search
help are now available in the collective search help. They appear at the end of
the list of available elementary search helps.
81
Table maintenence
82
What is table maintenance generator?
Table Maintenance Generator ( from now we call it as ‘TMG’) acts as a user interface tool
which is used to create a equipment by which customized tables created by end users can be
changed as required, such as making an entry to that table, deleting an entry etc.
Table maintenance generator is a user interface tool which is used to change the entry of the
table or delete an entry from the table or create an entry for the table.
A table can be maintained in two ways:
1. from any program
2. Using the TMG.
Through whatever we may update the table; the table should have the “Maintenance allowed”
property defined in the attributes.
Transaction Codes:
SE54: Generate Table Maintenance Dialog
SE55: Table view maintenance DDIC call
SE56: Table view display DDIC call
SE57: Deletion of Table Maintenance
83
SM30: Maintenance Table Views:
Implementation of table maintenance generator for a custom table
We will implement the table maintenance generator for a custom table.
Requirement:
A table is having certain no. of fields say field1 to field5. During the maintenance of the table by end-
user, if the user has entered value ‘X’ in field2, then field4 should be enabled and filled with certain value
and field5 should be disabled and if the field2 has value ‘Y’, then field4 should be disabled and field5
should be enabled and filled with certain value.
Go to SE11 and create a table with the fields as per the requirement.
84
In table change mode, click on Utilities and then click on Table maintenance generator.
If the table needs to be maintained by only particular group of people, then the Authorization group
needs to be filled otherwise fill it as &NC&. To maintain the authorization group refer to SU21.
Function group is the name to which the generated maintenance modules will belong to.
Generally Function Group name can be same as table name.
Maintenance can be done in two ways:
1. Maintenance & Overview both on one screen
2. Maintenance on one screen and Overview on another screen.
85
Table entries can be transported with the help of “Dialog data transport details”. If Standard recording
routine is checked, then table entries will be included in Transport request (More information available at
the end of the document). If other is checked the entry won’t be included in the TR.
Click on create on the application tool bar and after generation of TMG without errors click on save.
To disable & enable the fields of the table during maintenance, Maintenance screens need to be
modified during every new entry accordingly. Follow the procedure to achieve the same:
Click on Environment  Modification  Maintenance Screens & Click on Layout.
In the Layout, Click on Sales Org field and assign the group as ‘ABC’ and for Plant assign group as
‘DEF’.
86
In the PBO, create a Z Module and write the following code:
87
LOOP AT SCREEN.
IF ztestvks-field1 EQ 'X'.
IF screen-group1 = 'DEF'.
screen-input = '0'.
ENDIF.
ELSEIF ztestvks-field1 EQ 'Y'.
IF screen-group1 = 'ABC'.
screen-input = '0'.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
As per the requirement, for every new entry in the table, the fields should have the constant values
before only. For this purpose, the event needs to be chosen which performs the action. We will go with
“05 creating a new entry”.
List of Events available in Table maintenance
01 Before saving the data in the database
02 After saving the data in the database
03 Before deleting the data displayed
04 After deleting the data displayed
05 Creating a new entry
06 After completely performing the function 'Get original'
07 Before correcting the contents of a selected field
08 After correcting the contents of a selected field
09 After getting the original of an entry
10 After creating the header entries for the change task (E071)
11 After changing a key entry for the change task (E071K)
12 After changing the key entries for the change task (E071K)
13 Exit editing (exit main function module)
14 After lock/unlock in the main function module
15 Before retrieving deleted entries
16 After retrieving deleted entries
17 Do not use. Before print: Event 26
18 After checking whether the data has changed
19 After initializing global variables, field symbols, etc.
20 after input in date sub screen (time-dep. tab. /views)
88
21 Fill hidden fields
22 Go to long text maintenance for other languages
23 Before calling address maintenance screen
24 After restricting an entry (time-dep. tab./views)
25 Individual authorization checks
26 Before creating a list
27 After creation or copying a GUID (not a key field)
28 After entering a date restriction for time-dep. views
AA Instead of the standard data read routine
AB Instead of the standard database change routine
AC Instead of the standard 'Get original' routine
AD Instead of the standard RO field read routine
AE Instead of standard positioning coding
AF Instead of reading texts in other languages
AG Instead of 'Get original' for texts in other languages
AH Instead of DB change for texts in other languages
ST GUI menu main program name
AI Internal use only
89
Click on New Entries tab and Choose 05.
In form routine enter “AT_NEWENTRY” and click on EDITOR.
90
Go to the events and in the form routine: AT_NEWENTRY, write the following code:
LOOP AT SCREEN.
IF ztestvks-field1 EQ 'X'.
IF screen-group1 = 'DEF'.
ztestvks-vkorg = '2011'.
ENDIF.
ELSEIF ztestvks-field1 EQ 'Y'.
IF screen-group1 = 'ABC'.
ztestvks-werks = '1400'.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
Click on Save & activate and press F3 & F3.
Check the same by adding some entries through SM30:
91
Dialog Data Transport details (Changing the option to “Standard recording routine”):
Values entered in ZTESTVKS through SM30 and clicked on save:
92
An introduction to Search helps
93
Introduction
Search helps are data selection methods used to provide the possible value list for a screen
field. I.e. Search helps are used to provide F4 help for screen fields. The selection logic for the
data to be displayed can be to show the entries from a single table (no coding required) or
even can be complex ABAP code to select the data from different tables which are related or a
combination of both. Thus search helps can be used to show very specific information that
would be required by the user to select an entry from the possible value list.
There are two types of search helps.
3) Elementary search helps: Elementary search help defines a specific search path. The
following components need to be defined for an elementary search help
a) Where to pick the data from (Selection method)
b) What fields have to be considered while selecting the data and what are fields
to be displayed (Search help parameters)
Dialog box of elementary search help
4) Collective Search helps: Collective search helps are a collection of elementary search
helps, thereby providing multiple search paths for a particular field on the screen. The
user can select the required search path and use it to get the desired list. Here too we
can define the input parameters and the output parameters for the search help.
Necessary mapping between the collective search help and the included elementary
search help has to be provided.
94
Dialog box of Collective search help
Creating Elementary Search Helps:
In SE11 give the search help name and click the create button. Choose “Elementary search
help” in the pop up that follows. This takes you to the screen where you enter the details of
the search help.
In the Definition tab you have to enter the following details:
7) Selection method: The table from which the data is to be selected by the search help
for display of possible value list is to be entered here. This is not a mandatory field. If
the selection method is not entered then the data selection (from displaying the
possible value list) will have to be done in the search help exit (explained later).
8) Text Table: This field is non editable. If a text table exists for the selection method
(table) entered then this field is populated automatically.
9) Dialog type: The dialog type defines the steps that are followed by the search help
through the process of displaying the search help. You can select from the following
dialog types:
a) Immediate value display: The possible value list is displayed immediately on
calling the search help.
b) Dialog with value restriction: On calling the search help a dialog box for
restricting the values (Just like a selection screen) selected is displayed first.
This dialog box will have those parameters, which are defined as the import
parameters in the search help parameters.
95
c) Dialog depends on value set: If the possible value list contains less than 100
entries then the list is displayed immediately. If not then this behaves similar to
dialog with value restriction.
As a convention, if the possible value list has very less number of entries we would be
using the first (a) and if the list will have large volume of data we would use options (b)
and (c).
10) Hot key: Hot key (short cut) can be assigned to elementary search help. This can be any
character or digit. This will be used when this elementary search help is used as a part
of the collective search help. (To call a specific elementary search help from a
collective search help enter the following in the field to which the collective search help
is attached “ =<Hot key of the elementary search help> “ and do an F4. For e.g. =A and
press F4, where A is the hotkey for a specific elementary search help).
11) Search help exit: Search help exit is a function module, which is used to modify and
manipulate with the data selection procedure and the selected data. The function
module should have the same interface as the function module
F4IF_SHLP_EXIT_EXAMPLE.
The function module defined as the search help exit will be called at different time
points during the process of data selection by the search help. The different time
points at which this function module is called and the manipulations that are possible
at each time point are explained in detail in a later section.
12) Parameters: Here you define the search help parameters. You can define import
parameters and export parameters for the search help. Following are the
characteristics of the parameters that you would have to define.
a) Checkbox ‘IMP’: If the parameter is an import parameter then check this
checkbox.
b) Checkbox ‘EXP’: If the parameter is an export parameter then check this
checkbox.
96
(Note: A parameter can be both import as well as export parameter depending
on the requirement. See the section Value transfer for input help for knowing
how the import and export parameters transfer values to and from the field to
which the search help is attached).
c) LPOS: This is the position of the parameter in the hit list. If a parameter need
not appear in the hit list then leave this field blank. Note that same position
number cannot occur more than once in a search help.
d) SPOS: This is the position of the parameter in the dialog box for value
restriction. (Selection screen). If a parameter need not appear in the dialog box
then leave this field blank. If no dialog box appears for value restriction then
this field can be left blank for all the parameters. Note that same position
number cannot occur more than once in a search help.
e) SDIS: If this check box is checked then in the dialog box for value restriction, the
parameter will appear as a display only field. The user will be able to see the
value restriction for this field but will not be able to modify the value.
f) Data Element and Checkbox ‘Modified’: A search help parameter should have
an associated data element. This data element will define the output attributes
for the parameter and the help functions (F4 help) for the parameter on the
dialog box for value restriction.
If a table is entered in the “Selection method’ of the search help then the data
element is picked up from the field of the table having the same name. All the
changes that you perform on this field in the database table, those get reflected
in the search help too.
If you want to assign a different data element other than that is defined in the
database table then check the checkbox ‘Modified” for the parameter. Now the
data element field becomes editable and you can enter any required data
element. The new data element should have same data type, length and the
number of decimal places as the previous one. Only difference would be that
the changes that you make to the field in the ‘Selection method’ would not get
reflected in the search help.
g) Default Value: You can enter the default value for the parameter in this field.
97
Once these details are defined, activate the search help. We can test the search help by
doing an ‘F8’ on the maintain search help screen or the display search help screen.
Creating Collective Search Helps:
In SE11 give the search help name and click the create button. Choose “Collective search help”
in the pop up that follows. This takes you to the screen where you enter the details of the
search help.
In the definitions tab enter the following details:
3) Search Help Exit: The use of the search help exit is the same as that in an elementary
search helps. In case of collective search helps the time points at which the exit (FM) is
called is slightly different than in case of elementary search helps.
The different time points at which this function module is called and the manipulations
that are possible at each time point are explained in detail in a later section.
4) Parameters: Just like elementary search helps collective search also has the import and
export parameters. See the section Value transfer for input help for knowing how the
import and export parameters transfer values to and from the field to which the search
help is attached.
In the included search helps tab define the following.
3) List down the elementary search helps that are going to be the part of this collective
search help.
4) Do the parameter assignment for each of the elementary search helps listed. This
procedure actually does a mapping between the parameters of the collective search
help and the individual elementary search helps. The mapping is automatically
proposed by the system but can be changed manually.
98
Once done, activate the search help. The collective search help also can be single tested from
the maintain search help screen or the display search help screen using the ‘F8’ functionality.
Attaching search helps to fields
5) Attaching the search help to a data element.
For attaching the search help to a data element go to further characteristics tab of the
data element through SE11 and enter the search help name in the field provided. Then
map an export parameter of the search help to the data element.
When input help is asked for any field using this data element, the corresponding
search help is triggered. If the user selects a line of the hit list in the input help, the
contents of this parameter are returned to the corresponding screen field. It is not
possible to return several values when the search help is attached to a data element.
6) Attaching the search help to a check table
If a field has check table then the possible values for this field is defined by the contents
of the check table. The key fields of the check table will be automatically present in the
possible value list. If a text table is assigned to the check table then the text will also be
present in the hit list.
99
Attaching a search help to the check table can again modify the hit list obtained from
the check table. Assigning a search help to the check table field can do this. (Through
SE11)
(Place the cursor on the field to which the search help has to be assigned and click on the
button “Search help”)
7) Attaching the search help to a table field
Assign a search help to the table field through SE11 (Refer the above screen shot)
8) Attaching the search help to a screen field
Search help can be assigned to a screen field. In this case the search help assignment is
valid only for that screen.
For dialog screens the assignment can be done through the Screen Painter in the
attributes for the field.
100
In the selection screen of the executable programs the search helps can be assigned to
the parameters and select-options as follows:
Parameter : <PAR> like <field name> matchcode object
<Search help>.
Select-Options:<SEL> for <fieldname> matchcode object
<Search help>.
Value Transport for input helps
If a search help is attached to a screen field directly or through a data element then
only one search help parameter can be assigned to the field. The value transport takes place
between this field and the export parameter of the search help attached to the field.
(Even in this case the search help can have more than one export parameter. The search help
will transfer that field which is the first export parameter defined in the search help)
If the search help is attached to a table field or a check table then the value transport
can take place for more than one field that are linked to the search help through its
parameters. The import parameter of the search help picks up data from that field of the
screen, which has the same name as the search help parameter. If such a field is found then it
copies the data into the respective parameter and if not found then it leaves the parameter
blank. Mapping of the output parameters to the screen fields is similar to the input
parameters. The values are transported to the fields having the same name. Thus data can be
transferred to more than one fields.
101
Using Search help Exits
Search help Exit is just like any other function module and is used to modify the input help
process of any search help. Doing so we can provide very specific information required by the
user for choosing from the hit list. As mentioned earlier search help exits are called at specific
time points of the input help process. The current time point can be obtained from the
Function module parameter callcontrol-step.
Some of the time points at which manipulations with the data will be required most of the
time are:
6) SELONE
This time point occurs (only for collective search helps) before the dialog box for
entering the import parameters are displayed. This can be used for selecting an
elementary search help in the collective search help. This time point occurs only once in
the entire search help process.
The parameter SHLP_TAB has one entry each for all the possible elementary search
helps. If an entry for a specific search help is deleted from SHLD_TAB that search help
will not be offered in the dialog box for selection.
If there is only one entry remaining in SHLP_TAB, then the dialog box for selection can
be skipped by setting the parameter CALLCONTROL-STEP to either ‘PRESEL’ or ‘SELECT’.
7) PRESEL1
Once the search help is selected this event occurs before the interface of the selected
search help is entirely copied. So at this time point you can change the properties of
the interface parameters of the selected search help by changing the Function module
parameter SHLP-INTERFACE.
102
The properties like the screen field to which the search help parameter is attached, the
output field for which the input help is asked etc can be changed at this stage.
8) PRESEL
This time point occurs before the dialog box for value restriction is displayed. At this
time you can predefine the value restriction. This can be done by populating the
function module parameter SHLP-SELOPT.
e.g.
DATA: l_selopt LIKE ddshselopt.
l_selopt-shlpfield = <Name of any import parameter of the search help>.
l_selopt-sign = 'I'.
l_selopt-option = 'EQ'.
l_selopt-low = <Value for the field>.
l_selopt-shlpname = <Search help name>.
APPEND l_selopt TO shlp-selopt.
In the dialog box that appears the above restriction would already be
present. Use can enter any further selections if required.
9) SELECT
This is the time point where the actual selection of the data takes place. If you do not
want the default selection to take place, do the data selection that is required and
populate the same into the function module parameter RECORD_TAB.
For this first select the required data into an internal table and then use the FM
‘F4UT_RESULTS_MAP’.
Pass the following parameters in the above function module.
APPY_RESTRICTIONS = If you have not already applied the value restrictions then the
FM will do it if you pass this parameter as ‘X. SHLP_TAB = This is available in
the exit . Pass the same
103
RECORD_TAB = This is available in the exit . Pass the same
SOURCE_TAB = The internal table into which you have selected the data
Now to skip the standard selection set the function module parameter CALLCONTROL-
STEP to ‘DISP’. If this is not set then the default selection will over ride your data
selection.
10) DISP
This time point occurs before the data is displayed as the hit list. So here you can
manipulate with the parameter RECORD_TAB to change the values to be displayed.
Once you are done with the manipulations with the data if you want to display the data
then do not change CALLCONTROL-STEP.
If you do not want to display the hit list and select one value directly then keep only
that value in the table RECORD_TAB and set the CALLCONTROL-STEP as ‘RETURN’.
If you input help request should be aborted then set the CALLCONTROL-STEP as ‘EXIT’.
If you want to re initiate the whole selection process starting from the dialog box for
value restriction then set CALLCONTROL-STEP as ‘PRESEL’.
Note: Function modules are provided in the function library for operations that are
frequently executed in search help exits. The names of these function modules begin
with the prefix F4UT_. The use of each of these function modules are available in
the documentation of each of these Function modules.
104
105
CLASSICAL REPORTS
ABAP – Advanced Business Application Programming is a fourth generation
programming language and is used to develop all SAP R/3 applications. Programs In
ABAP can be broadly classified as:-
 List/Report Programs
 Dynamic/Dialog Programs.
Dynamic/Dialog programming serves as an interface to the SAP R/3 database. Dialog
programs, frequently called as module pools enable the user to interact with the SAP
database. This interaction can be in the form of adding entries, retrieving them for
display or even modifying them. Therefore such programs often act as the front end
to the R/3 database.
106
On the other hand List/Report programs serve as a medium to retrieve large amounts
of data from the R/3 database and process it for display to the user. In addition to this
report programs provide the user with the functionality of downloading the data in a
desired format from SAP to Excel or Notepad for distribution or record purposes.
This document is aimed to introduce the reader to Report Programming in ABAP. It
takes you through the basics of the ABAP Editor (SE38) and into the various aspects of
Report Programming. It provides a small tutorial with screen snapshots to enable the
reader to understand the concepts of Report Programming as well as create his/her
first report program.
Pre-Requisites: The reader should be comfortable with ABAP Data Dictionary,
Language constructs and Working with tables.
INDEX
1. ABAP EDITOR: SE38
2. INCLUDES
3. DEFINITIONS
4. SELECTION SCREEN
5. FORMS
6. EVENTS
7. DISPLAY OPTIONS
8. TEXT ELEMENTS
9. PROCESSING
10. VARIANTS
11. SAMPLE CODE
ABAP EDITOR: SE38
107
The ABAP Editor commonly referred to as SE38 is used for the creation of all Report
Programs. The editor is used for creating/editing the source code for the report
program as well as for the creation of variants, documentation, etc. Each of these will
be covered separately in the chapters to follow.
Let us now begin by creating our very own Report say z_samplereport. As we proceed
by clicking the “Create” button we are presented with a window where we define the
attributes of our report. Some of the basic attributes are explained below.
1. Title: The title provides a brief idea of what the report is designed to do.
2. Type: All reports are of the type “Executable program” (Type 1).
3. Status: The status defines whether the program is a Standard SAP Program or
a Customer Production Program or a Test Program.
4. Application: This refers to the Application Type Area-SD, FI, etc.
5. Authorization Group: This defines the Authorization Group to which a report is
assigned. This plays an important role when the system has to check whether
the user is authorized to execute a program or edit a program.
6. Editor Lock: This option provides the functionality of preventing other users
from making changes to the program.
108
Once these attributes are set, we proceed by saving the report. This brings us to the
main editor page of the report. This is where we write the code for the program.
The first line always contains the report name. We now define the line size and line
count for the report. We also include the NO STANDARD PAGE HEADING line so as to
suppress the list heading or name of the program. For displaying error / warning /
information messages, we define the message class which is maintained via
transaction SE91.
Thus an ideal report program would begin as:-
Report <report name> NO STANDARD PAGE HEADING
LINE-SIZE <size>
LINE-COUNT <n(n1)>
MESSAGE-ID <message class>.
INCLUDES
109
The Includes are reports of the type “Include Program”. These are used to separate
the definitions for the program and the actual code consisting of the select queries
and other presentation logic. The definitions are generally written in the top include
and the queries and other logic goes into the forms include. However there is no
standard naming convention for these includes and the names vary according to the
project standards.
Also, the use of includes is optional. If the program is a simple report with no complex
queries and few definitions, the entire code including the definitions & logic can be
written together in the main program itself. However the use of includes is a good
coding practice and aides in maintenance of code and debugging.
DEFINITIONS
110
The definition part of the code basically includes the list of tables which will be used in
the report. This is followed by the definitions of internal tables, constants & other
variables which will be used in the course of the report.
We now come to the definition of the Selection Screen - the interface between the
user and program. It is here that the user specifies the input values for which the
report should be executed.
SELECTION SCREEN
111
The syntax for defining the selection screen is as follows.
SELECTION-SCREEN BEGIN OF SCREEN <SCREEN #>
SELECTION-SCREEN BEGIN OF BLOCK <#> WITH FRAME TITLE <TEXT>
………
………
SELECTION-SCREEN END OF BLOCK <#>
SELECTION-SCREEN END OF SCREEN <SCREEN #>
The Selection Screen basically comprises of 2 main components:
 Select Options
 Parameters
SELECT OPTIONS:
 A select option can be used to input a range of values or a set of values to the
program.
 The syntax for defining a select option like the field of a table is as follows.
SELECT-OPTIONS: s_name FOR Table-Field.
Eg: SELECT-OPTIONS: s_bukrs FOR lfb1-bukrs.
 A Select Option can be made mandatory by using the following syntax.
SELECT-OPTIONS: s_name FOR Table-Field OBLIGATORY.
112
Eg: SELECT-OPTIONS: s_bukrs FOR lfb1-bukrs OBLIGATORY.
The above illustration shows how a select option would look like for the definition
stated in the example.
PARAMETERS:
 A parameter on the other hand can accept one single value for the course of
execution of the program.
 The syntax for defining a parameter like the field of a table is as follows.
PARAMETERS: p_name LIKE Table-Field.
Eg: PARAMETERS: p_lifnr LIKE lfb1-lifnr.
 As explained in the case of select options, a parameter can also be made
obligatory by use of the OBLIGATORY syntax.
 A select option can be used as a parameter by using the following syntax.
SELECT-OPTIONS: s_name FOR Table-Field NO INTERVALS
NO- EXTENSIONS.
The above illustration shows how a parameter would look like for the definition
stated in the example.
We can assign a default value to both select options and parameters by using the
DEFAULT <VALUE> tag after the definition.
FORMS
113
The forms generally contain the functions containing the select queries based on the
values input on the selection screen. These functions will be called from the main
program once the report is executed.
The forms also contain the logic for displaying the data fetched from the database by
the report program. This will be dealt in detail in the following sections.
EVENTS
114
The events in a report program basically define the order in which the code is
executed.
Following are the basic events in any report program:
1. LOAD-OF-PROGRAM: This event triggers the associated event in an internal
session after loading the program.
2. INITIALIZATION: This event is used for filling in values in the selection screen at
runtime. Basically, all values are initialized during the course of this event
3. AT SELECTION-SCREEN: Validation checks for input occur during this event.
4. START-OF-SELECTION: This event triggers the start of selection of data from
the database tables. All functions involving select queries are called during this
event. Once the requisite data is fetched, it is modified/customized as per the
requirements and then finally prepared for display.
5. END-OF-SELECTION: This event causes all fetched data to be displayed on the
screen. All functions associated with displaying the fetched data are called
during this event.
List Processing also occurs during End of Selection. Events during List
Processing include the following:
 TOP-OF-PAGE
 NEW PAGE
 END-OF-PAGE
115
DISPLAY OPTIONS
There are primarily 2 ways of displaying data fetched by a report.
 “WRITE” statements
 ALV List/Grid
WRITE STATEMENTS:
Following is the syntax for using write statements.
WRITE : / '|'.
WRITE AT 5: 'TITLE 1'.
WRITE AT 15 : '|'.
WRITE AT 20 :'TITLE 2'.
WRITE AT 35 : '|'.
WRITE AT 40 :'TITLE 3'.
WRITE AT 60 : '|'.
WRITE AT 65 :'TITLE 4'.
WRITE AT 75: '|'.
WRITE AT 80: 'TITLE 5'.
WRITE AT 90: '|'.
LOOP AT TABLE.
WRITE : / '|'.
WRITE AT 5: Table-Field.
WRITE AT 15 : '|'.
WRITE AT 20 :Table-Field.
WRITE AT 35 : '|'.
WRITE AT 40 :Table-Field.
WRITE AT 60 : '|'.
WRITE AT 65 :Table-Field.
WRITE AT 75: '|'.
WRITE AT 80: Table-Field.
WRITE AT 90: '|'.
ENDLOOP.
Additional formatting options available with WRITE options are use of different colors,
intensifying text and hotspots.
Hotspots: When one drags the mouse over the lines of data where hotspots are
activated, the cursor changes to a hand with an outstretched index finger. Hotspots
can be used for adding additional features such as redirection to tables, transactions,
etc.
116
The above screenshot shows an example of how a report developed using write
statements would look like.
However, it is a cumbersome task to design the output layout using write statements
especially when the amount of data being displayed is huge and display requirements
are complex. This also affects the readability of the report. Hence this method is
preferred only for small simple reports.
ALV-LIST/GRID:
SAP provides a list of ALV (ABAP List Viewer) function modules which can enhance the
functionality and readability of a report. Hence ALV is generally preferred for all
report displays. ALV also provides added functionalities like dynamic sorting of report
output and rearranging columns in the report output.
ALV’s are generally of 3 types:
1. List /SimpleALV
2. Grid/Block ALV
3. Hierarchical Sequential Report
117
The above illustration shows how an ALV Grid display would look like. However the
procedure for generating an ALV is beyond the scope of this document.
TEXT ELEMENTS
There are 3 different types of text elements:
1. LIST HEADINGS:
These are used to make dynamic List headings
118
2. SELECTION TEXTS:
These are used to give names to the select-options, parameters and block
titles used in the selection screen.
119
3. TEXT SYMBOLS:
Text symbols are used for printing texts on the selection screen or in the
report output. The use of selection texts is considered to be a good
programming practice as it serves as a substitute for hard-coding.Text symbols
also provides multi-lingual support.
120
PROCESSING THE REPORT
Once we are done with the coding, we check the report for any syntactic errors. The
editor displays the errors if any along with the line numbers and the suggested
correction.
Check the illustration below.
121
Once the report is found to be syntactically correct, we activate it. On activation, the
program is checked & an active version of the report is saved. Once the report is
activated, it is ready for processing.
On direct processing, the report is executed. Thus, the selection screen will be
displayed prompting the user to input the values for selection. Pressing the F4 Key
gives the user a list of possible values for that particular field
122
Once the user has entered the desired values, the report is executed.
On execution, the data is fetched from the data base and displayed to the user.
VARIANTS
A variant is a saved version of the input data filled into the selection screen. At
runtime, the variant can directly be selected. This removes the need to manually
enter the data in the selection screen over and over again. This generally helps when
we are testing a report for a particular set of values. Check the illustrations below for
the procedure to create a variant.
123
Once we have created the variants, they can be directly selected from the list of
available variants displayed on the selection screen.
124
Types of Internal Tables
1. Overview
This document highlights performance issues related to the 3 different kinds of internal tables:
 Standard table
 Sorted Table
 Hashed Table
It emphasizes how the selection of either of these tables, subject to functional requirements
and limitations, can affect the performance and execution time of our code.
125
2. Types of Internal Tables in ABAP/4
The table type defines how ABAP accesses individual table entries. There are three kinds of
internal table types:
o Standard table: A standard table has an internal logical index. You can access it either using
the index or using its key (refer to Appendix A for notes on KEY). If you use key access, the
response time is in linear relation to the number of table entries. The key of a standard
table is always non-unique. You cannot use the UNIQUE KEY addition in the definition of a
standard table.
o Sorted table: A sorted table is always stored correctly sorted by its key. Like standard
tables, they also have a linear index, and you can access them using either the index or
their key. If you use key access, the response time is in logarithmic relation to the number
of table entries, since the system uses a binary search. The key of a sorted table may be
either unique or non-unique, and you must use one of the additions UNIQUE or NON-
UNIQUE when you specify the key.
Standard tables and sorted tables are generically known as index tables.
o Hashed tables: Hashed tables do not have a logical index. You can only access a hashed
table using its key. The response time is therefore independent of the number of table
entries, since the system uses a hash algorithm to access the entries. The key of a hashed
table must be unique, so you must always use the UNIQUE addition when creating the
table.
126
Standard Sorted Hashed
Index type Logical Logical No Index
Access Type Index/Key Index/Key Key
Response time Linear Logarithmic Constant
Key Type Non-unique Unique/Non-Unique Unique
3. Choosing a Table Type
The table type that you use in a particular situation will depend on which of the typical internal
table operations listed above will be used with the table, and how often.
Standard Tables
This table type is most appropriate when you intend to address the table entries using the
index. This is the quickest way to access entries in a standard table. You should fill standard
tables using the APPEND statement, and read, modify, and delete entries using the index
(INDEX addition to the corresponding ABAP statement). If you use the key to access a standard
table, the access time increases in linear relation to the number of entries. If you need to use
key entries, standard tables are suitable if you can separate filling the table from the remaining
table processing. For example, you can fill a standard table by appending entries, and then sort
it. If you then use key access with the BINARY SEARCH option, the response time is only in
logarithmic relation to the number of table entries.
You should use index operations to access standard tables. For the sake of compatibility, you
can use TABLE as a synonym of STANDARD TABLE
Sorted Tables
This table type is suitable for tables that must be correctly sorted even while you are filing
them. You fill a sorted table using the INSERT ... INTO TABLE statement, observing the sort
sequence defined in the key. When you access the table using its key, the response time is in
logarithmic relation to the number of table entries, since the system automatically uses a
binary search. Sorted tables are particularly useful for partial sequential processing in a LOOP if
you can specify a portion of the table key starting from the left in the WHERE condition.
Hashed Tables
Hashed tables are useful if the main operation on the table is going to be key access. You
cannot access a hashed table using index access. However, the response time for key access is
constant, regardless of the number of table entries. Like database tables, hashed tables always
127
have a unique key. Hashed tables are therefore useful for constructing and processing internal
tables that resemble database tables.
4. General Performance Notes for Internal Tables
4.1 Index Management
As soon as you change an internal table using INSERT, DELETE or SORT, the logical sequence of
the table entries will no longer correspond with the physical sequence in the memory. When
this happens, the system creates a logical index, which also requires memory. Furthermore,
each INSERT or DELETE statement requires further memory. If your internal table is very large,
changing the index can result in significantly increased runtime.
The system does not administer secondary indexes for internal tables.
4.2 Filling Line-by-line
Unlike filling a table using the INSERT statement, using APPEND does not cost runtime in terms
of maintaining the index. If the sequence of the entries is unimportant, or they are already in
the correct order, you should use APPEND instead of INSERT.
4.3 Points to Remember
Functional
Only STANDARD tables are allowed as TABLES parameters in FM’s.
Performance
1. The runtime required to sort an internal table increases with the number of entries and the
length of the sort key.
2. Sorting an internal table with 100 entries with a 50 byte key requires about 1300 msn
(standardized microseconds). Using a 30-byte key, the runtime is about 950 msn.
3. If one of the specified sort criteria is itself an internal table, SORT may sometimes take
much longer.
Example 1: Declaration of hashed internal table with a unique key.
DATA: BEGIN OF tb_itab,
col1 TYPE i,
col2 TYPE c,
END OF tb_itab.
DATA itab LIKE HASHED TABLE OF tb_line WITH UNIQUE KEY col1.
And similarly we can declare internal tables as sorted or standard. Standard table are the
default tables created, i.e.
128
DATA itab LIKE STANDARD TABLE OF tb_line.
Is equivalent to
DATA itab LIKE tb_line.
5. Various tables operations w.r.t to types of internal tables
5.1 INSERT - Insert into an Internal Table
INSERT [wa INTO|INITIAL LINE INTO] TABLE itab.
The way in which the system inserts a new entry into the table depends on the table type:
o Standard Table: The new entry is added to the end of the table. Generic insertion is
therefore the same as an APPEND.
o Sorted Table: The new entry is added in its appropriate place, determined by the table
key. The key values are taken from the specified work area wa or from the header line
of the table. If the key is NON-UNIQUE, the entry is placed at the top of the list of
duplicates. The insertion point is determined internally using a binary search. This
makes the relationship between the runtime required and the number of table entries
logarithmic.
o Hashed Table: The new entry is placed in the internal hash administration of the table
according to the table key. The key values are taken from the specified work area wa or
the header line of the table. The runtime required remains constant, since it does not
depend on the number of table entries. The key must be unique.
Insert in a Sorted Table with Unique Key Insert in Hashed Table with Unique Key
* Entries: 1000, Duplicates: 250
* Line width: 100, Key width: 20
* ITAB2 takes 750 entries with unique key K
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
* Entries: 1000, Duplicates: 250
* Line width: 100, Key width: 20
* ITAB2 takes 750 entries with unique key K
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
4,337 2637
129
Filling a hash table is faster than for a sorted table. You can access single entries very fast.
5.2 LOOP - Loop Through an Internal Table
LOOP AT itab INTO wa where col1 = “raj”.
Places all entries of the internal table itab that satisfy the WHERE condition one by one into
the output area.
Notes
When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is
always required.
If you are working with a SORTED TABLE, the partial sequential processing can be optimized so
that only the entries that actually satisfy the WHERE condition are processed. This
optimization requires that the WHERE condition be specified in the form
WHERE k1 = v1 AND k2 = v2 AND... AND kn = vn
where the components k1, ..., kn are in the same sequence as the beginning of the table key.
Partial Sequential Access: Sorted Vs. Hashed Tables
Partial Sequential Access on a Hashed Table Partial Sequential Access on a Sorted Tables
* Entries: 10000, Line width: 100
* key width: 60, Subkey width: 20
* HTAB is a hashed table, 2000 entries are
read
* Key fields: K, DATA
LOOP AT HTAB INTO WA WHERE K = SUBKEY.
" ...
ENDLOOP.
* Entries: 10000, Line width: 100
* key width: 60, Subkey width: 20
* STAB is a sorted table, 2000 entries are
read
* Key fields: K, DATA
LOOP AT STAB INTO WA WHERE K = SUBKEY.
" ...
ENDLOOP.
6343 2212
5.3 READ - Reading an Internal Table
130
Variants:
1. READ TABLE itab WITH KEY k1 = v1 ... kn = vn
[BINARY SEARCH].
2. READ TABLE itab INDEX i.
Variant 1
READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH]
Effect
The system uses the specified key to identify the correct line. If the type of a value is not
compatible with the type of the corresponding key field, the system uses MOVE logic to
convert the value into the type of the component before reading the table. This is an
asymmetric comparison logic, in which the component type takes precedence over the value
type.
The way in which the system looks for an entry in the table depends on its table type:
o Standard Table: If you use the ... BINARY SEARCH addition, the system uses a binary
search. Otherwise, the search is sequential and the response time is in linear relation to
the number of table entries. This assumes that the internal table is sorted in ascending
order in the sequence of the specified key fields.
o Sorted Table: If the specified key fields form a left-justified extract of the table key, the
search is binary, otherwise sequential. The response time is in logarithmic relation to
the number of table entries.
o Hashed Table: Sequential search. The response time is constant.
Variant 2
READ TABLE itab INDEX i
Effect
Accessing the table entry with the index i.
Performance Issues:
1. The quickest way to access a single line of an internal table is direct access using an index,
because the response time is then not linked to the size of the table, and is restricted more
or less to the transport costs for a single line.
For hashed tables, the response time is constant. Accessing a table using the hash
administration makes the response time around 3 times slower than using index access.
If you use the key to access a table, the response time increase as the number of table
131
entries and the size of the search key increase. Searching using a binary search is
considerably quicker than using a linear search. Therefore, in many cases it can be quicker
to sort the table and then use the BINARY SEARCH addition.
2. Using statements that use an explicit work area for internal tables with a header line can
avoid unnecessary value assignments.
Runtime required to read a line from a table with 100 entries
Read…index = 7 msn
Read….key (30 bytes)...binary search = 25msn
Read….key = 100 msn
Statistical Performance Review of Various Table Types
Linear Search vs. Binary Search
Linear Search in an Internal Table Binary Search in an internal table
* Entries: 1000, Line width: 100
* Key width: 20
READ TABLE ITAB INTO WA
WITH KEY K = 'X'.
* Entries: 1000, Line width: 100
* Key width: 20
READ TABLE ITAB INTO WA
WITH KEY K = 'X'
BINARY SEARCH.
271 3
Single READ access on unique sorted vs. hashed table
Read on Unique Sorted Table Read on Unique Hashed table
* Entries: 1000
* Line width: 100, key width: 20
* STAB is a unique sorted table, 250 entries
are read
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE STAB INTO WA WITH TABLE
KEY K = N.
IF SY-SUBRC = 0.
* Entries: 1000
* Line width: 100, key width: 20
* HTAB is a hased table, 250 entries are
read
DO 250 TIMES.
N = 4 * SY-INDEX.
READ TABLE HTAB INTO WA WITH TABLE
KEY K = N.
132
" ...
ENDIF.
ENDDO.
IF SY-SUBRC = 0.
" ...
ENDIF.
ENDDO.
1725 1268
1. Entries in a sorted table are located by binary search. The costs depend on the
number of entries in the table (O (log n)).
2. Entries in a hashed table are located by an internal hash-algorithm. The costs are
constant (O (1)), i.e. they do not depend on the table size.
Hashed tables are optimized for single entry access, whereas sorted tables are optimized for
partial sequential loop operations.
Appendix A: Key
The key is used to identify lines in the table. There are two possible keys for an internal table -
the default key and a user-defined key. You can specify that the key should by UNIQUE or
NON-UNIQUE. If the key is unique, the internal table may not contain duplicate entries. The
uniqueness of the key depends partly on the table type (see below).
o The default key consists of all non-numeric components of the corresponding line type
that are not, and do not contain, internal tables.
o The user-defined key can consist of any components that are not, and do not contain,
internal tables (that is, do not have a deep-structured type). Internal tables with a user-
defined key are known as key tables. When you define the key, remember that the
sequence of the key fields is important for operations such as sorting.
133
Performance tuning
For all entries
The for all entries creates a where clause, where all the entries in the driver table are
combined with OR. If the number of entries in the driver table is larger than
rsdb/max_blocking_factor, several similar SQL statements are executed to limit the
length of the WHERE clause.
The plus
 Large amount of data
134
 Mixing processing and reading of data
 Fast internal reprocessing of data
 Fast
The Minus
 Difficult to program/understand
 Memory could be critical (use FREE or PACKAGE size)
Some steps that might make FOR ALL ENTRIES more efficient:
 Removing duplicates from the driver table
 Sorting the driver table
 If possible, convert the data in the driver table to ranges so a BETWEEN statement is
used instead of and OR statement:
FOR ALL ENTRIES IN i_tab
WHERE mykey >= i_tab-low and
mykey <= i_tab-high.
Nested selects
The plus:
 Small amount of data
 Mixing processing and reading of data
 Easy to code - and understand
The minus:
 Large amount of data
 when mixed processing isn’t needed
 Performance killer no. 1
Select using JOINS
The plus
 Very large amount of data
 Similar to Nested selects - when the accesses are planned by the
programmer
 In some cases the fastest
 Not so memory critical
The minus
 Very difficult to program/understand
 Mixing processing and reading of data not possible
Use the selection criteria
SELECT * FROM SBOOK.
CHECK: SBOOK-CARRID = 'LH' AND
135
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.
Use the aggregated functions
C4A = '000'.
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.
Select with view
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.
136
Select with index support
SELECT * FROM T100
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.
Select … Into table
REFRESH X006.
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT
SELECT * FROM T006 INTO TABLE X006.
Select with selection list
SELECT * FROM DD01L
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT
137
Key access to multiple lines
LOOP AT TAB.
CHECK TAB-K = KVAL.
" ...
ENDLOOP.
LOOP AT TAB WHERE K = KVAL.
" ...
ENDLOOP.
Copying internal tables
REFRESH TAB_DEST.
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.
TAB_DEST[] = TAB_SRC[].
Modifying a set of lines
LOOP AT TAB.
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
Deleting a sequence of lines
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
138
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
Linear search vs. binary
READ TABLE TAB WITH KEY K = 'X'.
READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.
Comparison of internal tables
DESCRIBE TABLE: TAB1 LINES L1,
TAB2 LINES L2.
IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP
AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE.
" ...
ENDIF.
IF TAB1[] = TAB2[].
" ...
ENDIF.
139
Modify selected components
LOOP AT TAB.
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.
WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.
Appending two internal tables
LOOP AT TAB_SRC.
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP
APPEND LINES OF TAB_SRC TO TAB_DEST.
Deleting a set of lines
LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
Tools available in SAP to pin-point a performance problem
 The runtime analysis (SE30)
 SQL Trace (ST05)
 Tips and Tricks tool
 The performance database
140
Optimizing the load of the database
Using table buffering
Using buffered tables improves the performance considerably. Note that in some
cases a statement can not be used with a buffered table, so when using these
statements the buffer will be bypassed. These statements are:
 Select DISTINCT
 ORDER BY / GROUP BY / HAVING clause
 Any WHERE clause that contains a sub query or IS NULL expression
 JOIN s
 A SELECT... FOR UPDATE
If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to
the SELECT clause.
Use the ABAP SORT Clause Instead of ORDER BY
The ORDER BY clause is executed on the database server while the ABAP SORT
statement is executed on the application server. The database server will
usually be the bottleneck, so sometimes it is better to move the sort from the
database server to the application server.
If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key
statement) but are sorting by another key, it could be better to use the ABAP
SORT statement to sort the data in an internal table. Note however that for very
large result sets it might not be a feasible solution and you would want to let the
database server sort it.
Avoid the SELECT DISTINCT Statement
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT,
if some of the fields are not part of an index. Instead use ABAP SORT +
DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate
rows.
141
PERFORMANCE TUNING IN SAP
Few points that should be noted by a developer while writing a piece of code to
Develop a good quality object with high performance.
For checking the performance of any object the transaction that should be used are:-
 ST05
 SE30.
 SE30: ABAP Runtime Analysis
1. On running the transaction, the object name or the transaction associated to it must be
specified as follows and then execute the same.
142
Fig: 1.0
2. The screen below (Fig 1.0.1) shall appear once the code is executed and when you come
back to the SE30 transaction screen by clicking “Back” button in the menu. Once you
reach the Fig 1.0 screen, click on the “Analyze” button.
This screen shows a bar diagram that indicates the system time utilized by the code (in
microseconds) which is classified under three categories:-
 ABAP Time
 Database Time
 R/3 System Time
143
Fig 1.0.1
Out of the three mentioned time’s the ABAP & Database Time can be controlled by proper usage
of the ABAP & SQL statements respectively which is mentioned in the later half of this document.
3. Now to get a detail analysis of the time utilized by each and every ABAP statement in your
code click on the button at the top left most corner of the
Fig 1.0.1. The detail analysis is as follows:-
Fig: 1.0.2
144
 ST05: Trace Request
 Under this transaction there are several Trace Modes of which SQL trace checkbox
needs to be checked to know the performance of each and every select query written in a
piece of code.
Fig: 1.0
 After checking the check box against the SQL Trace one has to switch on the trace
request which can be done in two ways:-
Fig: 2.0
1. Trace on: The SQL trace shall be on for the particular object that needs to be tested
under the developers Username.
Fig: 2.0.1
2. Trace on for user: The SQL trace shall be on for the particular object that needs to be
tested under the developers Username with filter.
145
Fig:
2.0.2
The difference between the two buttons can be explained by the following example:-
If a code is been executed by several users at the same time and if “Trace on” button is clicked
then the performance analysis that shall be shown will be a effect of execution of that code for
more than one scenario by different users at the same time.
Else if the same code is been executed by many users at the same time and if “Trace on for user
button” is clicked then the performance analysis that shall be shown will be only for the scenario
under that particular user for which the code is executed.
Now if you are clicking the “Trace On” button to ON the trace the only care that need to be taken
before doing it is you need to be ready with all your inputs in the selection screen. Because if you
ON the trace and then go to execute the object & fill the input fields, the time lapse between the
Trace ON & Executing the code does effect the performance time.
On clicking the “Trace on for user” button a popup window shall be flashed which shall ask for
the object name or the transaction associated to it of which the performance needs to be tested.
Fig: 2.0.3
On entering the object name the trace status shall be on as shown in the Fig 2.0.1 / Fig 2.0.2.
Now the object needs to be executed with the desired inputs. Once it is executed then the trace
need to be put off by clicking the “Trace off” button as shown in the Fig 2.0.
To view the performance analysis of the object, click on the “List Trace” button as shown in the
Fig 2.0. A popup window shall be flashed which is as follows:-
146
Fig: 2.0.4
Now on clicking enter a Basic Trace List screen shall appear which shall possess the analysis of
all the select queries in that particular object.
Fig: 2.0.5
Now place the cursor on the Object name against the Op. = REOPEN and click the “Explain”
button as shown in the Fig 2.0.5. On clicking the same the Execution plan for SQL statement shall
be displayed.
147
Fig: 2.0.6
In the Fig 2.0.6, it is seen that the estimated cost = 1 and the estimated rows = 1.
For a SQL statement to be performance tuned the Estimated Cost of it should be tending to 1 and
the Estimated Rows must be equal to the no. of desired rows that need to be fetched from the DB
Table.
So to make the SQL statement in your code performance tuned we need to check its Estimated
Cost and Estimated Rows values. To make it tend to the desired values mentioned above the
following points need to be taken care by the developer while writing the code:-
i. Complete conditions are specified in the where clause taking care of all the primary keys
and the order of it in the DB table.
ii. SELECT INTO TABLE is used instead of SELECT & APPEND.
iii. SELECT SINGLE is used instead of SELECT….ENDSELECT.
iv. SELECT * need to be avoided in case of fetching only few fields from the DB table.
Instead mention the field names that need to be fetched.
v. Usage of AGGREGATE functions (MAX, MIN, SUM, COUNT, etc) must be minimum.
vi. SELECT into CORRESPONDING-FIELDS should be avoided in case of few records being
selected
vii. Internal table is not empty check must be done before using FOR ALL ENTRIES in a
SELECT query.
viii. SELECT queries using FOR ALL ENTRIES must use the key fields.
ix. Multiple identical SELECTs must be avoided on the same DB table. Instead the data must
be fetched at one go into a global internal table and later on this internal table should be
used for further processing.
x. Avoid using JOINS in SELECT queries for more than three DB tables.
xi. Avoid using SELECT inside a LOOP ….ENDLOOP statement.
xii. MOVE statement must be used instead of MOVE-CORRESPONDING.
xiii. Usage of IS/IS NOT INITIAL instead of hard code values.
xiv. Already existing INDEXES associated with the DB tables must be used as they help in
making the search faster.
INDEXES
148
 Now if you click on ECMCT~1 in the Fig 2.0.6 the detailed information of the index 1
defined for the ECMCT table shall be displayed as in the
Fig 2.0.7(below). It indicates the usage of the Index of ECMCT table in your
SQL statement. If in the Execution Plan you find ECMCT~0 it means that the
basic primary keys of the table are used.
Fig: 2.0.7
 Clicking on ECMCT in the execution plan displays the following information of the
indexes associated with the ECMCT table. To get the detailed Index Statistics click on
the “Index Statistics” Button in the Fig 2.0.8 (below).
149
Fig: 2.0.8
xv. Performance tips specifically with Internal Tables:-
 Unnecessary sorting must be avoided.
 READ TABLE must be used with BINARY SEARCH.
 It must be Cleared / Refreshed wherever necessary.
 APPEND to be used instead of COLLECT.
 Usage of Memory ID should be minimal & freed immediately after use.
 CLEAR the Header Line / Work Area after the APPEND statement.
 CLEAR Header Line after DELETE statement.
150
Introduction to ALV Classic
Reporting
Astep-by-stepprogramming guide to
ALV reports
BY
151
Srinivas Palakurty
152
INTRODUCTION
SAP has introduced a lot of new technologies with Release 4.6. All of these are designed to
have a more pleasing user interface and make the work of the developer easier by automating many of
the standard functionalities, which was needed to be coded explicitly earlier. Along with automation,
the new technologies also bring with it a host of new and powerful features. But to use these features
you have to master them. It is similar to saying that if you have a Formula 1 Ferrari, the thrill is only if
you can drive it at 200 kms/hr.
ALV or the SAP LIST VIEWER is one such technology. It is a tool for making reports with a
better and standardized interface. All clients want the latest of technologies to be used for their
implementation and our client was no exception. We initially found the going tough because there is
hardly any documentation on ALV with the small exception of a few sample codes on the Internet. But
with hard work and an exploring attitude we (the SAP MAM Team of Transco ODC) developed a fair
amount of competency in ALV. This document is in a way, the documentation of our learnings.
This document is NOT a comprehensive work on ALV. Indeed, there are many features that we
discover every week. This manual gives an introduction to ALV and on how a person can write simple
ALV reports. It has been written with FULL code dumps and screen shots so that there is no scope for
confusion. It tries to give the initial impetus required to venture into further exploration of the
technology. There is no doubt that you will find newer features and ‘smarter’ way of doing things in
ALV. It is our request to you to document these learnings and contribute to the EAS Knowledge Base.
Remember, Rome was not built in a day.
With this let us put our best foot forward …
153
ABAP List Viewer – A summary of features
Introduction: Why?
In several business scenarios, we need to present data in a manner which
 Is easily readable,
 Is aesthetically appealing,
 can be manipulated in various ways,
 can be downloaded, and so on.
Building these facilities manually is extremely time-consuming, and also creates major maintenance-
hassles during the lifetime of the program. These problems are easily overcome by using generic,
standard methodologies provided by SAP, so that we get all the facilities we need, and more at the
mere click of the mouse, at the same time avoiding the maintenance work!
Features: What can I do with ALV?
1. Simple list displays
Display of data in rows/columns, with usual ALV facilities like sorting, etc., and provision for
user-commands, drill-downs and so on.
2. Multi-level list displays
Same as above, but we can now have a hierarchy – header and item level data display.
Can we display greater than three levels?
3. Multiple list displays
Several simple lists, displayed one after another.
4. Multiple, multi-level list displays
Several hierarchical lists!
1. The simple list display
a. Leading function-module
i. REUSE_ALV_LIST_DISPLAY (the obsolete version)
ii. REUSE_ALV_GRID_DISPLAY (the current version)
These function modules take various internal table, and generate a standard
display, on an ALV-standard screen.
b. How to pass on the fields to be printed
This is done by passing an internal table called the field-catalog. It consists typically of
the
 internal table-field name,
 the output length,
 the name to be displayed for the column,
 the justification
 formatting, like number of decimals, bold/normal and so on.
Also, if we are using a data-dictionary structure for the display, we can
avoid creating this internal table by making use of the function
REUSE_ALV_FIELDCATALOG_MERGE.
c. Layout details
We can specify several layout-formatting options by passing this internal table to the
function module, eg.,
 Optimize width of columns
 Minimum width of list output
d. Sorting, sub-totalling
154
A separate internal table is maintained for specifying the sort-orders, which fields need
subtotaling at different levels, what the name of each sub-total line would be, and so
on.
e. Event-handling
A standard function-module, REUSE_ALV_EVENTS_GET can be used to fetch a list of
events which are available for a given type of list.
To capture an event like top-of-page, top-of-list, end-of-list, etc., we provide the
leading function with an internal table, which maps the event-name in ALV, with a
handler-form we create in the program for the particular event. In conjunction with
this, we also need to provide the function-module with the program-name, where the
form-routines reside.
f. User-command handling
One single form-name is passed as a parameter to the leading function-module. At any
user-action like the clicking of a button, an enter-key hit, etc., this form-routine would
be executed. In this routine, we can capture specific ok-codes, and handle the same.
g. Drilldowns(popup)
There’s a function-module REUSE_ALV_POPUP_TO_SELECT, which is used to display a
popup, with a mini-list, from which specific rows/cells can be selected. The trigger for
this would be a call from the user-command-handling routine.
2. The hierarchical display
Very similar to the simple list display in terms of the parameters to be passed, but with a few
minor additions which make it possible to display a hierarchy.
a. Leading function-module
REUSE_ALV_HIERSEQ_LIST_DISPLAY – there’s no grid display for this! We need to pass
on two internal tables containing – one, the header data, and another, the item-details
for each header.
b. How to connect the tables
There’s an internal table, in which we can specify upto five distinct field-names
between the header and detail tables, which would be used for clubbing the detail-data
into separate header-displays.
3. The block-list display
a. Leading function-modules
i. REUSE_ALV_BLOCK_LIST_INIT
ii. REUSE_ALV_BLOCK_LIST_APPEND
iii. REUSE_ALV_BLOCK_LIST_DISPLAY
4. The block-hierarchical display
a. Leading function-modules
i. REUSE_ALV_BLOCK_LIST_INIT
ii. REUSE_ALV_BLOCK_HS_LIST_APPEND
iii. REUSE_ALV_BLOCK_LIST_DISPLAY
155
Chapter
1
A Simple ALV Program
TOPICS INTRODUCED
A simple ALV program.
REUSE_ALV_GRID_DISPLAY.
Minimum parameters to be passed.
Report ZSOMALV1:
REPORT zsomalv1 NO STANDARD PAGE HEADING.
*Description-----------------------------------------------------------*
* This program shows a simple ALV display of the table QMEL. Use the
* 'Pattern' button to write the call to function
* 'REUSE_ALV_GRID_DISPLAY'. Pass the table i_qmel to the function.
*----------------------------------------------------------------------*
DATA: i_qmel LIKE qmel OCCURS 0.
SELECT * FROM qmel INTO TABLE i_qmel.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
i_structure_name = 'QMEL'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
156
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_qmel
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
OUTPUT
Any ALV program requires a minimum of two parameters to be passed to the function
REUSE_ALV_GRID_DISPLAY.
 Field Catalogue (Details of the format of the columns to be displayed in the
report)
 And the data to be populated in those columns.
In the above case we are passing the name of the table itself (in place of the field catalogue which
is discussed later). The function automatically creates the field catalogue in this case.
157
ALV automatically sets a standard PF-STATUS (the row of buttons above the report). With these
you can do a lot of standard functions like send it by mail, sort, save as a local file etc).
A common mistake that every beginner does is not to uncomment the ‘EXPORTING’ line of the function after
writing it by the Pattern button. Due to it, the function does not recognize the structure name being passed to it.
Chapter
2
Choosing and saving Layouts
TOPICS INTRODUCED
1) How we can ensure that report allows the user to make, choose and save layouts (also called
display variants).
Optimize the column width to display data in the most efficient manner.
Other options that can be specified for layouts.
Report ZSOMALV2:
REPORT zsomalv2 NO STANDARD PAGE HEADING.
TYPE-POOLS: slis.
DATA: report_id LIKE sy-repid.
DATA: i_qmel LIKE qmel OCCURS 0.
DATA: i_layout TYPE slis_layout_alv.
SELECT * FROM qmel INTO TABLE i_qmel.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = report_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
i_structure_name = 'QMEL'
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = i_layout
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
158
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_qmel
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F1000_Layout_Init
*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
ENDFORM. " F1000_Layout_Init
159
OUTPUT
Difference in this program is the usage of a Type-Pool (SLIS). This type pool contains all the
standard structures and tables (for eg. slis_alv_layout), which are to be populated and passed to
REUSE_ALV_GRID_DISPLAY. It is a good idea to keep a printout of this type-pool when
coding ALV programs. This is also included in this document as APPENDIX A.
Other difference is that we are passing a value ‘A’ to the parameter i_save,
Value range of parameter i_save can be,
' ' = No display variants can be saved
'X' = Only standard display variants can be saved
'U‘ = Only user-specific display variants can be saved
'A' = Standard and user-specific display variants can be saved
Note that 2 other buttons have appeared in the PF-STATUS (Change Layout and Save layout). When you click
on ‘Change Layout’, a window comes up where you can specify the sort order, which all columns to bedisplayed
and other properties).
160
You can also sort the report using the sort buttons etc and click ‘Save Layout’. Then you are
asked whether it is user specific or default.
For all such interactive functions to work, we also need to pass the program ID (sy-repid) to
ALV (I meant REUSE_ALV ….). But it should never be passed alone, only after assigning it to
a variable.
The final thing is the passing of layout specifications (i_layout) to ALV. Please refer to the
other fields in the structure slis_layout_alv (it is combination of two structures which has more
structures etc). Through them you can specify a host of other properties.
For example,
i_layout-zebra = ‘X’  This will result in the lines of the report having alternate colour.
i_layout-no_vline = ‘X”  Columns are separated by space.
i_layout-no_scrolling = ‘X”  Scrolling is disabled.
We found that a lot of such options were not working. If you do further R&D on this; please document them and
contribute to the EAS KB.
161
Chapter
3
Specifying a field Catalogue
TOPICS INTRODUCED
1) Specify a heading for a report.
Create a field catalogue for the report.
In real life situations we will not need to simply display a table as we have been doing above. Most
probably it will be an internal table with a specific set of fields from different tables and maybe
plain integer or character fields. In such cases the simplest method to follow is to create an
internal table (of the same structure as what is to be displayed in the report) with the data; pass it
to ALV and also a field catalogue (also called fieldcat).
Report ZSOMALV3:
REPORT zsomalv3 NO STANDARD PAGE HEADING.
*Description-----------------------------------------------------------*
* TOPICS INTRODUCED:
* 1. Specify a heading for a report.
* 2. Create a field catalogue for the report.
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
DATA: BEGIN OF i_data OCCURS 0,
qmnum LIKE qmel-qmnum,
qmart LIKE qmel-qmart,
qmtxt LIKE qmel-qmtxt,
ws_row TYPE i,
ws_char(5) TYPE c,
chk,
END OF i_data.
DATA: report_id LIKE sy-repid.
DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
DATA: i_layout TYPE slis_layout_alv.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
SELECT qmnum
qmart
qmtxt
INTO TABLE i_data
FROM qmel
WHERE qmnum <= '00030000010'.
LOOP AT i_data.
i_data-ws_row = sy-tabix.
i_data-ws_char = 'AAAAA'.
MODIFY i_data.
ENDLOOP.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
PERFORM f2000_fieldcat_init CHANGING i_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
162
i_callback_program = report_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name = ' '
* I_BACKGROUND_ID = ' '
i_grid_title = ws_title
* I_GRID_SETTINGS =
is_layout = i_layout
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_data
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F1000_Layout_Init
*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-edit = 'X'.
ENDFORM. " F1000_Layout_Init
*&---------------------------------------------------------------------*
*& Form f2000_fieldcat_init
*&---------------------------------------------------------------------*
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMNUM'. " The field name and the table
line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req.
line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
line_fieldcat-seltext_m = 'Notification No.'. " Column Header
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
163
line_fieldcat-fieldname = 'QMART'.
line_fieldcat-ref_tabname = 'I_DATA'.
line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot.
line_fieldcat-seltext_m = 'Notif Type'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMTXT'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Description'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_ROW'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Row Number'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_CHAR'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Test Character Field'.
line_fieldcat-datatype = 'CHAR'.
line_fieldcat-outputlen = '15'. " You can specify the width of a
APPEND line_fieldcat TO i_fieldcat. " column.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'CHK'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Checkbox'.
line_fieldcat-checkbox = 'X'. " Display this field as a checkbox
line_fieldcat-edit = 'X'. " This option ensures that you can
" edit the checkbox. Else it will
" be protected.
APPEND line_fieldcat TO i_fieldcat.
ENDFORM. " f2000_fieldcat_init
164
OUTPUT
Over here we are purposely using a customized internal table which is being displayed in ALV. Notice
that it contains two kinds of fields. Ones with DDIC (Data Dictionary Reference) and others without. The
table we are using to create a field catalogue (i_fieldcat) is of type slis_t_fieldcat_alv. It is a table of
structure slis_fieldcat_alv. Refer to the SLIS type-pool to get the other options that you can specify for a
column.
For example,
line_fieldcat-icon = ‘X’  Specifies this column as a column of icons. You
must then
specify valid icon values for tnem to be shown in the
report.
line_fieldcat-lzero = ’X’  Allows leading zeroes to be shown for a number column.
line_fieldcat-just = ‘R’  R – Justify right, L – Left, C – Centre. Etc.
You can display a heading for the report using type lvc_title as shown.
NOTE: The table i_fieldcat is passed to the parameter it_fieldcat of the function instead of
i_structure_name as earlier.
165
Chapter
4
Initialize Events
TOPICS INTRODUCED
1) Initialize events.
2) Execute a specific requirement when an event is triggered.
3) Use an event 'TOP_OF_PAGE' to write a header for the report.
4) REUSE_ALV_COMMENTARY WRITE.
Report ZSOMALV4:
REPORT zsomalv4 NO STANDARD PAGE HEADING.
*Description-----------------------------------------------------------*
* TOPICS INTRODUCED:
* 1. Initialize events.
* 2. Execute a specific requirement when an event is triggered.
* 3. Use an event 'TOP_OF_PAGE' to write a header for the report.
* 4. REUSE_ALV_COMMENTARY WRITE.
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
DATA: BEGIN OF i_data OCCURS 0,
qmnum LIKE qmel-qmnum,
qmart LIKE qmel-qmart,
qmtxt LIKE qmel-qmtxt,
ws_row TYPE i,
ws_char(5) TYPE c,
chk,
END OF i_data.
DATA: report_id LIKE sy-repid.
DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
DATA: i_layout TYPE slis_layout_alv.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: i_events TYPE slis_t_event.
DATA: i_header TYPE slis_t_listheader.
SELECT qmnum
qmart
qmtxt
INTO TABLE i_data
FROM qmel
WHERE qmnum <= '00030000010'.
LOOP AT i_data.
i_data-ws_row = sy-tabix.
i_data-ws_char = 'AAAAA'.
MODIFY i_data.
ENDLOOP.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
PERFORM f2000_fieldcat_init CHANGING i_fieldcat.
PERFORM f3000_build_header CHANGING i_header.
PERFORM f4000_events_init CHANGING i_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
166
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = report_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name = ' '
* I_BACKGROUND_ID = ' '
i_grid_title = ws_title
* I_GRID_SETTINGS =
is_layout = i_layout
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
it_events = i_events
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_data
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F1000_Layout_Init
*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-edit = 'X'.
ENDFORM. " F1000_Layout_Init
*&---------------------------------------------------------------------*
*& Form f2000_fieldcat_init
*&---------------------------------------------------------------------*
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMNUM'. " The field name and the table
line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req.
line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
line_fieldcat-seltext_m = 'Notification No.'. " Column Header
167
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMART'.
line_fieldcat-ref_tabname = 'I_DATA'.
line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot.
line_fieldcat-seltext_m = 'Notif Type'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMTXT'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Description'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_ROW'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Row Number'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_CHAR'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Test Character Field'.
line_fieldcat-datatype = 'CHAR'.
line_fieldcat-outputlen = '15'. " You can specify the width of a
APPEND line_fieldcat TO i_fieldcat. " column.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'CHK'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Checkbox'.
line_fieldcat-checkbox = 'X'. " Display this field as a checkbox
line_fieldcat-edit = 'X'. " This option ensures that you can
" edit the checkbox. Else it will
" be protected.
APPEND line_fieldcat TO i_fieldcat.
ENDFORM. " f2000_fieldcat_init
*&---------------------------------------------------------------------*
*& Form f3000_build_header
*&---------------------------------------------------------------------*
FORM f3000_build_header USING i_header TYPE slis_t_listheader.
DATA: gs_line TYPE slis_listheader.
CLEAR gs_line.
gs_line-typ = 'H'.
gs_line-info = 'This is line of type HEADER'.
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'S'.
gs_line-key = 'STATUS 1'.
gs_line-info = 'This is line of type STATUS'.
APPEND gs_line TO i_header.
gs_line-key = 'STATUS 2'.
gs_line-info = 'This is also line of type STATUS'.
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'A'.
gs_line-info = 'This is line of type ACTION'.
APPEND gs_line TO i_header.
ENDFORM. " f3000_build_header
*&---------------------------------------------------------------------*
168
*& Form f4000_events_init
*&---------------------------------------------------------------------*
FORM f4000_events_init CHANGING i_events TYPE slis_t_event.
DATA: line_event TYPE slis_alv_event.
CLEAR line_event.
line_event-name = 'TOP_OF_PAGE'.
line_event-form = 'F4100_TOP_OF_PAGE'.
APPEND line_event TO i_events.
ENDFORM. " f3000_events_init
*---------------------------------------------------------------------*
* FORM F4100_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM f4100_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
ENDFORM.
OUTPUT
First let us discuss about events. As you may be aware, ABAP is a event driven
language. Through ALV we can cause one or more things to occur when an event is
triggered. Over here in the above example, we have defined the event TOP_OF_PAGE (By
defining an event, I mean associating a form to it, which is executed when that event
occurs).
169
To define an event, first declare a table of type slis_t_event and through a form (f4000_events_init)
append lines to the table i_events. Each line is of type slis_alv_event and contains only two fields; the
event and the associated form, which is executed upon that event. Later i_events is passed to ALV.
To write a header, we use the function REUSE_ALV_COMMENTARY_WRITE. This
function can be used to write headers or footers for reports. To this function we pass a table
of the text that we want to be written in the report. It is of type slis_t_listheader. This is a
table of rows, which can of three types, HEADER, STATUS or ACTION as defined in the
type slis_listheader, which is a line item of slis_t_listheader. (P.S: Please don’t ask we why
we have only three types. I don’t know!!)
ALV supports 16 events. They are:
1. ITEM_DATA_EXPAND
2. REP
3. REP_SEL_MODIFY
4. CALLER_EXIT
5. USER_COMMAND
6. TOP_OF_PAGE
7. DATA_CHANGED
8. TOP_OF_COVERPAGE
9. END_OF_COVERPAGE
10. FOREIGN_TOP_OF_PAGE
11. FOREIGN_END_OF_PAGE
12. PF_STATUS_SET
13. LIST_MODIFY
14. TOP_OF_LIST
15. END_OF_PAGE
16. END_OF_LIST
17. AFTER_LINE_OUTPUT
18. BEFORE_LINE_OUTPUT
19. SUBTOTAL_TEXT
170
Chapter
5
Customize you PF Status
TOPICS INTRODUCED
1) Learn about the ‘Standard’ PF-Status that comes as default.
2) Exclude function codes from ‘Standard’ PF-Status and customize it.
In all the previous reports, we have seen that ALV displays a standard PF Status by
default, which contains a bare minimum function codes (also called fcodes). This is helpful
because we do not have to explicitly code the PF Status. Actually, this PF Status is the
‘STANDARD’ PF Status of the program SAPLSALV with 46 function codes excluded
(disabled). Use transaction SE41 to view all the function codes.
In most practical cases, we will need to exclude some function codes from the standard
PF Status because they might be irrelevant to our report or because we may need to disable
certain standard function codes. (For example, there are reports where the user must NOT be
allowed to sort).
In the following program we will see how we display the entire ‘STANDARD’ PF
Status (including the 46 fcodes which are usually disabled) and also disable 4 of the fcodes.
Report ZSOMALV5:
REPORT zsomalv5 NO STANDARD PAGE HEADING.
*Description-----------------------------------------------------------*
* TOPICS INTRODUCED:
* 1. Learn about the ‘Standard’ PF-Status that comes as default.
* 2. Exclude function codes from ‘Standard’ PF-Status and customize it.
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
DATA: BEGIN OF i_data OCCURS 0,
qmnum LIKE qmel-qmnum,
qmart LIKE qmel-qmart,
qmtxt LIKE qmel-qmtxt,
ws_row TYPE i,
ws_char(5) TYPE c,
chk,
END OF i_data.
DATA: report_id LIKE sy-repid.
DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
DATA: i_layout TYPE slis_layout_alv.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: i_events TYPE slis_t_event.
DATA: i_header TYPE slis_t_listheader.
DATA: i_extab TYPE slis_t_extab.
SELECT qmnum
qmart
qmtxt
INTO TABLE i_data
FROM qmel
WHERE qmnum <= '00030000010'.
171
LOOP AT i_data.
i_data-ws_row = sy-tabix.
i_data-ws_char = 'AAAAA'.
MODIFY i_data.
ENDLOOP.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
PERFORM f2000_fieldcat_init CHANGING i_fieldcat.
PERFORM f3000_build_header CHANGING i_header.
PERFORM f4000_events_init CHANGING i_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = report_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name = ' '
* I_BACKGROUND_ID = ' '
i_grid_title = ws_title
* I_GRID_SETTINGS =
is_layout = i_layout
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
it_events = i_events
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_data
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F1000_Layout_Init
*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-edit = 'X'.
172
ENDFORM. " F1000_Layout_Init
*&---------------------------------------------------------------------*
*& Form f2000_fieldcat_init
*&---------------------------------------------------------------------*
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMNUM'. " The field name and the table
line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req.
line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
line_fieldcat-seltext_m = 'Notification No.'. " Column Header
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMART'.
line_fieldcat-ref_tabname = 'I_DATA'.
line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot.
line_fieldcat-seltext_m = 'Notif Type'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMTXT'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Description'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_ROW'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Row Number'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_CHAR'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Test Character Field'.
line_fieldcat-datatype = 'CHAR'.
line_fieldcat-outputlen = '15'. " You can specify the width of a
APPEND line_fieldcat TO i_fieldcat. " column.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'CHK'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Checkbox'.
line_fieldcat-checkbox = 'X'. " Display this field as a checkbox
line_fieldcat-edit = 'X'. " This option ensures that you can
" edit the checkbox. Else it will
" be protected.
APPEND line_fieldcat TO i_fieldcat.
ENDFORM. " f2000_fieldcat_init
*&---------------------------------------------------------------------*
*& Form f3000_build_header
*&---------------------------------------------------------------------*
FORM f3000_build_header USING i_header TYPE slis_t_listheader.
DATA: gs_line TYPE slis_listheader.
CLEAR gs_line.
gs_line-typ = 'H'.
gs_line-info = 'This is line of type HEADER'.
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'S'.
gs_line-key = 'STATUS 1'.
173
gs_line-info = 'This is line of type STATUS'.
APPEND gs_line TO i_header.
gs_line-key = 'STATUS 2'.
gs_line-info = 'This is also line of type STATUS'.
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'A'.
gs_line-info = 'This is line of type ACTION'.
APPEND gs_line TO i_header.
ENDFORM. " f3000_build_header
*&---------------------------------------------------------------------*
*& Form f4000_events_init
*&---------------------------------------------------------------------*
FORM f4000_events_init CHANGING i_events TYPE slis_t_event.
DATA: line_event TYPE slis_alv_event.
CLEAR line_event.
line_event-name = 'TOP_OF_PAGE'.
line_event-form = 'F4100_TOP_OF_PAGE'.
APPEND line_event TO i_events.
CLEAR line_event.
line_event-name = 'PF_STATUS_SET'.
line_event-form = 'F4200_PF_STATUS_SET'.
APPEND line_event TO i_events.
ENDFORM. " f3000_events_init
*---------------------------------------------------------------------*
* FORM F4100_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM f4100_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
ENDFORM.
*---------------------------------------------------------------------*
* FORM F4200_PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab.
REFRESH i_extab.
PERFORM f4210_exclude_fcodes CHANGING i_extab.
SET PF-STATUS 'STANDARD' OF PROGRAM 'SAPLSALV' EXCLUDING i_extab.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f4210_exclude_fcodes
*&---------------------------------------------------------------------*
FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab.
DATA: ws_fcode TYPE slis_extab.
CLEAR ws_fcode.
ws_fcode = '&EB9'. " Call up Report.
APPEND ws_fcode TO i_extab.
ws_fcode = '&ABC'. " ABC Analysis.
APPEND ws_fcode TO i_extab.
ws_fcode = '&NFO'. " Info Select.
APPEND ws_fcode TO i_extab.
ws_fcode = '&LFO'. " Information.
174
APPEND ws_fcode TO i_extab.
ENDFORM. " f4210_exclude_fcodes
OUTPUT
For starters, declare a new internal table ( i_extab) of type slis_t_extab. This will contain all the function codes,
which should be excluded from the PF Status. Initialize a new event called PF_STATUS_SET by assigning a
form to it. Inside this form (F4200_PF_STATUS_SET), first refresh the table i_extab, which gets populated by
the names of the 46 function codes that are populated by default by ALV. Then call a form, which populates
i_extab with the names of the 4 fcodes. Finally set the PF Status.
175
Chapter
6
Process callback events
TOPICS INTRODUCED
1) Add customized buttons (function codes) to ‘Standard’ PF Status.
2) Customize the processing of such events.
In many cases, we may need to add buttons (function codes) to our PF status and assign a code
that will be executed when that function code is triggered. We can either create our own PF status
or copy the STANDARD pf status of program SAPLSALV creating our own to which we can add
buttons and function codes.
Report ZSOMALV6:
REPORT zsomalv6 NO STANDARD PAGE HEADING.
*Description-----------------------------------------------------------*
* TOPICS INTRODUCED:
* 1. Add customized buttons (function codes) to ‘Standard’ PF Status.
* 2. Customize the processing of such events.
*----------------------------------------------------------------------*
TYPE-POOLS: slis.
DATA: BEGIN OF i_data OCCURS 0,
qmnum LIKE qmel-qmnum,
qmart LIKE qmel-qmart,
qmtxt LIKE qmel-qmtxt,
ws_row TYPE i,
ws_char(5) TYPE c,
chk,
END OF i_data.
DATA: report_id LIKE sy-repid.
DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'.
DATA: i_layout TYPE slis_layout_alv.
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: i_events TYPE slis_t_event.
DATA: i_header TYPE slis_t_listheader.
DATA: i_extab TYPE slis_t_extab.
SELECT qmnum
qmart
qmtxt
INTO TABLE i_data
FROM qmel
WHERE qmnum <= '00030000010'.
LOOP AT i_data.
i_data-ws_row = sy-tabix.
i_data-ws_char = 'AAAAA'.
MODIFY i_data.
176
ENDLOOP.
report_id = sy-repid.
PERFORM f1000_layout_init CHANGING i_layout.
PERFORM f2000_fieldcat_init CHANGING i_fieldcat.
PERFORM f3000_build_header CHANGING i_header.
PERFORM f4000_events_init CHANGING i_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = report_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name = ' '
* I_BACKGROUND_ID = ' '
i_grid_title = ws_title
* I_GRID_SETTINGS =
is_layout = i_layout
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
it_events = i_events
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = i_data
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F1000_Layout_Init
*&---------------------------------------------------------------------*
FORM f1000_layout_init USING i_layout TYPE slis_layout_alv.
CLEAR i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-edit = 'X'.
ENDFORM. " F1000_Layout_Init
*&---------------------------------------------------------------------*
*& Form f2000_fieldcat_init
177
*&---------------------------------------------------------------------*
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMNUM'. " The field name and the table
line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req.
line_fieldcat-key = 'X'. " Specifies the column as a key (Blue)
line_fieldcat-seltext_m = 'Notification No.'. " Column Header
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMART'.
line_fieldcat-ref_tabname = 'I_DATA'.
line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot.
line_fieldcat-seltext_m = 'Notif Type'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'QMTXT'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Description'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_ROW'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_m = 'Row Number'.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'WS_CHAR'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Test Character Field'.
line_fieldcat-datatype = 'CHAR'.
line_fieldcat-outputlen = '15'. " You can specify the width of a
APPEND line_fieldcat TO i_fieldcat. " column.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'CHK'.
line_fieldcat-tabname = 'I_DATA'.
line_fieldcat-seltext_l = 'Checkbox'.
line_fieldcat-checkbox = 'X'. " Display this field as a checkbox
line_fieldcat-edit = 'X'. " This option ensures that you can
" edit the checkbox. Else it will
" be protected.
APPEND line_fieldcat TO i_fieldcat.
ENDFORM. " f2000_fieldcat_init
*&---------------------------------------------------------------------*
*& Form f3000_build_header
*&---------------------------------------------------------------------*
FORM f3000_build_header USING i_header TYPE slis_t_listheader.
DATA: gs_line TYPE slis_listheader.
CLEAR gs_line.
gs_line-typ = 'H'.
gs_line-info = 'This is line of type HEADER'.
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'S'.
gs_line-key = 'STATUS 1'.
gs_line-info = 'This is line of type STATUS'.
APPEND gs_line TO i_header.
gs_line-key = 'STATUS 2'.
gs_line-info = 'This is also line of type STATUS'.
178
APPEND gs_line TO i_header.
CLEAR gs_line.
gs_line-typ = 'A'.
gs_line-info = 'This is line of type ACTION'.
APPEND gs_line TO i_header.
ENDFORM. " f3000_build_header
*&---------------------------------------------------------------------*
*& Form f4000_events_init
*&---------------------------------------------------------------------*
FORM f4000_events_init CHANGING i_events TYPE slis_t_event.
DATA: line_event TYPE slis_alv_event.
CLEAR line_event.
line_event-name = 'TOP_OF_PAGE'.
line_event-form = 'F4100_TOP_OF_PAGE'.
APPEND line_event TO i_events.
CLEAR line_event.
line_event-name = 'PF_STATUS_SET'.
line_event-form = 'F4200_PF_STATUS_SET'.
APPEND line_event TO i_events.
CLEAR line_event.
line_event-name = 'USER_COMMAND'.
line_event-form = 'F4300_USER_COMMAND'.
APPEND line_event TO i_events.
ENDFORM. " f3000_events_init
*---------------------------------------------------------------------*
* FORM F4100_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM f4100_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header.
ENDFORM.
*---------------------------------------------------------------------*
* FORM F4200_PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab.
REFRESH i_extab.
PERFORM f4210_exclude_fcodes CHANGING i_extab.
* The PF status is an exact copy of the PF status 'STANDARD' of program
* SAPLSALV but with command 'CHNG' added to it.
SET PF-STATUS 'ZSOM_STANDARD' EXCLUDING i_extab.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f4210_exclude_fcodes
*&---------------------------------------------------------------------*
FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab.
DATA: ws_fcode TYPE slis_extab.
CLEAR ws_fcode.
ws_fcode = '&EB9'. " Call up Report.
APPEND ws_fcode TO i_extab.
ws_fcode = '&ABC'. " ABC Analysis.
APPEND ws_fcode TO i_extab.
179
ws_fcode = '&NFO'. " Info Select.
APPEND ws_fcode TO i_extab.
ws_fcode = '&LFO'. " Information.
APPEND ws_fcode TO i_extab.
ENDFORM. " f4210_exclude_fcodes
*&---------------------------------------------------------------------*
*& Form f4300_user_command
*&---------------------------------------------------------------------*
FORM f4300_user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
CASE ucomm.
WHEN '&IC1'. "Double Click line Item
READ TABLE i_data INDEX selfield-tabindex.
IF i_data-qmnum NE space.
SET PARAMETER ID 'IQM' FIELD i_data-qmnum.
CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN.
CLEAR ucomm.
ENDIF.
WHEN 'CHNG'. " Change Notification Icon
READ TABLE i_data INDEX selfield-tabindex.
IF i_data-qmnum NE space.
SET PARAMETER ID 'IQM' FIELD i_data-qmnum.
CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN.
CLEAR ucomm.
ENDIF.
ENDCASE.
CLEAR ucomm.
ENDFORM. " f4300_user_command
OUTPUT
In this program, first we created a PF status (ZSOM_STANDARD), which was an exact copy of
STANDARD of program SAPLSALV through transaction SE41 (Menu Painter). Then we
added another button to it (circled in white) with a new fcode called ‘CHNG’. Creation of PF
status is not covered in this document, as it is available in any standard ABAP material. After
this this we set this PF status instead of STANADRD.
We initialize a third event USER_COMMAND and associate a form with it. In this form we can
capture the function codes and write any functionality under it. If we write functionality for an
180
existing fcode, then this gets precedence over the default functionality that might be associated
with it.
In this example, we capture a standard fcode ‘&IC1’ that is nothing but double clicking a line of
the report. We are capturing the notification number of that line and calling transaction IW52
with it. We are also doing the same when a user clicks on the new ‘Change Notification’ button.
When the user clicks the “Back’ button in IW52, it comes back to the report.
181
Chapter
7
Sort Catalogue
TOPICS INTRODUCED
1) Define a sort catalogue for a report.
2) Sort a report using a sort catalogue.
Creating a sort catalogue is very similar to creating a field catalogue. In it we can specify the
fieldnames, table names, order of sorting, whether it should be sorted ascending or descending.
The steps to be taken are, first declare an internal table ( i_sort ) of type slis_t_sortinfo_alv. This is
a table of the structure slis_sortinfo_alv. Then create the sort catalogue in a form which is to be
called before the call to ALV. (i.e. REUSE_ALV_GRID_DISPLAY)
*&---------------------------------------------------------------------*
*& Form f5000_sortcat_init
*&---------------------------------------------------------------------*
form f5000_sortcat_init changing i_sortcat TYPE slis_t_sortinfo_alv..
DATA: line_sortinfo TYPE slis_sortinfo_alv.
CLEAR line_sortinfo.
line_sortinfo-fieldname = 'QMART'.
line_sortinfo-tabname = 'I_DATA'.
line_sortinfo-spos = 1. " First sort by this field.
line_sortinfo-down = 'X'. " Descending
APPEND line_sortinfo TO i_sortcat.
line_sortinfo-fieldname = 'WS_ROW'.
line_sortinfo-tabname = 'I_DATA'.
line_sortinfo-spos = 2. " Second sort by this field.
line_sortinfo-up = 'X'. " Ascending
APPEND line_sortinfo TO i_sortcat.
endform. " f5000_sortcat_init
Then pass i_sortcat to ALV through the parameter it_sort.
it_fieldcat = i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = i_sortcat
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
In form F4200_pf_status_set, change the setting of the PF status to,
SET PF-STATUS 'ZSOM_STANDARD' OF PROGRAM 'ZSOMALV6' EXCLUDING i_extab.
Or else you will get an error. This is because this PF status was created for program ZSOMALV6.
182
OUTPUT
In this example we have sorted the above list first by notification type (QMART) descending
and then by row number (WS_ROW) ascending. Do note the small red arrows that come up in
the column header indicating the type of sort.
The usage of a sort catalogue is actually not required !! This is also the reason why I have decided to put it
towards the last. Just sort the internal data table (i_data) in the required manner before passing it to ALV and it
will be displayed as shown above. The only difference is that the red arrows won’t be there. . In short the
statement,
SORT i_data BY qmart DESCENDING ws_row ASCENDING.
Is enough to replace all the code written above !!
183
Appendix
A
Type-Pool ‘SLIS’
type-pool slis .
">>Y9CK015723
types: begin of slis_lvc_s_bds_extended,
bytesize type int4,
EXTOBJID type char255, "Y9CK016268
end of slis_lvc_s_bds_extended.
types: begin of slis_lvc_s_bds2.
include type lvc_s_bds.
include type slis_lvc_s_bds_extended.
types: end of slis_lvc_s_bds2.
types: slis_lvc_t_bds2 type slis_lvc_s_bds2 occurs 1.
"<<Y9CK015723
">>Y9CK016292
*Trace Extern-Intern-Konvertierung
types: begin of slis_lvc_s_expa,
OP type CHAR4,
EXTERN type LVC_VALUE,
INTERN type LVC_VALUE,
*INCLUDE type RSCONVLITE
ACTIVE type RSSCR_CFLG,
OLENGTH type RSSCR_OLEN,
DECIMALS type RSDECIMALS,
SIGN type SIGNFLAG,
LOWER type RSSCR_LOWC,
CONVEXIT type CONVEXIT,
*INCLUDE type TABFIELD
TABNAME type TABNAME,
FIELDNAME type FIELDNAME,
LFIELDNAME type FNAM_____4,
CURRENCY type CHAR30,
end of slis_lvc_s_expa.
*Textstruktur(ALV-Batch)
types: begin of slis_lvc_s_1022,
line(1022) type c,
end of slis_lvc_s_1022.
*Text-Tabelle(ALV Batch)
types: slis_lvc_t_1022 type slis_lvc_s_1022 occurs 1.
*Ausgabefiles
types: begin of slis_lvc_s_fils,
FILENAME type CHAR255,
SIZE type INT4,
MIMETYPE type CHAR128,
PRIMARY type FLAG,
BINARY type FLAG,
end of slis_lvc_s_fils.
*Filestruktur
types: slis_lvc_t_fils type slis_lvc_s_fils occurs 1.
*Mimetype-Mapping
types: begin of slis_lvc_s_mima,
MIMETYPE type CHAR128,
BINARY type FLAG,
184
end of slis_lvc_s_mima.
*ALV: Mime-Mapping
types: slis_lvc_t_mima type slis_lvc_s_mima occurs 1.
*ALV-W3Text
types: slis_lvc_t_text type w3html occurs 1.
*X255-Tabelle
types: slis_lvc_t_mime type w3mime occurs 1.
*Tabelle X1022
types: slis_lvc_t_x1022 type bapiconten occurs 1.
"<<Y9CK016292
types: slis_list_type(1) type n,
slis_char_1(1) type c,
slis_text40(40) type c.
types: slis_tabname(30) type c,
slis_fieldname(30) type c,
slis_sel_tab_field(60) type c,
slis_formname(30) type c,
slis_entry(60) type c,
slis_edit_mask(60) type c,
slis_coldesc(4) type c.
*types: begin of slis_filtered_entries,
* index type i,
* end of slis_filtered_entries.
types: slis_t_filtered_entries type i occurs 0.
*--- Structure for additional fieldcat
types: begin of slis_add_fieldcat,
fieldname type slis_fieldname,
web_field type slis_fieldname,
href_hndl type i,
end of slis_add_fieldcat.
types: slis_t_add_fieldcat type slis_add_fieldcat occurs 0.
*--- Structure for reprep-initialization
types: begin of slis_reprep_id,
tool(2) type c,
appl(4) type c,
subc(2) type c,
onam(54) type c,
end of slis_reprep_id.
types: begin of slis_reprep_communication,
stop(1) type c,
end of slis_reprep_communication.
*** Structure for colors
types: begin of slis_color,
col type i,
int type i,
inv type i,
end of slis_color.
types: begin of slis_coltypes,
heacolfir type slis_color, " heading_cols_first
heacolnex type slis_color, " heading_cols_nex
hearowfir type slis_color, " heading_rows_first
hearownex type slis_color, " heading_rows_next
lisbodfir type slis_color, " list_body_first
lisbodnex type slis_color, " list_body_next
lisbod type slis_color, " list_body
higcolkey type slis_color, " highlight_col_key
higcol type slis_color, " highlight_col
higrow type slis_color, " highlight_row
185
higsum type slis_color, " highlight_sum
higsumhig type slis_color, " highlight_sum_high
higsumlow type slis_color, " highlight_sum_low
higins type slis_color, " highlight_inserted
higpos type slis_color, " highlight_positive
higneg type slis_color, " highlight_negative
hig type slis_color, " highlight
heahie type slis_color, " heading_hier
lisbodhie type slis_color, " list_body_hierinfo
end of slis_coltypes.
*** Fieldcat
types: begin of slis_fieldcat_main0,
row_pos like sy-curow, " output in row
col_pos like sy-cucol, " position of the column
fieldname type slis_fieldname,
tabname type slis_tabname,
currency(5) type c,
cfieldname type slis_fieldname, " field with currency unit
ctabname type slis_tabname, " and table
ifieldname type slis_fieldname, " initial column
quantity(3) type c,
qfieldname type slis_fieldname, " field with quantity unit
qtabname type slis_tabname, " and table
round type i, " round in write statement
exponent(3) type c, " exponent for floats
key(1) type c, " column with key-color
icon(1) type c, " as icon
symbol(1) type c, " as symbol
checkbox(1) type c, " as checkbox
just(1) type c, " (R)ight (L)eft (C)ent.
lzero(1) type c, " leading zero
no_sign(1) type c, " write no-sign
no_zero(1) type c, " write no-zero
no_convext(1) type c,
edit_mask type slis_edit_mask, "
emphasize(4) type c, " emphasize
fix_column(1) type c, " Spalte fixieren
do_sum(1) type c, " sum up
no_out(1) type c, " (O)blig.(X)no out
tech(1) type c, " technical field
outputlen like dd03p-outputlen,
offset type dd03p-outputlen, " offset
seltext_l like dd03p-scrtext_l, " long key word
seltext_m like dd03p-scrtext_m, " middle key word
seltext_s like dd03p-scrtext_s, " short key word
ddictxt(1) type c, " (S)hort (M)iddle (L)ong
rollname like dd03p-rollname,
datatype like dd03p-datatype,
inttype like dd03p-inttype,
intlen like dd03p-intlen,
lowercase like dd03p-lowercase,
end of slis_fieldcat_main0.
types: begin of slis_fieldcat_main1,
ref_fieldname like dd03p-fieldname,
ref_tabname like dd03p-tabname,
roundfieldname type slis_fieldname,
roundtabname type slis_tabname,
decimalsfieldname type slis_fieldname,
decimalstabname type slis_tabname,
decimals_out(6) type c, " decimals in write statement
text_fieldname type slis_fieldname,
reptext_ddic like dd03p-reptext, " heading (ddic)
ddic_outputlen like dd03p-outputlen,
end of slis_fieldcat_main1.
types: begin of slis_fieldcat_main.
include type slis_fieldcat_main0.
include type slis_fieldcat_main1.
types: end of slis_fieldcat_main.
186
types: begin of slis_fieldcat_alv_spec,
key_sel(1) type c, " field not obligatory
no_sum(1) type c, " do not sum up
sp_group(4) type c, " group specification
reprep(1) type c, " selection for rep/rep
input(1) type c, " input
edit(1) type c, " internal use only
hotspot(1) type c, " hotspot
end of slis_fieldcat_alv_spec.
types: begin of slis_fieldcat_alv.
include type slis_fieldcat_main.
include type slis_fieldcat_alv_spec.
types: end of slis_fieldcat_alv.
types: begin of slis_fieldcat_alv1.
include type slis_fieldcat_main1.
types: end of slis_fieldcat_alv1.
types: slis_t_fieldcat_alv type slis_fieldcat_alv occurs 1.
* Events for Callback
types: begin of slis_event_exit.
types: ucomm like sy-ucomm,
before(1) type c,
after(1) type c,
end of slis_event_exit.
types: slis_t_event_exit type slis_event_exit occurs 1.
* Callback Interface structure for non display subtotals text
types: begin of slis_subtot_text,
criteria type slis_fieldname,
keyword like dd03p-reptext,
criteria_text(255) type c,
max_len like dd03p-outputlen,
display_text_for_subtotal(255) type c,
end of slis_subtot_text.
*** Layout
types: begin of slis_print_alv0,
print(1) type c, " print to spool
prnt_title(1) type c, " moment to print the title
end of slis_print_alv0.
types: begin of slis_print_alv1,
no_print_selinfos(1) type c, " display no selection infos
no_coverpage(1) type c, "
no_new_page(1) type c, "
reserve_lines type i, " lines reserved for end of page
no_print_listinfos(1) type c, " display no listinfos
no_change_print_params(1) type c, " don't change linesize
no_print_hierseq_item(1) type c, "don't expand item
end of slis_print_alv1.
types: begin of slis_print_alv.
include type alv_s_prnt.
include type slis_print_alv1.
types: end of slis_print_alv.
types: begin of slis_layout_main,
dummy,
end of slis_layout_main.
types: begin of slis_layout_alv_spec0,
no_colhead(1) type c, " no headings
no_hotspot(1) type c, " headings not as hotspot
zebra(1) type c, " striped pattern
no_vline(1) type c, " columns separated by space
cell_merge(1) type c, " not suppress field replication
edit(1) type c, " for grid only
187
edit_mode(1) type c, " for grid only
numc_sum(1) type c, " totals for NUMC-Fields possib.
no_input(1) type c, " only display fields
f2code like sy-ucomm, "
reprep(1) type c, " report report interface active
no_keyfix(1) type c, " do not fix keycolumns
expand_all(1) type c, " Expand all positions
no_author(1) type c, " No standard authority check
* PF-status
def_status(1) type c, " default status space or 'A'
item_text(20) type c, " Text for item button
end of slis_layout_alv_spec0.
types: begin of slis_layout_alv_spec1,
* Display options
colwidth_optimize(1) type c,
no_min_linesize(1) type c, " line size = width of the list
min_linesize like sy-linsz, " if initial min_linesize = 80
max_linesize like sy-linsz, " Default 250
window_titlebar like sy-title,
no_uline_hs(1) type c,
* Exceptions
lights_fieldname type slis_fieldname," fieldname for exception
lights_tabname type slis_tabname, " fieldname for exception
lights_rollname like dfies-rollname," rollname f. exceptiondocu
lights_condense(1) type c, " fieldname for exception
* Sums
no_sumchoice(1) type c, " no choice for summing up
no_totalline(1) type c, " no total line
no_subchoice(1) type c, " no choice for subtotals
no_subtotals(1) type c, " no subtotals possible
no_unit_splitting type c, " no sep. tot.lines by inh.units
totals_before_items type c, " diplay totals before the items
totals_only(1) type c, " show only totals
totals_text(60) type c, " text for 1st col. in total line
subtotals_text(60) type c, " text for 1st col. in subtotals
* Interaction
box_fieldname type slis_fieldname, " fieldname for checkbox
box_tabname type slis_tabname," tabname for checkbox
box_rollname like dd03p-rollname," rollname for checkbox
expand_fieldname type slis_fieldname, " fieldname flag 'expand'
hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
confirmation_prompt, " confirm. prompt when leaving
key_hotspot(1) type c, " keys as hotspot " K_KEYHOT
flexible_key(1) type c, " key columns movable,...
group_buttons(1) type c, " buttons for COL1 - COL5
get_selinfos(1) type c, " read selection screen
group_change_edit(1) type c, " Settings by user for new group
no_scrolling(1) type c, " no scrolling
* Detailed screen
detail_popup(1) type c, " show detail in popup
detail_initial_lines(1) type c, " show also initial lines
detail_titlebar like sy-title," Titlebar for detail
* Display variants
header_text(20) type c, " Text for header button
default_item(1) type c, " Items as default
* colour
info_fieldname type slis_fieldname, " infofield for listoutput
coltab_fieldname type slis_fieldname, " colors
* others
list_append(1) type c, " no call screen
xifunckey type aqs_xikey, " eXtended interaction(SAPQuery)
xidirect type flag, " eXtended INTeraction(SAPQuery)
dtc_layout type dtc_s_layo, "Layout for configure the Tabstip
end of slis_layout_alv_spec1.
types: begin of slis_layout_alv_spec.
include type slis_layout_alv_spec0.
include type slis_layout_alv_spec1.
types: end of slis_layout_alv_spec.
188
types: begin of slis_layout_alv.
include type slis_layout_main.
include type slis_layout_alv_spec.
types: end of slis_layout_alv.
types: begin of slis_layout_alv1.
include type slis_layout_main.
include type slis_layout_alv_spec1.
types: end of slis_layout_alv1.
*--- Structure for the excluding table (function codes)
types: begin of slis_extab,
fcode like rsmpe-func,
end of slis_extab.
*--- Lineinfo before output
types: begin of slis_lineinfo,
tabname type slis_tabname,
tabindex like sy-tabix,
subtot(1) type c,
subtot_level(2) type n,
endsum(1) type c,
sumindex like sy-tabix,
linsz like sy-linsz,
linno like sy-linno,
end of slis_lineinfo.
*--- Structure for scrolling in list
types: begin of slis_list_scroll,
lsind like sy-lsind,
cpage like sy-cpage,
staro like sy-staro,
staco like sy-staco,
cursor_line like sy-curow,
cursor_offset like sy-cucol,
end of slis_list_scroll.
* information cursor position ALV
types: begin of slis_selfield,
tabname type slis_tabname,
tabindex like sy-tabix,
sumindex like sy-tabix,
endsum(1) type c,
sel_tab_field type slis_sel_tab_field,
value type slis_entry,
before_action(1) type c,
after_action(1) type c,
refresh(1) type c,
ignore_multi(1) type c, " ignore selection by checkboxes (F2)
col_stable(1) type c,
row_stable(1) type c,
* colwidth_optimize(1) type c,
exit(1) type c,
fieldname type slis_fieldname,
grouplevel type i,
collect_from type i,
collect_to type i,
end of slis_selfield.
*--- excluding table
types: slis_t_extab type slis_extab occurs 1.
* special groups for column selection
types: begin of slis_sp_group_alv,
sp_group(4) type c,
text(40) type c,
end of slis_sp_group_alv.
types: slis_t_sp_group_alv type slis_sp_group_alv occurs 1.
* information for sort and subtotals
types: begin of slis_sortinfo_alv,
* spos(2) type n,
spos like alvdynp-sortpos,
fieldname type slis_fieldname,
tabname type slis_fieldname,
189
* up(1) type c,
* down(1) type c,
* group(2) type c,
* subtot(1) type c,
up like alvdynp-sortup,
down like alvdynp-sortdown,
group like alvdynp-grouplevel,
subtot like alvdynp-subtotals,
comp(1) type c,
expa(1) type c,
obligatory(1) type c,
end of slis_sortinfo_alv.
types: slis_t_sortinfo_alv type slis_sortinfo_alv occurs 1.
* information for selections
types: begin of slis_seldis1_alv,
field like dfies-fieldname,
table like dfies-tabname,
stext(40),
valuf(80),
valut(80),
sign0(1),
optio(2),
ltext(40),
stype(1),
length type p,
no_text(1),
inttype like dfies-inttype,
fieldname type slis_fieldname,
tabname type slis_tabname,
org_selname type rsscr_name, "introduced this FO 09.01.00
end of slis_seldis1_alv.
types: slis_seldis_alv type slis_seldis1_alv occurs 1.
* filter
types: begin of slis_filter_alv0,
fieldname type slis_fieldname,
tabname type slis_tabname,
seltext(40),
valuf(80),
valut(80),
valuf_int(80),
valut_int(80),
sign0(1),
sign_icon(4),
optio(2),
stype(1),
decimals like dfies-decimals,
intlen like dfies-intlen,
convexit like dfies-convexit,
edit_mask type slis_edit_mask,
lowercase like dfies-lowercase,
inttype like dfies-inttype,
datatype like dfies-datatype,
exception(1) type c,
no_sign(1) type c,
or(1) type c,
order type order,
cqvalue(5) type c,
end of slis_filter_alv0.
types: begin of slis_filter_alv1,
ref_fieldname like dfies-fieldname,
ref_tabname like dfies-tabname,
ddic_outputlen like dfies-outputlen,
end of slis_filter_alv1.
types: begin of slis_filter_alv.
include type slis_filter_alv0.
include type slis_filter_alv1.
types: end of slis_filter_alv.
190
types: slis_t_filter_alv type slis_filter_alv occurs 1.
* delete or add an entry in the select-option info
types: begin of slis_selentry_hide_alv,
mode(1) type c, "(D)elete (A)dd
selname like rsparams-selname.
include type slis_seldis1_alv.
types end of slis_selentry_hide_alv.
types: slis_t_selentry_hide_alv type slis_selentry_hide_alv occurs 1.
* delete or add an entry in the select-option info
types: begin of slis_sel_hide_alv,
mode(1) type c, "(R)eplace or (C)hange
t_entries type slis_t_selentry_hide_alv,
end of slis_sel_hide_alv.
* Header table for top of page
types: begin of slis_listheader,
typ(1) type c, " H = Header, S = Selection, A = Action
key(20) type c,
info type slis_entry,
end of slis_listheader.
types: slis_t_listheader type slis_listheader occurs 1.
*--- Structure for specific color settings
types: begin of slis_specialcol_alv,
fieldname type slis_fieldname,
color type slis_color,
nokeycol(1) type c,
end of slis_specialcol_alv.
types: slis_t_specialcol_alv type slis_specialcol_alv occurs 1.
*--- Structure for event handling
types: begin of slis_alv_event,
name(30),
form(30),
end of slis_alv_event.
types: slis_t_event type slis_alv_event occurs 0.
*--- Structure for key information
types: begin of slis_keyinfo_alv,
header01 type slis_fieldname,
item01 type slis_fieldname,
header02 type slis_fieldname,
item02 type slis_fieldname,
header03 type slis_fieldname,
item03 type slis_fieldname,
header04 type slis_fieldname,
item04 type slis_fieldname,
header05 type slis_fieldname,
item05 type slis_fieldname,
end of slis_keyinfo_alv.
*--- Structure for callback CALLER_EXIT and REUSE_ALV_POPUP_TO_SELECT
types: begin of slis_data_caller_exit,
dummy like sy-repid,
without_load_variant(1),
callback_header_transport type slis_formname,
columnopt(1),
end of slis_data_caller_exit.
types: begin of slis_status,
callback_program like sy-repid,
callback_pf_status_set type slis_formname,
callback_user_command type slis_formname,
counter_of_lists_added type i,
actual_list_to_display type i,
flg_to_be_refreshed,
it_excluding type slis_t_extab,
print type slis_print_alv,
flg_checkboxes_active,
flg_overview_active,
flg_intcheck(1) type c,
end of slis_status.
* Exporting structure
types: begin of slis_exit_by_user,
191
back(1) type c,
exit(1) type c,
cancel(1) type c,
end of slis_exit_by_user.
constants:
* Events
slis_ev_item_data_expand type slis_formname value 'ITEM_DATA_EXPAND',
slis_ev_reprep_sel_modify type slis_formname value 'REPREP_SEL_MODIFY',
slis_ev_caller_exit_at_start type slis_formname value 'CALLER_EXIT',
slis_ev_user_command type slis_formname value 'USER_COMMAND',
slis_ev_top_of_page type slis_formname value 'TOP_OF_PAGE',
slis_ev_data_changed type slis_formname value 'DATA_CHANGED',
slis_ev_top_of_coverpage type slis_formname value 'TOP_OF_COVERPAGE',
slis_ev_end_of_coverpage type slis_formname value 'END_OF_COVERPAGE',
slis_ev_foreign_top_of_page type slis_formname
value 'FOREIGN_TOP_OF_PAGE',
slis_ev_foreign_end_of_page type slis_formname
value 'FOREIGN_END_OF_PAGE',
slis_ev_pf_status_set type slis_formname value 'PF_STATUS_SET',
slis_ev_list_modify type slis_formname value 'LIST_MODIFY',
slis_ev_top_of_list type slis_formname value 'TOP_OF_LIST',
slis_ev_end_of_page type slis_formname value 'END_OF_PAGE',
slis_ev_end_of_list type slis_formname value 'END_OF_LIST',
slis_ev_after_line_output type slis_formname value 'AFTER_LINE_OUTPUT',
slis_ev_before_line_output type slis_formname value
'BEFORE_LINE_OUTPUT',
slis_ev_subtotal_text type slis_formname value
'SUBTOTAL_TEXT'.
192
Appendix
B
How to colour lines of a report
1. Include a 4-character field in the internal data table that is being passed to
REUSE_ALV_GRID_DISPLAY.
Eg: DATA: BEGIN OF i_data OCCURS 10,
qmnum LIKE viqmel-qmnum,
qmart LIKE viqmel-qmart,
zzvalstat LIKE viqmel-zzvalstat,
valstattxt LIKE zawprcode-valstattxt,
kunum LIKE viqmel-kunum,
bstnk LIKE viqmel-bstnk,
qmtxt LIKE viqmel-qmtxt,
ws_color(4)TYPE c,
END OF i_data.
2. In the code, loop through the lines of the internal table and assign values to this field. The 4-
character value will be of the format - Cxyz.
Char 1 – is always C indicating that it’s a color property.
Char 2 (x) – color code, which can be any value from (1 – 7).
Char 3 (y) – Intensity on/off. (1 = on, 0 = off).
Char 4 (z) – Inverse display on/off. (1 = on, 0 = off).
(From the above, it is clear that we can have only 28 different coloring options)
Eg: C401.
LOOP AT i_data.
IF (expression 1).
i_data-ws_color = ‘C510’.
ELSEIF(expression 2).
i_data-ws_color = ‘C200’.
ELSE.
i_data-ws_color = ‘C711’.
ENDIF.
MODIFY i_data.
ENDLOOP.
3. When specifying the layout properties, specify the name of this field (ws_color) as the color
field.
FORM f1200_define_layout CHANGING p_i_layout TYPE
slis_layout_alv.
CLEAR p_i_layout.
p_i_layout-zebra = 'X'.
p_i_layout-colwidth_optimize = 'X'.
p_i_layout-info_fieldname = 'WS_COLOR'.
193
ENDFORM. " F1200_define_layout
Example:
Shown below is screen dump with 14 coloring options. You could try out the rest 14!!
Code:
LOOP AT i_data.
cnt = cnt + 1.
IF cnt = 1.
i_data-ws_color = 'C110'.
ELSEIF cnt = 2.
i_data-ws_color = 'C210'.
ELSEIF cnt = 3.
i_data-ws_color = 'C310'.
ELSEIF cnt = 4.
i_data-ws_color = 'C410'.
ELSEIF cnt = 5.
i_data-ws_color = 'C510'.
ELSEIF cnt = 6.
i_data-ws_color = 'C610'.
ELSEIF cnt = 7.
i_data-ws_color = 'C710'.
elseIF cnt = 8.
i_data-ws_color = 'C100'.
ELSEIF cnt = 9.
i_data-ws_color = 'C200'.
ELSEIF cnt = 10
i_data-ws_color = 'C300'.
ELSEIF cnt = 11.
i_data-ws_color = 'C400'.
ELSEIF cnt = 12.
i_data-ws_color = 'C500'.
ELSEIF cnt = 13.
i_data-ws_color = 'C600'.
ELSEIF cnt = 14.
i_data-ws_color = 'C700'.
ENDIF.
MODIFY i_data.
ENDLOOP.
194
Module pools
195
Controlling the Screen Flow
Overview
For the user, a transaction is a series of screens that appear one after another.
In the transaction program, screens are chained together by a series of
“next-screen” numbers. When you define the transaction, you specify the
number of the first screen. Then, for each screen in the transaction, you
can specify a “next screen” statically or dynamically:
Static screen pointers
When you define a screen, you specify a Next screen attribute for it. This
attribute gives the name of the screen that is to follow the current screen by
default. However, the static attribute is overridden whenever a “next-screen”
is set dynamically.
Transaction
Attributes
Name: TZ40
First Screen: Screen
100
Screen
200
Next Screen = 200 Next Screen = 0
Static Screen Chain
END
196
Dynamic screen
sequence
Any screen can set its own “next screen” as part of screen processing. The
ABAP/4 commands for doing this are SET SCREEN and CALL SCREEN.
When you set screens dynamically, you can string them together one after the
other (as in a chain), or insert groups of them into the current chain.
The following topics provide information on handling screens in a transaction:
Introduction to Screen Flow Control
Setting the Next Screen
Calling a New Screen Sequence
Leaving the Current Screen
Example Transaction: Setting and Calling Screens
Processing Screens in Background
197
Introduction to Screen Flow Control
As an example of controlling screen flow in a transaction, look at transaction
TZ40. (This transaction is in development class SDWA and is delivered with the
system.) TZ40 lets users display flight information and enter updates into the
display.
TZ40 uses two screens and a dialog box (popup window) for getting user
updates. The transaction always displays the first two screens (numbers 100 and
200). The third (210) however only appears under certain conditions. The
possible flow of screens looks as follows:
Screen
100
Screen
200
Screen
210
Possible Screen Flow
In practice, the user sees the following sequence:
Screen 100: The user enters flight information and presses ENTER to
request a display of flight details.
Screen 200: The system displays complete details about the flight, in update
mode. The user types over the display to enter the changes.
198
Screen 210
Screen 210 appears only if the user tries to exit screen 200 without saving. The
popup reminds the user to save the changes or cancel them (by specifying Yes or
No).
199
To make this sequence of screens possible, transaction TZ40 must be able to
call the dialog box screen conditionally.
An ABAP/4 module can “branch to” or “call” the next screen. The difference
lies in where you want control to go after processing the next screen. The
relevant ABAP/4 commands are:
SET SCREEN <screen-number>.
CALL SCREEN <screen-number>.
LEAVE SCREEN.
LEAVE TO SCREEN <screen-number>.
With SET SCREEN, the current screen simply specifies the next screen in the
chain. Control branches to this next screen as soon as the current screen has
been processed. Return from next screen to current screen is not automatic.
With CALL SCREEN, the current (calling) chain is suspended, and a next
screen (or screen chain) is called in. The called screen can then return to the
suspended chain with the statement LEAVE SCREEN TO SCREEN 0.
For complete information, see:
Setting the Next Screen
Calling a New Screen Sequence
Leaving the Current Screen
200
Setting the Next Screen
Every screen has a static Next screen attribute that specifies the next screen to
follow the current one. You can override this specification by using the SET
SCREEN statement:
SET SCREEN <screen number>.
SET SCREEN tells the system to ignore the statically defined Next screen and use
<screen number> as the next screen instead.
Screen 100
Next Screen = 110
Screen 200
Next Screen = 210
Screen 110 Screen 210
SET SCREEN 200
Next Screen = 120 Next Screen = 220
Screen 120
Next Screen = 130
Screen 220
Next Screen = 0
SET SCREEN
This override is temporary and has no effect on the attribute values stored in the
Screen
Painter
.
A SET SCREEN statement merely specifies the next screen: it does not
interrupt processing of the current screen. If you want to branch to the
next screen without finishing the current one, use LEAVE SCREEN.
Note
Note that you can specify the next-screen number with a variable:
DATA: REQSCRN LIKE SY-DYNNR VALUE ‘100’.
MODULE SET_NEXT_SCREEN.
SET SCREEN REQSCRN.
ENDMODULE.
The system field SY-DYNNR always contains the number of the current screen.
201
202
Calling a New Screen Sequence
Sometimes you want to insert a screen, or a whole sequence of screens, into the
course of a transaction. For instance, you might want to let an user call a popup
screen from the main application screen to let them enter secondary information.
After they have completed their entries, the users should be able to close the
popup and return directly to the place where they left off in the main screen. There
are two methods for doing this:
use the CALL SCREEN statement
The CALL SCREEN statement lets you insert such a sequence into the
current one. Using this statement is described here.
call a dialog module
A dialog module is a callable sequence of screens that does not belong to a
particular transaction. Dialog modules have their own module pools, and can
be called by any transaction. For information on using dialog modules, see
Calling Dialog Modules.
The syntax for calling up a new screen sequence is:
CALL SCREEN <screen number>.
You can think of CALL SCREEN as “stacking” a sequence, since the statement
actually suspends the current sequence and starts a new one. The system
continues with the new sequence until it is finished, at which point the suspended
sequence is resumed. (Processing resumes with the statement directly after the
CALL SCREEN.)
Screen 100
Next Screen = 110
Screen 200
Next Screen = 210
Screen 110
CALL SCREEN 200
. . .
Next Screen = 120
Screen 210
Next Screen = 220
Screen 120 Screen 220
Next Screen = 130 Next Screen = 0
CALL SCREEN
203
204
To call a screen as a dialog box (popup), use CALL SCREEN with the options
STARTING AT, ENDING AT:
CALL SCREEN <screen number>
STARTING AT <start column> <start line>
ENDING AT <end column> <end line>
The STARTING AT and ENDING AT options tell the system where to
position the popup screen. The screen itself must be smaller than a regular
screen.
In the ABAP/4 world, each stackable sequence of screens is a “call mode”. This
is important because of the way you return from a given current sequence. To
terminate a call mode and return to a suspended chain, set the “next screen” to 0
and leave to it:
LEAVE TO SCREEN 0. or SET SCREEN 0.
LEAVE SCREEN.
When you return to the suspended chain, execution resumes with the statement
directly following the original CALL SCREEN statement.
The original sequence of screens in a transaction is itself a calling mode. If you
LEAVE TO SCREEN 0 in this sequence (that is, without having stacked any
additional call modes), you return from the transaction altogether.
Note
You can have up to 9 calling modes stacked at one time.
Leaving the Current Screen
To discontinue processing for the current screen, use:
LEAVE TO SCREEN <screen number>.
or
SET SCREEN <number>.
LEAVE SCREEN.
Both of these statements terminate processing for the current screen and go directly
to
<screen number>. If you use SET SCREEN without LEAVE SCREEN, the
program finishes processing for the current screen before branching to
<screen number>.
If you use LEAVE SCREEN without a SET SCREEN before it, you terminate the
current screen and branch directly to the screen specified as the default next-
screen in the screen attributes.
In “calling mode”, the special screen number 0 (LEAVE TO SCREEN 0) causes
the system to jump back to the previous call level. That is, if you have called a
screen sequence with CALL SCREEN, leaving to screen 0 terminates the
sequence and returns to the calling screen. If you have not called a screen
sequence, LEAVE TO SCREEN 0 terminates the transaction. For information on
CALL SCREEN, see Calling a New Screen Sequence.
205
206
Example Transaction: Setting and Calling Screens
To see a complete implementation of screen flow control, it is useful to look
at how transaction TZ40 (development class SDWA) is organized.
Screen Flow Logic
To demonstrate how a transaction branches to or calls a screen, look at processing
for screen 200. The handling of the exit commands (function codes BACK and
EXIT) shows how. When handling a BACK or EXIT function code, the PAI
module must check whether flight details have changed since the screen display or
last save. If so, screen 200 must call up the popup 210 to prompt about saving.
The relevant parts of the screen
200’s flow logic are:
*---------------------------------------------------------------*
* Screen 200: Flow Logic *
*&--------------------------------------------------------------*
PROCESS AFTER INPUT.
MODULE EXIT_0200 AT EXIT-COMMAND.
* (...<Field checks here>...)
MODULE USER_COMMAND_0200.
ABAP/4 Code
The PAI modules for screen 200 follow. Transaction TZ40 offers all the return
functions (Back , Exit and Cancel) as exit-commands. In Screen 200, however,
only the Cancel function allows immediate exit from the screen. To effect a
cancel, standard exit logic is used to tell the system to go back to screen 100:
207
*&---------------------------------------------------------------*
*& Module EXIT_0200 INPUT
*&---------------------------------------------------------------*
MODULE EXIT_0200 INPUT.
CASE OK_CODE.
WHEN ’CANC’.
CLEAR OK_CODE.
SET SCREEN 100.
LEAVE SCREEN.
ENDCASE.
ENDMODULE.
All other function codes for screen 200 are handled as
follows: The SAVE function triggers an update of the
database.
The EXIT and BACK functions trigger calls to the SAFETY_CHECK
routine. This routine checks for unsaved data in the screen, and reminds the
user to save if necessary.
Note the return technique. For the EXIT function, control returns from the
transaction altogether (SET SCREEN 0). For the BACK function, the previous
screen is set as the following screen. (SET SCREEN 100).
*&---------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
CASE OK_CODE.
WHEN ’SAVE’.
UPDATE SPFLI.
IF SY-SUBRC = 0.
MESSAGE S001 WITH SPFLI-CARRID SPFLI-CONNID.
ELSE.
MESSAGE A002 WITH SPFLI-CARRID SPFLI-CONNID.
ENDIF.
CLEAR OK_CODE.
WHEN ’EXIT’.
CLEAR OK_CODE.
PERFORM SAFETY_CHECK USING RCODE.
IF RCODE = ’EXIT’. SET SCREEN 0. LEAVE SCREEN. ENDIF.
WHEN ’BACK’.
CLEAR OK_CODE.
PERFORM SAFETY_CHECK USING RCODE.
IF RCODE = ’EXIT’. SET SCREEN 100. LEAVE SCREEN. ENDIF.
ENDCASE.
ENDMODULE.
Code for the SAFETY_CHECK routine follows. The CHECK statement
compares current screen values to the saved screen values. If the values match,
no save is needed, and the routine terminates.
If the values differ, SAFETY_CHECK calls the popup screen 210. The popup
asks the user if he wants to save, and returns the answer (SAVE, EXIT and
CANC) in the OK_CODE.
*---------------------------------------------------------------*
208
* Subroutine SAFETY_CHECK *
*-----------------------------------------------------------
----* FORM SAFETY_CHECK USING RCODE.
LOCAL OK_CODE.
RCODE = ’EXIT’.
CHECK SPFLI NE OLD_SPFLI.
CLEAR OK_CODE.
CALL SCREEN 210 STARTING AT 10 5.
CASE OK_CODE.
WHEN ’SAVE’. UPDATE SPFLI.
WHEN
’EXIT’.
WHEN ’CANC’. CLEAR SPFLI.
ENDCASE.
ENDFORM.
Processing Screens in
Background
You can suppress entire screens using SUPPRESS DIALOG. This
command allows you to perform screen processing "in the background".
The system carries out all PBO and PAI logic, but does not display the
screen to the user.
Suppressing screens is useful when you are branching to list-mode from
a transaction dialog step.
Use the SUPPRESS DIALOG command in the first module called from the
screen’s
PBO logic. For example:
**** ABAP/4 module processing for Screen 100
CALL SCREEN 110 STARTING AT 10 5
**** Screen 110 flow logic
PROCESS BEFORE OUTPUT.
MODULE DIALOG_WINDOW.
**** ABAP/4 module processing
MODULE DIALOG_WINDOW OUTPUT.
SUPPRESS DIALOG.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
WRITE: /
WRITE: /
ENDMODULE.
The SUPPRESS DIALOG statement lets you use the processing context
for screen 110 as a framework for displaying the standard list output. If
you don’t use SUPPRESS DIALOG here, screen 110 is displayed, and is
empty. When the user presses ENTER, the standard list output is displayed.
209
Tab Strip Controls through ABAP
by
Sreenivas Palakurty
1. Introduction:
Tab Strips allow us to easily define different components of an application on a single
screen and navigate between them. Instead of navigating between many screens,
the user at once sees all the destinations he or she must call to accomplish the given
task.
Let us
consider
the
example of
a tab strip
which we see very often.
Author Vijay Sai Vempati
Reviewer
Review Date
Version 1.0
210
Fig 1: Example of a Tab Strip
As the figure shows, there are different tabs like General, Computer name,
Hardware, Advanced etc in a single dialog box. Each of these tabs shows us a
different display with customizations as per the user requirements. The task of the
user is simplified to a great extent as the need for navigating between the screens is
reduced.
This BOK intends to explain the creation of Tab Strip Controls through:
1) Report Programming.
2) Dialog Programming.
2. Components of a Tab Strip:
The main components of a Tab Strip are:
2.1 Tab Titles:
They refer to the name of the tab and are generally sorted from left to right
according to the workflow. Incase there are more number of tab titles than can be
displayed; the R/3 system automatically displays scroll buttons for horizontal
scrolling at the upper right margin.
The R/3 system does not support multiple-line tab titles. If multiple lines were used
instead of the scroll buttons, due to the language dependency of the titles a different
number of tab title lines would appear for each logon language. Since the tab page is
of fixed size, the developer would have to save as many blank lines above the tab
211
strip as might be needed under worst conditions. This would waste screen space and
reduce readability.
2.2 Tab Page:
The Screen Painter locks the first line of a tab page, which the system needs to draw
the tab titles. Otherwise, the layout rules for creating screens apply. A tab strip
requires three additional screen lines for the tab titles line, the lower border, and the
locked first line.
A tab page together with the tab titles texts corresponds to a group box. Therefore,
you need no further box that includes all fields of a tab page.
2.3 Environment:
The tab strip should be provided with a constant environment. This means that if you
go from one tab page to another, the menu bar and the application bar must not
change.
2.4 Navigation:
The user perceives a screen that contains a tab strip as a unit. The individual tab
pages thus are components of the screen, such as boxes of groups of fields.
3. Programming the Tab Strips:
Tab Strips can be programmed either through Report or Dialog.
3.1 Report Programming:
The Tab Strip controls can be made through report programming by defining sub
screens in the selection screen and assigning the user command to the tab titles.
Example:
212
Fig 2: Example of a Tab Strip control through Report Program
For the Tab Strip Control of fig 2, there are three sub screens which were initially
defined.The piece of code which creates the sub screen within the selection screen is
written below:
The statement “selection-screen begin of screen <<screen no>> as sub
screen” defines sub screen in the selection screen.
In this way, we can define as many sub screens as required on the selection screen
in which the tab strip control is included. The code given below maps the tab strip
controls with the sub screens.
selection-screen begin of screen 100 as subscreen.
selection-screen begin of block b1 with frame.
parameters: p1(10) type c,
p2(10) type c,
p3(10) type c.
selection-screen end of block b1.
selection-screen end of screen 100.
selection-screen: begin of tabbed block mytab for 10 lines,
tab (20) button1 user-command push1,
tab (20) button2 user-command push2,
tab (20) button3 user-command push3,
selection-screen end of block mytab.
213
The statement “selection-screen begin of tabbed block <<block>> for n
lines” maps the sub screens with the defined Tab Strip Control <<block>>. n
defines the number of lines in the sub screen area.
The statement “selection-screen end of block <<block>>” closes the block
opened.
Inside the tabbed block, we create the tab page and assign the function code to it.
“selection-screen tab (len) tabname user-command ucomm” creates a tab
page with name tabname and length len and assigns the function code ucomm to
it.
In the above example button-1, button-2 and button-3 refer to the tab names
and push1, push2 and push3 refer to the function codes assigned to the respective
tabs.
The tab names are entered as text elements through the following path:
Goto  Text elements  Text symbols.
The following piece of code assigns the tab names to the text elements:
The next step in the process is to determine the active tab at the runtime. This is
obtained by defining the active tab page and the sub screen number. Consider the
following piece of code.
button1 = text-010.
button2 = text-020.
button3 = text-060.
initialization.
mytab-prog = sy-repid.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.
214
In the above code, we are defining the active tab as Button 1 which is the sub screen
100.
mytab-activetab = ‘BUTTON1’ activates the tab title whose function code is
BUTTON1.
So, when we run the program and enter the selection screen, the default tab will be
BUTTON1.
The next step in the process is the navigation of the screens within the Tab Strip
controls.
Consider the following piece of code:
Depending upon the tab selected, the corresponding sub screen should be shown for
further processing or entering the required data. Whenever a tab name is selected,
the corresponding sub screen should be called and the active tab has to be the tab
name, as seen in the above example.
This is how we create Strip controls through Report programming.
at selection-screen.
case sy-ucomm.
when 'PUSH1'.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.
when 'PUSH2'.
mytab-dynnr = 200.
mytab-activetab = 'BUTTON2'.
when 'PUSH3'.
mytab-dynnr = 300.
mytab-activetab = 'BUTTON3'.
endcase.
215
3.2Dialog Programming:
Initially the tab strip has to be defined in the screen painter. Execute the
following steps to create a simple tab strip:
1) Set the tab strip borders.
2) Define tab titles.
3) Define and allocate the sub screen area.
4) Program the flow logic.
3.2.1 Set the tab Strip borders:
After creating the tab strip, set the borders i.e. length and height of the tab
strip control. Incase of a Graphical Screen painter determine the area by
dragging the mouse over the screen. Incase of a non-graphical screen painter
enter manually the length and height of the tab strip.
3.2.2 Define Tab Titles:
By default, the new tab strip contains two tab titles. Technically, tab titles are
treated like pushbuttons. This becomes obvious when you double-click on a
tab title in the attributes window. For each tab title, enter field name, field
text, and function code.
3.2.3 Define and allocate the sub screen area:
Each tab title must be allocated to a sub screen area. In order to do this,
select a tab title and create a sub screen in it.
216
Fig 3: Tab Strip Control element
As an example, in the above figure, the sub screen SUBSCR1 is assigned to the
tab strip with tabs TAB1 and TAB2.
3.2.4 Program the Flow Logic:
The sub screens which are used in the program are to be included as follows:
In the module pool, declare the tab strip similar to the table control using the
CONTROLS Statement.
PROCESS BEFORE OUTPUT.
...
CALL SUBSCREEN <area> INCLUDING <program> <screen>.
...
PROCESS AFTER INPUT.
...
CALL SUBSCREEN <area>.
CONTROLS: MYTABSTRIP
217
In the above example, MYTABSTRIP is the field name of the tab strip in the
screen painter. At runtime, at present only the attribute ACTIVETAB is
available, which determines the currently active tab page. You fill it with the
function code of the corresponding tab title.
To activate the tab title whose function code is ‘F1’, use the statement:
In the Process after input, we check for the tab which is pressed and then
execute the tab strip as per the fcode. A typical code for that
looks as follows:
This is how we generate Tab Strip controls through Dialog Programming.
MYTABSTRIP-ACTIVETAB = ‘F1’
MODULE FCODE.
CASE OK_CODE.
WHEN ‘TAB1’.
DYNPRONR = ‘0200’.
TABSTRIP1-ACTIVETAB =
OK_CODE.
CLEAR OK-CODE
WHEN ‘TAB2’.
DYNPRONR = ‘0300’.
TABSTRIP1-ACTIVETAB =
OK_CODE.
....
218
Submitted by: Sreenivas Palakurty
Introduction to
SMARTFORMS
219
Table of Contents
Introduction
Purpose of this Introduction…………………………………………. 220
Who will benefit………………………………………………………. 220
Prerequisites…………………………………………………………… 220
refresher on sapscript………………………………………………… 3
Smart Forms: What is it?……………………………………………… 221
SmartForms Vs SAP Script…………………………………………… 221
Main Advantages of Smart Forms…………………………………… 221
features introduced by sap in smart forms………………………… 4
architecture of sap smartform……………………………………… 5
hands on screen sequence
smartforms……………….……………………………………………. 7
page and windows……………………………………………………… 12
smartstyle……………………………………………………………… 28
template………………………………………………………………… 38
config setting…………………………………………………………... 54
refresher on smartforms : summary……………………………… 58
220
Introduction
Purpose of this Introduction
This introduction is intended to allow a quick entry into the work with the
Smart Forms. SAP introduced SmartForms in 1998 to overcome the
limitations in SAP Scripts. This document would help a beginner to start
from scratch and generate his own Smart Forms. There is a self help
screen sequence to guide the beginners to create Smartforms of their own
and gain confidence
Who will benefit
All SAP users. Most of the new projects would be using this technology.
Clients would increasingly demand smartforms to be used rather than
sapscript.
Prerequisites
The user should know SAP Script. In this document I would briefly
compare SAP script with SAP SMART Forms, highlighting the prominent
features before moving on to how to work with SMART Forms, which is
our focus.
SAP Script is SAP text management and form printing tool. By this we make a output
look beautiful which is cumbersome to do by a report program.
SAPscript consists of the following components:
An editor for entering and editing text Styles and forms for designing the print
layout
A composer, which is the central module for output formatting
A programming interface for integrating SAPscript components in your own
application programs and programming the output using forms
Various database tables for storing texts, styles and forms
REFRESHER ON
SAP SCRIPT
WE can insert picture or Logo (Company Logo) in the output, which is not possible by
report program.
221
Smart Forms: What is it?
We use SAP Smart Forms to create and maintain forms for mass printing in SAP
Systems. SmartForms are easier to develop, maintain and transport than SAP Script.
As output medium SAP Smart Forms support a printer, a fax, e-mail, or the Internet (by
using the generated XML output).In addition to the tool, SAP delivers a selection of
forms for central business processes like forms in the applications SD,FI, HR and CRM
of the R/3 Release.
SmartForms Vs SAP Script
Multiple page formats are possible in smartforms which is not the case in
SAPScripts
It is possible to have a smartform without a main window .
Labels cannot be created in smartforms.
Routines can be written in smartforms tool.
Smartforms generates a function module when activated.
Main Advantages of Smart Forms:
SAP Smart Forms offer the following advantages:
Creating and maintaining forms requiring half the time
Adapting forms without any programming knowledge due to entirely graphical
user interface
Web Publishing using the generated XML output
The SAP Smart Forms has replaced the SAPscript forms. SAPscript forms will also be
supported in the future; you can use them without making any changes for years to come.
You can use SAPscript texts in the Smart Forms. Migration of SAPscript forms into
Smart Forms is supported.
Features introduced by SAP in Smart Forms:
THE SMART FORMS ALLOW THE USER TO EXECUTE SIMPLE MODIFICATIONS TO THE FORM AND IN THE
FORM LOGIC BY USING SIMPLE GRAPHICAL TOOLS.
NOTE
222
TO PRINT A FORM THE USER WILL NEED A PROGRAM FOR THE DATA RETRIEVAL AND A SMART FORM
THAT CONTAINS THE ENTIRE FORM LOGIC. AS THESE TWO ARE SEPARATE WE SHOULD ADAPT THE SMART
FORM IF CHANGES TO THE FORM LOGIC IS NECESSARY. THE APPLICATION PROGRAM PASSES THE DATA
VIA A FUNCTION MODULE INTERFACE TO THE SMART FORM. WHEN ACTIVATING THE SMART FORM THE
SYSTEM AUTOMATICALLY GENERATES THE FUNCTION MODULE AND AT THE RUNTIME PROCESS THIS.
THE USER DESIGNS THE FORM USING THE GRAPHICAL FORM PAINTER AND THE GRAPHICAL TABLE
PAINTER. THE FORM LOGIC IS REPRESENTED BY THE HIERARCHICAL STRUCTURE THAT CONSISTS OF
INDIVIDUAL NODES, SUCH AS NODES FOR GLOBAL SETTINGS, NODES FOR TEXTS, NODES FOR OUTPUT
TABLES OR NODES FOR GRAPHICS. TO MAKE ANY CHANGES WE HAVE TO USE THE DRAG&DROP,
CUT&PASTE. THESE ACTIONS DO NOT INCLUDE WRITING OF CODING LINES OR USING A SCRIPT LANGUAGE.
FOR WEB PUBLISHING, THE SYSTEM PROVIDES A GENERATED XML OUTPUT OF THE PROCESSED
FORM.
WE CAN INSERT STATIC AND DYNAMIC TABLES. THESE INCLUDE THE LINE FEEDS IN THE INDIVIDUAL
TABLE CELLS, TRIGGERING EVENTS FOR TABLE HEADINGS AND SUBTOTALS AND SORTING DATA BEFORE
OUTPUT.
THE SMART FORMS ALLOW THE USER TO INCLUDE GRAPHICS, WHICH CAN BE DISPLAYED AS A PART
OF THE FORM OR AS BACKGROUND GRAPHICS. DURING PRINTOUT THE USER CAN SUPPRESS THE
BACKGROUND GRAPHIC AS AND WHEN NECESSARY.
THE SMART FORMS ALSO SUPPORTS THE POSTAGE OPTIMIZING.
223
Form Description
Data Retrieval
Database
SMART
FORM
Activate
ABAP
FUNCTION
MODULE
APPLICATION
PROGRAM
Database Selection
Function
Module
Call
Later
Selection
OUTPUT
(Printer)
Architecture of SAP Smart Form : Schematic Flow
224
IN A SMART FORM WE DESCRIBE:
THE LAYOUT OF THE FORM (ELEMENT POSITIONS ON A PAGE).
INDIVIDUAL ELEMENTS TO BE DISPLAYED, FOR EX: TEXT, GRAPHICS, ADDRESSES, TABLES ETC.,
THE FORM LOGIC, FOR EXAMPLE TO READ THE APPLICATION DATA FROM INTERNAL TABLES, TO
INTRODUCE CONDITIONS AND TO CONTROL THE PROCESS FLOWS.
A FORM INTERFACE TO TRANSFER THE APPLICATION DATA TO FORM DEFINITION.
WHEN A SMART FORM IS ACTIVATED , THE SYSTEM GENERATES A FUNCTION MODULE THAT
ENCAPSULATES ALL THE ATTRIBUTES OF THE SMART FORM.
AS SOON AS THE APPLICATION PROGRAM CALLS THE FUNCTION MODULE, THE SMART FORM USES THE
MODULE INTERFACE TO TRANSFER ANY TABLE DATA PREVIOUSLY SELECTED AND TO PRINT THE FORM
ACCORDING TO THE FORM DESCRIPTION.
ALL THESE WILL BECOME CLEARER ONCE WE GO THROUGH THE SELF HELP SCREEN SEQUENCE IN THE
SUBSEQUENT PAGES.
225
Hands On Guide: This is a self-help guide lucidly illustrated with tips, meant for
beginners.
We first go to SAP Menu: The path is SAP Menu  Tools  Form Printout  Smart
Forms
The transaction code (T code) : Smart Forms
Lets use forms starting with ‘BC’ as SAP has created these for training purposes.
click
226
Let’s use BC470_FLOWS to demonstrate the various elements of Smart Forms.
WE NOW ARRIVE AT THE DISPLAY FORM SCREEN, WHICH IS DIVIDED, INTO 3 MAIN SECTIONS:
click
227
NAVIGATION WINDOW, FORM PAINTER AND MAINTENANCE WINDOW. WEWILL DISCUSS EACH OF THESE IN
DETAIL
 Navigation window consist of nodes and sub nodes. They contain all the elements
(text, window etc) that belong to sap forms.
 Maintenance window shows attributes of the elements
 Form printer window shows the layout of the page.
228
GLOBAL SETTING IS AT THE FORM LEVEL. YOU CAN ACCESS THESE FROM ANYWHERE IN THE SMART FORM
You can change the language by changing this field in Form Attribute: this will change
the text
language (but not the layout).
Form interface tells us what are the import and export parameters, exceptions, tables etc
that we
SAPscript does not allow changing the language. SAP FORMS gives the user
this option.
Also whenever we create smart forms, SAP creates/generates a function module.
NOTE
229
pass to the function module. These we can add but we cannot change/modify the default
values
Lets add a Global Database for practice. I have created NUMC_DATE through TYPES
230
new type created in TYPES
231
Global definition is what we define in smart form. We can define our own variable,
constants etc. that we can access in the code that we write. Here we would use we of the
types, which we have defined earlier (char_fifteen) to declare ‘CLERK’.
232
Diff between TYPE and TYPES
TYPES: What we create: char, constants etc. TYPE is used to choose from standard SAP
data type
Pages and Windows
In smart form, page is at the highest level: SAP processes the first page, next page and
then Terms
General Terms and Conditions…if u wish to change the order, just drag and drop the
sequence.
What we created in
‘Types’ is being used to
declare a variable.
233
1 OF 10 ETC initialize or increase counter
234
Conditional break…next page of next page become ‘term’ page (SAP stops processing /
execution of this page)
U can define print mode globally for all the pages instead of declaring this at each page
235
NOW LETS CREATE OUR OWN SMART FORM LET’S COPY A STANDARD SMART FORM [BC470_FLOWS]OF SAP
AND CREATE ZBC470_FLOWS_AVID. THEN WEWOULD PLAY AROUND WITH ITS DIFFERENT ELEMENTS.
LETS CREATE A NEW PAGE IN OUR OBJECT.
236
THIS IS THE PAGE WE CREATED. LETS NAME IT AS ‘TEST1’.
237
I HAVE CHANGED THE SEQUENCE BY DRAGGING AND DROP. NOW TEST1 APPEARS BEFORE THE FIRST
PAGE.
238
FOR BACKGROUND PICTURE AND GRAPHICS YOU CAN PICK UP EITHER BLACK AND WHITE OR COLOR
BITMAP IMAGES AND ARE STORED IN THE FORM OF STANDARD TEXTS. WE TAKE A DETOUR FROM THE
SMARTFORM SCREEN AND OPEN FORM GRAPHICS SCREEN. TRANSACTION CODE: SE78
NOW LETS GO BACK TO THE MAIN SCREEN ……BACKGROUND PIC
PRINTING WILL TAKE PLACE ON THE BASIS OF ‘NEXT PAGE’ FIELD.
BUT PROCESSING WILL HAPPEN AS PER THE SEQUENCE IN NAVIGATION WINDOW!NOTE
239
HERE THERE ARE 3 OPTIONS : BLACK AND WHITE, COLOR AND DYNAMIC BITMAP PICTURES. WE NAME THE
BACKGROUND PICTURE AND CHOOSE THE DETERMINE DYNAMICALLY OPTION.
240
NOTE: RUNTIME COLOR …….USE THE FIELD WITH AMPERSAND.
NOW AFTER THE PAGE, WE CREATE A NEW WINDOW. THERE WILL BE OUTPUT OPTIONS, ATTRIBUTES AND
CONDITIONS IN EACH WINDOW.
241
242
CANNOT USE MAIN IN THIS FIELD BECAUSE SAP CREATES MAIN BY DEFAULT AND DOESN’T ALLOW MAIN AS
NAME.
 WE CANNOT HAVE MORE THAN 1 MAIN WINDOW IN A PAGE. WE CAN HAVE MULTIPLE SECONDARY
WINDOWS
 WHATEVER U PRINT IN SECONDARY WINDOW…IT HAS TO BE STATIC. (IF U HAVE 20 LINES IN A PO AND
THERE IS PAGE CONSTRAINT THE LINES GET CARRIED FORWARD TO NEXT PAGE IN THE MAIN WINDOW.
I.E. IN A PREDECESSOR AND SUCCESSOR TYPE OF CONTENT, THEY WILL BE PRINTED IN SEQUENCE IN
MAIN WINDOW. THIS IS NOT ALLOWED IN SECONDARY WINDOWS.
NOTE
DIFFERENCE IN MAIN AND SECONDARY WINDOWS IN A FORM
243
YOU CAN HAVE ONLY WE MAIN PAGE WHICH U CAN STRETCH TO MULTIPLE PAGES (YOU CAN COPY AND STRETCH IT)
BUT YOU CAN HAVE MULTIPLE SECONDARY WINDOWS.
INSIDE THE MAIN WINDOW WE CAN ADD TEXT AS INTRODUCTION TO CUSTOMIZE THE FORM OUTPUT. IN SMART FORM
WHAT YOU SEE IS WHAT YOU GET.
244
IN THE OUTPUT, WE HAVE THE OPTION OF SIZING AND POSITIONING THE MAIN WINDOW ALONG WITH DIFFERENT
SHADING AND COLOR CHOICES.
245
WE CAN HAVE CONDITIONS….TO BE EXECUTED AT RUN TIME WE TAKE AN EXAMPLE TO ILLUSTRATE THIS.
246
BY DEFAULT THIS WILL BE AND.
SOME PRACTICAL EXAMPLES OF CONDITIONS IN A WINDOW IN FORM COULD BE THAT, ON THE
FIRST PAGE, WE WANT THE COMPANY LOGO AND ADDRESS OF CUSTOMER BUT ON
SUBSEQUENT PAGES WE DON’T WANT CUSTOMER ADDRESS. SIMILARLY WE MAY WISH TO
HAVE SIGNATURE ONLY AT THE LAST PAGE. APPROPRIATE CONDITIONS/FLOW LOGIC CAN BE
INSERTED HERE TO TAKE CARE OF THESE SITUATIONS. WE CAN GIVE FLOW LOGIC FOR BOTH
MAIN AND SECONDARY WINDOWS.
NOTE
247
NOW WE COME TO THE LAST PART OF THE PAGES AND WINDOW SECTION I.E. THE ADDRESS ELEMENT.
NOTE: CAM = CENTRAL ADDRESS MANAGEMENT
E.G. BASED ON THE COUNTRY, WE MAY TAKE COUNTRY SPECIFIC FORMAT (E.G. IN US THE ZIP CODE IS MUST, WHILE
IN INDIA IT IS NOT A MANDATORY FIELD.)
248
LETS CREATE A NEW ADDRESS. IT CAN BE OF 4 TYPES: PERSONAL, OFFICIAL, ORGANIZATION ADDRESS OR IT MAY BE
DETERMINED DURING RUNTIME BASED ON THE SELECTION PARAMETER (DYNAMICALLY DETERMINED).
U NEED TO FIND ADDRESS NUMBER ONLY AND EVERYTHING ELSE WILL BE POPULATED
THE ATTRIBUTES COULD BE OF 3 TYPES: TEXT ELEMENT, INCLUDE TEXT AND TEXT MODULE
WEWOULD THEN FILL UP TEXT NAME: STATIC OR DYNAMIC, TEXT OBJECT (E.G. TEXT) AND TEXT ID (E.G. ADRS)
249
WE THEN NUMBER THE PAGES IN THE FOOTER SPACE PROVIDED
AND WRITE OUR CODE AS TEXT ELEMENT.
250
251
WE CAN USE THE SYSTEM FIELDS IN DATA DICTIONARY TABLE SFSY COMPWENTS WHILE WRITING
THE LOGIC FOR SMARTFORM
LETS ADD A NEW TEXT ELEMENT ‘TXT1’ CHOOSING APPROPIATE PARAGRAPH AND CHARACTER FORMATS.
252
WE CAN HAVE OUR OWN SMART STYLE : PARAGRAPH AS WELL AS CHARACTER FORMATS. LETS CHECK OUT A
STANDARD STYLE BEFORE CREATING OUR OWN!
253
THE HEADER DATA IN EACH SMART STYLE ALLOWS US TO CONFIGURE FONT SIZE, LINE AND CHARACTER SPACING.
254
SAP PROVIDES DIFFERENT PARAGRAPH FORMATS FOR STANDARD, HEADER AND FOOTER, CENTERED AND TOTALS.
255
LETS CREATE A PARAGRAPH AV (WHICH IS DELETED AFTER THE EXERCISE).
256
NOW IT COMES IN THE FORM AS THE MENU OF PARAGRAPH FORMATS IN THE SAP SMART FORM.
NOTE : AV HAS COME IN THE MENU. ALIGNMENT IS AS PER THE PARAGRAPH FORMAT AV.
257
THE NEWLY CREATED PARAGRAPH FONT (E.G. AV) WON’T BE PART OF GLOBAL SETTINGS. IF
WE CHANGE THE FORM ATTRIBUTE - OUTPUT OPTIONS-- AND STYLE TO SOME OTHER
STYLE (LIKE FROM BC470 TO BC 470_STYLS) THIS OPTION WOULD NO LONGER BE THERE.
NOTE
258
LETS CREATE A NEW STYLE (ZBC470_AVI) WITH 2 PARAGRAPH FORMATS AND WE CHARACTER FORMAT
259
NOW I MENTION IN FORM ATTRIBUTE MY OWN STYLE
I CHECK OUT MY OUTPUT IN THE NEXT PAGE FORM.
260
WHEN YOU CREATE A TABLE, SAP AUTOMATICALLY CREATES 3 AREAS: HEADER, MAIN AND FOOTER. IN MAIN AREA,
THERE ARE MANY CELLS, WHICH ARE PROCESSED RECORD BY RECORD.
261
IN MAIN AREA, WE CREATE DIFFERENT CELLS. IN TABLE PAINTER, WE DRAW THE FORMAT AS PER CLIENT
REQUIREMENT (E.G. HEADING, SUB HEADING, ITEM, SUB TOTAL, GRAND TOTAL ETC.)
WE USE THE TABLE LAYOUT TO DETERMINE:
 THE NUMBER OF LINES AND CELLS
 THE HEIGHT OF EACH LINE
 THE WIDTH OF EACH CELL
 THE ALIGNMENT OF THE TABLE IN THE WINDOW
 WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES
WE CAN EITHER DRAW THE TABLE BY VISUAL AID OR WE CAN CLICK ON DETAILS BUTTON AND SET THE
AREA ALLOTTED TO EACH CELL BY FILLING IN THE MEASUREMENTS.
Click
262
Click
263
IN DATA PAINTER, WE CAN PROCESS THE DATA BEFORE DISPLAYING IT IN SMARTFORM. SAP PROVIDES US WITH THE
OPTION OF PUTTING SOME BASIC LOGIC. E.G. LOOP, WHERE CONDITION, OPTION OF ROW-BY-ROW SELECTION, SORT
CONDITION, AT THE END OF TABLE PROCESSING: EVENTS (PROVIDED BY SAP).
FOR EASY NAVIGATION AND ACCESS, SMARTFORM PROVIDES FIELD LIST OPTION. WE CAN ACTIVATE THAT BY
UTILITIES- FIELD LIST ON/OFF.
264
WE CAN PUT CONDITIONS/LOGIC BY PUTTING ABAP CODE INSIDE ‘BOOKINGS’ MAIN AREA, PROGRAM LINES. HERE WE
FIRST DECLARE THE INPUT AND OUTPUT PARAMETERS.
265
HERE WE PUT THE TEXT ELEMENT AS PER PARAGRAPH AND CHARACTER FORMAT. WE MAY HAVE A TEXT WHICH IS
DETERMINED DURING RUN TIME (DYNAMIC).
266
NOW LETS CREATE OUR OWN TABLE. HERE WE CAN PUT LOGIC AS PER CLIENT REQUIREMENT.
TEMPLATE: Template is used when we know the exact size of the output or
the output is in a fixed format. E.g. Tax form/ cheques /airline form/railway
ticket: all these use templates.
Diff between table and template: In Table the height changes dynamically.
WE CALL A ROW A ‘LINE’ IN TEMPLATE.
NOTE
267
Whenever you wish to write your code in SAP Smartform, you have to create the proper
flow logic. We use ‘command’ to code any conditions for going to the next page
268
This is to terminate the current page and start processing the new page.
269
270
In Smartform, We can process our own logic. We can call some table, select some data
do standard data manipulations through this. In navigation wndow, First Page-- Main
Window -- Create -- Flow Logic -- Program line. But it is advisable not to write
programs here as it slows down the process. It is advisable to write the code in print
program.
This is very similar to table. If you wish to dynamically determine the output, we can
loop at internal table
271
272
Flow Logic: Alternative: In this we can embed ‘If - else’ kind of logic.
273
If what we type here is True then it will get processed under the True button.
We next explore another feature of Smartform: Folder
274
Folder is used to modularize the navigation; it has nothing to do with technical thing. The
order you mention in the folder is the order that SAP will process.
There is an option given in Smartforms. We can migrate old SAPscripts to smartforms.
Note: We should check the text elements and make sure the flow logic works in the new
format.
275
Here I am migrating a previously created SAP script to Smartform.
276
277
In Function Module screen, (se37)
To get the function module name, after saving and activating the form, go to
Environment – function module name. This function module name has to be given in the
main program to call the form.
Else go to function module SSF_FUNCTION_MODULE_NAME and give the name of
the program.
In the print program mentiwed below, populating certain fields from database tables into it creates an
output internal table. Once the output internal table is ready, then the function module
SSF_FUNCTION_MODULE_NAME is called. Here, in the import parameters, the name of the smart
form is given. The output of this function module is the name of another function module.
This function module is again called, in this example, the name of the function module is
"/1BCDWB/SF00000007”.
So, in case of smart forms, we use 2 function modules for the processing of the smart form. Once this
internal table is thrown from the smart form, then in the layout, the required fields can be displayed.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
CALL FUNCTION '/1BCDWB/SF00000007'
278
279
280
we have to mention this name (of function module) in the print program.
Supposing we want to print a Purchase Order:
We need to have a print program and a smart form name to be given in the customizing
settings. Also in the print program, we call the function name we got from above.
Let’s check out the print program SAPBC470_PROGS.
281
In this program we have the SSF_FUNCTION_MODULE_NAME. We execute the
program.
282
This calls the SAP Smart form. We are checking the output in Monocolour.
283
This is the way our smart form looks.
284
SE37: We use the just created function module. /1BCDWB/SF00000007. We execute
this.
285
286
287
CHECK PRINT
PREVIEW
288
We can set the background of the output as any file stored in our hard disk. We can call a
graphics from desktop or any other pic stored in the hard disk. Transaction code: SE78
289
290
Now let us delve in to configuration settings to modify our smartform as per requirement.
Creating output type and assigning smart form name in spro
Spro –> materials mgt –> purchasing —> messages —> output control –> message types
–> define message types for Purchase order.
291
292
We can create our own message type. We can define various options like transmission
medium here like Print, Fax, EDI etc.
Select we output type and double click on processing routine to get the following screen.
It will execute the print program as soon as we call ‘neu’ message type. In the above
screen, we can mention the name of the smart form for that output type. Once this is dwe
we can mention the output type in the purchase order
me22n: Lets take an existing P.O.
293
Click
294
The Output is defined here in P.O.
295
WHAT WE HAVE DISCUSSED THUS FAR, IWILL TRY TO SUM UP:
SMART FORMS IS VERY SIMILAR TO SAP SCRIPTS. THIS IS ALSO A TOOL, WHICH IS EXTENSIVELY USED
TO CREATE LAYOUTS, AND THEN A SEPARATE PRINT PROGRAM IS CREATED. THIS PRINT PROGRAM IS
USED TO CREATE THE OUTPUT INTERNAL TABLE, WHICH IN TURN IS THROWN TO THE SMART FORM WHERE
THE FIELD VALUES ARE DISPLAYED.
SAP SMARTFORMS CAN BE USED FOR CREATING AND MAINTAINING FORMS FOR MASS PRINTING IN
SAP SYSTEMS. THE OUTPUT MEDIUM FOR SMARTFORMS SUPPORT PRINTER, FAX, E-MAIL, OR THE
INTERNET (BY USING THE GENERATED XML OUTPUT).
THESE ARE THE STEPS TO CREATE YOUR OWN SMARTFORM:
1. CREATE A NEW SMARTFORMS
TRANSACTION CODE SMARTFORMS
CREATE NEW SMARTFORMS CALL ZSMART
2. DEFINE LOOPING PROCESS FOR INTERNAL TABLE
PAGES AND WINDOWS
FIRST PAGE -> HEADER WINDOW (CURSOR AT FIRST PAGE THEN CLICK EDIT -> NODE -> CREATE)
HERE, YOU CAN SPECIFY YOUR TITLE AND PAGE NUMBERING
&SFSY-PAGE& (PAGE 1) OF &SFSY-FORMPAGES(Z4.0)& (TOTAL PAGE)
MAIN WINDOWS -> TABLE -> DATA
IN THE LOOP SECTION, TICK INTERNAL TABLE AND FILL IN
ITAB1 (TABLE IN ABAP SMARTFORM CALLING FUNCTION) INTO ITAB2
3. DEFINE TABLE IN SMARTFORMS
GLOBAL SETTINGS :
FORM INTERFACE
VARIABLE NAME TYPE ASSIGNMENT REFERENCE TYPE
ITAB1 TYPE TABLE STRUCTURE
GLOBAL DEFINITIONS
VARIABLE NAME TYPE ASSIGNMENT REFERENCE TYPE
ITAB2 TYPE TABLE STRUCTURE
4. TO DISPLAY THE DATA IN THE FORM
MAKE USED OF THE TABLE PAINTER AND DECLARE THE LINE TYPE IN TABSTRIPS TABLE
E.G. HD_GEN FOR PRINTING HEADER DETAILS,
IT_GEN FOR PRINTING DATA DETAILS.
YOU HAVE TO SPECIFY THE LINE TYPE IN YOUR TEXT ELEMENTS IN THE TABSTRIPS OUTPUT OPTIONS.
TICK THE NEW LINE AND SPECIFY THE LINE TYPE FOR OUTPUTTING THE DATA.
DECLARE YOUR OUTPUT FIELDS IN TEXT ELEMENTS
TABSTRIPS - OUTPUT OPTIONS
FOR DIFFERENT FONTS USE THIS STYLE : IDWTCERTSTYLE
FOR QUANTITY OR AMOUT YOU CAN USED THIS VARIABLE &GS_ITAB-AMOUNT(12.2)&
5. CALLING SMARTFORMS FROM YOUR ABAP PROGRAM
REPORT ZSMARTFORM.
* CALLING SMARTFORMS FROM YOUR ABAP PROGRAM.
* COLLECTING ALL THE TABLE DATA IN YOUR PROGRAM, AND PASS ONCE TO SMARTFORMS
* SMARTFORMS
* DECLARE YOUR TABLE TYPE IN :-
* GLOBAL SETTINGS -> FORM INTERFACE
* GLOBAL DEFININTIONS -> GLOBAL DATA
* MAIN WINDOW -> TABLE -> DATA
*
* WRITTEN BY : SAP HINTS AND TIPS ON CONFIGURATION AND ABAP/4 PROGRAMMING
* HTTP://SAPR3.TRIPOD.COM
*
TABLES: MKPF.
REFRESHER ON SMART FORMS
296
DATA: FM_NAME TYPE RS38L_FNAM.
DATA: BEGIN OF INT_MKPF OCCURS 0.
INCLUDE STRUCTURE MKPF.
DATA: END OF INT_MKPF.
SELECT-OPTIONS S_MBLNR FOR MKPF-MBLNR MEMORY ID 001.
SELECT * FROM MKPF WHERE MBLNR IN S_MBLNR.
MOVE-CORRESPONDING MKPF TO INT_MKPF.
APPEND INT_MKPF.
ENDSELECT.
* AT THE END OF YOUR PROGRAM.
* PASSING DATA TO SMARTFORMS
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZSMARTFORM'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
FM_NAME = FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
WRITE: / 'ERROR 1'.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION FM_NAME
* EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
* CONTROL_PARAMETERS =
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
TABLES
GS_MKPF = INT_MKPF
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ADDITIONAL FONTS FOR YOUR SMARTFORMS
YOU CAN CREATE ADDITIONAL FONTS AND STYLE WITH TRANSACTION SMARTSTYLES
THIS CAN THEN BE DEFINE IN THE PARAGRAPH AND CHARACTER FORMATS, WHICH YOU CAN THEN BE
ASSIGN TO TEXTS AND FIELDS IN THE SMART FORM.
THE CHARACTER FORMATS INCLUDES EFFECTS SUCH AS SUPERSCRIPT, SUBSCRIPT, BARCODE AND FONT
ATTRIBUTES.
297
VARIOUS UTILITIES AND THEIR FUNCTIONS IN SMARTFORMS
CREATING FORMS USING SAP SMART FORMS
WHEN CREATING A FORM WE MUST:
RETRIEVE THE APPLICATION DATA
DESCRIBE THE FORM
PASS THE APPLICATION DATA TO THE FORM
RETRIEVING THE APPLICATION DATA:
WRITE AN ABAP PROGRAM TO RETRIEVE DATA OR INCLUDE A RETRIEVAL ROUTINE INTO THE APPLICATION.
THIS CODE CONSISTS OF STATEMENTS THAT SELECT DATA FROM DATABASES ACCORDING TO CERTAIN
SELECTION CRITERIA. STORE THE RETRIEVED DATA IN INTERNAL TABLES, STRUCTURES OR VARIABLES
AND TRANSFER IT TO THE FORM IN WE STEP
.
DESCRIBING THE FORM:
THE USER DEFINES THE FORM USING A SMART FORM. USE THE TOOLS OF THE FORM BUILDER AS LISTED
BELOW:
USE THE FORM PAINTER TO POSITION THE WINDOWS, GRAPHICS AND ADDRESSES ON A PAGE.
USE THE PC EDITOR TO WRITE THE TEXTS.
USE THE TABLE PAINTER TO FORMAT THE TABLES.
THE FLOW CONTROL IS USED TO PRINT THE PAGES AND ELEMENTS.
FORM LOGIC
IN THE FORM BUILDER WE CAN DESCRIBE A SMART FORM BY A SET OF NODES. TO DO THIS, WE CAN BUILD
UP A TREE STRUCTURE ON THE LEFT SIDE OF THE USER INTERFACE.
THE NODE GLOBAL SETTINGS AND ITS THREE SUCCESSORS FORM ATTRIBUTES, FORM INTERFACE AND
GLOBAL DEFINITIONS ALWAYS EXISTS FOR ANY NEWLY CREATED FORMS.
TO DESCRIBE THE FORM LOGIC, CREATE THE HIERARCHY UNDER THE NODE PAGES AND WINDOWS.
THE FOLLOWING RULES APPLY TO CONTROL THE FLOW OF THE FORM OUTPUT.
THE NODES IN THE TREE STRUCTURE ARE PROCESSED FROM TOP TO BOTTOM.
FOR EACH NODE THERE IS A TAB, THIS CAN BE USED TO LINK THE NODE TO A CONDITION. IF THE CONDITION
IS TRUE, THE SYSTEM PROCESSES THE NODE. IF NOT, IT SKIPS THE NODE AND ALL ITS SUCCESSORS.
WE SHOULD DEFINE A NEXT PAGE FOR EACH PAGE.
GRAPHICAL USER INTERFACE
THE BASIC ABAP PROGRAMMING SKILLS ARE REQUIRED ONLY IN SPECIAL CASES LIKE CALLING A
FUNCTION MODULE OR FOR COMPLEX AND EXTENSIVE CONDITIONS.
THE SAP FORM BUILDER OF THE SMART FORM CONSISTS OF:
FORM PAINTER FOR CREATING THE LAYOUT OF THE FORM
PC EDITOR FOR ENTERING TEXTS AND FIELDS INTO OUTPUT AREAS
NAVIGATION FREE FOR MAINTAINING THE FORM LOGIC
TABLE PAINTER FOR CREATING TEMPLATES AND TABLES
FORM CHECK
TO DEFINE THE TEXT FORMATS, WE CAN USE THE SMART STYLES.
THE FORM PAINTER:
THE FORM PAINTER OFFERS THE FOLLOWING FUNCTIONS:
DESIGN AREA WITH RULER, CURSOR WITH HELP LINES, AND HE GRID AND MAIN GRID.
DISPLAY OF THE CURSOR POSITION IN THE RULER, WHICH CAN BE SUPPRESSED AND SET.
TWO LEVEL GRID WITH ENGAGE FUNCTION WHICH CAN BE CUSTOMIZED.
WHEN CREATING, CHANGING AND MOVING A WINDOW, THE WINDOW SIZE APPEARS IN THE RULER.
DETACHABLE TOOLBAR CONTAINING THE MOST IMPORTANT FUNCTIONS.
AUTOSCROLLING WHEN MOVING WINDOWS, PLACING WINDOWS IN THE BACKGROUND.
ZOOM FACTORS THAT CAN BE SET TO ANY VALUE AND AUTOZOOMING OF THE DESIGN AREA TO THE
WINDOW SIZE.
SENSITIVE CONTEXT MENU.
298
PLACING A SCANNED GRAPHIC INTO THE BACKGROUND OF THE DESIGN AREA.
THE PC EDITOR:
THE PC EDITOR OFFERS THE FOLLOWING FUNCTIONS:
ENTER, DELETE, SELECT, CUT AND COPY TEXTS.
ASSIGN PARAGRAPH AND CHARACTER FORMATS.
INCLUDE, CHANGE AND DELETE FIELDS.
THE TABLE PAINTER:
THE TABLE PAINTER OFFERS THE FOLLOWING FUNCTIONS:
DRAWING LINES AND COLUMNS
INSERTING , CUTTING , COPYING AND DELETING LINES
DELETING CELLS
CHANGING CELL SIZE AND MOVING CELL SEPARATOR LINES
SPLITTING CELLS
SELECTING TABLE PATTERNS
STYLE BUILDER:
ON THE LEFT OF THE STYLE BUILDER SCREEN CONSISTS OF THE PREDETERMINED NODES (HEADER DATA,
FOLDER FOR PARAGRAPH FORMATS, FOLDER FOR CHARACTER FORMATS).
ON THE RIGHT WE CAN SEE THE MAINTENANCE SCREEN WITH ITS TAB PAGES. AT THE BOTTOM THE
PREVIEW OF THE SELECTED FONT CAN BE VIEWED.
FIELD LIST AND ERROR LIST:
THE FIELD LIST DISPLAYS THE FOLLOWING DATA IN THE FORM A TREE STRUCTURE:
ALL TABLES, FIELDS AND STRUCTURES PASSED VIA THE FORM INTERFACE.
SYSTEM FIELDS AND THE FIELDS THAT ARE DEFINED IN THE GLOBAL DEFINITIONS.
THIS ALLOWS WETO CHECK WHETHER A CORRECT FIELD NAME HAS BEEN ENTERED OR NOT AND THAT
THE FORM KNOWS THE FIELD OR NOT. TO DISPLAY THE FIELD LIST, IN THE FORM BUILDER CHOOSE FIELD
LIST ON/OFF.
THE ERROR LIST CONTAINS THE LIST OF ERRORS AND WARNINGS DISPLAYED AT THE BOTTOM OF THE
MAINTENANCE SCREEN.
NODE TYPES:
WHEN A FORM IS CREATED, THE TREE STRUCTURE OF THE FORM PAINTER CONTAINS TWO ROOT NODES.
THE SUCCESSORS OF THE GLOBAL SETTINGS NODE ARE USED TO MAINTAIN FORM ATTRIBUTES, THE FORM
INTERFACE AND GLOBAL DEFINITIONS.
THE SUCCESSORS OF THE PAGES AND WINDOWS NODE TO CREATE THE PAGES OF THE FORM, POSITION
ELEMENTS ON THESE PAGES, AND DETERMINE THE SEQUENCE ON HOW TO PROCESS THESE CREATED ELEMENTS.
BASIC ELEMENTS OF A FORM
CREATING PAGES:
EACH FORM CONSISTS OF WE OR MORE PAGES. THE FIRST PAGE IN THE TREE STRUCTURE IS THE START
PAGE AND THE PROCESSING OF THE FORM STARTS WITH THIS PAGE ITSELF.
OPEN THE CONTEXT MENU FOR EXISTING PAGE NODE AND CHOOSE CREATEPAGE
ENTER A UNIQUE NAME FOR THE NODE AND A DESCRIPTION
DETERMINE THE FORMAT AND THE MODE OF THE PAGE COUNTER ON THE GENERAL ATTRIBUTES TAB
DETERMINE THE PRINT ATTRIBUTES OF THE PAGE ON THE OUTPUT OPTIONS
DETERMINE A BACKGROUND GRAPHIC FOR THE ENTIRE PAGE ON THE BACKGROUND TAB
CREATING WINDOWS:
WE CAN SET THE SIZE AND POSITION OF THE WINDOW GRAPHICALLY IN THE FORM PAINTER. THERE ARE
MAIN WINDOWS AND SUBWINDOWS. THE DIFFERENCE BETWEEN THESE TWO IS THAT THE OUTPUT IN A
MAIN WINDOW CAN COVER SEVERAL PAGES.
OPEN THE CONTEXT MENU FOR AN EXISTING PAGE NODE AND CHOOSEWINDOW
ENTER A NAME FOR THE NODE AND A DESCRIPTION
299
ON THE GENERAL ATTRIBUTES INDICATE WHETHER THE WINDOW IS A MAIN WINDOW. IF SUB WINDOW WANTS
TO BE CREATED THEN LEAVE THE CHECKBOX EMPTY
POSITIONING TEXTS ON THE FORM
THE TEXTS ARE DISPLAYED IN THE FORM USING TEXT NODES. THE ONLY EXCEPTIONS ARE ADDRESSES.
THIS USES ITS OWN NODE.
THE PREDECESSOR NODE OF THE TEXT NODE DETERMINES ITS USE:
PREDECESSOR
NODE
USED TO
SUB WINDOW [POSITION TEXT ON WE OR MORE PAGES]
MAIN WINDOW [DISPLAY TEXT IN RELATION TO OTHER NODES IN THE MAIN WINDOW, IT MAY COVER
SEVERAL PAGES]
TEMPLATE [DISPLAYS TEXTS FOR TABLE CELLS OF A STATIC TABLE]
TABLE [DISPLAY TABLE CONTENTS]
HEADER AND
FOOTER
[DISPLAY COLUMN HEADINGS AND GRAND TOTALS IN TABLES]
EVENT NODE [DISPLAY SUBTOTALS IN A TABLE]
THERE ARE THREE TEXT TYPES:
TEXT ELEMENT : TO ENTER NEW TEXT IN THE PC EDITOR
TEXT MODULE : TO INCLUDE A TEXT MODULE
INCLUDE TEXT : TO INCLUDE AN EXISTING SAPSCRIPT TEXT
ENTERING TEXTS IN PC EDITOR:
TO CREATE A TEXT NODE CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHOULD RECEIVE THE
TEXT, THEN CHOOSE->TEXT
ENTER A UNIQUE NAME FOR THE NODE AND THE NODE DESCRIPTION
ON THE GENERAL ATTRIBUTES TAB CHOOSE TEXT ELEMENT AS TEXT TYPE
ENTER THE TEXT IN THE PC EDITOR
IN THE TEXT NODE BOX CHOOSE WHETHER THE TEXT SHOULD BE STARTED WITH A NEW PARAGRAPH OR ONLY IN A NEW LINE
INCLUDING TEXT MODULES:
TEXT MODULE OF THE TEXT NODE IS USED TO REFER TO AN EXISTING TEXT MODULE IN THE SYSTEM. THE TEXT MODULES
CAN BE USED IN TWO WAYS:
REFER TO THE TEXT MODULE. THE TEXT THEN APPEARS READ-ONLY IN THE PC EDITOR AND IS INCLUDED WHEN THE FORM IS
PRINTED.
COPY THE TEXT MODULE. THE SYSTEM THEN COPIES THE TEXT OF THE MODULE AND AUTOMATICALLY CONVERTS THE TEXT
NODE INTO AN EDITABLE TEXT ELEMENT.
TO CREATE A TEXT NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHALL CONTAIN THE
TEXT AND CHOOSE CREATE->TEXT
ENTER A UNIQUE NAME FOR THE NODE AND A DESCRIPTION
ON THE GENERAL ATTRIBUTES TAB SELECT THE TEXT TYPE TEXT MODULE
ENTER THE NAME OF THE TEXT MODULE IN THE TEXT NAME FIELD
INCLUDING SAPSCRIPT TEXTS:
WE CAN USE THE TEXT TYPE INCLUDE TEXT NODE TO REFER TO A SAPSCRIPT TEXT THAT ALREADY EXISTS IN THE SYSTEM.
TO IDENTIFY THE TEXT THE TEXT NAME, OBJECT, ID AND THE LANGUAGE IS NEEDED.
TO CREATE THE TEXT NODE CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHALL RECEIVE THE
TEXT AND CHOOSE CREATE -> TEXT
ENTER A UNIQUE NAME FOR THE NODE AND THE NODE DESCRIPTION
ON THE GENERAL ATTRIBUTES TAB CHOOSE INCLUDE TEXT AS TEXT TYPE
INSERTING ADDRESSES:
WE CAN USE THE ADDRESS NODE TO INSERT AN ADDRESS INTO THE FORM. THIS GUARANTEES THAT THE ADDRESS IS
FORMATTED ACCORDING TO THE POSTAL RULES OF THE SENDER COUNTRY.
TO CREATE AN ADDRESS NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT WEWANTS TO
CONTAIN THE TEXT AND CHOOSE CREATE->TEXT
300
ENTER A NAME FOR THE NODE AND A DESCRIPTION
DETERMINE THE ADDRESS TYPE ON THE GENERAL ATTRIBUTES TAB
FOR ORGANIZATIONAL ADDRESSES WE HAVE TO SPECIFY THE ADDRESS NUMBER, FOR ANY OTHER WE HAVE TO SPECIFY THE
PERSON NUMBER AND THE ADDRESS NUMBER
IN THE BOX ADDITIONAL ADDRESSES WE CAN MAINTAIN OTHER ATTRIBUTES TO SPECIFY HOW TO DISPLAY THE ADDRESS
PRINTING GRAPHICS:
GOTO TCODE SE78 TO IMPORT GRAPHICS INTO THE SAP SYSTEM. THE TRANSACTION IMPORTS THE GRAPHICS AND STORES
IT IN THE BDS (BUSINESS TRANSACTION SERVER) AND THEN IT CAN BE DISPLAYED IN THE FORM.
TO CREATE THE GRAPHIC NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE AND CHOOSE CREATE-
>GRAPHIC
ENTER A NAME FOR THE NODE AND THE DESCRIPTION
ON THE GENERAL ATTRIBUTES DETERMINE WHETHER A COLORED OR A BLACK AND WHITE
USE THE FIELDS OBJECT , ID AND NAME TO IDENTIFY THE GRAPHIC
DISPLAYING A STATIC TABLE
USE NODE TYPE TEMPLATE TO DISPLAY A TABLE WHOSE LAYOUT AND SIZE IS DETERMINED BEFORE THE RUNTIME OF THE
PRINT PROGRAM.
TO CREATE A TEMPLATE DEFINE A TABLE LAYOUT TO DETERMINE THE CELL STRUCTURE FOR EACH LINE. THE CELLS ARE
USED TO DISPLAY THE CELL STRUCTURE FOR EACH LINE. THE CELLS ARE USED TO DISPLAY THE CONTENTS OF THE
SUCCESSOR NODES OF THE TEMPLATE NODE. THIS ALLOWS US TO POSITION TEXT AND A GRAPHIC SIDE BY SIDE.
THE TEMPLATE NODE IS ALSO USED FOR LABEL PRINTING. TO USE A TEMPLATE WE MUST DO THE FOLLOWING:
DEFINE THE TABLE LAYOUT
DISPLAY THE CONTENTS IN THE TABLE CELLS
DEFINE THE TABLE LAYOUT:
THE TABLE LAYOUT IS USED TO DETERMINE THE FOLLOWING,
THE NUMBER OF LINES AND CELLS
THE HEIGHT OF EACH CELL
THE WIDTH OF EACH CELL
THE ALIGNMENT OF THE TABLE IN THE WINDOW
WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES
CREATE A TEMPLATE NODE AND MAINTAIN THE ATTRIBUTES WIDTH, HORIZONTAL ALIGNMENT AND VERTICAL ALIGNMENT.
USE THE TABLE CONTROL ON THE TEMPLATE TAB TO DEFINE THE LAYOUT OF THE LINES. EACH LINE OF THE TEMPLATE MUST
HAVE A DEFINITION.
USE THE PATTERN BOX TO SELECT THE DESIRED TABLE PATTERN.
DISPLAYING CONTENTS IN CELLS:
THE TEMPLATE NODE DEFINES THE TABLE LAYOUT. THE SUCCESSOR NODES OF THE TEMPLATE DETERMINE THE DATA TO BE
DISPLAYED IN THE TABLE CELLS.
COMBINING NODES:
THE MORE EXTENSIVE THE FORM BECOMES, THE LESSER CLEAR BECOMES THE NODE HIERARCHY IN THE TREE STRUCTURE.
TO AVOID THIS WE CAN COMBINE THE RELATED NODES BY APPENDING THEM UNDER A FOLDER NODE.
LLET" STYLE="MARGIN-LEFT:1.75IN;TEXT-INDENT:-.25IN;MSO-LIST:L8 LEVEL1 LFO23; TAB-STOPS:LIST 1.75IN">
THE WIDTH OF EACH CELL
THE ALIGNMENT OF THE TABLE IN THE WINDOW
WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES
CREATE A TEMPLATE NODE AND MAINTAIN THE ATTRIBUTES WIDTH, HORIZONTAL ALIGNMENT AND
VERTICAL ALIGNMENT.
USE THE TABLE CONTROL ON THE TEMPLATE TAB TO DEFINE THE LAYOUT OF THE LINES. EACH LINE OF
THE TEMPLATE MUST HAVE A DEFINITION.
USE THE PATTERN BOX TO SELECT THE DESIRED TABLE PATTERN.
DISPLAYING CONTENTS IN CELLS:
THE TEMPLATE NODE DEFINES THE TABLE LAYOUT. THE SUCCESSOR NODES OF THE TEMPLATE
DETERMINE THE DATA TO BE DISPLAYED IN THE TABLE CELLS.
COMBINING NODES:
301
THE MORE EXTENSIVE THE FORM BECOMES, THE LESSER CLEAR BECOMES THE NODE HIERARCHY IN THE
TREE STRUCTURE. TO AVOID THIS WE CAN COMBINE THE RELATED NODES BY APPENDING THEM UNDER A
FOLDER NODE.
302
A Step-by-Step Approach to Create SAP Script
Introduction
Purpose of document: This document is all about creation of SAP
Script. This document will help in –
 To familiarize with SAP Script
 Elements of SAP Script
 Processing of SAP Script
 Step-by-Step method to create a simple script
 Some advanced control commands in brief.
Who will benefit: All ABAPers.
Prerequisite: Knowledge of ABAP.
Introduction to SAP Script
Business uses several forms in day-to day activities. These forms can be
a –
 Purchase Orders
 Sales Orders
 Credit Memos
 Debit Memos
 Invoices
 Salary Slips etc.
To facilitate design, build and printing of these forms, SAP provides a
tool which is known as SAP Script. In addition to it, R/3 comes with a
set of pre-designed forms that can be easily customized to fit the needs
of individual business.
For e.g. - MEDRUCK is a SAP Script layout which is available in R/3
system which can be used to generate Purchase Order. This is a
standard layout available in R/3 for generation of Purchase Order which
can be customized according to individual business needs.
A SAP Script layout is not alone capable of printing these various
business forms; it’s merely a structure which defines areas within a page
that is populated with data specific to business needs. The collection of
data and passing it to script layout is done through its FORM Routine.
This FORM Routine is an ABAP program which involves some standard
function modules to pass business data to SAP Script layout. Thus,
combination of SAP Script layout and its FORM Routine together
responsible for generation of these business forms.
For e.g. – The associated FORM Routine for above mentioned SAP Script
Layout is SAPFM06P available in R/3.
303
This document is mainly intended to demonstrate the basic steps to
create a SAP Script Layout. Since, its associated FORM Routine is
basically an ABAP program which can be coded according to business
demand to collect desired data, however the standard function modules
needed to invoke Script layout and to pass business data will be
discussed in brief.
SAP Script Layout Elements
A SAP Script Layout consists of following elements –
 Pages
 Windows
 Page windows
 Paragraphs Formats
 Character Formats
Let’s discuss them in short –
Pages: Pages are general layout of script. A page would normally be
divided into three parts –
 Header
 Body
 Footer
A script can consist of many pages where the first page can be in
different format and second page onwards can be in different formats.
HEADER
BODY
FOOTER
304
Windows: To specify position of contents on the page, windows are
created.
WINDOWS
Page Windows: Page windows are used to specify sizes and to determine
position of each window.
Paragraph Formats: Paragraph formats are used for formatting
paragraphs. Font and tabs are important paragraph format. If we do not
specify font, form uses default font.
Character Formats: Character formats are basically used to override
paragraph formats for specific words in a paragraph. For e.g. if we want to
bold a specific word within a paragraph, we make use of character formats.
How SAP Script Processed
The SAP Script runtime environment co-ordinates the processing of SAP
Script as shown below –
LOGO COMPANY NAME
CONTENT
ADDRESS
305
As shown above the SAP Script layout environment retrieves layout and
content data from SAP Script form. Also it retrieves necessary business
data according to business logic defined in Form Routine from the R/3
database.
Thus, combining both of these, finally it generates the SAP Script form.
This generated SAP Script form can be –
 Printed
 Faxed
 E-mailed
 Displayed on terminal
as per requirement.
Steps to create SAP Script Layout
 Go to Transaction SE71 and give name of script you want.
306
 Press Create and the following pop-up will appear. Don’t forget to
see that the form is created in the client and not in the
application server.
307
 Just Press Enter and save the layout after giving a short
description.
308
 Now click on tab Pages. The following screen will appear -
309
 Create a page called PAGE1 and press Enter. Give next page as
PAGE1 only and press Enter.
 Now click on tab Windows. The following screen will appear –
310
 Apart from existing Main window, create Header and Footer for
this page.
311
 Now click on tab Paragraph Formats where you can create your
own paragraph formats which can be used while writing text
312
elements for windows. The following four paragraph formats has
been created as shown below –
The various parameters such as
o Margins
o Alignment,
o Font type
o Font size etc.
should be entered as per requirement.
 Now click on tab Page Windows and associate previously created
windows to PAGE1. This can be done by clicking on Edit from
menu bar and choosing option Create Element, where previously
created all windows will be shown up. Double click on those
windows which you want to associate with this page and
assigning following four parameters for all windows –
o Left Margin
o Upper Margin
o Window Width
o Window Height
The resulting screen will look as –
313
 Select Header window and click on Icon for text elements.
The shown editor can be chosen by clicking option Go to from
menu bar and selection option Change Editor. Enter desired text
as shown below –
314
 Now go back to previous screen, select Main window and press
Icon for text elements. Enter following texts as shown –
Note- All variable names must be enclosed in ampersands (&).
315
 Now go back to previous screen, select Footer window and press
Icon for text elements. Enter following texts as shown –
 Now go back & save it. Click on Header Icon , the following
screen will appear –
316
 Click on Basic Settings and assign First Page as PAGE1 and
Default Paragraph as P2 and save it as shown –
317
 Now check for Definition and Activate the script. Script Layout is
complete now.
318
Creation of Form Routine
319
Once Script Layout is complete, now we will create its Form Routine.
This Form Routine is an ABAP Program through which SAP Script Layout
is invoked using three function modules viz.
 OPEN_FORM
 WRITE_FORM
 CLOSE_FORM
These function modules are used in the same manner as listed above.
Out of
all these, OPEN_FORM and CLOSE_FORM are used only once while
WRITE_FORM can be used any number of times in between OPEN_FORM
and CLOSE_FORM depending on requirement. Create a report program
using transaction SE38 and copy following code snippets and activate it.
Code Snippet:
REPORT ZTESTSCRIPT_FORMROUTINE .
*-----------------------------------------------------------
------------
* Database tables
*-----------------------------------------------------------
------------
TABLES: kna1.
*-----------------------------------------------------------
------------
* Contants
*-----------------------------------------------------------
------------
CONSTANTS: co_mulgrave(8) VALUE 'MULGRAVE'.
*-----------------------------------------------------------
------------
* Internal Tables
*-----------------------------------------------------------
------------
DATA: BEGIN OF tb_kunnr OCCURS 0,
name1 LIKE kna1-name1,
ort01 LIKE kna1-ort01,
pstlz LIKE kna1-pstlz,
regio LIKE kna1-regio,
END OF tb_kunnr.
*-----------------------------------------------------------
------------
* START OF PROCESSING
*-----------------------------------------------------------
------------
START-OF-SELECTION.
* Select details of customer of Mulgrave city
SELECT name1
ort01
pstlz
regio
320
INTO TABLE tb_kunnr
FROM kna1
WHERE ort01 = co_mulgrave.
*-----------------------------------------------------------
------------
* END OF PROCESSING
*-----------------------------------------------------------
------------
END-OF-SELECTION.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
* DEVICE = 'PRINTER'
* DIALOG = 'X'
FORM = '/DCSEA/ZTESTSC'
LANGUAGE = SY-LANGU
* OPTIONS =
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
* EXCEPTIONS
* CANCELED = 1
* DEVICE = 2
* FORM = 3
* OPTIONS = 4
* UNCLOSED = 5
* MAIL_OPTIONS = 6
* ARCHIVE_ERROR = 7
* INVALID_FAX_NUMBER = 8
* MORE_PARAMS_NEEDED_IN_BATCH = 9
* SPOOL_ERROR = 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 tb_kunnr.
* Write header
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT = ' '
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'HEADER'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT = 1
321
* FUNCTION = 2
* TYPE = 3
* UNOPENED = 4
* UNSTARTED = 5
* WINDOW = 6
* BAD_PAGEFORMAT_FOR_PRINT = 7
* SPOOL_ERROR = 8
* OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Write main contents
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'MAIN'
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'MAIN'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT = 1
* FUNCTION = 2
* TYPE = 3
* UNOPENED = 4
* UNSTARTED = 5
* WINDOW = 6
* BAD_PAGEFORMAT_FOR_PRINT = 7
* SPOOL_ERROR = 8
* OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Write Footer
CALL FUNCTION 'WRITE_FORM'
EXPORTING
* ELEMENT = ' '
* FUNCTION = 'SET'
* TYPE = 'BODY'
WINDOW = 'FOOTER'.
* IMPORTING
* PENDING_LINES =
* EXCEPTIONS
* ELEMENT = 1
* FUNCTION = 2
* TYPE = 3
* UNOPENED = 4
* UNSTARTED = 5
* WINDOW = 6
* BAD_PAGEFORMAT_FOR_PRINT = 7
* SPOOL_ERROR = 8
* OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
322
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP. "LOOP AT tb_kunnr
CALL FUNCTION 'CLOSE_FORM'
* IMPORTING
* RESULT =
* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* SPOOL_ERROR = 4
* OTHERS = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
On execution of above program, the following screen will appear –
Click on Print Preview, the output will be as shown –
323
Transporting Script Layout between clients
Since SAP Script Layout is client dependent thus layout designed in
development client can not be tested until it is transported to test client.
Thus, to transport layout from one client to another, transaction SCC1 is
used (Screen shot below).
324
To transport layout, mention source client, request number under which
layout is locked and click on checkbox Incl. task for request. Finally, click
on tab Start Immediately as shown below –
325
326
Function Modules Used in Script:
In the Driver we must use all or some of the function modules that are listed below to
transfer the data.
 Open_Form
 Close_Form
 Start_Form
 Write_Form
 Write_Form_Lines
 End_Form
 Control_Form
 Read_Form_elements
 Read_Form_Lines
Any driver program must contain Open_Form, Close_Form and Write_Form. Other
function modules are optional.
OPEN_FORM: This function module opens layout set printing. One must call this
function module before he uses any of other layout set function modules like
Write_Form, Start_Form, Control_Form etc., You need specify a layout set name in
the export parameters of this function module. If nothing is passed to Open_Form
then one should use Start_Form function module to open layout set before starting
the output. The layout set opened by Open_Form should be closed by Close_Form
function module, other wise output doesn’t appear. We can use any number of
Open_Form, Close_Form functions in one single program. But Close_Form must be
there for every Open_Form in the program.
Some of the important export parameters we have to pass to Open_Form
function module.
Form: Enter the Layout set name here, which then controls the output
formatting. If nothing is specified then we must use Start_Form for opening layout
set.
Language: Layout sets are Language dependent. Enter the desired language
here. If the entered layout set is not in that language, then the function tries to
open the Form entered in its original language. The default value is SY-LANGU.
Device: SAP Script can format a text on different device types. The device can
be ‘PRINTER’ or ‘TELEX’, ‘TELEFAX’, ’ABAP’ and ‘SCREEN’.
Dialog: Use parameter DIALOG to determine whether to display a dialog box
before printing, in which the user can set several spool parameters for print
formatting. Possible values: SPACE displays no print parameter screen. 'X'
display print parameter screen. Default value: 'X'
Options: Use parameter OPTIONS to set several options for print formatting.
The parameter has the structure ITCPO. The user can change some of the
defined settings on the print control screen. The default value for Options is ‘ ‘.
We will discuss about ITCPO structure in detail later.
Other Export, Import and Exceptions are self-explanatory.
327
Close_Form: The function module closes the layout set opened using
OPEN_FORM. The system executes any terminating processing steps for the last
opened layout set. No Export parameters for this Function Module.
Start_Form: In-between the function modules OPEN_FORM and CLOSE_FORM,
we can use different layout sets. This allows us to combine several different layout
sets into one print output. However, we can combine only those layout sets that have
the same page format. To switch layout sets, use the function module
START_FORM. If another layout set is still open, we must close it first using
END_FORM. If we specify no layout set name when calling START_FORM, the
system restarts the last open layout set. If after OPEN_FORM no layout set was
activated yet, the system leaves the function module with the exception UNUSED.
Some of the important export parameters for this function module are
Form: The parameter contains the name of the layout set you want to use for
printing. If you specify no layout set here, the system restarts the last active layout
set.
Language: Layout sets are language-dependent. Enter the desired language
here. If the layout set does not exist in this language, the system tries to call the
layout set in its original language. If the parameter LANGUAGE is empty, the
system uses the language of the last active layout set.
Startpage: Usually, SAP script starts with the page specified as start page in
the layout set definition. If we want to start output with another layout set page,
enter the name of the desired layout set page here. If the desired page is not
defined, the system uses the start page defined in the layout set.
Program: To replace program symbols, SAP script must know which active
program contains the work areas for the values to be passed. If we omit the
parameter, the system searches for the field values in the program that was
specified in the parameter OPTIONS (field TDPROGRAM) of OPEN_FORM. If we
enter a program name, the system replaces the program symbols with the values
from this program up to the next END_FORM.
Exceptions and other Export, Import parameters are self-explanatory.
Write_Form: The system outputs the layout set element specified in parameter
ELEMENT into the currently opened layout set. In the parameter WINDOW we can
specify the name of a window for the output. Remember that the layout set element
must be defined in this window. The parameter FUNCTION specifies how to merge
the text lines to be output with any existing contents in the window. In this case, there
are differences between the different window types or areas. Some of the important
export parameters used in Write_Form.
328
Element: Specify the name of the text element you want to output into the layout
set window specified in the parameter WINDOW. The element must be defined in
that layout set window. If you specify no element, the system uses the default
element, if one is defined in the layout set.
Window: Specify the name of the window into which you want to output the
layout set element specified in the parameter ELEMENT. Default value for
Window is ‘MAIN’.
Function: The parameter determines how to output the text element into the
respective window. The output type depends on the window type and area:
Window Type: MAIN Area: BODY
SET/APPEND: Appends to previous output.
Window Type: Main Area: Top/Bottom and
Window Type: Other than Main and all areas
SET : Delete the old element contents and prints the new elements
APPEND: Appends the new content to existing elements.
Type: The system interprets this parameter only for output to the main window. The parameter determines the area of the
main window into which we want to output the element. Possible values: 'TOP' header area
'BODY' main area
'BOTTOM' footer area
Default value: 'BODY'
Write_Form_Lines: This function module outputs the text lines in table LINES into the specified layout set window. The text
lines must have the SAP script ITF format. From the data in the text header, the system uses only the field TDSTYLE to
apply the formatting attributes defined in the specified style for this text. If the field is empty, the system uses the identically
named formatting attributes (character and paragraph formats) of the layout set.
Use parameter WINDOW to specify into which of the windows defined in the layout set we want to output the text. We can
specify any window used in the layout set. The parameter FUNCTION determines how to merge the text lines to be output
with any existing contents in the window. There are differences between the different window types or areas.
Header: This parameter contains the header of the text module we want to output in the current layout set.
For the formatting process, the system uses only the entries in the header fields TDSTYLE and TDFORM.
Structure: THEAD
WINDOW: Enter the name of the window into which we want to output the layout set element specified in
parameter ELEMENT. Default value: 'MAIN'
FUNCTION: This parameter determines how to output the text element into the respective window. The
output type depends on the window type and area: Window type MAIN, area BODY: 'SET' append to
previous output 'APPEND' same as SET. DELETE' no effect. Window type MAIN, areas TOP and
BOTTOM; all other windows: 'SET' delete old window or area contents and output the element
'APPEND' append the element to the existing elements 'DELETE' no effect
329
Default value: 'SET'
TYPE: The system interprets this parameter only for output to the main window. The parameter
determines the area of the main window into which you want to output the element. Possible values: 'TOP'
header area 'BODY' main area 'BOTTOM' footer area Default value: 'BODY'
END_FORM: END_FORM ends the currently open layout set and executes the required termination processing. After
calling this function module, no more layout set is active. For further output, we must start a new layout set using
START_FORM. No Export parameters.
CONTROL_FORM: Use this function module to pass SAP Script Control Commands to the layout set. The Control command
is passed through the export parameter ‘COMMAND’ in quotes.
READ_FORM_ELEMENTS: This function module fills a table with all text
elements that appear in one layout set. If we specify no layout set name, the
system includes all elements of the currently open layout set. If we specify a
layout set, the system uses the information about the active version of the layout
set, retrieved from the database. Here we have two export parameters, Form and
Language and a table parameter Elements.
READ_FORM_LINES: Use this function module to transfer the lines of a layout
set element into an internal table. If we specify no layout set name, the system
transfers the text lines of the currently open layout set. If we specify a layout set,
the system uses the text lines of the active version of the layout set from the
database. The Export parameters are Form, Language, Window and Element. If
we pass these 4 parameters the function module returns a table with the lines
from layout set.
Procedure
Migrating a SAPscript form
1. Go to the SAP Smart Forms initial screen (transaction SMARTFORMS ).
2. In the Form field enter the name of the Smart Form you want to create.
3. Choose Utilities  Migrate SAPscript form.
The dialog window Migrate SAPscript Form appears.
4. Enter the name and the language of the source form (SAPscript).
5. Choose Enter.
This takes you to the change mode of the SAP Form Builder.
330
If the selected SAPscript form does not exist in the selected language, a dialog
window appears on which you can select one of the existing languages.
6. Now change the design of the form and of the form logic. To activate the Smart Form
choose Activate.
Converting a SAPscript style
1. Go to the Smart Styles inital screen (transaction SMARTSTYLES ).
2. In the Style name field enter the name of the Smart Style you want to create.
3. Choose Smart Styles  Convert SAPscript style.
4. Enter the name of the SAPscript style you want to convert.
5. Choose Enter.
A list of the converted styles appears.
6. Choose Back. You can now change the Smart Style (Change).To activate the Smart
Style choose Activate.
Mass Migration of SAPscript Forms
1. In Reporting select the program SF_MIGRATE and execute it.
2. Select the names and the language of the SAPscript forms and choose Execute. The
system creates the Smart Forms under the names of the SAPscript forms plus the
extension _SF.
It displays a list of the migrated forms.
3. To change and adapt a form, go to transaction SMARTFORMS . Then activate the changed
Smart Form.
Result
You created one or more Smart Forms based on the respective SAPscript form(s) and a Smart
Style based on the respective SAPscript style.
SAP SCRIPT LOGO PRINTING
To Create a logo in SAP printouts , just do the following
1. Save a Logo using Paintshop Pro or Corel Draw as Tiff file.
2. Run this program RSTXLDMC and enter the following parameters
Enter file name C:MAILCOMPLOGO.TIF
UOM CM
331
Line width for text 132
Text name ZHEX-MACRO-COMPLOGO
Text ID ST
Text language = E
Number of Tiff gray levels (2,4,9) 2
3. Then Create a new window 'COMP' with attributes;
Window COMP description Company Logo
Left margin 7.00 CH window width 10.00 CH
Upper margin LN window height 8.00 LN
Finally in the text element , mention
/: INCLUDE 'ZHEX-MACRO-COMPLOGO' OBJECT TEXT ID ST LANGUAGE
'E'.
Please note that if object name is not indicated as 'ZHEX...', the logo may not be printed!
You will not be able to see the logo in a test print. The same will be printed in actual
printout.
SAP SCRIPTS SYMBOLS
Commands
1. Defining a variable
2. Define and insert a standard text:
3. Formatting addresses
4. Avoiding pagebreaks in a paragraph
332
5. Conditonal text ouput IF - ENDIF
1. Defining a variable
DEFINE &CUST& = '00000021'.
2. Define and insert a standard text:
Standard texts is predifined textst that can be used in more than one form. Standard texts are can
be created, changed and displayed using transaction SO10.
The text ID is used to callsify texts.
To include a stadard text in a form, use the INCLUDE command:
/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD
When formatting the standard text the PARAGRAPH parameter is used. To center the text use:
/: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD LANGUAGE EN PARAGRAPH
C.
3. Formatting addresses
The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of
the recipient's country, as defined in the
country parameter.
ADDRESS DELIVERY PARAGRAPH AD
NAME &KNA1-NAME&
STREET &KNA1-STRAS&
POSTCODE &KNA1-PSTLZ&
CITY &KNA1-ORT01&'
COUNTRY &KNA1-LAND1&
FROMCOUNTRY 'DE'
ENDADDRESS
4. Avoiding pagebreaks in a paragraph
/: PROTECT
:
:
/: ENDPROTECT
The text lines to be protected are enclosed between the two commands
333
5. Conditonal text ouput IF - ENDIF
You can use IF/ENDIF like in a normal ABAP program
/: IF condition
:
:
/: ENDIF
and
/: IF condition
:
/: ELSE
:
/: ENDIF
Example:
/: IF &SPFLI-CITYTO& = "BERLIN"
* ..... put some text here
/: ENDIF
Frames lines and shading
BOX
Draws a box
Syntax:
/: BOX <xpos> <ypos> <width> <height> <frame> <intensity>
The intensity is the grey scale of the box as %. The frame parameters is the thickness of the
frame. Default is 0.
Each of the paramteters ypos, xpos, width, height and frame muts be followed of the
measurement unit:
TW (twip)
PT (point)
IN (inch)
334
MM (millimeter)
CM (centimeter)
LN (line)
CH (character).
Examples:
/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY
10 FRAME 0 TW
/: BOX FRAME 10 TW
Draws a frame around the current window with a frame thickness of 10 TW (= 0.5 PT).
/: BOX INTENSITY 10
Fills the window background with shading having a gray scale of 10 %.
/: BOX HEIGHT 0 TW FRAME 10 TW
Draws a horizontal line across the complete top edge of the window.
/: BOX WIDTH 0 TW FRAME 10 TW
Draws a vertical line along the complete height of the left hand edge of the window.
/: BOX WIDTH '17.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15
/: BOX WIDTH '17.5' CM HEIGHT '13.5' CM FRAME 10 TW
/: BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
/: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
Draws two rectangles and two lines to construct a table of three columns with a highlighted
heading section.
POSITION and SIZE
You can use the POSITION and SIZE commands to set default parmeters for a box. This can be
usefull if you have several boxes that share the same parameters.
Example:
/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM
/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10
If you want to set the position realtively to the window use POSITION WINDOW to set the
position to the top/left start of the window. Then use POSITION to set the current position
relatively to the start of the Window. Note that
you uses "+" or "-" in the ORIGIN position to the set the position relatively.
/: POSITION WINDOW
335
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM
the position is now 5 MM from the left and 10 MM from the top of the window.
NOTE: After using the position command you can move the current position realtively to the last
used position
/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM
Now the position will be X = 15 and Y = 30
More examples:
/: POSITION WINDOW
Sets the origin for the coordinate system to the upper left corner of the window.
/: POSITION XORIGIN 2 CM YORIGIN '2.5 CM'
Sets the origin for the coordinate system to a point 2 cm from the left edge and 2.5 cm from the
upper edge of the output page.
/: POSITION XORIGIN '-1.5' CM YORIGIN -1 CM
Shifts the origin for the coordinates 1.5 cm to the left and 1 cm up.
Drawing a line
You can draw a line by setting the Height or Width of a box to 0 and add a frame. E.g. a
horizontal line:
/: SIZE HEIGHT '0' MM WIDTH '200' MM
/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100
Window and Page
WINDOW sets the values for the width and height to the values of the current window (default
setting).
PAGE Sets the values for the width and height to the values of the current output page.
Examples:
/: SIZE WINDOW
Sets WIDTH and HEIGHT to the current window dimensions.
/: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM
Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm.
/: POSITION WINDOW
336
/: POSITION XORIGIN -20 TW YORIGIN -20 TW
/: SIZE WIDTH +40 TW HEIGHT +40 TW
/: BOX FRAME 10 TW
A frame is added to the current window. The edges of the frame extend beyond the edges of the
window itself, so as to avoid obscuring the leading and trailing text characters.
Structure of a print program
The print program is used to print forms. The program retieves the necesary data from datbase
tables, defines the order of in which text elements are printed, chooses a form for printing and
selects an output device and print options.
* Open form printing - Must be called before working with any of the other form function
modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....
*To begin several indentical forms containing different data within a single spool request, begin
each form using START_FORM, and end it using END_FORM
call funtion 'START_FORM'.....
* Write text elements to a window of the form
call function 'WRITE_FORM'.....
* Ends form
call funtion 'END_FORM'.....
* Closes form printing
call function 'CLOSE_FORM'....
Examples of function calls
OPEN FORM
* Structure for the OPTIONS parameter
DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
DATA END OF OPTIONS.
337
OPTIONS-TDDEST = '*'.
OPTIONS-TDIMMED = '*'.
OPTIONS-TDDELETE = '*'.
OPTIONS-TDNEWID = 'X'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
* FORM = ' '
* LANGUAGE = SY-LANGU
OPTIONS = OPTIONS
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
MAIL_OPTIONS = 6
ARCHIVE_ERROR = 7
INVALID_FAX_NUMBER = 8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10
.
IF sy-subrc <> 0.
...............................
ENDIF.
START_FORM
CALL FUNCTION 'START_FORM'
* EXPORTING
338
* ARCHIVE_INDEX =
FORM = 'MY_FORM'
* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
* EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
OTHERS = 6
WRITE_FORM
See 'WRITE_FORM'
END_FORM
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT =
EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
OTHERS = 3
CLOSE_FORM
* Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END OF RESULT.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT
* RDI_RESULT =
* TABLES
339
* OTFDATA =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* OTHERS = 4
.
WRITE FORM function module
The print program is used to print forms. The program retieves the necesary data from datbase
tables, defines the order of in which text elements are printed, chooses a form for printing and
selects an output device and print options.
* Open form printing - Must be called before working with any of the other form function
modules.
Must be ended with function module CLOSE FORM
call function 'OPEN_FORM'.....
*To begin several indentical forms containing different data within a single spool request, begin
each form using START_FORM, and end it using END_FORM
call funtion 'START_FORM'.....
* Write text elements to a window of the form
call function 'WRITE_FORM'.....
* Ends form
call funtion 'END_FORM'.....
* Closes form printing
call function 'CLOSE_FORM'....
Examples of function calls
OPEN FORM
* Structure for the OPTIONS parameter
DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
340
DATA END OF OPTIONS.
OPTIONS-TDDEST = '*'.
OPTIONS-TDIMMED = '*'.
OPTIONS-TDDELETE = '*'.
OPTIONS-TDNEWID = 'X'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
* APPLICATION = 'TX'
* ARCHIVE_INDEX =
* ARCHIVE_PARAMS =
DEVICE = 'PRINTER'
DIALOG = 'X'
* FORM = ' '
* LANGUAGE = SY-LANGU
OPTIONS = OPTIONS
* MAIL_SENDER =
* MAIL_RECIPIENT =
* MAIL_APPL_OBJECT =
* RAW_DATA_INTERFACE = '*'
* IMPORTING
* LANGUAGE =
* NEW_ARCHIVE_PARAMS =
* RESULT =
EXCEPTIONS
CANCELED = 1
DEVICE = 2
FORM = 3
OPTIONS = 4
UNCLOSED = 5
MAIL_OPTIONS = 6
ARCHIVE_ERROR = 7
INVALID_FAX_NUMBER = 8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS = 10
.
IF sy-subrc <> 0.
...............................
ENDIF.
START_FORM
341
CALL FUNCTION 'START_FORM'
* EXPORTING
* ARCHIVE_INDEX =
FORM = 'MY_FORM'
* LANGUAGE = ' '
* STARTPAGE = ' '
* PROGRAM = ' '
* MAIL_APPL_OBJECT =
* IMPORTING
* LANGUAGE =
* EXCEPTIONS
FORM = 1
FORMAT = 2
UNENDED = 3
UNOPENED = 4
UNUSED = 5
OTHERS = 6
WRITE_FORM
See 'WRITE_FORM'
END_FORM
CALL FUNCTION 'END_FORM'
* IMPORTING
* RESULT =
EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
OTHERS = 3
CLOSE_FORM
* Structure for Print options (return values) - Pages selected for printing, Number of copies etc.
DATA BEGIN OF RESULT.
INCLUDE STRUCTURE ITCPP.
DATA END OF RESULT.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT
342
* RDI_RESULT =
* TABLES
* OTFDATA =
* EXCEPTIONS
* UNOPENED = 1
* BAD_PAGEFORMAT_FOR_PRINT = 2
* SEND_ERROR = 3
* OTHERS = 4
.
CONTROL_FORM Calling Commands Using a program
The function module CONTROL_FORM can be used to create SapScript control statements from
within an ABAP program.
Example:
call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'PROTECT'.
call function 'WRITE_FORM'.....................
call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'ENDPROTECT'.
Boxes Lines Shading
Setting default parameters for a box:
You can use the POSITION and SIZE commands to set default parmeters for a
box.
Instead of:
/: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM
INTENSITY 10 FRAME 0 TW
343
You can write:
/: POSITION XORIGIN '11.21' YORIGIN '5.31' MM
/: SIZE HEIGHT '2' MM WIDTH '76' MM
/: BOX FRAME 10 TW INTENSITY 10
This can be usefull if you gave several boxes that share the same parameters
If you want to set the position realtively to the window use POSITION WINDOW
to
set the position to the top/left start of the window. Then use POSITION
to set the current position relatively to the start of the Window. Note that
you uses "+" or "-" in the ORIGIN position to the set the position
relatively.
/: POSITION WINDOW
/: POSITION XORIGIN '+5' MM YORIGIN '+10' MM
the position is now 5 MM from the left and 10 MM from the top of the window
NOTE: After using the position command you can move the current position
realtively to the
last used position
/: POSITION XORIGIN '+10' MM YORIGIN '+20' MM
Now the position will be X = 15 and Y = 30
Drawing a line. You can draw a line by setting the Height or Weidth to 0
and add a frane. E.g. a horizontal line:
/: SIZE HEIGHT '0' MM WIDTH '200' MM
/: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100
Styles
Styles are used to predefine paragraph and character formats for forms. SAP provides several
standard styles e.g. for Address includes, on-line documentation and so on. You can define your
own styles.
To find styles, create styles and maintaine styles, use transaction SE72.
344
You assign style to a text by using menu Format -> Style
You can make temporary style changes using the control command /: STYLE
Using graphics in SapScript
Use transaction SE78 to inmport graphics to SAP.
In the form painter, you can either include directly to the form using menu Edit->Graphic-
>Create or using the INCLUDE statement in a window.
To use an INCLUDE stanment, goto into the woindow script editor and use menu Include-
>Graphic. The include can look like this for a bitmap:
/: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON
Modifications
Considerations in connection with modifications
The standard SAP print program should only be changed when it is absolutely necessary. If
additional data is needed, these can in many cases be retrieved using a a PERFORM statement in
the form instead of changing the print program..
There can be the following reasons to change the print program:
Structureal changes
New text eloements are needed
Print program to be used to print additional forms
Determine/change which forms and printprograms that are used for printing
The forms and print programs for a given output type and application can be found in table
TNAPR Processing programs for output
Use view V_TNAPR in (Transaction SE30) to change entries.
TROUBLE-SHOOTING SAP SCRIPTS:
In this section, I have explained regarding some of the errors that occur while
using the SAP Scripts with each error in each step.
345
STEP1: Check List of things before Trouble shooting SAP Scripts:
Following things needs to be check listed before starting the trouble shooting for the
sap scripts.
 The form and its ABAP print program are used
 We have to check out whether the SAP standard versions are used or form
or whether the driver program are modified?
 If we are using the printer to take the printouts?
 If the printer is used then check whether its device type is Standard SAP
device or whether it is defined by the user.
STEP2: If there are errors that data or field Contents are missing or the
Includes or the symbols are not Printed
In case of missing data, first of all check the data in the spool.
 If the data gets printed correctly in the spool, then there might be problem
with the printer.
 If data is not found in the spool then there can be problem with the print
program. And if it is ok with the print program then check with the form.
Step3: If the field values are not printed correctly
 If the field values are not printed correctly then debug the print program. If
the fields are not declared then SAP script will not read those fields.
Step 4: Error while reading the print program name.
 Generally the name of the print program is passed to ITCPO-TDPROGRAM
parameter of the OPEN_FORM function module. If the name is not passed
correctly then this error occurs.
Step 5: Error ‘INCLUDE is not found’.
 Include is set in the following format
/: INCLUDE <name> OBJECT <object> ID <id> LANGUAGE <l>
If those variables values are not assigned correctly, then this error occurs.
Step6: Error that text is not printed correctly’.
 This can be verified by including the sample text in the text element and
activate the form. If it prints correctly then there will problem with the include
parameters.
 If the sample text is not printed then it is problem with the text element and
it is not called from the print program.
346
 There will also be problem with language defined and the language used also.
Step 7: Error in fonts:
 Generally SAP Scripts uses printer font which is almost same as the form
submitted. If the printer font and the submitted form font are not matched
then this error occurs.
Step 8: Error ‘Text is not printed correctly in the desired positions’.
 First Check whether the tabs are used. If the field to be placed between the
tab positions is larger than the gap available at that particular position then
there is a possibility of the text not printed correctly in the desired positions.
 If the alignments are not given correctly then also there will be a chance for
not printing the text in the desired positions.
 Check if the standard drivers are used for printing as the standard drivers
cannot over prints the text.
Step 9: Special characters are replaced by normal characters:
 Check whether any standard SAP Device is used and whether it supports
the required character set.
 If not got to transaction SPAD and check whether the required character
set matches with the character set there.
 If not goto transaction sp01 and by using using the display function print
the character. If it prints correctly in the output controller then there
problem persists with the printer .
 If not check if there are any changes made to the page code definiton in
spool adminstration. If yes, execute the program RSTXDELL by selecting
the character set in the execution screen . Upon execution all the character
sets are deleted.
Step 10: Using the SAP Script Form Debugger
 Errors that occur in sap script can be mostly identified by using the SAP Script
debugger.
 First debugger is activated and the printer output is verified in the dialog box.
 Every function module, include and every warning are verified in the
debugger.
 To turn off the debugger, choose Debugger and press exit in the debugger
window.
6. Need for Performance Tuning for driver Programs:
347
Performance tuning for the driver program is essential to reduce the
processing time taken by that driver program and to make it efficient in
doping its work. An efficient driver program delivers the script output to the
user in a finite time as per the complexity of the program.
7. Queries Related to Sap scripts:
1. How to list out all sap scripts in ZH (any language)?
Sol: GO to TADIR table give OBJECT as 'FORM ' and MASTERLANG as
'ZH'. Then u will get all form names in that language.
2. How to divide the sap script main window into 99 times?
Sol: Go to SAP script (SE71) -> Page window tab -> Edit -> Main window
there a pop up appears and you can give according and you can get the
number of windows.
3. How can we download the sap scripts to our PC?
Sol: Use the program RSTXSCRP.
On execution, select the radio button ‘Form’.
In Mode give EXPORT.
Provide the Form Name in Object Name
And Save with .FRM extension.
4. What is the significance of following symbols in text element
editor.
Sol:
Syntax: &symbol(<)&
The leading sign is normally displayed to the right of a numeric value,
except in the case of a floating point number. This option enables you to
specify that the leading sign should be placed to the left of the number.
Syntax: &symbol(>)&
The default setting is to print the leading sign to the right of a numeric
value. If you used the SET SIGN LEFT control command to specify that the
leading sign should be printed in front of the value, you can override this
specification for individual symbols. The symbols specified with the >
option are then printed with the leading sign to the right.
Syntax:&symbol(Z)&
Certain symbol values are printed with leading zeros. If you want to
suppress these, use the Z option.
5. What is the procedure to display the SAP Script in different
languages?
Sol:
 Go to transaction se63.
 Translation-ABAP objects--- Other Long texts- Expand FS
forms and styles
348
 Select FORM Forms By double clicking on the Forms
 Provide the Object name which is nothing but the form name.
 Provide the Source Language And Target language.
 Then got to edit
 Select The Radio Button as Window Texts and Documentation.
 Open it in Change Mode.
 Change the Texts and Elements.
 Save It and activate it.
6. What is the ‘LPD’ error in sap scripts?
Sol:
 This error occurs when the text in the sub windows is not fitted in
the size of the window. In order to overcome this error the text
length inside the window is checked with the window size. This
error occurs only in the case of sub windows.
7. How to import a logo to window in sap script?
Sol: Go To ->SE78 (Graphics Administration).
On Left Panel ->Stored on document server -> Graphics -> Bitmap
Images.
On Right Window-> (Store on document server) Enter the file you want to
mention which is on your Hard disk (Say) (C:/Windows...)
Go To->Click on Import button on the left Toolbar.
Rest follows the process.
In your Script Text Editor:
Go To->Insert->Graphics->Store on Document server.
Name->Copy and Paste it from->SE78.
Sample Code for Logo how will it look after inserting the graphics logo.
/: BOX FRAME 20 TW
* P1
/: BITMAP 'LOGO' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 100
8. How to transfer the scripts?
Sol: There are 3 ways to transfer scripts. They are
a. Using program RSTXR3TR - By using the transport requests
b. Using program RSTXSCRP - It transfers the script from one server to
the other server.
349
c. Using transaction SCC1 - It copies the script in one client to the other
client.
9. Are the scripts Client dependent or independent?
Sol: Scripts are client dependent, because the changes done in one client
will not be reflected in to other and also scripts are stored in ITF format as
text in client dependent tables STXH and STXL.
10. Why the error “WRITE_FORM is invalid” occurs?
Sol: If the correct element name is not given while calling the function
module ‘WRITE_FORM’ then this error occurs.
11. Why we use open form, write form, close form , start form
and end form in scripts?
Sol:
OPEN_FORM: This form opens the script. The module OPEN_FORM opens
layout set printing.
WRITE_FORM: This form is used to write the content mentioned in the
windows of the SAP Script.
START_FORM: This form is dynamically call a page in the script. The
layout set can be changed in the current print procedure with
START_FORM. This may also be used to trigger a new-spool id.
END_FORM: This form is used to close the current layout set.
CLOSE_FORM: This form closes the current SAP script form.
You can have any number for WRITE_FORM, START_FORM and
END_FORM, but for a script you can have only one OPEN_FORM and
CLOSE_FORM.
12. Some standard programs and their functionalities:
Sol:
RSTXFCOM: Comparison of Two Forms
RSTXFCON SAP script: Conversion of Page Format for Forms
RSTXFCPY: Copy Forms Between Clients
RSTXFDEL: Delete and Repair
RSTXFINF: Comprehensive Information about a Specific Form
RSTXFLST: Display Forms in Two Different Clients
13. How to find all SAP scripts and their driver programs?
Sol:
 NACE T-Code is used for finding all the driver programs linked to
forms or by using the table TNAPR, we can find script form names
and their driver programs.
350
 Go to table TTXFP , there we can find the forms and their
corresponding print programs.
14. How to migrate Sap scripts to smart forms?
Sol:
 Go to the SAP Smart Forms initial screen (transaction
SMARTFORMS).
 In the Form field enter the name of the Smart Form you want to
create.
 Migrate SAP script form  Choose Utilities
The dialog window Migrate SAP script Form appears.
 Enter the name and the language of the source form (SAP script).
 Click Enter.
This takes you to the change mode of the SAP Form Builder.
If the selected SAP script form does not exist in the selected
language, a dialog window appears on which you can select one of
the existing languages.
 Now change the design of the form and of the form logic. To
activate the Smart Form choose Activate.
Alternate Method:
 By using the standard program ‘SF_MIGRATE’ the sap scripts
can be migrated to smart forms.
351
BOK
On
Function Module User Exits
352
353
INDEX
Introduction ..……………………………………………………………………………….4
How to find user exits ………………………………………………………………………5
Case 1: User Exit name is not known ………………………………………………..5
Case 2: User Exit name is known …………………………………………………..10
Using Project management of SAP Enhancements ……………………………..................12
A. Project creation ………………………………………………………………………12
B. Enhancement Assignment …………………………………………………………....13
Test for User Exit …………………………………………………………………………..14
A. Sales Order creation ………………………………………………………………….14
B. Display Sales …………………………………………………………………………17
Summary …………………………………………………………………………………....19
References …………………………………………………………………………………..19
354
Introduction
User exit is a functionality provided by SAP to add custom validation or enhancements to
existing SAP transaction. User exit offer you the option of enhancing existing functions according
to your personal requirements. Every module pool has customer function FORM in PBO and
PAI. This form is basically a function that has an INCLUDE object. User can include
enhancements or source code that will be triggered during execution of this transaction.
The exit is implemented as a call to a function module. The code for the function module is
written by the developer. You are not writing the code directly in the function module, but in
include that is implemented in the function module.
The naming standard of function modules for function module exits is:
EXIT_<program name><3 digit suffix>
The call to a function module exit is implemented as:
CALL CUSTOMER.-FUNCTION <3 digit suffix>
Note: This enhancement is used to create settlement rules to internal orders as receivers based on
the company code of the cost center and fiscal year.
355
How to find user exits
CASE 1: User Exit name is not known
Display the program where you are searching for an exit and search for CALL CUSTOMER
356
357
This screen consists of call customer-function which has an exit ‘001’.
Double click on ‘001’ in above screen. It will lead to include where exit is being called.
358
This screen consists of function call to trigger user exit when all necessary requirement
will be fulfilled.
This oval shows entire function call for exit ‘001’.
359
This oval has exit to be triggered.
Again double click on ‘001’ in above screen which navigates to function module exits for the
exit.
This screen is displaying function module exits for the exit which has include where
required logic has been implemented in the form of code.
This function module will get executed when user exit will be triggered.
360
In above screen oval showing include where logic needs to be implemented.
CASE 2: User Exit name is known
If you know the Exit name, go to transaction CMOD.
Choose menu Utilities->SAP Enhancements. Enter the component name as name of function
module exits. Execute (F8).
361
Above screen showing function module name in oval where logic should be
implemented.
Double click on function module name used for user exit.
You will now come to a screen that shows the function module exits for the exit.
In this screen we have include (showing in oval) to code the logic.
362
Using Project management of SAP Enhancements
363
A. Project Creation:
We want to create a project to enhance transaction VA01
- Go to transaction CMOD
- Create a project called ZASR0001
This project is required to assign enhancement to trigger the user exit.
B. Enhancement Assignment
364
- Choose the Enhancement assign radio button and press the Change button
In the first column enter COOM0003 Predefine sold-to party in sales document. Note that an
enhancement can only be used in one project. If the enhancement is already in use, and error
message will be displayed.
Press Save.
365
Press Components.
You can now see that enhancement uses user exit EXIT_SAPLKOBS_001.
Double click on the exit.
Above screen has function module (showing in oval) where it has an include to code
required logic.
Now the function module is displayed. Double click on include where we need to code in the
function module
Insert the code into include. In this example Sales order line items will need to be settled to post
Results Analysis data to FI. SAP requires settlement rules to be assigned to sales order line items
to enable posting. Settlement rules will need to be created automatically to support month end
settlement to internal orders.
Activate the include program. Go back to CMOD and activate the project.
366
Test for User Exit
A. Sales Order creation
Go to transaction VA01 and create a sales order.
Example:
For sales order creation Sold-to-Party, Sales Organization, Distribution channel and Division is
required to enter. In this example Sold-to-party will be 5999999999. The receiver internal order
will need to be obtained from a custom table that will map the internal order which will be the
settlement receiver by the company code and profit center of the sales order item. Get single
record from table ZSETRULE_MAP where the company code and profit center combination in
the mapping table. Get records from the mapping table for company code and profit center
combination corresponding to the sales order item.
Goto transaction VA01 and give required detail and Enter.
367
Enter Sold-to-party, Req.deliv.date, Material, Target quantity and item category at the input and
press Enter in order to create Sales Order (Oval showing all required input field to be entered).
At the next screen we need to give Sales District.
Press Save.
After save, system creates sales order.
In this process records from the mapping table where company code from mapping table =
company code of the sales order obtained from table VBAK. Get sales order number from VBAP-
VBELN using the sales order object number field which is an import parameter COBRA-OBJNR
as a link to VBAP-OBJNR. And where profit center ZSO_PRCTR from mapping table = profit
center of the sales order item from VBAP-PRCTR.
Only sales orders line for ZATM, ZAFS and ZAFM item category codes will need to be selected
for this purpose. Settlement profile for line items with this item category will automatically be
defaulted by the item category of the sales order line item.
368
B. Display Sales Order
To display sales order detail, go to transaction VA03. Enter sales order number which needs to be
displayed. Press enter.
369
Select the line item for which settlement rule is need to be displayed. Double click on line item
which leads to next screen.
At this screen go to Account Assignment tab and press.
A settlement rule tab will appear on the screen. Press it.
Settlement detail will appear as given below:
If no settlement rule is defined for that material then it will display information “No Settlement
rule is defined”.
370
Summary:
This user exit has been created to create settlement rules to internal orders as receivers based on
the company code of the cost center and fiscal year. Sales order line items will need to be settled
to post Results Analysis data to FI. SAP requires settlement rules to be assigned to sales order
line items to enable posting. Settlement rules will need to be created automatically to support
month end settlement to internal orders. Only sales orders line for specified item category codes
will need to be selected for this purpose. Settlement profile for line items with this item category
will automatically be defaulted by the item category of the sales order line item.
This process can be followed for other function module User Exit.
Documentation for project User-Exits in PO/GR.
What is User Exit ?
You can use User Exits to adapt the SAP System to your company's specific
requirements. They do not involve modifications to the original coding; instead, they
consist of a separate area that is defined by SAP and shipped with the standard system
either empty or with default values. You can individually configure and activate these
system extensions. By enhancing the SAP software via user exits, we avoid modifications
in the traditional sense.
A further advantage of user exits is that programs developed with user exits remain
unchanged during upgrades to the SAP software.
User exits are not affected by SSCR, because the customer-specific parts of the user exits
are implemented in the customer name range.
Categories of User Exits
Three types of user exits exist:
 Function exits. Function exits are function modules that have been defined by
SAP and that you can activate. The application developers determine which data
is passed on and define the function groups and function modules in the function
library (with short text and interface, but without coding).
 Menu exits. Menu exits can be used to activate menu items and furnish them with
additional functionality.
 Screen exits. Screen exits enable you to add additional fields to a screen.
371
You can only take advantage of exits if SAP has added them to one of its standard
applications. For this reason, you need to know how to locate the exits available in the
SAP System. SAP organizes its exits in packages are called SAP enhancements. Each
SAP enhancement can contain many individual exits.
Different ways to find out user exits for a particular application.
1> Using transaction CMOD-
Steps:-
Choose Utilities Enhancements Project management from the ABAP
Workbench menu. From here, choose Utilities  SAP enhancements to call a
selection screen that lets you look for the exits available in standard applications.
If you do not know the name of a specific enhancement package, you can search
for enhancements by development class. To list all enhancements in the entire
system, choose the Execute function without specifying any selection criteria.
The system displays a list of all enhancement packages.
2> Using transaction SE81-
Steps:-
Use the Application Hierarchy to search for exits that are available for a particular
application area. You can access the application hierarchy by choosing ABAP
Workbench  Overview  Application hierarchy
The SAP Application Hierarchy lists all of the standard SAP applications and
their component parts. You can use the hierarchy with the Repository Information
System to locate exits available for specific applications or programs. To locate
the exits associated with Materials Management, for example, proceed as follows:
1. Place the cursor on the Materials Management branch of the Application
Hierarchy tree and choose Sel./desel. sub-tree.
The system marks the application area.
2. Choose Repository Infosys.
The system lets you search for any objects assigned to a particular
application.
3. Expand the Environment sub-tree in the Repository Information System.
4. Expand the Exit Techniques sub-tree. Choose either Enhancements or
Projects for specific customer exit by double-clicking.
372
The system offers a selection screen that allows you to narrow down your
search. You can leave the fields on this screen empty.
5. Choose Execute.
The system will retrieve all the enhancements assigned the category you
marked in the Application Hierarchy.
3> Using Transaction SPRO – IMG-
Use IMG to locate the enhancements for desired application.
For eg. To locate it for MM-Purcahsing, Follow the given path:-
Select Material Management tree from initial screen.
Select purchasing from this tree.
You will get Enhancements for Purchasing item within this subtree.
Click on Documentation icon to view all the User- exits supported for this
area.
List of User-Exits for PO/GR and their functionality-
LMEDR001 Enhancements to print program (of purchasing Documents)
LMELA002 Adopt batch no. from shipping notification when posting a GR
Enhancement LMELA002 comprises a function module that is invoked when a
GR is processed with reference to a shipping notification.
This enhancement allows the batch number to be taken from the associated
shipping notification as the default value for each item in the goods
receipt.
A prerequisite is that you use enhancement LMELA010 to adopt the batch
numbers in the shipping notification.
373
M06E0004 Changes to communication structure for release purch. doc.
M06E0005 Role determination for release of purchasing documents
ME590001 Grouping of requsitions for PO split in ME59
Enhancement ME590001 allows you to use a non-standard-SAP logic for
grouping requisitions for purchase orders or PO items when automatically
converting requisitions into POs.
In the standard system, you can use the selection parameters to specify
that a new PO is to be created when one of the criteria "purchasing
group", "plant", "storage location", "item category", "delivery date",
"vendor sub-range", "purchase requisition number", "purchase requisition
item", or "company code" changes.
The function exit EXIT_SAPLME59_001 enables you to define any other
criteria (example: see below).
The function module has the following parameters:
o T_EBAN
Table with all requisitions that are to be converted. The table is
pre-sorted according to the splitting criteria you selected on the
selection screen.
o T_EBANX
Index table containing those requisitions for which a new PO or PO
item is to be generated. This table is likewise pre-filled in the
standard system. For example, the field T_EBANX-PO_NEW is filled
with 'X' in the case of each requisition that is assigned to a
different vendor than the preceding one.
374
Example:
You want to generate a new purchase order for each requester shown in
the requisition. The relevant source code in program ZXM01U01 might look
like this:
DATA: L_EBAN LIKE EBAN OCCURS 0 WITH HEADER LINE,
L_TABIX LIKE SY-TABIX,
NEXT_EBAN LIKE EBAN,
NEW_PO LIKE SY-CALLD,
OLD_AFNAM LIKE EBAN-AFNAM.
LOOP AT T_EBAN.
L_TABIX = SY-TABIX + 1.
READ TABLE T_EBAN INDEX L_TABIX INTO NEXT_EBAN.
IF SY-SUBRC NE 0.
NEW_PO = 'X'.
ELSE.
READ TABLE T_EBANX WITH KEY BANFN = NEXT_EBAN-BANFN
BNFPO = NEXT_EBAN-BNFPO.
IF SY-SUBRC EQ 0 AND NOT T_EBANX-NEW_PO IS INITIAL.
NEW_PO = 'X'.
ELSE.
CLEAR NEW_PO.
ENDIF.
ENDIF.
APPEND T_EBAN TO L_EBAN.
CHECK NEW_PO EQ 'X'.
SORT L_EBAN BY AFNAM WERKS BANFN BNFPO.
CLEAR OLD_AFNAM.
375
LOOP AT L_EBAN.
IF SY-TABIX EQ 1 OR L_EBAN-AFNAM NE OLD_AFNAM.
READ TABLE T_EBANX WITH KEY BANFN = L_EBAN-BANFN
BNFPO = L_EBAN-BNFPO.
IF SY-SUBRC EQ 0.
T_EBANX-NEW_PO = 'X'.
MODIFY T_EBANX INDEX SY-TABIX.
ELSE.
CLEAR T_EBANX.
T_EBANX-BANFN = L_EBAN-BANFN.
T_EBANX-BNFPO = L_EBAN-BNFPO.
T_EBANX-NEW_PO = 'X'.
APPEND T_EBANX.
ENDIF.
ENDIF.
OLD_AFNAM = L_EBAN-AFNAM.
ENDLOOP.
APPEND LINES OF L_EBAN TO L_EBAN_ALL.
REFRESH L_EBAN.
ENDLOOP.
T_EBAN[] = L_EBAN_ALL[].
MEAG0001 Distribution of contract/scheduling agreement from CRM
MEETA001 Define schedule line type (backlog, immed. req., preview)
MEFLD004 Determine earliest delivery date f. check w. GR (only PO)
When goods are received with reference to a purchase order, the system
checks the earliest delivery date against the GR date. The function exit
of the enhancement MEFLD004 allows you to change the earliest delivery
date and refuse to accept too-early deliveries, for example.
376
Whether or not the GR can be posted dependes on the attributes of the
system message "Earliest possible delivery date is &" (message class M7,
number 254). You specify in Customizing whether this is issued as an
error or warning message or whether it does not appear at all.
MELAB001 Gen. forecast delivery schedules: Transfer schedule implem.
MEQUERY1 Enhancement to Document Overview ME21N/ME51N
MEVME001 WE default quantity calc. and over/ underdelivery tolerance
The enhancement MEVME001 comprises the user exit EXIT_SAPLEINR_001,
which is invoked to calculate the default quantity in the case of a
goods receipt against a scheduling agreement.
Example
If your vendors frequently deliver early, you can use this user exit
to specify that instead of the quantity open to date, the quantity
open up to the day after tomorrow is taken as the default quantity
for a goods receipt.
You can also specify that the tolerance check is to relate not to
the default quantity but to the total scheduled quantity.
This enhancement can be used to define the following data differently to
that in the standard system:
o Default quantity for goods receipt
In the standard system, the quantity open to date from the last-
transmitted SA release is used in the case of scheduling agreements
with release documentation (document type LPA). In the case of
scheduling agreements without release documentation (document type
LP), the open quantity to date is used.
377
Note
If you use vendor confirmations with GR assignment, the quantity
from the confirmation is suggested (i.e. in this case, the default
quantity cannot be influenced via the user exit.
o The quantity to which the tolerance calculation is to relate
(In the standard system, the tolerance check relates to the default
quantity - i.e. the quantity open to date). At the time of the
tolerance check, the tolerance limits for under- and overdeliveries
entered in the scheduling agreement item are taken into account.
The parameters F1 and F2 are passed on in the interface to the user
exit. These parameters must contain the following data:
Parameter F1
= Default quantity + total of all already delivered quantities (posted
GR quantity)
(The already delivered quantity is deducted again prior to the output of
the default quantity on the screen.)
Parameter F2
= Quantity to which the tolerance calculation relates
All schedule lines for the relevant item are passed on in the internal
table "CETT" as the basis for determining the default quantity and the
tolerance.
Note
378
Please note that the user exit applies to both document types.
MM06E001 User exits for EDI inbound and outbound purchasing documents
MM06E003 Number range and document number
This enhancement allows you to specify (via function module
EXIT_SAPMM06E_001) that you either
o assign a document number yourself, or
o only determine a number range ID
The number range ID and all header data are then passed on to the
following function module NUMBER_GET_NEXT. This determines the
document
number
Example:
You can assign the numbers in dependence on the company code. Depending
on the company code, you choose a number range interval and then use the
standard function module. In the event of an error, you can either issue
your own error message or use the standard message via the exceptions.
MM06E004 Control import data screens in purchase order
MM06E005 Customer fields in purchasing document
MM06E007 Change document for requisitions upon conversion into PO
MM06E008 Monitoring of contr. target value in case of release orders
MM06E009 Relevant texts for "Texts exist" indicator
MM06E010 Field selection for vendor address
MM06E011 Activate PReq Block
379
MMDA0001 Default delivery addresses
MMFAB001 User exit for generation of release order
MRFLB001 Control Items for Contract Release Order
SAPL2012 Customer Exit from Enjoy: Purchase Orders via BAPIs
SAPLMEWP Customer exit for processing of purchase orders via BAPIs
SAPMMWE1 Create requirement coverage request - materials catalog data
WVLB0003 User exits for automatic PO-based load building in 99.A
WVLB0005 User exits in TR WLB5 (manual load bulding)
WVLB000A User exits for control program for load building
---------------------------------------------------------GR----------------------------------------------
---------------
LIFO0040 User interfaces for LIFO valuation
MBCF0002 Customer function exit: Segment text in material doc. item
MBCF0005 Material document item for goods receipt/issue slip
MBCF0006 Customer function for WBS element
MBCF0007 Customer function exit: Updating a reservation
MBCF0009 Filling the storage location field
MBCF0010 Customer exit: Create reservation BAPI_RESERVATION_CREATE1
MBCF0011 Read From RESB and RKPF For Print List in MB26
MBCFC003 Maintenance of batch master data for goods movements
MBCFC004 Maintenance of batch specifications for goods movements
NIWE0000 Change quantities within scope of balance sheet valuation
NIWE0001 Lowest value determination based on market prices
NIWE0002 Lowest value determination by range of coverage or movement
NIWE0003 Loss-Free Valuation
WBWE0001 Function exits for valuation for structured materials
380
ALE – IDOC Scenario with Customized Idoc.
Aim: Transfer the data from one system to another using user customized Idoc.
Sender System:
Server: 172.25.8.185
Client: 200
Data from Z table: zsach1
ReceiverSystem:
Server: 172.25.9.198
Client: 800
Data from Z table: zsach1
Data is fetched from Z table on the sender system and inserted it in the Z table of
Receiver system using ALE/IDOC.
Document Designed by :
Sachin Dabhade
09850848853
381
Settings on the Sender End
Table Creation T – Code SE11. The table contains data that is to be sent to Receiver.
ALE Configuration
T-Code – SALE
Defining Logical System
200 is our sender
800 is our receiver
382
Assigning Client to Logical System
200 is our sender
800 is our receiver
Defining Target System for RFC Calls (Tcode – SM59)
383
Click on R/3 Connections and then Create TAB
Step 1
Step 2
384
Defining Port
The sender system is connected to the receiver system through this Port.
Defining Partner Profiles
385
The partner for client 200(Sender) is the client 800 (Receiver)
Since this is a sender we have to define only Outbound Parameters in this case.
Here you can see the Message type is Z message type.
2. Maintaining Distribution Model ( TCode BD64 )
386
Create new Distribution Model
387
Add Message Type
388
Now Distribute this Model View
Distribute it from Edit  Model View  Distribute
389
Defining the Z Segment type
Tcode – WE31
Defining the Basic Type
T Code WE30
390
Click on New
This will take you to next screen as follows
391
Here you have connected the basic type to the segment type.
Enter again and this will take you to screen as follows
This shows the relation between the basic and the segment types.
Next you need to make the entry of the segment in the system table.
Tcode : WE81
392
Next is the following entry which is required.
Here you are specifying the message type and the basic type and the release version.
This is all about the configuration you need to do on the sender side.
393
Now on the sender side you also need a program that will fetch the required data,
couple it in the IDOC format and post it.
Here is a small piece of code that could be useful.
*&---------------------------------------------------------------------*
*& Report ZSACH_CUST_IDOC *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report zsach_cust_idoc .
parameters : p_logsys like tbdlst-logsys.
data : gen_segment like edidd-segnam value 'ZSACH'.
data : control_dat like edidc,
gen_data like z1hdr .
tables :zsach1.
data: begin of inttab occurs 0,
lname type z1hdr-lname,
fname type z1hdr-fname,
end of inttab.
data :
int_edidd like edidd occurs 0 with header line,
int_edidc like edidc occurs 0 with header line.
select * from zsach1 into corresponding fields of table inttab.
if sy-subrc ne 0.
message 'no data' type 'I'.
exit.
endif.
control_dat-mestyp = 'ZSACH'.
control_dat-idoctp = 'ZSACH'.
control_dat-rcvprt = 'LS'.
control_dat-rcvprn = p_logsys.
loop at inttab.
gen_data-lname = inttab-lname.
gen_data-fname = inttab-fname.
* GEN_DATA-SSN = INTTAB-SSN.
* GEN_DATA-DOB = INTTAB-DOB.
int_edidd-segnam = gen_segment.
394
int_edidd-sdata = gen_data.
append int_edidd.
endloop.
call function 'MASTER_IDOC_DISTRIBUTE'
exporting
master_idoc_control = control_dat
* OBJ_TYPE = ''
* CHNUM = ''
tables
communication_idoc_control = int_edidc
master_idoc_data = int_edidd
exceptions
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
others = 5
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno.
else.
loop at int_edidc.
write :/ 'IDOC GENERATED',int_edidc-docnum.
endloop.
commit work.
endif.
Settings on the receiver side.
The ALE configuration is same as we did it on the sender side. Please refer to earlier
pages.
The receiver specific differences are mentioned below.
T-Code – SALE
200 is our sender
800 is our receiver
395
Steps
Defining Logical System (Same as sender)
Assigning Client to Logical System (Same as sender)
Defining Target System for RFC Calls (Tcode – SM59) (Same as sender)
Defining Port(Same as sender)
Defining Partner Profiles – Here we are accepting the data from
Sender system. Hence we need to configure it as Inbound.
396
Click on the sign above to go to next screen.
Here the message type is to be created again as it was created on the sender side.
The following steps are repeated on the receiver end
Tcode WE30
Tcode WE31
Tcode WE82
397
Tcode WE81
Here on the receiver end, we need to specify a process code at the time of defining
the partner profile.
Process code is something that has the logic defined about what to be done after
receiving the Idoc.
In our case, on receipt of the Idoc, we are updating the Z Table. I.e Inserting the
data from the Idoc into the Z Table.
Creating a Process Code
Tcode – WE42
398
The logic associated is coded in the Function Module which is specified in the
Identification Field above.
Also the processing type is selected as Processing by Function Module as above.
399
The function Module is specified in the following screen.
To have your function Module in the above drop down list, the entry is to be made
using the following transaction
TCode – BD51
Once the entry is done here, the function module appears in the drop down list in the
previous stage.
Also it is important to make the following entry
Tcode WE57
400
Function Module will look something as below:
401
Source Code
function z_idoc_input_sach .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" VALUE(NO_APPLICATION_LOG) LIKE SY-DATAR OPTIONAL
*" VALUE(MASSSAVEINFOS) LIKE MASSSAVINF STRUCTURE MASSSAVINF
*" OPTIONAL
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
402
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------
include mbdconwf.
data : it_emp_data like zsach1 occurs 0 with header line.
data : gen_data like zsach1 .
workflow_result = c_wf_result_ok.
*
data : counter type int4.
select count( * ) from zsach1 into counter.
counter = counter + 1.
loop at idoc_contrl.
if idoc_contrl-mestyp ne 'ZSACH'.
raise wrong_function_called.
endif.
clear gen_data.
refresh it_emp_data.
loop at idoc_data where docnum eq idoc_contrl-docnum.
if idoc_data-segnam = 'ZSACH'.
gen_data = idoc_data-sdata.
it_emp_data-mandt = counter.
it_emp_data-lname = gen_data-lname.
it_emp_data-fname = gen_data-fname.
counter = counter + 1.
append it_emp_data.
else.
message 'ERROR' type 'I'.
endif.
endloop.
endloop.
* LOOP AT IT_EMP_DATA.
*
* CONCATENATE 'INB' IT_EMP_DATA-LNAME INTO IT_EMP_DATA-LNAME.
* MODIFY IT_EMP_DATA.
* ENDLOOP.
* modify ZSACH1 FROM TABLE IT_EMP_DATA.
403
insert zsach1 from table it_emp_data.
*****
call function 'EDI_DOCUMENT_OPEN_FOR_EDIT'
exporting
document_number = idoc_data-docnum
importing
idoc_control = idoc_contrl
tables
idoc_data = idoc_data
exceptions
document_foreign_lock = 1
document_not_exist = 2
document_not_open = 3
status_is_unable_for_changing = 4
others = 5.
*itab_edidd-docnum = '0000000000221999'.
*itab_edidd-psgnum = '000111'.
*itab_edidd-sdata = itab_edidd-sdata.
*APPEND itab_edidd.
call function 'EDI_CHANGE_DATA_SEGMENTS'
tables
idoc_changed_data_range = idoc_data
exceptions
idoc_not_open = 1
data_record_not_exist = 2
others = 3.
*****
data t_itab_edids40 like edi_ds40 occurs 0 with header line.
clear t_itab_edids40.
t_itab_edids40-docnum = idoc_data-docnum.
t_itab_edids40-status = '51'.
t_itab_edids40-repid = sy-repid.
t_itab_edids40-tabnam = 'EDI_DS'.
t_itab_edids40-mandt = sy-mandt.
t_itab_edids40-stamqu = 'SAP'.
t_itab_edids40-stamid = 'B1'.
t_itab_edids40-stamno = '999'.
t_itab_edids40-stapa1 = 'Sold to changed to '.
*t_itab_edids40-stapa2 = t_new_kunnr.
t_itab_edids40-logdat = sy-datum.
t_itab_edids40-logtim = sy-uzeit.
append t_itab_edids40.
call function 'EDI_DOCUMENT_CLOSE_EDIT'
exporting
document_number = idoc_data-docnum
do_commit = 'X'
404
do_update = 'X'
write_all_status = 'X'
tables
status_records = t_itab_edids40
exceptions
idoc_not_open = 1
db_error = 2
others = 3.
endfunction.
405
Running the Application
Sender system
Checking the Idoc
T Code WE02
406
Checking the data on the Receiver end
Tcode: WE02
The Idoc has arrived here
Checking the Data
Double click on the Idoc
407
Checking the Database
This way, the data has come to the receiver end successfully.
408
LSM Workbench
LSMW Quick Ref and steps for XD02
This BOK provides a Quick Introduction to working with LSMW and step-by-step guide to update
customer master records using XD02 in Standard Batch/Direct Input method.
SI# Date Doc Version Author Reviewer Review
Comments
1 05.02.2007 1.0 Lavanya
Kundella
Ramnarayana
Halder
TARGET READERS: Technical/Functional/Basis Consultants in SAP Practice
Data Migration
409
Scope
The focus of this BoK is to give a brief idea of LSMW and step-by-step guide to update
customer master records using XD02 in Standard Batch/Direct input method.
What is Data Migration/LSM?
 Data transfer from non-SAP systems to SAP R/3.
 Periodic data transfer.
 Requires customized R/3 system.
 Switch off legacy system.
Figure 1: source: “help.sap.com”
Why is data migration so expensive?
 Need to develop conversion programs (which cannot be used later on)
 Need to deal with lots of technical details and different technology.
What is LSMW (Legacy System Migration Workbench)?
 LSMW is R/3 based tool.
 LSMW supports periodic and single data transfer from non-sap systems to R/3.
 Uses standard R/3 interfaces.
410
How LSM Workbench works?
 SAP AG July 1999 21
Accelerating Data Migration: LSM Workbench
One or several
files
R/3Standard
Convert data
Batch Input
processing
Legacy data
on PC
Read data
Converted
data
Read data
Legacy data
on application
server
IDoc inbound
processing
Direct Input
processing
How LSM Workbench works
Structure
relations
Field mapping
Conversion
rules
Figure 2: source: “help.sap.com”
What kind of data can be read?
 Data from spreadsheet-based applications. Ex: MS-Excel, MS Access etc.
 Data from host systems on R/3 application servers.
 Fixed record length, end of record indicator or hexadecimal length field at the
beginning.
 With and without separator.
 Code page conversion.
 “Hierarchical” data with identifying field values”.
Which data can be migrated via LSMW?
All data where an interface exists.
 Standard Batch Input, Standard Direct Input.
411
1. Precondition: application program
2. Entries in table SXDA* (DX Workbench)
 Batch Input Recording
1. Recording transaction
2. Flat target structure
 Methods for Business Objects (BAPIs)
 All BAPIs for which an ALE-IDOC interface has been generated.
 IDOCs
 All
What LSMW can do?
 Organize the data migration project
 project, subproject, object
 Document the data migration project
 Define data conversion per object
 select target
 business object (ex: customer master, material master)
 method (ex: create, change)
 import technique (ex: batch-input, IDOCs)
 define source
 structure of the source data (segments, fields, file attributes etc)
 define relations
 between source and target (SAP R/3) on record level and on field
level
 define rules
 transfer of field contents
 Read data (technical conversion)
 Convert data (conversion of values)
 Import data
 with a standard import technique
 batch-input
 direct input
 method for a business-object (“BAPI”)
 IDOCs technique
 this means:
 LSMW does not write data into the databases of the applications
 precondition for the use of LSMW is the availability of a data transfer
interface in the R/3 application
 Transport the data migration object
 via download and upload
 via R/3 transport system
412
Advantages of LSMW?
 Part of the SAP system and thus independent of individual platforms.
 A variety of technical possibilities of data conversion.
 Data consistency due to standard import techniques.
 Generation of the conversion program on the basis of defined rules.
 Clear Interactive process guide.
 Charge-free for SAP customers and SAP partners.
LSMW to Update Customer Master Records with Standard
Object
To start working with the LSM Workbench, use transaction LSMW
Create an Object CUST_OBJ within Project as ZLK_LSMW and Subproject as
CUSTOMERS.
Figure 3 LSMW Object with Standard SAP Object
Step 1: Maintain Object attributes
You will be updating the customer master records with the help of Standard Batch Input;
therefore, choose radio-button Standard Batch/Direct Input.
Enter Object ‘0050’ for Customer Master Records and default method ‘0000’ and click on Save.
413
Figure 4 Standard Batch/Direct Input Object Attributes
Step 2: Maintain Source Structures
Give a name and a description to the source structure.
Figure 5 Source Structure
414
Step 3: Maintain Source Fields
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 .
Figure 6 Source fields of source Structure
Note that your input file will have four fields as key fields and you need to update three fields in
the system.
415
Step 4: Maintain Structure Relations
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.
Figure 7 Structure Relation
416
Step 5: Maintain field mapping and conversion rules
Keep your cursor on ‘TCODE’ field and click on ‘Insert Rule’ icon
Figure 8 LSMW Conversion Rules
Choose radio button ‘Constant’ 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’.
417
Figure 9 Assign Source fields
Similarly, choose source fields for Sales Organization, Distribution Channel, and Division.
Figure 10 Field Mapping and Conversion Rules
418
Scroll down to structure BKNVV fields and assign source fields to three fields Sales Office, Sales
Group, and Customer Group
Figure 11 Field Mapping and Conversion Rules
Save and go back to main screen.
Step 6: Maintain fixed values, translations, user-defined routines
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.
419
Figure 12 Maintain Fixed values, translations, user defined routines
Step 7: Specify files
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 PC (local drive) as C:XD02.txt.
Figure 12 Data in the tab delimited file
Xd02.txt
Source data in tab delimited file
420
Figure 13 Specify File name
421
Figure 14 Specify File name
Step 8: Assign files
Execute step ‘Assign Files’ and the system automatically defaults the filename to the source
structure.
Figure 15 Assign file to Source Structure
422
Step 9: Read data
In this step, LSMW reads the data from the source file (from PC’s local drive). You have the
option to read only selected rows and convert data values to internal format.
Figure 16 Read Data
Figure 17 Read Data
423
Step 10: Display read data
This step is optional. If required, you can review the field contents for the rows of data read.
Figure 17 Display Read Data
Step 11: Convert data
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.
424
Figure 17 Convert Data
Figure 18 Convert Data
Step 12: Display Converted data
When you convert data, LSMW automatically converts into the appropriate structure layouts, as
required by Standard program (RFBIDE00).
425
Figure 19 Converted data into multiple structures
Note that if you had only one record in source file, the converted file has four records.
Earlier, creating this input file, so that the standard interface program can read it, was a big
nightmare, the primary reason being that it could have multiple record layouts. Even for a simple
conversion with one input record, you would have to create this complex file with many record
layouts. The advantage of LSMW is that it prepares these multi-layout files automatically.
Step 13: Create batch input session
Once source data is converted in internal format, you can create a BDC session to process the
updates.
426
Figure 20 Create BDC Session
Figure 21 BDC Session ‘CUST_OBJ’ created
Step 14: Run Batch Input Session
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).
427
Figure 22 BDC Session ‘CUST_OBJ’ Process
Figure 23 Customer record updated with Customer Group
428
429
430
431
432
433
434
435
436
437
438
439
440
441
SAP's OPEN SQL, syntax of the SELECT
statement
Basic form:
SELECT result FROM source [INTO target] [WHERE condition] [GROUP BY fields]
[ORDER BY order].
SELECT clause
Variants:
1. SELECT [SINGLE [FOR UPDATE] DISTINCT] *
2. SELECT [SINGLE [FOR UPDATE] DISTINCT] s1 ... sn
3. SELECT [SINGLE [FOR UPDATE] DISTINCT] (itab)
FROM clause
Variants:
1. ... FROM dbtab
Additions:
1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS
2. ... FROM (dbtabname)
Additions:
1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS
INTO target
(This form of the FROM clause works only in conjunction with the
INTO clause.)
INTO clause
Variants:
1. ... INTO wa
442
2. ... INTO CORRESPONDING FIELDS OF wa
3. ... INTO (f1, ..., fn)
4. ... INTO TABLE itab
5. ... INTO CORRESPONDING FIELDS OF TABLE itab
6. ... APPENDING TABLE itab
7. ... APPENDING CORRESPONDING FIELDS OF TABLE itab
WHERE clause
Variants:
1. ... WHERE f op g
2. ... WHERE f [NOT] BETWEEN g1 AND g2
3. ... WHERE f [NOT] LIKE g
4. ... WHERE f [NOT] IN (g1, ..., gn)
5. ... WHERE f [NOT] IN itab
6. ... WHERE f IS [NOT] NULL
7. ... WHERE NOT cond
8. ... WHERE cond1 AND cond2
9. ... WHERE cond1 OR cond2
10. ... WHERE (itab)
11. ... WHERE cond AND (itab)
12. ... FOR ALL ENTRIES IN itab WHERE cond
opera
tor
Meaning
EQ
or =
equal to
NE
or <>
not equal to
LT
or <
less than
LE
or <=
less than or equal to
GT
or >
greater than or equal to
GE
or >=
greater than or euqal to
443
GROUP-BY clause
Variants:
1. ... GROUP BY f1 ... fn
2. ... GROUP BY (itab)
ORDER-BY clause
Variants:
1. ... ORDER BY PRIMARY KEY
2. ... ORDER BY f1 ... fn
3. ... ORDER BY (itab)
Useful Dev. and Workbench Transactions
SCAM CATT Management
SCAT Computer Aided Test Tool
SE09 Workbench Organizer
SE10 Customizing Organizer
SE11 ABAP/4 Dictionary Maintenance
SE12 ABAP/4 Dictionary Display
SE13 Maintain Technical Settings (Tables)
SE14 Utilities for Dictionary Tables
444
SE15 ABAP/4 Repository Information System
SE16 Data Browser
SE17 General Table Display
SE30 ABAP/4 Runtime Analysis
SE32 ABAP/4 Text Element Maintenance
SE35 ABAP/4 Dialog Modules
SE36 ABAP/4: Logical Databases
SE37 ABAP/4 Function Modules
SE38 ABAP/4 Program Development
SE39 Splitscreen Editor: Program Compare
SE41 Menu Painter
SE43 Maintain Area Menu
SE51 Screen Painter
SE54 Generate View Maintenance Module
SE61 R/3 Documentation
SE62 Industry utilities
SE63 Translation
SE64 Terminology
SE65 R/3 document. short text statistics
SE66 R/3 Documentation Statistics (Test!)
SE68 Translation Administration
SE71 SAPscript layout set
SE72 SAPscript styles
SE73 SAPscript font maintenance (revised)
SE74 SAPscript format conversion
SE75 SAPscript Settings
SE76 SAPscript Translation Layout Sets
SE77 SAPscript Translation Styles
SE80 ABAP/4 Development Workbench
SE81 SAP Application Hierarchy
SE82 Customer Application Hierarchy
SE84 ABAP/4 Repository Information System
SE85 ABAP/4 Dictionary Information System
SE86 ABAP/4 Repository Information System
445
SE87 Data Modeler Information System
SE88 Development Coordination Info System
SE91 Maintain Messages
SE92 Maintain system log messages
SE93 Maintain Transaction Codes
SEU Object Browser
SHD0 Transaction variant maintenance
SQ00 ABAP/4 Query: Start Queries
SQ01 ABAP/4 Query: Maintain Queries
SQ02 ABAP/4 Query: Maintain Funct. Areas
SQ03 ABAP/4 Query: Maintain User Groups
SQ07 ABAP/4 Query: Language Comparison
System field (sy-dbcnt)(2)
REPORT ZBCTCB92.
TABLES: T000.
DATA: BEGIN OF T OCCURS 0,
FIELD(10),
END OF T.
DATA: NUM TYPE N.
DETAIL.
* sy-linct and sy-linsz describes a page of the list
WRITE: / 'Example of sy-linct and sy-linsz'.
SKIP.
WRITE: / SY-LINCT, 'line and', (3) SY-LINSZ, 'column is a page'.
* sy-index works in do-enddo and while-endwhile loops.
* it contains the number of loop passes.
WRITE: /'Example of sy-index'.
SKIP.
DO 5 TIMES.
WRITE: SY-INDEX.
ENDDO.
* sy-tabix is the index number of the currently processed row
446
* for an internal table
SKIP.
WRITE: /'Example of sy-tabix'.
SKIP.
T-FIELD = 'One'. APPEND T.
T-FIELD = 'Two'. APPEND T.
T-FIELD = 'Three'. APPEND T.
T-FIELD = 'Four'. APPEND T.
T-FIELD = 'Five'. APPEND T.
WRITE: /'Example of sy-tabix I'.
SKIP.
LOOP AT T.
WRITE: / SY-TABIX, T-FIELD.
ENDLOOP.
*sy-fdpos contains off-set after string comparison and search operations
SKIP.
WRITE: /'Example of sy-fdpos'.
SKIP.
CLEAR T.
SEARCH T FOR 're'.
READ TABLE T INDEX SY-TABIX.
WRITE: / SY-TABIX, T-FIELD.
SKIP.
WRITE: /9 'At the example of sy-tabix, Row', (3) SY-TABIX, ',' ,
'keyword ''re'' found at off-set position:', (3) SY-FDPOS.
SKIP.
* sy-dbcnt contains the number of selected records.
* sy-subrc is 0 if an operation was successful.
WRITE: /'Example of sy-dbcnt and sy-subrc I'.
SKIP.
SELECT * FROM T000 WHERE MANDT BETWEEN '000' AND '066'.
WRITE: /10 'Mandant:', T000-MANDT.
ENDSELECT.
WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.
447
WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC .
SKIP.
WRITE: /'Example of sy-dbcnt and sy-subrc II: don't find records'.
SKIP.
SELECT * FROM T000 WHERE MANDT EQ -1.
ENDSELECT.
WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.
WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC.
System fields sy-lilli(3)
REPORT ZBCTCB90 NO STANDARD PAGE HEADING
LINE-COUNT 20 LINE-SIZE 255.
TABLES: T000.
DETAIL.
DO 5 TIMES.
SELECT * FROM T000.
WRITE: / T000-MANDT, T000-MTEXT.
ENDSELECT.
NEW-PAGE.
ENDDO.
TOP-OF-PAGE.
WRITE: / 'Page', SY-PAGNO.
AT LINE-SELECTION.
DETAIL.
* SY-LSIND is the index of the current list
WRITE: / 'SY-LSIND:', SY-LSIND LEFT-JUSTIFIED.
* SY-LISTI is the index of the previous list
WRITE: / 'SY-LISTI:', SY-LISTI LEFT-JUSTIFIED.
* SY-LILLI is the number of the selected line in the absolute list
WRITE: / 'SY-LILLI:', SY-LILLI LEFT-JUSTIFIED.
* SY-CUROW is the position of the selected line on the screen
WRITE: / 'SY-CUROW:', SY-CUROW LEFT-JUSTIFIED.
448
* SY-CUCOL is the position of the cursor in the window
WRITE: / 'SY-CUCOL:', SY-CUCOL LEFT-JUSTIFIED.
SKIP.
WRITE: / 'SY-CPAGE and SY-STAR0 do not depend on the cursor
position'.
SKIP.
* SY-CPAGE is the currently displayed page of the list
WRITE: / 'SY-CPAGE:', SY-CPAGE LEFT-JUSTIFIED.
* SY-STARO is the number of the topmost actual list line displayed
* on the current page.
WRITE: / 'SY-STARO:', SY-STARO LEFT-JUSTIFIED.
SKIP.
* SY-STACO is the number of the first displayed column on the
* screen. Scroll the list right with the scrollbar to test it
WRITE: / 'SY-STACO:', SY-STACO LEFT-JUSTIFIED.
SKIP.
* contents of the selected line
WRITE: / 'SY-LISEL:', SY-LISEL.
System fields V
Program code
REPORT ZBCTCB93 NO STANDARD PAGE HEADING.
PARAMETERS: TEST.
DATA: SESSION TYPE I.
DATA: BEGIN OF T_TSTCT OCCURS 10.
INCLUDE STRUCTURE TSTCT.
DATA: END OF T_TSTCT.
DETAIL.
SESSION = SY-MODNO + 1.
SET MARGIN 5 3.
* The report must have a selection screen and from there execute+print
* should be called the SET MARGIN to take effect.
WRITE: / 'Number of this session:', SESSION.
WRITE: / 'List starts from the ', SY-MACOL, ',', SY-MAROW, 'upper-left
corner.'.
449
SKIP.
WRITE: / 'This is the', SY-FDAYW, '. workday of the week.'.
APPEND T_TSTCT.
APPEND T_TSTCT.
APPEND T_TSTCT.
DESCRIBE TABLE T_TSTCT.
WRITE: / 'Line width of internal table: 1 (lang) + 4 (tcode) + 36 (text) =', SY-
TLENG.
WRITE: / 'OCCURS parameter:', SY-TOCCU.
WRITE: / 'Number of entries in internal table:', SY-TFILL
System fields I
Program code
REPORT ZBCTCB93 NO STANDARD PAGE HEADING.
DETAIL.
WRITE: /5 'Logon name of the user: ' RIGHT-JUSTIFIED, 40 SY-UNAME.
WRITE: /5 'Logon client: ' RIGHT-JUSTIFIED, 40 SY-MANDT.
WRITE: /5 'Logon language: ' RIGHT-JUSTIFIED, 40 SY-LANGU.
WRITE: /5 'Current date: ' RIGHT-JUSTIFIED, 40 SY-DATUM.
WRITE: /5 'Current time: ' RIGHT-JUSTIFIED, 40 SY-UZEIT.
WRITE: /5 'Current transaction: ' RIGHT-JUSTIFIED, 40 SY-TCODE.
WRITE: /5 'Main program: ' RIGHT-JUSTIFIED, 40 SY-CPROG.
SKIP.
WRITE: /5 'SAP System ID: ' RIGHT-JUSTIFIED, 40 SY-SYSID.
WRITE: /5 'SAP Release: ' RIGHT-JUSTIFIED, 40 SY-SAPRL.
WRITE: /5 'Host: ' RIGHT-JUSTIFIED, 40 SY-HOST.
WRITE: /5 'Operating system: ' RIGHT-JUSTIFIED, 40 SY-OPSYS.
WRITE: /5 'Database system: ' RIGHT-JUSTIFIED, 40 SY-DBSYS.
SKIP TO LINE 20. POSITION 10.
WRITE: SY-COLNO, ',', SY-LINNO, 'Cursor position (column, row).'.
450
WRITE: 'New:', SY-COLNO,',',SY-LINNO.
SKIP.
SY-ULINE = '------ Underline ------'.
ULINE (23).
WRITE: /5 'Vertical bar:', SY-VLINE.
TOP-OF-PAGE.
DETAIL.
WRITE: 2 'Report Title: ', SY-TITLE(20).
WRITE: 'Page Number: ', SY-PAGNO.
SKIP
System fields IV
Program code
REPORT ZBCTCB99 NO STANDARD PAGE HEADING.
PARAMETERS: TEST.
DETAIL.
IF SY-BATCH EQ SPACE.
WRITE: / 'Report was started on-line'.
WRITE: / 'Using variant:', SY-SLSET.
ELSE.
WRITE: / 'Report was started in background'.
ENDIF.
System fields VI
SY-DATAR
In transaction programming this field indicates the change of data on the
screen. In the PBO part you may set default values of the input fields of the
dynpro. In the PAI part you can check if they were changed. If SY-DATAR is
set, then the user has modified or entered new data on the screen.
SY-BINPT
451
This field indicates if the transaction was called in a Batch Input session or by
an online user.To test it, a batch input session must be created. From Release
3.1g the next procedure can be used.
 Create a report which displays this system field
 Create a Transaction code for this report
 Use transaction SHDB to record a the previous transaction
 Press the Overview button and choose the 'generate
program' function.
 Running the previously generated program it will create a
Batch Input session
 Now call transaction SM35 and process the created Batch
Input in foreground. It should display an 'X' for system
field SY-BINPT.
SY-CALLD
This field indicates if the transaction was called from another transaction.
 Create a report which displays this system field
 Create a Transaction code for this report
 Create a new report containing the next ABAP command:
CALL TRANSACTION tcode. Where tcode is the
Transaction code you created. When you run this report, it
should display an 'X' for system field SY-CALLD.
System fields VIII
REPORT ZZBETO98.
PARAMETERS: PARAM(6) DEFAULT 'TEST'.
WRITE: / 'System variables for printing.'.
WRITE: / 'Please check the spool for the printout'.
SKIP.
* check is necessary to prevent further recursive calls of this program.
IF NOT ( SY-PDEST IS INITIAL ).
SKIP.
WRITE: / 'System variables for printing:'.
SKIP.
WRITE: / ' Layout: SY-PAART',SY-PAART.
* This can be used in normal lists as well.
* If used with 'new-page print on', it continues counting
WRITE: / ' Current page number: SY-PAGNO', SY-PAGNO.
WRITE: / ' Printer: SY-PDEST', SY-PDEST.
452
WRITE: / ' Priority: SY-PEXPI', SY-PEXPI.
WRITE: / ' List name: SY-PLIST', SY-PLIST.
WRITE: / ' Department: SY-PRABT', SY-PRABT.
* output cover sheet with the report's parameters
WRITE: / ' Output cover sheet: SY-PRBIG', SY-PRBIG.
WRITE: / ' No. of copies: SY-PRCOP', SY-PRCOP.
WRITE: / ' Dataset name: SY-PRDSN', SY-PRDSN.
WRITE: / ' Print immediately: SY-PRIMM', SY-PRIMM.
WRITE: / ' New list: SY-PRNEW', SY-PRNEW.
* Receiver must be a valid user-id
WRITE: / ' Receiver: SY-PRREC', SY-PRREC.
WRITE: / ' Delete after output: SY-PRREL', SY-PRREL.
WRITE: / ' Cover text: SY-PRTXT', SY-PRTXT.
EXIT.
ENDIF.
SUBMIT ZZBETO98 TO SAP-SPOOL
DESTINATION 'ST03'
COPIES 3
LIST NAME 'NEWLIST'
LIST DATASET 'TESTLIST'
COVER TEXT 'Test of system variables'
LIST AUTHORITY 'BASIS'
IMMEDIATELY ' '
KEEP IN SPOOL 'X'
NEW LIST IDENTIFICATION 'X'
DATASET EXPIRATION '8'
LINE-COUNT 90
LINE-SIZE 120
LAYOUT 'X_90_120'
SAP COVER PAGE 'X'
COVER PAGE 'X'
RECEIVER 'SAP*'
DEPARTMENT 'DEP.'
WITHOUT SPOOL DYNPRO.
System fields VII
Program code
REPORT ZSYSTEM.
* You must click on a row to see results.
DATA: L_SROW TYPE I VALUE 10.
DATA: L_SCOL TYPE I VALUE 15.
453
DATA: L_EROW TYPE I VALUE 20.
DATA: L_ECOL TYPE I VALUE 70.
WRITE: / ' Initial values: '.
WRITE: / ' SY-WINX1:', SY-WINX1.
WRITE: / ' SY-WINX2:', SY-WINX2.
WRITE: / ' SY-WINY1:', SY-WINY1.
WRITE: / ' SY-WINY2:', SY-WINY2.
AT LINE-SELECTION.
WINDOW STARTING AT L_SCOL L_SROW ENDING AT L_ECOL
L_EROW .
WRITE: / ' Values are from the upper left corner of the window.'.
SKIP.
WRITE: / ' After displaying the new window: '.
SKIP.
WRITE: / ' SY-WINX1:', SY-WINX1, '(Column of the left side)'.
WRITE: / ' SY-WINX2:', SY-WINX2, '(Column of the right side)'.
WRITE: / ' SY-WINY1:', SY-WINY1, '(Row of the upper side)'.
WRITE: / ' SY-WINY2:', SY-WINY2, '(Row of the lower side)'.
454

More Related Content

PDF
Beginner’s guide to sap abap 1
PPT
Ab1011 module pool programming
PPT
Alv theory
PPT
Call transaction method
PPTX
Sap abap-data structures and internal tables
PPT
SAP ABAP - Needed Notes
PDF
Bapi step-by-step
PPT
ABAP Open SQL & Internal Table
Beginner’s guide to sap abap 1
Ab1011 module pool programming
Alv theory
Call transaction method
Sap abap-data structures and internal tables
SAP ABAP - Needed Notes
Bapi step-by-step
ABAP Open SQL & Internal Table

What's hot (20)

PPT
ABAP Programming Overview
PPT
Introduction to ABAP
DOC
1000 solved questions
PPT
Sap abap part1
PPT
abap list viewer (alv)
PPTX
SAP Modularization techniques
PDF
Ooabap notes with_programs
PPT
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
PDF
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
PPTX
Bdc BATCH DATA COMMUNICATION
PPTX
Reports
DOC
Sap abap interview questions
PDF
Abap reports
PPTX
SAP Adobe forms
PDF
Sap Abap Reports
PPT
BATCH DATA COMMUNICATION
PDF
Sp rao abap
PDF
Abap object-oriented-programming-tutorials
PPT
ABAP Object oriented concepts
PPT
List Processing in ABAP
ABAP Programming Overview
Introduction to ABAP
1000 solved questions
Sap abap part1
abap list viewer (alv)
SAP Modularization techniques
Ooabap notes with_programs
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
500+ SAP ABAP INTERVIEW QUESTIONS WITH ANSWERS
Bdc BATCH DATA COMMUNICATION
Reports
Sap abap interview questions
Abap reports
SAP Adobe forms
Sap Abap Reports
BATCH DATA COMMUNICATION
Sp rao abap
Abap object-oriented-programming-tutorials
ABAP Object oriented concepts
List Processing in ABAP
Ad

Viewers also liked (20)

PDF
Exercise in alv
PDF
WEBDYPRO ABAP WITH DETAILED NOTES
DOC
Step by step guide to basic web dynpro abap
PDF
Epic abap
PDF
IGROWSOFT abap material
PDF
Sap sapscripts tips and tricks
PDF
Smartforms interview questions with answers
PDF
Crm technical
PDF
Introducing enhancement framework.doc
PPS
Abap web dynpro
DOC
Scenario on business transaction events
PDF
Sap script made easy
PPT
Oo abap-sap-1206973306636228-5
PDF
Webdynpro by vijayender_reddy
DOC
SAP ABAP Material
DOC
Badi document
PDF
SAP ABAP data dictionary
PPTX
SAP ABAP using OOPS - JH Softech
PDF
Version it satya_dev
PDF
Data binding
Exercise in alv
WEBDYPRO ABAP WITH DETAILED NOTES
Step by step guide to basic web dynpro abap
Epic abap
IGROWSOFT abap material
Sap sapscripts tips and tricks
Smartforms interview questions with answers
Crm technical
Introducing enhancement framework.doc
Abap web dynpro
Scenario on business transaction events
Sap script made easy
Oo abap-sap-1206973306636228-5
Webdynpro by vijayender_reddy
SAP ABAP Material
Badi document
SAP ABAP data dictionary
SAP ABAP using OOPS - JH Softech
Version it satya_dev
Data binding
Ad

Similar to Sap abap material (20)

DOC
Abap faq
PPTX
Sap abap
PDF
Ijebea14 228
PPTX
Sap abap
PPTX
Sap abap database table
PPT
Implementing the Database Server session 01
PDF
ABAP FAQ S On Reports Scripts BDC Dialogs ABAP Reporting SAP TERMINOLOGY
DOC
Ab ap faq
PPTX
Data concepts
PPTX
SKILLWISE-DB2 DBA
DOCX
RELATIONAL DATABASE PURPOSE OF DATABASE SYSTEM
DOCX
Database Concepts
PDF
23246406 dbms-unit-1
PPTX
Introduction to Database Management Systems (DBMS)
PPT
Data_Dictionary of sap abap known as DDIC.ppt
PPTX
Introduction to database
PPTX
DATABASE MANAGEMENT SYSTEMS CS 3492.pptx
PDF
oracle intro
PPTX
Database Management System
PPTX
Introduction to database
Abap faq
Sap abap
Ijebea14 228
Sap abap
Sap abap database table
Implementing the Database Server session 01
ABAP FAQ S On Reports Scripts BDC Dialogs ABAP Reporting SAP TERMINOLOGY
Ab ap faq
Data concepts
SKILLWISE-DB2 DBA
RELATIONAL DATABASE PURPOSE OF DATABASE SYSTEM
Database Concepts
23246406 dbms-unit-1
Introduction to Database Management Systems (DBMS)
Data_Dictionary of sap abap known as DDIC.ppt
Introduction to database
DATABASE MANAGEMENT SYSTEMS CS 3492.pptx
oracle intro
Database Management System
Introduction to database

More from Kranthi Kumar (20)

PDF
Dynamic binding
PDF
Creating simple comp
PDF
Creating messages
PDF
Creating a comp
PDF
Controllers and context programming
PDF
Context at design
PDF
Binding,context mapping,navigation exercise
PDF
Alv for web
PDF
Web(abap introduction)
PDF
control techniques
PPT
Chapter 07 debugging sap scripts
PPT
Chapter 06 printing sap script forms
PPT
Chapter 05 sap script - configuration
PPT
Chapter 04 sap script - output program
PPT
Chapter 02 sap script forms
PPT
sap script overview
PPT
Batch input session
DOCX
Using folder options for page protection
PPT
Business workflow
PPT
07 sap scripts
Dynamic binding
Creating simple comp
Creating messages
Creating a comp
Controllers and context programming
Context at design
Binding,context mapping,navigation exercise
Alv for web
Web(abap introduction)
control techniques
Chapter 07 debugging sap scripts
Chapter 06 printing sap script forms
Chapter 05 sap script - configuration
Chapter 04 sap script - output program
Chapter 02 sap script forms
sap script overview
Batch input session
Using folder options for page protection
Business workflow
07 sap scripts

Sap abap material

  • 2. 2 Sap architecture  If you use the possibilities of the distributed R/3 system according to the client/server methodology, then the R/3 components are spread across a three-tier CPU hierarchy. The database server is installed on a central computer, which means the processes representing the database service run here. This computer also houses at least the R/3 update service, that is, this CPU is responsible for all database changes. Multiple application servers can be connected to the dabase server. The application servers process the actual application logic. Multiple front-ends (workstation, PC) on which the users are working can then connect to each application server. The individual front-ends handle all presentation tasks.  SAP AG Central DB (stores all data and application programs) R/3 Client/Server – Three-Level Computer Hierarchy User interaction Application logic Database update Central DB buffer Input data from the user Output data to the user Read database and update buffers Object- oriented change requests (asynchronous)
  • 3. 3  R/3 Basis configurations: A: Central system with centrally installed presentation software B: Two-tier client/server system with distributed presentation software C: Two-tier client/server system; presentation and application run on the same computer D: Three-tier client/server system; presentation, application, and database each run on their own computer  The central process of the application server is the SAP dispatcher as central control. The SAP dispatcher, together with the specific operating system, manages the resources for the R/3 applications  The main tasks of the dispatcher include:  S A P A G R / 3 C l i e n t / S e r v e r C o n f i g u r a t i o n s T h r e e - t i e r c l i e n t / s e r v e r D i s t r i b u t e d p r e s e n t a t i o n T w o - t i e r c l i e n t / s e r v e r S A P R / 3 S y s t e m P r e s e n t a t i o n A p p l i c a t i o n D a t a b a s e C e n t r a l s y s t e m  SAP AG The SAP Dispatcher Presentation Application Buffer Database Communication SAPGUISAPGUI SAPGUISAPGUI Work process Work process Work process Dispatcher
  • 4. 4 evenly distributing the transaction load among the work processes, interfacing with the presentation level, organizing the communication activities.  The dispatcher carries out the following tasks during initialization reading profile parameters, creating and initializing semaphores, generating roll areas, starting work processes, logging on to the message server.  The user entries on the screen are received by the SAP presentation program SAPGUI which converts it into its own format and sends it to the dispatcher.  The dispatcher manages the information exchange between the SAPGUI and the work processes, whereby all users share a few work processes.  The dispatcher first stores the processing requests in request queues and then processes them.  The dispatcher dispatches the requests one after the other to free work processes. The actual processing is done by the work processes.  At end of processing, the dispatcher returns the results of a work process back to the SAPGUI who interprets the data and generates the output screen.  SAP AG Dialog Step Dataflow Application Presentation Database Relational database system Request queues SAPGUI ROLL 222 444 555 Terminal process Dialog object 333 666 111 777 Work process
  • 6. 6 Table Types DATA BASE : Store the data base permanently until deleted. These tables are classified into 3 types 1.) Transparent Table 2.) Pooled Table 3.) Clustered Table
  • 7. 7 Transparent Table: Exists with the same structure both in dictionary as well as in database exactly with the same data and fields. Pooled Table: Pooled tables are logical tables that must be assigned to a table pool when they are defined. Pooled tables are used to store control data. Several pooled tables can be combined in a table pool. The data of these pooled tables are then sorted in a common table in the database. EG: All Condition tables i.e., Annn tables (pricing/discounts etc.,) belong to the table Pool KAPOL (Condition Pool) as the underlying concept is same across different condition tables, but, they have different Key (primary) fields. Cluster Table: Cluster tables are logical tables that must be assigned to a table cluster when they are defined. Cluster tables can be used to store control data. They can also be used to store temporary data or texts, such as documentation. EG: Accounting Document Segment (Line Item records) BSEG is a cluster table that belongs to the table cluster RFBLG. Also, other tables such as BSEC, BSED, BSES, BSET also come under the same table cluster as all of them possess the common Key i.e., BUKRS/BELNR/GJAHR. And CDPOS (CDCLS) BSEC - One-Time Account Data Document Segment, BSED- bill of exchange Fields Document Segment BSEG-Accounting Document Segment, BSES-Document Control Data, BSET-Tax Data Document Segment Pooled and Cluster Tables Differences Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables. A table pool or table cluster should be used exclusively for storing internal control information (screen sequences, program parameters, temporary data, continuous texts such as documentation). All data of commercial relevance is stored exclusively in transparent tables! Table Pools A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool. The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument field (Vardata). A pool has the following structure: Field Data type Meaning Tabname CHAR(10) Name of pooled table Varkey CHAR (n) Contains the entries from all key fields of the pooled table record as a string, max. length for n is 110 Dataln INT2(5) Length of the string in Vardata
  • 8. 8 Vardata RAW (n) Contains the entries from all data fields of the pooled table record as a string, max. length n depends on the database system used If a pooled table record is saved, it is stored in the table pool assigned. The name of the pooled table is written to the field Tabname. The contents of all key fields of the pooled table are written as a string to field Varkey and the contents of all data fields as a string to field Vardata. The length of the string stored in Vardata is entered in field Dataln by the database interface Due to the structure of a table pool, there are certain restrictions on the pooled tables assigned to it. The name of a pooled table may not exceed 10 characters. Since Varkey is a character field, all key fields of a pooled table must have character data types (for example, CHAR, NUMC, CLNT). The total length of all key fields or all data fields of a pooled table must not exceed the length of the Varkey or Vardata field of the assigned pool. Table Clusters Several logical data records from different cluster tables can be stored together in one physical record in a table cluster. A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are created. Control information on the structure of the data string is still written at the beginning of the Vardata field. A table cluster has the following structure: Field Data type Meaning CLKEY1 * First key field CLKEY2 * Second key field ... ... ... CLKEYn * nth key field
  • 9. 9 Pageno INT2(5) Number of the continuation record Timestamp CHAR(14) Time stamps Pagelg INT2(5) Length of the string in Vardata Vardata RAW (n) Contains the entries from the data fields of the assigned cluster tables as a string, max. length n depends on the database system used The records of all cluster tables with the same key are stored under one key in the assigned table cluster. The values of the key fields are stored in the corresponding key fields of the table cluster. The values of all data fields of the assigned cluster tables are written as a string to the Vardata field of the table cluster. Besides the actual data values, the data string contains information on the structure of the data and which table it comes from. If the string exceeds the maximum length of the Vardata field, a continuation record is written with the same key values. The continuation records for a key are distinguished by their value in field Pageno. The actual length of the string in the Vardata field is stored in the Pagelg field by the database interface. You need the structural information stored in the ABAP Dictionary to read the data from a pooled table or cluster table correctly. These tables can therefore only be processed using Open SQL with the cluster interface, and not with Native SQL directly in the database.
  • 10. 10 Transparent Pool Cluster Contain a single table. Used to store master data They are used to hold a large number of very small tables(stores customizing data or system data) They are used to hold data from a few number of large tables.(stores system data) It has a one-to-one relationship with a table in the database It has a many-to-one relationship with a table in the database It has a many-to-one relationship with table in the database For each transparent table there is one associated table in the database It is stored with other pooled tables in a single table called table pool in the database Many cluster tables are stored in a single table in the database called a table cluster The database table has the same name, same number of fields and the fields have the same names The database table has different name, different number of fields and fields have different names The database table has different name, different number of fields and fields have different names There is only a single table Table pools contain more tables than table clusters Contains less tables than table pools Single table can have one or more primary key Primary key of each table does not begin with same fields or fields Primary key of each table begins with same fields or fields Secondary indexes can be created Secondary indexes cannot be created Secondary indexes cannot be created They can be accessed using open and native SQL They can be accessed using open SQL only They can be accessed using open SQL only USE: They are used to hold master data e.g. Table vendors or table of customers. Example of transaction data is orders placed by customers USE: They reduce the amount of database resources needed when many small tables have to be opened at the same time USE: They would be used when the tables have primary key in common and data in these tables are all accesses simultaneously
  • 11. 11 IMPORTANT CONTROL PROPERTIES OF TABLE 1) Delivery class: The delivery class controls the transport of table data when installing or upgrading, in a client copy and when transporting between customer systems. The delivery class is also used in the extended table maintenance. Example A: Application table (master and transaction data). C: Customer table, data is maintained by the customer only. L: Table for storing temporary data. 2.) Data class in technical settings: The data class defines the physical area of the database (for ORACLE the TABLESPACE) in which your table is logically stored. If you choose a data class correctly, your table will automatically be assigned to the correct area when it is created on the database. Important table spaces are:-  APPL0 --- Master data  APPL1 --- Transaction data  APPL2 --- Organizational and customizing data 3.) Size category: The size category determines the probable space requirement for a table in the database.(0 to 9). Example: If size category 0 means 100 records. Then as a group sap stores a max of 100 records. If this is filed one more space equivalent to 100 records will be allocated Note: if we store the records in too many places retrieving the records will be slower, so choose appropriate size category 4.) Display Maintenance:
  • 12. 12 This property Defines if the user can manipulate / Display the data directly on the table level  Allowed :- the user can directly manipulate(Create / Modify) directly on the table.  with Restriiction:- The user is not allowed to manipulate but he can only display .  Not Allowed:- The user can not manipulate or display the records. The separate program should control the display and manipulation. 5.) Buffering status: Buffering specifies whether the records 1.) Buffering not allowed, 2.)Buffering allowed but not activated and 3.) Buffering Switched on. Single-record buffering With this kind of buffering, only the records of a table which are actually accessed are loaded into the buffer. This kind of buffering requires less storage space in the buffer than full buffering. However, greater organization is necessary and considerably more database accesses are necessary for loading. ABAP Program Select Query Database interface R/3 Database table buffer Database buffer Application Server Database Server Database Fig.1. Database Table buffering
  • 13. 13 If an as yet unbuffered record is accessed with SELECT SINGLE, a database access occurs to load the record. If the table does not contain a record for the specified key ('no record found'), this record is noted as nonexistent in the buffer. If a further attempt is made to access this record, a renewed database access can be avoided. When should single-record buffering be selected?  For large tables where there are frequent single-record accesses (with SELECT SINGLE ...). The size of the records being accessed should be between 100-200 KB.  For comparatively small tables for which the access range is large, it is normally advisable to opt for full buffering. Only one database access is required to load such a table for full buffering, whilst single-record buffering calls for a very large number of table accesses. Generic buffering In a read access to a record of a generically buffered table, all the records whose left-justified part of the key (generic area) corresponds are loaded into the buffer. If this type of buffering is selected, the generic area must be defined by specifying a number n of key fields. The first n key fields of the table then define the generic key. The number of key fields to be entered must lie between 1 and the number of key fields -1. For example, only values between 1 and 5 are permitted for a table with 6 key fields. When should generic buffering be selected?  A table should be buffered generically if usually only certain areas of the table are required. The individual generic areas are treated like independent tables which are fully buffered. Please also read the text about full buffering.  The generic key area should be selected so that the generic areas are not too small to prevent too may generic areas being produced. If there are only a few records per generic area, it is more efficient to use full buffering.  Generic buffering only makes sense if the table is accessed by a specified generic key. If, when an access takes place, a field of the generic key is not supplied with a value, the buffer is ignored and the records are read directly from the database.  Language-specific tables are an example of a good use of generic buffering (with the language key field as generic key area). Full buffering With full buffering, either the complete table or none of the table is in the buffer. If a read access is made to a record, all records of the table are transferred to the buffer. When should you select full buffering?
  • 14. 14  For tables up to 30 KB in size. If a table is accessed frequently, but all accesses are read accesses, this value can be exceeded.  For larger tables where large numbers of records are frequently accessed. However, if the application program is able to formulate an extremely selective WHERE condition using a database index, it may be advisable to dispense with full buffering.  For tables with frequent accesses to data not contained in the table. Since all records are contained in the buffer, a quick decision can be made as to whether or not the table contains a record for a specific key. When considering whether a table should be fully buffered, you should take three aspects into account: the size of the table, the number of read accesses, and the number of write accesses. Tables best suited to full buffering are small, frequently read, and rarely updated. Buffering of database tables is a technique in which the data from database table is copied into the local storage place in application server, known as buffers. Hence the subsequent requests for data is instead fetched from the buffered tables rather than actually accessing the database tables. This in turn increases the performance by reducing the database hit time. Database table buffering: For the first time when data from a DB Table is requested, database interface hit the database to fetch the data. However if the table is buffered one then the data from the table is filled into the buffer also. Hence for all subsequent requests of data from the same table the data is fetched from buffer. Limitations: Only transparent table and pooled tables can be buffered. Clustered tables can not be buffered. The key fields of the buffered tables need to be mapped to one of the ABAP types C, N, D or T. Table buffering types: Three types of buffering are allowed for any table.  Full table Buffering.  Generic Buffering with no of keys  Single record Buffering Implementing Table buffer Different types of buffering are explained with example below:
  • 15. 15 Full table Buffering: Full table buffering as the name suggest is to get all the data of a table into the buffer space. When a SELECT statement is executed on the given table for the first time it hits the database to get the data and also fills the table buffer in the application server. But all the select statements requesting the data from this table will fetch it from the buffer. Example: Fig.2. the table ZZZ_EMP_PROJ Let the table zzz_emp_proj be a database table that is not buffered. Then for the select query of simple type that selects all the values from this table will directly hit the database to fetch the data. The following SQL trace list shows how much duration it takes to get the data from the database. Fig.3. SQL trace list showing database fetch time when table is not buffered
  • 16. 16 Now let us change the technical settings of the table to Full Table Buffering. Then for all the select statements which do a select on the table zzz_emp_proj we will have the following characteristics, i.e. for the first time it will fetch from the database. Then it will buffer the whole table data, so for subsequent requests data is fetched from the buffer. That reduces the fetch time drastically. We can see from bellow screen shot of the SQL trace list the yellow lines are for database hit. The rest are within application server only. Fig.4. Technical Setting for Full Table Buffer Fig.5. SQL Trace showing the duration of select statement executed first time in a fully buffered table
  • 17. 17 Fig.6. SQL trace showing data fetched from buffer for subsequent select statement
  • 18. 18 Full buffering is preferred in the following cases.  If a table is accessed frequently for read purpose mostly then it is advisable to go for full table buffering  If a table is accessed more often to check whether an entry is available or not, those kinds of tables could be fully buffered so that it will be checked in the buffer without going into the database  Primarily small tables with frequent read access and with very less probability of written on to, are best suited for full table  SAP suggests tables of size below 30 KB should be fully buffered. However this could be applied to larger tables depending on number of read and write attempt.  Sometimes it is also advisable to avoid buffers if a well formulated WHERE statement could be written based on the indices of the db table. Generic table Buffering: When a table is buffered generically based on certain keys then the records containing the given values for these keys are copied into the buffer. So for those select statements with fully specified generic keys it gets the data from Buffer. If the key is not assigned a value in the select statement then the statement will bypass the buffer and select it from the database. It is always an important factor to decide the key of generic buffering. If we chose a key with small variation then while buffering large amount of data will come into the buffer. This in turn will increase the fetch time of data. Example: Let us again take the same database table zzz_emp_proj and which is buffered generically on the first key that is project. Fig.7. Here we can see the table we used for our example for full table buffering zzz_emp_proj. This table will get buffered totally as we have maintained full table buffer in the technical settings of this table
  • 19. 19 Fig.8. Table is Generic Area buffered with no of key fields 1 Then for the select query with certain value of project it will select those part of data for which the key contains the given value from database and put them in buffer. For all subsequent queries where the key value does not change it will go to the same place and get the data without hitting the database. Suppose we select all entries from this table zzz_emp_proj where project is ‘DCSAPMNT’ and location is ‘Bangalore’ then it gets the data from database for the first time and populate the buffer with the values where project is ‘DCSAPMNT’. As we have maintained the technical settings of this table as ‘generic buffer with no of keys 1’. Hence for next time whenever it goes to get the data with the same key value it will be fetched from the buffer itself Hence you can see the difference of time in following two screen shots. Fig.9. data that will be buffered for the given table
  • 20. 20 Fig.10. Shows the db hit time for execution of select for the first time Fig.11. Shows the decrease in total duration for fetch data as it is being fetched from buffer. From these two SQL trace list above we can understand how drastically the fetch time decreases if fetched from the buffer. The yellow lines indicate the database hit and light blue lines indicates that the data is fetched from buffer.
  • 21. 21 Single record Buffering: Single record buffering will buffer only one record in the application server. Hence for the first selection statement it buffers the records selected. And in case of subsequent selections it gets the value from the buffer. If you change the select query in order to get some different lines then it will fetch the data from database. Similarly if the select query selects more than one line then the buffer is overlooked and data is fetched from the database table. Example: The select query selecting one record from table zzz_emp_proj which is not buffered presently. Fig.12. example of data selected in table for single record buffering Fig.13. Technical settings for single record buffering
  • 22. 22 Fig.14- zzz_emp_proj table Without Buffering. Fig.15. after buffering first time selection Fig.16. After buffering subsequent time selection data fetched from buffer. These SQL trace lists show how the duration has decreased in the buffering of the table. Technically single-record buffer contains central administrative structure, a table directory and the data area. The table names are stored in alphabetical order and the data area is organized in frames of fixed size. While searching the buffer a binary search is done in the table directory then in the corresponding frames to get the records. Single record buffering also stores information about the nonexistent record of database table, by using a flag. So single record buffering is advisable when again and again we are accessing nonexistent records of data base. However depending upon our requirement we can chose our buffering so that it will increase the performance of the program as a whole.
  • 23. 23
  • 24. 24 Synchronization Issue: The buffer is present in the application server. The data is copied into the buffer and for subsequent selection it fetches the data from this storage. However any modification to the database has to be reflected onto these buffers in application servers. Therefore we have following two ways in which the buffer is synchronized. Synchronous scenario: Whenever the database is updated corresponding to some buffered table it floods the information across the applications servers those have buffered the values of tables. This might lead to inconsistency of the data as this process is highly dependant on the network’s reliability. Asynchronous Scenario: the data is modified in the database table but is not updated to the corresponding buffers in the application server. However a table DDLOG in the central database is updated with these modifications. The application servers holding the buffers poll at this table in certain time intervals. If it finds the modification in the given table relevant to its buffers then it clear the corresponding buffer. So next time the select query executes the data is fetched from the database table and buffered. Avoiding Buffer: In certain cases we might need to avoid buffers and directly fetch the data from database table which might be more time effective. The following select queries do not make use of the buffer even if the corresponding table is buffered. i. SELECT... BYPASSING BUFFER ii. SELECT with aggregate function (COUNT, MIN, MAX, SUM, AVG) iii. SELECT DISTINCT iv. SELECT... WHERE... IS NULL v. ORDER BY (with the exception of PRIMARY KEY) vi. SELECT FOR UPDATE vii. All access through the Native SQL also by pass the buffer
  • 25. 25 Domain: A domain describes the technical attributes of a field, such as the data type or the number of positions in a field. The domain defines primarily a value range describing the valid data values for the fields referring to this domain. Different technical fields of the same type can be combined in a domain. Fields referring to the same domain are changed at the same time when a domain is changed. This ensures the consistency of these fields. Data elements : (elementary types) Elementary types have no structure. They describe the data type attributes (such as given Dictionary data type, number of places) and information that is relevant for the screen (such as title) of unstructured data objects (variables/fields). Creation of Transparent Table 1. Enter the table name and press Create 2. Enter the description, Delivery class and check on table maintenance allowed. Then click on the tab Fields.
  • 26. 26 3. Enter the ZCHAR in fields tab and ZCHAR_DE in field type tab. 4. Double click on ZCHAR_DE. Then it will ask for Save. Press ‘YES”.
  • 27. 27 5. Save it as a local object on pressing Local object button 6. Now it will ask for the creation of the data element. Press Yes.
  • 28. 28 7. Click on the Field label tab and enter the lengths and descriptions accordingly. 8. Then press Definition tab and enter the domain.
  • 29. 29 9. Double click on that zchar_d to create domain, then it will ask for save before going next screen. Press Yes. 10. Save it as a local object.
  • 30. 30 11. Now it will ask for domain creation. Press Yes. 12. Give short description for that domain which you are creating. And mention the data type in data type field and length in no. characters field an press ENTER.
  • 31. 31 13. Then press Ctrl+F3. It will ask for save before activation. Save it as a local Object. 14. Press Enter.
  • 32. 32 15. Then the following screen appears. Press on back button. 16. Press Ctrl+F3. You will get the following screen. Press Back button.
  • 33. 33 17. You will get the following screen.
  • 34. 34 18. Create one more field ZNUM and give data element name as ZNUM_DE. And double click on ‘ZNUM_DE’ 19. Save it by pressing Yes. 20. Now it will ask for the data element creation. Press Yes. 21. Give short description of the data element. And give the lengths and field labels accordingly in Field label tab.
  • 35. 35 22. Press on Definition tab and give the domain name in Domain field. Double click on ZNUM_D. 23. It will ask for save. Press Yes.
  • 36. 36 24. Save it as a local Object. 25. Now it asks for Domain creation. Press Yes. 26. Give short description in short text field. Enter the data type and no. characters, Press Enter. Then Press on Activate button or Press Ctrl+F3.
  • 37. 37 27. Save this as a local object. 28. Press enter.
  • 38. 38 29. Now you will get the following screen. Press Back button.
  • 39. 39 30. Activate the data element By pressing Activate button or Pressing Ctrl+F3. 31. Press enter.
  • 40. 40 32. Press Back button.
  • 41. 41 33. Now we created two fields. And Data elements and Domain for these two fields. Now we have to maintain the technical settings. Press on Technical settings button.
  • 42. 42 34. Give the data class and size category of the table as per the requirement. And press the back button. 35. Now activate the table by pressing the activate button or CTRL+F3. 36. Press enter.
  • 43. 43 37. Now you will get the following screen.
  • 44. 44 38. Now enter the data into table. Go to Utilities Table contents  Create Entries. 39. Now enter the data in the fields and Save it.
  • 45. 45 40. You will get the following screen after clicking the Reset Button. 41. Enter the data for the second entry into the table. 42. Save it and press reset.
  • 46. 46 43. You will get the following screen. 44. Again enter the data for the third entry.
  • 47. 47 45. Press save, Reset (Optional) and Back button. 46. Now you will get the following screen.
  • 48. 48 47. To see the table contents go to Utilities  Table contents  Display. Or press Ctrl+Shift+F10. 48. You will get the following screen.
  • 49. 49 49. Press on run button or press F8. Now it will display the table contents. Creation of a table pool and pool table Step 1: Go to transaction SE11. Go to Utilities  Other Dictionary Objects
  • 50. 50 Step 2: Select Radio button Table pool/Cluster Give table Pool Name: ZTBL_POOL. Then press F5 or choose Create. Step 3: Then Select Radio button Table Pool. Press Enter.
  • 51. 51 Step 4: Then you go to maintain Poll Screen there give Short Description. Step 5: Then go to Technical settings.
  • 52. 52 Step 6: In the “Maintain technical Settings” screen Provide Size category. Save and activate the table Pool. Go back to SE11. Step 7: Go to SE11 ABAP Dictionary: Initial Screen. Create a Z table.
  • 53. 53 Step 8: Maintain Delivery and Maintenance attributes for the Z table. Add fields to the Z table. Maintain Technical settings and Enhancement Category.
  • 54. 54 Step 9: Then Go to Extras Change table category Step 10: Choose Table type. In our Example it is Pooled table.
  • 55. 55 Step 11: Go back to Delivery and Maintenance tab and provide Pool/Cluster value. We have successfully created Table pool and Pooled table.
  • 57. 57 VIEW: Is a imaginary database which does not really exist  Projection View Database View  Maintenance View Help View  Database View (SE11) Database views are implement an inner join, that is, only records of the primary table (selected via the join operation) for which the corresponding records of the secondary tables also exist are fetched. Inconsistencies between primary and secondary table could, therefore, lead to a reduced selection set. In database views, the join conditions can be formulated using equality relationships between any base fields. In the other types of view, they must be taken from existing foreign keys. That is, tables can only be collected in a maintenance or help view if they are linked to one another via foreign keys.
  • 58. 58  Help View ( SE54) Help views are used to output additional information when the online help system is called. When the F4 button is pressed for a screen field, a check is first made on whether a matchcode is defined for this field. If this is not the case, the help view is displayed in which the check table of the field is the primary table. Thus, for each table no more than one help view can be created, that is, a table can only be primary table in at most one help view.  Projection View Projection views are used to suppress or mask certain fields in a table (projection), thus minimizing the number of interfaces. This means that only the data that is actually required is exchanged when the database is accessed. A projection view can draw upon only one table. Selection conditions cannot be specified for projection views.  Maintenance View ( SE54 ) Maintenance views enable a business-oriented approach to looking at data, while at the same time, making it possible to maintain the data involved. Data from several tables can be summarized in a maintenance view and maintained collectively via this view. That is, the data is entered via the view and then distributed to the underlying tables by the system. Creating a projection view:- We use projection view to mask unwanted fields and display only relevant fields in a table. Basically View acts like a database table only, the difference is view will not occupy storage space. 1. Creating Projection View
  • 59. 59 2. Choose Projection View in the pop up which appears when you click on create 3. Give Description & base Table name(In this example we have taken KNA1)
  • 60. 60 4. After giving table name click on Table fields button 5. Choose the fields which you want to be displayed in output and click copy
  • 61. 61 6. Now Save, Activate & execute it, output will be
  • 62. 62 Summary In standard SAP tables we will have many fields, of which we will use only few fields. whenever we go and view the data we have to come across unwanted data, to avoid this and get display of field which relevant to scenario we use this projection view.
  • 63. 63 Structures Structure:- Structure is a user defined group of variables which can hold 1 record during time Go to transaction SE11 and select the radio button “Data type”. Enter a structure name starting with Y or Z.
  • 64. 64 Press create button. A pop-up screen appears with 3 different options. Select the radio button structure. The screen will be displayed like this. Provide the description and also components.
  • 65. 65 Then press SAVE, CHECK and ACTIVATE. Structure Created Successfully.
  • 67. 67 Introduction Search helps are data selection methods used to provide the possible value list for a screen field. I.e. Search helps are used to provide F4 help for screen fields. The selection logic for the data to be displayed can be to show the entries from a single table (no coding required) or even can be complex ABAP code to select the data from different tables which are related or a combination of both. Thus search helps can be used to show very specific information that would be required by the user to select an entry from the possible value list. There are two types of search helps. 1) Elementary search helps: Elementary search help defines a specific search path. The following components need to be defined for an elementary search help a) Where to pick the data from (Selection method) b) What fields have to be considered while selecting the data and what are fields to be displayed (Search help parameters) Dialog box of elementary search help
  • 68. 68 An Elementary search help is a search help that describes an input help process in which it is not possible to select one of a number of search paths. The online behavior of an elementary search help is controlled by defining the dialog type and by specifying the fields to be displayed in the dialog box for restricting values or in the dialog box for displaying the hit list (including the order in these dialog boxes). These fields must be defined as parameters of the search help. For data collection, a database table or a view is normally defined and the possible values are selected here. This table/view is called the selection method of the search help. If the selection method is a table, a text table can also be used for collecting data if one exists. In the selection, those fields of the selection method (and possibly of the text table) which have parameters with the same names in the search help are used. If the standard options for describing the online behavior or data collection for the search help are not sufficient, you can define its behavior more flexibly by using a search help exit. 2) Collective Search helps: Collective search helps are a collection of elementary search helps, thereby providing multiple search paths for a particular field on the screen. The user can select the required search path and use it to get the desired list. Here too we can define the input parameters and the output parameters for the search help. Necessary mapping between the collective search help and the included elementary search help has to be provided. Dialog box of Collective search help
  • 69. 69 A Collective search help describes an input help process in which the user can choose one of several alternative search paths. Each alternative search path corresponds to an elementary search help, i.e. a collective search help contains several elementary search helps. Both elementary search helps and other collective search helps can be included in a collective search help. if a collective search help contains other collective search helps, they are resolved down to the level of the elementary search helps when the input help is called. Like an elementary search help, a collective search help has an interface of import and export parameters. The data is exchanged between the screen template and the parameters of the elementary search helps contained in it using this interface. The parameters of the search helps included in a collective search help must be assigned to the parameters of the collective search help. During the input help process, the collective search help only controls the user's selection of the required search path. The rest of the dialog and data collection is controlled by the selected elementary search help. If selection of the required elementary search help should be made flexible (e.g. with context-specific definition of the set of available search paths), the collective search help must be assigned a search help exit. Creating Elementary Search Helps: In SE11 give the search help name and click the create button. Choose “Elementary search help” in the pop up that follows. This takes you to the screen where you enter the details of the search help. In the Definition tab you have to enter the following details: 1) Selection method: The table from which the data is to be selected by the search help for display of possible value list is to be entered here. This is not a mandatory field. If the selection method is not entered then the data selection (from displaying the possible value list) will have to be done in the search help exit (explained later). 2) Text Table: This field is non editable. If a text table exists for the selection method (table) entered then this field is populated automatically.
  • 70. 70 3) Dialog type: The dialog type defines the steps that are followed by the search help through the process of displaying the search help. You can select from the following dialog types: a) Immediate value display: The possible value list is displayed immediately on calling the search help. b) Dialog with value restriction: On calling the search help a dialog box for restricting the values (Just like a selection screen) selected is displayed first. This dialog box will have those parameters, which are defined as the import parameters in the search help parameters. c) Dialog depends on value set: If the possible value list contains less than 100 entries then the list is displayed immediately. If not then this behaves similar to dialog with value restriction. As a convention, if the possible value list has very less number of entries we would be using the first (a) and if the list will have large volume of data we would use options (b) and (c). 4) Hot key: Hot key (short cut) can be assigned to elementary search help. This can be any character or digit. This will be used when this elementary search help is used as a part of the collective search help. (To call a specific elementary search help from a collective search help enter the following in the field to which the collective search help is attached “ =<Hot key of the elementary search help> “ and do an F4. For e.g. =A and press F4, where A is the hotkey for a specific elementary search help). 5) Search help exit: Search help exit is a function module, which is used to modify and manipulate with the data selection procedure and the selected data. The function module should have the same interface as the function module F4IF_SHLP_EXIT_EXAMPLE. The function module defined as the search help exit will be called at different time points during the process of data selection by the search help. The different time points at which this function module is called and the manipulations that are possible at each time point are explained in detail in a later section.
  • 71. 71 6) Parameters: Here you define the search help parameters. You can define import parameters and export parameters for the search help. Following are the characteristics of the parameters that you would have to define. a) Checkbox ‘IMP’: If the parameter is an import parameter then check this checkbox. b) Checkbox ‘EXP’: If the parameter is an export parameter then check this checkbox. (Note: A parameter can be both import as well as export parameter depending on the requirement. See the section Value transfer for input help for knowing how the import and export parameters transfer values to and from the field to which the search help is attached). c) LPOS: This is the position of the parameter in the hit list. If a parameter need not appear in the hit list then leave this field blank. Note that same position number cannot occur more than once in a search help.(This will set postion on the box which is displayed after F4 is pressed) d) SPOS: This is the position of the parameter in the dialog box for value restriction. (Selection screen). If a parameter need not appear in the dialog box then leave this field blank. If no dialog box appears for value restriction then this field can be left blank for all the parameters. Note that same position number cannot occur more than once in a search help. e) SDIS: If this check box is checked then in the dialog box for value restriction, the parameter will appear as a display only field. The user will be able to see the value restriction for this field but will not be able to modify the value. f) Data Element and Checkbox ‘Modified’: A search help parameter should have an associated data element. This data element will define the output attributes for the parameter and the help functions (F4 help) for the parameter on the dialog box for value restriction. If a table is entered in the “Selection method’ of the search help then the data element is picked up from the field of the table having the same name. All the changes that you perform on this field in the database table, those get reflected in the search help too.
  • 72. 72 If you want to assign a different data element other than that is defined in the database table then check the checkbox ‘Modified” for the parameter. Now the data element field becomes editable and you can enter any required data element. The new data element should have same data type, length and the number of decimal places as the previous one. Only difference would be that the changes that you make to the field in the ‘Selection method’ would not get reflected in the search help. g) Default Value: You can enter the default value for the parameter in this field. Once these details are defined, activate the search help. We can test the search help by doing an ‘F8’ on the maintain search help screen or the display search help screen. Creating Collective Search Helps: In SE11 give the search help name and click the create button. Choose “Collective search help” in the pop up that follows. This takes you to the screen where you enter the details of the search help. In the definitions tab enter the following details:
  • 73. 73 1) Search Help Exit: The use of the search help exit is the same as that in an elementary search helps. In case of collective search helps the time points at which the exit (FM) is called is slightly different than in case of elementary search helps. The different time points at which this function module is called and the manipulations that are possible at each time point are explained in detail in a later section. 2) Parameters: Just like elementary search helps collective search also has the import and export parameters. See the section Value transfer for input help for knowing how the import and export parameters transfer values to and from the field to which the search help is attached. In the included search helps tab define the following. 1) List down the elementary search helps that are going to be the part of this collective search help. 2) Do the parameter assignment for each of the elementary search helps listed. This procedure actually does a mapping between the parameters of the collective search help and the individual elementary search helps. The mapping is automatically proposed by the system but can be changed manually. Once done, activate the search help. The collective search help also can be single tested from the maintain search help screen or the display search help screen using the ‘F8’ functionality. Attaching search helps to fields 1) Attaching the search help to a data element. For attaching the search help to a data element go to further characteristics tab of the data element through SE11 and enter the search help name in the field provided. Then map an export parameter of the search help to the data element. When input help is asked for any field using this data element, the corresponding search help is triggered. If the user selects a line of the hit list in the input help, the
  • 74. 74 contents of this parameter are returned to the corresponding screen field. It is not possible to return several values when the search help is attached to a data element. 2) Attaching the search help to a check table If a field has check table then the possible values for this field is defined by the contents of the check table. The key fields of the check table will be automatically present in the possible value list. If a text table is assigned to the check table then the text will also be present in the hit list. Attaching a search help to the check table can again modify the hit list obtained from the check table. Assigning a search help to the check table field can do this. (Through SE11)
  • 75. 75 (Place the cursor on the field to which the search help has to be assigned and click on the button “Search help”) 3) Attaching the search help to a table field Assign a search help to the table field through SE11 (Refer the above screen shot) 4) Attaching the search help to a screen field Search help can be assigned to a screen field. In this case the search help assignment is valid only for that screen. For dialog screens the assignment can be done through the Screen Painter in the attributes for the field. In the selection screen of the executable programs the search helps can be assigned to the parameters and select-options as follows: Parameter : <PAR> like <field name> matchcode object <Search help>. Select-Options:<SEL> for <fieldname> matchcode object <Search help>. Value Transport for input helps
  • 76. 76 If a search help is attached to a screen field directly or through a data element then only one search help parameter can be assigned to the field. The value transport takes place between this field and the export parameter of the search help attached to the field. (Even in this case the search help can have more than one export parameter. The search help will transfer that field which is the first export parameter defined in the search help) If the search help is attached to a table field or a check table then the value transport can take place for more than one field that are linked to the search help through its parameters. The import parameter of the search help picks up data from that field of the screen, which has the same name as the search help parameter. If such a field is found then it copies the data into the respective parameter and if not found then it leaves the parameter blank. Mapping of the output parameters to the screen fields is similar to the input parameters. The values are transported to the fields having the same name. Thus data can be transferred to more than one fields. Using Search help Exits Search help Exit is just like any other function module and is used to modify the input help process of any search help. Doing so we can provide very specific information required by the user for choosing from the hit list. As mentioned earlier search help exits are called at specific time points of the input help process. The current time point can be obtained from the Function module parameter callcontrol-step. Some of the time points at which manipulations with the data will be required most of the time are: 1) SELONE This time point occurs (only for collective search helps) before the dialog box for entering the import parameters are displayed. This can be used for selecting an
  • 77. 77 elementary search help in the collective search help. This time point occurs only once in the entire search help process. The parameter SHLP_TAB has one entry each for all the possible elementary search helps. If an entry for a specific search help is deleted from SHLD_TAB that search help will not be offered in the dialog box for selection. If there is only one entry remaining in SHLP_TAB, then the dialog box for selection can be skipped by setting the parameter CALLCONTROL-STEP to either ‘PRESEL’ or ‘SELECT’. 2) PRESEL1 Once the search help is selected this event occurs before the interface of the selected search help is entirely copied. So at this time point you can change the properties of the interface parameters of the selected search help by changing the Function module parameter SHLP-INTERFACE. The properties like the screen field to which the search help parameter is attached, the output field for which the input help is asked etc can be changed at this stage. 3) PRESEL This time point occurs before the dialog box for value restriction is displayed. At this time you can predefine the value restriction. This can be done by populating the function module parameter SHLP-SELOPT. e.g. DATA: l_selopt LIKE ddshselopt. l_selopt-shlpfield = <Name of any import parameter of the search help>. l_selopt-sign = 'I'. l_selopt-option = 'EQ'. l_selopt-low = <Value for the field>. l_selopt-shlpname = <Search help name>. APPEND l_selopt TO shlp-selopt.
  • 78. 78 In the dialog box that appears the above restriction would already be present. Use can enter any further selections if required. 4) SELECT This is the time point where the actual selection of the data takes place. If you do not want the default selection to take place, do the data selection that is required and populate the same into the function module parameter RECORD_TAB. For this first select the required data into an internal table and then use the FM ‘F4UT_RESULTS_MAP’. Pass the following parameters in the above function module. APPY_RESTRICTIONS = If you have not already applied the value restrictions then the FM will do it if you pass this parameter as ‘X. SHLP_TAB = This is available in the exit . Pass the same RECORD_TAB = This is available in the exit . Pass the same SOURCE_TAB = The internal table into which you have selected the data Now to skip the standard selection set the function module parameter CALLCONTROL- STEP to ‘DISP’. If this is not set then the default selection will over ride your data selection. 5) DISP This time point occurs before the data is displayed as the hit list. So here you can manipulate with the parameter RECORD_TAB to change the values to be displayed. Once you are done with the manipulations with the data if you want to display the data then do not change CALLCONTROL-STEP. If you do not want to display the hit list and select one value directly then keep only that value in the table RECORD_TAB and set the CALLCONTROL-STEP as ‘RETURN’.
  • 79. 79 If you input help request should be aborted then set the CALLCONTROL-STEP as ‘EXIT’. If you want to re initiate the whole selection process starting from the dialog box for value restriction then set CALLCONTROL-STEP as ‘PRESEL’. Note: Function modules are provided in the function library for operations that are frequently executed in search help exits. The names of these function modules begin with the prefix F4UT_. The use of each of these function modules are available in the documentation of each of these Function modules. An Append search help is used for modification-free enhancement of a collective search help (that is not the original in the current system) with further search help inclusions. This technique can be used for example in special developments and country versions, and by SAP partners and customers to add further search paths to a collective search help of the standard system. An append search help has a fixed assignment to a collective search help (its appending object). This appending object is enhanced with the append search help. The structure of an append search help corresponds to that of a collective search help, but the append search help takes on the parameters of its appending object so that it cannot be maintained separately any longer. Furthermore, an append search help cannot be assigned a search help exit. An append search help is automatically included in its appending object. The parameters of the two search helps having the same name are assigned to each other. Note: You can also hide modification-free search helps from a collective search help with an append search help. You have to insert the search help to be hidden in the append search help and then hide the inclusion there. The search path(s) defined by this search help are no longer offered in the appending search help. To cancel this, remove the hidden inclusion again from the append search help. Note: Append search helps can also be used themselves to describe an input help. They are treated like collective search helps. Note: If the parameters of the appending object change, this change is not automatically made in the append search help. Instead, you are informed
  • 80. 80 that the parameters of the append search help should be adjusted. In this case you should check if you want to change the assignments between the parameters of the append search help and the search helps included in them. Procedure: Proceed as follows to enhance a collective search help of the standard system with your own search paths: 1. For each search path, create an elementary search help in your namespace and activate these search helps. 2. In display mode, go to the maintenance screen for the collective search help and choose Goto -> Append search helps. Create the append search help in your namespace. 3. Include the elementary search help defined in the first step in the append search help. Maintain the parameter assignments between the parameters of the append search help and the parameters of the included search helps. 4. Activate the append search help. The append search help is automatically added to your appending object. The search paths inserted in the append search help are now available in the collective search help. They appear at the end of the list of available elementary search helps.
  • 82. 82 What is table maintenance generator? Table Maintenance Generator ( from now we call it as ‘TMG’) acts as a user interface tool which is used to create a equipment by which customized tables created by end users can be changed as required, such as making an entry to that table, deleting an entry etc. Table maintenance generator is a user interface tool which is used to change the entry of the table or delete an entry from the table or create an entry for the table. A table can be maintained in two ways: 1. from any program 2. Using the TMG. Through whatever we may update the table; the table should have the “Maintenance allowed” property defined in the attributes. Transaction Codes: SE54: Generate Table Maintenance Dialog SE55: Table view maintenance DDIC call SE56: Table view display DDIC call SE57: Deletion of Table Maintenance
  • 83. 83 SM30: Maintenance Table Views: Implementation of table maintenance generator for a custom table We will implement the table maintenance generator for a custom table. Requirement: A table is having certain no. of fields say field1 to field5. During the maintenance of the table by end- user, if the user has entered value ‘X’ in field2, then field4 should be enabled and filled with certain value and field5 should be disabled and if the field2 has value ‘Y’, then field4 should be disabled and field5 should be enabled and filled with certain value. Go to SE11 and create a table with the fields as per the requirement.
  • 84. 84 In table change mode, click on Utilities and then click on Table maintenance generator. If the table needs to be maintained by only particular group of people, then the Authorization group needs to be filled otherwise fill it as &NC&. To maintain the authorization group refer to SU21. Function group is the name to which the generated maintenance modules will belong to. Generally Function Group name can be same as table name. Maintenance can be done in two ways: 1. Maintenance & Overview both on one screen 2. Maintenance on one screen and Overview on another screen.
  • 85. 85 Table entries can be transported with the help of “Dialog data transport details”. If Standard recording routine is checked, then table entries will be included in Transport request (More information available at the end of the document). If other is checked the entry won’t be included in the TR. Click on create on the application tool bar and after generation of TMG without errors click on save. To disable & enable the fields of the table during maintenance, Maintenance screens need to be modified during every new entry accordingly. Follow the procedure to achieve the same: Click on Environment  Modification  Maintenance Screens & Click on Layout. In the Layout, Click on Sales Org field and assign the group as ‘ABC’ and for Plant assign group as ‘DEF’.
  • 86. 86 In the PBO, create a Z Module and write the following code:
  • 87. 87 LOOP AT SCREEN. IF ztestvks-field1 EQ 'X'. IF screen-group1 = 'DEF'. screen-input = '0'. ENDIF. ELSEIF ztestvks-field1 EQ 'Y'. IF screen-group1 = 'ABC'. screen-input = '0'. ENDIF. ENDIF. MODIFY SCREEN. ENDLOOP. As per the requirement, for every new entry in the table, the fields should have the constant values before only. For this purpose, the event needs to be chosen which performs the action. We will go with “05 creating a new entry”. List of Events available in Table maintenance 01 Before saving the data in the database 02 After saving the data in the database 03 Before deleting the data displayed 04 After deleting the data displayed 05 Creating a new entry 06 After completely performing the function 'Get original' 07 Before correcting the contents of a selected field 08 After correcting the contents of a selected field 09 After getting the original of an entry 10 After creating the header entries for the change task (E071) 11 After changing a key entry for the change task (E071K) 12 After changing the key entries for the change task (E071K) 13 Exit editing (exit main function module) 14 After lock/unlock in the main function module 15 Before retrieving deleted entries 16 After retrieving deleted entries 17 Do not use. Before print: Event 26 18 After checking whether the data has changed 19 After initializing global variables, field symbols, etc. 20 after input in date sub screen (time-dep. tab. /views)
  • 88. 88 21 Fill hidden fields 22 Go to long text maintenance for other languages 23 Before calling address maintenance screen 24 After restricting an entry (time-dep. tab./views) 25 Individual authorization checks 26 Before creating a list 27 After creation or copying a GUID (not a key field) 28 After entering a date restriction for time-dep. views AA Instead of the standard data read routine AB Instead of the standard database change routine AC Instead of the standard 'Get original' routine AD Instead of the standard RO field read routine AE Instead of standard positioning coding AF Instead of reading texts in other languages AG Instead of 'Get original' for texts in other languages AH Instead of DB change for texts in other languages ST GUI menu main program name AI Internal use only
  • 89. 89 Click on New Entries tab and Choose 05. In form routine enter “AT_NEWENTRY” and click on EDITOR.
  • 90. 90 Go to the events and in the form routine: AT_NEWENTRY, write the following code: LOOP AT SCREEN. IF ztestvks-field1 EQ 'X'. IF screen-group1 = 'DEF'. ztestvks-vkorg = '2011'. ENDIF. ELSEIF ztestvks-field1 EQ 'Y'. IF screen-group1 = 'ABC'. ztestvks-werks = '1400'. ENDIF. ENDIF. MODIFY SCREEN. ENDLOOP. Click on Save & activate and press F3 & F3. Check the same by adding some entries through SM30:
  • 91. 91 Dialog Data Transport details (Changing the option to “Standard recording routine”): Values entered in ZTESTVKS through SM30 and clicked on save:
  • 92. 92 An introduction to Search helps
  • 93. 93 Introduction Search helps are data selection methods used to provide the possible value list for a screen field. I.e. Search helps are used to provide F4 help for screen fields. The selection logic for the data to be displayed can be to show the entries from a single table (no coding required) or even can be complex ABAP code to select the data from different tables which are related or a combination of both. Thus search helps can be used to show very specific information that would be required by the user to select an entry from the possible value list. There are two types of search helps. 3) Elementary search helps: Elementary search help defines a specific search path. The following components need to be defined for an elementary search help a) Where to pick the data from (Selection method) b) What fields have to be considered while selecting the data and what are fields to be displayed (Search help parameters) Dialog box of elementary search help 4) Collective Search helps: Collective search helps are a collection of elementary search helps, thereby providing multiple search paths for a particular field on the screen. The user can select the required search path and use it to get the desired list. Here too we can define the input parameters and the output parameters for the search help. Necessary mapping between the collective search help and the included elementary search help has to be provided.
  • 94. 94 Dialog box of Collective search help Creating Elementary Search Helps: In SE11 give the search help name and click the create button. Choose “Elementary search help” in the pop up that follows. This takes you to the screen where you enter the details of the search help. In the Definition tab you have to enter the following details: 7) Selection method: The table from which the data is to be selected by the search help for display of possible value list is to be entered here. This is not a mandatory field. If the selection method is not entered then the data selection (from displaying the possible value list) will have to be done in the search help exit (explained later). 8) Text Table: This field is non editable. If a text table exists for the selection method (table) entered then this field is populated automatically. 9) Dialog type: The dialog type defines the steps that are followed by the search help through the process of displaying the search help. You can select from the following dialog types: a) Immediate value display: The possible value list is displayed immediately on calling the search help. b) Dialog with value restriction: On calling the search help a dialog box for restricting the values (Just like a selection screen) selected is displayed first. This dialog box will have those parameters, which are defined as the import parameters in the search help parameters.
  • 95. 95 c) Dialog depends on value set: If the possible value list contains less than 100 entries then the list is displayed immediately. If not then this behaves similar to dialog with value restriction. As a convention, if the possible value list has very less number of entries we would be using the first (a) and if the list will have large volume of data we would use options (b) and (c). 10) Hot key: Hot key (short cut) can be assigned to elementary search help. This can be any character or digit. This will be used when this elementary search help is used as a part of the collective search help. (To call a specific elementary search help from a collective search help enter the following in the field to which the collective search help is attached “ =<Hot key of the elementary search help> “ and do an F4. For e.g. =A and press F4, where A is the hotkey for a specific elementary search help). 11) Search help exit: Search help exit is a function module, which is used to modify and manipulate with the data selection procedure and the selected data. The function module should have the same interface as the function module F4IF_SHLP_EXIT_EXAMPLE. The function module defined as the search help exit will be called at different time points during the process of data selection by the search help. The different time points at which this function module is called and the manipulations that are possible at each time point are explained in detail in a later section. 12) Parameters: Here you define the search help parameters. You can define import parameters and export parameters for the search help. Following are the characteristics of the parameters that you would have to define. a) Checkbox ‘IMP’: If the parameter is an import parameter then check this checkbox. b) Checkbox ‘EXP’: If the parameter is an export parameter then check this checkbox.
  • 96. 96 (Note: A parameter can be both import as well as export parameter depending on the requirement. See the section Value transfer for input help for knowing how the import and export parameters transfer values to and from the field to which the search help is attached). c) LPOS: This is the position of the parameter in the hit list. If a parameter need not appear in the hit list then leave this field blank. Note that same position number cannot occur more than once in a search help. d) SPOS: This is the position of the parameter in the dialog box for value restriction. (Selection screen). If a parameter need not appear in the dialog box then leave this field blank. If no dialog box appears for value restriction then this field can be left blank for all the parameters. Note that same position number cannot occur more than once in a search help. e) SDIS: If this check box is checked then in the dialog box for value restriction, the parameter will appear as a display only field. The user will be able to see the value restriction for this field but will not be able to modify the value. f) Data Element and Checkbox ‘Modified’: A search help parameter should have an associated data element. This data element will define the output attributes for the parameter and the help functions (F4 help) for the parameter on the dialog box for value restriction. If a table is entered in the “Selection method’ of the search help then the data element is picked up from the field of the table having the same name. All the changes that you perform on this field in the database table, those get reflected in the search help too. If you want to assign a different data element other than that is defined in the database table then check the checkbox ‘Modified” for the parameter. Now the data element field becomes editable and you can enter any required data element. The new data element should have same data type, length and the number of decimal places as the previous one. Only difference would be that the changes that you make to the field in the ‘Selection method’ would not get reflected in the search help. g) Default Value: You can enter the default value for the parameter in this field.
  • 97. 97 Once these details are defined, activate the search help. We can test the search help by doing an ‘F8’ on the maintain search help screen or the display search help screen. Creating Collective Search Helps: In SE11 give the search help name and click the create button. Choose “Collective search help” in the pop up that follows. This takes you to the screen where you enter the details of the search help. In the definitions tab enter the following details: 3) Search Help Exit: The use of the search help exit is the same as that in an elementary search helps. In case of collective search helps the time points at which the exit (FM) is called is slightly different than in case of elementary search helps. The different time points at which this function module is called and the manipulations that are possible at each time point are explained in detail in a later section. 4) Parameters: Just like elementary search helps collective search also has the import and export parameters. See the section Value transfer for input help for knowing how the import and export parameters transfer values to and from the field to which the search help is attached. In the included search helps tab define the following. 3) List down the elementary search helps that are going to be the part of this collective search help. 4) Do the parameter assignment for each of the elementary search helps listed. This procedure actually does a mapping between the parameters of the collective search help and the individual elementary search helps. The mapping is automatically proposed by the system but can be changed manually.
  • 98. 98 Once done, activate the search help. The collective search help also can be single tested from the maintain search help screen or the display search help screen using the ‘F8’ functionality. Attaching search helps to fields 5) Attaching the search help to a data element. For attaching the search help to a data element go to further characteristics tab of the data element through SE11 and enter the search help name in the field provided. Then map an export parameter of the search help to the data element. When input help is asked for any field using this data element, the corresponding search help is triggered. If the user selects a line of the hit list in the input help, the contents of this parameter are returned to the corresponding screen field. It is not possible to return several values when the search help is attached to a data element. 6) Attaching the search help to a check table If a field has check table then the possible values for this field is defined by the contents of the check table. The key fields of the check table will be automatically present in the possible value list. If a text table is assigned to the check table then the text will also be present in the hit list.
  • 99. 99 Attaching a search help to the check table can again modify the hit list obtained from the check table. Assigning a search help to the check table field can do this. (Through SE11) (Place the cursor on the field to which the search help has to be assigned and click on the button “Search help”) 7) Attaching the search help to a table field Assign a search help to the table field through SE11 (Refer the above screen shot) 8) Attaching the search help to a screen field Search help can be assigned to a screen field. In this case the search help assignment is valid only for that screen. For dialog screens the assignment can be done through the Screen Painter in the attributes for the field.
  • 100. 100 In the selection screen of the executable programs the search helps can be assigned to the parameters and select-options as follows: Parameter : <PAR> like <field name> matchcode object <Search help>. Select-Options:<SEL> for <fieldname> matchcode object <Search help>. Value Transport for input helps If a search help is attached to a screen field directly or through a data element then only one search help parameter can be assigned to the field. The value transport takes place between this field and the export parameter of the search help attached to the field. (Even in this case the search help can have more than one export parameter. The search help will transfer that field which is the first export parameter defined in the search help) If the search help is attached to a table field or a check table then the value transport can take place for more than one field that are linked to the search help through its parameters. The import parameter of the search help picks up data from that field of the screen, which has the same name as the search help parameter. If such a field is found then it copies the data into the respective parameter and if not found then it leaves the parameter blank. Mapping of the output parameters to the screen fields is similar to the input parameters. The values are transported to the fields having the same name. Thus data can be transferred to more than one fields.
  • 101. 101 Using Search help Exits Search help Exit is just like any other function module and is used to modify the input help process of any search help. Doing so we can provide very specific information required by the user for choosing from the hit list. As mentioned earlier search help exits are called at specific time points of the input help process. The current time point can be obtained from the Function module parameter callcontrol-step. Some of the time points at which manipulations with the data will be required most of the time are: 6) SELONE This time point occurs (only for collective search helps) before the dialog box for entering the import parameters are displayed. This can be used for selecting an elementary search help in the collective search help. This time point occurs only once in the entire search help process. The parameter SHLP_TAB has one entry each for all the possible elementary search helps. If an entry for a specific search help is deleted from SHLD_TAB that search help will not be offered in the dialog box for selection. If there is only one entry remaining in SHLP_TAB, then the dialog box for selection can be skipped by setting the parameter CALLCONTROL-STEP to either ‘PRESEL’ or ‘SELECT’. 7) PRESEL1 Once the search help is selected this event occurs before the interface of the selected search help is entirely copied. So at this time point you can change the properties of the interface parameters of the selected search help by changing the Function module parameter SHLP-INTERFACE.
  • 102. 102 The properties like the screen field to which the search help parameter is attached, the output field for which the input help is asked etc can be changed at this stage. 8) PRESEL This time point occurs before the dialog box for value restriction is displayed. At this time you can predefine the value restriction. This can be done by populating the function module parameter SHLP-SELOPT. e.g. DATA: l_selopt LIKE ddshselopt. l_selopt-shlpfield = <Name of any import parameter of the search help>. l_selopt-sign = 'I'. l_selopt-option = 'EQ'. l_selopt-low = <Value for the field>. l_selopt-shlpname = <Search help name>. APPEND l_selopt TO shlp-selopt. In the dialog box that appears the above restriction would already be present. Use can enter any further selections if required. 9) SELECT This is the time point where the actual selection of the data takes place. If you do not want the default selection to take place, do the data selection that is required and populate the same into the function module parameter RECORD_TAB. For this first select the required data into an internal table and then use the FM ‘F4UT_RESULTS_MAP’. Pass the following parameters in the above function module. APPY_RESTRICTIONS = If you have not already applied the value restrictions then the FM will do it if you pass this parameter as ‘X. SHLP_TAB = This is available in the exit . Pass the same
  • 103. 103 RECORD_TAB = This is available in the exit . Pass the same SOURCE_TAB = The internal table into which you have selected the data Now to skip the standard selection set the function module parameter CALLCONTROL- STEP to ‘DISP’. If this is not set then the default selection will over ride your data selection. 10) DISP This time point occurs before the data is displayed as the hit list. So here you can manipulate with the parameter RECORD_TAB to change the values to be displayed. Once you are done with the manipulations with the data if you want to display the data then do not change CALLCONTROL-STEP. If you do not want to display the hit list and select one value directly then keep only that value in the table RECORD_TAB and set the CALLCONTROL-STEP as ‘RETURN’. If you input help request should be aborted then set the CALLCONTROL-STEP as ‘EXIT’. If you want to re initiate the whole selection process starting from the dialog box for value restriction then set CALLCONTROL-STEP as ‘PRESEL’. Note: Function modules are provided in the function library for operations that are frequently executed in search help exits. The names of these function modules begin with the prefix F4UT_. The use of each of these function modules are available in the documentation of each of these Function modules.
  • 104. 104
  • 105. 105 CLASSICAL REPORTS ABAP – Advanced Business Application Programming is a fourth generation programming language and is used to develop all SAP R/3 applications. Programs In ABAP can be broadly classified as:-  List/Report Programs  Dynamic/Dialog Programs. Dynamic/Dialog programming serves as an interface to the SAP R/3 database. Dialog programs, frequently called as module pools enable the user to interact with the SAP database. This interaction can be in the form of adding entries, retrieving them for display or even modifying them. Therefore such programs often act as the front end to the R/3 database.
  • 106. 106 On the other hand List/Report programs serve as a medium to retrieve large amounts of data from the R/3 database and process it for display to the user. In addition to this report programs provide the user with the functionality of downloading the data in a desired format from SAP to Excel or Notepad for distribution or record purposes. This document is aimed to introduce the reader to Report Programming in ABAP. It takes you through the basics of the ABAP Editor (SE38) and into the various aspects of Report Programming. It provides a small tutorial with screen snapshots to enable the reader to understand the concepts of Report Programming as well as create his/her first report program. Pre-Requisites: The reader should be comfortable with ABAP Data Dictionary, Language constructs and Working with tables. INDEX 1. ABAP EDITOR: SE38 2. INCLUDES 3. DEFINITIONS 4. SELECTION SCREEN 5. FORMS 6. EVENTS 7. DISPLAY OPTIONS 8. TEXT ELEMENTS 9. PROCESSING 10. VARIANTS 11. SAMPLE CODE ABAP EDITOR: SE38
  • 107. 107 The ABAP Editor commonly referred to as SE38 is used for the creation of all Report Programs. The editor is used for creating/editing the source code for the report program as well as for the creation of variants, documentation, etc. Each of these will be covered separately in the chapters to follow. Let us now begin by creating our very own Report say z_samplereport. As we proceed by clicking the “Create” button we are presented with a window where we define the attributes of our report. Some of the basic attributes are explained below. 1. Title: The title provides a brief idea of what the report is designed to do. 2. Type: All reports are of the type “Executable program” (Type 1). 3. Status: The status defines whether the program is a Standard SAP Program or a Customer Production Program or a Test Program. 4. Application: This refers to the Application Type Area-SD, FI, etc. 5. Authorization Group: This defines the Authorization Group to which a report is assigned. This plays an important role when the system has to check whether the user is authorized to execute a program or edit a program. 6. Editor Lock: This option provides the functionality of preventing other users from making changes to the program.
  • 108. 108 Once these attributes are set, we proceed by saving the report. This brings us to the main editor page of the report. This is where we write the code for the program. The first line always contains the report name. We now define the line size and line count for the report. We also include the NO STANDARD PAGE HEADING line so as to suppress the list heading or name of the program. For displaying error / warning / information messages, we define the message class which is maintained via transaction SE91. Thus an ideal report program would begin as:- Report <report name> NO STANDARD PAGE HEADING LINE-SIZE <size> LINE-COUNT <n(n1)> MESSAGE-ID <message class>. INCLUDES
  • 109. 109 The Includes are reports of the type “Include Program”. These are used to separate the definitions for the program and the actual code consisting of the select queries and other presentation logic. The definitions are generally written in the top include and the queries and other logic goes into the forms include. However there is no standard naming convention for these includes and the names vary according to the project standards. Also, the use of includes is optional. If the program is a simple report with no complex queries and few definitions, the entire code including the definitions & logic can be written together in the main program itself. However the use of includes is a good coding practice and aides in maintenance of code and debugging. DEFINITIONS
  • 110. 110 The definition part of the code basically includes the list of tables which will be used in the report. This is followed by the definitions of internal tables, constants & other variables which will be used in the course of the report. We now come to the definition of the Selection Screen - the interface between the user and program. It is here that the user specifies the input values for which the report should be executed. SELECTION SCREEN
  • 111. 111 The syntax for defining the selection screen is as follows. SELECTION-SCREEN BEGIN OF SCREEN <SCREEN #> SELECTION-SCREEN BEGIN OF BLOCK <#> WITH FRAME TITLE <TEXT> ……… ……… SELECTION-SCREEN END OF BLOCK <#> SELECTION-SCREEN END OF SCREEN <SCREEN #> The Selection Screen basically comprises of 2 main components:  Select Options  Parameters SELECT OPTIONS:  A select option can be used to input a range of values or a set of values to the program.  The syntax for defining a select option like the field of a table is as follows. SELECT-OPTIONS: s_name FOR Table-Field. Eg: SELECT-OPTIONS: s_bukrs FOR lfb1-bukrs.  A Select Option can be made mandatory by using the following syntax. SELECT-OPTIONS: s_name FOR Table-Field OBLIGATORY.
  • 112. 112 Eg: SELECT-OPTIONS: s_bukrs FOR lfb1-bukrs OBLIGATORY. The above illustration shows how a select option would look like for the definition stated in the example. PARAMETERS:  A parameter on the other hand can accept one single value for the course of execution of the program.  The syntax for defining a parameter like the field of a table is as follows. PARAMETERS: p_name LIKE Table-Field. Eg: PARAMETERS: p_lifnr LIKE lfb1-lifnr.  As explained in the case of select options, a parameter can also be made obligatory by use of the OBLIGATORY syntax.  A select option can be used as a parameter by using the following syntax. SELECT-OPTIONS: s_name FOR Table-Field NO INTERVALS NO- EXTENSIONS. The above illustration shows how a parameter would look like for the definition stated in the example. We can assign a default value to both select options and parameters by using the DEFAULT <VALUE> tag after the definition. FORMS
  • 113. 113 The forms generally contain the functions containing the select queries based on the values input on the selection screen. These functions will be called from the main program once the report is executed. The forms also contain the logic for displaying the data fetched from the database by the report program. This will be dealt in detail in the following sections. EVENTS
  • 114. 114 The events in a report program basically define the order in which the code is executed. Following are the basic events in any report program: 1. LOAD-OF-PROGRAM: This event triggers the associated event in an internal session after loading the program. 2. INITIALIZATION: This event is used for filling in values in the selection screen at runtime. Basically, all values are initialized during the course of this event 3. AT SELECTION-SCREEN: Validation checks for input occur during this event. 4. START-OF-SELECTION: This event triggers the start of selection of data from the database tables. All functions involving select queries are called during this event. Once the requisite data is fetched, it is modified/customized as per the requirements and then finally prepared for display. 5. END-OF-SELECTION: This event causes all fetched data to be displayed on the screen. All functions associated with displaying the fetched data are called during this event. List Processing also occurs during End of Selection. Events during List Processing include the following:  TOP-OF-PAGE  NEW PAGE  END-OF-PAGE
  • 115. 115 DISPLAY OPTIONS There are primarily 2 ways of displaying data fetched by a report.  “WRITE” statements  ALV List/Grid WRITE STATEMENTS: Following is the syntax for using write statements. WRITE : / '|'. WRITE AT 5: 'TITLE 1'. WRITE AT 15 : '|'. WRITE AT 20 :'TITLE 2'. WRITE AT 35 : '|'. WRITE AT 40 :'TITLE 3'. WRITE AT 60 : '|'. WRITE AT 65 :'TITLE 4'. WRITE AT 75: '|'. WRITE AT 80: 'TITLE 5'. WRITE AT 90: '|'. LOOP AT TABLE. WRITE : / '|'. WRITE AT 5: Table-Field. WRITE AT 15 : '|'. WRITE AT 20 :Table-Field. WRITE AT 35 : '|'. WRITE AT 40 :Table-Field. WRITE AT 60 : '|'. WRITE AT 65 :Table-Field. WRITE AT 75: '|'. WRITE AT 80: Table-Field. WRITE AT 90: '|'. ENDLOOP. Additional formatting options available with WRITE options are use of different colors, intensifying text and hotspots. Hotspots: When one drags the mouse over the lines of data where hotspots are activated, the cursor changes to a hand with an outstretched index finger. Hotspots can be used for adding additional features such as redirection to tables, transactions, etc.
  • 116. 116 The above screenshot shows an example of how a report developed using write statements would look like. However, it is a cumbersome task to design the output layout using write statements especially when the amount of data being displayed is huge and display requirements are complex. This also affects the readability of the report. Hence this method is preferred only for small simple reports. ALV-LIST/GRID: SAP provides a list of ALV (ABAP List Viewer) function modules which can enhance the functionality and readability of a report. Hence ALV is generally preferred for all report displays. ALV also provides added functionalities like dynamic sorting of report output and rearranging columns in the report output. ALV’s are generally of 3 types: 1. List /SimpleALV 2. Grid/Block ALV 3. Hierarchical Sequential Report
  • 117. 117 The above illustration shows how an ALV Grid display would look like. However the procedure for generating an ALV is beyond the scope of this document. TEXT ELEMENTS There are 3 different types of text elements: 1. LIST HEADINGS: These are used to make dynamic List headings
  • 118. 118 2. SELECTION TEXTS: These are used to give names to the select-options, parameters and block titles used in the selection screen.
  • 119. 119 3. TEXT SYMBOLS: Text symbols are used for printing texts on the selection screen or in the report output. The use of selection texts is considered to be a good programming practice as it serves as a substitute for hard-coding.Text symbols also provides multi-lingual support.
  • 120. 120 PROCESSING THE REPORT Once we are done with the coding, we check the report for any syntactic errors. The editor displays the errors if any along with the line numbers and the suggested correction. Check the illustration below.
  • 121. 121 Once the report is found to be syntactically correct, we activate it. On activation, the program is checked & an active version of the report is saved. Once the report is activated, it is ready for processing. On direct processing, the report is executed. Thus, the selection screen will be displayed prompting the user to input the values for selection. Pressing the F4 Key gives the user a list of possible values for that particular field
  • 122. 122 Once the user has entered the desired values, the report is executed. On execution, the data is fetched from the data base and displayed to the user. VARIANTS A variant is a saved version of the input data filled into the selection screen. At runtime, the variant can directly be selected. This removes the need to manually enter the data in the selection screen over and over again. This generally helps when we are testing a report for a particular set of values. Check the illustrations below for the procedure to create a variant.
  • 123. 123 Once we have created the variants, they can be directly selected from the list of available variants displayed on the selection screen.
  • 124. 124 Types of Internal Tables 1. Overview This document highlights performance issues related to the 3 different kinds of internal tables:  Standard table  Sorted Table  Hashed Table It emphasizes how the selection of either of these tables, subject to functional requirements and limitations, can affect the performance and execution time of our code.
  • 125. 125 2. Types of Internal Tables in ABAP/4 The table type defines how ABAP accesses individual table entries. There are three kinds of internal table types: o Standard table: A standard table has an internal logical index. You can access it either using the index or using its key (refer to Appendix A for notes on KEY). If you use key access, the response time is in linear relation to the number of table entries. The key of a standard table is always non-unique. You cannot use the UNIQUE KEY addition in the definition of a standard table. o Sorted table: A sorted table is always stored correctly sorted by its key. Like standard tables, they also have a linear index, and you can access them using either the index or their key. If you use key access, the response time is in logarithmic relation to the number of table entries, since the system uses a binary search. The key of a sorted table may be either unique or non-unique, and you must use one of the additions UNIQUE or NON- UNIQUE when you specify the key. Standard tables and sorted tables are generically known as index tables. o Hashed tables: Hashed tables do not have a logical index. You can only access a hashed table using its key. The response time is therefore independent of the number of table entries, since the system uses a hash algorithm to access the entries. The key of a hashed table must be unique, so you must always use the UNIQUE addition when creating the table.
  • 126. 126 Standard Sorted Hashed Index type Logical Logical No Index Access Type Index/Key Index/Key Key Response time Linear Logarithmic Constant Key Type Non-unique Unique/Non-Unique Unique 3. Choosing a Table Type The table type that you use in a particular situation will depend on which of the typical internal table operations listed above will be used with the table, and how often. Standard Tables This table type is most appropriate when you intend to address the table entries using the index. This is the quickest way to access entries in a standard table. You should fill standard tables using the APPEND statement, and read, modify, and delete entries using the index (INDEX addition to the corresponding ABAP statement). If you use the key to access a standard table, the access time increases in linear relation to the number of entries. If you need to use key entries, standard tables are suitable if you can separate filling the table from the remaining table processing. For example, you can fill a standard table by appending entries, and then sort it. If you then use key access with the BINARY SEARCH option, the response time is only in logarithmic relation to the number of table entries. You should use index operations to access standard tables. For the sake of compatibility, you can use TABLE as a synonym of STANDARD TABLE Sorted Tables This table type is suitable for tables that must be correctly sorted even while you are filing them. You fill a sorted table using the INSERT ... INTO TABLE statement, observing the sort sequence defined in the key. When you access the table using its key, the response time is in logarithmic relation to the number of table entries, since the system automatically uses a binary search. Sorted tables are particularly useful for partial sequential processing in a LOOP if you can specify a portion of the table key starting from the left in the WHERE condition. Hashed Tables Hashed tables are useful if the main operation on the table is going to be key access. You cannot access a hashed table using index access. However, the response time for key access is constant, regardless of the number of table entries. Like database tables, hashed tables always
  • 127. 127 have a unique key. Hashed tables are therefore useful for constructing and processing internal tables that resemble database tables. 4. General Performance Notes for Internal Tables 4.1 Index Management As soon as you change an internal table using INSERT, DELETE or SORT, the logical sequence of the table entries will no longer correspond with the physical sequence in the memory. When this happens, the system creates a logical index, which also requires memory. Furthermore, each INSERT or DELETE statement requires further memory. If your internal table is very large, changing the index can result in significantly increased runtime. The system does not administer secondary indexes for internal tables. 4.2 Filling Line-by-line Unlike filling a table using the INSERT statement, using APPEND does not cost runtime in terms of maintaining the index. If the sequence of the entries is unimportant, or they are already in the correct order, you should use APPEND instead of INSERT. 4.3 Points to Remember Functional Only STANDARD tables are allowed as TABLES parameters in FM’s. Performance 1. The runtime required to sort an internal table increases with the number of entries and the length of the sort key. 2. Sorting an internal table with 100 entries with a 50 byte key requires about 1300 msn (standardized microseconds). Using a 30-byte key, the runtime is about 950 msn. 3. If one of the specified sort criteria is itself an internal table, SORT may sometimes take much longer. Example 1: Declaration of hashed internal table with a unique key. DATA: BEGIN OF tb_itab, col1 TYPE i, col2 TYPE c, END OF tb_itab. DATA itab LIKE HASHED TABLE OF tb_line WITH UNIQUE KEY col1. And similarly we can declare internal tables as sorted or standard. Standard table are the default tables created, i.e.
  • 128. 128 DATA itab LIKE STANDARD TABLE OF tb_line. Is equivalent to DATA itab LIKE tb_line. 5. Various tables operations w.r.t to types of internal tables 5.1 INSERT - Insert into an Internal Table INSERT [wa INTO|INITIAL LINE INTO] TABLE itab. The way in which the system inserts a new entry into the table depends on the table type: o Standard Table: The new entry is added to the end of the table. Generic insertion is therefore the same as an APPEND. o Sorted Table: The new entry is added in its appropriate place, determined by the table key. The key values are taken from the specified work area wa or from the header line of the table. If the key is NON-UNIQUE, the entry is placed at the top of the list of duplicates. The insertion point is determined internally using a binary search. This makes the relationship between the runtime required and the number of table entries logarithmic. o Hashed Table: The new entry is placed in the internal hash administration of the table according to the table key. The key values are taken from the specified work area wa or the header line of the table. The runtime required remains constant, since it does not depend on the number of table entries. The key must be unique. Insert in a Sorted Table with Unique Key Insert in Hashed Table with Unique Key * Entries: 1000, Duplicates: 250 * Line width: 100, Key width: 20 * ITAB2 takes 750 entries with unique key K REFRESH ITAB2. LOOP AT ITAB1 INTO WA. INSERT WA INTO TABLE ITAB2. IF SY-SUBRC <> 0. " ... ENDIF. ENDLOOP. * Entries: 1000, Duplicates: 250 * Line width: 100, Key width: 20 * ITAB2 takes 750 entries with unique key K REFRESH ITAB2. LOOP AT ITAB1 INTO WA. INSERT WA INTO TABLE ITAB2. IF SY-SUBRC <> 0. " ... ENDIF. ENDLOOP. 4,337 2637
  • 129. 129 Filling a hash table is faster than for a sorted table. You can access single entries very fast. 5.2 LOOP - Loop Through an Internal Table LOOP AT itab INTO wa where col1 = “raj”. Places all entries of the internal table itab that satisfy the WHERE condition one by one into the output area. Notes When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required. If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. This optimization requires that the WHERE condition be specified in the form WHERE k1 = v1 AND k2 = v2 AND... AND kn = vn where the components k1, ..., kn are in the same sequence as the beginning of the table key. Partial Sequential Access: Sorted Vs. Hashed Tables Partial Sequential Access on a Hashed Table Partial Sequential Access on a Sorted Tables * Entries: 10000, Line width: 100 * key width: 60, Subkey width: 20 * HTAB is a hashed table, 2000 entries are read * Key fields: K, DATA LOOP AT HTAB INTO WA WHERE K = SUBKEY. " ... ENDLOOP. * Entries: 10000, Line width: 100 * key width: 60, Subkey width: 20 * STAB is a sorted table, 2000 entries are read * Key fields: K, DATA LOOP AT STAB INTO WA WHERE K = SUBKEY. " ... ENDLOOP. 6343 2212 5.3 READ - Reading an Internal Table
  • 130. 130 Variants: 1. READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH]. 2. READ TABLE itab INDEX i. Variant 1 READ TABLE itab WITH KEY k1 = v1 ... kn = vn [BINARY SEARCH] Effect The system uses the specified key to identify the correct line. If the type of a value is not compatible with the type of the corresponding key field, the system uses MOVE logic to convert the value into the type of the component before reading the table. This is an asymmetric comparison logic, in which the component type takes precedence over the value type. The way in which the system looks for an entry in the table depends on its table type: o Standard Table: If you use the ... BINARY SEARCH addition, the system uses a binary search. Otherwise, the search is sequential and the response time is in linear relation to the number of table entries. This assumes that the internal table is sorted in ascending order in the sequence of the specified key fields. o Sorted Table: If the specified key fields form a left-justified extract of the table key, the search is binary, otherwise sequential. The response time is in logarithmic relation to the number of table entries. o Hashed Table: Sequential search. The response time is constant. Variant 2 READ TABLE itab INDEX i Effect Accessing the table entry with the index i. Performance Issues: 1. The quickest way to access a single line of an internal table is direct access using an index, because the response time is then not linked to the size of the table, and is restricted more or less to the transport costs for a single line. For hashed tables, the response time is constant. Accessing a table using the hash administration makes the response time around 3 times slower than using index access. If you use the key to access a table, the response time increase as the number of table
  • 131. 131 entries and the size of the search key increase. Searching using a binary search is considerably quicker than using a linear search. Therefore, in many cases it can be quicker to sort the table and then use the BINARY SEARCH addition. 2. Using statements that use an explicit work area for internal tables with a header line can avoid unnecessary value assignments. Runtime required to read a line from a table with 100 entries Read…index = 7 msn Read….key (30 bytes)...binary search = 25msn Read….key = 100 msn Statistical Performance Review of Various Table Types Linear Search vs. Binary Search Linear Search in an Internal Table Binary Search in an internal table * Entries: 1000, Line width: 100 * Key width: 20 READ TABLE ITAB INTO WA WITH KEY K = 'X'. * Entries: 1000, Line width: 100 * Key width: 20 READ TABLE ITAB INTO WA WITH KEY K = 'X' BINARY SEARCH. 271 3 Single READ access on unique sorted vs. hashed table Read on Unique Sorted Table Read on Unique Hashed table * Entries: 1000 * Line width: 100, key width: 20 * STAB is a unique sorted table, 250 entries are read DO 250 TIMES. N = 4 * SY-INDEX. READ TABLE STAB INTO WA WITH TABLE KEY K = N. IF SY-SUBRC = 0. * Entries: 1000 * Line width: 100, key width: 20 * HTAB is a hased table, 250 entries are read DO 250 TIMES. N = 4 * SY-INDEX. READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
  • 132. 132 " ... ENDIF. ENDDO. IF SY-SUBRC = 0. " ... ENDIF. ENDDO. 1725 1268 1. Entries in a sorted table are located by binary search. The costs depend on the number of entries in the table (O (log n)). 2. Entries in a hashed table are located by an internal hash-algorithm. The costs are constant (O (1)), i.e. they do not depend on the table size. Hashed tables are optimized for single entry access, whereas sorted tables are optimized for partial sequential loop operations. Appendix A: Key The key is used to identify lines in the table. There are two possible keys for an internal table - the default key and a user-defined key. You can specify that the key should by UNIQUE or NON-UNIQUE. If the key is unique, the internal table may not contain duplicate entries. The uniqueness of the key depends partly on the table type (see below). o The default key consists of all non-numeric components of the corresponding line type that are not, and do not contain, internal tables. o The user-defined key can consist of any components that are not, and do not contain, internal tables (that is, do not have a deep-structured type). Internal tables with a user- defined key are known as key tables. When you define the key, remember that the sequence of the key fields is important for operations such as sorting.
  • 133. 133 Performance tuning For all entries The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause. The plus  Large amount of data
  • 134. 134  Mixing processing and reading of data  Fast internal reprocessing of data  Fast The Minus  Difficult to program/understand  Memory could be critical (use FREE or PACKAGE size) Some steps that might make FOR ALL ENTRIES more efficient:  Removing duplicates from the driver table  Sorting the driver table  If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement: FOR ALL ENTRIES IN i_tab WHERE mykey >= i_tab-low and mykey <= i_tab-high. Nested selects The plus:  Small amount of data  Mixing processing and reading of data  Easy to code - and understand The minus:  Large amount of data  when mixed processing isn’t needed  Performance killer no. 1 Select using JOINS The plus  Very large amount of data  Similar to Nested selects - when the accesses are planned by the programmer  In some cases the fastest  Not so memory critical The minus  Very difficult to program/understand  Mixing processing and reading of data not possible Use the selection criteria SELECT * FROM SBOOK. CHECK: SBOOK-CARRID = 'LH' AND
  • 135. 135 SBOOK-CONNID = '0400'. ENDSELECT. SELECT * FROM SBOOK WHERE CARRID = 'LH' AND CONNID = '0400'. ENDSELECT. Use the aggregated functions C4A = '000'. SELECT * FROM T100 WHERE SPRSL = 'D' AND ARBGB = '00'. CHECK: T100-MSGNR > C4A. C4A = T100-MSGNR. ENDSELECT. SELECT MAX( MSGNR ) FROM T100 INTO C4A WHERE SPRSL = 'D' AND ARBGB = '00'. Select with view SELECT * FROM DD01L WHERE DOMNAME LIKE 'CHAR%' AND AS4LOCAL = 'A'. SELECT SINGLE * FROM DD01T WHERE DOMNAME = DD01L-DOMNAME AND AS4LOCAL = 'A' AND AS4VERS = DD01L-AS4VERS AND DDLANGUAGE = SY-LANGU. ENDSELECT. SELECT * FROM DD01V WHERE DOMNAME LIKE 'CHAR%' AND DDLANGUAGE = SY-LANGU. ENDSELECT.
  • 136. 136 Select with index support SELECT * FROM T100 WHERE ARBGB = '00' AND MSGNR = '999'. ENDSELECT. SELECT * FROM T002. SELECT * FROM T100 WHERE SPRSL = T002-SPRAS AND ARBGB = '00' AND MSGNR = '999'. ENDSELECT. ENDSELECT. Select … Into table REFRESH X006. SELECT * FROM T006 INTO X006. APPEND X006. ENDSELECT SELECT * FROM T006 INTO TABLE X006. Select with selection list SELECT * FROM DD01L WHERE DOMNAME LIKE 'CHAR%' AND AS4LOCAL = 'A'. ENDSELECT SELECT DOMNAME FROM DD01L INTO DD01L-DOMNAME WHERE DOMNAME LIKE 'CHAR%' AND AS4LOCAL = 'A'. ENDSELECT
  • 137. 137 Key access to multiple lines LOOP AT TAB. CHECK TAB-K = KVAL. " ... ENDLOOP. LOOP AT TAB WHERE K = KVAL. " ... ENDLOOP. Copying internal tables REFRESH TAB_DEST. LOOP AT TAB_SRC INTO TAB_DEST. APPEND TAB_DEST. ENDLOOP. TAB_DEST[] = TAB_SRC[]. Modifying a set of lines LOOP AT TAB. IF TAB-FLAG IS INITIAL. TAB-FLAG = 'X'. ENDIF. MODIFY TAB. ENDLOOP. TAB-FLAG = 'X'. MODIFY TAB TRANSPORTING FLAG WHERE FLAG IS INITIAL. Deleting a sequence of lines DO 101 TIMES. DELETE TAB_DEST INDEX 450.
  • 138. 138 ENDDO. DELETE TAB_DEST FROM 450 TO 550. Linear search vs. binary READ TABLE TAB WITH KEY K = 'X'. READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH. Comparison of internal tables DESCRIBE TABLE: TAB1 LINES L1, TAB2 LINES L2. IF L1 <> L2. TAB_DIFFERENT = 'X'. ELSE. TAB_DIFFERENT = SPACE. LOOP AT TAB1. READ TABLE TAB2 INDEX SY-TABIX. IF TAB1 <> TAB2. TAB_DIFFERENT = 'X'. EXIT. ENDIF. ENDLOOP. ENDIF. IF TAB_DIFFERENT = SPACE. " ... ENDIF. IF TAB1[] = TAB2[]. " ... ENDIF.
  • 139. 139 Modify selected components LOOP AT TAB. TAB-DATE = SY-DATUM. MODIFY TAB. ENDLOOP. WA-DATE = SY-DATUM. LOOP AT TAB. MODIFY TAB FROM WA TRANSPORTING DATE. ENDLOOP. Appending two internal tables LOOP AT TAB_SRC. APPEND TAB_SRC TO TAB_DEST. ENDLOOP APPEND LINES OF TAB_SRC TO TAB_DEST. Deleting a set of lines LOOP AT TAB_DEST WHERE K = KVAL. DELETE TAB_DEST. ENDLOOP DELETE TAB_DEST WHERE K = KVAL. Tools available in SAP to pin-point a performance problem  The runtime analysis (SE30)  SQL Trace (ST05)  Tips and Tricks tool  The performance database
  • 140. 140 Optimizing the load of the database Using table buffering Using buffered tables improves the performance considerably. Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed. These statements are:  Select DISTINCT  ORDER BY / GROUP BY / HAVING clause  Any WHERE clause that contains a sub query or IS NULL expression  JOIN s  A SELECT... FOR UPDATE If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause. Use the ABAP SORT Clause Instead of ORDER BY The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server. If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it. Avoid the SELECT DISTINCT Statement As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
  • 141. 141 PERFORMANCE TUNING IN SAP Few points that should be noted by a developer while writing a piece of code to Develop a good quality object with high performance. For checking the performance of any object the transaction that should be used are:-  ST05  SE30.  SE30: ABAP Runtime Analysis 1. On running the transaction, the object name or the transaction associated to it must be specified as follows and then execute the same.
  • 142. 142 Fig: 1.0 2. The screen below (Fig 1.0.1) shall appear once the code is executed and when you come back to the SE30 transaction screen by clicking “Back” button in the menu. Once you reach the Fig 1.0 screen, click on the “Analyze” button. This screen shows a bar diagram that indicates the system time utilized by the code (in microseconds) which is classified under three categories:-  ABAP Time  Database Time  R/3 System Time
  • 143. 143 Fig 1.0.1 Out of the three mentioned time’s the ABAP & Database Time can be controlled by proper usage of the ABAP & SQL statements respectively which is mentioned in the later half of this document. 3. Now to get a detail analysis of the time utilized by each and every ABAP statement in your code click on the button at the top left most corner of the Fig 1.0.1. The detail analysis is as follows:- Fig: 1.0.2
  • 144. 144  ST05: Trace Request  Under this transaction there are several Trace Modes of which SQL trace checkbox needs to be checked to know the performance of each and every select query written in a piece of code. Fig: 1.0  After checking the check box against the SQL Trace one has to switch on the trace request which can be done in two ways:- Fig: 2.0 1. Trace on: The SQL trace shall be on for the particular object that needs to be tested under the developers Username. Fig: 2.0.1 2. Trace on for user: The SQL trace shall be on for the particular object that needs to be tested under the developers Username with filter.
  • 145. 145 Fig: 2.0.2 The difference between the two buttons can be explained by the following example:- If a code is been executed by several users at the same time and if “Trace on” button is clicked then the performance analysis that shall be shown will be a effect of execution of that code for more than one scenario by different users at the same time. Else if the same code is been executed by many users at the same time and if “Trace on for user button” is clicked then the performance analysis that shall be shown will be only for the scenario under that particular user for which the code is executed. Now if you are clicking the “Trace On” button to ON the trace the only care that need to be taken before doing it is you need to be ready with all your inputs in the selection screen. Because if you ON the trace and then go to execute the object & fill the input fields, the time lapse between the Trace ON & Executing the code does effect the performance time. On clicking the “Trace on for user” button a popup window shall be flashed which shall ask for the object name or the transaction associated to it of which the performance needs to be tested. Fig: 2.0.3 On entering the object name the trace status shall be on as shown in the Fig 2.0.1 / Fig 2.0.2. Now the object needs to be executed with the desired inputs. Once it is executed then the trace need to be put off by clicking the “Trace off” button as shown in the Fig 2.0. To view the performance analysis of the object, click on the “List Trace” button as shown in the Fig 2.0. A popup window shall be flashed which is as follows:-
  • 146. 146 Fig: 2.0.4 Now on clicking enter a Basic Trace List screen shall appear which shall possess the analysis of all the select queries in that particular object. Fig: 2.0.5 Now place the cursor on the Object name against the Op. = REOPEN and click the “Explain” button as shown in the Fig 2.0.5. On clicking the same the Execution plan for SQL statement shall be displayed.
  • 147. 147 Fig: 2.0.6 In the Fig 2.0.6, it is seen that the estimated cost = 1 and the estimated rows = 1. For a SQL statement to be performance tuned the Estimated Cost of it should be tending to 1 and the Estimated Rows must be equal to the no. of desired rows that need to be fetched from the DB Table. So to make the SQL statement in your code performance tuned we need to check its Estimated Cost and Estimated Rows values. To make it tend to the desired values mentioned above the following points need to be taken care by the developer while writing the code:- i. Complete conditions are specified in the where clause taking care of all the primary keys and the order of it in the DB table. ii. SELECT INTO TABLE is used instead of SELECT & APPEND. iii. SELECT SINGLE is used instead of SELECT….ENDSELECT. iv. SELECT * need to be avoided in case of fetching only few fields from the DB table. Instead mention the field names that need to be fetched. v. Usage of AGGREGATE functions (MAX, MIN, SUM, COUNT, etc) must be minimum. vi. SELECT into CORRESPONDING-FIELDS should be avoided in case of few records being selected vii. Internal table is not empty check must be done before using FOR ALL ENTRIES in a SELECT query. viii. SELECT queries using FOR ALL ENTRIES must use the key fields. ix. Multiple identical SELECTs must be avoided on the same DB table. Instead the data must be fetched at one go into a global internal table and later on this internal table should be used for further processing. x. Avoid using JOINS in SELECT queries for more than three DB tables. xi. Avoid using SELECT inside a LOOP ….ENDLOOP statement. xii. MOVE statement must be used instead of MOVE-CORRESPONDING. xiii. Usage of IS/IS NOT INITIAL instead of hard code values. xiv. Already existing INDEXES associated with the DB tables must be used as they help in making the search faster. INDEXES
  • 148. 148  Now if you click on ECMCT~1 in the Fig 2.0.6 the detailed information of the index 1 defined for the ECMCT table shall be displayed as in the Fig 2.0.7(below). It indicates the usage of the Index of ECMCT table in your SQL statement. If in the Execution Plan you find ECMCT~0 it means that the basic primary keys of the table are used. Fig: 2.0.7  Clicking on ECMCT in the execution plan displays the following information of the indexes associated with the ECMCT table. To get the detailed Index Statistics click on the “Index Statistics” Button in the Fig 2.0.8 (below).
  • 149. 149 Fig: 2.0.8 xv. Performance tips specifically with Internal Tables:-  Unnecessary sorting must be avoided.  READ TABLE must be used with BINARY SEARCH.  It must be Cleared / Refreshed wherever necessary.  APPEND to be used instead of COLLECT.  Usage of Memory ID should be minimal & freed immediately after use.  CLEAR the Header Line / Work Area after the APPEND statement.  CLEAR Header Line after DELETE statement.
  • 150. 150 Introduction to ALV Classic Reporting Astep-by-stepprogramming guide to ALV reports BY
  • 152. 152 INTRODUCTION SAP has introduced a lot of new technologies with Release 4.6. All of these are designed to have a more pleasing user interface and make the work of the developer easier by automating many of the standard functionalities, which was needed to be coded explicitly earlier. Along with automation, the new technologies also bring with it a host of new and powerful features. But to use these features you have to master them. It is similar to saying that if you have a Formula 1 Ferrari, the thrill is only if you can drive it at 200 kms/hr. ALV or the SAP LIST VIEWER is one such technology. It is a tool for making reports with a better and standardized interface. All clients want the latest of technologies to be used for their implementation and our client was no exception. We initially found the going tough because there is hardly any documentation on ALV with the small exception of a few sample codes on the Internet. But with hard work and an exploring attitude we (the SAP MAM Team of Transco ODC) developed a fair amount of competency in ALV. This document is in a way, the documentation of our learnings. This document is NOT a comprehensive work on ALV. Indeed, there are many features that we discover every week. This manual gives an introduction to ALV and on how a person can write simple ALV reports. It has been written with FULL code dumps and screen shots so that there is no scope for confusion. It tries to give the initial impetus required to venture into further exploration of the technology. There is no doubt that you will find newer features and ‘smarter’ way of doing things in ALV. It is our request to you to document these learnings and contribute to the EAS Knowledge Base. Remember, Rome was not built in a day. With this let us put our best foot forward …
  • 153. 153 ABAP List Viewer – A summary of features Introduction: Why? In several business scenarios, we need to present data in a manner which  Is easily readable,  Is aesthetically appealing,  can be manipulated in various ways,  can be downloaded, and so on. Building these facilities manually is extremely time-consuming, and also creates major maintenance- hassles during the lifetime of the program. These problems are easily overcome by using generic, standard methodologies provided by SAP, so that we get all the facilities we need, and more at the mere click of the mouse, at the same time avoiding the maintenance work! Features: What can I do with ALV? 1. Simple list displays Display of data in rows/columns, with usual ALV facilities like sorting, etc., and provision for user-commands, drill-downs and so on. 2. Multi-level list displays Same as above, but we can now have a hierarchy – header and item level data display. Can we display greater than three levels? 3. Multiple list displays Several simple lists, displayed one after another. 4. Multiple, multi-level list displays Several hierarchical lists! 1. The simple list display a. Leading function-module i. REUSE_ALV_LIST_DISPLAY (the obsolete version) ii. REUSE_ALV_GRID_DISPLAY (the current version) These function modules take various internal table, and generate a standard display, on an ALV-standard screen. b. How to pass on the fields to be printed This is done by passing an internal table called the field-catalog. It consists typically of the  internal table-field name,  the output length,  the name to be displayed for the column,  the justification  formatting, like number of decimals, bold/normal and so on. Also, if we are using a data-dictionary structure for the display, we can avoid creating this internal table by making use of the function REUSE_ALV_FIELDCATALOG_MERGE. c. Layout details We can specify several layout-formatting options by passing this internal table to the function module, eg.,  Optimize width of columns  Minimum width of list output d. Sorting, sub-totalling
  • 154. 154 A separate internal table is maintained for specifying the sort-orders, which fields need subtotaling at different levels, what the name of each sub-total line would be, and so on. e. Event-handling A standard function-module, REUSE_ALV_EVENTS_GET can be used to fetch a list of events which are available for a given type of list. To capture an event like top-of-page, top-of-list, end-of-list, etc., we provide the leading function with an internal table, which maps the event-name in ALV, with a handler-form we create in the program for the particular event. In conjunction with this, we also need to provide the function-module with the program-name, where the form-routines reside. f. User-command handling One single form-name is passed as a parameter to the leading function-module. At any user-action like the clicking of a button, an enter-key hit, etc., this form-routine would be executed. In this routine, we can capture specific ok-codes, and handle the same. g. Drilldowns(popup) There’s a function-module REUSE_ALV_POPUP_TO_SELECT, which is used to display a popup, with a mini-list, from which specific rows/cells can be selected. The trigger for this would be a call from the user-command-handling routine. 2. The hierarchical display Very similar to the simple list display in terms of the parameters to be passed, but with a few minor additions which make it possible to display a hierarchy. a. Leading function-module REUSE_ALV_HIERSEQ_LIST_DISPLAY – there’s no grid display for this! We need to pass on two internal tables containing – one, the header data, and another, the item-details for each header. b. How to connect the tables There’s an internal table, in which we can specify upto five distinct field-names between the header and detail tables, which would be used for clubbing the detail-data into separate header-displays. 3. The block-list display a. Leading function-modules i. REUSE_ALV_BLOCK_LIST_INIT ii. REUSE_ALV_BLOCK_LIST_APPEND iii. REUSE_ALV_BLOCK_LIST_DISPLAY 4. The block-hierarchical display a. Leading function-modules i. REUSE_ALV_BLOCK_LIST_INIT ii. REUSE_ALV_BLOCK_HS_LIST_APPEND iii. REUSE_ALV_BLOCK_LIST_DISPLAY
  • 155. 155 Chapter 1 A Simple ALV Program TOPICS INTRODUCED A simple ALV program. REUSE_ALV_GRID_DISPLAY. Minimum parameters to be passed. Report ZSOMALV1: REPORT zsomalv1 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * This program shows a simple ALV display of the table QMEL. Use the * 'Pattern' button to write the call to function * 'REUSE_ALV_GRID_DISPLAY'. Pass the table i_qmel to the function. *----------------------------------------------------------------------* DATA: i_qmel LIKE qmel OCCURS 0. SELECT * FROM qmel INTO TABLE i_qmel. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' * I_CALLBACK_PROGRAM = ' ' * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' i_structure_name = 'QMEL' * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = * IS_LAYOUT = * IT_FIELDCAT = * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' * I_SAVE = ' ' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0
  • 156. 156 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_qmel EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. OUTPUT Any ALV program requires a minimum of two parameters to be passed to the function REUSE_ALV_GRID_DISPLAY.  Field Catalogue (Details of the format of the columns to be displayed in the report)  And the data to be populated in those columns. In the above case we are passing the name of the table itself (in place of the field catalogue which is discussed later). The function automatically creates the field catalogue in this case.
  • 157. 157 ALV automatically sets a standard PF-STATUS (the row of buttons above the report). With these you can do a lot of standard functions like send it by mail, sort, save as a local file etc). A common mistake that every beginner does is not to uncomment the ‘EXPORTING’ line of the function after writing it by the Pattern button. Due to it, the function does not recognize the structure name being passed to it. Chapter 2 Choosing and saving Layouts TOPICS INTRODUCED 1) How we can ensure that report allows the user to make, choose and save layouts (also called display variants). Optimize the column width to display data in the most efficient manner. Other options that can be specified for layouts. Report ZSOMALV2: REPORT zsomalv2 NO STANDARD PAGE HEADING. TYPE-POOLS: slis. DATA: report_id LIKE sy-repid. DATA: i_qmel LIKE qmel OCCURS 0. DATA: i_layout TYPE slis_layout_alv. SELECT * FROM qmel INTO TABLE i_qmel. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' i_structure_name = 'QMEL' * I_BACKGROUND_ID = ' ' * I_GRID_TITLE = * I_GRID_SETTINGS = is_layout = i_layout * IT_FIELDCAT = * IT_EXCLUDING = * IT_SPECIAL_GROUPS =
  • 158. 158 * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_qmel EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. ENDFORM. " F1000_Layout_Init
  • 159. 159 OUTPUT Difference in this program is the usage of a Type-Pool (SLIS). This type pool contains all the standard structures and tables (for eg. slis_alv_layout), which are to be populated and passed to REUSE_ALV_GRID_DISPLAY. It is a good idea to keep a printout of this type-pool when coding ALV programs. This is also included in this document as APPENDIX A. Other difference is that we are passing a value ‘A’ to the parameter i_save, Value range of parameter i_save can be, ' ' = No display variants can be saved 'X' = Only standard display variants can be saved 'U‘ = Only user-specific display variants can be saved 'A' = Standard and user-specific display variants can be saved Note that 2 other buttons have appeared in the PF-STATUS (Change Layout and Save layout). When you click on ‘Change Layout’, a window comes up where you can specify the sort order, which all columns to bedisplayed and other properties).
  • 160. 160 You can also sort the report using the sort buttons etc and click ‘Save Layout’. Then you are asked whether it is user specific or default. For all such interactive functions to work, we also need to pass the program ID (sy-repid) to ALV (I meant REUSE_ALV ….). But it should never be passed alone, only after assigning it to a variable. The final thing is the passing of layout specifications (i_layout) to ALV. Please refer to the other fields in the structure slis_layout_alv (it is combination of two structures which has more structures etc). Through them you can specify a host of other properties. For example, i_layout-zebra = ‘X’  This will result in the lines of the report having alternate colour. i_layout-no_vline = ‘X”  Columns are separated by space. i_layout-no_scrolling = ‘X”  Scrolling is disabled. We found that a lot of such options were not working. If you do further R&D on this; please document them and contribute to the EAS KB.
  • 161. 161 Chapter 3 Specifying a field Catalogue TOPICS INTRODUCED 1) Specify a heading for a report. Create a field catalogue for the report. In real life situations we will not need to simply display a table as we have been doing above. Most probably it will be an internal table with a specific set of fields from different tables and maybe plain integer or character fields. In such cases the simplest method to follow is to create an internal table (of the same structure as what is to be displayed in the report) with the data; pass it to ALV and also a field catalogue (also called fieldcat). Report ZSOMALV3: REPORT zsomalv3 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Specify a heading for a report. * 2. Create a field catalogue for the report. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: report_id LIKE sy-repid. DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'. DATA: i_layout TYPE slis_layout_alv. DATA: i_fieldcat TYPE slis_t_fieldcat_alv. SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' '
  • 162. 162 i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = * IT_EVENTS = * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMNUM'. " The field name and the table line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req. line_fieldcat-key = 'X'. " Specifies the column as a key (Blue) line_fieldcat-seltext_m = 'Notification No.'. " Column Header APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat.
  • 163. 163 line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMTXT'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Description'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_ROW'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Row Number'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_CHAR'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Test Character Field'. line_fieldcat-datatype = 'CHAR'. line_fieldcat-outputlen = '15'. " You can specify the width of a APPEND line_fieldcat TO i_fieldcat. " column. CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init
  • 164. 164 OUTPUT Over here we are purposely using a customized internal table which is being displayed in ALV. Notice that it contains two kinds of fields. Ones with DDIC (Data Dictionary Reference) and others without. The table we are using to create a field catalogue (i_fieldcat) is of type slis_t_fieldcat_alv. It is a table of structure slis_fieldcat_alv. Refer to the SLIS type-pool to get the other options that you can specify for a column. For example, line_fieldcat-icon = ‘X’  Specifies this column as a column of icons. You must then specify valid icon values for tnem to be shown in the report. line_fieldcat-lzero = ’X’  Allows leading zeroes to be shown for a number column. line_fieldcat-just = ‘R’  R – Justify right, L – Left, C – Centre. Etc. You can display a heading for the report using type lvc_title as shown. NOTE: The table i_fieldcat is passed to the parameter it_fieldcat of the function instead of i_structure_name as earlier.
  • 165. 165 Chapter 4 Initialize Events TOPICS INTRODUCED 1) Initialize events. 2) Execute a specific requirement when an event is triggered. 3) Use an event 'TOP_OF_PAGE' to write a header for the report. 4) REUSE_ALV_COMMENTARY WRITE. Report ZSOMALV4: REPORT zsomalv4 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Initialize events. * 2. Execute a specific requirement when an event is triggered. * 3. Use an event 'TOP_OF_PAGE' to write a header for the report. * 4. REUSE_ALV_COMMENTARY WRITE. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: report_id LIKE sy-repid. DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'. DATA: i_layout TYPE slis_layout_alv. DATA: i_fieldcat TYPE slis_t_fieldcat_alv. DATA: i_events TYPE slis_t_event. DATA: i_header TYPE slis_t_listheader. SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING
  • 166. 166 * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMNUM'. " The field name and the table line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req. line_fieldcat-key = 'X'. " Specifies the column as a key (Blue) line_fieldcat-seltext_m = 'Notification No.'. " Column Header
  • 167. 167 APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMTXT'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Description'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_ROW'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Row Number'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_CHAR'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Test Character Field'. line_fieldcat-datatype = 'CHAR'. line_fieldcat-outputlen = '15'. " You can specify the width of a APPEND line_fieldcat TO i_fieldcat. " column. CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init *&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------* FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'S'. gs_line-key = 'STATUS 1'. gs_line-info = 'This is line of type STATUS'. APPEND gs_line TO i_header. gs_line-key = 'STATUS 2'. gs_line-info = 'This is also line of type STATUS'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header *&---------------------------------------------------------------------*
  • 168. 168 *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init *---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header. ENDFORM. OUTPUT First let us discuss about events. As you may be aware, ABAP is a event driven language. Through ALV we can cause one or more things to occur when an event is triggered. Over here in the above example, we have defined the event TOP_OF_PAGE (By defining an event, I mean associating a form to it, which is executed when that event occurs).
  • 169. 169 To define an event, first declare a table of type slis_t_event and through a form (f4000_events_init) append lines to the table i_events. Each line is of type slis_alv_event and contains only two fields; the event and the associated form, which is executed upon that event. Later i_events is passed to ALV. To write a header, we use the function REUSE_ALV_COMMENTARY_WRITE. This function can be used to write headers or footers for reports. To this function we pass a table of the text that we want to be written in the report. It is of type slis_t_listheader. This is a table of rows, which can of three types, HEADER, STATUS or ACTION as defined in the type slis_listheader, which is a line item of slis_t_listheader. (P.S: Please don’t ask we why we have only three types. I don’t know!!) ALV supports 16 events. They are: 1. ITEM_DATA_EXPAND 2. REP 3. REP_SEL_MODIFY 4. CALLER_EXIT 5. USER_COMMAND 6. TOP_OF_PAGE 7. DATA_CHANGED 8. TOP_OF_COVERPAGE 9. END_OF_COVERPAGE 10. FOREIGN_TOP_OF_PAGE 11. FOREIGN_END_OF_PAGE 12. PF_STATUS_SET 13. LIST_MODIFY 14. TOP_OF_LIST 15. END_OF_PAGE 16. END_OF_LIST 17. AFTER_LINE_OUTPUT 18. BEFORE_LINE_OUTPUT 19. SUBTOTAL_TEXT
  • 170. 170 Chapter 5 Customize you PF Status TOPICS INTRODUCED 1) Learn about the ‘Standard’ PF-Status that comes as default. 2) Exclude function codes from ‘Standard’ PF-Status and customize it. In all the previous reports, we have seen that ALV displays a standard PF Status by default, which contains a bare minimum function codes (also called fcodes). This is helpful because we do not have to explicitly code the PF Status. Actually, this PF Status is the ‘STANDARD’ PF Status of the program SAPLSALV with 46 function codes excluded (disabled). Use transaction SE41 to view all the function codes. In most practical cases, we will need to exclude some function codes from the standard PF Status because they might be irrelevant to our report or because we may need to disable certain standard function codes. (For example, there are reports where the user must NOT be allowed to sort). In the following program we will see how we display the entire ‘STANDARD’ PF Status (including the 46 fcodes which are usually disabled) and also disable 4 of the fcodes. Report ZSOMALV5: REPORT zsomalv5 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Learn about the ‘Standard’ PF-Status that comes as default. * 2. Exclude function codes from ‘Standard’ PF-Status and customize it. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: report_id LIKE sy-repid. DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'. DATA: i_layout TYPE slis_layout_alv. DATA: i_fieldcat TYPE slis_t_fieldcat_alv. DATA: i_events TYPE slis_t_event. DATA: i_header TYPE slis_t_listheader. DATA: i_extab TYPE slis_t_extab. SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'.
  • 171. 171 LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data. ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'.
  • 172. 172 ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMNUM'. " The field name and the table line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req. line_fieldcat-key = 'X'. " Specifies the column as a key (Blue) line_fieldcat-seltext_m = 'Notification No.'. " Column Header APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMTXT'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Description'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_ROW'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Row Number'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_CHAR'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Test Character Field'. line_fieldcat-datatype = 'CHAR'. line_fieldcat-outputlen = '15'. " You can specify the width of a APPEND line_fieldcat TO i_fieldcat. " column. CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init *&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------* FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'S'. gs_line-key = 'STATUS 1'.
  • 173. 173 gs_line-info = 'This is line of type STATUS'. APPEND gs_line TO i_header. gs_line-key = 'STATUS 2'. gs_line-info = 'This is also line of type STATUS'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header *&---------------------------------------------------------------------* *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'PF_STATUS_SET'. line_event-form = 'F4200_PF_STATUS_SET'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init *---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header. ENDFORM. *---------------------------------------------------------------------* * FORM F4200_PF_STATUS_SET * *---------------------------------------------------------------------* FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab. REFRESH i_extab. PERFORM f4210_exclude_fcodes CHANGING i_extab. SET PF-STATUS 'STANDARD' OF PROGRAM 'SAPLSALV' EXCLUDING i_extab. ENDFORM. *&---------------------------------------------------------------------* *& Form f4210_exclude_fcodes *&---------------------------------------------------------------------* FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab. DATA: ws_fcode TYPE slis_extab. CLEAR ws_fcode. ws_fcode = '&EB9'. " Call up Report. APPEND ws_fcode TO i_extab. ws_fcode = '&ABC'. " ABC Analysis. APPEND ws_fcode TO i_extab. ws_fcode = '&NFO'. " Info Select. APPEND ws_fcode TO i_extab. ws_fcode = '&LFO'. " Information.
  • 174. 174 APPEND ws_fcode TO i_extab. ENDFORM. " f4210_exclude_fcodes OUTPUT For starters, declare a new internal table ( i_extab) of type slis_t_extab. This will contain all the function codes, which should be excluded from the PF Status. Initialize a new event called PF_STATUS_SET by assigning a form to it. Inside this form (F4200_PF_STATUS_SET), first refresh the table i_extab, which gets populated by the names of the 46 function codes that are populated by default by ALV. Then call a form, which populates i_extab with the names of the 4 fcodes. Finally set the PF Status.
  • 175. 175 Chapter 6 Process callback events TOPICS INTRODUCED 1) Add customized buttons (function codes) to ‘Standard’ PF Status. 2) Customize the processing of such events. In many cases, we may need to add buttons (function codes) to our PF status and assign a code that will be executed when that function code is triggered. We can either create our own PF status or copy the STANDARD pf status of program SAPLSALV creating our own to which we can add buttons and function codes. Report ZSOMALV6: REPORT zsomalv6 NO STANDARD PAGE HEADING. *Description-----------------------------------------------------------* * TOPICS INTRODUCED: * 1. Add customized buttons (function codes) to ‘Standard’ PF Status. * 2. Customize the processing of such events. *----------------------------------------------------------------------* TYPE-POOLS: slis. DATA: BEGIN OF i_data OCCURS 0, qmnum LIKE qmel-qmnum, qmart LIKE qmel-qmart, qmtxt LIKE qmel-qmtxt, ws_row TYPE i, ws_char(5) TYPE c, chk, END OF i_data. DATA: report_id LIKE sy-repid. DATA: ws_title TYPE lvc_title VALUE 'An ALV Report'. DATA: i_layout TYPE slis_layout_alv. DATA: i_fieldcat TYPE slis_t_fieldcat_alv. DATA: i_events TYPE slis_t_event. DATA: i_header TYPE slis_t_listheader. DATA: i_extab TYPE slis_t_extab. SELECT qmnum qmart qmtxt INTO TABLE i_data FROM qmel WHERE qmnum <= '00030000010'. LOOP AT i_data. i_data-ws_row = sy-tabix. i_data-ws_char = 'AAAAA'. MODIFY i_data.
  • 176. 176 ENDLOOP. report_id = sy-repid. PERFORM f1000_layout_init CHANGING i_layout. PERFORM f2000_fieldcat_init CHANGING i_fieldcat. PERFORM f3000_build_header CHANGING i_header. PERFORM f4000_events_init CHANGING i_events. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' i_callback_program = report_id * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_CALLBACK_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * i_structure_name = ' ' * I_BACKGROUND_ID = ' ' i_grid_title = ws_title * I_GRID_SETTINGS = is_layout = i_layout it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT = * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' i_save = 'A' * IS_VARIANT = it_events = i_events * IT_EVENT_EXIT = * IS_PRINT = * IS_REPREP_ID = * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * IT_ALV_GRAPHICS = * IT_ADD_FIELDCAT = * IT_HYPERLINK = * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = i_data EXCEPTIONS program_error = 1 OTHERS = 2 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form F1000_Layout_Init *&---------------------------------------------------------------------* FORM f1000_layout_init USING i_layout TYPE slis_layout_alv. CLEAR i_layout. i_layout-colwidth_optimize = 'X'. i_layout-edit = 'X'. ENDFORM. " F1000_Layout_Init *&---------------------------------------------------------------------* *& Form f2000_fieldcat_init
  • 177. 177 *&---------------------------------------------------------------------* FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv. DATA: line_fieldcat TYPE slis_fieldcat_alv. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMNUM'. " The field name and the table line_fieldcat-tabname = 'I_DATA'. " name are the two minimum req. line_fieldcat-key = 'X'. " Specifies the column as a key (Blue) line_fieldcat-seltext_m = 'Notification No.'. " Column Header APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMART'. line_fieldcat-ref_tabname = 'I_DATA'. line_fieldcat-hotspot = 'X'. " Shows the field as a hotspot. line_fieldcat-seltext_m = 'Notif Type'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'QMTXT'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Description'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_ROW'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_m = 'Row Number'. APPEND line_fieldcat TO i_fieldcat. CLEAR line_fieldcat. line_fieldcat-fieldname = 'WS_CHAR'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Test Character Field'. line_fieldcat-datatype = 'CHAR'. line_fieldcat-outputlen = '15'. " You can specify the width of a APPEND line_fieldcat TO i_fieldcat. " column. CLEAR line_fieldcat. line_fieldcat-fieldname = 'CHK'. line_fieldcat-tabname = 'I_DATA'. line_fieldcat-seltext_l = 'Checkbox'. line_fieldcat-checkbox = 'X'. " Display this field as a checkbox line_fieldcat-edit = 'X'. " This option ensures that you can " edit the checkbox. Else it will " be protected. APPEND line_fieldcat TO i_fieldcat. ENDFORM. " f2000_fieldcat_init *&---------------------------------------------------------------------* *& Form f3000_build_header *&---------------------------------------------------------------------* FORM f3000_build_header USING i_header TYPE slis_t_listheader. DATA: gs_line TYPE slis_listheader. CLEAR gs_line. gs_line-typ = 'H'. gs_line-info = 'This is line of type HEADER'. APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'S'. gs_line-key = 'STATUS 1'. gs_line-info = 'This is line of type STATUS'. APPEND gs_line TO i_header. gs_line-key = 'STATUS 2'. gs_line-info = 'This is also line of type STATUS'.
  • 178. 178 APPEND gs_line TO i_header. CLEAR gs_line. gs_line-typ = 'A'. gs_line-info = 'This is line of type ACTION'. APPEND gs_line TO i_header. ENDFORM. " f3000_build_header *&---------------------------------------------------------------------* *& Form f4000_events_init *&---------------------------------------------------------------------* FORM f4000_events_init CHANGING i_events TYPE slis_t_event. DATA: line_event TYPE slis_alv_event. CLEAR line_event. line_event-name = 'TOP_OF_PAGE'. line_event-form = 'F4100_TOP_OF_PAGE'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'PF_STATUS_SET'. line_event-form = 'F4200_PF_STATUS_SET'. APPEND line_event TO i_events. CLEAR line_event. line_event-name = 'USER_COMMAND'. line_event-form = 'F4300_USER_COMMAND'. APPEND line_event TO i_events. ENDFORM. " f3000_events_init *---------------------------------------------------------------------* * FORM F4100_TOP_OF_PAGE * *---------------------------------------------------------------------* FORM f4100_top_of_page. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING it_list_commentary = i_header. ENDFORM. *---------------------------------------------------------------------* * FORM F4200_PF_STATUS_SET * *---------------------------------------------------------------------* FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab. REFRESH i_extab. PERFORM f4210_exclude_fcodes CHANGING i_extab. * The PF status is an exact copy of the PF status 'STANDARD' of program * SAPLSALV but with command 'CHNG' added to it. SET PF-STATUS 'ZSOM_STANDARD' EXCLUDING i_extab. ENDFORM. *&---------------------------------------------------------------------* *& Form f4210_exclude_fcodes *&---------------------------------------------------------------------* FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab. DATA: ws_fcode TYPE slis_extab. CLEAR ws_fcode. ws_fcode = '&EB9'. " Call up Report. APPEND ws_fcode TO i_extab. ws_fcode = '&ABC'. " ABC Analysis. APPEND ws_fcode TO i_extab.
  • 179. 179 ws_fcode = '&NFO'. " Info Select. APPEND ws_fcode TO i_extab. ws_fcode = '&LFO'. " Information. APPEND ws_fcode TO i_extab. ENDFORM. " f4210_exclude_fcodes *&---------------------------------------------------------------------* *& Form f4300_user_command *&---------------------------------------------------------------------* FORM f4300_user_command USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield. CASE ucomm. WHEN '&IC1'. "Double Click line Item READ TABLE i_data INDEX selfield-tabindex. IF i_data-qmnum NE space. SET PARAMETER ID 'IQM' FIELD i_data-qmnum. CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN. CLEAR ucomm. ENDIF. WHEN 'CHNG'. " Change Notification Icon READ TABLE i_data INDEX selfield-tabindex. IF i_data-qmnum NE space. SET PARAMETER ID 'IQM' FIELD i_data-qmnum. CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN. CLEAR ucomm. ENDIF. ENDCASE. CLEAR ucomm. ENDFORM. " f4300_user_command OUTPUT In this program, first we created a PF status (ZSOM_STANDARD), which was an exact copy of STANDARD of program SAPLSALV through transaction SE41 (Menu Painter). Then we added another button to it (circled in white) with a new fcode called ‘CHNG’. Creation of PF status is not covered in this document, as it is available in any standard ABAP material. After this this we set this PF status instead of STANADRD. We initialize a third event USER_COMMAND and associate a form with it. In this form we can capture the function codes and write any functionality under it. If we write functionality for an
  • 180. 180 existing fcode, then this gets precedence over the default functionality that might be associated with it. In this example, we capture a standard fcode ‘&IC1’ that is nothing but double clicking a line of the report. We are capturing the notification number of that line and calling transaction IW52 with it. We are also doing the same when a user clicks on the new ‘Change Notification’ button. When the user clicks the “Back’ button in IW52, it comes back to the report.
  • 181. 181 Chapter 7 Sort Catalogue TOPICS INTRODUCED 1) Define a sort catalogue for a report. 2) Sort a report using a sort catalogue. Creating a sort catalogue is very similar to creating a field catalogue. In it we can specify the fieldnames, table names, order of sorting, whether it should be sorted ascending or descending. The steps to be taken are, first declare an internal table ( i_sort ) of type slis_t_sortinfo_alv. This is a table of the structure slis_sortinfo_alv. Then create the sort catalogue in a form which is to be called before the call to ALV. (i.e. REUSE_ALV_GRID_DISPLAY) *&---------------------------------------------------------------------* *& Form f5000_sortcat_init *&---------------------------------------------------------------------* form f5000_sortcat_init changing i_sortcat TYPE slis_t_sortinfo_alv.. DATA: line_sortinfo TYPE slis_sortinfo_alv. CLEAR line_sortinfo. line_sortinfo-fieldname = 'QMART'. line_sortinfo-tabname = 'I_DATA'. line_sortinfo-spos = 1. " First sort by this field. line_sortinfo-down = 'X'. " Descending APPEND line_sortinfo TO i_sortcat. line_sortinfo-fieldname = 'WS_ROW'. line_sortinfo-tabname = 'I_DATA'. line_sortinfo-spos = 2. " Second sort by this field. line_sortinfo-up = 'X'. " Ascending APPEND line_sortinfo TO i_sortcat. endform. " f5000_sortcat_init Then pass i_sortcat to ALV through the parameter it_sort. it_fieldcat = i_fieldcat * IT_EXCLUDING = * IT_SPECIAL_GROUPS = IT_SORT = i_sortcat * IT_FILTER = * IS_SEL_HIDE = * I_DEFAULT = 'X' In form F4200_pf_status_set, change the setting of the PF status to, SET PF-STATUS 'ZSOM_STANDARD' OF PROGRAM 'ZSOMALV6' EXCLUDING i_extab. Or else you will get an error. This is because this PF status was created for program ZSOMALV6.
  • 182. 182 OUTPUT In this example we have sorted the above list first by notification type (QMART) descending and then by row number (WS_ROW) ascending. Do note the small red arrows that come up in the column header indicating the type of sort. The usage of a sort catalogue is actually not required !! This is also the reason why I have decided to put it towards the last. Just sort the internal data table (i_data) in the required manner before passing it to ALV and it will be displayed as shown above. The only difference is that the red arrows won’t be there. . In short the statement, SORT i_data BY qmart DESCENDING ws_row ASCENDING. Is enough to replace all the code written above !!
  • 183. 183 Appendix A Type-Pool ‘SLIS’ type-pool slis . ">>Y9CK015723 types: begin of slis_lvc_s_bds_extended, bytesize type int4, EXTOBJID type char255, "Y9CK016268 end of slis_lvc_s_bds_extended. types: begin of slis_lvc_s_bds2. include type lvc_s_bds. include type slis_lvc_s_bds_extended. types: end of slis_lvc_s_bds2. types: slis_lvc_t_bds2 type slis_lvc_s_bds2 occurs 1. "<<Y9CK015723 ">>Y9CK016292 *Trace Extern-Intern-Konvertierung types: begin of slis_lvc_s_expa, OP type CHAR4, EXTERN type LVC_VALUE, INTERN type LVC_VALUE, *INCLUDE type RSCONVLITE ACTIVE type RSSCR_CFLG, OLENGTH type RSSCR_OLEN, DECIMALS type RSDECIMALS, SIGN type SIGNFLAG, LOWER type RSSCR_LOWC, CONVEXIT type CONVEXIT, *INCLUDE type TABFIELD TABNAME type TABNAME, FIELDNAME type FIELDNAME, LFIELDNAME type FNAM_____4, CURRENCY type CHAR30, end of slis_lvc_s_expa. *Textstruktur(ALV-Batch) types: begin of slis_lvc_s_1022, line(1022) type c, end of slis_lvc_s_1022. *Text-Tabelle(ALV Batch) types: slis_lvc_t_1022 type slis_lvc_s_1022 occurs 1. *Ausgabefiles types: begin of slis_lvc_s_fils, FILENAME type CHAR255, SIZE type INT4, MIMETYPE type CHAR128, PRIMARY type FLAG, BINARY type FLAG, end of slis_lvc_s_fils. *Filestruktur types: slis_lvc_t_fils type slis_lvc_s_fils occurs 1. *Mimetype-Mapping types: begin of slis_lvc_s_mima, MIMETYPE type CHAR128, BINARY type FLAG,
  • 184. 184 end of slis_lvc_s_mima. *ALV: Mime-Mapping types: slis_lvc_t_mima type slis_lvc_s_mima occurs 1. *ALV-W3Text types: slis_lvc_t_text type w3html occurs 1. *X255-Tabelle types: slis_lvc_t_mime type w3mime occurs 1. *Tabelle X1022 types: slis_lvc_t_x1022 type bapiconten occurs 1. "<<Y9CK016292 types: slis_list_type(1) type n, slis_char_1(1) type c, slis_text40(40) type c. types: slis_tabname(30) type c, slis_fieldname(30) type c, slis_sel_tab_field(60) type c, slis_formname(30) type c, slis_entry(60) type c, slis_edit_mask(60) type c, slis_coldesc(4) type c. *types: begin of slis_filtered_entries, * index type i, * end of slis_filtered_entries. types: slis_t_filtered_entries type i occurs 0. *--- Structure for additional fieldcat types: begin of slis_add_fieldcat, fieldname type slis_fieldname, web_field type slis_fieldname, href_hndl type i, end of slis_add_fieldcat. types: slis_t_add_fieldcat type slis_add_fieldcat occurs 0. *--- Structure for reprep-initialization types: begin of slis_reprep_id, tool(2) type c, appl(4) type c, subc(2) type c, onam(54) type c, end of slis_reprep_id. types: begin of slis_reprep_communication, stop(1) type c, end of slis_reprep_communication. *** Structure for colors types: begin of slis_color, col type i, int type i, inv type i, end of slis_color. types: begin of slis_coltypes, heacolfir type slis_color, " heading_cols_first heacolnex type slis_color, " heading_cols_nex hearowfir type slis_color, " heading_rows_first hearownex type slis_color, " heading_rows_next lisbodfir type slis_color, " list_body_first lisbodnex type slis_color, " list_body_next lisbod type slis_color, " list_body higcolkey type slis_color, " highlight_col_key higcol type slis_color, " highlight_col higrow type slis_color, " highlight_row
  • 185. 185 higsum type slis_color, " highlight_sum higsumhig type slis_color, " highlight_sum_high higsumlow type slis_color, " highlight_sum_low higins type slis_color, " highlight_inserted higpos type slis_color, " highlight_positive higneg type slis_color, " highlight_negative hig type slis_color, " highlight heahie type slis_color, " heading_hier lisbodhie type slis_color, " list_body_hierinfo end of slis_coltypes. *** Fieldcat types: begin of slis_fieldcat_main0, row_pos like sy-curow, " output in row col_pos like sy-cucol, " position of the column fieldname type slis_fieldname, tabname type slis_tabname, currency(5) type c, cfieldname type slis_fieldname, " field with currency unit ctabname type slis_tabname, " and table ifieldname type slis_fieldname, " initial column quantity(3) type c, qfieldname type slis_fieldname, " field with quantity unit qtabname type slis_tabname, " and table round type i, " round in write statement exponent(3) type c, " exponent for floats key(1) type c, " column with key-color icon(1) type c, " as icon symbol(1) type c, " as symbol checkbox(1) type c, " as checkbox just(1) type c, " (R)ight (L)eft (C)ent. lzero(1) type c, " leading zero no_sign(1) type c, " write no-sign no_zero(1) type c, " write no-zero no_convext(1) type c, edit_mask type slis_edit_mask, " emphasize(4) type c, " emphasize fix_column(1) type c, " Spalte fixieren do_sum(1) type c, " sum up no_out(1) type c, " (O)blig.(X)no out tech(1) type c, " technical field outputlen like dd03p-outputlen, offset type dd03p-outputlen, " offset seltext_l like dd03p-scrtext_l, " long key word seltext_m like dd03p-scrtext_m, " middle key word seltext_s like dd03p-scrtext_s, " short key word ddictxt(1) type c, " (S)hort (M)iddle (L)ong rollname like dd03p-rollname, datatype like dd03p-datatype, inttype like dd03p-inttype, intlen like dd03p-intlen, lowercase like dd03p-lowercase, end of slis_fieldcat_main0. types: begin of slis_fieldcat_main1, ref_fieldname like dd03p-fieldname, ref_tabname like dd03p-tabname, roundfieldname type slis_fieldname, roundtabname type slis_tabname, decimalsfieldname type slis_fieldname, decimalstabname type slis_tabname, decimals_out(6) type c, " decimals in write statement text_fieldname type slis_fieldname, reptext_ddic like dd03p-reptext, " heading (ddic) ddic_outputlen like dd03p-outputlen, end of slis_fieldcat_main1. types: begin of slis_fieldcat_main. include type slis_fieldcat_main0. include type slis_fieldcat_main1. types: end of slis_fieldcat_main.
  • 186. 186 types: begin of slis_fieldcat_alv_spec, key_sel(1) type c, " field not obligatory no_sum(1) type c, " do not sum up sp_group(4) type c, " group specification reprep(1) type c, " selection for rep/rep input(1) type c, " input edit(1) type c, " internal use only hotspot(1) type c, " hotspot end of slis_fieldcat_alv_spec. types: begin of slis_fieldcat_alv. include type slis_fieldcat_main. include type slis_fieldcat_alv_spec. types: end of slis_fieldcat_alv. types: begin of slis_fieldcat_alv1. include type slis_fieldcat_main1. types: end of slis_fieldcat_alv1. types: slis_t_fieldcat_alv type slis_fieldcat_alv occurs 1. * Events for Callback types: begin of slis_event_exit. types: ucomm like sy-ucomm, before(1) type c, after(1) type c, end of slis_event_exit. types: slis_t_event_exit type slis_event_exit occurs 1. * Callback Interface structure for non display subtotals text types: begin of slis_subtot_text, criteria type slis_fieldname, keyword like dd03p-reptext, criteria_text(255) type c, max_len like dd03p-outputlen, display_text_for_subtotal(255) type c, end of slis_subtot_text. *** Layout types: begin of slis_print_alv0, print(1) type c, " print to spool prnt_title(1) type c, " moment to print the title end of slis_print_alv0. types: begin of slis_print_alv1, no_print_selinfos(1) type c, " display no selection infos no_coverpage(1) type c, " no_new_page(1) type c, " reserve_lines type i, " lines reserved for end of page no_print_listinfos(1) type c, " display no listinfos no_change_print_params(1) type c, " don't change linesize no_print_hierseq_item(1) type c, "don't expand item end of slis_print_alv1. types: begin of slis_print_alv. include type alv_s_prnt. include type slis_print_alv1. types: end of slis_print_alv. types: begin of slis_layout_main, dummy, end of slis_layout_main. types: begin of slis_layout_alv_spec0, no_colhead(1) type c, " no headings no_hotspot(1) type c, " headings not as hotspot zebra(1) type c, " striped pattern no_vline(1) type c, " columns separated by space cell_merge(1) type c, " not suppress field replication edit(1) type c, " for grid only
  • 187. 187 edit_mode(1) type c, " for grid only numc_sum(1) type c, " totals for NUMC-Fields possib. no_input(1) type c, " only display fields f2code like sy-ucomm, " reprep(1) type c, " report report interface active no_keyfix(1) type c, " do not fix keycolumns expand_all(1) type c, " Expand all positions no_author(1) type c, " No standard authority check * PF-status def_status(1) type c, " default status space or 'A' item_text(20) type c, " Text for item button end of slis_layout_alv_spec0. types: begin of slis_layout_alv_spec1, * Display options colwidth_optimize(1) type c, no_min_linesize(1) type c, " line size = width of the list min_linesize like sy-linsz, " if initial min_linesize = 80 max_linesize like sy-linsz, " Default 250 window_titlebar like sy-title, no_uline_hs(1) type c, * Exceptions lights_fieldname type slis_fieldname," fieldname for exception lights_tabname type slis_tabname, " fieldname for exception lights_rollname like dfies-rollname," rollname f. exceptiondocu lights_condense(1) type c, " fieldname for exception * Sums no_sumchoice(1) type c, " no choice for summing up no_totalline(1) type c, " no total line no_subchoice(1) type c, " no choice for subtotals no_subtotals(1) type c, " no subtotals possible no_unit_splitting type c, " no sep. tot.lines by inh.units totals_before_items type c, " diplay totals before the items totals_only(1) type c, " show only totals totals_text(60) type c, " text for 1st col. in total line subtotals_text(60) type c, " text for 1st col. in subtotals * Interaction box_fieldname type slis_fieldname, " fieldname for checkbox box_tabname type slis_tabname," tabname for checkbox box_rollname like dd03p-rollname," rollname for checkbox expand_fieldname type slis_fieldname, " fieldname flag 'expand' hotspot_fieldname type slis_fieldname, " fieldname flag hotspot confirmation_prompt, " confirm. prompt when leaving key_hotspot(1) type c, " keys as hotspot " K_KEYHOT flexible_key(1) type c, " key columns movable,... group_buttons(1) type c, " buttons for COL1 - COL5 get_selinfos(1) type c, " read selection screen group_change_edit(1) type c, " Settings by user for new group no_scrolling(1) type c, " no scrolling * Detailed screen detail_popup(1) type c, " show detail in popup detail_initial_lines(1) type c, " show also initial lines detail_titlebar like sy-title," Titlebar for detail * Display variants header_text(20) type c, " Text for header button default_item(1) type c, " Items as default * colour info_fieldname type slis_fieldname, " infofield for listoutput coltab_fieldname type slis_fieldname, " colors * others list_append(1) type c, " no call screen xifunckey type aqs_xikey, " eXtended interaction(SAPQuery) xidirect type flag, " eXtended INTeraction(SAPQuery) dtc_layout type dtc_s_layo, "Layout for configure the Tabstip end of slis_layout_alv_spec1. types: begin of slis_layout_alv_spec. include type slis_layout_alv_spec0. include type slis_layout_alv_spec1. types: end of slis_layout_alv_spec.
  • 188. 188 types: begin of slis_layout_alv. include type slis_layout_main. include type slis_layout_alv_spec. types: end of slis_layout_alv. types: begin of slis_layout_alv1. include type slis_layout_main. include type slis_layout_alv_spec1. types: end of slis_layout_alv1. *--- Structure for the excluding table (function codes) types: begin of slis_extab, fcode like rsmpe-func, end of slis_extab. *--- Lineinfo before output types: begin of slis_lineinfo, tabname type slis_tabname, tabindex like sy-tabix, subtot(1) type c, subtot_level(2) type n, endsum(1) type c, sumindex like sy-tabix, linsz like sy-linsz, linno like sy-linno, end of slis_lineinfo. *--- Structure for scrolling in list types: begin of slis_list_scroll, lsind like sy-lsind, cpage like sy-cpage, staro like sy-staro, staco like sy-staco, cursor_line like sy-curow, cursor_offset like sy-cucol, end of slis_list_scroll. * information cursor position ALV types: begin of slis_selfield, tabname type slis_tabname, tabindex like sy-tabix, sumindex like sy-tabix, endsum(1) type c, sel_tab_field type slis_sel_tab_field, value type slis_entry, before_action(1) type c, after_action(1) type c, refresh(1) type c, ignore_multi(1) type c, " ignore selection by checkboxes (F2) col_stable(1) type c, row_stable(1) type c, * colwidth_optimize(1) type c, exit(1) type c, fieldname type slis_fieldname, grouplevel type i, collect_from type i, collect_to type i, end of slis_selfield. *--- excluding table types: slis_t_extab type slis_extab occurs 1. * special groups for column selection types: begin of slis_sp_group_alv, sp_group(4) type c, text(40) type c, end of slis_sp_group_alv. types: slis_t_sp_group_alv type slis_sp_group_alv occurs 1. * information for sort and subtotals types: begin of slis_sortinfo_alv, * spos(2) type n, spos like alvdynp-sortpos, fieldname type slis_fieldname, tabname type slis_fieldname,
  • 189. 189 * up(1) type c, * down(1) type c, * group(2) type c, * subtot(1) type c, up like alvdynp-sortup, down like alvdynp-sortdown, group like alvdynp-grouplevel, subtot like alvdynp-subtotals, comp(1) type c, expa(1) type c, obligatory(1) type c, end of slis_sortinfo_alv. types: slis_t_sortinfo_alv type slis_sortinfo_alv occurs 1. * information for selections types: begin of slis_seldis1_alv, field like dfies-fieldname, table like dfies-tabname, stext(40), valuf(80), valut(80), sign0(1), optio(2), ltext(40), stype(1), length type p, no_text(1), inttype like dfies-inttype, fieldname type slis_fieldname, tabname type slis_tabname, org_selname type rsscr_name, "introduced this FO 09.01.00 end of slis_seldis1_alv. types: slis_seldis_alv type slis_seldis1_alv occurs 1. * filter types: begin of slis_filter_alv0, fieldname type slis_fieldname, tabname type slis_tabname, seltext(40), valuf(80), valut(80), valuf_int(80), valut_int(80), sign0(1), sign_icon(4), optio(2), stype(1), decimals like dfies-decimals, intlen like dfies-intlen, convexit like dfies-convexit, edit_mask type slis_edit_mask, lowercase like dfies-lowercase, inttype like dfies-inttype, datatype like dfies-datatype, exception(1) type c, no_sign(1) type c, or(1) type c, order type order, cqvalue(5) type c, end of slis_filter_alv0. types: begin of slis_filter_alv1, ref_fieldname like dfies-fieldname, ref_tabname like dfies-tabname, ddic_outputlen like dfies-outputlen, end of slis_filter_alv1. types: begin of slis_filter_alv. include type slis_filter_alv0. include type slis_filter_alv1. types: end of slis_filter_alv.
  • 190. 190 types: slis_t_filter_alv type slis_filter_alv occurs 1. * delete or add an entry in the select-option info types: begin of slis_selentry_hide_alv, mode(1) type c, "(D)elete (A)dd selname like rsparams-selname. include type slis_seldis1_alv. types end of slis_selentry_hide_alv. types: slis_t_selentry_hide_alv type slis_selentry_hide_alv occurs 1. * delete or add an entry in the select-option info types: begin of slis_sel_hide_alv, mode(1) type c, "(R)eplace or (C)hange t_entries type slis_t_selentry_hide_alv, end of slis_sel_hide_alv. * Header table for top of page types: begin of slis_listheader, typ(1) type c, " H = Header, S = Selection, A = Action key(20) type c, info type slis_entry, end of slis_listheader. types: slis_t_listheader type slis_listheader occurs 1. *--- Structure for specific color settings types: begin of slis_specialcol_alv, fieldname type slis_fieldname, color type slis_color, nokeycol(1) type c, end of slis_specialcol_alv. types: slis_t_specialcol_alv type slis_specialcol_alv occurs 1. *--- Structure for event handling types: begin of slis_alv_event, name(30), form(30), end of slis_alv_event. types: slis_t_event type slis_alv_event occurs 0. *--- Structure for key information types: begin of slis_keyinfo_alv, header01 type slis_fieldname, item01 type slis_fieldname, header02 type slis_fieldname, item02 type slis_fieldname, header03 type slis_fieldname, item03 type slis_fieldname, header04 type slis_fieldname, item04 type slis_fieldname, header05 type slis_fieldname, item05 type slis_fieldname, end of slis_keyinfo_alv. *--- Structure for callback CALLER_EXIT and REUSE_ALV_POPUP_TO_SELECT types: begin of slis_data_caller_exit, dummy like sy-repid, without_load_variant(1), callback_header_transport type slis_formname, columnopt(1), end of slis_data_caller_exit. types: begin of slis_status, callback_program like sy-repid, callback_pf_status_set type slis_formname, callback_user_command type slis_formname, counter_of_lists_added type i, actual_list_to_display type i, flg_to_be_refreshed, it_excluding type slis_t_extab, print type slis_print_alv, flg_checkboxes_active, flg_overview_active, flg_intcheck(1) type c, end of slis_status. * Exporting structure types: begin of slis_exit_by_user,
  • 191. 191 back(1) type c, exit(1) type c, cancel(1) type c, end of slis_exit_by_user. constants: * Events slis_ev_item_data_expand type slis_formname value 'ITEM_DATA_EXPAND', slis_ev_reprep_sel_modify type slis_formname value 'REPREP_SEL_MODIFY', slis_ev_caller_exit_at_start type slis_formname value 'CALLER_EXIT', slis_ev_user_command type slis_formname value 'USER_COMMAND', slis_ev_top_of_page type slis_formname value 'TOP_OF_PAGE', slis_ev_data_changed type slis_formname value 'DATA_CHANGED', slis_ev_top_of_coverpage type slis_formname value 'TOP_OF_COVERPAGE', slis_ev_end_of_coverpage type slis_formname value 'END_OF_COVERPAGE', slis_ev_foreign_top_of_page type slis_formname value 'FOREIGN_TOP_OF_PAGE', slis_ev_foreign_end_of_page type slis_formname value 'FOREIGN_END_OF_PAGE', slis_ev_pf_status_set type slis_formname value 'PF_STATUS_SET', slis_ev_list_modify type slis_formname value 'LIST_MODIFY', slis_ev_top_of_list type slis_formname value 'TOP_OF_LIST', slis_ev_end_of_page type slis_formname value 'END_OF_PAGE', slis_ev_end_of_list type slis_formname value 'END_OF_LIST', slis_ev_after_line_output type slis_formname value 'AFTER_LINE_OUTPUT', slis_ev_before_line_output type slis_formname value 'BEFORE_LINE_OUTPUT', slis_ev_subtotal_text type slis_formname value 'SUBTOTAL_TEXT'.
  • 192. 192 Appendix B How to colour lines of a report 1. Include a 4-character field in the internal data table that is being passed to REUSE_ALV_GRID_DISPLAY. Eg: DATA: BEGIN OF i_data OCCURS 10, qmnum LIKE viqmel-qmnum, qmart LIKE viqmel-qmart, zzvalstat LIKE viqmel-zzvalstat, valstattxt LIKE zawprcode-valstattxt, kunum LIKE viqmel-kunum, bstnk LIKE viqmel-bstnk, qmtxt LIKE viqmel-qmtxt, ws_color(4)TYPE c, END OF i_data. 2. In the code, loop through the lines of the internal table and assign values to this field. The 4- character value will be of the format - Cxyz. Char 1 – is always C indicating that it’s a color property. Char 2 (x) – color code, which can be any value from (1 – 7). Char 3 (y) – Intensity on/off. (1 = on, 0 = off). Char 4 (z) – Inverse display on/off. (1 = on, 0 = off). (From the above, it is clear that we can have only 28 different coloring options) Eg: C401. LOOP AT i_data. IF (expression 1). i_data-ws_color = ‘C510’. ELSEIF(expression 2). i_data-ws_color = ‘C200’. ELSE. i_data-ws_color = ‘C711’. ENDIF. MODIFY i_data. ENDLOOP. 3. When specifying the layout properties, specify the name of this field (ws_color) as the color field. FORM f1200_define_layout CHANGING p_i_layout TYPE slis_layout_alv. CLEAR p_i_layout. p_i_layout-zebra = 'X'. p_i_layout-colwidth_optimize = 'X'. p_i_layout-info_fieldname = 'WS_COLOR'.
  • 193. 193 ENDFORM. " F1200_define_layout Example: Shown below is screen dump with 14 coloring options. You could try out the rest 14!! Code: LOOP AT i_data. cnt = cnt + 1. IF cnt = 1. i_data-ws_color = 'C110'. ELSEIF cnt = 2. i_data-ws_color = 'C210'. ELSEIF cnt = 3. i_data-ws_color = 'C310'. ELSEIF cnt = 4. i_data-ws_color = 'C410'. ELSEIF cnt = 5. i_data-ws_color = 'C510'. ELSEIF cnt = 6. i_data-ws_color = 'C610'. ELSEIF cnt = 7. i_data-ws_color = 'C710'. elseIF cnt = 8. i_data-ws_color = 'C100'. ELSEIF cnt = 9. i_data-ws_color = 'C200'. ELSEIF cnt = 10 i_data-ws_color = 'C300'. ELSEIF cnt = 11. i_data-ws_color = 'C400'. ELSEIF cnt = 12. i_data-ws_color = 'C500'. ELSEIF cnt = 13. i_data-ws_color = 'C600'. ELSEIF cnt = 14. i_data-ws_color = 'C700'. ENDIF. MODIFY i_data. ENDLOOP.
  • 195. 195 Controlling the Screen Flow Overview For the user, a transaction is a series of screens that appear one after another. In the transaction program, screens are chained together by a series of “next-screen” numbers. When you define the transaction, you specify the number of the first screen. Then, for each screen in the transaction, you can specify a “next screen” statically or dynamically: Static screen pointers When you define a screen, you specify a Next screen attribute for it. This attribute gives the name of the screen that is to follow the current screen by default. However, the static attribute is overridden whenever a “next-screen” is set dynamically. Transaction Attributes Name: TZ40 First Screen: Screen 100 Screen 200 Next Screen = 200 Next Screen = 0 Static Screen Chain END
  • 196. 196 Dynamic screen sequence Any screen can set its own “next screen” as part of screen processing. The ABAP/4 commands for doing this are SET SCREEN and CALL SCREEN. When you set screens dynamically, you can string them together one after the other (as in a chain), or insert groups of them into the current chain. The following topics provide information on handling screens in a transaction: Introduction to Screen Flow Control Setting the Next Screen Calling a New Screen Sequence Leaving the Current Screen Example Transaction: Setting and Calling Screens Processing Screens in Background
  • 197. 197 Introduction to Screen Flow Control As an example of controlling screen flow in a transaction, look at transaction TZ40. (This transaction is in development class SDWA and is delivered with the system.) TZ40 lets users display flight information and enter updates into the display. TZ40 uses two screens and a dialog box (popup window) for getting user updates. The transaction always displays the first two screens (numbers 100 and 200). The third (210) however only appears under certain conditions. The possible flow of screens looks as follows: Screen 100 Screen 200 Screen 210 Possible Screen Flow In practice, the user sees the following sequence: Screen 100: The user enters flight information and presses ENTER to request a display of flight details. Screen 200: The system displays complete details about the flight, in update mode. The user types over the display to enter the changes.
  • 198. 198 Screen 210 Screen 210 appears only if the user tries to exit screen 200 without saving. The popup reminds the user to save the changes or cancel them (by specifying Yes or No).
  • 199. 199 To make this sequence of screens possible, transaction TZ40 must be able to call the dialog box screen conditionally. An ABAP/4 module can “branch to” or “call” the next screen. The difference lies in where you want control to go after processing the next screen. The relevant ABAP/4 commands are: SET SCREEN <screen-number>. CALL SCREEN <screen-number>. LEAVE SCREEN. LEAVE TO SCREEN <screen-number>. With SET SCREEN, the current screen simply specifies the next screen in the chain. Control branches to this next screen as soon as the current screen has been processed. Return from next screen to current screen is not automatic. With CALL SCREEN, the current (calling) chain is suspended, and a next screen (or screen chain) is called in. The called screen can then return to the suspended chain with the statement LEAVE SCREEN TO SCREEN 0. For complete information, see: Setting the Next Screen Calling a New Screen Sequence Leaving the Current Screen
  • 200. 200 Setting the Next Screen Every screen has a static Next screen attribute that specifies the next screen to follow the current one. You can override this specification by using the SET SCREEN statement: SET SCREEN <screen number>. SET SCREEN tells the system to ignore the statically defined Next screen and use <screen number> as the next screen instead. Screen 100 Next Screen = 110 Screen 200 Next Screen = 210 Screen 110 Screen 210 SET SCREEN 200 Next Screen = 120 Next Screen = 220 Screen 120 Next Screen = 130 Screen 220 Next Screen = 0 SET SCREEN This override is temporary and has no effect on the attribute values stored in the Screen Painter . A SET SCREEN statement merely specifies the next screen: it does not interrupt processing of the current screen. If you want to branch to the next screen without finishing the current one, use LEAVE SCREEN. Note Note that you can specify the next-screen number with a variable: DATA: REQSCRN LIKE SY-DYNNR VALUE ‘100’. MODULE SET_NEXT_SCREEN. SET SCREEN REQSCRN. ENDMODULE. The system field SY-DYNNR always contains the number of the current screen.
  • 201. 201
  • 202. 202 Calling a New Screen Sequence Sometimes you want to insert a screen, or a whole sequence of screens, into the course of a transaction. For instance, you might want to let an user call a popup screen from the main application screen to let them enter secondary information. After they have completed their entries, the users should be able to close the popup and return directly to the place where they left off in the main screen. There are two methods for doing this: use the CALL SCREEN statement The CALL SCREEN statement lets you insert such a sequence into the current one. Using this statement is described here. call a dialog module A dialog module is a callable sequence of screens that does not belong to a particular transaction. Dialog modules have their own module pools, and can be called by any transaction. For information on using dialog modules, see Calling Dialog Modules. The syntax for calling up a new screen sequence is: CALL SCREEN <screen number>. You can think of CALL SCREEN as “stacking” a sequence, since the statement actually suspends the current sequence and starts a new one. The system continues with the new sequence until it is finished, at which point the suspended sequence is resumed. (Processing resumes with the statement directly after the CALL SCREEN.) Screen 100 Next Screen = 110 Screen 200 Next Screen = 210 Screen 110 CALL SCREEN 200 . . . Next Screen = 120 Screen 210 Next Screen = 220 Screen 120 Screen 220 Next Screen = 130 Next Screen = 0 CALL SCREEN
  • 203. 203
  • 204. 204 To call a screen as a dialog box (popup), use CALL SCREEN with the options STARTING AT, ENDING AT: CALL SCREEN <screen number> STARTING AT <start column> <start line> ENDING AT <end column> <end line> The STARTING AT and ENDING AT options tell the system where to position the popup screen. The screen itself must be smaller than a regular screen. In the ABAP/4 world, each stackable sequence of screens is a “call mode”. This is important because of the way you return from a given current sequence. To terminate a call mode and return to a suspended chain, set the “next screen” to 0 and leave to it: LEAVE TO SCREEN 0. or SET SCREEN 0. LEAVE SCREEN. When you return to the suspended chain, execution resumes with the statement directly following the original CALL SCREEN statement. The original sequence of screens in a transaction is itself a calling mode. If you LEAVE TO SCREEN 0 in this sequence (that is, without having stacked any additional call modes), you return from the transaction altogether. Note You can have up to 9 calling modes stacked at one time. Leaving the Current Screen To discontinue processing for the current screen, use: LEAVE TO SCREEN <screen number>. or SET SCREEN <number>. LEAVE SCREEN. Both of these statements terminate processing for the current screen and go directly to <screen number>. If you use SET SCREEN without LEAVE SCREEN, the program finishes processing for the current screen before branching to <screen number>. If you use LEAVE SCREEN without a SET SCREEN before it, you terminate the current screen and branch directly to the screen specified as the default next- screen in the screen attributes. In “calling mode”, the special screen number 0 (LEAVE TO SCREEN 0) causes the system to jump back to the previous call level. That is, if you have called a screen sequence with CALL SCREEN, leaving to screen 0 terminates the sequence and returns to the calling screen. If you have not called a screen sequence, LEAVE TO SCREEN 0 terminates the transaction. For information on CALL SCREEN, see Calling a New Screen Sequence.
  • 205. 205
  • 206. 206 Example Transaction: Setting and Calling Screens To see a complete implementation of screen flow control, it is useful to look at how transaction TZ40 (development class SDWA) is organized. Screen Flow Logic To demonstrate how a transaction branches to or calls a screen, look at processing for screen 200. The handling of the exit commands (function codes BACK and EXIT) shows how. When handling a BACK or EXIT function code, the PAI module must check whether flight details have changed since the screen display or last save. If so, screen 200 must call up the popup 210 to prompt about saving. The relevant parts of the screen 200’s flow logic are: *---------------------------------------------------------------* * Screen 200: Flow Logic * *&--------------------------------------------------------------* PROCESS AFTER INPUT. MODULE EXIT_0200 AT EXIT-COMMAND. * (...<Field checks here>...) MODULE USER_COMMAND_0200. ABAP/4 Code The PAI modules for screen 200 follow. Transaction TZ40 offers all the return functions (Back , Exit and Cancel) as exit-commands. In Screen 200, however, only the Cancel function allows immediate exit from the screen. To effect a cancel, standard exit logic is used to tell the system to go back to screen 100:
  • 207. 207 *&---------------------------------------------------------------* *& Module EXIT_0200 INPUT *&---------------------------------------------------------------* MODULE EXIT_0200 INPUT. CASE OK_CODE. WHEN ’CANC’. CLEAR OK_CODE. SET SCREEN 100. LEAVE SCREEN. ENDCASE. ENDMODULE. All other function codes for screen 200 are handled as follows: The SAVE function triggers an update of the database. The EXIT and BACK functions trigger calls to the SAFETY_CHECK routine. This routine checks for unsaved data in the screen, and reminds the user to save if necessary. Note the return technique. For the EXIT function, control returns from the transaction altogether (SET SCREEN 0). For the BACK function, the previous screen is set as the following screen. (SET SCREEN 100). *&---------------------------------------------------------------* *& Module USER_COMMAND_0200 INPUT *&---------------------------------------------------------------* MODULE USER_COMMAND_0200 INPUT. CASE OK_CODE. WHEN ’SAVE’. UPDATE SPFLI. IF SY-SUBRC = 0. MESSAGE S001 WITH SPFLI-CARRID SPFLI-CONNID. ELSE. MESSAGE A002 WITH SPFLI-CARRID SPFLI-CONNID. ENDIF. CLEAR OK_CODE. WHEN ’EXIT’. CLEAR OK_CODE. PERFORM SAFETY_CHECK USING RCODE. IF RCODE = ’EXIT’. SET SCREEN 0. LEAVE SCREEN. ENDIF. WHEN ’BACK’. CLEAR OK_CODE. PERFORM SAFETY_CHECK USING RCODE. IF RCODE = ’EXIT’. SET SCREEN 100. LEAVE SCREEN. ENDIF. ENDCASE. ENDMODULE. Code for the SAFETY_CHECK routine follows. The CHECK statement compares current screen values to the saved screen values. If the values match, no save is needed, and the routine terminates. If the values differ, SAFETY_CHECK calls the popup screen 210. The popup asks the user if he wants to save, and returns the answer (SAVE, EXIT and CANC) in the OK_CODE. *---------------------------------------------------------------*
  • 208. 208 * Subroutine SAFETY_CHECK * *----------------------------------------------------------- ----* FORM SAFETY_CHECK USING RCODE. LOCAL OK_CODE. RCODE = ’EXIT’. CHECK SPFLI NE OLD_SPFLI. CLEAR OK_CODE. CALL SCREEN 210 STARTING AT 10 5. CASE OK_CODE. WHEN ’SAVE’. UPDATE SPFLI. WHEN ’EXIT’. WHEN ’CANC’. CLEAR SPFLI. ENDCASE. ENDFORM. Processing Screens in Background You can suppress entire screens using SUPPRESS DIALOG. This command allows you to perform screen processing "in the background". The system carries out all PBO and PAI logic, but does not display the screen to the user. Suppressing screens is useful when you are branching to list-mode from a transaction dialog step. Use the SUPPRESS DIALOG command in the first module called from the screen’s PBO logic. For example: **** ABAP/4 module processing for Screen 100 CALL SCREEN 110 STARTING AT 10 5 **** Screen 110 flow logic PROCESS BEFORE OUTPUT. MODULE DIALOG_WINDOW. **** ABAP/4 module processing MODULE DIALOG_WINDOW OUTPUT. SUPPRESS DIALOG. LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0. WRITE: / WRITE: / ENDMODULE. The SUPPRESS DIALOG statement lets you use the processing context for screen 110 as a framework for displaying the standard list output. If you don’t use SUPPRESS DIALOG here, screen 110 is displayed, and is empty. When the user presses ENTER, the standard list output is displayed.
  • 209. 209 Tab Strip Controls through ABAP by Sreenivas Palakurty 1. Introduction: Tab Strips allow us to easily define different components of an application on a single screen and navigate between them. Instead of navigating between many screens, the user at once sees all the destinations he or she must call to accomplish the given task. Let us consider the example of a tab strip which we see very often. Author Vijay Sai Vempati Reviewer Review Date Version 1.0
  • 210. 210 Fig 1: Example of a Tab Strip As the figure shows, there are different tabs like General, Computer name, Hardware, Advanced etc in a single dialog box. Each of these tabs shows us a different display with customizations as per the user requirements. The task of the user is simplified to a great extent as the need for navigating between the screens is reduced. This BOK intends to explain the creation of Tab Strip Controls through: 1) Report Programming. 2) Dialog Programming. 2. Components of a Tab Strip: The main components of a Tab Strip are: 2.1 Tab Titles: They refer to the name of the tab and are generally sorted from left to right according to the workflow. Incase there are more number of tab titles than can be displayed; the R/3 system automatically displays scroll buttons for horizontal scrolling at the upper right margin. The R/3 system does not support multiple-line tab titles. If multiple lines were used instead of the scroll buttons, due to the language dependency of the titles a different number of tab title lines would appear for each logon language. Since the tab page is of fixed size, the developer would have to save as many blank lines above the tab
  • 211. 211 strip as might be needed under worst conditions. This would waste screen space and reduce readability. 2.2 Tab Page: The Screen Painter locks the first line of a tab page, which the system needs to draw the tab titles. Otherwise, the layout rules for creating screens apply. A tab strip requires three additional screen lines for the tab titles line, the lower border, and the locked first line. A tab page together with the tab titles texts corresponds to a group box. Therefore, you need no further box that includes all fields of a tab page. 2.3 Environment: The tab strip should be provided with a constant environment. This means that if you go from one tab page to another, the menu bar and the application bar must not change. 2.4 Navigation: The user perceives a screen that contains a tab strip as a unit. The individual tab pages thus are components of the screen, such as boxes of groups of fields. 3. Programming the Tab Strips: Tab Strips can be programmed either through Report or Dialog. 3.1 Report Programming: The Tab Strip controls can be made through report programming by defining sub screens in the selection screen and assigning the user command to the tab titles. Example:
  • 212. 212 Fig 2: Example of a Tab Strip control through Report Program For the Tab Strip Control of fig 2, there are three sub screens which were initially defined.The piece of code which creates the sub screen within the selection screen is written below: The statement “selection-screen begin of screen <<screen no>> as sub screen” defines sub screen in the selection screen. In this way, we can define as many sub screens as required on the selection screen in which the tab strip control is included. The code given below maps the tab strip controls with the sub screens. selection-screen begin of screen 100 as subscreen. selection-screen begin of block b1 with frame. parameters: p1(10) type c, p2(10) type c, p3(10) type c. selection-screen end of block b1. selection-screen end of screen 100. selection-screen: begin of tabbed block mytab for 10 lines, tab (20) button1 user-command push1, tab (20) button2 user-command push2, tab (20) button3 user-command push3, selection-screen end of block mytab.
  • 213. 213 The statement “selection-screen begin of tabbed block <<block>> for n lines” maps the sub screens with the defined Tab Strip Control <<block>>. n defines the number of lines in the sub screen area. The statement “selection-screen end of block <<block>>” closes the block opened. Inside the tabbed block, we create the tab page and assign the function code to it. “selection-screen tab (len) tabname user-command ucomm” creates a tab page with name tabname and length len and assigns the function code ucomm to it. In the above example button-1, button-2 and button-3 refer to the tab names and push1, push2 and push3 refer to the function codes assigned to the respective tabs. The tab names are entered as text elements through the following path: Goto  Text elements  Text symbols. The following piece of code assigns the tab names to the text elements: The next step in the process is to determine the active tab at the runtime. This is obtained by defining the active tab page and the sub screen number. Consider the following piece of code. button1 = text-010. button2 = text-020. button3 = text-060. initialization. mytab-prog = sy-repid. mytab-dynnr = 100. mytab-activetab = 'BUTTON1'.
  • 214. 214 In the above code, we are defining the active tab as Button 1 which is the sub screen 100. mytab-activetab = ‘BUTTON1’ activates the tab title whose function code is BUTTON1. So, when we run the program and enter the selection screen, the default tab will be BUTTON1. The next step in the process is the navigation of the screens within the Tab Strip controls. Consider the following piece of code: Depending upon the tab selected, the corresponding sub screen should be shown for further processing or entering the required data. Whenever a tab name is selected, the corresponding sub screen should be called and the active tab has to be the tab name, as seen in the above example. This is how we create Strip controls through Report programming. at selection-screen. case sy-ucomm. when 'PUSH1'. mytab-dynnr = 100. mytab-activetab = 'BUTTON1'. when 'PUSH2'. mytab-dynnr = 200. mytab-activetab = 'BUTTON2'. when 'PUSH3'. mytab-dynnr = 300. mytab-activetab = 'BUTTON3'. endcase.
  • 215. 215 3.2Dialog Programming: Initially the tab strip has to be defined in the screen painter. Execute the following steps to create a simple tab strip: 1) Set the tab strip borders. 2) Define tab titles. 3) Define and allocate the sub screen area. 4) Program the flow logic. 3.2.1 Set the tab Strip borders: After creating the tab strip, set the borders i.e. length and height of the tab strip control. Incase of a Graphical Screen painter determine the area by dragging the mouse over the screen. Incase of a non-graphical screen painter enter manually the length and height of the tab strip. 3.2.2 Define Tab Titles: By default, the new tab strip contains two tab titles. Technically, tab titles are treated like pushbuttons. This becomes obvious when you double-click on a tab title in the attributes window. For each tab title, enter field name, field text, and function code. 3.2.3 Define and allocate the sub screen area: Each tab title must be allocated to a sub screen area. In order to do this, select a tab title and create a sub screen in it.
  • 216. 216 Fig 3: Tab Strip Control element As an example, in the above figure, the sub screen SUBSCR1 is assigned to the tab strip with tabs TAB1 and TAB2. 3.2.4 Program the Flow Logic: The sub screens which are used in the program are to be included as follows: In the module pool, declare the tab strip similar to the table control using the CONTROLS Statement. PROCESS BEFORE OUTPUT. ... CALL SUBSCREEN <area> INCLUDING <program> <screen>. ... PROCESS AFTER INPUT. ... CALL SUBSCREEN <area>. CONTROLS: MYTABSTRIP
  • 217. 217 In the above example, MYTABSTRIP is the field name of the tab strip in the screen painter. At runtime, at present only the attribute ACTIVETAB is available, which determines the currently active tab page. You fill it with the function code of the corresponding tab title. To activate the tab title whose function code is ‘F1’, use the statement: In the Process after input, we check for the tab which is pressed and then execute the tab strip as per the fcode. A typical code for that looks as follows: This is how we generate Tab Strip controls through Dialog Programming. MYTABSTRIP-ACTIVETAB = ‘F1’ MODULE FCODE. CASE OK_CODE. WHEN ‘TAB1’. DYNPRONR = ‘0200’. TABSTRIP1-ACTIVETAB = OK_CODE. CLEAR OK-CODE WHEN ‘TAB2’. DYNPRONR = ‘0300’. TABSTRIP1-ACTIVETAB = OK_CODE. ....
  • 218. 218 Submitted by: Sreenivas Palakurty Introduction to SMARTFORMS
  • 219. 219 Table of Contents Introduction Purpose of this Introduction…………………………………………. 220 Who will benefit………………………………………………………. 220 Prerequisites…………………………………………………………… 220 refresher on sapscript………………………………………………… 3 Smart Forms: What is it?……………………………………………… 221 SmartForms Vs SAP Script…………………………………………… 221 Main Advantages of Smart Forms…………………………………… 221 features introduced by sap in smart forms………………………… 4 architecture of sap smartform……………………………………… 5 hands on screen sequence smartforms……………….……………………………………………. 7 page and windows……………………………………………………… 12 smartstyle……………………………………………………………… 28 template………………………………………………………………… 38 config setting…………………………………………………………... 54 refresher on smartforms : summary……………………………… 58
  • 220. 220 Introduction Purpose of this Introduction This introduction is intended to allow a quick entry into the work with the Smart Forms. SAP introduced SmartForms in 1998 to overcome the limitations in SAP Scripts. This document would help a beginner to start from scratch and generate his own Smart Forms. There is a self help screen sequence to guide the beginners to create Smartforms of their own and gain confidence Who will benefit All SAP users. Most of the new projects would be using this technology. Clients would increasingly demand smartforms to be used rather than sapscript. Prerequisites The user should know SAP Script. In this document I would briefly compare SAP script with SAP SMART Forms, highlighting the prominent features before moving on to how to work with SMART Forms, which is our focus. SAP Script is SAP text management and form printing tool. By this we make a output look beautiful which is cumbersome to do by a report program. SAPscript consists of the following components: An editor for entering and editing text Styles and forms for designing the print layout A composer, which is the central module for output formatting A programming interface for integrating SAPscript components in your own application programs and programming the output using forms Various database tables for storing texts, styles and forms REFRESHER ON SAP SCRIPT WE can insert picture or Logo (Company Logo) in the output, which is not possible by report program.
  • 221. 221 Smart Forms: What is it? We use SAP Smart Forms to create and maintain forms for mass printing in SAP Systems. SmartForms are easier to develop, maintain and transport than SAP Script. As output medium SAP Smart Forms support a printer, a fax, e-mail, or the Internet (by using the generated XML output).In addition to the tool, SAP delivers a selection of forms for central business processes like forms in the applications SD,FI, HR and CRM of the R/3 Release. SmartForms Vs SAP Script Multiple page formats are possible in smartforms which is not the case in SAPScripts It is possible to have a smartform without a main window . Labels cannot be created in smartforms. Routines can be written in smartforms tool. Smartforms generates a function module when activated. Main Advantages of Smart Forms: SAP Smart Forms offer the following advantages: Creating and maintaining forms requiring half the time Adapting forms without any programming knowledge due to entirely graphical user interface Web Publishing using the generated XML output The SAP Smart Forms has replaced the SAPscript forms. SAPscript forms will also be supported in the future; you can use them without making any changes for years to come. You can use SAPscript texts in the Smart Forms. Migration of SAPscript forms into Smart Forms is supported. Features introduced by SAP in Smart Forms: THE SMART FORMS ALLOW THE USER TO EXECUTE SIMPLE MODIFICATIONS TO THE FORM AND IN THE FORM LOGIC BY USING SIMPLE GRAPHICAL TOOLS. NOTE
  • 222. 222 TO PRINT A FORM THE USER WILL NEED A PROGRAM FOR THE DATA RETRIEVAL AND A SMART FORM THAT CONTAINS THE ENTIRE FORM LOGIC. AS THESE TWO ARE SEPARATE WE SHOULD ADAPT THE SMART FORM IF CHANGES TO THE FORM LOGIC IS NECESSARY. THE APPLICATION PROGRAM PASSES THE DATA VIA A FUNCTION MODULE INTERFACE TO THE SMART FORM. WHEN ACTIVATING THE SMART FORM THE SYSTEM AUTOMATICALLY GENERATES THE FUNCTION MODULE AND AT THE RUNTIME PROCESS THIS. THE USER DESIGNS THE FORM USING THE GRAPHICAL FORM PAINTER AND THE GRAPHICAL TABLE PAINTER. THE FORM LOGIC IS REPRESENTED BY THE HIERARCHICAL STRUCTURE THAT CONSISTS OF INDIVIDUAL NODES, SUCH AS NODES FOR GLOBAL SETTINGS, NODES FOR TEXTS, NODES FOR OUTPUT TABLES OR NODES FOR GRAPHICS. TO MAKE ANY CHANGES WE HAVE TO USE THE DRAG&DROP, CUT&PASTE. THESE ACTIONS DO NOT INCLUDE WRITING OF CODING LINES OR USING A SCRIPT LANGUAGE. FOR WEB PUBLISHING, THE SYSTEM PROVIDES A GENERATED XML OUTPUT OF THE PROCESSED FORM. WE CAN INSERT STATIC AND DYNAMIC TABLES. THESE INCLUDE THE LINE FEEDS IN THE INDIVIDUAL TABLE CELLS, TRIGGERING EVENTS FOR TABLE HEADINGS AND SUBTOTALS AND SORTING DATA BEFORE OUTPUT. THE SMART FORMS ALLOW THE USER TO INCLUDE GRAPHICS, WHICH CAN BE DISPLAYED AS A PART OF THE FORM OR AS BACKGROUND GRAPHICS. DURING PRINTOUT THE USER CAN SUPPRESS THE BACKGROUND GRAPHIC AS AND WHEN NECESSARY. THE SMART FORMS ALSO SUPPORTS THE POSTAGE OPTIMIZING.
  • 223. 223 Form Description Data Retrieval Database SMART FORM Activate ABAP FUNCTION MODULE APPLICATION PROGRAM Database Selection Function Module Call Later Selection OUTPUT (Printer) Architecture of SAP Smart Form : Schematic Flow
  • 224. 224 IN A SMART FORM WE DESCRIBE: THE LAYOUT OF THE FORM (ELEMENT POSITIONS ON A PAGE). INDIVIDUAL ELEMENTS TO BE DISPLAYED, FOR EX: TEXT, GRAPHICS, ADDRESSES, TABLES ETC., THE FORM LOGIC, FOR EXAMPLE TO READ THE APPLICATION DATA FROM INTERNAL TABLES, TO INTRODUCE CONDITIONS AND TO CONTROL THE PROCESS FLOWS. A FORM INTERFACE TO TRANSFER THE APPLICATION DATA TO FORM DEFINITION. WHEN A SMART FORM IS ACTIVATED , THE SYSTEM GENERATES A FUNCTION MODULE THAT ENCAPSULATES ALL THE ATTRIBUTES OF THE SMART FORM. AS SOON AS THE APPLICATION PROGRAM CALLS THE FUNCTION MODULE, THE SMART FORM USES THE MODULE INTERFACE TO TRANSFER ANY TABLE DATA PREVIOUSLY SELECTED AND TO PRINT THE FORM ACCORDING TO THE FORM DESCRIPTION. ALL THESE WILL BECOME CLEARER ONCE WE GO THROUGH THE SELF HELP SCREEN SEQUENCE IN THE SUBSEQUENT PAGES.
  • 225. 225 Hands On Guide: This is a self-help guide lucidly illustrated with tips, meant for beginners. We first go to SAP Menu: The path is SAP Menu  Tools  Form Printout  Smart Forms The transaction code (T code) : Smart Forms Lets use forms starting with ‘BC’ as SAP has created these for training purposes. click
  • 226. 226 Let’s use BC470_FLOWS to demonstrate the various elements of Smart Forms. WE NOW ARRIVE AT THE DISPLAY FORM SCREEN, WHICH IS DIVIDED, INTO 3 MAIN SECTIONS: click
  • 227. 227 NAVIGATION WINDOW, FORM PAINTER AND MAINTENANCE WINDOW. WEWILL DISCUSS EACH OF THESE IN DETAIL  Navigation window consist of nodes and sub nodes. They contain all the elements (text, window etc) that belong to sap forms.  Maintenance window shows attributes of the elements  Form printer window shows the layout of the page.
  • 228. 228 GLOBAL SETTING IS AT THE FORM LEVEL. YOU CAN ACCESS THESE FROM ANYWHERE IN THE SMART FORM You can change the language by changing this field in Form Attribute: this will change the text language (but not the layout). Form interface tells us what are the import and export parameters, exceptions, tables etc that we SAPscript does not allow changing the language. SAP FORMS gives the user this option. Also whenever we create smart forms, SAP creates/generates a function module. NOTE
  • 229. 229 pass to the function module. These we can add but we cannot change/modify the default values Lets add a Global Database for practice. I have created NUMC_DATE through TYPES
  • 230. 230 new type created in TYPES
  • 231. 231 Global definition is what we define in smart form. We can define our own variable, constants etc. that we can access in the code that we write. Here we would use we of the types, which we have defined earlier (char_fifteen) to declare ‘CLERK’.
  • 232. 232 Diff between TYPE and TYPES TYPES: What we create: char, constants etc. TYPE is used to choose from standard SAP data type Pages and Windows In smart form, page is at the highest level: SAP processes the first page, next page and then Terms General Terms and Conditions…if u wish to change the order, just drag and drop the sequence. What we created in ‘Types’ is being used to declare a variable.
  • 233. 233 1 OF 10 ETC initialize or increase counter
  • 234. 234 Conditional break…next page of next page become ‘term’ page (SAP stops processing / execution of this page) U can define print mode globally for all the pages instead of declaring this at each page
  • 235. 235 NOW LETS CREATE OUR OWN SMART FORM LET’S COPY A STANDARD SMART FORM [BC470_FLOWS]OF SAP AND CREATE ZBC470_FLOWS_AVID. THEN WEWOULD PLAY AROUND WITH ITS DIFFERENT ELEMENTS. LETS CREATE A NEW PAGE IN OUR OBJECT.
  • 236. 236 THIS IS THE PAGE WE CREATED. LETS NAME IT AS ‘TEST1’.
  • 237. 237 I HAVE CHANGED THE SEQUENCE BY DRAGGING AND DROP. NOW TEST1 APPEARS BEFORE THE FIRST PAGE.
  • 238. 238 FOR BACKGROUND PICTURE AND GRAPHICS YOU CAN PICK UP EITHER BLACK AND WHITE OR COLOR BITMAP IMAGES AND ARE STORED IN THE FORM OF STANDARD TEXTS. WE TAKE A DETOUR FROM THE SMARTFORM SCREEN AND OPEN FORM GRAPHICS SCREEN. TRANSACTION CODE: SE78 NOW LETS GO BACK TO THE MAIN SCREEN ……BACKGROUND PIC PRINTING WILL TAKE PLACE ON THE BASIS OF ‘NEXT PAGE’ FIELD. BUT PROCESSING WILL HAPPEN AS PER THE SEQUENCE IN NAVIGATION WINDOW!NOTE
  • 239. 239 HERE THERE ARE 3 OPTIONS : BLACK AND WHITE, COLOR AND DYNAMIC BITMAP PICTURES. WE NAME THE BACKGROUND PICTURE AND CHOOSE THE DETERMINE DYNAMICALLY OPTION.
  • 240. 240 NOTE: RUNTIME COLOR …….USE THE FIELD WITH AMPERSAND. NOW AFTER THE PAGE, WE CREATE A NEW WINDOW. THERE WILL BE OUTPUT OPTIONS, ATTRIBUTES AND CONDITIONS IN EACH WINDOW.
  • 241. 241
  • 242. 242 CANNOT USE MAIN IN THIS FIELD BECAUSE SAP CREATES MAIN BY DEFAULT AND DOESN’T ALLOW MAIN AS NAME.  WE CANNOT HAVE MORE THAN 1 MAIN WINDOW IN A PAGE. WE CAN HAVE MULTIPLE SECONDARY WINDOWS  WHATEVER U PRINT IN SECONDARY WINDOW…IT HAS TO BE STATIC. (IF U HAVE 20 LINES IN A PO AND THERE IS PAGE CONSTRAINT THE LINES GET CARRIED FORWARD TO NEXT PAGE IN THE MAIN WINDOW. I.E. IN A PREDECESSOR AND SUCCESSOR TYPE OF CONTENT, THEY WILL BE PRINTED IN SEQUENCE IN MAIN WINDOW. THIS IS NOT ALLOWED IN SECONDARY WINDOWS. NOTE DIFFERENCE IN MAIN AND SECONDARY WINDOWS IN A FORM
  • 243. 243 YOU CAN HAVE ONLY WE MAIN PAGE WHICH U CAN STRETCH TO MULTIPLE PAGES (YOU CAN COPY AND STRETCH IT) BUT YOU CAN HAVE MULTIPLE SECONDARY WINDOWS. INSIDE THE MAIN WINDOW WE CAN ADD TEXT AS INTRODUCTION TO CUSTOMIZE THE FORM OUTPUT. IN SMART FORM WHAT YOU SEE IS WHAT YOU GET.
  • 244. 244 IN THE OUTPUT, WE HAVE THE OPTION OF SIZING AND POSITIONING THE MAIN WINDOW ALONG WITH DIFFERENT SHADING AND COLOR CHOICES.
  • 245. 245 WE CAN HAVE CONDITIONS….TO BE EXECUTED AT RUN TIME WE TAKE AN EXAMPLE TO ILLUSTRATE THIS.
  • 246. 246 BY DEFAULT THIS WILL BE AND. SOME PRACTICAL EXAMPLES OF CONDITIONS IN A WINDOW IN FORM COULD BE THAT, ON THE FIRST PAGE, WE WANT THE COMPANY LOGO AND ADDRESS OF CUSTOMER BUT ON SUBSEQUENT PAGES WE DON’T WANT CUSTOMER ADDRESS. SIMILARLY WE MAY WISH TO HAVE SIGNATURE ONLY AT THE LAST PAGE. APPROPRIATE CONDITIONS/FLOW LOGIC CAN BE INSERTED HERE TO TAKE CARE OF THESE SITUATIONS. WE CAN GIVE FLOW LOGIC FOR BOTH MAIN AND SECONDARY WINDOWS. NOTE
  • 247. 247 NOW WE COME TO THE LAST PART OF THE PAGES AND WINDOW SECTION I.E. THE ADDRESS ELEMENT. NOTE: CAM = CENTRAL ADDRESS MANAGEMENT E.G. BASED ON THE COUNTRY, WE MAY TAKE COUNTRY SPECIFIC FORMAT (E.G. IN US THE ZIP CODE IS MUST, WHILE IN INDIA IT IS NOT A MANDATORY FIELD.)
  • 248. 248 LETS CREATE A NEW ADDRESS. IT CAN BE OF 4 TYPES: PERSONAL, OFFICIAL, ORGANIZATION ADDRESS OR IT MAY BE DETERMINED DURING RUNTIME BASED ON THE SELECTION PARAMETER (DYNAMICALLY DETERMINED). U NEED TO FIND ADDRESS NUMBER ONLY AND EVERYTHING ELSE WILL BE POPULATED THE ATTRIBUTES COULD BE OF 3 TYPES: TEXT ELEMENT, INCLUDE TEXT AND TEXT MODULE WEWOULD THEN FILL UP TEXT NAME: STATIC OR DYNAMIC, TEXT OBJECT (E.G. TEXT) AND TEXT ID (E.G. ADRS)
  • 249. 249 WE THEN NUMBER THE PAGES IN THE FOOTER SPACE PROVIDED AND WRITE OUR CODE AS TEXT ELEMENT.
  • 250. 250
  • 251. 251 WE CAN USE THE SYSTEM FIELDS IN DATA DICTIONARY TABLE SFSY COMPWENTS WHILE WRITING THE LOGIC FOR SMARTFORM LETS ADD A NEW TEXT ELEMENT ‘TXT1’ CHOOSING APPROPIATE PARAGRAPH AND CHARACTER FORMATS.
  • 252. 252 WE CAN HAVE OUR OWN SMART STYLE : PARAGRAPH AS WELL AS CHARACTER FORMATS. LETS CHECK OUT A STANDARD STYLE BEFORE CREATING OUR OWN!
  • 253. 253 THE HEADER DATA IN EACH SMART STYLE ALLOWS US TO CONFIGURE FONT SIZE, LINE AND CHARACTER SPACING.
  • 254. 254 SAP PROVIDES DIFFERENT PARAGRAPH FORMATS FOR STANDARD, HEADER AND FOOTER, CENTERED AND TOTALS.
  • 255. 255 LETS CREATE A PARAGRAPH AV (WHICH IS DELETED AFTER THE EXERCISE).
  • 256. 256 NOW IT COMES IN THE FORM AS THE MENU OF PARAGRAPH FORMATS IN THE SAP SMART FORM. NOTE : AV HAS COME IN THE MENU. ALIGNMENT IS AS PER THE PARAGRAPH FORMAT AV.
  • 257. 257 THE NEWLY CREATED PARAGRAPH FONT (E.G. AV) WON’T BE PART OF GLOBAL SETTINGS. IF WE CHANGE THE FORM ATTRIBUTE - OUTPUT OPTIONS-- AND STYLE TO SOME OTHER STYLE (LIKE FROM BC470 TO BC 470_STYLS) THIS OPTION WOULD NO LONGER BE THERE. NOTE
  • 258. 258 LETS CREATE A NEW STYLE (ZBC470_AVI) WITH 2 PARAGRAPH FORMATS AND WE CHARACTER FORMAT
  • 259. 259 NOW I MENTION IN FORM ATTRIBUTE MY OWN STYLE I CHECK OUT MY OUTPUT IN THE NEXT PAGE FORM.
  • 260. 260 WHEN YOU CREATE A TABLE, SAP AUTOMATICALLY CREATES 3 AREAS: HEADER, MAIN AND FOOTER. IN MAIN AREA, THERE ARE MANY CELLS, WHICH ARE PROCESSED RECORD BY RECORD.
  • 261. 261 IN MAIN AREA, WE CREATE DIFFERENT CELLS. IN TABLE PAINTER, WE DRAW THE FORMAT AS PER CLIENT REQUIREMENT (E.G. HEADING, SUB HEADING, ITEM, SUB TOTAL, GRAND TOTAL ETC.) WE USE THE TABLE LAYOUT TO DETERMINE:  THE NUMBER OF LINES AND CELLS  THE HEIGHT OF EACH LINE  THE WIDTH OF EACH CELL  THE ALIGNMENT OF THE TABLE IN THE WINDOW  WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES WE CAN EITHER DRAW THE TABLE BY VISUAL AID OR WE CAN CLICK ON DETAILS BUTTON AND SET THE AREA ALLOTTED TO EACH CELL BY FILLING IN THE MEASUREMENTS. Click
  • 263. 263 IN DATA PAINTER, WE CAN PROCESS THE DATA BEFORE DISPLAYING IT IN SMARTFORM. SAP PROVIDES US WITH THE OPTION OF PUTTING SOME BASIC LOGIC. E.G. LOOP, WHERE CONDITION, OPTION OF ROW-BY-ROW SELECTION, SORT CONDITION, AT THE END OF TABLE PROCESSING: EVENTS (PROVIDED BY SAP). FOR EASY NAVIGATION AND ACCESS, SMARTFORM PROVIDES FIELD LIST OPTION. WE CAN ACTIVATE THAT BY UTILITIES- FIELD LIST ON/OFF.
  • 264. 264 WE CAN PUT CONDITIONS/LOGIC BY PUTTING ABAP CODE INSIDE ‘BOOKINGS’ MAIN AREA, PROGRAM LINES. HERE WE FIRST DECLARE THE INPUT AND OUTPUT PARAMETERS.
  • 265. 265 HERE WE PUT THE TEXT ELEMENT AS PER PARAGRAPH AND CHARACTER FORMAT. WE MAY HAVE A TEXT WHICH IS DETERMINED DURING RUN TIME (DYNAMIC).
  • 266. 266 NOW LETS CREATE OUR OWN TABLE. HERE WE CAN PUT LOGIC AS PER CLIENT REQUIREMENT. TEMPLATE: Template is used when we know the exact size of the output or the output is in a fixed format. E.g. Tax form/ cheques /airline form/railway ticket: all these use templates. Diff between table and template: In Table the height changes dynamically. WE CALL A ROW A ‘LINE’ IN TEMPLATE. NOTE
  • 267. 267 Whenever you wish to write your code in SAP Smartform, you have to create the proper flow logic. We use ‘command’ to code any conditions for going to the next page
  • 268. 268 This is to terminate the current page and start processing the new page.
  • 269. 269
  • 270. 270 In Smartform, We can process our own logic. We can call some table, select some data do standard data manipulations through this. In navigation wndow, First Page-- Main Window -- Create -- Flow Logic -- Program line. But it is advisable not to write programs here as it slows down the process. It is advisable to write the code in print program. This is very similar to table. If you wish to dynamically determine the output, we can loop at internal table
  • 271. 271
  • 272. 272 Flow Logic: Alternative: In this we can embed ‘If - else’ kind of logic.
  • 273. 273 If what we type here is True then it will get processed under the True button. We next explore another feature of Smartform: Folder
  • 274. 274 Folder is used to modularize the navigation; it has nothing to do with technical thing. The order you mention in the folder is the order that SAP will process. There is an option given in Smartforms. We can migrate old SAPscripts to smartforms. Note: We should check the text elements and make sure the flow logic works in the new format.
  • 275. 275 Here I am migrating a previously created SAP script to Smartform.
  • 276. 276
  • 277. 277 In Function Module screen, (se37) To get the function module name, after saving and activating the form, go to Environment – function module name. This function module name has to be given in the main program to call the form. Else go to function module SSF_FUNCTION_MODULE_NAME and give the name of the program. In the print program mentiwed below, populating certain fields from database tables into it creates an output internal table. Once the output internal table is ready, then the function module SSF_FUNCTION_MODULE_NAME is called. Here, in the import parameters, the name of the smart form is given. The output of this function module is the name of another function module. This function module is again called, in this example, the name of the function module is "/1BCDWB/SF00000007”. So, in case of smart forms, we use 2 function modules for the processing of the smart form. Once this internal table is thrown from the smart form, then in the layout, the required fields can be displayed. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' CALL FUNCTION '/1BCDWB/SF00000007'
  • 278. 278
  • 279. 279
  • 280. 280 we have to mention this name (of function module) in the print program. Supposing we want to print a Purchase Order: We need to have a print program and a smart form name to be given in the customizing settings. Also in the print program, we call the function name we got from above. Let’s check out the print program SAPBC470_PROGS.
  • 281. 281 In this program we have the SSF_FUNCTION_MODULE_NAME. We execute the program.
  • 282. 282 This calls the SAP Smart form. We are checking the output in Monocolour.
  • 283. 283 This is the way our smart form looks.
  • 284. 284 SE37: We use the just created function module. /1BCDWB/SF00000007. We execute this.
  • 285. 285
  • 286. 286
  • 288. 288 We can set the background of the output as any file stored in our hard disk. We can call a graphics from desktop or any other pic stored in the hard disk. Transaction code: SE78
  • 289. 289
  • 290. 290 Now let us delve in to configuration settings to modify our smartform as per requirement. Creating output type and assigning smart form name in spro Spro –> materials mgt –> purchasing —> messages —> output control –> message types –> define message types for Purchase order.
  • 291. 291
  • 292. 292 We can create our own message type. We can define various options like transmission medium here like Print, Fax, EDI etc. Select we output type and double click on processing routine to get the following screen. It will execute the print program as soon as we call ‘neu’ message type. In the above screen, we can mention the name of the smart form for that output type. Once this is dwe we can mention the output type in the purchase order me22n: Lets take an existing P.O.
  • 294. 294 The Output is defined here in P.O.
  • 295. 295 WHAT WE HAVE DISCUSSED THUS FAR, IWILL TRY TO SUM UP: SMART FORMS IS VERY SIMILAR TO SAP SCRIPTS. THIS IS ALSO A TOOL, WHICH IS EXTENSIVELY USED TO CREATE LAYOUTS, AND THEN A SEPARATE PRINT PROGRAM IS CREATED. THIS PRINT PROGRAM IS USED TO CREATE THE OUTPUT INTERNAL TABLE, WHICH IN TURN IS THROWN TO THE SMART FORM WHERE THE FIELD VALUES ARE DISPLAYED. SAP SMARTFORMS CAN BE USED FOR CREATING AND MAINTAINING FORMS FOR MASS PRINTING IN SAP SYSTEMS. THE OUTPUT MEDIUM FOR SMARTFORMS SUPPORT PRINTER, FAX, E-MAIL, OR THE INTERNET (BY USING THE GENERATED XML OUTPUT). THESE ARE THE STEPS TO CREATE YOUR OWN SMARTFORM: 1. CREATE A NEW SMARTFORMS TRANSACTION CODE SMARTFORMS CREATE NEW SMARTFORMS CALL ZSMART 2. DEFINE LOOPING PROCESS FOR INTERNAL TABLE PAGES AND WINDOWS FIRST PAGE -> HEADER WINDOW (CURSOR AT FIRST PAGE THEN CLICK EDIT -> NODE -> CREATE) HERE, YOU CAN SPECIFY YOUR TITLE AND PAGE NUMBERING &SFSY-PAGE& (PAGE 1) OF &SFSY-FORMPAGES(Z4.0)& (TOTAL PAGE) MAIN WINDOWS -> TABLE -> DATA IN THE LOOP SECTION, TICK INTERNAL TABLE AND FILL IN ITAB1 (TABLE IN ABAP SMARTFORM CALLING FUNCTION) INTO ITAB2 3. DEFINE TABLE IN SMARTFORMS GLOBAL SETTINGS : FORM INTERFACE VARIABLE NAME TYPE ASSIGNMENT REFERENCE TYPE ITAB1 TYPE TABLE STRUCTURE GLOBAL DEFINITIONS VARIABLE NAME TYPE ASSIGNMENT REFERENCE TYPE ITAB2 TYPE TABLE STRUCTURE 4. TO DISPLAY THE DATA IN THE FORM MAKE USED OF THE TABLE PAINTER AND DECLARE THE LINE TYPE IN TABSTRIPS TABLE E.G. HD_GEN FOR PRINTING HEADER DETAILS, IT_GEN FOR PRINTING DATA DETAILS. YOU HAVE TO SPECIFY THE LINE TYPE IN YOUR TEXT ELEMENTS IN THE TABSTRIPS OUTPUT OPTIONS. TICK THE NEW LINE AND SPECIFY THE LINE TYPE FOR OUTPUTTING THE DATA. DECLARE YOUR OUTPUT FIELDS IN TEXT ELEMENTS TABSTRIPS - OUTPUT OPTIONS FOR DIFFERENT FONTS USE THIS STYLE : IDWTCERTSTYLE FOR QUANTITY OR AMOUT YOU CAN USED THIS VARIABLE &GS_ITAB-AMOUNT(12.2)& 5. CALLING SMARTFORMS FROM YOUR ABAP PROGRAM REPORT ZSMARTFORM. * CALLING SMARTFORMS FROM YOUR ABAP PROGRAM. * COLLECTING ALL THE TABLE DATA IN YOUR PROGRAM, AND PASS ONCE TO SMARTFORMS * SMARTFORMS * DECLARE YOUR TABLE TYPE IN :- * GLOBAL SETTINGS -> FORM INTERFACE * GLOBAL DEFININTIONS -> GLOBAL DATA * MAIN WINDOW -> TABLE -> DATA * * WRITTEN BY : SAP HINTS AND TIPS ON CONFIGURATION AND ABAP/4 PROGRAMMING * HTTP://SAPR3.TRIPOD.COM * TABLES: MKPF. REFRESHER ON SMART FORMS
  • 296. 296 DATA: FM_NAME TYPE RS38L_FNAM. DATA: BEGIN OF INT_MKPF OCCURS 0. INCLUDE STRUCTURE MKPF. DATA: END OF INT_MKPF. SELECT-OPTIONS S_MBLNR FOR MKPF-MBLNR MEMORY ID 001. SELECT * FROM MKPF WHERE MBLNR IN S_MBLNR. MOVE-CORRESPONDING MKPF TO INT_MKPF. APPEND INT_MKPF. ENDSELECT. * AT THE END OF YOUR PROGRAM. * PASSING DATA TO SMARTFORMS CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING FORMNAME = 'ZSMARTFORM' * VARIANT = ' ' * DIRECT_CALL = ' ' IMPORTING FM_NAME = FM_NAME EXCEPTIONS NO_FORM = 1 NO_FUNCTION_MODULE = 2 OTHERS = 3. IF SY-SUBRC <> 0. WRITE: / 'ERROR 1'. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION FM_NAME * EXPORTING * ARCHIVE_INDEX = * ARCHIVE_INDEX_TAB = * ARCHIVE_PARAMETERS = * CONTROL_PARAMETERS = * MAIL_APPL_OBJ = * MAIL_RECIPIENT = * MAIL_SENDER = * OUTPUT_OPTIONS = * USER_SETTINGS = 'X' * IMPORTING * DOCUMENT_OUTPUT_INFO = * JOB_OUTPUT_INFO = * JOB_OUTPUT_OPTIONS = TABLES GS_MKPF = INT_MKPF EXCEPTIONS FORMATTING_ERROR = 1 INTERNAL_ERROR = 2 SEND_ERROR = 3 USER_CANCELED = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ADDITIONAL FONTS FOR YOUR SMARTFORMS YOU CAN CREATE ADDITIONAL FONTS AND STYLE WITH TRANSACTION SMARTSTYLES THIS CAN THEN BE DEFINE IN THE PARAGRAPH AND CHARACTER FORMATS, WHICH YOU CAN THEN BE ASSIGN TO TEXTS AND FIELDS IN THE SMART FORM. THE CHARACTER FORMATS INCLUDES EFFECTS SUCH AS SUPERSCRIPT, SUBSCRIPT, BARCODE AND FONT ATTRIBUTES.
  • 297. 297 VARIOUS UTILITIES AND THEIR FUNCTIONS IN SMARTFORMS CREATING FORMS USING SAP SMART FORMS WHEN CREATING A FORM WE MUST: RETRIEVE THE APPLICATION DATA DESCRIBE THE FORM PASS THE APPLICATION DATA TO THE FORM RETRIEVING THE APPLICATION DATA: WRITE AN ABAP PROGRAM TO RETRIEVE DATA OR INCLUDE A RETRIEVAL ROUTINE INTO THE APPLICATION. THIS CODE CONSISTS OF STATEMENTS THAT SELECT DATA FROM DATABASES ACCORDING TO CERTAIN SELECTION CRITERIA. STORE THE RETRIEVED DATA IN INTERNAL TABLES, STRUCTURES OR VARIABLES AND TRANSFER IT TO THE FORM IN WE STEP . DESCRIBING THE FORM: THE USER DEFINES THE FORM USING A SMART FORM. USE THE TOOLS OF THE FORM BUILDER AS LISTED BELOW: USE THE FORM PAINTER TO POSITION THE WINDOWS, GRAPHICS AND ADDRESSES ON A PAGE. USE THE PC EDITOR TO WRITE THE TEXTS. USE THE TABLE PAINTER TO FORMAT THE TABLES. THE FLOW CONTROL IS USED TO PRINT THE PAGES AND ELEMENTS. FORM LOGIC IN THE FORM BUILDER WE CAN DESCRIBE A SMART FORM BY A SET OF NODES. TO DO THIS, WE CAN BUILD UP A TREE STRUCTURE ON THE LEFT SIDE OF THE USER INTERFACE. THE NODE GLOBAL SETTINGS AND ITS THREE SUCCESSORS FORM ATTRIBUTES, FORM INTERFACE AND GLOBAL DEFINITIONS ALWAYS EXISTS FOR ANY NEWLY CREATED FORMS. TO DESCRIBE THE FORM LOGIC, CREATE THE HIERARCHY UNDER THE NODE PAGES AND WINDOWS. THE FOLLOWING RULES APPLY TO CONTROL THE FLOW OF THE FORM OUTPUT. THE NODES IN THE TREE STRUCTURE ARE PROCESSED FROM TOP TO BOTTOM. FOR EACH NODE THERE IS A TAB, THIS CAN BE USED TO LINK THE NODE TO A CONDITION. IF THE CONDITION IS TRUE, THE SYSTEM PROCESSES THE NODE. IF NOT, IT SKIPS THE NODE AND ALL ITS SUCCESSORS. WE SHOULD DEFINE A NEXT PAGE FOR EACH PAGE. GRAPHICAL USER INTERFACE THE BASIC ABAP PROGRAMMING SKILLS ARE REQUIRED ONLY IN SPECIAL CASES LIKE CALLING A FUNCTION MODULE OR FOR COMPLEX AND EXTENSIVE CONDITIONS. THE SAP FORM BUILDER OF THE SMART FORM CONSISTS OF: FORM PAINTER FOR CREATING THE LAYOUT OF THE FORM PC EDITOR FOR ENTERING TEXTS AND FIELDS INTO OUTPUT AREAS NAVIGATION FREE FOR MAINTAINING THE FORM LOGIC TABLE PAINTER FOR CREATING TEMPLATES AND TABLES FORM CHECK TO DEFINE THE TEXT FORMATS, WE CAN USE THE SMART STYLES. THE FORM PAINTER: THE FORM PAINTER OFFERS THE FOLLOWING FUNCTIONS: DESIGN AREA WITH RULER, CURSOR WITH HELP LINES, AND HE GRID AND MAIN GRID. DISPLAY OF THE CURSOR POSITION IN THE RULER, WHICH CAN BE SUPPRESSED AND SET. TWO LEVEL GRID WITH ENGAGE FUNCTION WHICH CAN BE CUSTOMIZED. WHEN CREATING, CHANGING AND MOVING A WINDOW, THE WINDOW SIZE APPEARS IN THE RULER. DETACHABLE TOOLBAR CONTAINING THE MOST IMPORTANT FUNCTIONS. AUTOSCROLLING WHEN MOVING WINDOWS, PLACING WINDOWS IN THE BACKGROUND. ZOOM FACTORS THAT CAN BE SET TO ANY VALUE AND AUTOZOOMING OF THE DESIGN AREA TO THE WINDOW SIZE. SENSITIVE CONTEXT MENU.
  • 298. 298 PLACING A SCANNED GRAPHIC INTO THE BACKGROUND OF THE DESIGN AREA. THE PC EDITOR: THE PC EDITOR OFFERS THE FOLLOWING FUNCTIONS: ENTER, DELETE, SELECT, CUT AND COPY TEXTS. ASSIGN PARAGRAPH AND CHARACTER FORMATS. INCLUDE, CHANGE AND DELETE FIELDS. THE TABLE PAINTER: THE TABLE PAINTER OFFERS THE FOLLOWING FUNCTIONS: DRAWING LINES AND COLUMNS INSERTING , CUTTING , COPYING AND DELETING LINES DELETING CELLS CHANGING CELL SIZE AND MOVING CELL SEPARATOR LINES SPLITTING CELLS SELECTING TABLE PATTERNS STYLE BUILDER: ON THE LEFT OF THE STYLE BUILDER SCREEN CONSISTS OF THE PREDETERMINED NODES (HEADER DATA, FOLDER FOR PARAGRAPH FORMATS, FOLDER FOR CHARACTER FORMATS). ON THE RIGHT WE CAN SEE THE MAINTENANCE SCREEN WITH ITS TAB PAGES. AT THE BOTTOM THE PREVIEW OF THE SELECTED FONT CAN BE VIEWED. FIELD LIST AND ERROR LIST: THE FIELD LIST DISPLAYS THE FOLLOWING DATA IN THE FORM A TREE STRUCTURE: ALL TABLES, FIELDS AND STRUCTURES PASSED VIA THE FORM INTERFACE. SYSTEM FIELDS AND THE FIELDS THAT ARE DEFINED IN THE GLOBAL DEFINITIONS. THIS ALLOWS WETO CHECK WHETHER A CORRECT FIELD NAME HAS BEEN ENTERED OR NOT AND THAT THE FORM KNOWS THE FIELD OR NOT. TO DISPLAY THE FIELD LIST, IN THE FORM BUILDER CHOOSE FIELD LIST ON/OFF. THE ERROR LIST CONTAINS THE LIST OF ERRORS AND WARNINGS DISPLAYED AT THE BOTTOM OF THE MAINTENANCE SCREEN. NODE TYPES: WHEN A FORM IS CREATED, THE TREE STRUCTURE OF THE FORM PAINTER CONTAINS TWO ROOT NODES. THE SUCCESSORS OF THE GLOBAL SETTINGS NODE ARE USED TO MAINTAIN FORM ATTRIBUTES, THE FORM INTERFACE AND GLOBAL DEFINITIONS. THE SUCCESSORS OF THE PAGES AND WINDOWS NODE TO CREATE THE PAGES OF THE FORM, POSITION ELEMENTS ON THESE PAGES, AND DETERMINE THE SEQUENCE ON HOW TO PROCESS THESE CREATED ELEMENTS. BASIC ELEMENTS OF A FORM CREATING PAGES: EACH FORM CONSISTS OF WE OR MORE PAGES. THE FIRST PAGE IN THE TREE STRUCTURE IS THE START PAGE AND THE PROCESSING OF THE FORM STARTS WITH THIS PAGE ITSELF. OPEN THE CONTEXT MENU FOR EXISTING PAGE NODE AND CHOOSE CREATEPAGE ENTER A UNIQUE NAME FOR THE NODE AND A DESCRIPTION DETERMINE THE FORMAT AND THE MODE OF THE PAGE COUNTER ON THE GENERAL ATTRIBUTES TAB DETERMINE THE PRINT ATTRIBUTES OF THE PAGE ON THE OUTPUT OPTIONS DETERMINE A BACKGROUND GRAPHIC FOR THE ENTIRE PAGE ON THE BACKGROUND TAB CREATING WINDOWS: WE CAN SET THE SIZE AND POSITION OF THE WINDOW GRAPHICALLY IN THE FORM PAINTER. THERE ARE MAIN WINDOWS AND SUBWINDOWS. THE DIFFERENCE BETWEEN THESE TWO IS THAT THE OUTPUT IN A MAIN WINDOW CAN COVER SEVERAL PAGES. OPEN THE CONTEXT MENU FOR AN EXISTING PAGE NODE AND CHOOSEWINDOW ENTER A NAME FOR THE NODE AND A DESCRIPTION
  • 299. 299 ON THE GENERAL ATTRIBUTES INDICATE WHETHER THE WINDOW IS A MAIN WINDOW. IF SUB WINDOW WANTS TO BE CREATED THEN LEAVE THE CHECKBOX EMPTY POSITIONING TEXTS ON THE FORM THE TEXTS ARE DISPLAYED IN THE FORM USING TEXT NODES. THE ONLY EXCEPTIONS ARE ADDRESSES. THIS USES ITS OWN NODE. THE PREDECESSOR NODE OF THE TEXT NODE DETERMINES ITS USE: PREDECESSOR NODE USED TO SUB WINDOW [POSITION TEXT ON WE OR MORE PAGES] MAIN WINDOW [DISPLAY TEXT IN RELATION TO OTHER NODES IN THE MAIN WINDOW, IT MAY COVER SEVERAL PAGES] TEMPLATE [DISPLAYS TEXTS FOR TABLE CELLS OF A STATIC TABLE] TABLE [DISPLAY TABLE CONTENTS] HEADER AND FOOTER [DISPLAY COLUMN HEADINGS AND GRAND TOTALS IN TABLES] EVENT NODE [DISPLAY SUBTOTALS IN A TABLE] THERE ARE THREE TEXT TYPES: TEXT ELEMENT : TO ENTER NEW TEXT IN THE PC EDITOR TEXT MODULE : TO INCLUDE A TEXT MODULE INCLUDE TEXT : TO INCLUDE AN EXISTING SAPSCRIPT TEXT ENTERING TEXTS IN PC EDITOR: TO CREATE A TEXT NODE CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHOULD RECEIVE THE TEXT, THEN CHOOSE->TEXT ENTER A UNIQUE NAME FOR THE NODE AND THE NODE DESCRIPTION ON THE GENERAL ATTRIBUTES TAB CHOOSE TEXT ELEMENT AS TEXT TYPE ENTER THE TEXT IN THE PC EDITOR IN THE TEXT NODE BOX CHOOSE WHETHER THE TEXT SHOULD BE STARTED WITH A NEW PARAGRAPH OR ONLY IN A NEW LINE INCLUDING TEXT MODULES: TEXT MODULE OF THE TEXT NODE IS USED TO REFER TO AN EXISTING TEXT MODULE IN THE SYSTEM. THE TEXT MODULES CAN BE USED IN TWO WAYS: REFER TO THE TEXT MODULE. THE TEXT THEN APPEARS READ-ONLY IN THE PC EDITOR AND IS INCLUDED WHEN THE FORM IS PRINTED. COPY THE TEXT MODULE. THE SYSTEM THEN COPIES THE TEXT OF THE MODULE AND AUTOMATICALLY CONVERTS THE TEXT NODE INTO AN EDITABLE TEXT ELEMENT. TO CREATE A TEXT NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHALL CONTAIN THE TEXT AND CHOOSE CREATE->TEXT ENTER A UNIQUE NAME FOR THE NODE AND A DESCRIPTION ON THE GENERAL ATTRIBUTES TAB SELECT THE TEXT TYPE TEXT MODULE ENTER THE NAME OF THE TEXT MODULE IN THE TEXT NAME FIELD INCLUDING SAPSCRIPT TEXTS: WE CAN USE THE TEXT TYPE INCLUDE TEXT NODE TO REFER TO A SAPSCRIPT TEXT THAT ALREADY EXISTS IN THE SYSTEM. TO IDENTIFY THE TEXT THE TEXT NAME, OBJECT, ID AND THE LANGUAGE IS NEEDED. TO CREATE THE TEXT NODE CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT SHALL RECEIVE THE TEXT AND CHOOSE CREATE -> TEXT ENTER A UNIQUE NAME FOR THE NODE AND THE NODE DESCRIPTION ON THE GENERAL ATTRIBUTES TAB CHOOSE INCLUDE TEXT AS TEXT TYPE INSERTING ADDRESSES: WE CAN USE THE ADDRESS NODE TO INSERT AN ADDRESS INTO THE FORM. THIS GUARANTEES THAT THE ADDRESS IS FORMATTED ACCORDING TO THE POSTAL RULES OF THE SENDER COUNTRY. TO CREATE AN ADDRESS NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE THAT WEWANTS TO CONTAIN THE TEXT AND CHOOSE CREATE->TEXT
  • 300. 300 ENTER A NAME FOR THE NODE AND A DESCRIPTION DETERMINE THE ADDRESS TYPE ON THE GENERAL ATTRIBUTES TAB FOR ORGANIZATIONAL ADDRESSES WE HAVE TO SPECIFY THE ADDRESS NUMBER, FOR ANY OTHER WE HAVE TO SPECIFY THE PERSON NUMBER AND THE ADDRESS NUMBER IN THE BOX ADDITIONAL ADDRESSES WE CAN MAINTAIN OTHER ATTRIBUTES TO SPECIFY HOW TO DISPLAY THE ADDRESS PRINTING GRAPHICS: GOTO TCODE SE78 TO IMPORT GRAPHICS INTO THE SAP SYSTEM. THE TRANSACTION IMPORTS THE GRAPHICS AND STORES IT IN THE BDS (BUSINESS TRANSACTION SERVER) AND THEN IT CAN BE DISPLAYED IN THE FORM. TO CREATE THE GRAPHIC NODE , CALL THE CONTEXT MENU FOR THAT NODE IN THE TREE STRUCTURE AND CHOOSE CREATE- >GRAPHIC ENTER A NAME FOR THE NODE AND THE DESCRIPTION ON THE GENERAL ATTRIBUTES DETERMINE WHETHER A COLORED OR A BLACK AND WHITE USE THE FIELDS OBJECT , ID AND NAME TO IDENTIFY THE GRAPHIC DISPLAYING A STATIC TABLE USE NODE TYPE TEMPLATE TO DISPLAY A TABLE WHOSE LAYOUT AND SIZE IS DETERMINED BEFORE THE RUNTIME OF THE PRINT PROGRAM. TO CREATE A TEMPLATE DEFINE A TABLE LAYOUT TO DETERMINE THE CELL STRUCTURE FOR EACH LINE. THE CELLS ARE USED TO DISPLAY THE CELL STRUCTURE FOR EACH LINE. THE CELLS ARE USED TO DISPLAY THE CONTENTS OF THE SUCCESSOR NODES OF THE TEMPLATE NODE. THIS ALLOWS US TO POSITION TEXT AND A GRAPHIC SIDE BY SIDE. THE TEMPLATE NODE IS ALSO USED FOR LABEL PRINTING. TO USE A TEMPLATE WE MUST DO THE FOLLOWING: DEFINE THE TABLE LAYOUT DISPLAY THE CONTENTS IN THE TABLE CELLS DEFINE THE TABLE LAYOUT: THE TABLE LAYOUT IS USED TO DETERMINE THE FOLLOWING, THE NUMBER OF LINES AND CELLS THE HEIGHT OF EACH CELL THE WIDTH OF EACH CELL THE ALIGNMENT OF THE TABLE IN THE WINDOW WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES CREATE A TEMPLATE NODE AND MAINTAIN THE ATTRIBUTES WIDTH, HORIZONTAL ALIGNMENT AND VERTICAL ALIGNMENT. USE THE TABLE CONTROL ON THE TEMPLATE TAB TO DEFINE THE LAYOUT OF THE LINES. EACH LINE OF THE TEMPLATE MUST HAVE A DEFINITION. USE THE PATTERN BOX TO SELECT THE DESIRED TABLE PATTERN. DISPLAYING CONTENTS IN CELLS: THE TEMPLATE NODE DEFINES THE TABLE LAYOUT. THE SUCCESSOR NODES OF THE TEMPLATE DETERMINE THE DATA TO BE DISPLAYED IN THE TABLE CELLS. COMBINING NODES: THE MORE EXTENSIVE THE FORM BECOMES, THE LESSER CLEAR BECOMES THE NODE HIERARCHY IN THE TREE STRUCTURE. TO AVOID THIS WE CAN COMBINE THE RELATED NODES BY APPENDING THEM UNDER A FOLDER NODE. LLET" STYLE="MARGIN-LEFT:1.75IN;TEXT-INDENT:-.25IN;MSO-LIST:L8 LEVEL1 LFO23; TAB-STOPS:LIST 1.75IN"> THE WIDTH OF EACH CELL THE ALIGNMENT OF THE TABLE IN THE WINDOW WHETHER AND WHERE TO DISPLAY SEPARATOR LINES OR FRAMES CREATE A TEMPLATE NODE AND MAINTAIN THE ATTRIBUTES WIDTH, HORIZONTAL ALIGNMENT AND VERTICAL ALIGNMENT. USE THE TABLE CONTROL ON THE TEMPLATE TAB TO DEFINE THE LAYOUT OF THE LINES. EACH LINE OF THE TEMPLATE MUST HAVE A DEFINITION. USE THE PATTERN BOX TO SELECT THE DESIRED TABLE PATTERN. DISPLAYING CONTENTS IN CELLS: THE TEMPLATE NODE DEFINES THE TABLE LAYOUT. THE SUCCESSOR NODES OF THE TEMPLATE DETERMINE THE DATA TO BE DISPLAYED IN THE TABLE CELLS. COMBINING NODES:
  • 301. 301 THE MORE EXTENSIVE THE FORM BECOMES, THE LESSER CLEAR BECOMES THE NODE HIERARCHY IN THE TREE STRUCTURE. TO AVOID THIS WE CAN COMBINE THE RELATED NODES BY APPENDING THEM UNDER A FOLDER NODE.
  • 302. 302 A Step-by-Step Approach to Create SAP Script Introduction Purpose of document: This document is all about creation of SAP Script. This document will help in –  To familiarize with SAP Script  Elements of SAP Script  Processing of SAP Script  Step-by-Step method to create a simple script  Some advanced control commands in brief. Who will benefit: All ABAPers. Prerequisite: Knowledge of ABAP. Introduction to SAP Script Business uses several forms in day-to day activities. These forms can be a –  Purchase Orders  Sales Orders  Credit Memos  Debit Memos  Invoices  Salary Slips etc. To facilitate design, build and printing of these forms, SAP provides a tool which is known as SAP Script. In addition to it, R/3 comes with a set of pre-designed forms that can be easily customized to fit the needs of individual business. For e.g. - MEDRUCK is a SAP Script layout which is available in R/3 system which can be used to generate Purchase Order. This is a standard layout available in R/3 for generation of Purchase Order which can be customized according to individual business needs. A SAP Script layout is not alone capable of printing these various business forms; it’s merely a structure which defines areas within a page that is populated with data specific to business needs. The collection of data and passing it to script layout is done through its FORM Routine. This FORM Routine is an ABAP program which involves some standard function modules to pass business data to SAP Script layout. Thus, combination of SAP Script layout and its FORM Routine together responsible for generation of these business forms. For e.g. – The associated FORM Routine for above mentioned SAP Script Layout is SAPFM06P available in R/3.
  • 303. 303 This document is mainly intended to demonstrate the basic steps to create a SAP Script Layout. Since, its associated FORM Routine is basically an ABAP program which can be coded according to business demand to collect desired data, however the standard function modules needed to invoke Script layout and to pass business data will be discussed in brief. SAP Script Layout Elements A SAP Script Layout consists of following elements –  Pages  Windows  Page windows  Paragraphs Formats  Character Formats Let’s discuss them in short – Pages: Pages are general layout of script. A page would normally be divided into three parts –  Header  Body  Footer A script can consist of many pages where the first page can be in different format and second page onwards can be in different formats. HEADER BODY FOOTER
  • 304. 304 Windows: To specify position of contents on the page, windows are created. WINDOWS Page Windows: Page windows are used to specify sizes and to determine position of each window. Paragraph Formats: Paragraph formats are used for formatting paragraphs. Font and tabs are important paragraph format. If we do not specify font, form uses default font. Character Formats: Character formats are basically used to override paragraph formats for specific words in a paragraph. For e.g. if we want to bold a specific word within a paragraph, we make use of character formats. How SAP Script Processed The SAP Script runtime environment co-ordinates the processing of SAP Script as shown below – LOGO COMPANY NAME CONTENT ADDRESS
  • 305. 305 As shown above the SAP Script layout environment retrieves layout and content data from SAP Script form. Also it retrieves necessary business data according to business logic defined in Form Routine from the R/3 database. Thus, combining both of these, finally it generates the SAP Script form. This generated SAP Script form can be –  Printed  Faxed  E-mailed  Displayed on terminal as per requirement. Steps to create SAP Script Layout  Go to Transaction SE71 and give name of script you want.
  • 306. 306  Press Create and the following pop-up will appear. Don’t forget to see that the form is created in the client and not in the application server.
  • 307. 307  Just Press Enter and save the layout after giving a short description.
  • 308. 308  Now click on tab Pages. The following screen will appear -
  • 309. 309  Create a page called PAGE1 and press Enter. Give next page as PAGE1 only and press Enter.  Now click on tab Windows. The following screen will appear –
  • 310. 310  Apart from existing Main window, create Header and Footer for this page.
  • 311. 311  Now click on tab Paragraph Formats where you can create your own paragraph formats which can be used while writing text
  • 312. 312 elements for windows. The following four paragraph formats has been created as shown below – The various parameters such as o Margins o Alignment, o Font type o Font size etc. should be entered as per requirement.  Now click on tab Page Windows and associate previously created windows to PAGE1. This can be done by clicking on Edit from menu bar and choosing option Create Element, where previously created all windows will be shown up. Double click on those windows which you want to associate with this page and assigning following four parameters for all windows – o Left Margin o Upper Margin o Window Width o Window Height The resulting screen will look as –
  • 313. 313  Select Header window and click on Icon for text elements. The shown editor can be chosen by clicking option Go to from menu bar and selection option Change Editor. Enter desired text as shown below –
  • 314. 314  Now go back to previous screen, select Main window and press Icon for text elements. Enter following texts as shown – Note- All variable names must be enclosed in ampersands (&).
  • 315. 315  Now go back to previous screen, select Footer window and press Icon for text elements. Enter following texts as shown –  Now go back & save it. Click on Header Icon , the following screen will appear –
  • 316. 316  Click on Basic Settings and assign First Page as PAGE1 and Default Paragraph as P2 and save it as shown –
  • 317. 317  Now check for Definition and Activate the script. Script Layout is complete now.
  • 319. 319 Once Script Layout is complete, now we will create its Form Routine. This Form Routine is an ABAP Program through which SAP Script Layout is invoked using three function modules viz.  OPEN_FORM  WRITE_FORM  CLOSE_FORM These function modules are used in the same manner as listed above. Out of all these, OPEN_FORM and CLOSE_FORM are used only once while WRITE_FORM can be used any number of times in between OPEN_FORM and CLOSE_FORM depending on requirement. Create a report program using transaction SE38 and copy following code snippets and activate it. Code Snippet: REPORT ZTESTSCRIPT_FORMROUTINE . *----------------------------------------------------------- ------------ * Database tables *----------------------------------------------------------- ------------ TABLES: kna1. *----------------------------------------------------------- ------------ * Contants *----------------------------------------------------------- ------------ CONSTANTS: co_mulgrave(8) VALUE 'MULGRAVE'. *----------------------------------------------------------- ------------ * Internal Tables *----------------------------------------------------------- ------------ DATA: BEGIN OF tb_kunnr OCCURS 0, name1 LIKE kna1-name1, ort01 LIKE kna1-ort01, pstlz LIKE kna1-pstlz, regio LIKE kna1-regio, END OF tb_kunnr. *----------------------------------------------------------- ------------ * START OF PROCESSING *----------------------------------------------------------- ------------ START-OF-SELECTION. * Select details of customer of Mulgrave city SELECT name1 ort01 pstlz regio
  • 320. 320 INTO TABLE tb_kunnr FROM kna1 WHERE ort01 = co_mulgrave. *----------------------------------------------------------- ------------ * END OF PROCESSING *----------------------------------------------------------- ------------ END-OF-SELECTION. CALL FUNCTION 'OPEN_FORM' EXPORTING * APPLICATION = 'TX' * ARCHIVE_INDEX = * ARCHIVE_PARAMS = * DEVICE = 'PRINTER' * DIALOG = 'X' FORM = '/DCSEA/ZTESTSC' LANGUAGE = SY-LANGU * OPTIONS = * MAIL_SENDER = * MAIL_RECIPIENT = * MAIL_APPL_OBJECT = * RAW_DATA_INTERFACE = '*' * IMPORTING * LANGUAGE = * NEW_ARCHIVE_PARAMS = * RESULT = * EXCEPTIONS * CANCELED = 1 * DEVICE = 2 * FORM = 3 * OPTIONS = 4 * UNCLOSED = 5 * MAIL_OPTIONS = 6 * ARCHIVE_ERROR = 7 * INVALID_FAX_NUMBER = 8 * MORE_PARAMS_NEEDED_IN_BATCH = 9 * SPOOL_ERROR = 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 tb_kunnr. * Write header CALL FUNCTION 'WRITE_FORM' EXPORTING * ELEMENT = ' ' * FUNCTION = 'SET' * TYPE = 'BODY' WINDOW = 'HEADER'. * IMPORTING * PENDING_LINES = * EXCEPTIONS * ELEMENT = 1
  • 321. 321 * FUNCTION = 2 * TYPE = 3 * UNOPENED = 4 * UNSTARTED = 5 * WINDOW = 6 * BAD_PAGEFORMAT_FOR_PRINT = 7 * SPOOL_ERROR = 8 * OTHERS = 9 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * Write main contents CALL FUNCTION 'WRITE_FORM' EXPORTING ELEMENT = 'MAIN' * FUNCTION = 'SET' * TYPE = 'BODY' WINDOW = 'MAIN'. * IMPORTING * PENDING_LINES = * EXCEPTIONS * ELEMENT = 1 * FUNCTION = 2 * TYPE = 3 * UNOPENED = 4 * UNSTARTED = 5 * WINDOW = 6 * BAD_PAGEFORMAT_FOR_PRINT = 7 * SPOOL_ERROR = 8 * OTHERS = 9 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * Write Footer CALL FUNCTION 'WRITE_FORM' EXPORTING * ELEMENT = ' ' * FUNCTION = 'SET' * TYPE = 'BODY' WINDOW = 'FOOTER'. * IMPORTING * PENDING_LINES = * EXCEPTIONS * ELEMENT = 1 * FUNCTION = 2 * TYPE = 3 * UNOPENED = 4 * UNSTARTED = 5 * WINDOW = 6 * BAD_PAGEFORMAT_FOR_PRINT = 7 * SPOOL_ERROR = 8 * OTHERS = 9 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • 322. 322 * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDLOOP. "LOOP AT tb_kunnr CALL FUNCTION 'CLOSE_FORM' * IMPORTING * RESULT = * RDI_RESULT = * TABLES * OTFDATA = * EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 * SEND_ERROR = 3 * SPOOL_ERROR = 4 * OTHERS = 5 . IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. On execution of above program, the following screen will appear – Click on Print Preview, the output will be as shown –
  • 323. 323 Transporting Script Layout between clients Since SAP Script Layout is client dependent thus layout designed in development client can not be tested until it is transported to test client. Thus, to transport layout from one client to another, transaction SCC1 is used (Screen shot below).
  • 324. 324 To transport layout, mention source client, request number under which layout is locked and click on checkbox Incl. task for request. Finally, click on tab Start Immediately as shown below –
  • 325. 325
  • 326. 326 Function Modules Used in Script: In the Driver we must use all or some of the function modules that are listed below to transfer the data.  Open_Form  Close_Form  Start_Form  Write_Form  Write_Form_Lines  End_Form  Control_Form  Read_Form_elements  Read_Form_Lines Any driver program must contain Open_Form, Close_Form and Write_Form. Other function modules are optional. OPEN_FORM: This function module opens layout set printing. One must call this function module before he uses any of other layout set function modules like Write_Form, Start_Form, Control_Form etc., You need specify a layout set name in the export parameters of this function module. If nothing is passed to Open_Form then one should use Start_Form function module to open layout set before starting the output. The layout set opened by Open_Form should be closed by Close_Form function module, other wise output doesn’t appear. We can use any number of Open_Form, Close_Form functions in one single program. But Close_Form must be there for every Open_Form in the program. Some of the important export parameters we have to pass to Open_Form function module. Form: Enter the Layout set name here, which then controls the output formatting. If nothing is specified then we must use Start_Form for opening layout set. Language: Layout sets are Language dependent. Enter the desired language here. If the entered layout set is not in that language, then the function tries to open the Form entered in its original language. The default value is SY-LANGU. Device: SAP Script can format a text on different device types. The device can be ‘PRINTER’ or ‘TELEX’, ‘TELEFAX’, ’ABAP’ and ‘SCREEN’. Dialog: Use parameter DIALOG to determine whether to display a dialog box before printing, in which the user can set several spool parameters for print formatting. Possible values: SPACE displays no print parameter screen. 'X' display print parameter screen. Default value: 'X' Options: Use parameter OPTIONS to set several options for print formatting. The parameter has the structure ITCPO. The user can change some of the defined settings on the print control screen. The default value for Options is ‘ ‘. We will discuss about ITCPO structure in detail later. Other Export, Import and Exceptions are self-explanatory.
  • 327. 327 Close_Form: The function module closes the layout set opened using OPEN_FORM. The system executes any terminating processing steps for the last opened layout set. No Export parameters for this Function Module. Start_Form: In-between the function modules OPEN_FORM and CLOSE_FORM, we can use different layout sets. This allows us to combine several different layout sets into one print output. However, we can combine only those layout sets that have the same page format. To switch layout sets, use the function module START_FORM. If another layout set is still open, we must close it first using END_FORM. If we specify no layout set name when calling START_FORM, the system restarts the last open layout set. If after OPEN_FORM no layout set was activated yet, the system leaves the function module with the exception UNUSED. Some of the important export parameters for this function module are Form: The parameter contains the name of the layout set you want to use for printing. If you specify no layout set here, the system restarts the last active layout set. Language: Layout sets are language-dependent. Enter the desired language here. If the layout set does not exist in this language, the system tries to call the layout set in its original language. If the parameter LANGUAGE is empty, the system uses the language of the last active layout set. Startpage: Usually, SAP script starts with the page specified as start page in the layout set definition. If we want to start output with another layout set page, enter the name of the desired layout set page here. If the desired page is not defined, the system uses the start page defined in the layout set. Program: To replace program symbols, SAP script must know which active program contains the work areas for the values to be passed. If we omit the parameter, the system searches for the field values in the program that was specified in the parameter OPTIONS (field TDPROGRAM) of OPEN_FORM. If we enter a program name, the system replaces the program symbols with the values from this program up to the next END_FORM. Exceptions and other Export, Import parameters are self-explanatory. Write_Form: The system outputs the layout set element specified in parameter ELEMENT into the currently opened layout set. In the parameter WINDOW we can specify the name of a window for the output. Remember that the layout set element must be defined in this window. The parameter FUNCTION specifies how to merge the text lines to be output with any existing contents in the window. In this case, there are differences between the different window types or areas. Some of the important export parameters used in Write_Form.
  • 328. 328 Element: Specify the name of the text element you want to output into the layout set window specified in the parameter WINDOW. The element must be defined in that layout set window. If you specify no element, the system uses the default element, if one is defined in the layout set. Window: Specify the name of the window into which you want to output the layout set element specified in the parameter ELEMENT. Default value for Window is ‘MAIN’. Function: The parameter determines how to output the text element into the respective window. The output type depends on the window type and area: Window Type: MAIN Area: BODY SET/APPEND: Appends to previous output. Window Type: Main Area: Top/Bottom and Window Type: Other than Main and all areas SET : Delete the old element contents and prints the new elements APPEND: Appends the new content to existing elements. Type: The system interprets this parameter only for output to the main window. The parameter determines the area of the main window into which we want to output the element. Possible values: 'TOP' header area 'BODY' main area 'BOTTOM' footer area Default value: 'BODY' Write_Form_Lines: This function module outputs the text lines in table LINES into the specified layout set window. The text lines must have the SAP script ITF format. From the data in the text header, the system uses only the field TDSTYLE to apply the formatting attributes defined in the specified style for this text. If the field is empty, the system uses the identically named formatting attributes (character and paragraph formats) of the layout set. Use parameter WINDOW to specify into which of the windows defined in the layout set we want to output the text. We can specify any window used in the layout set. The parameter FUNCTION determines how to merge the text lines to be output with any existing contents in the window. There are differences between the different window types or areas. Header: This parameter contains the header of the text module we want to output in the current layout set. For the formatting process, the system uses only the entries in the header fields TDSTYLE and TDFORM. Structure: THEAD WINDOW: Enter the name of the window into which we want to output the layout set element specified in parameter ELEMENT. Default value: 'MAIN' FUNCTION: This parameter determines how to output the text element into the respective window. The output type depends on the window type and area: Window type MAIN, area BODY: 'SET' append to previous output 'APPEND' same as SET. DELETE' no effect. Window type MAIN, areas TOP and BOTTOM; all other windows: 'SET' delete old window or area contents and output the element 'APPEND' append the element to the existing elements 'DELETE' no effect
  • 329. 329 Default value: 'SET' TYPE: The system interprets this parameter only for output to the main window. The parameter determines the area of the main window into which you want to output the element. Possible values: 'TOP' header area 'BODY' main area 'BOTTOM' footer area Default value: 'BODY' END_FORM: END_FORM ends the currently open layout set and executes the required termination processing. After calling this function module, no more layout set is active. For further output, we must start a new layout set using START_FORM. No Export parameters. CONTROL_FORM: Use this function module to pass SAP Script Control Commands to the layout set. The Control command is passed through the export parameter ‘COMMAND’ in quotes. READ_FORM_ELEMENTS: This function module fills a table with all text elements that appear in one layout set. If we specify no layout set name, the system includes all elements of the currently open layout set. If we specify a layout set, the system uses the information about the active version of the layout set, retrieved from the database. Here we have two export parameters, Form and Language and a table parameter Elements. READ_FORM_LINES: Use this function module to transfer the lines of a layout set element into an internal table. If we specify no layout set name, the system transfers the text lines of the currently open layout set. If we specify a layout set, the system uses the text lines of the active version of the layout set from the database. The Export parameters are Form, Language, Window and Element. If we pass these 4 parameters the function module returns a table with the lines from layout set. Procedure Migrating a SAPscript form 1. Go to the SAP Smart Forms initial screen (transaction SMARTFORMS ). 2. In the Form field enter the name of the Smart Form you want to create. 3. Choose Utilities  Migrate SAPscript form. The dialog window Migrate SAPscript Form appears. 4. Enter the name and the language of the source form (SAPscript). 5. Choose Enter. This takes you to the change mode of the SAP Form Builder.
  • 330. 330 If the selected SAPscript form does not exist in the selected language, a dialog window appears on which you can select one of the existing languages. 6. Now change the design of the form and of the form logic. To activate the Smart Form choose Activate. Converting a SAPscript style 1. Go to the Smart Styles inital screen (transaction SMARTSTYLES ). 2. In the Style name field enter the name of the Smart Style you want to create. 3. Choose Smart Styles  Convert SAPscript style. 4. Enter the name of the SAPscript style you want to convert. 5. Choose Enter. A list of the converted styles appears. 6. Choose Back. You can now change the Smart Style (Change).To activate the Smart Style choose Activate. Mass Migration of SAPscript Forms 1. In Reporting select the program SF_MIGRATE and execute it. 2. Select the names and the language of the SAPscript forms and choose Execute. The system creates the Smart Forms under the names of the SAPscript forms plus the extension _SF. It displays a list of the migrated forms. 3. To change and adapt a form, go to transaction SMARTFORMS . Then activate the changed Smart Form. Result You created one or more Smart Forms based on the respective SAPscript form(s) and a Smart Style based on the respective SAPscript style. SAP SCRIPT LOGO PRINTING To Create a logo in SAP printouts , just do the following 1. Save a Logo using Paintshop Pro or Corel Draw as Tiff file. 2. Run this program RSTXLDMC and enter the following parameters Enter file name C:MAILCOMPLOGO.TIF UOM CM
  • 331. 331 Line width for text 132 Text name ZHEX-MACRO-COMPLOGO Text ID ST Text language = E Number of Tiff gray levels (2,4,9) 2 3. Then Create a new window 'COMP' with attributes; Window COMP description Company Logo Left margin 7.00 CH window width 10.00 CH Upper margin LN window height 8.00 LN Finally in the text element , mention /: INCLUDE 'ZHEX-MACRO-COMPLOGO' OBJECT TEXT ID ST LANGUAGE 'E'. Please note that if object name is not indicated as 'ZHEX...', the logo may not be printed! You will not be able to see the logo in a test print. The same will be printed in actual printout. SAP SCRIPTS SYMBOLS Commands 1. Defining a variable 2. Define and insert a standard text: 3. Formatting addresses 4. Avoiding pagebreaks in a paragraph
  • 332. 332 5. Conditonal text ouput IF - ENDIF 1. Defining a variable DEFINE &CUST& = '00000021'. 2. Define and insert a standard text: Standard texts is predifined textst that can be used in more than one form. Standard texts are can be created, changed and displayed using transaction SO10. The text ID is used to callsify texts. To include a stadard text in a form, use the INCLUDE command: /: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD When formatting the standard text the PARAGRAPH parameter is used. To center the text use: /: INCLUDE Z_BC460_EX4_HF OBJECT TEXT ID SDVD LANGUAGE EN PARAGRAPH C. 3. Formatting addresses The ADDRESS-ENDADDRESS command formats addresses according to the postal norms of the recipient's country, as defined in the country parameter. ADDRESS DELIVERY PARAGRAPH AD NAME &KNA1-NAME& STREET &KNA1-STRAS& POSTCODE &KNA1-PSTLZ& CITY &KNA1-ORT01&' COUNTRY &KNA1-LAND1& FROMCOUNTRY 'DE' ENDADDRESS 4. Avoiding pagebreaks in a paragraph /: PROTECT : : /: ENDPROTECT The text lines to be protected are enclosed between the two commands
  • 333. 333 5. Conditonal text ouput IF - ENDIF You can use IF/ENDIF like in a normal ABAP program /: IF condition : : /: ENDIF and /: IF condition : /: ELSE : /: ENDIF Example: /: IF &SPFLI-CITYTO& = "BERLIN" * ..... put some text here /: ENDIF Frames lines and shading BOX Draws a box Syntax: /: BOX <xpos> <ypos> <width> <height> <frame> <intensity> The intensity is the grey scale of the box as %. The frame parameters is the thickness of the frame. Default is 0. Each of the paramteters ypos, xpos, width, height and frame muts be followed of the measurement unit: TW (twip) PT (point) IN (inch)
  • 334. 334 MM (millimeter) CM (centimeter) LN (line) CH (character). Examples: /: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10 FRAME 0 TW /: BOX FRAME 10 TW Draws a frame around the current window with a frame thickness of 10 TW (= 0.5 PT). /: BOX INTENSITY 10 Fills the window background with shading having a gray scale of 10 %. /: BOX HEIGHT 0 TW FRAME 10 TW Draws a horizontal line across the complete top edge of the window. /: BOX WIDTH 0 TW FRAME 10 TW Draws a vertical line along the complete height of the left hand edge of the window. /: BOX WIDTH '17.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15 /: BOX WIDTH '17.5' CM HEIGHT '13.5' CM FRAME 10 TW /: BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW /: BOX XPOS '13.5' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW Draws two rectangles and two lines to construct a table of three columns with a highlighted heading section. POSITION and SIZE You can use the POSITION and SIZE commands to set default parmeters for a box. This can be usefull if you have several boxes that share the same parameters. Example: /: POSITION XORIGIN '11.21' YORIGIN '5.31' MM /: SIZE HEIGHT '2' MM WIDTH '76' MM /: BOX FRAME 10 TW INTENSITY 10 If you want to set the position realtively to the window use POSITION WINDOW to set the position to the top/left start of the window. Then use POSITION to set the current position relatively to the start of the Window. Note that you uses "+" or "-" in the ORIGIN position to the set the position relatively. /: POSITION WINDOW
  • 335. 335 /: POSITION XORIGIN '+5' MM YORIGIN '+10' MM the position is now 5 MM from the left and 10 MM from the top of the window. NOTE: After using the position command you can move the current position realtively to the last used position /: POSITION XORIGIN '+10' MM YORIGIN '+20' MM Now the position will be X = 15 and Y = 30 More examples: /: POSITION WINDOW Sets the origin for the coordinate system to the upper left corner of the window. /: POSITION XORIGIN 2 CM YORIGIN '2.5 CM' Sets the origin for the coordinate system to a point 2 cm from the left edge and 2.5 cm from the upper edge of the output page. /: POSITION XORIGIN '-1.5' CM YORIGIN -1 CM Shifts the origin for the coordinates 1.5 cm to the left and 1 cm up. Drawing a line You can draw a line by setting the Height or Width of a box to 0 and add a frame. E.g. a horizontal line: /: SIZE HEIGHT '0' MM WIDTH '200' MM /: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100 Window and Page WINDOW sets the values for the width and height to the values of the current window (default setting). PAGE Sets the values for the width and height to the values of the current output page. Examples: /: SIZE WINDOW Sets WIDTH and HEIGHT to the current window dimensions. /: SIZE WIDTH '3.5' CM HEIGHT '7.6' CM Sets WIDTH to 3.5 cm and HEIGHT to 7.6 cm. /: POSITION WINDOW
  • 336. 336 /: POSITION XORIGIN -20 TW YORIGIN -20 TW /: SIZE WIDTH +40 TW HEIGHT +40 TW /: BOX FRAME 10 TW A frame is added to the current window. The edges of the frame extend beyond the edges of the window itself, so as to avoid obscuring the leading and trailing text characters. Structure of a print program The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options. * Open form printing - Must be called before working with any of the other form function modules. Must be ended with function module CLOSE FORM call function 'OPEN_FORM'..... *To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM call funtion 'START_FORM'..... * Write text elements to a window of the form call function 'WRITE_FORM'..... * Ends form call funtion 'END_FORM'..... * Closes form printing call function 'CLOSE_FORM'.... Examples of function calls OPEN FORM * Structure for the OPTIONS parameter DATA BEGIN OF OPTIONS. INCLUDE STRUCTURE ITCPO. DATA END OF OPTIONS.
  • 337. 337 OPTIONS-TDDEST = '*'. OPTIONS-TDIMMED = '*'. OPTIONS-TDDELETE = '*'. OPTIONS-TDNEWID = 'X'. CALL FUNCTION 'OPEN_FORM' EXPORTING * APPLICATION = 'TX' * ARCHIVE_INDEX = * ARCHIVE_PARAMS = DEVICE = 'PRINTER' DIALOG = 'X' * FORM = ' ' * LANGUAGE = SY-LANGU OPTIONS = OPTIONS * MAIL_SENDER = * MAIL_RECIPIENT = * MAIL_APPL_OBJECT = * RAW_DATA_INTERFACE = '*' * IMPORTING * LANGUAGE = * NEW_ARCHIVE_PARAMS = * RESULT = EXCEPTIONS CANCELED = 1 DEVICE = 2 FORM = 3 OPTIONS = 4 UNCLOSED = 5 MAIL_OPTIONS = 6 ARCHIVE_ERROR = 7 INVALID_FAX_NUMBER = 8 MORE_PARAMS_NEEDED_IN_BATCH = 9 OTHERS = 10 . IF sy-subrc <> 0. ............................... ENDIF. START_FORM CALL FUNCTION 'START_FORM' * EXPORTING
  • 338. 338 * ARCHIVE_INDEX = FORM = 'MY_FORM' * LANGUAGE = ' ' * STARTPAGE = ' ' * PROGRAM = ' ' * MAIL_APPL_OBJECT = * IMPORTING * LANGUAGE = * EXCEPTIONS FORM = 1 FORMAT = 2 UNENDED = 3 UNOPENED = 4 UNUSED = 5 OTHERS = 6 WRITE_FORM See 'WRITE_FORM' END_FORM CALL FUNCTION 'END_FORM' * IMPORTING * RESULT = EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 OTHERS = 3 CLOSE_FORM * Structure for Print options (return values) - Pages selected for printing, Number of copies etc. DATA BEGIN OF RESULT. INCLUDE STRUCTURE ITCPP. DATA END OF RESULT. CALL FUNCTION 'CLOSE_FORM' IMPORTING RESULT = RESULT * RDI_RESULT = * TABLES
  • 339. 339 * OTFDATA = * EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 * SEND_ERROR = 3 * OTHERS = 4 . WRITE FORM function module The print program is used to print forms. The program retieves the necesary data from datbase tables, defines the order of in which text elements are printed, chooses a form for printing and selects an output device and print options. * Open form printing - Must be called before working with any of the other form function modules. Must be ended with function module CLOSE FORM call function 'OPEN_FORM'..... *To begin several indentical forms containing different data within a single spool request, begin each form using START_FORM, and end it using END_FORM call funtion 'START_FORM'..... * Write text elements to a window of the form call function 'WRITE_FORM'..... * Ends form call funtion 'END_FORM'..... * Closes form printing call function 'CLOSE_FORM'.... Examples of function calls OPEN FORM * Structure for the OPTIONS parameter DATA BEGIN OF OPTIONS. INCLUDE STRUCTURE ITCPO.
  • 340. 340 DATA END OF OPTIONS. OPTIONS-TDDEST = '*'. OPTIONS-TDIMMED = '*'. OPTIONS-TDDELETE = '*'. OPTIONS-TDNEWID = 'X'. CALL FUNCTION 'OPEN_FORM' EXPORTING * APPLICATION = 'TX' * ARCHIVE_INDEX = * ARCHIVE_PARAMS = DEVICE = 'PRINTER' DIALOG = 'X' * FORM = ' ' * LANGUAGE = SY-LANGU OPTIONS = OPTIONS * MAIL_SENDER = * MAIL_RECIPIENT = * MAIL_APPL_OBJECT = * RAW_DATA_INTERFACE = '*' * IMPORTING * LANGUAGE = * NEW_ARCHIVE_PARAMS = * RESULT = EXCEPTIONS CANCELED = 1 DEVICE = 2 FORM = 3 OPTIONS = 4 UNCLOSED = 5 MAIL_OPTIONS = 6 ARCHIVE_ERROR = 7 INVALID_FAX_NUMBER = 8 MORE_PARAMS_NEEDED_IN_BATCH = 9 OTHERS = 10 . IF sy-subrc <> 0. ............................... ENDIF. START_FORM
  • 341. 341 CALL FUNCTION 'START_FORM' * EXPORTING * ARCHIVE_INDEX = FORM = 'MY_FORM' * LANGUAGE = ' ' * STARTPAGE = ' ' * PROGRAM = ' ' * MAIL_APPL_OBJECT = * IMPORTING * LANGUAGE = * EXCEPTIONS FORM = 1 FORMAT = 2 UNENDED = 3 UNOPENED = 4 UNUSED = 5 OTHERS = 6 WRITE_FORM See 'WRITE_FORM' END_FORM CALL FUNCTION 'END_FORM' * IMPORTING * RESULT = EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 OTHERS = 3 CLOSE_FORM * Structure for Print options (return values) - Pages selected for printing, Number of copies etc. DATA BEGIN OF RESULT. INCLUDE STRUCTURE ITCPP. DATA END OF RESULT. CALL FUNCTION 'CLOSE_FORM' IMPORTING RESULT = RESULT
  • 342. 342 * RDI_RESULT = * TABLES * OTFDATA = * EXCEPTIONS * UNOPENED = 1 * BAD_PAGEFORMAT_FOR_PRINT = 2 * SEND_ERROR = 3 * OTHERS = 4 . CONTROL_FORM Calling Commands Using a program The function module CONTROL_FORM can be used to create SapScript control statements from within an ABAP program. Example: call function 'CONTROL_FORM' EXPORTING COMMAND = 'PROTECT'. call function 'WRITE_FORM'..................... call function 'CONTROL_FORM' EXPORTING COMMAND = 'ENDPROTECT'. Boxes Lines Shading Setting default parameters for a box: You can use the POSITION and SIZE commands to set default parmeters for a box. Instead of: /: BOX XPOS '11.21' MM YPOS '5.31' MM HEIGHT '10' MM WIDTH '20' MM INTENSITY 10 FRAME 0 TW
  • 343. 343 You can write: /: POSITION XORIGIN '11.21' YORIGIN '5.31' MM /: SIZE HEIGHT '2' MM WIDTH '76' MM /: BOX FRAME 10 TW INTENSITY 10 This can be usefull if you gave several boxes that share the same parameters If you want to set the position realtively to the window use POSITION WINDOW to set the position to the top/left start of the window. Then use POSITION to set the current position relatively to the start of the Window. Note that you uses "+" or "-" in the ORIGIN position to the set the position relatively. /: POSITION WINDOW /: POSITION XORIGIN '+5' MM YORIGIN '+10' MM the position is now 5 MM from the left and 10 MM from the top of the window NOTE: After using the position command you can move the current position realtively to the last used position /: POSITION XORIGIN '+10' MM YORIGIN '+20' MM Now the position will be X = 15 and Y = 30 Drawing a line. You can draw a line by setting the Height or Weidth to 0 and add a frane. E.g. a horizontal line: /: SIZE HEIGHT '0' MM WIDTH '200' MM /: BOX FRAME 10 TW XPOS '11.21' MM YPOS '14.81' MM INTENSITY 100 Styles Styles are used to predefine paragraph and character formats for forms. SAP provides several standard styles e.g. for Address includes, on-line documentation and so on. You can define your own styles. To find styles, create styles and maintaine styles, use transaction SE72.
  • 344. 344 You assign style to a text by using menu Format -> Style You can make temporary style changes using the control command /: STYLE Using graphics in SapScript Use transaction SE78 to inmport graphics to SAP. In the form painter, you can either include directly to the form using menu Edit->Graphic- >Create or using the INCLUDE statement in a window. To use an INCLUDE stanment, goto into the woindow script editor and use menu Include- >Graphic. The include can look like this for a bitmap: /: BITMAP MYLOGO OBJECT GRAPHICS ID BMAP TYPE BMON Modifications Considerations in connection with modifications The standard SAP print program should only be changed when it is absolutely necessary. If additional data is needed, these can in many cases be retrieved using a a PERFORM statement in the form instead of changing the print program.. There can be the following reasons to change the print program: Structureal changes New text eloements are needed Print program to be used to print additional forms Determine/change which forms and printprograms that are used for printing The forms and print programs for a given output type and application can be found in table TNAPR Processing programs for output Use view V_TNAPR in (Transaction SE30) to change entries. TROUBLE-SHOOTING SAP SCRIPTS: In this section, I have explained regarding some of the errors that occur while using the SAP Scripts with each error in each step.
  • 345. 345 STEP1: Check List of things before Trouble shooting SAP Scripts: Following things needs to be check listed before starting the trouble shooting for the sap scripts.  The form and its ABAP print program are used  We have to check out whether the SAP standard versions are used or form or whether the driver program are modified?  If we are using the printer to take the printouts?  If the printer is used then check whether its device type is Standard SAP device or whether it is defined by the user. STEP2: If there are errors that data or field Contents are missing or the Includes or the symbols are not Printed In case of missing data, first of all check the data in the spool.  If the data gets printed correctly in the spool, then there might be problem with the printer.  If data is not found in the spool then there can be problem with the print program. And if it is ok with the print program then check with the form. Step3: If the field values are not printed correctly  If the field values are not printed correctly then debug the print program. If the fields are not declared then SAP script will not read those fields. Step 4: Error while reading the print program name.  Generally the name of the print program is passed to ITCPO-TDPROGRAM parameter of the OPEN_FORM function module. If the name is not passed correctly then this error occurs. Step 5: Error ‘INCLUDE is not found’.  Include is set in the following format /: INCLUDE <name> OBJECT <object> ID <id> LANGUAGE <l> If those variables values are not assigned correctly, then this error occurs. Step6: Error that text is not printed correctly’.  This can be verified by including the sample text in the text element and activate the form. If it prints correctly then there will problem with the include parameters.  If the sample text is not printed then it is problem with the text element and it is not called from the print program.
  • 346. 346  There will also be problem with language defined and the language used also. Step 7: Error in fonts:  Generally SAP Scripts uses printer font which is almost same as the form submitted. If the printer font and the submitted form font are not matched then this error occurs. Step 8: Error ‘Text is not printed correctly in the desired positions’.  First Check whether the tabs are used. If the field to be placed between the tab positions is larger than the gap available at that particular position then there is a possibility of the text not printed correctly in the desired positions.  If the alignments are not given correctly then also there will be a chance for not printing the text in the desired positions.  Check if the standard drivers are used for printing as the standard drivers cannot over prints the text. Step 9: Special characters are replaced by normal characters:  Check whether any standard SAP Device is used and whether it supports the required character set.  If not got to transaction SPAD and check whether the required character set matches with the character set there.  If not goto transaction sp01 and by using using the display function print the character. If it prints correctly in the output controller then there problem persists with the printer .  If not check if there are any changes made to the page code definiton in spool adminstration. If yes, execute the program RSTXDELL by selecting the character set in the execution screen . Upon execution all the character sets are deleted. Step 10: Using the SAP Script Form Debugger  Errors that occur in sap script can be mostly identified by using the SAP Script debugger.  First debugger is activated and the printer output is verified in the dialog box.  Every function module, include and every warning are verified in the debugger.  To turn off the debugger, choose Debugger and press exit in the debugger window. 6. Need for Performance Tuning for driver Programs:
  • 347. 347 Performance tuning for the driver program is essential to reduce the processing time taken by that driver program and to make it efficient in doping its work. An efficient driver program delivers the script output to the user in a finite time as per the complexity of the program. 7. Queries Related to Sap scripts: 1. How to list out all sap scripts in ZH (any language)? Sol: GO to TADIR table give OBJECT as 'FORM ' and MASTERLANG as 'ZH'. Then u will get all form names in that language. 2. How to divide the sap script main window into 99 times? Sol: Go to SAP script (SE71) -> Page window tab -> Edit -> Main window there a pop up appears and you can give according and you can get the number of windows. 3. How can we download the sap scripts to our PC? Sol: Use the program RSTXSCRP. On execution, select the radio button ‘Form’. In Mode give EXPORT. Provide the Form Name in Object Name And Save with .FRM extension. 4. What is the significance of following symbols in text element editor. Sol: Syntax: &symbol(<)& The leading sign is normally displayed to the right of a numeric value, except in the case of a floating point number. This option enables you to specify that the leading sign should be placed to the left of the number. Syntax: &symbol(>)& The default setting is to print the leading sign to the right of a numeric value. If you used the SET SIGN LEFT control command to specify that the leading sign should be printed in front of the value, you can override this specification for individual symbols. The symbols specified with the > option are then printed with the leading sign to the right. Syntax:&symbol(Z)& Certain symbol values are printed with leading zeros. If you want to suppress these, use the Z option. 5. What is the procedure to display the SAP Script in different languages? Sol:  Go to transaction se63.  Translation-ABAP objects--- Other Long texts- Expand FS forms and styles
  • 348. 348  Select FORM Forms By double clicking on the Forms  Provide the Object name which is nothing but the form name.  Provide the Source Language And Target language.  Then got to edit  Select The Radio Button as Window Texts and Documentation.  Open it in Change Mode.  Change the Texts and Elements.  Save It and activate it. 6. What is the ‘LPD’ error in sap scripts? Sol:  This error occurs when the text in the sub windows is not fitted in the size of the window. In order to overcome this error the text length inside the window is checked with the window size. This error occurs only in the case of sub windows. 7. How to import a logo to window in sap script? Sol: Go To ->SE78 (Graphics Administration). On Left Panel ->Stored on document server -> Graphics -> Bitmap Images. On Right Window-> (Store on document server) Enter the file you want to mention which is on your Hard disk (Say) (C:/Windows...) Go To->Click on Import button on the left Toolbar. Rest follows the process. In your Script Text Editor: Go To->Insert->Graphics->Store on Document server. Name->Copy and Paste it from->SE78. Sample Code for Logo how will it look after inserting the graphics logo. /: BOX FRAME 20 TW * P1 /: BITMAP 'LOGO' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 100 8. How to transfer the scripts? Sol: There are 3 ways to transfer scripts. They are a. Using program RSTXR3TR - By using the transport requests b. Using program RSTXSCRP - It transfers the script from one server to the other server.
  • 349. 349 c. Using transaction SCC1 - It copies the script in one client to the other client. 9. Are the scripts Client dependent or independent? Sol: Scripts are client dependent, because the changes done in one client will not be reflected in to other and also scripts are stored in ITF format as text in client dependent tables STXH and STXL. 10. Why the error “WRITE_FORM is invalid” occurs? Sol: If the correct element name is not given while calling the function module ‘WRITE_FORM’ then this error occurs. 11. Why we use open form, write form, close form , start form and end form in scripts? Sol: OPEN_FORM: This form opens the script. The module OPEN_FORM opens layout set printing. WRITE_FORM: This form is used to write the content mentioned in the windows of the SAP Script. START_FORM: This form is dynamically call a page in the script. The layout set can be changed in the current print procedure with START_FORM. This may also be used to trigger a new-spool id. END_FORM: This form is used to close the current layout set. CLOSE_FORM: This form closes the current SAP script form. You can have any number for WRITE_FORM, START_FORM and END_FORM, but for a script you can have only one OPEN_FORM and CLOSE_FORM. 12. Some standard programs and their functionalities: Sol: RSTXFCOM: Comparison of Two Forms RSTXFCON SAP script: Conversion of Page Format for Forms RSTXFCPY: Copy Forms Between Clients RSTXFDEL: Delete and Repair RSTXFINF: Comprehensive Information about a Specific Form RSTXFLST: Display Forms in Two Different Clients 13. How to find all SAP scripts and their driver programs? Sol:  NACE T-Code is used for finding all the driver programs linked to forms or by using the table TNAPR, we can find script form names and their driver programs.
  • 350. 350  Go to table TTXFP , there we can find the forms and their corresponding print programs. 14. How to migrate Sap scripts to smart forms? Sol:  Go to the SAP Smart Forms initial screen (transaction SMARTFORMS).  In the Form field enter the name of the Smart Form you want to create.  Migrate SAP script form  Choose Utilities The dialog window Migrate SAP script Form appears.  Enter the name and the language of the source form (SAP script).  Click Enter. This takes you to the change mode of the SAP Form Builder. If the selected SAP script form does not exist in the selected language, a dialog window appears on which you can select one of the existing languages.  Now change the design of the form and of the form logic. To activate the Smart Form choose Activate. Alternate Method:  By using the standard program ‘SF_MIGRATE’ the sap scripts can be migrated to smart forms.
  • 352. 352
  • 353. 353 INDEX Introduction ..……………………………………………………………………………….4 How to find user exits ………………………………………………………………………5 Case 1: User Exit name is not known ………………………………………………..5 Case 2: User Exit name is known …………………………………………………..10 Using Project management of SAP Enhancements ……………………………..................12 A. Project creation ………………………………………………………………………12 B. Enhancement Assignment …………………………………………………………....13 Test for User Exit …………………………………………………………………………..14 A. Sales Order creation ………………………………………………………………….14 B. Display Sales …………………………………………………………………………17 Summary …………………………………………………………………………………....19 References …………………………………………………………………………………..19
  • 354. 354 Introduction User exit is a functionality provided by SAP to add custom validation or enhancements to existing SAP transaction. User exit offer you the option of enhancing existing functions according to your personal requirements. Every module pool has customer function FORM in PBO and PAI. This form is basically a function that has an INCLUDE object. User can include enhancements or source code that will be triggered during execution of this transaction. The exit is implemented as a call to a function module. The code for the function module is written by the developer. You are not writing the code directly in the function module, but in include that is implemented in the function module. The naming standard of function modules for function module exits is: EXIT_<program name><3 digit suffix> The call to a function module exit is implemented as: CALL CUSTOMER.-FUNCTION <3 digit suffix> Note: This enhancement is used to create settlement rules to internal orders as receivers based on the company code of the cost center and fiscal year.
  • 355. 355 How to find user exits CASE 1: User Exit name is not known Display the program where you are searching for an exit and search for CALL CUSTOMER
  • 356. 356
  • 357. 357 This screen consists of call customer-function which has an exit ‘001’. Double click on ‘001’ in above screen. It will lead to include where exit is being called.
  • 358. 358 This screen consists of function call to trigger user exit when all necessary requirement will be fulfilled. This oval shows entire function call for exit ‘001’.
  • 359. 359 This oval has exit to be triggered. Again double click on ‘001’ in above screen which navigates to function module exits for the exit. This screen is displaying function module exits for the exit which has include where required logic has been implemented in the form of code. This function module will get executed when user exit will be triggered.
  • 360. 360 In above screen oval showing include where logic needs to be implemented. CASE 2: User Exit name is known If you know the Exit name, go to transaction CMOD. Choose menu Utilities->SAP Enhancements. Enter the component name as name of function module exits. Execute (F8).
  • 361. 361 Above screen showing function module name in oval where logic should be implemented. Double click on function module name used for user exit. You will now come to a screen that shows the function module exits for the exit. In this screen we have include (showing in oval) to code the logic.
  • 362. 362 Using Project management of SAP Enhancements
  • 363. 363 A. Project Creation: We want to create a project to enhance transaction VA01 - Go to transaction CMOD - Create a project called ZASR0001 This project is required to assign enhancement to trigger the user exit. B. Enhancement Assignment
  • 364. 364 - Choose the Enhancement assign radio button and press the Change button In the first column enter COOM0003 Predefine sold-to party in sales document. Note that an enhancement can only be used in one project. If the enhancement is already in use, and error message will be displayed. Press Save.
  • 365. 365 Press Components. You can now see that enhancement uses user exit EXIT_SAPLKOBS_001. Double click on the exit. Above screen has function module (showing in oval) where it has an include to code required logic. Now the function module is displayed. Double click on include where we need to code in the function module Insert the code into include. In this example Sales order line items will need to be settled to post Results Analysis data to FI. SAP requires settlement rules to be assigned to sales order line items to enable posting. Settlement rules will need to be created automatically to support month end settlement to internal orders. Activate the include program. Go back to CMOD and activate the project.
  • 366. 366 Test for User Exit A. Sales Order creation Go to transaction VA01 and create a sales order. Example: For sales order creation Sold-to-Party, Sales Organization, Distribution channel and Division is required to enter. In this example Sold-to-party will be 5999999999. The receiver internal order will need to be obtained from a custom table that will map the internal order which will be the settlement receiver by the company code and profit center of the sales order item. Get single record from table ZSETRULE_MAP where the company code and profit center combination in the mapping table. Get records from the mapping table for company code and profit center combination corresponding to the sales order item. Goto transaction VA01 and give required detail and Enter.
  • 367. 367 Enter Sold-to-party, Req.deliv.date, Material, Target quantity and item category at the input and press Enter in order to create Sales Order (Oval showing all required input field to be entered). At the next screen we need to give Sales District. Press Save. After save, system creates sales order. In this process records from the mapping table where company code from mapping table = company code of the sales order obtained from table VBAK. Get sales order number from VBAP- VBELN using the sales order object number field which is an import parameter COBRA-OBJNR as a link to VBAP-OBJNR. And where profit center ZSO_PRCTR from mapping table = profit center of the sales order item from VBAP-PRCTR. Only sales orders line for ZATM, ZAFS and ZAFM item category codes will need to be selected for this purpose. Settlement profile for line items with this item category will automatically be defaulted by the item category of the sales order line item.
  • 368. 368 B. Display Sales Order To display sales order detail, go to transaction VA03. Enter sales order number which needs to be displayed. Press enter.
  • 369. 369 Select the line item for which settlement rule is need to be displayed. Double click on line item which leads to next screen. At this screen go to Account Assignment tab and press. A settlement rule tab will appear on the screen. Press it. Settlement detail will appear as given below: If no settlement rule is defined for that material then it will display information “No Settlement rule is defined”.
  • 370. 370 Summary: This user exit has been created to create settlement rules to internal orders as receivers based on the company code of the cost center and fiscal year. Sales order line items will need to be settled to post Results Analysis data to FI. SAP requires settlement rules to be assigned to sales order line items to enable posting. Settlement rules will need to be created automatically to support month end settlement to internal orders. Only sales orders line for specified item category codes will need to be selected for this purpose. Settlement profile for line items with this item category will automatically be defaulted by the item category of the sales order line item. This process can be followed for other function module User Exit. Documentation for project User-Exits in PO/GR. What is User Exit ? You can use User Exits to adapt the SAP System to your company's specific requirements. They do not involve modifications to the original coding; instead, they consist of a separate area that is defined by SAP and shipped with the standard system either empty or with default values. You can individually configure and activate these system extensions. By enhancing the SAP software via user exits, we avoid modifications in the traditional sense. A further advantage of user exits is that programs developed with user exits remain unchanged during upgrades to the SAP software. User exits are not affected by SSCR, because the customer-specific parts of the user exits are implemented in the customer name range. Categories of User Exits Three types of user exits exist:  Function exits. Function exits are function modules that have been defined by SAP and that you can activate. The application developers determine which data is passed on and define the function groups and function modules in the function library (with short text and interface, but without coding).  Menu exits. Menu exits can be used to activate menu items and furnish them with additional functionality.  Screen exits. Screen exits enable you to add additional fields to a screen.
  • 371. 371 You can only take advantage of exits if SAP has added them to one of its standard applications. For this reason, you need to know how to locate the exits available in the SAP System. SAP organizes its exits in packages are called SAP enhancements. Each SAP enhancement can contain many individual exits. Different ways to find out user exits for a particular application. 1> Using transaction CMOD- Steps:- Choose Utilities Enhancements Project management from the ABAP Workbench menu. From here, choose Utilities  SAP enhancements to call a selection screen that lets you look for the exits available in standard applications. If you do not know the name of a specific enhancement package, you can search for enhancements by development class. To list all enhancements in the entire system, choose the Execute function without specifying any selection criteria. The system displays a list of all enhancement packages. 2> Using transaction SE81- Steps:- Use the Application Hierarchy to search for exits that are available for a particular application area. You can access the application hierarchy by choosing ABAP Workbench  Overview  Application hierarchy The SAP Application Hierarchy lists all of the standard SAP applications and their component parts. You can use the hierarchy with the Repository Information System to locate exits available for specific applications or programs. To locate the exits associated with Materials Management, for example, proceed as follows: 1. Place the cursor on the Materials Management branch of the Application Hierarchy tree and choose Sel./desel. sub-tree. The system marks the application area. 2. Choose Repository Infosys. The system lets you search for any objects assigned to a particular application. 3. Expand the Environment sub-tree in the Repository Information System. 4. Expand the Exit Techniques sub-tree. Choose either Enhancements or Projects for specific customer exit by double-clicking.
  • 372. 372 The system offers a selection screen that allows you to narrow down your search. You can leave the fields on this screen empty. 5. Choose Execute. The system will retrieve all the enhancements assigned the category you marked in the Application Hierarchy. 3> Using Transaction SPRO – IMG- Use IMG to locate the enhancements for desired application. For eg. To locate it for MM-Purcahsing, Follow the given path:- Select Material Management tree from initial screen. Select purchasing from this tree. You will get Enhancements for Purchasing item within this subtree. Click on Documentation icon to view all the User- exits supported for this area. List of User-Exits for PO/GR and their functionality- LMEDR001 Enhancements to print program (of purchasing Documents) LMELA002 Adopt batch no. from shipping notification when posting a GR Enhancement LMELA002 comprises a function module that is invoked when a GR is processed with reference to a shipping notification. This enhancement allows the batch number to be taken from the associated shipping notification as the default value for each item in the goods receipt. A prerequisite is that you use enhancement LMELA010 to adopt the batch numbers in the shipping notification.
  • 373. 373 M06E0004 Changes to communication structure for release purch. doc. M06E0005 Role determination for release of purchasing documents ME590001 Grouping of requsitions for PO split in ME59 Enhancement ME590001 allows you to use a non-standard-SAP logic for grouping requisitions for purchase orders or PO items when automatically converting requisitions into POs. In the standard system, you can use the selection parameters to specify that a new PO is to be created when one of the criteria "purchasing group", "plant", "storage location", "item category", "delivery date", "vendor sub-range", "purchase requisition number", "purchase requisition item", or "company code" changes. The function exit EXIT_SAPLME59_001 enables you to define any other criteria (example: see below). The function module has the following parameters: o T_EBAN Table with all requisitions that are to be converted. The table is pre-sorted according to the splitting criteria you selected on the selection screen. o T_EBANX Index table containing those requisitions for which a new PO or PO item is to be generated. This table is likewise pre-filled in the standard system. For example, the field T_EBANX-PO_NEW is filled with 'X' in the case of each requisition that is assigned to a different vendor than the preceding one.
  • 374. 374 Example: You want to generate a new purchase order for each requester shown in the requisition. The relevant source code in program ZXM01U01 might look like this: DATA: L_EBAN LIKE EBAN OCCURS 0 WITH HEADER LINE, L_TABIX LIKE SY-TABIX, NEXT_EBAN LIKE EBAN, NEW_PO LIKE SY-CALLD, OLD_AFNAM LIKE EBAN-AFNAM. LOOP AT T_EBAN. L_TABIX = SY-TABIX + 1. READ TABLE T_EBAN INDEX L_TABIX INTO NEXT_EBAN. IF SY-SUBRC NE 0. NEW_PO = 'X'. ELSE. READ TABLE T_EBANX WITH KEY BANFN = NEXT_EBAN-BANFN BNFPO = NEXT_EBAN-BNFPO. IF SY-SUBRC EQ 0 AND NOT T_EBANX-NEW_PO IS INITIAL. NEW_PO = 'X'. ELSE. CLEAR NEW_PO. ENDIF. ENDIF. APPEND T_EBAN TO L_EBAN. CHECK NEW_PO EQ 'X'. SORT L_EBAN BY AFNAM WERKS BANFN BNFPO. CLEAR OLD_AFNAM.
  • 375. 375 LOOP AT L_EBAN. IF SY-TABIX EQ 1 OR L_EBAN-AFNAM NE OLD_AFNAM. READ TABLE T_EBANX WITH KEY BANFN = L_EBAN-BANFN BNFPO = L_EBAN-BNFPO. IF SY-SUBRC EQ 0. T_EBANX-NEW_PO = 'X'. MODIFY T_EBANX INDEX SY-TABIX. ELSE. CLEAR T_EBANX. T_EBANX-BANFN = L_EBAN-BANFN. T_EBANX-BNFPO = L_EBAN-BNFPO. T_EBANX-NEW_PO = 'X'. APPEND T_EBANX. ENDIF. ENDIF. OLD_AFNAM = L_EBAN-AFNAM. ENDLOOP. APPEND LINES OF L_EBAN TO L_EBAN_ALL. REFRESH L_EBAN. ENDLOOP. T_EBAN[] = L_EBAN_ALL[]. MEAG0001 Distribution of contract/scheduling agreement from CRM MEETA001 Define schedule line type (backlog, immed. req., preview) MEFLD004 Determine earliest delivery date f. check w. GR (only PO) When goods are received with reference to a purchase order, the system checks the earliest delivery date against the GR date. The function exit of the enhancement MEFLD004 allows you to change the earliest delivery date and refuse to accept too-early deliveries, for example.
  • 376. 376 Whether or not the GR can be posted dependes on the attributes of the system message "Earliest possible delivery date is &" (message class M7, number 254). You specify in Customizing whether this is issued as an error or warning message or whether it does not appear at all. MELAB001 Gen. forecast delivery schedules: Transfer schedule implem. MEQUERY1 Enhancement to Document Overview ME21N/ME51N MEVME001 WE default quantity calc. and over/ underdelivery tolerance The enhancement MEVME001 comprises the user exit EXIT_SAPLEINR_001, which is invoked to calculate the default quantity in the case of a goods receipt against a scheduling agreement. Example If your vendors frequently deliver early, you can use this user exit to specify that instead of the quantity open to date, the quantity open up to the day after tomorrow is taken as the default quantity for a goods receipt. You can also specify that the tolerance check is to relate not to the default quantity but to the total scheduled quantity. This enhancement can be used to define the following data differently to that in the standard system: o Default quantity for goods receipt In the standard system, the quantity open to date from the last- transmitted SA release is used in the case of scheduling agreements with release documentation (document type LPA). In the case of scheduling agreements without release documentation (document type LP), the open quantity to date is used.
  • 377. 377 Note If you use vendor confirmations with GR assignment, the quantity from the confirmation is suggested (i.e. in this case, the default quantity cannot be influenced via the user exit. o The quantity to which the tolerance calculation is to relate (In the standard system, the tolerance check relates to the default quantity - i.e. the quantity open to date). At the time of the tolerance check, the tolerance limits for under- and overdeliveries entered in the scheduling agreement item are taken into account. The parameters F1 and F2 are passed on in the interface to the user exit. These parameters must contain the following data: Parameter F1 = Default quantity + total of all already delivered quantities (posted GR quantity) (The already delivered quantity is deducted again prior to the output of the default quantity on the screen.) Parameter F2 = Quantity to which the tolerance calculation relates All schedule lines for the relevant item are passed on in the internal table "CETT" as the basis for determining the default quantity and the tolerance. Note
  • 378. 378 Please note that the user exit applies to both document types. MM06E001 User exits for EDI inbound and outbound purchasing documents MM06E003 Number range and document number This enhancement allows you to specify (via function module EXIT_SAPMM06E_001) that you either o assign a document number yourself, or o only determine a number range ID The number range ID and all header data are then passed on to the following function module NUMBER_GET_NEXT. This determines the document number Example: You can assign the numbers in dependence on the company code. Depending on the company code, you choose a number range interval and then use the standard function module. In the event of an error, you can either issue your own error message or use the standard message via the exceptions. MM06E004 Control import data screens in purchase order MM06E005 Customer fields in purchasing document MM06E007 Change document for requisitions upon conversion into PO MM06E008 Monitoring of contr. target value in case of release orders MM06E009 Relevant texts for "Texts exist" indicator MM06E010 Field selection for vendor address MM06E011 Activate PReq Block
  • 379. 379 MMDA0001 Default delivery addresses MMFAB001 User exit for generation of release order MRFLB001 Control Items for Contract Release Order SAPL2012 Customer Exit from Enjoy: Purchase Orders via BAPIs SAPLMEWP Customer exit for processing of purchase orders via BAPIs SAPMMWE1 Create requirement coverage request - materials catalog data WVLB0003 User exits for automatic PO-based load building in 99.A WVLB0005 User exits in TR WLB5 (manual load bulding) WVLB000A User exits for control program for load building ---------------------------------------------------------GR---------------------------------------------- --------------- LIFO0040 User interfaces for LIFO valuation MBCF0002 Customer function exit: Segment text in material doc. item MBCF0005 Material document item for goods receipt/issue slip MBCF0006 Customer function for WBS element MBCF0007 Customer function exit: Updating a reservation MBCF0009 Filling the storage location field MBCF0010 Customer exit: Create reservation BAPI_RESERVATION_CREATE1 MBCF0011 Read From RESB and RKPF For Print List in MB26 MBCFC003 Maintenance of batch master data for goods movements MBCFC004 Maintenance of batch specifications for goods movements NIWE0000 Change quantities within scope of balance sheet valuation NIWE0001 Lowest value determination based on market prices NIWE0002 Lowest value determination by range of coverage or movement NIWE0003 Loss-Free Valuation WBWE0001 Function exits for valuation for structured materials
  • 380. 380 ALE – IDOC Scenario with Customized Idoc. Aim: Transfer the data from one system to another using user customized Idoc. Sender System: Server: 172.25.8.185 Client: 200 Data from Z table: zsach1 ReceiverSystem: Server: 172.25.9.198 Client: 800 Data from Z table: zsach1 Data is fetched from Z table on the sender system and inserted it in the Z table of Receiver system using ALE/IDOC. Document Designed by : Sachin Dabhade 09850848853
  • 381. 381 Settings on the Sender End Table Creation T – Code SE11. The table contains data that is to be sent to Receiver. ALE Configuration T-Code – SALE Defining Logical System 200 is our sender 800 is our receiver
  • 382. 382 Assigning Client to Logical System 200 is our sender 800 is our receiver Defining Target System for RFC Calls (Tcode – SM59)
  • 383. 383 Click on R/3 Connections and then Create TAB Step 1 Step 2
  • 384. 384 Defining Port The sender system is connected to the receiver system through this Port. Defining Partner Profiles
  • 385. 385 The partner for client 200(Sender) is the client 800 (Receiver) Since this is a sender we have to define only Outbound Parameters in this case. Here you can see the Message type is Z message type. 2. Maintaining Distribution Model ( TCode BD64 )
  • 388. 388 Now Distribute this Model View Distribute it from Edit  Model View  Distribute
  • 389. 389 Defining the Z Segment type Tcode – WE31 Defining the Basic Type T Code WE30
  • 390. 390 Click on New This will take you to next screen as follows
  • 391. 391 Here you have connected the basic type to the segment type. Enter again and this will take you to screen as follows This shows the relation between the basic and the segment types. Next you need to make the entry of the segment in the system table. Tcode : WE81
  • 392. 392 Next is the following entry which is required. Here you are specifying the message type and the basic type and the release version. This is all about the configuration you need to do on the sender side.
  • 393. 393 Now on the sender side you also need a program that will fetch the required data, couple it in the IDOC format and post it. Here is a small piece of code that could be useful. *&---------------------------------------------------------------------* *& Report ZSACH_CUST_IDOC * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* report zsach_cust_idoc . parameters : p_logsys like tbdlst-logsys. data : gen_segment like edidd-segnam value 'ZSACH'. data : control_dat like edidc, gen_data like z1hdr . tables :zsach1. data: begin of inttab occurs 0, lname type z1hdr-lname, fname type z1hdr-fname, end of inttab. data : int_edidd like edidd occurs 0 with header line, int_edidc like edidc occurs 0 with header line. select * from zsach1 into corresponding fields of table inttab. if sy-subrc ne 0. message 'no data' type 'I'. exit. endif. control_dat-mestyp = 'ZSACH'. control_dat-idoctp = 'ZSACH'. control_dat-rcvprt = 'LS'. control_dat-rcvprn = p_logsys. loop at inttab. gen_data-lname = inttab-lname. gen_data-fname = inttab-fname. * GEN_DATA-SSN = INTTAB-SSN. * GEN_DATA-DOB = INTTAB-DOB. int_edidd-segnam = gen_segment.
  • 394. 394 int_edidd-sdata = gen_data. append int_edidd. endloop. call function 'MASTER_IDOC_DISTRIBUTE' exporting master_idoc_control = control_dat * OBJ_TYPE = '' * CHNUM = '' tables communication_idoc_control = int_edidc master_idoc_data = int_edidd exceptions error_in_idoc_control = 1 error_writing_idoc_status = 2 error_in_idoc_data = 3 sending_logical_system_unknown = 4 others = 5 . if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno. else. loop at int_edidc. write :/ 'IDOC GENERATED',int_edidc-docnum. endloop. commit work. endif. Settings on the receiver side. The ALE configuration is same as we did it on the sender side. Please refer to earlier pages. The receiver specific differences are mentioned below. T-Code – SALE 200 is our sender 800 is our receiver
  • 395. 395 Steps Defining Logical System (Same as sender) Assigning Client to Logical System (Same as sender) Defining Target System for RFC Calls (Tcode – SM59) (Same as sender) Defining Port(Same as sender) Defining Partner Profiles – Here we are accepting the data from Sender system. Hence we need to configure it as Inbound.
  • 396. 396 Click on the sign above to go to next screen. Here the message type is to be created again as it was created on the sender side. The following steps are repeated on the receiver end Tcode WE30 Tcode WE31 Tcode WE82
  • 397. 397 Tcode WE81 Here on the receiver end, we need to specify a process code at the time of defining the partner profile. Process code is something that has the logic defined about what to be done after receiving the Idoc. In our case, on receipt of the Idoc, we are updating the Z Table. I.e Inserting the data from the Idoc into the Z Table. Creating a Process Code Tcode – WE42
  • 398. 398 The logic associated is coded in the Function Module which is specified in the Identification Field above. Also the processing type is selected as Processing by Function Module as above.
  • 399. 399 The function Module is specified in the following screen. To have your function Module in the above drop down list, the entry is to be made using the following transaction TCode – BD51 Once the entry is done here, the function module appears in the drop down list in the previous stage. Also it is important to make the following entry Tcode WE57
  • 400. 400 Function Module will look something as below:
  • 401. 401 Source Code function z_idoc_input_sach . *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD *" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC *" VALUE(NO_APPLICATION_LOG) LIKE SY-DATAR OPTIONAL *" VALUE(MASSSAVEINFOS) LIKE MASSSAVINF STRUCTURE MASSSAVINF *" OPTIONAL *" EXPORTING *" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT *" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR *" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK *" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
  • 402. 402 *" TABLES *" IDOC_CONTRL STRUCTURE EDIDC *" IDOC_DATA STRUCTURE EDIDD *" IDOC_STATUS STRUCTURE BDIDOCSTAT *" RETURN_VARIABLES STRUCTURE BDWFRETVAR *" SERIALIZATION_INFO STRUCTURE BDI_SER *" EXCEPTIONS *" WRONG_FUNCTION_CALLED *"---------------------------------------------------------------------- include mbdconwf. data : it_emp_data like zsach1 occurs 0 with header line. data : gen_data like zsach1 . workflow_result = c_wf_result_ok. * data : counter type int4. select count( * ) from zsach1 into counter. counter = counter + 1. loop at idoc_contrl. if idoc_contrl-mestyp ne 'ZSACH'. raise wrong_function_called. endif. clear gen_data. refresh it_emp_data. loop at idoc_data where docnum eq idoc_contrl-docnum. if idoc_data-segnam = 'ZSACH'. gen_data = idoc_data-sdata. it_emp_data-mandt = counter. it_emp_data-lname = gen_data-lname. it_emp_data-fname = gen_data-fname. counter = counter + 1. append it_emp_data. else. message 'ERROR' type 'I'. endif. endloop. endloop. * LOOP AT IT_EMP_DATA. * * CONCATENATE 'INB' IT_EMP_DATA-LNAME INTO IT_EMP_DATA-LNAME. * MODIFY IT_EMP_DATA. * ENDLOOP. * modify ZSACH1 FROM TABLE IT_EMP_DATA.
  • 403. 403 insert zsach1 from table it_emp_data. ***** call function 'EDI_DOCUMENT_OPEN_FOR_EDIT' exporting document_number = idoc_data-docnum importing idoc_control = idoc_contrl tables idoc_data = idoc_data exceptions document_foreign_lock = 1 document_not_exist = 2 document_not_open = 3 status_is_unable_for_changing = 4 others = 5. *itab_edidd-docnum = '0000000000221999'. *itab_edidd-psgnum = '000111'. *itab_edidd-sdata = itab_edidd-sdata. *APPEND itab_edidd. call function 'EDI_CHANGE_DATA_SEGMENTS' tables idoc_changed_data_range = idoc_data exceptions idoc_not_open = 1 data_record_not_exist = 2 others = 3. ***** data t_itab_edids40 like edi_ds40 occurs 0 with header line. clear t_itab_edids40. t_itab_edids40-docnum = idoc_data-docnum. t_itab_edids40-status = '51'. t_itab_edids40-repid = sy-repid. t_itab_edids40-tabnam = 'EDI_DS'. t_itab_edids40-mandt = sy-mandt. t_itab_edids40-stamqu = 'SAP'. t_itab_edids40-stamid = 'B1'. t_itab_edids40-stamno = '999'. t_itab_edids40-stapa1 = 'Sold to changed to '. *t_itab_edids40-stapa2 = t_new_kunnr. t_itab_edids40-logdat = sy-datum. t_itab_edids40-logtim = sy-uzeit. append t_itab_edids40. call function 'EDI_DOCUMENT_CLOSE_EDIT' exporting document_number = idoc_data-docnum do_commit = 'X'
  • 404. 404 do_update = 'X' write_all_status = 'X' tables status_records = t_itab_edids40 exceptions idoc_not_open = 1 db_error = 2 others = 3. endfunction.
  • 405. 405 Running the Application Sender system Checking the Idoc T Code WE02
  • 406. 406 Checking the data on the Receiver end Tcode: WE02 The Idoc has arrived here Checking the Data Double click on the Idoc
  • 407. 407 Checking the Database This way, the data has come to the receiver end successfully.
  • 408. 408 LSM Workbench LSMW Quick Ref and steps for XD02 This BOK provides a Quick Introduction to working with LSMW and step-by-step guide to update customer master records using XD02 in Standard Batch/Direct Input method. SI# Date Doc Version Author Reviewer Review Comments 1 05.02.2007 1.0 Lavanya Kundella Ramnarayana Halder TARGET READERS: Technical/Functional/Basis Consultants in SAP Practice Data Migration
  • 409. 409 Scope The focus of this BoK is to give a brief idea of LSMW and step-by-step guide to update customer master records using XD02 in Standard Batch/Direct input method. What is Data Migration/LSM?  Data transfer from non-SAP systems to SAP R/3.  Periodic data transfer.  Requires customized R/3 system.  Switch off legacy system. Figure 1: source: “help.sap.com” Why is data migration so expensive?  Need to develop conversion programs (which cannot be used later on)  Need to deal with lots of technical details and different technology. What is LSMW (Legacy System Migration Workbench)?  LSMW is R/3 based tool.  LSMW supports periodic and single data transfer from non-sap systems to R/3.  Uses standard R/3 interfaces.
  • 410. 410 How LSM Workbench works?  SAP AG July 1999 21 Accelerating Data Migration: LSM Workbench One or several files R/3Standard Convert data Batch Input processing Legacy data on PC Read data Converted data Read data Legacy data on application server IDoc inbound processing Direct Input processing How LSM Workbench works Structure relations Field mapping Conversion rules Figure 2: source: “help.sap.com” What kind of data can be read?  Data from spreadsheet-based applications. Ex: MS-Excel, MS Access etc.  Data from host systems on R/3 application servers.  Fixed record length, end of record indicator or hexadecimal length field at the beginning.  With and without separator.  Code page conversion.  “Hierarchical” data with identifying field values”. Which data can be migrated via LSMW? All data where an interface exists.  Standard Batch Input, Standard Direct Input.
  • 411. 411 1. Precondition: application program 2. Entries in table SXDA* (DX Workbench)  Batch Input Recording 1. Recording transaction 2. Flat target structure  Methods for Business Objects (BAPIs)  All BAPIs for which an ALE-IDOC interface has been generated.  IDOCs  All What LSMW can do?  Organize the data migration project  project, subproject, object  Document the data migration project  Define data conversion per object  select target  business object (ex: customer master, material master)  method (ex: create, change)  import technique (ex: batch-input, IDOCs)  define source  structure of the source data (segments, fields, file attributes etc)  define relations  between source and target (SAP R/3) on record level and on field level  define rules  transfer of field contents  Read data (technical conversion)  Convert data (conversion of values)  Import data  with a standard import technique  batch-input  direct input  method for a business-object (“BAPI”)  IDOCs technique  this means:  LSMW does not write data into the databases of the applications  precondition for the use of LSMW is the availability of a data transfer interface in the R/3 application  Transport the data migration object  via download and upload  via R/3 transport system
  • 412. 412 Advantages of LSMW?  Part of the SAP system and thus independent of individual platforms.  A variety of technical possibilities of data conversion.  Data consistency due to standard import techniques.  Generation of the conversion program on the basis of defined rules.  Clear Interactive process guide.  Charge-free for SAP customers and SAP partners. LSMW to Update Customer Master Records with Standard Object To start working with the LSM Workbench, use transaction LSMW Create an Object CUST_OBJ within Project as ZLK_LSMW and Subproject as CUSTOMERS. Figure 3 LSMW Object with Standard SAP Object Step 1: Maintain Object attributes You will be updating the customer master records with the help of Standard Batch Input; therefore, choose radio-button Standard Batch/Direct Input. Enter Object ‘0050’ for Customer Master Records and default method ‘0000’ and click on Save.
  • 413. 413 Figure 4 Standard Batch/Direct Input Object Attributes Step 2: Maintain Source Structures Give a name and a description to the source structure. Figure 5 Source Structure
  • 414. 414 Step 3: Maintain Source Fields 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 . Figure 6 Source fields of source Structure Note that your input file will have four fields as key fields and you need to update three fields in the system.
  • 415. 415 Step 4: Maintain Structure Relations 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. Figure 7 Structure Relation
  • 416. 416 Step 5: Maintain field mapping and conversion rules Keep your cursor on ‘TCODE’ field and click on ‘Insert Rule’ icon Figure 8 LSMW Conversion Rules Choose radio button ‘Constant’ 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’.
  • 417. 417 Figure 9 Assign Source fields Similarly, choose source fields for Sales Organization, Distribution Channel, and Division. Figure 10 Field Mapping and Conversion Rules
  • 418. 418 Scroll down to structure BKNVV fields and assign source fields to three fields Sales Office, Sales Group, and Customer Group Figure 11 Field Mapping and Conversion Rules Save and go back to main screen. Step 6: Maintain fixed values, translations, user-defined routines 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.
  • 419. 419 Figure 12 Maintain Fixed values, translations, user defined routines Step 7: Specify files 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 PC (local drive) as C:XD02.txt. Figure 12 Data in the tab delimited file Xd02.txt Source data in tab delimited file
  • 420. 420 Figure 13 Specify File name
  • 421. 421 Figure 14 Specify File name Step 8: Assign files Execute step ‘Assign Files’ and the system automatically defaults the filename to the source structure. Figure 15 Assign file to Source Structure
  • 422. 422 Step 9: Read data In this step, LSMW reads the data from the source file (from PC’s local drive). You have the option to read only selected rows and convert data values to internal format. Figure 16 Read Data Figure 17 Read Data
  • 423. 423 Step 10: Display read data This step is optional. If required, you can review the field contents for the rows of data read. Figure 17 Display Read Data Step 11: Convert data 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.
  • 424. 424 Figure 17 Convert Data Figure 18 Convert Data Step 12: Display Converted data When you convert data, LSMW automatically converts into the appropriate structure layouts, as required by Standard program (RFBIDE00).
  • 425. 425 Figure 19 Converted data into multiple structures Note that if you had only one record in source file, the converted file has four records. Earlier, creating this input file, so that the standard interface program can read it, was a big nightmare, the primary reason being that it could have multiple record layouts. Even for a simple conversion with one input record, you would have to create this complex file with many record layouts. The advantage of LSMW is that it prepares these multi-layout files automatically. Step 13: Create batch input session Once source data is converted in internal format, you can create a BDC session to process the updates.
  • 426. 426 Figure 20 Create BDC Session Figure 21 BDC Session ‘CUST_OBJ’ created Step 14: Run Batch Input Session 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).
  • 427. 427 Figure 22 BDC Session ‘CUST_OBJ’ Process Figure 23 Customer record updated with Customer Group
  • 428. 428
  • 429. 429
  • 430. 430
  • 431. 431
  • 432. 432
  • 433. 433
  • 434. 434
  • 435. 435
  • 436. 436
  • 437. 437
  • 438. 438
  • 439. 439
  • 440. 440
  • 441. 441 SAP's OPEN SQL, syntax of the SELECT statement Basic form: SELECT result FROM source [INTO target] [WHERE condition] [GROUP BY fields] [ORDER BY order]. SELECT clause Variants: 1. SELECT [SINGLE [FOR UPDATE] DISTINCT] * 2. SELECT [SINGLE [FOR UPDATE] DISTINCT] s1 ... sn 3. SELECT [SINGLE [FOR UPDATE] DISTINCT] (itab) FROM clause Variants: 1. ... FROM dbtab Additions: 1. ... CLIENT SPECIFIED 2. ... BYPASSING BUFFER 3. ... UP TO n ROWS 2. ... FROM (dbtabname) Additions: 1. ... CLIENT SPECIFIED 2. ... BYPASSING BUFFER 3. ... UP TO n ROWS INTO target (This form of the FROM clause works only in conjunction with the INTO clause.) INTO clause Variants: 1. ... INTO wa
  • 442. 442 2. ... INTO CORRESPONDING FIELDS OF wa 3. ... INTO (f1, ..., fn) 4. ... INTO TABLE itab 5. ... INTO CORRESPONDING FIELDS OF TABLE itab 6. ... APPENDING TABLE itab 7. ... APPENDING CORRESPONDING FIELDS OF TABLE itab WHERE clause Variants: 1. ... WHERE f op g 2. ... WHERE f [NOT] BETWEEN g1 AND g2 3. ... WHERE f [NOT] LIKE g 4. ... WHERE f [NOT] IN (g1, ..., gn) 5. ... WHERE f [NOT] IN itab 6. ... WHERE f IS [NOT] NULL 7. ... WHERE NOT cond 8. ... WHERE cond1 AND cond2 9. ... WHERE cond1 OR cond2 10. ... WHERE (itab) 11. ... WHERE cond AND (itab) 12. ... FOR ALL ENTRIES IN itab WHERE cond opera tor Meaning EQ or = equal to NE or <> not equal to LT or < less than LE or <= less than or equal to GT or > greater than or equal to GE or >= greater than or euqal to
  • 443. 443 GROUP-BY clause Variants: 1. ... GROUP BY f1 ... fn 2. ... GROUP BY (itab) ORDER-BY clause Variants: 1. ... ORDER BY PRIMARY KEY 2. ... ORDER BY f1 ... fn 3. ... ORDER BY (itab) Useful Dev. and Workbench Transactions SCAM CATT Management SCAT Computer Aided Test Tool SE09 Workbench Organizer SE10 Customizing Organizer SE11 ABAP/4 Dictionary Maintenance SE12 ABAP/4 Dictionary Display SE13 Maintain Technical Settings (Tables) SE14 Utilities for Dictionary Tables
  • 444. 444 SE15 ABAP/4 Repository Information System SE16 Data Browser SE17 General Table Display SE30 ABAP/4 Runtime Analysis SE32 ABAP/4 Text Element Maintenance SE35 ABAP/4 Dialog Modules SE36 ABAP/4: Logical Databases SE37 ABAP/4 Function Modules SE38 ABAP/4 Program Development SE39 Splitscreen Editor: Program Compare SE41 Menu Painter SE43 Maintain Area Menu SE51 Screen Painter SE54 Generate View Maintenance Module SE61 R/3 Documentation SE62 Industry utilities SE63 Translation SE64 Terminology SE65 R/3 document. short text statistics SE66 R/3 Documentation Statistics (Test!) SE68 Translation Administration SE71 SAPscript layout set SE72 SAPscript styles SE73 SAPscript font maintenance (revised) SE74 SAPscript format conversion SE75 SAPscript Settings SE76 SAPscript Translation Layout Sets SE77 SAPscript Translation Styles SE80 ABAP/4 Development Workbench SE81 SAP Application Hierarchy SE82 Customer Application Hierarchy SE84 ABAP/4 Repository Information System SE85 ABAP/4 Dictionary Information System SE86 ABAP/4 Repository Information System
  • 445. 445 SE87 Data Modeler Information System SE88 Development Coordination Info System SE91 Maintain Messages SE92 Maintain system log messages SE93 Maintain Transaction Codes SEU Object Browser SHD0 Transaction variant maintenance SQ00 ABAP/4 Query: Start Queries SQ01 ABAP/4 Query: Maintain Queries SQ02 ABAP/4 Query: Maintain Funct. Areas SQ03 ABAP/4 Query: Maintain User Groups SQ07 ABAP/4 Query: Language Comparison System field (sy-dbcnt)(2) REPORT ZBCTCB92. TABLES: T000. DATA: BEGIN OF T OCCURS 0, FIELD(10), END OF T. DATA: NUM TYPE N. DETAIL. * sy-linct and sy-linsz describes a page of the list WRITE: / 'Example of sy-linct and sy-linsz'. SKIP. WRITE: / SY-LINCT, 'line and', (3) SY-LINSZ, 'column is a page'. * sy-index works in do-enddo and while-endwhile loops. * it contains the number of loop passes. WRITE: /'Example of sy-index'. SKIP. DO 5 TIMES. WRITE: SY-INDEX. ENDDO. * sy-tabix is the index number of the currently processed row
  • 446. 446 * for an internal table SKIP. WRITE: /'Example of sy-tabix'. SKIP. T-FIELD = 'One'. APPEND T. T-FIELD = 'Two'. APPEND T. T-FIELD = 'Three'. APPEND T. T-FIELD = 'Four'. APPEND T. T-FIELD = 'Five'. APPEND T. WRITE: /'Example of sy-tabix I'. SKIP. LOOP AT T. WRITE: / SY-TABIX, T-FIELD. ENDLOOP. *sy-fdpos contains off-set after string comparison and search operations SKIP. WRITE: /'Example of sy-fdpos'. SKIP. CLEAR T. SEARCH T FOR 're'. READ TABLE T INDEX SY-TABIX. WRITE: / SY-TABIX, T-FIELD. SKIP. WRITE: /9 'At the example of sy-tabix, Row', (3) SY-TABIX, ',' , 'keyword ''re'' found at off-set position:', (3) SY-FDPOS. SKIP. * sy-dbcnt contains the number of selected records. * sy-subrc is 0 if an operation was successful. WRITE: /'Example of sy-dbcnt and sy-subrc I'. SKIP. SELECT * FROM T000 WHERE MANDT BETWEEN '000' AND '066'. WRITE: /10 'Mandant:', T000-MANDT. ENDSELECT. WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED.
  • 447. 447 WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC . SKIP. WRITE: /'Example of sy-dbcnt and sy-subrc II: don't find records'. SKIP. SELECT * FROM T000 WHERE MANDT EQ -1. ENDSELECT. WRITE: /12 'Number of selected records:', SY-DBCNT CENTERED. WRITE: /12 'Return code: ' RIGHT-JUSTIFIED, SY-SUBRC. System fields sy-lilli(3) REPORT ZBCTCB90 NO STANDARD PAGE HEADING LINE-COUNT 20 LINE-SIZE 255. TABLES: T000. DETAIL. DO 5 TIMES. SELECT * FROM T000. WRITE: / T000-MANDT, T000-MTEXT. ENDSELECT. NEW-PAGE. ENDDO. TOP-OF-PAGE. WRITE: / 'Page', SY-PAGNO. AT LINE-SELECTION. DETAIL. * SY-LSIND is the index of the current list WRITE: / 'SY-LSIND:', SY-LSIND LEFT-JUSTIFIED. * SY-LISTI is the index of the previous list WRITE: / 'SY-LISTI:', SY-LISTI LEFT-JUSTIFIED. * SY-LILLI is the number of the selected line in the absolute list WRITE: / 'SY-LILLI:', SY-LILLI LEFT-JUSTIFIED. * SY-CUROW is the position of the selected line on the screen WRITE: / 'SY-CUROW:', SY-CUROW LEFT-JUSTIFIED.
  • 448. 448 * SY-CUCOL is the position of the cursor in the window WRITE: / 'SY-CUCOL:', SY-CUCOL LEFT-JUSTIFIED. SKIP. WRITE: / 'SY-CPAGE and SY-STAR0 do not depend on the cursor position'. SKIP. * SY-CPAGE is the currently displayed page of the list WRITE: / 'SY-CPAGE:', SY-CPAGE LEFT-JUSTIFIED. * SY-STARO is the number of the topmost actual list line displayed * on the current page. WRITE: / 'SY-STARO:', SY-STARO LEFT-JUSTIFIED. SKIP. * SY-STACO is the number of the first displayed column on the * screen. Scroll the list right with the scrollbar to test it WRITE: / 'SY-STACO:', SY-STACO LEFT-JUSTIFIED. SKIP. * contents of the selected line WRITE: / 'SY-LISEL:', SY-LISEL. System fields V Program code REPORT ZBCTCB93 NO STANDARD PAGE HEADING. PARAMETERS: TEST. DATA: SESSION TYPE I. DATA: BEGIN OF T_TSTCT OCCURS 10. INCLUDE STRUCTURE TSTCT. DATA: END OF T_TSTCT. DETAIL. SESSION = SY-MODNO + 1. SET MARGIN 5 3. * The report must have a selection screen and from there execute+print * should be called the SET MARGIN to take effect. WRITE: / 'Number of this session:', SESSION. WRITE: / 'List starts from the ', SY-MACOL, ',', SY-MAROW, 'upper-left corner.'.
  • 449. 449 SKIP. WRITE: / 'This is the', SY-FDAYW, '. workday of the week.'. APPEND T_TSTCT. APPEND T_TSTCT. APPEND T_TSTCT. DESCRIBE TABLE T_TSTCT. WRITE: / 'Line width of internal table: 1 (lang) + 4 (tcode) + 36 (text) =', SY- TLENG. WRITE: / 'OCCURS parameter:', SY-TOCCU. WRITE: / 'Number of entries in internal table:', SY-TFILL System fields I Program code REPORT ZBCTCB93 NO STANDARD PAGE HEADING. DETAIL. WRITE: /5 'Logon name of the user: ' RIGHT-JUSTIFIED, 40 SY-UNAME. WRITE: /5 'Logon client: ' RIGHT-JUSTIFIED, 40 SY-MANDT. WRITE: /5 'Logon language: ' RIGHT-JUSTIFIED, 40 SY-LANGU. WRITE: /5 'Current date: ' RIGHT-JUSTIFIED, 40 SY-DATUM. WRITE: /5 'Current time: ' RIGHT-JUSTIFIED, 40 SY-UZEIT. WRITE: /5 'Current transaction: ' RIGHT-JUSTIFIED, 40 SY-TCODE. WRITE: /5 'Main program: ' RIGHT-JUSTIFIED, 40 SY-CPROG. SKIP. WRITE: /5 'SAP System ID: ' RIGHT-JUSTIFIED, 40 SY-SYSID. WRITE: /5 'SAP Release: ' RIGHT-JUSTIFIED, 40 SY-SAPRL. WRITE: /5 'Host: ' RIGHT-JUSTIFIED, 40 SY-HOST. WRITE: /5 'Operating system: ' RIGHT-JUSTIFIED, 40 SY-OPSYS. WRITE: /5 'Database system: ' RIGHT-JUSTIFIED, 40 SY-DBSYS. SKIP TO LINE 20. POSITION 10. WRITE: SY-COLNO, ',', SY-LINNO, 'Cursor position (column, row).'.
  • 450. 450 WRITE: 'New:', SY-COLNO,',',SY-LINNO. SKIP. SY-ULINE = '------ Underline ------'. ULINE (23). WRITE: /5 'Vertical bar:', SY-VLINE. TOP-OF-PAGE. DETAIL. WRITE: 2 'Report Title: ', SY-TITLE(20). WRITE: 'Page Number: ', SY-PAGNO. SKIP System fields IV Program code REPORT ZBCTCB99 NO STANDARD PAGE HEADING. PARAMETERS: TEST. DETAIL. IF SY-BATCH EQ SPACE. WRITE: / 'Report was started on-line'. WRITE: / 'Using variant:', SY-SLSET. ELSE. WRITE: / 'Report was started in background'. ENDIF. System fields VI SY-DATAR In transaction programming this field indicates the change of data on the screen. In the PBO part you may set default values of the input fields of the dynpro. In the PAI part you can check if they were changed. If SY-DATAR is set, then the user has modified or entered new data on the screen. SY-BINPT
  • 451. 451 This field indicates if the transaction was called in a Batch Input session or by an online user.To test it, a batch input session must be created. From Release 3.1g the next procedure can be used.  Create a report which displays this system field  Create a Transaction code for this report  Use transaction SHDB to record a the previous transaction  Press the Overview button and choose the 'generate program' function.  Running the previously generated program it will create a Batch Input session  Now call transaction SM35 and process the created Batch Input in foreground. It should display an 'X' for system field SY-BINPT. SY-CALLD This field indicates if the transaction was called from another transaction.  Create a report which displays this system field  Create a Transaction code for this report  Create a new report containing the next ABAP command: CALL TRANSACTION tcode. Where tcode is the Transaction code you created. When you run this report, it should display an 'X' for system field SY-CALLD. System fields VIII REPORT ZZBETO98. PARAMETERS: PARAM(6) DEFAULT 'TEST'. WRITE: / 'System variables for printing.'. WRITE: / 'Please check the spool for the printout'. SKIP. * check is necessary to prevent further recursive calls of this program. IF NOT ( SY-PDEST IS INITIAL ). SKIP. WRITE: / 'System variables for printing:'. SKIP. WRITE: / ' Layout: SY-PAART',SY-PAART. * This can be used in normal lists as well. * If used with 'new-page print on', it continues counting WRITE: / ' Current page number: SY-PAGNO', SY-PAGNO. WRITE: / ' Printer: SY-PDEST', SY-PDEST.
  • 452. 452 WRITE: / ' Priority: SY-PEXPI', SY-PEXPI. WRITE: / ' List name: SY-PLIST', SY-PLIST. WRITE: / ' Department: SY-PRABT', SY-PRABT. * output cover sheet with the report's parameters WRITE: / ' Output cover sheet: SY-PRBIG', SY-PRBIG. WRITE: / ' No. of copies: SY-PRCOP', SY-PRCOP. WRITE: / ' Dataset name: SY-PRDSN', SY-PRDSN. WRITE: / ' Print immediately: SY-PRIMM', SY-PRIMM. WRITE: / ' New list: SY-PRNEW', SY-PRNEW. * Receiver must be a valid user-id WRITE: / ' Receiver: SY-PRREC', SY-PRREC. WRITE: / ' Delete after output: SY-PRREL', SY-PRREL. WRITE: / ' Cover text: SY-PRTXT', SY-PRTXT. EXIT. ENDIF. SUBMIT ZZBETO98 TO SAP-SPOOL DESTINATION 'ST03' COPIES 3 LIST NAME 'NEWLIST' LIST DATASET 'TESTLIST' COVER TEXT 'Test of system variables' LIST AUTHORITY 'BASIS' IMMEDIATELY ' ' KEEP IN SPOOL 'X' NEW LIST IDENTIFICATION 'X' DATASET EXPIRATION '8' LINE-COUNT 90 LINE-SIZE 120 LAYOUT 'X_90_120' SAP COVER PAGE 'X' COVER PAGE 'X' RECEIVER 'SAP*' DEPARTMENT 'DEP.' WITHOUT SPOOL DYNPRO. System fields VII Program code REPORT ZSYSTEM. * You must click on a row to see results. DATA: L_SROW TYPE I VALUE 10. DATA: L_SCOL TYPE I VALUE 15.
  • 453. 453 DATA: L_EROW TYPE I VALUE 20. DATA: L_ECOL TYPE I VALUE 70. WRITE: / ' Initial values: '. WRITE: / ' SY-WINX1:', SY-WINX1. WRITE: / ' SY-WINX2:', SY-WINX2. WRITE: / ' SY-WINY1:', SY-WINY1. WRITE: / ' SY-WINY2:', SY-WINY2. AT LINE-SELECTION. WINDOW STARTING AT L_SCOL L_SROW ENDING AT L_ECOL L_EROW . WRITE: / ' Values are from the upper left corner of the window.'. SKIP. WRITE: / ' After displaying the new window: '. SKIP. WRITE: / ' SY-WINX1:', SY-WINX1, '(Column of the left side)'. WRITE: / ' SY-WINX2:', SY-WINX2, '(Column of the right side)'. WRITE: / ' SY-WINY1:', SY-WINY1, '(Row of the upper side)'. WRITE: / ' SY-WINY2:', SY-WINY2, '(Row of the lower side)'.
  • 454. 454