Beruflich Dokumente
Kultur Dokumente
Dictionary
reference
Dictionary
reference
Selection screen
Selection Texts
The field names appear as text in front of the input fields of a selection screen by default. You
can replace them with selection texts and translate them into the required language. The
selection texts appear for the user in the logon language.
If the input field is typed directly or indirectly with a data element, you can copy the field
labels from one of the texts stored in the Dictionary.
SAP AG AC400 4-139
SAP AG 2006
Database
table
ABAP program
pa_car
LH
Selection
screen
PARAMETERS pa_car TYPE s_carr_id.
...
LH
SELECT * FROM spfli
DATA wa_spfli TYPE spfli.
INTO wa_spfli
WHERE carrid = pa_car .
WRITE: / ...
ENDSELECT.
Using Parameters
To get the standard selection screen in an executable program, all you need to do is program a
PARAMETERS statement.
The statement PARAMETERS name TYPE typename or PARAMETERS name LIKE
data_object generates an elementary input field on the selection screen and declares a data
object name of the same type.
If the user enters a value and chooses Execute, the input value is placed in the internal data
object name for the program. Only entries that conform to the type are permitted.
SAP AG AC400 4-140
SAP AG 2006
Database
table
ABAP program
Selection
screen
SELECT-OPTIONS
so_car FOR wa_spfli-carrid .
...
DATA wa_spfli TYPE spfli.
SELECT * FROM spfli
INTO wa_spfli
WHERE carrid IN so_car .
WRITE: / ...
ENDSELECT.
AA DL
( Selection conditions )
Internal table so_car
sign option low high
I
I
E
EQ
EQ
BT
LH
AA DL
BA
Using Select Options
You define selection options using the SELECT-OPTIONS name FOR data_object
statement: Two data objects of the same type appear on the selection screen as input fields for
entering range limits by default. A pushbutton also appears for carrying out complex range
selections.
The ABAP runtime system defines an internal table name with four columns as a data object
inside the program:
sign to indicate whether the value or the interval should be included (I) or excluded from the
range (E),
option for the operator (BT, ...): You will find all the possible operators in the keyword
documentation for SELECT-OPTIONS,
low for the lower limit of an interval or individual value,
high for the upper limit of an interval.
This selection table name always refers to a data object that has already been defined. The data
object normally serves as the target field in data selection and the selection table as the
possible range of values. For this reason there is a special form of WHERE clause for the
database selection that queries whether the corresponding field is contained in the range on the
database.
Note:
A similar inclusion query is also define for the IF statement.
SAP AG AC400 4-141
SAP AG 2006
...
PARAMETERS pa_car TYPE s_carr_id.
CONSTANTS actvt_display(2) VALUE '03'.
* Event processed after leaving the selection screen
AT SELECTION-SCREEN.
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD pa_car
ID 'ACTVT' FIELD actvt_display.
IF sy-subrc NE 0.
* Show selection screen again with error message
MESSAGE e045(bc400) WITH pa_car.
ENDIF.
START-OF-SELECTION.
...
Example: Authorization Check for the Selection Screen
By way of example of an additional input check with an error dialog, a program with an input
field for the abbreviation of an airline is to be extended.
The authorization check is to be performed at the selection screen:
If the user has display authorization for the airline that was entered, the program is to
continue processing.
If the user has no display authorization, the selection screen should be displayed again with
an error message in the status bar.
SAP AG AC400 4-142
SAP AG 2006
Consistency check
at data input
Flexible
programflow
200
120
140
100
300
Type checks
Possible values
Input help
?
Formatting
options
Dynpro Properties
Dynpros contain not only screen layouts with input and output fields but also their own
processing logic.
By integrating the ABAP Dictionary, automatic consistency checks are available for screen
input fields. As well as the type check, this also includes foreign key checks and checks against
fixed values. Information from the Dictionary is automatically used for these checks.
The checks can be extended to include checks specific to the program. Technology is available
for dynpros that controls the check sequence and makes the fields ready for input again when
errors are discovered.
The layout can be structured very flexibly, with input fields, output fields, radio buttons,
checkboxes, and above all, pushbuttons that enable the user to influence the further course of
the program.
The same formatting options are available for the dynpro as for the list and the selection
screen: Fixed point numbers and dates are formatted according to the settings in the user fixed
values, time according to hh:mm:ss, amounts according to the contents of a currency field and
lengths, weights and so on according to the content of a unit of measure field.
SAP AG AC400 4-143
SAP AG 2006
Dynpro sequence
100
200
300
120
140
CALL SCREEN 100.
ABAP program
Next dynpro = 0
Dynpro calls
You start a dynpro sequence
by specifying the first dynpro as the start dynpro for a transaction code belonging to the
"dialog transaction" type, or
by calling a dynpro from any ABAP processing block in the program.
In this unit we will limit ourselves to the latter option.
SAP AG AC400 4-144
SAP AG 2006
Properties Element list
Flow logic
(flow control)
4 Dynpro number
4 Short description
4 Dynpro type
4 Next dynpro
4 . . .
PROCESS BEFORE OUTPUT.
MODULE clear_ok_code.
PROCESS AFTER INPUT.
MODULE user_command.
Layout
Departure
Screen Painter
Arrival
Layout editor
4 Field A
CHAR20
Required
Entry field
...
4 Field B
...
4 . . .
4 . . .
Dynpro Components
The following components belong to a dynpro:
Properties:
- They contain a four figure number for the dynpro name, a short text and information
about the dynpro type (for example normal for full screen).
Layout:
- You can place elements on your dynpro. Elements that appear on the dynpro are called
screen elements.
Element list:
- This contains the properties of the screen elements such as position, size and data type.
Flow control:
- This contains processing logic that should be processed before the dynpro is sent to the
presentation server (PBO) and processing logic that should be processed after a user
action (PAI).
SAP AG AC400 4-145
SAP AG 2006
Properties
of an element
Element list
Create fields
with Dictionary
reference
Toolbar
Graphical Layout Editor
Layout area
The Graphical Layout Editor
You can start other functions from the graphical Layout Editor:
Element properties:
- This dialog box shows all the attributes for a screen element. You can change some of
these attributes directly in the dialog box.
Example: Readiness for input of an input/output field.
Fetch from Dictionary / Fetch from Program:
- In this dialog box you can generate fields with typing for a global type or fields of the
same type for data objects in the program.
Element list:
- This shows all the elements displayed on the dynpro together with the relevant attributes.
Attributes can be changed directly here too.
SAP AG AC400 4-146
SAP AG 2006
100
...
CALL SCREEN 100.
...
MODULE abc OUTPUT.
...
ENDMODULE.
PBO
MODULE abc.
MODULE xyz INPUT.
...
ENDMODULE.
PAI
MODULE xyz.
ABAP program
Dynpro 100
Calling Modules
The ABAP statement CALL SCREEN <nnnn> interrupts processing of the processing block
and calls the dynpro.
Two event blocks are available for each dynpro:
PROCESS BEFORE OUTPUT (PBO) is processed before the dynpro is displayed. At this
event, modules can be called that preassign values to the screen fields, for example.
PROCESS AFTER INPUT (PAI) is processed after a user action. The program logic,
which depends on the user action, has to be encoded at PAI.
Beachten Sie:
The source text for the PBO and PAI events is created with the Screen Painter and not with
the ABAP Editor. Both event blocks together are termed the flow logic of the dynpro.
A separate, small command record (no ABAP statement!) is available for programming the
flow logic. The most important statement in this record is MODULE module_name. This
calls the ABAP processing block module_name, within which you can enter ABAP code as
normal.
Modules are processing blocks without an interface that can only be called from the flow
logic. A module is enclosed by the ABAP statements MODULE and ENDMODULE.
SAP AG AC400 4-147
SAP AG 2006
PROCESS BEFORE OUTPUT.
...
Back Save
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'. ...
WHEN 'SAVE'. ...
ENDCASE.
ENDMODULE.
PROCESS AFTER INPUT.
ABAP program
MODULE user_command_0100.
Dynpro 100
...
CALL SCREEN 100.
...
Analyzing the Function Code for PAI
You can analyze the user actions in a PAI module. This PAI module is normally named
user_command_nnnn (nnnn stands for the dynpro number). Analyze the function code in this
module in the ok_code field.
Note:
For historical reasons, modules have no interface and no local variables. In modules you can
access all the global data in the ABAP program.
SAP AG AC400 4-148
SAP AG 2006
PROCESS BEFORE OUTPUT.
...
PROCESS AFTER INPUT.
MODULE user_command_100.
MODULE user_command_100 INPUT.
ENDMODULE.
Cancel Yes No
Create object
PAI module USER_COMMAND_100 does not
exist.
Do you want to create the object?
Double-click
USER_COMMAND_0100 PAI module
New include
Framework program
Include election
ZBC400_00_DYNPRO
Create PAI module
Screen
painter
Dynpro flow control
ABAP
Editor
...
Creating Modules Using Forward Navigation
In the flow control (PBO and PAI) you normally implement MODULE calls. The modules
themselves are created in ABAP.
There are two options for creating a module:
Forward navigation: From the Screen Painter you create a module by double-clicking on
the module name in the flow logic.
Navigation area: If you want to create a module from the object list of the program, choose
a new program object "PBO module" or "PAI module".
A module can be called from several dynpros (reusability).
Note that a module that you call at the PBO event is defined with the MODULE ... OUTPUT
statement; you can only call a module that is defined with the MODULE ... INPUT statement
at the PAI event.
SAP AG AC400 4-149
SAP AG 2006
100
...
CALL SCREEN 100.
...
MODULE abc OUTPUT.
...
ENDMODULE.
PBO
MODULE abc.
MODULE xyz INPUT.
...
ENDMODULE.
PAI
MODULE xyz.
Dynpro 100
Next dynpro: 100
Fixed Screen Sequences
Dynpro attributes:
ABAP program
If the next dynpro for dynpro 100 is set to 100, the dynpro is processed again after PAI has
finished.
SAP AG AC400 4-150
SAP AG 2006
100
...
CALL SCREEN 100.
...
MODULE abc OUTPUT.
...
ENDMODULE.
PBO
MODULE abc.
MODULE xyz INPUT.
...
ENDMODULE.
PAI
MODULE xyz.
Dynpro 100
Dynpro attributes
:
Next dynpro: 0
Ending Dynpro Sequences - Fixed Rule
ABAP program
By specifying the next dynpro here, you determine that after the dynpro has been completely
processed, processing continues at the dynpro callpoint.
SAP AG AC400 4-151
SAP AG 2006
100
...
CALL SCREEN 100.
...
MODULE abc OUTPUT.
...
ENDMODULE.
PBO
MODULE abc.
MODULE xyz INPUT.
SET SCREEN 0.
ENDMODULE.
PAI
MODULE xyz.
Dynpro 100
Dynpro attributes
:
Next dynpro: 100
0
ABAP program
Ending Dynpro Sequences - Variable Rule
The next dynpro can be set dynamically from a PAI module using the ABAP statement SET
SCREEN nnnn. This represses the static entry.
The system enters the number of the current dynpro as the next dynpro by default. As a result,
the enter key or the green checkmark only leads to a field check, and the dynpro is sent again
after this, with a corresponding error message, if applicable. You can only exit it using a
pushbutton intended for this purpose that is caught in a PAI module.
Note that when the same dynpros are processed again, all the PBO modules are run again. If
you decide to fill the TABLES structure in a PBO module, you must ensure that this does not
overwrite the changes made to the data on the dynpro by the user when it is called again.
SAP AG AC400 4-152
SAP AG 2006
DATA ok_code LIKE sy-ucomm.
START-OF-SELECTION.
...
AT LINE-SELECTION.
...
CALL SCREEN 100.
...
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
SET SCREEN 0.
MESSAGE s057(bc400).
WHEN 'SAVE'.
* Saving changes in data base
...
SET SCREEN 0.
MESSAGE s058(bc400).
ENDCASE.
ENDMODULE.
Syntax Example: Analyzing the Function Code
For our scenario, two pushbuttons should be caught:
With 'BACK', the next dynpro is set to 0 dynamically. This takes you back to the callpoint.
In our case, this means returning to the basic list. The message 057 appears in the status bar
in the following screen.
With 'SAVE' the program behaves in the same way as for 'BACK'. It returns to the basic
list, however, a different message appears in the status bar. In the unit Cross-Program
Modularization the program is extended with a change to the data record.
SAP AG AC400 4-153
SAP AG 2006
Flight data Edit Goto System Help
Help F1
Select F2
Back F3
. . .
Function key
settings
Change flight times
GUI title
Menu bar
Toolbar
Application toolbar
Function key settings
Terms for the User Interface
GUI status
The user interface appears with the following elements:
The title bar contains the title of the actual screen.
The menu bar contains expandable menus.
The menus contain the functions that you can execute in the program. Menus can contain
submenus (cascading menus). The "System" and "Help" menus are available with identical
functions on all screens in the R/3 system. Neither of these menus can be changed or hidden.
The toolbar contains icons for functions that are used very frequently. The toolbar contains the
same icons on every screen in the R/3 system with function keys that have been permanently
assigned. The icons for functions that cannot be executed on the actual screen are grayed out.
The (function) key setting can be displayed with a right mouse click. All functions that can be
executed by way of the menu should also be executable by way of a function key.
The application toolbar enables frequently used function keys on a screen to be executed by
clicking on an icon or a pushbutton too.
An interface is created for each program that contains the elements listed above. Views can be
created on the user interface for different screens: GUI status.
SAP AG AC400 4-154
SAP AG 2006
F2
F9
...
Toolbar
%EX BACK RW
PICK
%PRI %SC P--
Menu bar Menu bar flight data
i
Application toolbar
i
Function keys Function keys flight data
i
Application toolbar flight data
P-
q
q +
+
+
q
P+ P++
?
%SC+
Choose
Recommended function key settings
User-determined function keys
F5
F6
...
<...> Select
Status in the Menu Painter Function Keys
The key assignment is divided into three areas:
Toolbar: Specific function codes are required for the functions Save, Back, Program Exit,
Cancel, Print and the Scroll icons, as well as for the Enter key. The corresponding function
key is automatically assigned when you assign a function code to the icon in the toolbar.
Recommended function key settings: Functions are proposed here that should normally be
assigned to specific function keys.
User-determined function keys: All the other function codes are listed here that are not
covered by standard icons. You can look for suitable keys here for functions specific to a
particular program.
In addition, you can define a pushbutton in the application toolbar for function keys that are
often required. Icons or text can be represented on pushbuttons.
SAP AG AC400 4-155
SAP AG 2006
Menu bar
Menu bar flight data
i
Application toolbar
i
Function keys
Function keys flight data
i
Application toolbar flight data
Flight data
Code Text
Edit Goto
Code Text Code Text
PICK
%SC
%SC+
RW
Select
Search
Extend search
Cancel
PRI
%EX
Return BACK Print
Save/Send
Exit
>
Status in the Menu Painter Menu Bar
The system proposes standard layouts for the menu bar which you can also modify, however.
The menu bar can contain a maximum of eight menus, six user-definable menus as well as
System and Help, which are automatically inserted as standard menus.
SAP AG AC400 4-156
SAP AG 2006
Menu bar
SCREEN
SCREEN
SCREEN
i
i
i
Selection and Integration
of subobjects of an
already defined status
Application toolbar
Function keys
Including Existing Status Elements
Create a new status for the dynpro and use an icon to display all the menu bar or function key
assignments that have already been defined. In the example program only one menu bar or
function key assignment is displayed.
Double-click on this to select it so that you can reference the same menu bar and the same
function key assignment for the dynpro status as in the list status.
SAP AG AC400 4-157
SAP AG 2006
Function code
Flight data Edit Goto
Code Text
Select
function code
Back BACK
Application toolbar
i
Function keys Function keys flight data
i
Application toolbar flight data
Menu bar Menu bar flight data
i
1
Set to active/
inactive
2
Deactivating Status Functions
To set an active or inactive status for functions, proceed as follows:
Switch to change mode status by double-clicking and the Display * Change icons.
Place the cursor on the required function code and click on the active * inactive icons in the
application toolbar
In our example, we add the SAVE function, which does not belong to the standard list
functions, to the toolbar and the Flight Data menu. The system points out that we are
referencing the menu bar and the toolbar. If we confirm the dialog box, the SAVE function is
automatically included in the status for the menu bar and the toolbar and displayed as inactive
there.
The functions BACK and SAVE in our example are analyzed in the PAI module
user_command_0100.
SAP AG AC400 4-158
SAP AG 2006
SET TITLEBAR 'T_ABC'.
Program
Title code
Title
Create title
xxxxx
T_ABC
Change flight times
GUI interface: Title T_ABC does not exist.
Do you want to create the object?
Cancel
Create object
Yes No
Confirm
START-OF-SELECTION block ( for list )
or
PBO module ( for dynpro)
Double-
click
Defining GUI Titles
There are three options for creating or maintaining a title:
From the object list of the repository browser,
by forward navigation from the ABAP Editor, or
directly, using the Menu Painter tool.
A name of a title can have a maximum of 20 characters.
Note: If you create the proposed PBO module status_nnnn by forward navigation, the SET
TITLEBAR 'XXX'. statement is automatically generated in the module. It is turned into a
comment. You can use this proposal by deleting the asterisk and entering the number of the
title. Then you can create the title by forward navigation.
SAP AG AC400 4-159
SAP AG 2006
attr1
attr2
...
meth1
meth2
...
Class
(Formal description of objects)
Object attribute
Object methods
attr1 8
ABC
Objects (instances) of the class
attr2
meth1
meth2
attr1 3
XYZ
attr2
meth1
meth2
attr1 5
SAP
attr2
meth1
meth2
Concept of Object-Oriented Programming
The first impression of a class is that it is like a function group:
It contains data objects (attributes) and functions (methods). These components can be
protected from external access. Then only methods can be used to access them.
In contrast to function groups, however, classes can be instanced several times. In other words,
more than one runtime object can be generated for a class for each program. Another way of
looking at it is that a class contains the technical description of objects (instances). All these
objects therefore have the same attributes and offer the same methods. They can all be
physically distinguished from one another, however. Their attributes can have different
characteristic values.
Classes can be defined locally, within an executable program, or globally.
As of release 4.6a, the ABAP runtime system supports standard object-oriented syntax
elements. However, these cannot be discussed properly in the time available in this training
course. You will find detailed information about this in the SAP Library.
SAP AG AC400 4-160
SAP AG 2006
ABAP program
DATA ref1 TYPE REF TO myclass.
DATA ref2 TYPE REF TO myclass.
CREATE OBJECT ref1 ...
...
CREATE OBJECT ref2 ...
CALL METHOD ref1->meth1
EXPORTING ...
IMPORTING ...
EXCEPTIONS ...
CALL METHOD ref2->meth1
EXPORTING ...
IMPORTING ...
EXCEPTIONS ...
ref1 ref2
meth1
meth2
meth2
meth1
Instantiation of Objects and Method Calls
To generate and address class instances you need so-called reference variables. These are
pointers to the instances. You define such reference variables with
DATA reference_name TYPE REF TO class_name.
The data objects are created in the memory when the program starts. However, because no
instances have yet been generated, the reference variables are still empty at this point.
At runtime you can generate as many class instances as you want using
CREATE OBJECT reference_name.
- The import parameters for a special method, the CONSTRUCTOR, may have to be
populated. This special method is executed immediately after the instance has been
generated. Basic settings for the actual instance are normally made.
You call the methods for an instance using
CALL METHOD reference_name->method_name.
- In contrast to calling a function module, the function name is not sufficient here,
as several instances of a class normally exist for each program. You use the reference
variable, followed by the object component selector ->, to cause a specific instance to call
its method.
SAP AG AC400 4-161
SAP AG 2006
AA
0017
0064
LH
0400
0402
Airlines
Tree control
http://www.sap.com
HTML viewer control
Grid control Picture control
CL_GUI_ALV_GRID CL_GUI_PICTURE
CL_GUI_HTML_VIEWER CL_SIMPLE_TREE_MODEL
EnjoySAP Controls as Standard Classes
As of release 4.6a the ABAP Workbench offers a large range of new EnjoySAP controls to
relocate dialog functions from the application server to the presentation server. The steering of
these controls is object-oriented, and takes place with the help of classes, the SAP Control
Framework.
Method calls steer the controls from your ABAP program. The Control Framework sends your
requirements to the presentation server, where they are converted in accordance with the
platform.
You can give the user the option of triggering events on the presentation server. These are
converted in turn by the Control Framework, so that your ABAP program can respond to them.
You will find detailed information about EnjoySAP controls and the Control Framework in the
SAP Library.
SAP AG AC400 4-162
SAP AG 2006
17
64
AA
AA
AA
AA
LH
LH
LH
LH
LH
17
17
400
402
400
400
402
2000-01-17
2000-02-20
2000-03-11
2000-05-19
2000-01-13
2000-02-26
2000-03-21
2000-03-04
2000-05-28
USD
USD
USD
USD
EUR
EUR
EUR
EUR
EUR
513,69
1234,56
1234,56
513,69
513,69
369,00
1234,56
1234,56
1234,56
A321
747-400
A310-300
A319
A319
A310-300
A310-300
A321
747-400
Details
Sort
Search
Filter
Total
Print
Download
Display variant
Toolbar
The SAP Grid Control
The ALV grid control is used for displaying non-hierarchical data in a table. Numerous user
functions are already implemented.
In the control, the columns can be made wider and smaller, or adapted to fit the data that is
currently being output using the Optimum Width function. Columns can also be swapped
around by selecting a column and dragging it to another position.
Standard functions are offered in the control toolbar. The Details View displays the fields in
the line on which the cursor was positioned in a modular dialog box.
The ALV control provides a Sort Function for any number of columns. You can determine
complex sort criteria and arrange the columns in ascending or descending order.
With the Search function you can search in lines or columns within a selected area for a
character string (generic search without *).
Totals can be requested for one or more numeric columns. Using the Subtotals function you
can then build control level lists: You select the column (non-numeric fields only) you want to
consider and the system provides you with the control level totals.
With Print and Download the complete list is always processed and not just the section in the
screen display.
The user can also make Display Variant settings.
SAP AG AC400 4-163
SAP AG 2006
Area
Custom
container
control
SAP grid control
Dynpro 100
Process
Before
Output
Process
After
Input
PBO module
Control
area
...
...
Container
instance
Grid
instance
The Custom Container as a Dynpro Object
An EnjoySAP control must be embedded in an SAP container control. This manages the
embedded controls and provides a physical area for visualization.
The container becomes the parent of the embedded control.
Since containers are themselves controls, they can be nested within one another. This allows
you to work with controls both flexibly and in a modular way.
You require at least one container and an ALV grid instance in order to use an ALV grid
control in your program.
SAP AG AC400 4-164
SAP AG 2006
Area
Custom
container
control
SAP grid control
Container
instance
Grid
instance
CL_GUI_CUSTOM_CONTAINER
CL_GUI_ALV_GRID
CLASS BUILDER
The SAP Grid in the Custom Container
Global classes (object types) are available in the Class Builder for steering the custom
container control and the ALV grid control :
CL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID.
SAP AG AC400 4-165
SAP AG 2006
Int. types Events
Superclasses
Methods
CONSTRUCTOR
CL_GUI_CUSTOM_CONTAINER
Class CL_GUI_CUSTOM_CONTAINER
Attributes Interfaces Properties Methods
Parameter for method CONSTRUCTOR
Parameter
PARENT
CONTAINER_NAME
...
Value Optional ... Associated type ... Description
. .
.
.
.
.
.
Mandatory parameter
of the CONSTRUCTOR method
have to be supplied with CREATE
OBJECT.
Class Builder
Is called implicitly with
CREATE OBJECT
The Constructor Method
For more detailed information about the global class CL_GUI_CUSTOM_CONTAINER,
navigate to the Class Builder: Display the object list for the class in the navigation area of the
Object Navigator. Then display the entire class or individual components in the editing area.
Alternatively, you can double-click on the class name from an ABAP program to access the
Class Builder. Depending on the display mode you then click on Parameter or Signature to get
detailed information about the interface parameters.
The global class CL_GUI_CUSTOM_CONTAINER only has the CONSTRUCTOR
method. When the instance is generated using CREATE OBJECT in the program, you have
to transfer at least the mandatory parameter container_name. The name of a custom container
area on a dynpro must be transferred to this parameter.
SAP AG AC400 4-166
SAP AG 2006
Superclasses
Interfaces
Attributes
Methods
. . .
CONSTRUCTOR
. . .
SET_TABLE_FOR_FIRST_DISPLAY
. . .
REFRESH_TABLE_DISPLAY
. . .
Redefinitions
Events
CL_GUI_ALV_GRID
If an implicit call is made at
CREATE OBJECT;
Mandatory parameter :
i_parent
Mandatory parameter :
it_outtab (Display data)
Optional parameter :
i_structure_name
(global structure for describing
the table line type)
Important SAP Grid Control Methods
The global class CL_GUI_ALV_GRID has numerous methods.. To display the content of an
internal table with an ALV grid control it is sufficient to examine three methods more closely.
CONSTRUCTOR:
The pointer to the container control instance must be transferred to the constructor.
SET_TABLE_FOR_FIRST_DISPLAY:
The internal table with the data to be displayed must be transferred to the it_outtab
parameter. This table must be a standard table so that the user can deploy the sort functions.
In addition, technical information is required for formatting the grid columns. The easiest
thing to do is to use a flat structure or a transparent table - in other words, a global type - as
the line type for the internal table. In this case, all you need to do now is transfer the name of
the line type to the i_structure_name parameter.
Alternatively, you can also construct a so-called field catalog and transfer it to
it_fieldcatalog.
REFRESH_TABLE_DISPLAY:
You only need to execute this method if the contents of the internal table have changed since
the first time they were displayed.
SAP AG AC400 4-167
SAP AG 2006
Custom
control
area
Type: Custom control
Name: CONTAINER_1
Resizing
Vertical : Min. lines: 5
Horizontal : Min. columns: 20
C
Screen Painter
Placing the Custom Control Container on the Dynpro
To reserve an area for an EnjoySAP control on a dynpro, you have to use the Screen Painter
(Layout pushbutton) to create a custom container area.
To the left of the toolbar next to the editing area you will find an icon with the description
Custom Control:
Choose the Custom Control pushbutton. Then determine the size and position of the area on
the dynpro. To do this, you should proceed as follows: You determine the top left corner of
the area by pressing the selection key of your mouse. Holding the mouse button down, drag
the mouse diagonally to the bottom right as far as the required lower right corner of the area
to be created. As soon as you release the mouse button, the lower right corner is fixed.
You can change the size and position of the area at any time by drag and drop using the
"pull symbol" that appears on the edge of the area.
Assign a name to your newly created dynpro element (here: CONTAINER_1).
You can use the attributes Vertical Resizing and Horizontal Resizing to determine whether or
not the area should be extended accordingly when you resize the dynpro. If you set the
attributes, you can determine the minimum size to which the area can be reduced using the
additional attributes Min. Lines and Min. Columns. The upper limit is determined by the size of
the area.
SAP AG AC400 4-168
SAP AG 2006
container_r
gdt_spfli
ok_code
grid_r
Custom Control Containers as Data Objects
DATA gdt_spfli TYPE sbc400_t_spfli.
DATA: container_r TYPE REF TO cl_gui_custom_container ,
grid_r TYPE REF TO cl_gui_alv_grid .
DATA ok_code TYPE sy-ucomm.
START-OF-SELECTION.
* fill internal table ...
CALL SCREEN 100.
Two reference variables are required in the ABAP program.
The reference variable that points to the container control instance is called container_r here,
and is typed with the global class cl_gui_custom_container.
The reference variable that points to the grid control instance is called grid_r here, and is
typed with the global class cl_gui_alv_grid.
SAP AG AC400 4-169
SAP AG 2006
container_r
grid_r
Instantiation of Custom Control Containers
MODULE create_control OUTPUT.
IF container_r IS INITIAL.
CREATE OBJECT container_r
EXPORTING container_name = 'CONTAINER_1'
CREATE OBJECT grid_r
EXPORTING i_parent = container_r.
...
ENDIF.
ENDMODULE.
You generate control instances with the CREATE OBJECT statement.
Make sure that you let the system create the statement for you. In this way, you avoid spelling
mistakes and errors. Similar to function module calls, the complete interface is implemented in
your program. CREATE OBJECT is the interface for the constructor method. Optional
parameters are inserted as a comment.
Control editing must be processed before the dynpro is displayed. It should also be coupled in
a modular way to the processing of the respective dynpro. For this reason we recommend you
implement a PBO module here.
The controls should be instantiated only once - before the dynpro is first displayed. This can
be realized simply by querying the content of one of the two reference variables.
Since the instantiation of the container control is implemented in the corresponding PBO
module here, it is sufficient to supply the name of the customer container area. In other cases,
the program name and dynpro number can be given as well.
When instantiating the grid control, it is sufficient to transfer the pointer to the container
instance. Thus the container control manages the technical linking of the grid control to the
dynpro.
SAP AG AC400 4-170
SAP AG 2006
MODULE create_control OUTPUT.
IF container_r IS INITIAL.
CREATE OBJECT container_r
EXPORTING container_name = 'CONTAINER_1' .
CREATE OBJECT grid_r
EXPORTING i_parent = container_r .
ENDIF.
ENDMODULE.
container_r
grid_r
CALL METHOD CALL METHOD
grid_r grid_r- -> >set_table_for_first_display set_table_for_first_display
EXPORTING EXPORTING i_structure_name i_structure_name = 'SPFLI' = 'SPFLI'
CHANGING CHANGING it_outtab it_outtab = = gdt_spfli gdt_spfli . .
Containing SAP Grids
To send the content of the internal table and the line type to the grid control, you have to call
the method set_table_for_first_display.
You transfer the name of the internal table to the it_outtab parameter.
Since the internal table was typed with the transparent table SPFLI as the line type, it is
sufficient to transfer this name to the i_structure_name parameter.
Basic settings for the grid control could also be supplied here too.
If the content of the internal table changes while the program is running, you have to call the
refresh_table_display method before you display the dynpro again.
SAP AG AC400 4-171
SAP AG 2006
Dialogs are programmed with the help of dynpro
technology.
By using the custom container, ALV reports can
be linked to dynpro technology.
Dialogs and ALV Reports: Summary
SAP AG AC400 4-172
Exercises
Unit 1: Dialogs and ALV Reports
At the conclusion of this exercise, you will know about:
The program library
The basic concept of dynpro logic
The custom control container
Database accesses
ALV as a tool for creating reports
1-1 The program library
1-1-1 Search for the custom container and ALV grid control documentation
in the program library.
1-1-2 Select a simple example program for an ALV grid control. Analyze the
program. Use the debugger for this too. Is a customer container used in
the ALV grid control?
1-2 Programming an ALV report using a template
1-2-1 Copy the program BCALV_GRID_DEMO with all the subobjects to
your local objects under the new name Y##ALV_GRID_DEMO.
1-2-2 Change the program Y##ALV_GRID_DEMO so that it displays
company codes instead of flights.
1-2-3 Change the screen output. Remove the text This belongs to the
dynpro. Then maximize the screen and the custom container to use all
the existing screen space to display the data.
1-2-4 Enter the title List of all company codes for your company code list.
SAP AG AC400 4-173
SAP AG AC400 4-174
Solutions
Unit 1: Dialogs and ALV Reports
1-1 The program library
1-1-1 Search for the custom container and ALV grid control documentation
in the program library.
Tools>ABAP Workbench>Overview>Reuse Library
Function Subscribe to Library
Selection SAP Technology
Navigation in the structure tree
SAP Technology >Controls>Control Container or
SAP Technology>Controls>ALV Grid Control
You will learn more about programs under the four tab pages
Overview, Documentation, Examples, and Program Objects.
1-1-2 Select a simple example program for an ALV grid control. Analyze the
program. Use the debugger for this too. Is a customer container used in
the ALV grid control?
Tools>ABAP Workbench>Overview>Reuse Library
Navigation in the structure tree
SAP Technology>Controls>ALV Grid Control
Tab page Examples
Examples>Simplest Call>BCALV_GRID_DEMO
The custom container G_CUSTOM_CONTAINER is typed under the
data declaration. The custom container is instantiated in the PBO
module. G_CUSTOM_CONTAINER is listed under the Element
List tab page for dynpro 100.
SAP AG AC400 4-175
1-2 Programming an ALV report using a template
1-2-1 Copy the program BCALV_GRID_DEMO with its subobjects to your
local objects under the new name Y##ALV_GRID_DEMO.
Tools>ABAP Workbench>Overview>Object Navigator
View Program
Program BCALV_GRID_DEMO
Selection Folder BCALV_GRID_DEMO
Context menu Copy
Target program Y##ALV_GRID_DEMO
Selection for Interface, dynpros, includes
Function Copy
Function Local object
1-2-2 Change the program Y##ALV_GRID_DEMO so that it displays
company codes instead of flights.
First you have to ascertain in which table the company codes are
listed. You can do this, for example, by following the path
Tools>ABAP Workbench>Overview>Business Object Browser.
The company code can be found under the Financial Accounting
application components. Double-click on it to see a list of the key
fields. By double-clicking on the key field you will see the reference
table T001.
Call the editor in change mode.
Function Find/Replace
Find SFLIGHT
Replace with T001
Function Activate (activate all subobjects)
Test your program.
SAP AG AC400 4-176
1-2-3 Change the screen output. Remove the text This belongs to the
dynpro. Then maximize the screen and the custom container to use all
the existing screen space to display the data.
Edit the dynpro 100. Under the Properties tab page, set the
maintainable coordinates to 200 / 255.
Function Layout
In the new layout mode, remove the text This belongs to the dynpro.
Then select close.
Function Attribute window
Visualized length 255
Visualized height 196
Function Close
Function Activate
Exit layout maintenance and the flow logic of the dynpro. Test your
program again.
1-2-4 Enter the title List of all company codes for your company code list.
Edit your program. Include a new line before the IF condition in the
module PBO.
SET TITLEBAR '100'.
Double-clicking on the title 100 allows you to create the title
manually.
Title List of all company codes
Function Copy
Function Activate (all objects)
Test your program again.
SAP AG AC400 4-177
SAP AG AC400 5-178
SAP AG 2006
Course Overview Diagram: Customer
Enhancements
Cust omer Enhanc ement s
Cust omer Enhanc ement s
The ABAP Wor k benc h
The ABAP Wor k benc h
Fi r st At t empt s at Pr ogr ammi ng
Fi r st At t empt s at Pr ogr ammi ng
Templ at e Al l oc at i on
Templ at e Al l oc at i on
Ex t r ac t i on
Ex t r ac t i on
Di al ogs and ALV Repor t s
Di al ogs and ALV Repor t s
SAP AG AC400 5-179
SAP AG 2006
Customer Enhancements - Unit Overview
This unit presents customer modifications and
enhancements. A Business Add-In is implemented.
Contents:
SAP AG AC400 5-180
SAP AG 2006
Differentiate between modifications and
enhancements
Implement BAdIs
Customer Enhancements: Unit Objectives
At the conclusion of this unit, you will be able to:
SAP AG AC400 5-181
SAP AG 2006
R/3 Business
Applications
(Standard SAP
system)
Customer
programs
Custom
develop-
ment
Enhance-
ment
Modification Customizing
Customizing ABAP
Workbench
Personalizing
Change Levels
You can adapt the R/3 system to your requirements in the following ways:
Customizing: For configuring your business processes and functions using the
Implementation Guide. Possible changes are thus planned and organized.
Personalizing: For changing the global display properties of fields (default settings,
hidden/visible), user-specific menu navigation.
Modification: Changes to SAP Repository objects in the customer's system. If SAP ships a
modified version of the object, the customer version must be adjusted with regard to the new
SAP version. Up to Release 4.0B, this must be performed manually using the upgrade
utilities. As of Release 4.5A, this technical adjustment is largely automated by means of the
Modification Assistant.
Enhancement: For creating customer Repository objects that are integrated in SAP
Repository objects.
Custom development: For creating custom Repository objects in line with customer
namespaces.
Customizing and most personalizing settings are configured with the Business Engineer tools.
Custom developments, enhancement concepts, and modifications, on the other hand, are are
managed with the ABAP Workbench tools.
SAP AG AC400 5-182
SAP AG 2006
Originals and Copies
Copy
Original
Copy
Copy
Original
SAP object SAP object SAP object
Customer object Customer object
Transport of
development
Development system
Follow-on system
An original object can exist in one system only. In the case of objects shipped by SAP, the
"original system" is located at SAP. These objects are merely copies in your customer system.
This applies to both your development system and all other follow-on systems.
If you create your own objects, these objects are original objects in your development system.
You always assign developments to a change request using a "development/correction" task.
This request is then used to transport the objects from your development system to your
follow-on systems.
SAP AG AC400 5-183
SAP AG 2006
Corrections and Repairs
Modified
copy
Corrected
original
Copy
Copy
Corrected
original
SAP object
Transport
of correction
SAP object SAP object
Customer object
Customer object
Correction
Repair Correction
Transport
of the repair
Follow-on system
Development system
Changes to original objects are referred to as corrections. For this reason, the system records
these changes in a transport request along with tasks of the type "development/correction".
If a copy is changed (that is, an object is not changed in the original system), this change is
included in a task of the type"repair". Repairs to SAP objects are known as modifications.
When you make repairs to your own objects (for example, following an emergency in your
production system), you can also make the changes to the original objects in your development
system straight away. It is essential that any changes you make to copies are also made to
the original objects immediately.
This option is not available for SAP objects because the originals are not available in one of
your systems.
You should only make modifications to the standard system if these are essential for
optimizing certain processes in your company. You should also be aware that good
background knowledge of the structure and process flow of an application is essential as a
basis for assessing modification options and for designing effective modifications to change
the standard system.
SAP AG AC400 5-184
SAP AG 2006
Modifications During an Upgrade
Modified
copy
Copy
Corrected
original
SAP object
Transport
of adjustment
SAP object SAP object
Upgrade Upgrade
Modification
adjustment
Follow-on system
Corrected
original
Copy
Customer object Customer object
Development system
Conflicts can occur when you import an upgrade, Support Package, or any other transport
request from SAP to your system.
Conflicts only occur when you modify an SAP object and the same object is shipped again by
SAP. In this case, the object shipped by SAP becomes the active object in the Repository
within your R/3 system.
If you want to rescue your changes, you have perform a modification adjustment for the
objects in question. If you have modified many SAP objects, you may experience considerable
delays when you install an upgrade.
To ensure consistency between your development system and your follow-on systems, we
recommend that you perform the modification adjustment in your development system only.
The adjustment objects are then transported to your follow-on systems.
SAP AG AC400 5-185
SAP AG 2006
Procedure for Functional Changes
Modification
Custom development with
SAP program as template
No
No
Yes
Does the standard SAP system
contain a similar function at all?
No
Does the
SAP application support
the integration of additional functions with
enhancements?
Yes
Enhancement
Is there a standard function
that can be adapted to the customer's requirements
in Customizing?
Yes
Customizing
Personalizing
No
Custom development
CSP solution
C
u
s
t
o
m
i
z
i
n
g
D
e
v
e
l
o
p
m
e
n
t
If the standard functions cannot be adapted to the customer's requirements using the available
Customizing or personalizing options, a development project must be started or, if available, a
CSP solution (CSP = Complementary Software Product) must be used. A list of CSP solutions
certified by SAP is available on SAP Service Marketplace under the alias /softwarepartner.
Development projects are used to manage custom developments if similar functions are not
available in the standard SAP system. Otherwise, standard SAP objects are used as a basis for
enhancements, user exits, modifications, or copies of SAP programs.
Modifications are problematic because, following a system upgrade, the new SAP version
must be adjusted with regard to the modified customer version. Up to Release 4.0B, this must
be performed manually using the upgrade utilities. As of Release 4.5A, this technical
comparison is largely automated by means of the Modification Assistant.
For this reason, you should only use modifications if
The Customizing or personalizing options do not satisfy your requirements
Suitable enhancements or user exits are not available or planned
Copying the SAP object to the customer namespace is not practical.
SAP AG AC400 5-186
SAP AG 2006
ABAP Workbench Change Levels
R/3 Business
Applications
(Standard SAP system)
Customer
programs
With call of SAP objects
Without call of SAP
objects
Custom
development
Modification Assistant
Modification
User exits
ABAP Dictionary
Tables
Data elements
Program enhancements
Function module exits
Business Transaction
Events
Business Add-Ins
Menu enhancements
Menu exits
Business Add-Ins
Screen enhancements
Screen exits
Business Add-Ins
Enhancement
Modifications are changes to SAP objects in customer systems. They are:
Located at user exits (subroutines reserved for customers in objects within the SAP
namespace)
Hard-coded at various positions in SAP Repository objects.
In custom developments, SAP Repository objects can be called from custom-defined
programs. Example: A customer writes a program that calls an SAP function module.
In the enhancement concepts, the roles are reversed: Repository objects that you have created
or changed are called by programs shipped by SAP. Example: You are using a function
module exit that is called by SAP. Enhancements can be made at the following levels:
In the ABAP program (function module exit)
In the GUI (menu exit)
In screens for displaying a subscreen in a screen area provided by SAP (screen exit)
As runs of custom program sections based on a screen field (field exit)
In tables or structures of the ABAP Dictionary (table enhancement).
SAP AG AC400 5-187
SAP AG 2006
ProgramEnhancements: Functionality
*** SAP program ***
*********************************
PROGRAM <name of SAP program>.
< <Enhancement Enhancement call call> >
<Object in customer namespace>
Customer exit
Exit function module
Business Transaction Event
Function module
Business Add-In
Method
The basic purpose of a program enhancement is to call an object in the customer namespace.
There are various ways of doing this:
Customer exits
- A special exit function module is called by the SAP application program. The function
module is part of a function group that is handled by the system in a specific manner.
Business Transaction Events
- A function module is called dynamically by the SAP application program in the customer
namespace.
Business Add-Ins
- The application program calls a method of a class or instance of a class. This class is in
the customer namespace.
SAP AG AC400 5-188
SAP AG 2006
Program Enhancements: SAP and Customer
SAP Customer
Customer exit:
Function module exit
FM coding
Business Transaction Events
Function module
in customer
namespace
Business Add-Ins
Method in
customer class
Call
Admin.
Interface
Documentation
Program enhancements enable you to define additional program logic for an SAP application
program. At present, SAP provides the options shown above.
The advantages and limitations of each enhancement option are discussed in greater detail in
the relevant units.
SAP AG AC400 5-189
SAP AG 2006
SAP Customer
PROGRAM ... .
...
*Original Coding..
...
...
...
...
*Original Coding..
...
SAP Program
Modifications
PROGRAM ... .
...
*Original Coding..
...
...
...
...
*Original Coding..
...
* Added/changed by customer
* Coding
SAP Program
When you make a modification, you modify the object shipped by SAP directly.
This has certain consequences the next time you perform an upgrade. If the object is shipped
again, you have to decide whether the new object shipped by SAP or the one you modified is
to be valid in your system.
Up to Release 4.0B, the finest level of granularity at which modifications were recorded was
the Repository object itself, such as an include program.
As of Release 4.5A, modifications are recorded with a finer level of granularity. This is
facilitated by the Modification Assistant, which is discussed in the Unit on "Modifications".
The modification adjustment concept was also thoroughly revised as a result. The procedure
for adjusting modifications is also discussed in this unit.
SAP AG AC400 5-190
SAP AG 2006
Business Add-Ins: Components
BAdI
FCodes
Program
<prog> +ABC
Function Code
Properties.
Multiple Use
Filter Dependent
INTERFACE
<badi-interface>.
DATA: a1 ...
ENDINTERFACE.
METHODS m2 ...
METHODS m1
EXPORTING
e_par1
e_par2
IMPORTING
i_par1.
Subscreens
Calling Program
<prog> 0200
Screen No.
ABCD
Subscreen Area
Scr..
Desc.
Generated
BAdI
Class
Business Add-Ins group the components of an enhancement. A Business Add-In can provide
the following enhancement options:
Program enhancement: The interfaces for program enhancements are defined in the Business
Add-In in the form of interface methods. This interface is used to implement the
enhancement. The SAP program calls the interface methods for the generated BAdI class.
Menu enhancement: Like customer exits, function codes can be entered in a BAdI. The
corresponding menu entries are included in the CUA definition and are visible when the
BAdI is implemented.
Screen enhancement: Like customer exits, screen enhancements can be defined in a BAdI
and then implemented.
Several components are created when you define a BAdI:
Interface
Generated class (BAdI class) that implements the interface
The generated class (BAdI class) has the following tasks:
Filtering: If a BAdI is to be executed under certain conditions only, the BAdI class ensures
that only the valid implementations are called.
Control: The BAdI class calls the active implementations.
SAP AG AC400 5-191
SAP AG 2006
Business Add-Ins: Flowchart
Application prog.
Service class
CL_EXITHANDLER
Instance of
BAdI class
<badi-class>
BAdI: Instance of
implement. class
Process active
implementations
1 1
2 2
This slide shows the process flow of a program that contains a BAdI call. You can use this
slide to help you understand the features and limitations of Business Add-Ins.
Not shown: A reference variable that refers to the BAdI interface must be declared in the
declaration section.
An object reference is generated in the first step. This is carried out by the service class
CL_EXITHANDLER shipped by SAP. The exact syntax will be explained on a later slide. The
requirements for calling the methods of the program enhancement are thus fulfilled.
The BAdI class that implements the interface is generated in the BAdI definition. The interface
method of the BAdI class is called in the second call (2). The BAdI class searches for all of the
active implementations for the Business Add-In and calls the implemented methods.
SAP AG AC400 5-192
SAP AG 2006
Business Add-Ins: Calling Program
REPORT <program_using_badi>.
START-OF-SELECTION.
END-OF-SELECTION.
DATA: r_var
TYPE REF TO <badi-interface>.
CALL METHOD
cl_exithandler=>get_instance
CHANGING
instance = r_var.
CALL METHOD r_var->method
EXPORTING
<i_variables>
IMPORTING
<e_variables>.
r_var
1
2
Instance of
<badi-class>
The above syntax is required to call a Business Add-In. The numbers shown correspond to the
calls on the last slide.
First, you have to define a reference variable that refers to the BAdI interface. The name of the
reference variable does not have to contain the name of the BAdI.
An object reference is generated in the first call (1). This creates an instance of the generated
BAdI class. This object reference can address only the methods of the interface.
This object reference can then be used to call the methods provided by the enhancement (2).
SAP AG AC400 5-193
SAP AG 2006
Implementing BAdIs: Methods
FCodes Interface Properties
Method
BAdI method
Description
<badi-interface>
Interface Name
<impl-class>
Name of Implementing Class
<method>
Class Builder: Edit Method <badi-interface>~<m...>
METHOD <badi-interface>~<method>.
*...
ENDMETHOD.
You can choose any name for the implementing class. However, SAP recommends that you
follow the proposed naming convention. The proposed name consists of
Namespace prefix, Y or Z
CL_ (stands for class)
IM_ (stands for implementation)
Name of the implementation (without namespace prefix)
By double-clicking the name of the method, you can go to the editor for implementing the
method.
Finally, you have to activate the objects.
SAP AG AC400 5-194
SAP AG 2006
Implementing BAdIs: Private Methods
Class Builder: Edit Method <badi-interface>~<m...>
METHOD <badi-interface>~<method>.
ENDMETHOD.
CALL METHOD < CALL METHOD <priv_method priv_method> EXPORTING ... . > EXPORTING ... .
Class Builder: Change Class <impl-class>
Events Methods Properties
Method
New method in implementation
Description
<priv_method>
Type
Parameters Exceptions
In the implementing class, you can create private methods that you call from the interface
method.
To do so, you edit the implementing class directly in the Class Builder. Here, you create the
private method and interface. You specify whether the method should be visible and
implement it.
SAP AG AC400 5-195
SAP AG 2006
Implementing BAdIs: Activation
Business Add-Ins: Implem. Maintenance Initial Screen
<impl>
Implementation Name
Activate
Undo activation
Display Create Change
You can use the relevant icons to activate the implementation of a Business Add-In. From this
point on, the methods of the implementation are processed when the calling program is
executed.
If you deactivate the implementation, the methods are no longer called. The calls in the
application program are still processed. However, the instance of the adapter class is no longer
able to find an active implementation. Unlike the call "CALL CUSTOMER-FUNCTION", the
call "CALL METHOD CL_EXITHANDLER=>GET_INSTANCE" is still executed even
though there is no implementation. This also applies to the method call that calls the method of
the adapter class.
You can activate or deactivate a BAdI only in the original system of the implementation
without having to make actual modifications. When you do so, you have to transport the
activation/deactivation to the downstream systems.
Multiple implementations can exist in a system for a Business Add-In that can have only one
implementation. Only one implementation can be active at any one time.
SAP AG AC400 5-196
SAP AG 2006
Modifications must be maintained when SAP
Notes and system upgrades are implemented.
SAP recommends that customer enhancements
do not contain modifications.
BAdIs are used in particular to implement
customer enhancements without the need for
modifications.
Customer Enhancements Unit Summary:
SAP AG AC400 5-197
SAP AG AC400 5-198
Exercises
Unit: Customer Enhancements
At the conclusion of this exercise, you will be able to:
Explain the concept of BAdIs
Implement BAdIs
1-1 Research the BAdIs shipped as standard
1-1-1 Use the Repository Information System of the Object Navigator to find
out how many BAdIs are shipped for Financial Accounting and Cost
Accounting.
1-1-2 Take a closer look at BAdI FAGL_AUTHORITY_CHECK. To which
component does the BAdI FAGL_AUTHORITY_CHECK belong?
How many methods does the BAdI have?
1-1-3 What parameters does the CHECK_LEDGER_AUTHORITY method
have? How does the method output the result of an authorization
check?
1-1-4 How many implementations already exist for the BAdI
FAGL_AUTHORITY_CHECK?
1-1-5 Implement the BAdI FAGL_AUTHORITY_CHECK. Use the
implementation name Y##FAGL_AUTHORITY. Save your
implementation as a local object. You do not have authorization for
ledger AL but do have authorization to display documents for ledger
0L.
As an optional requirement, you could use the function module
Y##AUTHORIZATION in your implementation to evaluate the
authorization that you grant according to the ledger. In this case, you
have to enhance the function module and your authorization object.
1-1-6 Now test your implementation in the BAdI environment. Then post a
G/L account document and check the document display.
SAP AG AC400 5-199
SAP AG AC400 5-200
Solutions
Unit: Customer Enhancements
1-1 Research the BAdIs shipped as standard
1-1-1 Use the Repository Information System of the Object Navigator to find
out how many BAdIs are shipped for Financial Accounting and Cost
Accounting.
Use transaction SE84 or choose Tools ABAP Workbench
Overview Information System..
Open the "Enhancements" folder in the object tree. Look for
"Definitions" under "Business Add-Ins". Use the following search
criteria
Application component FI* and CO*
Max. no. of hits 5000
1-1-2 Take a closer look at BAdI FAGL_AUTHORITY_CHECK. To which
component does the BAdI FAGL_AUTHORITY_CHECK belong?
How many methods does the BAdI have?
Use the following search criterion this time:
BAdI Name FAGL_AUTHORITY_CHECK
The "Attributes" tab page shows the package
"FAGL_POSTING_SERVICES". Double-click this package to view
the package properties. The package belongs to the component "FI-
GL". The "Interface" tab page lists exactly one method
"CHECK_LEDGER_AUTHORITY".
1-1-3 What parameters does the CHECK_LEDGER_AUTHORITY method
have? How does the method output the result of an authorization
check?
The "Interface" tab page lists the method
"CHECK_LEDGER_AUTHORITY". Double-click the method to
view its parameters. It has six import parameters. You can view the
exception messages by choosing the "Exceptions" pushbutton. The
result of the authorization check is provided by means of the
"NO_AUTHORITY" exception.
SAP AG AC400 5-201
1-1-4 How many implementations already exist for the BAdI
FAGL_AUTHORITY_CHECK?
You can view the implementations from the menu on the initial screen
by choosing Implementation Overview.
1-1-5 Implement the BAdI FAGL_AUTHORITY_CHECK. Use the
implementation name Y## FAGL_AUTHORITY. Save your
implementation as a local object. You do not have authorization for
ledger AL but do have authorization to display documents for ledger
0L.
As an optional requirement, you could use the function module
Y##AUTHORIZATION in your implementation to evaluate the
authorization that you grant according to the ledger. In this case, you
have to enhance the function module and your authorization object.
You can create your own implementations from the menu on the initial
screen by choosing Implementation Create. On the "Interface" tab
page, you can double-click a method to program it.
1-1-6 Now test your implementation in the BAdI environment. Then post a
G/L account document and check the document display.
On the "Interface" tab page, you can both program and test methods.
SAP AG AC400 6-202
SAP AG 2006
Overview Diagram: Extraction
Ex t r ac t i on
Ex t r ac t i on
The ABAP Wor k benc h
The ABAP Wor k benc h
Fi r st At t empt s at Pr ogr ammi ng
Fi r st At t empt s at Pr ogr ammi ng
Templ at e Al l oc at i on
Templ at e Al l oc at i on
Cust omer Enhanc ement s
Cust omer Enhanc ement s
Di al ogs and ALV Repor t s
Di al ogs and ALV Repor t s
SAP AG AC400 6-203
SAP AG 2006
Extraction Overview
This unit describes how data is extracted to the BW
system. In particular, it explains how to extract data
using function modules that you have created
yourself.
Contents:
SAP AG AC400 6-204
SAP AG 2006
Describe how data is extracted to the BW
system
Write your own extraction functions
Extraction: Unit Objectives
At the conclusion of this unit, you will be able to:
SAP AG AC400 6-205
SAP AG 2006
The Administrator Workbench
Model i ng
Moni t or i ng
Sc hedul i ng
Admi ni st r at or
Wor k benc h
BW creation
Maintenance
Administration
Schedule data
transfer
Load data
Monitor data transfer
Monitor update process
The Administrator Workbench is a tool for maintaining, controlling, and monitoring Business
Information Warehouse.
For this reason, the Administrator Workbench is used at all levels in the BW system:
To create all the components of Business Information Warehouse, including Customizing
settings.
To schedule data transfer from different data sources.
To load data
To monitor data transfer and data updates
SAP AG AC400 6-206
SAP AG 2006
BW ser ver
Transfer structure
SAP syst em
Fi l e syst em
Communication structure
Transfer structure
Extraction
structure
Transfer structure Transfer structure
DataSource DataSource
Flat file
DataSource
DataSource
(replicate)
DataSource
(replicate)
InfoSource
Data targets
Transfer structure
Extraction
structure
File
Mapping & transfer rules
Update rules
Data Flow from the Source to the Target System
An InfoSource is a set of logically related information that is grouped together in one unit.
InfoSources contain transaction data (stored in InfoCubes) and master data (attributes, texts,
and hierarchies - stored in separate tables).
InfoSources describe the set of all available information about a business transaction or a type
of business transaction (such as cost center accounting).
Transfer structures are used to transfer data in a DataSource between a source system and the
associated SAP BW system. The transfer structure transports the data in the DataSource from a
source system to an SAP BW system and forwards it to the InfoSource using transfer rules.
The communication structure is independent of the source system and is generated from the
InfoSource. It is filled from the transfer structure in accordance with the transfer rules. The
communication structure contains all the fields in an InfoSource. The process of extracting and
transferring cleansed data to the communication structure is referred to as "data staging".
SAP AG AC400 6-207
SAP AG 2006
BW server
SAP sour c e syst em
DataSource
When the DataSource is
replicated, fields in the
extraction structure are used as
a template for the transfer
structure in BW.
1
2
When the (local) transfer
rules are activated, the transfer
structure is generated both
in the BW system and in the
SAP source system.
Extraction
structure
Transfer structure
Transfer structure
2 1
DataSource (replicate)
Verification Between the Source and Target System
The extraction tables in the source system represent the basis for a DataSource in an R/3
source system. The structure is created in the source system using the data elements that
describe the available data (usually in a table view).
With an R/3 source system, the "DataSource Replication" step copies the DataSource
extraction source structure as a template from the source system to the BW system.
SAP AG AC400 6-208
SAP AG 2006
Transfer Rules Transfer structure
Communication Str./Transfer Rules
0COMP_CODE
InfoObject Tp Rule
0CO_AREA
COSTC##
0CURRENCY
0PROFIT_CTR
0CO_AREA
COSTC##
0CURRENCY
0PROFIT_CTR
0COMP_CODE
InfoObject Field Assignment
InfoObject Field
0COMP_CODE
0PROFIT_CTR
0CURRENCY
COSTC##
KOKRS
WAERS
PRCTR
BUKRS
KOSTL
0CO_AREA
IDOC
Transfer Method
PSA
InfoSource COSTC## GR## Cost Center 13
Communication Structure
InfoObject Description Status Type Length
0CO_AREA
COSTC##
0CURRENCY
0PROFIT_CTR
CHAR
CHAR
CHAR
CUKY
13
4
5
10
Controlling area
GR## Cost Center 13
Currency
Profit Center
Source System IDES R/3
DataSource ZGR##CC_ATTR
Defining Transfer Rules
Transfer rules determine which fields in the transfer structure are transferred to which fields in
the communication structure. You can create detailed conversion rules to change or extend the
data that is transferred.
You can choose only one of the three types of transfer rule for each InfoObject in the
communication structure:
The fields are copied from the transfer structure and are not modified.
You can assign a fixed value to a field.
You can create/assign local transfer routines. Local transfer routines are ABAP programs
that you can copy or modify. The routine affects only the selected InfoObject in the
associated communication structure.
You have to activate the transfer rules before they can be applied.
SAP AG AC400 6-209
SAP AG 2006
You can use function modules to select the data
in the source system that you want to extract.
Extraction Unit Summary:
SAP AG AC400 6-210
Extraction - Exercises
Unit: Extraction
At the conclusion of this exercise, you will be able to transfer data from a
source system (such as R/3) to a BW system. You will be familiar with:
The data export concept using DataSources and extraction from the
source system
The procedure for importing data using InfoSources in the target
system
How to program an extraction using function modules.
1-1 Program an extraction module
1-1-1 Create the function module Y##BW. Use the extraction documentation
in SAP Library to define the interface. Use your function module to
select certain cost centers, such as all cost centers that belong to profit
center 1402 or those where Mr. Janning is the cost center manager.
1-1-2 Configure your function module Y##BW as an extractor by specifying
Y##DS as the master data DataSource. When you define the
DataSource, also enter "AC400AKR3" as the application component
and the export structure of your function module as the extraction
structure.
1-1-3 Test your extractor and use the debugger to analyze the extraction.
1-1-4 Log onto the BW system. Replicate the DataSource.
SAP AG AC400 6-211
1-2 Transfer data from the source system to the BW data model
After you have imported the data from the source system by replicating the
DataSource, you can transfer it to the BW data model. To do so, you first have
to define a data model and then verify the DataSource.
1-2-1 Define the characteristic TE_Y##M with the description "Y## Cost
Center" as an InfoObject for the BW model. The data type is CHAR
with length 10. Choose ALPHA as the conversion routine. Define the
following fields as characteristic attributes:
0CO_AREA
0COMP_CODE
0BUS_AREA
0PROFIT_CTR
0RESP_PERS
0EVCURRCOST.
1-2-2 Create the InfoSource TE_Y##M in the component "AC400AKBW"
to update master data of the InfoObject with the same name
(TE_Y##M) directly. Assign the DataSource Y##DS to the
InfoSource. In the transfer rules, assign your BW field TE_Y##M to
the source field KOSTL.
1-2-3 Control the transfer by creating an InfoPackage. On the "Processing"
tab page, choose "PSA and then in the InfoObject"; on the "Update"
tab page, choose "Full Update" and on the "Schedule" tab page, choose
"Start Data Load Immediately".
1-2-4 Load the cost centers from the source system. Observe the transfer in
the monitor and analyze the result.
SAP AG AC400 6-212
Solutions
Unit: Extraction
1-1 Program an extraction module
1-1-1 Create the function module Y##BW. Use the extraction documentation
in SAP Library to define the interface. Use your function module to
select certain cost centers, such as all cost centers that belong to profit
center 1402 or those where Mr. Janning is the cost center manager.
The extraction documentation is available at:
SAP Library SAP NetWeaver Information Integration
Business Intelligence
Then choose: SAP Business Information Warehouse Data
Warehousing Data Retrieval Data Extraction from SAP Source
Systems Customizing Extractors Maintaining Generic Data
Sources Function Module: Interface Description and Procedure
You can display a list of the existing cost centers in transaction KS13
by choosing Accounting Controlling Cost Center Accounting
Information System Reports for Cost Center Accounting Master
Data Indexes Cost Centers: Master Data Report
Table CSKS contains the cost center master data. This table must type
the export parameter E_T_DATA.
1-1-2 Configure your function module Y##BW as an extractor by specifying
Y##DS as the master data DataSource. When you define the
DataSource, also enter "AC400AKR3" as the application component
and the export structure of your function module as the extraction
structure.
DataSources are defined with transaction RSO2.
IMG Integration with Other mySAP.com Components Data
Transfer to the SAP Business Information Warehouse Generic
DataSources Maintain Generic DataSources
1-1-3 Test your extractor and use the debugger to analyze the extraction.
DataSources are also tested with transaction RSO2.
IMG Integration with Other mySAP.com Components Data
Transfer to the SAP Business Information Warehouse Generic
DataSources Maintain Generic DataSources
You can simulate the extraction by choosing DataSource Test
Extraction in the maintenance transaction.
SAP AG AC400 6-213
1-1-4 Log onto the BW system. Replicate the DataSource.
SAP AG AC400 6-214
1-2 Transfer data from the source system to the BW data model
After you have imported the data from the source system by replicating the
DataSource, you can transfer it to the BW data model. To do so, you first have
to define a data model and then verify the DataSource.
1-2-1 Define the characteristic TE_Y##M with the description "Y## Cost
Center" as an InfoObject for the BW model. The data type is CHAR
with length 10. Choose ALPHA as the conversion routine. Define the
following fields as characteristic attributes:
0CO_AREA
0COMP_CODE
0BUS_AREA
0PROFIT_CTR
0RESP_PERS
0EVCURRCOST
1-2-2 Create the InfoSource TE_Y##M in the component "AC400AKBW"
to update master data of the InfoObject with the same name
(TE_Y##M) directly. Assign the DataSource Y##DS to the
InfoSource. In the transfer rules, assign your BW field Y##_KOSTL to
the source field KOSTL.
1-2-3 Control the transfer by creating an InfoPackage. On the "Processing"
tab page, choose "PSA and then in the InfoObject"; on the "Update"
tab page, choose "Full Update" and on the "Schedule" tab page, choose
"Start Data Load Immediately".
1-2-4 Load the cost centers from the source system. Observe the transfer in
the monitor and analyze the result.
SAP AG AC400 7-215
SAP AG 2006
Overview Diagram: Template Allocation
Templ at e Al l oc at i on
Templ at e Al l oc at i on
The ABAP Wor k benc h
The ABAP Wor k benc h
Fi r st At t empt s at Pr ogr ammi ng
Fi r st At t empt s at Pr ogr ammi ng
Cust omer Enhanc ement s
Cust omer Enhanc ement s
Ex t r ac t i on
Ex t r ac t i on
Di al ogs and ALV Repor t s
Di al ogs and ALV Repor t s
SAP AG AC400 7-216
SAP AG 2006
Template Allocation Unit Overview
This unit presents the concept of template
allocation and describes interfaces that allow you to
implement specific data access and cost
calculations.
Contents:
SAP AG AC400 7-217
SAP AG 2006
Use your own methods in template allocation.
Template Allocation: Unit Objectives
At the conclusion of this unit, you will be able to:
SAP AG AC400 7-218
SAP AG 2006
The Template as a Costing Tool
Template
BOM
No. BOM
Items
Standard cost
estimate
Lot size
Material master data
Weight
External -
systems
Meas. data
Routing
No. work centers
CO-PA
No. value fields
Cost drivers can originate from many areas in the integrated R/3 system.
Bills of material can provide the number of components in a cost object, for example, and the
routing can indicate the number of work centers through which the cost object must pass.
The standard cost estimate can provide the lot size of the material produced.
SAP AG AC400 7-219
SAP AG 2006
Product Costing with Templates
Rout -
ing
Bill of
materials
Material Lot size
CO - values
Material
Activities
Overhead
Processes:
300000
300100
Cost
element:
R-4000
Functions
Template
Prod_1
Material:
R-4000
Statistical
key figures
Processes
Other
SAP sources
P
ro
cess
q
u
an
tities
Product cost planning includes the quantities and prices from the planned consumption of
process quantities.
The cost component view can be maintained in Customizing to include processes in an
aggregated view of process costs and quantities for individual product cost plans.
In Customizing for cost components, you can define each component as valuation relevant if
the process costs should be included in inventory.
In the itemization view of the product cost estimate, process values are marked "X."
Overhead values calculated using a costing sheet are marked "G".
SAP AG AC400 7-220
SAP AG 2006
Material:
R 4000
Unit cost estimate/
standard cost estimate
Derivation of Templates in the Cost Estimate
Template Prod _1
Template Prod_2
10
20
10
20
QuantityValuation time
Cleaning
Q. insp.
Process
30
20
Order-start
Delivery
Template Prod _3
Main template
Costing
sheet
Overhead
key
Overhead group:
SAP900
Valuation
variant 001
Costing
variant PPC1
The link between the template and the cost estimate is created through a template assignment
function in Customizing.
The template is assigned to a combination of overhead key and costing sheet.
The costing sheet is linked to a valuation variant, which, in turn, is linked to a costing variant
that is linked to the order type.
The overhead group belongs to the material master data. It is assigned to an overhead key in
Customizing.
You can still use a costing sheet for overheads that are not modeled using processes.
SAP AG AC400 7-221
SAP AG 2006
Template for cost element
Pl. Qty. Pl. Activ. Object Act. Qty . Act. Activ. . Act. Val. Ev.
Which
process?
Which process quantity?
When?
Under what conditions?
Template Rows as Formula Vectors
A template is created within a certain environment, which is determined by the cost object
that will consume the process quantities. A process that is consumed by a PP production
order, for example, is controlled by a template created in environment 001. Conversely, a
process (possibly the same process) that is consumed by a sales order is controlled by a
template created in environment 008.
A template consists of pre-defined columns. Each of these columns looks for information -
that is, it asks a question. The answer may be entered by the user, or determined dynamically
by the system.
The real power of Activity-Based Costing in R/3 is realized when the system answers these
questions dynamically.
SAP AG AC400 7-222
SAP AG 2006
"Functions" as Form Components
Template for cost element
Pl. Qty. Pl. Activ. Object Act. Qty . Act. Activ. . Act. Val. Ev.
Which
process?
How much of the process
quantity?
When?
Under what conditions?
F
u
n
c
t
i
o
n
s
F
u
n
c
t
i
o
n
s
F
u
n
c
t
i
o
n
s
F
u
n
c
t
i
o
n
s
Each environment contains a specific set of functions for the user to select in order to answer
the questions shown above. You create a template using the functions in the individual cells.
Each template can contain as many rows as are necessary.
There are 3 different types of rows that can be created and combined in one template. Each
type of row serves a different purpose. A Comment row is used for documentation. A
Business Process row is used for process consumption by a cost object. A Subtemplate row is
used to link templates for a nested template structure. A Calculation row can be used when
multiple Business Process rows use the results of a single calculation (in the same template
only). If the template is created in the SBP (Structured Business Process) environment, an
additional TASK row type is available so that a cost center or activity type can be used in the
"Object" column.
SAP AG AC400 7-223
SAP AG 2006
Under what
conditions?
Subenvironment 101: Processes
Functions: ......
......
Subenvironment 103: Material
Functions: Material_Characteristic_value
......
Subenvironment 107: General data
Functions: ......
......
Which
process?
When?
Which
process quantity?
PP production
order
Subenvironments as Function Groups
Each cost object in the system is permanently assigned to an environment. You cannot change
these assignments.
Each environment contains predefined subenvironments. This assignment is also fixed and
cannot be changed.
Each subenvironment contains a collection of specific functions that refer to the data in that
particular subenvironment. For instance, a function designed to read the material
characteristics assigned to a material in the material master is located in the Material
subenvironment in the environment defined by the consuming cost object.
The template, which is assigned to a specific environment when it is created, can access all
the functions that are assigned to the subenvironments.
SAP AG AC400 7-224
SAP AG 2006
Environments and Subenvironments
Subenvironment 105:
Routing
Subenvironment 103:
Material
New functions
Subenvironment 107:
General data
Environment 001: mat. c. est./
production orders
Environment 003: matl c. est.
without quantity structure
Environment PAC:
costing-based
profitability analysis
Subenvironment 101:
Sender process
Standard Optional
A subenvironment can be assigned to more than one environment, which means that the
functions within the subenvironment are available to more than one type of cost object. For
instance, the functions of the subenvironment that involve routings are available for sales
orders and production orders, but not for cost estimates without a quantity structure.
You can assign your own functions to either a subenvironment or an environment directly.
Assigning functions to a subenvironment provides you with greater flexibility, because more
than one type of cost object can use the available functions.
In Customizing, you can restrict the use of each new function to a single cell in the template.
Inside each cell, you can restrict how the function is used even further. By doing so, you can
ensure that the functions are used effectively. For instance, if a function requires a material
number as a parameter, only material number functions are made available.
SAP AG AC400 7-225
SAP AG 2006
Function Modules as Functions
Functions
Table field ABAP-Functions
Storage location: 0001
Material Master View:MRP. 2
Procurement
K_ABC_ORDER_MAT_CONFIRMATION
Table name:
MARC
Field name:LGPRO
There are two different kinds of functions: table-field and ABAP functions.
A table-field function allows a function to use fields from tables that have been allowed in the
specific, shipped environments.
An ABAP function is required if you need access to a field in a table that is not included in
the specific, shipped environments.
New functions must be created within the template environment area in Customizing.
When you create new functions, you must observe the three-level naming convention that
requires an external name, an internal name, and a logical function name.
Functions can be copied, changed, and/or renamed.
SAP AG AC400 7-226
SAP AG 2006
You can create your own allocation methods in
template allocation.
By doing so, you can implement your own
access types and cost calculations.
The allocation methods are realized by function
modules.
Template Allocation Unit Summary:
SAP AG AC400 7-227
Exercises
Unit: Function Modules in Template Allocation
At the conclusion of this exercise, you will be able to:
Use function modules in template allocation
1-1 Program your own function module for template allocation
1-1-2 Analyze the storage conditions for material R-F100 in plant 1000 at
storage location 002. Does a temperature condition exist?
1-1-3 Create a function module Y##WHENERGY that calculates and
outputs the warehouse energy consumption for a specific material
number, whose volume is measured in cubic meters, according to the
following formula: energy = volume x 1000 x temperature condition
1-1-4 Before your function module Y##WHENERGY can be used in the
template allocation, it must satisfy certain interface requirements. Find
out what these requirements are. To do so, use SAP Library or analyze
a function module that is already used in the template allocation.
1-2 Use your own function modules in the template allocation
1-2-1 First analyze the process costs in the cost estimate for material R-
F100. Which processes are involved and in what quantity? How is the
output quantity maintained?
1-2-2 Create a Y##Energy_consumption function with the same logical
function name in the "Materials" subenvironment in environment 001
(material cost estimate/production orders) . Assign your
Y##WHENERGY function module to this function. On the "Usage"
tab page for business processes, allow the function to calculate
quantities.
1-2-3 Create a template Y##. In this template, the quantity of the business
process 300901 ("Cooling") is calculated as a product of the
warehouse energy consumption for the order material and the total
material quantity for the order.
1-2-4 Add your template Y## to the template COPC-10 as a subtemplate.
1-2-5 Check the rate specified in annual planning for business process
300901 ("Cooling").
1-2-6 Recalculate the cost of goods manufactured for material R-F100.
SAP AG AC400 7-228
SAP AG AC400 7-229
Solutions
Unit: Function Modules in Template Allocation
1-1 Program your own function module for template allocation
1-1-1 Analyze the storage conditions for material R-F100. Does a
temperature condition exist? Which fields contain a temperature
condition and volume?
Start transaction MM03 by choosing Logistics Materials
Management Material Master Material Display Display
Current
Material R-F100
Pushbutton "Select (views)"
Choose General Plant Data / Storage 1
Choose General Plant Data / Storage 2
Choose "Continue"
Plant 1000
Storage location 0002
The "Plant Data / Stor. 1" tab page shows the temperature condition
01; the "Plant Data / Stor. 2" tab page shows the volume 0.75 M3. You
can use the input help to display the "Technical Information" for a
selected field. This information provides the names of the database
fields. These fields are:
Temperature conditions MARA-TEMPB
Volume MARA-VOLUM
Volume Unit MARA-VOLEH
SAP AG AC400 7-230
1-1-2 Before your function module Y##WHENERGY can be used in the
template allocation, it must satisfy certain interface requirements. Find
out what these requirements are. To do so, use SAP Library or analyze
a function module that is already used in the template allocation.
You can find the interface conditions in SAP Library by choosing
Financials Controlling Activity-Based Costing Template
Environment of Templates Implementing ABAP Functions.
In the template allocation function in the system (transaction CTU6),
you can find the "MaterialCharacteristicValue" function in the
"Materials" subenvironment of environment 001 by choosing IMG
Controlling Activity-Based Costing Templates Define
Environments and Function Trees. This is assigned to the function
module K_ABC_MATERIAL_FEATURE_VALUE and can be
analyzed with transaction SE37, for example.
1-1-3 Create a function module Y##WHENERGY that calculates and
outputs the warehouse energy consumption for a specific material
number, whose volume is measured in cubic meters, according to the
following formula: energy = volume x 1000 x temperature condition
* The table parameter RTABLE_VAL of type TPLIC_RVAL_TAB
* is defined in the type group TPLIC. This must be stored in
the
* top include in the following format:
* TYPE-POOLS: tplic.
FUNCTION Y##WHENERGY.
*"-------------------------------------------------------------
---------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(ID_MATNR) TYPE MATNR
*" REFERENCE(PERIOD_FROM)
*" REFERENCE(PERIOD_CNT)
*" REFERENCE(CALL_PROG) TYPE SY-REPID
*" TABLES
*" RTABLE_VAL TYPE TPLIC_RVAL_TAB
*"-------------------------------------------------------------
---------
* data
DATA: ls_mara TYPE mara.
DATA: ld_temp_faktor TYPE i.
DATA: ld_quantity TYPE tplic_rval-value.
DATA: ld_wa_rval TYPE tplic_rval.
* Clear output
CLEAR rtable_val[].
* Get master data
SELECT SINGLE *
FROM mara
INTO ls_mara
SAP AG AC400 7-231
WHERE matnr = id_matnr.
* Master record found?
CHECK sy-subrc = 0.
* Evaluate temperature condition
CASE ls_mara-tempb.
WHEN '01'.
ld_temp_faktor = 1.
WHEN '02'.
ld_temp_faktor = 2.
WHEN '03'.
ld_temp_faktor = 3.
WHEN OTHERS.
ENDCASE.
* Evaluate volume and determine result
CASE ls_mara-voleh.
WHEN 'M3'.
ld_quantity = ls_mara-volum * 1000 * ld_temp_faktor.
WHEN OTHERS.
"nothing to do.
ENDCASE.
* if no periodic result, fill the result table for periods
DO period_cnt TIMES.
ld_wa_rval-period = period_from + sy-index - 1.
ld_wa_rval-value = ld_quantity.
APPEND ld_wa_rval TO rtable_val.
ENDDO.
ENDFUNCTION.
1-1-4 Test your function module for material R-F100.
1-2 Use your own function modules in the template allocation
1-2-1 First analyze the process costs in the cost estimate for material R-
F100. Which processes are involved and in what quantity? How is the
output quantity maintained?
To find the material cost estimate (transaction CK13N), choose
Accounting Controlling Product Cost Controlling Product
Cost Planning Material Costing Cost Estimate with Quantity
Structure Display.
Material R-F100
Plant 1000
Costing variant PPC1
The costing structure functions include the "Materials Only/All Items"
pushbutton. You can use this pushbutton to expand the list to show all
SAP AG AC400 7-232
cost items and, in particular, the list of processes. A process is
allocated for the cost of goods manufactured:
Process Number Quantity
Work Scheduling 300900 1 pc
1-2-2 Create a Y##Energy_consumption function with the same logical
function name in the "Materials" subenvironment in environment 001
(material cost estimate/production orders) . Assign your
Y##WHENERGY function module to this function. On the "Usage"
tab page for business processes, allow the function to calculate
quantities.
Start the template allocation function in the system (transaction CTU6)
by choosing IMG Controlling Activity-Based Costing
Templates Define Environments and Function Trees
and select the "Materials" subenvironment in the object tree. Choose
"Create Function" from the context menu.
Function Y##Energy_consumption
Radio button "Lower Level"
Tab page "Basic Data"
Log. Function Name Y##WHENERGY
Tab page "Implementation"
ABAP Function Name Y##WHENERGY
Tab page "Usage"
Tab page "All Columns"
Select "Quantity Plan" in the "Business Process" row.
Pushbutton "Save"
SAP AG AC400 7-233
1-2-3 Create a template Y##. In this template, the quantity of the business
process 300901 ("Cooling") is calculated as a product of the
warehouse energy consumption for the order material and the total
material quantity for the order.
Start the template allocation function (transaction CTU6) in the system
by choosing
IMG Controlling Activity-Based Costing Templates
Maintain Templates
and choose "Create Template:
Template Y##
Environment 001
Enter another row:
Type "Business Process"
Object "300901"
Plan Quantity Double-click the field
In the editor, enter:
Y##Energy_consumption ( ID_MATNR = OrderMaterial ) *
OrderTotalQuantity
Pushbutton "Confirm Plan Quantity"
Enter "ACTIVE" in the "Plan Activation" column.
1-2-4 Add your template Y## to the template COPC-10 as a subtemplate.
Start the template allocation function (transaction CTU6) in the system
by choosing
IMG Controlling Activity-Based Costing Templates
Maintain Templates
and choose "Change Template":
Template COPC-10
Environment 001
Enter another row:
Pushbutton "Insert Row"
Type "Subtemplate"
Object Y##
Plan Activation "ACTIVE"
SAP AG AC400 7-234
1-2-5 Check the rate specified in annual planning for business process
300901 ("Cooling").
Start transaction CP26 by choosing
Accounting Controlling Activity-Based Costing Planning
Process Quantities/Prices Change
Version 0
From Period: Current period
To Period current period
Fiscal Year Current fiscal year
Pushbutton Overview Screen
Make sure that a price has been defined.
1-2-6 Recalculate the cost of goods manufactured for material R-F100.
You can find the material cost estimate (transaction CK13N) by
choosing
Accounting Controlling Product Cost Controlling
Product Cost Planning Material Costing Cost Estimate with
Quantity Structure Create
Material R-F100
Plant 1000
Costing variant PPC1
The costing structure functions include the "Materials Only/All Items"
pushbutton. You can use this pushbutton to expand the list to show all
cost items and, in particular, the list of processes. Process "300901"
here shows the quantity that was calculated using your function
module.
SAP AG AC400 8-235
SAP AG 2006
Appendix
Optional exercise 1
Write a program for maintaining customer address data
Optional Exercise 2
Write a program for opening and closing FI periods
Optional exercise 3
Program a report for master data groups in Cost
Accounting
SAP AG AC400 8-236
SAP AG AC400 8-237
Optional Exercise F1
Write a Program for Maintaining Customer Address Data
At the conclusion of this exercise, you will be able to:
Create tables
Select records from tables and write to tables
Call function modules
Requirement
The following function is available for vendors and is also required for customers:
Changes to addresses that are already known but will not take effect until a future date
can be maintained in advance. This takes place in three steps: Future changes can be
entered on a key-date basis using transaction MK12 (see path below). The planned
changes can be viewed with transaction MK14. Changes that have been flagged for key
dates can be activated with transactions MKH3 and MKH4. The paths are as follows:
MK12 Logistics Materials Management Purchasing Master Data
Vendor
Purchasing Change (Planned)
MK14 Logistics Materials Management Purchasing Master Data
Vendor
Purchasing Planned Changes
MKH3 Vendor Activate Planned Changes Activation Online
System Analysis
Find out which tables store the customer master data. If necessary, use the ABAP
Workbench or debugger to do so.
Program Design
The following functions are required to maintain the future customer address data:
(a) The existing address data is modeled as a template for future changes in
the form of a copy of the customer address data stored in a custom address
table
(b) There must be an option of maintaining the custom address table so that
key-date based updates can be flagged.
(c) The release of flagged updates is modeled in the form of a copy of the
custom address data to the standard address data table.
(d) It must be possible to reactivate the previous address data so that any
update errors can be rectified.
The custom address table is a copy of the standard address table ADRC with the name
Y##ADRC. If the definition of table Y##ADRC allows data to be displayed and
SAP AG AC400 8-238
maintained ("Delivery and Maintenance" tab page), you do not need to program the
function listed under (b) because you can use transaction SE16 instead.
In this case, write a program that offers three options:
(a) "INITI" for modeling the function listed under (a)
(b) "ACTIV" for modeling the function listed under (c)
(c) "REACT" for modeling the function listed under (d)
Task
F1-1 Create table Y##ADRC as a copy of table ADRC. Allow table maintenance.
F1-2 Create a domain Y##ACTION called "Action". The data type is CHAR and the
number of characters 10. For the range, define three fixed values "INITI" with the
description "Initialize", "ACTIV" with the description "Activate Changes", and
"REACT" with the description "Undo Changes".
F1-3 Create a data element Y##ACTION with the name "Action". Assign the domain
Y##ACTION to the data element.
F1-4 Create a Y##CUSTOMER program that contains the functions of the actions.
SAP AG AC400 8-239
Solution for Optional Exercise F1
Write a Program for Maintaining Customer Address Data
Requirement
The following function is available for vendors and is also required for customers:
Changes to addresses that are already known but will not take effect until a future date
can be maintained in advance. This takes place in three steps: Future changes can be
entered on a key-date basis using transaction MK12 (see path below). The planned
changes can be viewed with transaction MK14. Changes that have been flagged for key
dates can be activated with transactions MKH3 and MKH4. The paths are as follows:
MK12 Logistics Materials Management Purchasing Master Data
Vendor
Purchasing Change (Planned)
MK14 Logistics Materials Management Purchasing Master Data
Vendor
Purchasing Planned Changes
MKH3 Vendor Activate Planned Changes Activation Online
System Analysis
Find out which tables store the customer master data. If necessary, use the ABAP
Workbench or debugger to do so.
Program Design
The following functions are required to maintain the future customer address data:
(a) The existing address data is modeled as a template for future changes in
the form of a copy of the customer address data stored in a custom address
table
(b) There must be an option of maintaining the custom address table so that
key-date based updates can be flagged.
(c) The release of flagged updates is modeled in the form of a copy of the
custom address data to the standard address data table.
(d) It must be possible to reactivate the previous address data so that any
update errors can be rectified.
The custom address table is a copy of the standard address table ADRC with the name
Y##ADRC. If the definition of table Y##ADRC allows data to be displayed and
maintained ("Delivery and Maintenance" tab page), you do not need to program the
function listed under (b) because you can use transaction SE16 instead.
In this case, write a program that offers three options:
(a) "INITI" for modeling the function listed under (a)
(b) "ACTIV" for modeling the function listed under (c)
SAP AG AC400 8-240
(c) "REACT" for modeling the function listed under (d)
Task
F1-1 Create table Y##ADRC as a copy of table ADRC. Allow table maintenance.
Tools ABAP Workbench Development ABAP Dictionary
(SE11)
Select "Database table"
Database table ADRC
Function "Copy"
From Table ADRC
To Table Y##ADRC
Function Local Object
Tools ABAP Workbench Development ABAP Dictionary
(SE11)
Select "Database table"
Database table Y##ADRC
Function Change
Tab page "Delivery and Maintenance"
Date Browser X Display/Maintenance Allowed
Function "Activate"
F1-2 Create a domain Y##ACTION called "Action". The data type is CHAR and the
number of characters 10. For the range, define three fixed values "INITI" with the
description "Initialize", "ACTIV" with the description "Activate Changes", and
"REACT" with the description "Undo Changes".
Tools ABAP Workbench Development ABAP Dictionary
(SE11)
Select "Domain"
Domain Y##ACTION
Function "Create"
Short description Action for program Y##Customer
Tab page "Definition"
Data Type "CHAR"
No. Characters 10
Tab page "Value Range"
Fixed Value INITI
SAP AG AC400 8-241
Short Text Initialize
Fixed Value ACTIV
Short Text Activate changes
Fixed Value REACT
Short Text Undo changes
Function "Activate"
Function Local Object
F1-3 Create a data element Y##ACTION with the name "Action". Assign the domain
Y##ACTION to the data element.
Tools ABAP Workbench Development ABAP Dictionary
(SE11)
Select "Data Type"
Data Type Y##ACTION
Function "Create"
Select "Data Element"
Short Text Action for program Y##Customer
Tab page "Data Type"
Select "Elementary Type"
Select "Domain"
Domain Y##ACTION
Tab page "Field Label"
Short label Action
Medium label Action
Long label Action
Heading Action
Function "Activate"
Function "Local Object"
F1-4 Create a Y##CUSTOMER program that contains the functions of the actions.
You can create the message of class AC400 with the number 600 in the same way
as described for program Y##CUSTOMER. As soon as you have created the
program (as described below), you can maintain the selection texts in the editor
menu under
Goto Text Elements Selection Texts
by referencing the Data Dictionary.
Tools ABAP Workbench Overview Object Navigator
SAP AG AC400 8-242
View Local objects
Local objects AC400-##
Select the rood node $TMP AC400-##
Context menu Create Program
Program Y##CUSTOMER (without top
include)
Title Maintain future customer master data
Type "1 Executable Program"
Function "Save"
Function "Local Object"
In the proposed solution, we will use "AC400" instead of "Y##".
*&---------------------------------------------------------------------
*& Report AC400CUSTOMER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ac400customer.
* Tables
TABLES: kna1.
* Parameters
PARAMETERS: p_date TYPE date_from DEFAULT sy-datum NO-DISPLAY.
SELECT-OPTIONS: r_kunnr FOR kna1-kunnr.
PARAMETERS: p_action TYPE ac400action.
* Types
TYPES: yt_kunnr LIKE TABLE OF r_kunnr.
TYPES: yt_kna1 TYPE TABLE OF kna1.
TYPES: ys_kna1 TYPE kna1.
TYPES: ys_adrc TYPE adrc.
TYPES: yt_adrc TYPE TABLE OF ys_adrc.
TYPES: ys_ac400adrc TYPE ac400adrc.
TYPES: yt_ac400adrc TYPE TABLE OF ys_ac400adrc.
* Constants
CONSTANTS: gc_first_date LIKE sy-datum VALUE '00010101'.
CONSTANTS: gc_last_date LIKE sy-datum VALUE '99991231'.
SAP AG AC400 8-243
CONSTANTS: gc_empty_nation TYPE ad_nation VALUE IS INITIAL.
* Call the main program
PERFORM main
USING p_date
r_kunnr[]
p_action.
*&---------------------------------------------------------------------*
*& Form main
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_DATE text
* -->P_R_KUNNR[] text
* -->P_P_ACTION text
*----------------------------------------------------------------------*
FORM main
USING id_date LIKE sy-datum
it_kunnr TYPE yt_kunnr
id_action TYPE ac400action.
* data
DATA: lt_kna1 TYPE yt_kna1.
DATA: ls_kna1 TYPE ys_kna1.
DATA: ld_answer TYPE char3.
* Authorization check
CALL FUNCTION 'Y_AC400AUTHORITY'
IMPORTING
ed_answer = ld_answer.
CASE ld_answer.
WHEN 'IES'.
"ok
WHEN OTHERS.
MESSAGE e600(f1) WITH sy-uname text-001.
ENDCASE.
* select from kna1
SELECT *
FROM kna1
INTO TABLE lt_kna1
WHERE kunnr IN it_kunnr[].
* insert ykna1
LOOP AT lt_kna1
INTO ls_kna1.
* Evaluate according to action
CASE p_action.
* Initialize
WHEN 'INITI'.
PERFORM initialize
SAP AG AC400 8-244
USING p_date
ls_kna1.
* Activate
WHEN 'ACTIV'.
PERFORM activate
USING p_date
ls_kna1.
* Reactivate
WHEN 'REACT'.
PERFORM react
USING p_date
ls_kna1.
* Undefined input
WHEN OTHERS.
MESSAGE ID 'AC400' TYPE 'E' NUMBER '600'
WITH 'Choose a valid action".
ENDCASE.
WRITE: / 'Vendor', ls_kna1-kunnr, 'has been maintained'.
ENDLOOP.
ENDFORM. " main
*&---------------------------------------------------------------------*
*& Form initialize
*&---------------------------------------------------------------------*
FORM initialize
USING id_date TYPE date_from
is_kna1 TYPE ys_kna1.
* data
DATA: ls_adrc TYPE ys_adrc.
DATA: ls_yadrc TYPE ys_ac400adrc.
SELECT SINGLE *
FROM adrc
INTO ls_adrc
WHERE addrnumber = is_kna1-adrnr
AND date_from = gc_first_date
AND nation = gc_empty_nation.
* Delete existing entries
DELETE FROM ac400adrc
WHERE addrnumber = is_kna1-adrnr.
* Insert new from kna1
MOVE-CORRESPONDING ls_adrc TO ls_yadrc.
ls_yadrc-date_from = id_date.
INSERT ac400adrc FROM ls_yadrc.
ENDFORM. " initialize
SAP AG AC400 8-245
*&---------------------------------------------------------------------*
*& Form activate
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ID_DATE text
* -->P_LS_KUNNR text
*----------------------------------------------------------------------*
FORM activate
USING id_date TYPE date_from
is_kna1 TYPE ys_kna1.
* data
DATA: ls_adrc TYPE ys_adrc.
DATA: ls_ac400adrc TYPE ys_ac400adrc.
DATA: ls_adrc_old TYPE ys_adrc.
DATA: ls_adrc_new TYPE ys_adrc.
SELECT SINGLE *
FROM adrc
INTO ls_adrc
WHERE addrnumber = is_kna1-adrnr
AND date_from = gc_first_date
AND nation = gc_empty_nation.
SELECT SINGLE *
FROM ac400adrc
INTO ls_ac400adrc
WHERE addrnumber = is_kna1-adrnr
AND date_from = id_date
AND nation = gc_empty_nation.
IF sy-subrc = 0.
* init ls_kna1_new
MOVE-CORRESPONDING ls_ac400adrc TO ls_adrc_new.
ls_adrc_new-date_from = gc_first_date.
* Update customers
UPDATE adrc FROM ls_adrc_new.
* Archive previous entry
ls_adrc_old = ls_adrc.
ls_adrc_old-date_from = id_date - 1.
ls_adrc_old-date_to = id_date - 1.
MODIFY adrc FROM ls_adrc_old.
ELSE.
"nothing to do
ENDIF.
ENDFORM. " activate
SAP AG AC400 8-246
*&---------------------------------------------------------------------*
*& Form react
*&---------------------------------------------------------------------*
FORM react
USING id_date TYPE date_from
is_kna1 TYPE ys_kna1.
* data
DATA: ls_adrc_r TYPE ys_adrc.
DATA: ls_adrc_f TYPE ys_adrc.
DATA: lt_adrc TYPE yt_adrc.
DATA: ld_len LIKE sy-tabix.
SELECT *
FROM adrc
INTO TABLE lt_adrc
WHERE addrnumber = is_kna1-adrnr
AND date_from <= id_date
AND nation = gc_empty_nation.
SORT lt_adrc ASCENDING BY date_from.
DESCRIBE TABLE lt_adrc LINES ld_len.
IF ld_len > 0.
* Incorrect sentence
LOOP AT lt_adrc
INTO ls_adrc_f
WHERE date_from = gc_first_date.
EXIT.
ENDLOOP.
ls_adrc_f-date_from = id_date - 1.
ls_adrc_f-date_to = id_date - 1.
MODIFY adrc FROM ls_adrc_f.
* Correct sentence
READ TABLE lt_adrc INDEX ld_len INTO ls_adrc_r.
ls_adrc_r-date_from = gc_first_date.
ls_adrc_r-date_to = gc_last_date.
MODIFY adrc FROM ls_adrc_r.
ENDIF.
ENDFORM. " react
SAP AG AC400 8-247
Optional Exercise F2
Write a Program for Opening and Closing FI Periods
At the conclusion of this exercise, you will be able to:
Create tables
Select records from tables and write to tables
Call function modules
Display data records
Evaluate pushbuttons pressed by the user
Requirement
In Customizing for Accounting, periods can be opened or closed for posting. The relevant
path is:
IMG Financial Accounting Financial Accounting Global Settings
Document Posting Periods
For selected variants, you want the open periods interval to be shifted by one period on a
recurring key date (such as the end of the month). Assume that today is April 1 and this is
our key date. The periods open for posting up to now are February and March. As of
today, March and April are open for posting.
System Analysis
Find out which table contains the interval for open periods. If necessary, use the ABAP
Workbench or debugger to do so.
Program Design
The following objects are required to maintain the future customer address data:
(a) A custom table containing an (optional) key date for each period interval
(b) A program with the variant of the posting periods as a parameter. When called, it
determines the corresponding key date for the entered period interval variant. If the key
date has been exceeded, the period interval is shifted by one period. Before the data is
saved, the current and new statuses are displayed.
Task
Implement the above requirement. Your custom table is Y##T001B. Your program for
maintaining the posting periods is Y##PV.
SAP AG AC400 8-248
SAP AG AC400 8-249
Solution for Optional Exercise F2
Write a Program for Opening and Closing FI Periods
Requirement
In Customizing for Accounting, periods can be opened or closed for posting. The relevant
path is:
IMG Financial Accounting Financial Accounting Global Settings
Document Posting
Periods
For selected variants, you want the open periods interval to be shifted by one period on a
recurring key date (such as the end of the month). Assume that today is April 1 and this is
our key date. The periods open for posting up to now are February and March. As of
today, March and April are open for posting.
System Analysis
Find out which table contains the interval for open periods. If necessary, use the ABAP
Workbench or debugger to do so.
For example, call the transaction for maintaining the open periods:
IMG Financial Accounting Financial Accounting Global Settings Document
Posting Periods Open and Close Posting Periods
Select the first variant ("0001"). Press F1. Choose the "Technical Information"
pushbutton. The referenced table is "V_T001B" (this is actually a table view). You can
use the Data Dictionary (SE11) to take a look at this view. The table referenced in view
V_T001B is T001B. The entries in table T001B (which you can view with SE16) are
those that are proposed for maintenance in Customizing for open periods.
Program Design
The following objects are required to maintain the future customer address data:
(a) A custom table containing an (optional) key date for each period interval
(b) A program with the variant of the posting periods as a parameter. When called, it
determines the corresponding key date for the entered period interval variant. If the key
date has been exceeded, the period interval is shifted by one period. Before the data is
saved, the current and new statuses are displayed.
Task
Implement the above requirement. Your custom table is Y##T001B. Your program for
maintaining the posting periods is Y##PV.
SAP AG AC400 8-250
For more information on how to create a program and tables, refer to the solution for the
task "Write a Program for Maintaining Customer Address Data".
*&---------------------------------------------------------------------*
*& Report AC400PV
*&
*&---------------------------------------------------------------------*
* The custom table ac400t001b referenced in the report is
* activated for maintenance and belongs to delivery class c.
* The technical settings are data type APPL2 and
* size category 0.
* The table has the following structure:
* Field Key Data element Data type Length
* Mandt x Mandt
* Rrcty x Rrcty
* Opvar x Opvar
* Mkoar x Mkoar
* Key date Numc 2
* Status 1000 referenced in the report uses the functions
* of the function keys:
* SAVE for save
* ENTR for continue
REPORT ac400pv.
* Types
TYPES: ys_t001b TYPE t001b.
TYPES: yt_t001b TYPE TABLE OF ys_t001b.
TYPES: ys_ac400t001b TYPE ac400t001b.
TYPES: yt_ac400t001b TYPE TABLE OF ys_ac400t001b.
* Parameters
PARAMETERS: p_opvar TYPE opvar OBLIGATORY.
* Data
DATA: ls_t001 TYPE t001.
DATA: ls_t001b_old TYPE ys_t001b.
DATA: ls_t001b_new TYPE ys_t001b.
DATA: lt_t001b_old TYPE yt_t001b.
DATA: lt_t001b_new TYPE yt_t001b.
DATA: ls_ac400t001b TYPE ys_ac400t001b.
DATA: lt_ac400t001b TYPE yt_ac400t001b.
DATA: ld_result TYPE c.
DATA: ld_day_found TYPE c.
* Set status
SET PF-STATUS '1000'.
* Load T001b with the open periods for selected variant
PERFORM load_t001b
USING p_opvar
CHANGING lt_t001b_old.
SAP AG AC400 8-251
* Load ac400t001b with the key dates for selected variant
PERFORM load_ac400t001b
USING p_opvar
CHANGING lt_ac400t001b.
* Load Periv from reference company code for variant
PERFORM load_periv
USING p_opvar
CHANGING ls_t001.
* Edit the records for the variant
LOOP AT lt_t001b_old
INTO ls_t001b_old.
* Restrict table ac400t001b depending on t001b record
PERFORM get_day
USING lt_ac400t001b
ls_t001b_old
CHANGING ls_ac400t001b
ld_day_found.
* Depending on key date maintenance
CASE ld_day_found.
* Key date maintained
WHEN 'Y'.
* Key date reached?
PERFORM check_day
USING ls_t001
ls_ac400t001b
ls_t001b_old
CHANGING ld_result.
* Branch according to ld_result
CASE ld_result.
* Key date reached => maintain periods
WHEN 'Y'.
* Calculate Customizing
PERFORM calc_t001b
USING ls_t001
ls_t001b_old
CHANGING ls_t001b_new.
* Display Customizing
PERFORM show_t001b
USING ls_t001b_old
ls_t001b_new.
APPEND ls_t001b_new TO lt_t001b_new.
SAP AG AC400 8-252
* Key date NOT reached
WHEN 'N'.
* Undefined
WHEN OTHERS.
ENDCASE.
* Key date not maintained
WHEN OTHERS.
"nothing to do
ENDCASE.
ENDLOOP.
* at user-command
AT USER-COMMAND.
PERFORM do_ucomm
USING sy-ucomm
lt_t001b_new.
*&---------------------------------------------------------------------*
*& Form load_t001b
*&---------------------------------------------------------------------*
FORM load_t001b
USING id_opvar TYPE opvar
CHANGING et_t001b TYPE yt_t001b.
* Clear output
CLEAR et_t001b.
* data
DATA: ld_empty_bkont TYPE bkont_001b.
* select
SELECT *
FROM t001b
* INTO es_t001b
INTO TABLE et_t001b
WHERE rrcty = '0'
AND bukrs = id_opvar.
* AND mkoar = '+'
* AND bkont = ld_empty_bkont.
ENDFORM. " load_t001b
*&---------------------------------------------------------------------*
*& Form load_ac400t001b
*&---------------------------------------------------------------------*
FORM load_ac400t001b
USING id_opvar TYPE opvar
CHANGING et_ac400t001b TYPE yt_ac400t001b.
* Clear output
SAP AG AC400 8-253
CLEAR et_ac400t001b[].
* Select
SELECT *
FROM ac400t001b
INTO TABLE et_ac400t001b
WHERE opvar = id_opvar
AND rrcty = '0'.
ENDFORM. " load_ac400t001b
*&---------------------------------------------------------------------*
*& Form load_periv
*&---------------------------------------------------------------------*
FORM load_periv
USING id_opvar TYPE opvar
CHANGING es_t001 TYPE t001.
* Clear output
CLEAR es_t001.
* get priv
SELECT *
FROM t001
INTO es_t001
WHERE opvar = id_opvar.
EXIT.
ENDSELECT.
ENDFORM. " load_periv
*&---------------------------------------------------------------------*
*& Form get_day
*&---------------------------------------------------------------------*
FORM get_day
USING it_ac400t001b TYPE yt_ac400t001b
is_t001b TYPE ys_t001b
CHANGING es_ac400t001b TYPE ys_ac400t001b
ed_day_found TYPE c.
* Clear output
CLEAR es_ac400t001b.
ed_day_found = 'N'.
* Get sentence
LOOP AT it_ac400t001b
INTO es_ac400t001b
WHERE opvar = is_t001b-bukrs
AND mkoar = is_t001b-mkoar
AND rrcty = is_t001b-rrcty.
ed_day_found = 'Y'.
ENDLOOP.
SAP AG AC400 8-254
ENDFORM. " get_day
*&---------------------------------------------------------------------*
*& Form check_day
*&---------------------------------------------------------------------*
FORM check_day
USING is_t001 TYPE t001
is_ac400t001b TYPE ys_ac400t001b
is_t001b TYPE ys_t001b
CHANGING ed_result TYPE c.
* Clear output
CLEAR ed_result.
* data
DATA: ld_systemday TYPE n LENGTH 2.
DATA: ld_actbuper TYPE poper.
DATA: ld_actgjahr TYPE bdatj.
DATA: ld_check TYPE i.
* Determine current date
ld_systemday = sy-datum+6(2).
* Get current period
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = sy-datum
i_periv = is_t001-periv
IMPORTING
e_buper = ld_actbuper
e_gjahr = ld_actgjahr.
* 1.) Check whether key date exceeded
IF ld_systemday >= is_ac400t001b-stichtag.
ld_result = ld_result + 1.
ENDIF.
* 2.) Check whether set period < current period
IF is_t001b-tope1 < ld_actbuper
AND is_t001b-toye1 = ld_actgjahr.
ld_result = ld_result + 1.
* 3.) Check whether set year < today
ELSEIF is_t001b-toye1 < ld_actgjahr.
ld_result = ld_result + 1.
ENDIF.
IF ld_result = 2.
ed_result = 'Y'.
ELSE.
ed_result = 'N'.
ENDIF.
ENDFORM. " check_day
SAP AG AC400 8-255
*&---------------------------------------------------------------------*
*& Form calc_t001b
*&---------------------------------------------------------------------*
FORM calc_t001b
USING is_t001 TYPE t001
is_t001b_old TYPE ys_t001b
CHANGING es_t001b_new TYPE ys_t001b.
* set output
es_t001b_new = is_t001b_old.
* Define new start period
CALL FUNCTION 'CKML_F_GET_NEXT_PERIOD'
EXPORTING
input_period = is_t001b_old-frpe1
input_year = is_t001b_old-frye1
input_periv = is_t001-periv
IMPORTING
next_period = es_t001b_new-frpe1
next_year = es_t001b_new-frye1.
* Define new target period
CALL FUNCTION 'CKML_F_GET_NEXT_PERIOD'
EXPORTING
input_period = is_t001b_old-tope1
input_year = is_t001b_old-toye1
input_periv = is_t001-periv
IMPORTING
next_period = es_t001b_new-tope1
next_year = es_t001b_new-toye1.
ENDFORM. " calc_t001b
*&---------------------------------------------------------------------*
*& Form show_t001b
*&---------------------------------------------------------------------*
FORM show_t001b
USING is_t001b_old TYPE ys_t001b
is_t001b_new TYPE ys_t001b.
WRITE:/ is_t001b_old-mkoar.
* Output first line with current status
WRITE:/ text-001, "Current open periods
is_t001b_old-frpe1,
is_t001b_old-frye1,
'-',
is_t001b_old-tope1,
is_t001b_old-toye1.
* Output second line with new status
WRITE:/ text-002, "Open periods from now on
is_t001b_new-frpe1,
SAP AG AC400 8-256
is_t001b_new-frye1,
'-',
is_t001b_new-tope1,
is_t001b_new-toye1.
WRITE:/.
ENDFORM. " show_t001b
*&---------------------------------------------------------------------*
*& Form do_ucomm
*&---------------------------------------------------------------------*
FORM do_ucomm
USING id_ucomm LIKE sy-ucomm
it_t001b TYPE yt_t001b.
CASE id_ucomm.
WHEN 'ENTR'.
"nothing to do.
WHEN 'SAVE'.
PERFORM save
USING it_t001b.
LEAVE SCREEN.
WHEN OTHERS.
LEAVE SCREEN.
ENDCASE.
ENDFORM. " do_ucomm
*&---------------------------------------------------------------------*
*& Form save
*&---------------------------------------------------------------------*
FORM save
USING it_t001b TYPE yt_t001b.
UPDATE t001b FROM TABLE it_t001b.
ENDFORM. " save
SAP AG AC400 8-257
Optional Exercise F3
Program a Report for Master Data Groups in Cost
Accounting
At the conclusion of this exercise, you will be able to:
Select records from tables and display them with the ALV
Use custom containers
Use the PBO and PAI dialog programming events to modify your user
interface
Define and evaluate required entry fields
Define a transaction for calling your report
Requirement
In Cost Accounting, you can group cost centers, cost elements, internal orders, and so on.
You want to program a report that lists these groups. The report should display both the
selection parameters and the results list on one screen. The group type (cost center, cost
element, and so on) and also the name of the object should be available as selection
parameters. The group type should be a required entry. If only the type is entered, all
groups of this type should be listed. The second parameter can be used to filter out a
specific element of this type. Depending on the selected type, the description of the field
should change for positioning purposes:
Initial call:
Set class ___________
Set ID ____________
Results list empty
After 0102 has been entered as the set class, the screen should change to:
Set class 0102
Cost element group ____________
Results list contains all cost element groups
System Analysis
Found out which table stores the master data groups. If necessary, use the ABAP
Workbench or debugger to do so.
Task
Implement the above requirement. Your program Y##SET is part of your local objects.
SAP AG AC400 8-258
SAP AG AC400 8-259
Solution for Optional Exercise F3
Program a Report for Master Data Groups in Cost
Accounting
Requirement
In Cost Accounting, you can group cost centers, cost elements, internal orders, and so on.
You want to program a report that lists these groups. The report should display both the
selection parameters and the results list on one screen. The group type (cost center, cost
element, and so on) and also the name of the object should be available as selection
parameters. The group type should be a required entry. If only the type is entered, all
groups of this type should be listed. The second parameter can be used to filter out a
specific element of this type. Depending on the selected type, the description of the field
should change for positioning purposes:
Initial call:
Set class ___________
Set ID ____________
Results list empty
After 0102 has been entered as the set class, the screen should change to:
Set class 0102
Cost element group ____________
Results list contains all cost element groups
Finally, the program should be executable via a transaction.
System Analysis
Found out which table stores the master data groups. If necessary, use the ABAP
Workbench or debugger to do so.
Use the transaction, for example, to display the cost element groups (KAH1). After you
have entered the cost element group OAL on the initial screen, use the /h command to
activate the debugger before you release the data. In debugger mode, set a breakpoint for
the "SELECT" command to analyze the further table accesses. Check the tables at which
the debugger stops by listing their entries, for example. The table containing the cost
element groups must be included in the accesses.
Task
Implement the above requirement. Your program Y##SET is part of your local objects.
Your transaction is Y##SET and is also defined locally.
SAP AG AC400 8-260
Instructions on how to use the Program Editor and define screens are provided in the
exercise on maintaining customer address data.
Once you have created the program (see template below), define a transaction. You can
create transactions in the same way as programs using the Object Navigator (SE80).
When you define the transaction Y##Set, select "Program and Selection Screen (Report
Transaction)" as the initial object. Enter your program Y##SET with selection screen
"1000".
*&---------------------------------------------------------------------*
*& Report AC400SET
*&
*&---------------------------------------------------------------------*
* Screen 1000 referenced in the report has the following settings
*Properties
*Maintenance 200 240
*
*Element list
*Name Type Row Column Def.L. Vis.L. Hght Scrollable Format
*SETHEADER-SETCLASS Text 1 1 22 22 1
*SETHEADER-SETCLASS I/O 1 26 4 4 1 CHAR
*GD_SETCLSTEXT I/O 2 1 22 22 1 CHAR
*SETHEADER-SETNAME I/O 2 26 24 24 1 CHAR
*ALV CuCtr 4 1 240 240 197
*
* Element list (continued)
*Name Inp. Outp. Outp Only. Dict Fld
*SETHEADER-SETCLASS x
*SETHEADER-SETCLASS x x x
*GD_SETCLSTEXT x x
*SETHEADER-SETNAME x x x
*ALV
*
* Element list (special attributes and display attributes)
*Name Input Two-dimensional As desc. left
*SETHEADER-SETCLASS x
*SETHEADER-SETCLASS O obl.
*GD_SETCLSTEXT N n. poss. x
*SETHEADER-SETNAME poss.
*ALV
*
*Flow logic
*process before output.
*
** Set status
* module status_1000.
*
** Adjust field name and list
* module adjust_window.
**
*process after input.
** Call following module at "CANC"
SAP AG AC400 8-261
* module user_command_1000 at exit-command.
*
** Also with all other commands
* module user_command_1000.
* Status 1000 has the following properties
* Function keys
* Green arrow BACK
* Yellow arrow EXIT
* Red cross CANC (defined as exit command)
* Title 1000 is "Master Data Groups"
REPORT ac400set.
*Referenced tables
TABLES: setheader.
*Types for master data groups
TYPES: ys_setheader TYPE setheader.
TYPES: yt_setheader TYPE TABLE OF ys_setheader.
*Data declaration.
DATA: gt_outtab TYPE yt_setheader.
DATA: gd_setclstext TYPE setclstext.
DATA: go_container TYPE REF TO cl_gui_custom_container.
DATA: go_alv TYPE REF TO cl_gui_alv_grid.
*Data instantiation
CREATE OBJECT go_container
EXPORTING repid = sy-repid
dynnr = '1000'
container_name = 'ALV'.
CREATE OBJECT go_alv
EXPORTING i_parent = go_container.
*Call dialog box
CALL SCREEN 1000.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1000 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_1000 INPUT.
* Evaluation of pushbutton pressed by user
CASE sy-ucomm.
* Other or undefined
WHEN 'ENTR'
OR ' '.
PERFORM set_selection_status
USING setheader
CHANGING gt_outtab.
SAP AG AC400 8-262
* Other commands
WHEN OTHERS.
* Exit the transaction
SET SCREEN 0.
LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_1000 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_1000 OUTPUT.
SET PF-STATUS '1000'.
SET TITLEBAR '1000'.
ENDMODULE. " STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
*& Form set_selection_status
*&---------------------------------------------------------------------*
* This routine determines the status of the selection parameters.
* Possible statuses:
* UNDEF no selection parameters provided
* IDENT already selected with selection parameter
* FIRST first selection call
* NEW further selection call with new parameters
FORM set_selection_status
USING is_setheader TYPE setheader
CHANGING ct_outtab TYPE yt_setheader.
* data
DATA: ls_empty_setheader TYPE ys_setheader.
STATICS: ls_old_setheader TYPE ys_setheader.
DATA: ld_status TYPE string.
* Evaluate entered parameters and set status
CASE is_setheader.
* Undefined/empty parameters
WHEN ls_empty_setheader.
ld_status = 'UNDEF'.
* Unchanged parameters
WHEN ls_old_setheader.
ld_status = 'IDENT'.
* Selection parameters not used
WHEN OTHERS.
* First time
IF ls_old_setheader = ls_empty_setheader.
SAP AG AC400 8-263
ld_status = 'FIRST'.
* Change
ELSE.
ld_status = 'NEW'.
ENDIF.
* get data
PERFORM get_data
USING is_setheader
CHANGING ct_outtab.
* Update ls_old_setheader
ls_old_setheader = is_setheader.
ENDCASE.
* Remember status
PERFORM remind_status
USING 'SET'
CHANGING ld_status.
ENDFORM. " set_selection_status
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data
USING is_setheader TYPE ys_setheader
CHANGING et_outtab TYPE yt_setheader.
* Clear output
CLEAR et_outtab[].
* data
DATA: ld_empty_setname LIKE setheader-setname.
* Select according to set ID
CASE is_setheader-setname.
* All objects
WHEN ld_empty_setname.
SELECT *
FROM setheader
INTO TABLE et_outtab
WHERE setclass = is_setheader-setclass.
* One object
WHEN OTHERS.
SELECT *
FROM setheader
INTO TABLE et_outtab
WHERE setname = is_setheader-setname
AND setclass = is_setheader-setclass.
ENDCASE.
SAP AG AC400 8-264
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Module adjust_window OUTPUT
*&---------------------------------------------------------------------*
MODULE adjust_window OUTPUT.
PERFORM adjust_window
USING gt_outtab
setheader
CHANGING gd_setclstext.
ENDMODULE. " adjust_window OUTPUT
*&---------------------------------------------------------------------*
*& Form adjust_window
*&---------------------------------------------------------------------*
FORM adjust_window
USING it_outtab TYPE yt_setheader
is_setheader TYPE ys_setheader
CHANGING cd_setclstext TYPE setclstext.
* data
DATA: ld_status TYPE string.
* set ld_status
PERFORM remind_status
USING 'GET'
CHANGING ld_status.
* Evaluate status
CASE ld_status.
* Undefined
WHEN 'UNDEF'.
* Maintain cd-setclstext
PERFORM get_setclstext
USING is_setheader
CHANGING cd_setclstext.
* Existing selection
WHEN 'IDENT'.
"nothing to do
* First selection
WHEN 'FIRST'.
* Generate ALV
CALL METHOD go_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SETHEADER'
CHANGING
it_outtab = gt_outtab.
* Maintain cd_setclstext
PERFORM get_setclstext
USING is_setheader
SAP AG AC400 8-265
CHANGING cd_setclstext.
* New other selection
WHEN 'NEW'.
CALL METHOD go_alv->refresh_table_display.
* Maintain cd_setclstext
PERFORM get_setclstext
USING is_setheader
CHANGING cd_setclstext.
WHEN OTHERS.
* Maintain cd_setclstext
PERFORM get_setclstext
USING is_setheader
CHANGING cd_setclstext.
ENDCASE.
ENDFORM. "adjust_window
*&---------------------------------------------------------------------*
*& Form remind_status
*&---------------------------------------------------------------------*
* This routine stores the status of selection parameters and
* returns them on request.
* PBO and PAI communicate via this routine
* The following actions are possible:
* SET: Remember status
* GET: Return status
FORM remind_status
USING id_action TYPE string
CHANGING cd_status TYPE string.
* data
STATICS: ld_status TYPE string.
* Evaluate action
CASE id_action.
* Set status
WHEN 'SET'.
ld_status = cd_status.
* Read status
WHEN 'GET'.
cd_status = ld_status.
ENDCASE.
ENDFORM. "remind_status
*&---------------------------------------------------------------------*
*& Form get_setclstext
*&---------------------------------------------------------------------*
FORM get_setclstext
SAP AG AC400 8-266
USING is_setheader TYPE ys_setheader
CHANGING ed_setclstext TYPE setclstext.
* Clear output
CLEAR ed_setclstext.
* data
DATA: ls_setclst TYPE setclst.
DATA: ld_empty_setclass TYPE setclst.
DATA: ls_dd04v_wa TYPE dd04v.
* Processing according to is_setheader-setclass.
CASE is_setheader-setclass.
* Class not set
WHEN ld_empty_setclass.
CALL FUNCTION 'DDIF_DTEL_GET'
EXPORTING
name = 'SETNAMENEW'
langu = sy-langu
IMPORTING
dd04v_wa = ls_dd04v_wa.
* set output
ed_setclstext = ls_dd04v_wa-ddtext.
* Class set
WHEN OTHERS.
* select
SELECT SINGLE *
FROM setclst
INTO ls_setclst
WHERE langu = sy-langu
AND setclass = is_setheader-setclass.
* set output
ed_setclstext = ls_setclst-descript.
ENDCASE.
ENDFORM. " get_setclstext