Sapabapmaterial 140803141350 Phpapp02 PDF
Sapabapmaterial 140803141350 Phpapp02 PDF
Sapabapmaterial 140803141350 Phpapp02 PDF
Sap architecture
Database update
Central DB
buffer
Output data to
the user
O bjectoriented
change
requests
(asynchronous)
Application logic
Input data
from the user
User interaction
SAP AG
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.
R /3
R /3
S y s te m
A p p lic a t io n
D a ta b a s e
C e n tra l s y s te m
D is tr ib u te d
p r e s e n ta tio n
T w o -tie r
c lie n t/s e r v e r
T h r e e -tie r
c lie n t/s e r v e r
S A P
A G
SAPG UI
SAPGUI
SAPG UI
SAPG UI
Com munication
Application
Dispatcher
W ork
process
W ork
process
W ork
process
Buffer
Database
SAP AG
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:
3
evenly distributing the transaction load among the work processes, interfacing with the
presentation level, organizing the communication activities.
SAPGUI
Term inal
process
1
7
Application
Request queues
2
Dialog object
3
6
W ork
process
RO LL
4
5
Database
Relational
database system
SAP AG
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.
DATA DICTIONARIES
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
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
Data type
Meaning
Tabname
CHAR(10)
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)
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
CLKEY2
...
...
...
CLKEYn
Pageno
INT2(5)
Timestamp
CHAR(14)
Time stamps
Pagelg
INT2(5)
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.
Transparent
Contain a single table.
Used to store master
data
Pool
They are used to hold
a large number of
very small
tables(stores
customizing data or
system data)
It has a one-to-one
It has a many-to-one
relationship with a
relationship with a
table in the database table in the database
For each transparent It is stored with other
table there is one
pooled tables in a
associated table in
single table called
the database
table pool in the
database
The database table
The database table
has the same name,
has different name,
same number of fields different number of
and the fields have
fields and fields have
the same names
different names
There is only a single
Table pools contain
table
more tables than
table clusters
Single table can have Primary key of each
one or more primary
table does not begin
key
with same fields or
fields
Secondary indexes
Secondary indexes
can be created
cannot be created
They can be accessed They can be accessed
using open and native using open SQL only
SQL
USE: They are used to USE: They reduce the
hold master data e.g. amount of database
Table vendors or
resources needed
table of customers.
when many small
Example of
tables have to be
transaction data is
opened at the same
orders placed by
time
customers
Cluster
They are used to hold
data from a few
number of large
tables.(stores system
data)
It has a many-to-one
relationship with
table in the database
Many cluster tables
are stored in a single
table in the database
called a table cluster
The database table
has different name,
different number of
fields and fields have
different names
Contains less tables
than table pools
Primary key of each
table begins with
same fields or fields
Secondary indexes
cannot be created
They can be accessed
using open SQL only
USE: They would be
used when the tables
have primary key in
common and data in
these tables are all
accesses
simultaneously
10
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:
11
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.
Application
Server
ABAP Program
Select Query
R/3 Database
table buffer
Database interface
Database
Server
Database
Database
buffer
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.
12
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?
13
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.
14
Example:
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
15
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.5. SQL Trace showing the duration of select statement executed first time in a fully
buffered table
16
Fig.6. SQL trace showing data fetched from buffer for subsequent select statement
17
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.
18
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.
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.
20
21
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.
22
23
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 networks 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.
ii.
iii.
iv.
v.
vi.
vii.
24
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).
2.
Enter the description, Delivery class and check on table maintenance allowed. Then click on the
tab Fields.
25
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.
26
5.
6.
Now it will ask for the creation of the data element. Press Yes.
27
7.
Click on the Field label tab and enter the lengths and descriptions accordingly.
8.
28
9.
Double click on that zchar_d to create domain, then it will ask for save before going next screen.
Press Yes.
29
12. Give short description for that domain which you are creating. And mention the data type in data
30
13. Then press Ctrl+F3. It will ask for save before activation. Save it as a local Object.
31
16. Press Ctrl+F3. You will get the following screen. Press Back button.
32
33
18. Create one more field ZNUM and give data element name as ZNUM_DE. And double click on
ZNUM_DE
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
34
22. Press on Definition tab and give the domain name in Domain field. Double click on ZNUM_D.
35
26. Give short description in short text field. Enter the data type and no. characters, Press Enter.
36
37
29. Now you will get the following screen. Press Back button.
38
30. Activate the data element By pressing Activate button or Pressing Ctrl+F3.
39
40
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.
41
34. Give the data class and size category of the table as per the requirement.
35. Now
activate
the
table
by
pressing
the
42
activate
button
or
CTRL+F3.
43
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.
44
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.
45
47
47. To see the table contents go to Utilities Table contents Display. Or press Ctrl+Shift+F10.
48
49. Press on run button or press F8. Now it will display the table contents.
49
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.
50
Step
4:
Then you go to maintain Poll Screen there give Short Description.
Step 5:
Then go to Technical settings.
51
Step 6:
In the Maintain technical Settings screen Provide Size category.
52
Step 8:
Maintain Delivery and Maintenance attributes for the Z table.
53
Step 9:
Then Go to Extras Change table category
Step 10:
Choose Table type.
In our Example it is Pooled table.
54
Step 11:
Go back to Delivery and Maintenance tab and provide Pool/Cluster value.
55
views
56
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.
57
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 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
58
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)
59
5. Choose the fields which you want to be displayed in output and click copy
60
61
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.
62
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.
63
64
65
Search helps
66
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)
67
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.
68
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.
69
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:
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.
70
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.
71
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.
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.
72
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.
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.
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.
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
73
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.
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)
74
(Place the cursor on the field to which the search help has to be assigned and click on the
button Search help)
In the selection screen of the executable programs the search helps can be assigned to
the parameters and select-options as follows:
Parameter
75
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.
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
76
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.
77
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
SOURCE_TAB
= The internal table into which you have selected the data
Now to skip the standard selection set the function module parameter CALLCONTROLSTEP 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
78
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
80
Table maintenence
81
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
82
Requirement:
A table is having certain no. of fields say field1 to field5. During the maintenance of the table by enduser, 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.
83
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.
84
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 wont 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.
85
86
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
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
AA
AB
AC
AD
AE
AF
AG
AH
ST
AI
88
89
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:
90
Dialog Data Transport details (Changing the option to Standard recording routine):
91
92
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)
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.
93
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:
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.
94
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.
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.
95
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.
96
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.
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.
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.
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.
proposed by the system but can be changed manually.
97
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.
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.
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.
98
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)
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.
99
In the selection screen of the executable programs the search helps can be assigned to
the parameters and select-options as follows:
Parameter
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.
100
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.
101
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
the exit . Pass the same
102
= This is available in
RECORD_TAB
SOURCE_TAB
= The internal table into which you have selected the data
Now to skip the standard selection set the function module parameter CALLCONTROLSTEP 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
103
104
CLASSICAL REPORTS
List/Report Programs
Dynamic/Dialog Programs.
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
106
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.
107
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
108
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
109
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
110
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.
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.
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
112
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
113
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
114
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.
115
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.
ALVs are generally of 3 types:
1. List /SimpleALV
2. Grid/Block ALV
3. Hierarchical Sequential Report
116
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
117
2. SELECTION TEXTS:
These are used to give names to the select-options, parameters and block
titles used in the selection screen.
118
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.
119
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.
120
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
121
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.
122
Once we have created the variants, they can be directly selected from the list of
available variants displayed on the selection screen.
123
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.
124
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.
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 NONUNIQUE when you specify the key.
Standard tables and sorted tables are generically known as index tables.
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.
125
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
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
126
have a unique key. Hashed tables are therefore useful for constructing and processing internal
tables that resemble database tables.
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.
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
4,337
2637
128
Filling a hash table is faster than for a sorted table. You can access single entries very fast.
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
6343
2212
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
130
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
Readindex
=
Read.key (30 bytes)...binary search
Read.key
7 msn
=
25msn
=
100 msn
271
" ...
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.
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 userdefined 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.
132
Performance tuning
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:
Nested selects
The plus:
The minus:
The minus
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.
DOMNAME
= DD01L-DOMNAME
AND AS4LOCAL
= 'A'
AND AS4VERS
= DD01L-AS4VERS
135
ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.
TAB_DEST[] = TAB_SRC[].
TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.
ENDDO.
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.
138
WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.
139
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.
140
141
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
142
Fig 1.0.1
Out of the three mentioned times 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
143
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.
144
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:145
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.
146
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.
ii.
iii.
iv.
v.
vi.
vii.
viii.
ix.
x.
xi.
xii.
xiii.
xiv.
Complete conditions are specified in the where clause taking care of all the primary keys
and the order of it in the DB table.
SELECT INTO TABLE is used instead of SELECT & APPEND.
SELECT SINGLE is used instead of SELECT.ENDSELECT.
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.
Usage of AGGREGATE functions (MAX, MIN, SUM, COUNT, etc) must be minimum.
SELECT into CORRESPONDING-FIELDS should be avoided in case of few records being
selected
Internal table is not empty check must be done before using FOR ALL ENTRIES in a
SELECT query.
SELECT queries using FOR ALL ENTRIES must use the key fields.
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.
Avoid using JOINS in SELECT queries for more than three DB tables.
Avoid using SELECT inside a LOOP .ENDLOOP statement.
MOVE statement must be used instead of MOVE-CORRESPONDING.
Usage of IS/IS NOT INITIAL instead of hard code values.
Already existing INDEXES associated with the DB tables must be used as they help in
making the search faster.
INDEXES
147
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).
148
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.
149
BY
150
Srinivas Palakurty
151
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
152
153
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)
Theres 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 theres 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
Theres 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
154
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
155
*
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.
156
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
=
157
*
*
*
*
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
158
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 be displayed
and other properties).
159
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.
160
Chapter
3
Specifying a field Catalogue
TOPICS INTRODUCED
1) Specify a heading for a report.
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:
DATA:
DATA:
DATA:
report_id
ws_title
i_layout
i_fieldcat
LIKE
TYPE
TYPE
TYPE
sy-repid.
lvc_title VALUE 'An ALV Report'.
slis_layout_alv.
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.
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
line_fieldcat-tabname
line_fieldcat-key
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMNUM'.
" The field name and the table
= 'I_DATA'.
" name are the two minimum req.
= 'X'. " Specifies the column as a key (Blue)
= 'Notification No.'. " Column Header
i_fieldcat.
CLEAR line_fieldcat.
162
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
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMTXT'.
= 'I_DATA'.
= 'Description'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'WS_ROW'.
= 'I_DATA'.
= 'Row Number'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_l
line_fieldcat-datatype
line_fieldcat-outputlen
APPEND line_fieldcat TO
= 'WS_CHAR'.
= 'I_DATA'.
= 'Test Character Field'.
= 'CHAR'.
= '15'.
" You can specify the width of a
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
163
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.
164
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:
DATA:
DATA:
DATA:
DATA:
DATA:
report_id
ws_title
i_layout
i_fieldcat
i_events
i_header
LIKE
TYPE
TYPE
TYPE
TYPE
TYPE
sy-repid.
lvc_title VALUE 'An ALV Report'.
slis_layout_alv.
slis_t_fieldcat_alv.
slis_t_event.
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
165
*
*
*
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
line_fieldcat-tabname
line_fieldcat-key
line_fieldcat-seltext_m
=
=
=
=
'QMNUM'.
" The field name and the table
'I_DATA'.
" name are the two minimum req.
'X'. " Specifies the column as a key (Blue)
'Notification No.'. " Column Header
166
= 'QMTXT'.
= 'I_DATA'.
= 'Description'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'WS_ROW'.
= 'I_DATA'.
= 'Row Number'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_l
line_fieldcat-datatype
line_fieldcat-outputlen
APPEND line_fieldcat TO
= 'WS_CHAR'.
= 'I_DATA'.
= 'Test Character Field'.
= 'CHAR'.
= '15'.
" You can specify the width of a
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 =
gs_line-key =
gs_line-info =
APPEND gs_line
gs_line-key =
gs_line-info =
APPEND gs_line
'S'.
'STATUS 1'.
'This is line of type STATUS'.
TO i_header.
'STATUS 2'.
'This is also line of type STATUS'.
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
*&---------------------------------------------------------------------*
167
*&
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).
168
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.
19.
ITEM_DATA_EXPAND
REP
REP_SEL_MODIFY
CALLER_EXIT
USER_COMMAND
TOP_OF_PAGE
DATA_CHANGED
TOP_OF_COVERPAGE
END_OF_COVERPAGE
FOREIGN_TOP_OF_PAGE
FOREIGN_END_OF_PAGE
PF_STATUS_SET
LIST_MODIFY
TOP_OF_LIST
END_OF_PAGE
END_OF_LIST
AFTER_LINE_OUTPUT
BEFORE_LINE_OUTPUT
SUBTOTAL_TEXT
169
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:
DATA:
DATA:
DATA:
DATA:
DATA:
DATA:
report_id
ws_title
i_layout
i_fieldcat
i_events
i_header
i_extab
LIKE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
sy-repid.
lvc_title VALUE 'An ALV Report'.
slis_layout_alv.
slis_t_fieldcat_alv.
slis_t_event.
slis_t_listheader.
slis_t_extab.
SELECT qmnum
qmart
qmtxt
INTO TABLE i_data
FROM qmel
WHERE qmnum <= '00030000010'.
170
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'.
171
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
line_fieldcat-tabname
line_fieldcat-key
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMNUM'.
" The field name and the table
= 'I_DATA'.
" name are the two minimum req.
= 'X'. " Specifies the column as a key (Blue)
= 'Notification No.'. " Column Header
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
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMTXT'.
= 'I_DATA'.
= 'Description'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'WS_ROW'.
= 'I_DATA'.
= 'Row Number'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_l
line_fieldcat-datatype
line_fieldcat-outputlen
APPEND line_fieldcat TO
= 'WS_CHAR'.
= 'I_DATA'.
= 'Test Character Field'.
= 'CHAR'.
= '15'.
" You can specify the width of a
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'.
172
gs_line-info =
APPEND gs_line
gs_line-key =
gs_line-info =
APPEND gs_line
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'.
APPEND ws_fcode TO i_extab.
ws_fcode = '&ABC'.
APPEND ws_fcode TO i_extab.
ws_fcode = '&NFO'.
APPEND ws_fcode TO i_extab.
ws_fcode = '&LFO'.
" 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.
174
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:
DATA:
DATA:
DATA:
DATA:
DATA:
DATA:
report_id
ws_title
i_layout
i_fieldcat
i_events
i_header
i_extab
LIKE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
sy-repid.
lvc_title VALUE 'An ALV Report'.
slis_layout_alv.
slis_t_fieldcat_alv.
slis_t_event.
slis_t_listheader.
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.
175
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
176
*&---------------------------------------------------------------------*
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
line_fieldcat-tabname
line_fieldcat-key
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMNUM'.
" The field name and the table
= 'I_DATA'.
" name are the two minimum req.
= 'X'. " Specifies the column as a key (Blue)
= 'Notification No.'. " Column Header
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
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'QMTXT'.
= 'I_DATA'.
= 'Description'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_m
APPEND line_fieldcat TO
= 'WS_ROW'.
= 'I_DATA'.
= 'Row Number'.
i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname
line_fieldcat-tabname
line_fieldcat-seltext_l
line_fieldcat-datatype
line_fieldcat-outputlen
APPEND line_fieldcat TO
= 'WS_CHAR'.
= 'I_DATA'.
= 'Test Character Field'.
= 'CHAR'.
= '15'.
" You can specify the width of a
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 =
gs_line-key =
gs_line-info =
APPEND gs_line
gs_line-key =
gs_line-info =
'S'.
'STATUS 1'.
'This is line of type STATUS'.
TO i_header.
'STATUS 2'.
'This is also line of type STATUS'.
177
" 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'.
APPEND ws_fcode TO i_extab.
ws_fcode = '&ABC'.
APPEND ws_fcode TO i_extab.
178
ws_fcode = '&NFO'.
APPEND ws_fcode TO i_extab.
ws_fcode = '&LFO'.
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
179
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.
180
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
it_fieldcat
IT_EXCLUDING
IT_SPECIAL_GROUPS
IT_SORT
IT_FILTER
IS_SEL_HIDE
I_DEFAULT
= i_fieldcat
=
=
= i_sortcat
=
=
= 'X'
Or else you will get an error. This is because this PF status was created for program ZSOMALV6.
181
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 wont be there. . In short the
statement,
SORT i_data BY qmart DESCENDING ws_row ASCENDING.
182
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,
183
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
"
"
"
"
"
"
"
"
"
"
heading_cols_first
heading_cols_nex
heading_rows_first
heading_rows_next
list_body_first
list_body_next
list_body
highlight_col_key
highlight_col
highlight_row
184
higsum
type
higsumhig
type
higsumlow
type
higins
type
higpos
type
higneg
type
hig
type
heahie
type
lisbodhie
type
end of slis_coltypes.
slis_color,
slis_color,
slis_color,
slis_color,
slis_color,
slis_color,
slis_color,
slis_color,
slis_color,
"
"
"
"
"
"
"
"
"
highlight_sum
highlight_sum_high
highlight_sum_low
highlight_inserted
highlight_positive
highlight_negative
highlight
heading_hier
list_body_hierinfo
*** 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.
185
"
"
"
"
"
"
no headings
headings not as hotspot
striped pattern
columns separated by space
not suppress field replication
for grid only
186
edit_mode(1) type c,
numc_sum(1)
type c,
no_input(1) type c,
f2code like sy-ucomm,
reprep(1) type c,
no_keyfix(1) type c,
expand_all(1) type c,
no_author(1) type c,
PF-status
def_status(1) type c,
item_text(20) type c,
end of slis_layout_alv_spec0.
187
*
*
*
*
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.
189
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'.
191
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:
2. In the code, loop through the lines of the internal table and assign values to this field. The 4character value will be of the format - Cxyz.
Char 1
Char 2
Char 3
Char 4
(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'.
192
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.
193
Module pools
194
TZ40
First Screen:
Screen
100
Screen
200
Next Screen = 0
END
195
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
196
Screen
100
Screen
200
Screen
210
Screen 200: The system displays complete details about the flight, in update
mode. The user types over the display to enter the changes.
197
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).
198
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
199
SET SCREEN tells the system to ignore the statically defined Next screen and use
<screen number> as the next screen instead.
Screen 100
Screen 200
Screen 110
Screen 210
Screen 120
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.
200
201
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
Screen 200
Screen 110
Screen 210
Screen 120
Screen 220
Next Screen = 0
CALL SCREEN
202
203
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>
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
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 nextscreen 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.
204
205
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:
206
*&---------------------------------------------------------------*
*&
Module
EXIT_0200
INPUT
*&---------------------------------------------------------------*
MODULE EXIT_0200 INPUT.
CASE OK_CODE.
WHEN CANC.
CLEAR OK_CODE.
SET SCREEN 100.
LEAVE SCREEN.
ENDCASE.
ENDMODULE.
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.
207
Subroutine SAFETY_CHECK
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
screens
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 dont use SUPPRESS DIALOG here, screen 110 is displayed, and is
empty. When the user presses ENTER, the standard list output is displayed.
208
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
Author
Reviewer
the
Review Date
Version
consider
example of
1.0
a tab strip
209
210
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.
211
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:
button1 = text-010.
button2 = text-020.
button3 = text-060.
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.
initialization.
mytab-prog = sy-repid.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.
213
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:
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.
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.
214
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
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
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
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.
215
The sub screens which are used in the program are to be included as follows:
CONTROLS: MYTABSTRIP
In the module pool, declare the tab strip similar to the table control using the
CONTROLS Statement.
216
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:
MYTABSTRIP-ACTIVETAB = F1
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:
MODULE FCODE.
CASE OK_CODE.
WHEN TAB1.
DYNPRONR = 0200.
TABSTRIP1-ACTIVETAB =
OK_CODE.
CLEAR OK-CODE
WHEN TAB2.
DYNPRONR = 0300.
TABSTRIP1-ACTIVETAB =
OK_CODE.
....
217
Introduction to
SMARTFORMS
218
Table of Contents
Introduction
Purpose of this Introduction. 220
Who will benefit.
220
Prerequisites
220
refresher on sapscript
221
12
smartstyle 28
template
38
config setting... 54
refresher on smartforms : summary
219
58
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.
REFRESHER ON
SAP SCRIPT
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
WE can insert picture or Logo (Company Logo) in the output, which is not possible by
report program.
220
NOTE
THE SMART FORMS ALLOW THE USER TO EXECUTE SIMPLE MODIFICATIONS TO THE FORM AND IN THE
FORM LOGIC BY USING SIMPLE GRAPHICAL TOOLS.
221
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.
222
Data Retrieval
SMART
FORM
APPLICATION
PROGRAM
Activate
Database Selection
Function
Module
Call
ABAP
FUNCTION
MODULE
Later
Selection
Database
Form Description
OUTPUT
(Printer)
223
224
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
click
Lets use forms starting with BC as SAP has created these for training purposes.
225
click
WE NOW ARRIVE AT THE DISPLAY FORM SCREEN, WHICH IS DIVIDED, INTO 3 MAIN SECTIONS:
226
NAVIGATION WINDOW, FORM PAINTER AND MAINTENANCE WINDOW. WE WILL 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.
227
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).
NOTE
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.
Form interface tells us what are the import and export parameters, exceptions, tables etc
that we
228
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
229
230
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.
231
What we created in
Types is being used to
declare a variable.
232
1 OF 10 ETC
Conditional breaknext 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
234
NOW LETS CREATE OUR OWN SMART FORM LETS COPY A STANDARD SMART FORM [BC470_FLOWS]OF SAP
AND CREATE ZBC470_FLOWS_AVID. THEN WE WOULD PLAY AROUND WITH ITS DIFFERENT ELEMENTS.
235
236
I HAVE CHANGED THE SEQUENCE BY DRAGGING AND DROP. NOW TEST1 APPEARS BEFORE THE FIRST
PAGE.
237
NOTE
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
238
HERE THERE ARE 3 OPTIONS : BLACK AND WHITE, COLOR AND DYNAMIC BITMAP PICTURES. WE NAME THE
BACKGROUND PICTURE AND CHOOSE THE DETERMINE DYNAMICALLY OPTION.
239
240
241
CANNOT USE MAIN IN THIS FIELD BECAUSE SAP CREATES MAIN BY DEFAULT AND DOESNT ALLOW MAIN AS
NAME.
NOTE
WE CANNOT HAVE MORE THAN 1 MAIN WINDOW IN A PAGE. WE CAN HAVE MULTIPLE SECONDARY
WINDOWS
WHATEVER U PRINT IN SECONDARY WINDOWIT 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.
242
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.
243
IN THE OUTPUT, WE HAVE THE OPTION OF SIZING AND POSITIONING THE MAIN WINDOW ALONG WITH DIFFERENT
SHADING AND COLOR CHOICES.
244
WE CAN HAVE CONDITIONS.TO BE EXECUTED AT RUN TIME WE TAKE AN EXAMPLE TO ILLUSTRATE THIS.
245
NOTE
246
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.)
247
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
WE WOULD THEN FILL UP TEXT NAME: STATIC OR DYNAMIC, TEXT OBJECT (E.G. TEXT) AND TEXT ID (E.G. ADRS)
248
249
250
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.
251
WE CAN HAVE OUR OWN SMART STYLE : PARAGRAPH AS WELL AS CHARACTER FORMATS. LETS CHECK OUT A
STANDARD STYLE BEFORE CREATING OUR OWN!
252
THE HEADER DATA IN EACH SMART STYLE ALLOWS US TO CONFIGURE FONT SIZE, LINE AND CHARACTER SPACING.
253
SAP PROVIDES DIFFERENT PARAGRAPH FORMATS FOR STANDARD, HEADER AND FOOTER, CENTERED AND TOTALS.
254
255
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.
256
NOTE
THE NEWLY CREATED PARAGRAPH FONT (E.G. AV) WONT 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.
257
LETS CREATE A NEW STYLE (ZBC470_AVI) WITH 2 PARAGRAPH FORMATS AND WE CHARACTER FORMAT
258
259
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.
260
Click
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.
261
Click
262
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.
263
WE CAN PUT CONDITIONS/LOGIC BY PUTTING ABAP CODE INSIDE BOOKINGS MAIN AREA, PROGRAM LINES. HERE WE
FIRST DECLARE THE INPUT AND OUTPUT PARAMETERS.
264
HERE WE PUT THE TEXT ELEMENT AS PER PARAGRAPH AND CHARACTER FORMAT. WE MAY HAVE A TEXT WHICH IS
DETERMINED DURING RUN TIME (DYNAMIC).
265
NOW LETS CREATE OUR OWN TABLE. HERE WE CAN PUT LOGIC AS PER CLIENT REQUIREMENT.
NOTE
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.
266
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
267
This is to terminate the current page and start processing the new page.
268
269
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
270
271
272
If what we type here is True then it will get processed under the True button.
We next explore another feature of Smartform: Folder
273
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.
274
275
276
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'
277
278
279
we have to mention this name (of function module) in the print program.
280
281
This calls the SAP Smart form. We are checking the output in Monocolour.
282
283
284
285
286
CHECK PRINT
PREVIEW
287
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
288
289
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.
290
291
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.
292
Click
293
294
TABLES: MKPF.
295
296
297
298
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
USED TO
NODE
SUB WINDOW
[POSITION TEXT ON WE OR MORE PAGES]
MAIN WINDOW
TEMPLATE
[DISPLAY TEXT IN RELATION TO OTHER NODES IN THE MAIN WINDOW, IT MAY COVER
SEVERAL PAGES]
[DISPLAYS TEXTS FOR TABLE CELLS OF A STATIC TABLE]
TABLE
HEADER AND
FOOTER
EVENT NODE
299
300
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.
301
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.
302
Footer
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.
303
WINDOWS
LOGO
COMPANY NAME
CONTENT
ADDRESS
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.
304
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.
305
Press Create and the following pop-up will appear. Dont forget to
see that the form is created in the client and not in the
application server.
306
Just Press Enter and save the layout after giving a short
description.
307
308
Create a page called PAGE1 and press Enter. Give next page as
PAGE1 only and press Enter.
309
Apart from existing Main window, create Header and Footer for
this page.
310
Now click on tab Paragraph Formats where you can create your
own paragraph formats which can be used while writing text
311
312
313
314
, the following
316
Now check for Definition and Activate the script. Script Layout is
complete now.
317
318
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'.
319
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* Write header
CALL FUNCTION 'WRITE_FORM'
EXPORTING
*
ELEMENT
*
FUNCTION
*
TYPE
WINDOW
*
IMPORTING
*
PENDING_LINES
*
EXCEPTIONS
*
ELEMENT
320
= ' '
= 'SET'
= 'BODY'
= 'HEADER'.
=
= 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 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
321
"LOOP AT tb_kunnr
322
323
324
325
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 doesnt 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.
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.
327
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
'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
328
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.
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.
329
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.
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.
C:\MAIL\COMPLOGO.TIF
CM
330
Commands
1. Defining a variable
2. Define and insert a standard text:
3. Formatting addresses
4. Avoiding pagebreaks in a paragraph
331
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
332
Example:
/: IF &SPFLI-CITYTO& = "BERLIN"
* ..... put some text here
/: ENDIF
333
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.
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
334
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
*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'.....
OPEN FORM
* Structure for the OPTIONS parameter
DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
DATA END OF OPTIONS.
336
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
MAIL_OPTIONS
=5
=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
337
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
338
*
*
*
*
OTFDATA
=
EXCEPTIONS
UNOPENED
=1
BAD_PAGEFORMAT_FOR_PRINT = 2
*
*
SEND_ERROR
OTHERS
=3
=4
*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'.....
OPEN FORM
* Structure for the OPTIONS parameter
DATA BEGIN OF OPTIONS.
INCLUDE STRUCTURE ITCPO.
339
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
MAIL_OPTIONS
=5
=6
ARCHIVE_ERROR
=7
INVALID_FAX_NUMBER
=8
MORE_PARAMS_NEEDED_IN_BATCH = 9
OTHERS
= 10
.
IF sy-subrc <> 0.
...............................
ENDIF.
START_FORM
340
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
341
*
*
*
*
*
*
RDI_RESULT
=
TABLES
OTFDATA
=
EXCEPTIONS
UNOPENED
=1
BAD_PAGEFORMAT_FOR_PRINT = 2
*
*
SEND_ERROR
OTHERS
=3
=4
Example:
call function 'CONTROL_FORM'
EXPORTING
COMMAND = 'PROTECT'.
342
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.
343
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.
344
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.
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.
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.
345
There will also be problem with language defined and the language used also.
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.
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.
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.
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.
346
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
347
6.
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.
BOX FRAME 20 TW
P1
BITMAP 'LOGO' OBJECT GRAPHICS ID BMAP TYPE BCOL DPI 100
c. Using transaction SCC1 - It copies the script in one client to the other
client.
9.
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.
349
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.
350
BOK
On
Function Module User Exits
351
352
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
353
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.
354
355
356
Double click on 001 in above screen. It will lead to include where exit is being called.
357
This screen consists of function call to trigger user exit when all necessary requirement
will be fulfilled.
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.
359
360
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.
361
362
A. Project Creation:
We want to create a project to enhance transaction VA01
-
Go to transaction CMOD
Create a project called ZASR0001
B. Enhancement Assignment
363
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.
364
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.
365
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.
366
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).
367
368
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.
If no settlement rule is defined for that material then it will display information No Settlement
rule is defined.
369
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.
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.
370
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.
2> Using transaction SE81Steps: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.
371
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 IMGUse 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.
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.
372
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.
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.
373
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:
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.
374
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[].
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.
375
376
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.
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
377
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
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.
378
SAPL2012
MBCF0002
MBCF0007
MBCF0009
MBCF0010
MBCF0011
379
380
ALE Configuration
T-Code SALE
381
382
Step 2
383
Defining Port
The sender system is connected to the receiver system through this Port.
Defining Partner Profiles
384
2.
385
386
387
388
Tcode WE31
389
Click on New
390
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
391
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.
392
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.
= 'ZSACH'.
= 'ZSACH'.
= 'LS'.
= 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.
393
int_edidd-sdata = gen_data.
append int_edidd.
endloop.
call function 'MASTER_IDOC_DISTRIBUTE'
exporting
master_idoc_control
*
OBJ_TYPE
*
CHNUM
tables
communication_idoc_control
master_idoc_data
= control_dat
= ''
= ''
= int_edidc
= 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.
T-Code SALE
200 is our sender
800 is our receiver
394
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)
395
Click on the
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
396
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.
397
The logic associated is coded in the Function Module which is specified in the
Identification Field above.
398
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
399
400
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
401
*" 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.
402
*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.
*****
=
=
=
=
=
=
=
=
=
idoc_data-docnum.
'51'.
sy-repid.
'EDI_DS'.
sy-mandt.
'SAP'.
'B1'.
'999'.
'Sold to changed to '.
= t_new_kunnr.
= sy-datum.
= sy-uzeit.
append t_itab_edids40.
call function 'EDI_DOCUMENT_CLOSE_EDIT'
exporting
document_number = idoc_data-docnum
do_commit
= 'X'
403
do_update
write_all_status
tables
status_records
exceptions
idoc_not_open
db_error
others
= 'X'
= 'X'
= t_itab_edids40
= 1
= 2
= 3.
endfunction.
404
T Code WE02
405
406
This way, the data has come to the receiver end successfully.
407
LSM Workbench
LSMW Quick Ref and steps for XD02
Data Migration
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
05.02.2007
1.0
Lavanya
Kundella
Ramnarayana
Halder
408
Review
Comments
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?
409
Legacy data
on PC
Read data
Read data
Structure
relations
Field mapping
Legacy data
on application
server
Convert data
Converted
data
Direct Input
processing
IDoc inbound
processing
R/3 Standard
Batch Input
processing
Conversion
rules
21
IDOCs
All
411
Advantages of LSMW?
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.
412
Figure 5
Source Structure
413
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
Note that your input file will have four fields as key fields and you need to update three fields in
the system.
414
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 dont 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.
415
416
Similarly, choose source fields for Sales Organization, Distribution Channel, and Division.
417
Scroll down to structure BKNVV fields and assign source fields to three fields Sales Office, Sales
Group, and Customer Group
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.
418
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.
Xd02.txt
419
420
Execute step Assign Files and the system automatically defaults the filename to the source
structure.
421
In this step, LSMW reads the data from the source file (from PCs local drive). You have the
option to read only selected rows and convert data values to internal format.
422
This step is optional. If required, you can review the field contents for the rows of data read.
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.
423
When you convert data, LSMW automatically converts into the appropriate structure layouts, as
required by Standard program (RFBIDE00).
424
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.
425
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).
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
Meaning
EQ
or =
equal to
NE
or <>
not equal to
LT
or <
less than
LE
or <=
GT
or >
GE
or >=
442
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)
443
444
446
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.'.
448
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) =', SYTLENG.
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:
SKIP.
WRITE: /5 'SAP System ID:
WRITE: /5 'Host:
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
450
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.
SY-CALLD
This field indicates if the transaction was called from another transaction.
452
453
454