Resue Components in SAP ABAP Lesson Ten

The R/3 System offers several techniques that you can use to make business logic available for reuse.

Function modules: can be called from any ABAP Program. Parameters are also passed to the interface. Function modules that belong together are combined to form function groups. Program logic and user dialogs can be encapsulated in function modules.

Objects: You can use the compatible extension "ABAP objects" to create objects at runtime, with reference to central classes.

BAPIs are methods of business objects, which are made available using the Business Object Repository (BOR).

Logical databases are data collection programs that can be coupled with executable programs. In a logical database, the data are transferred using logical hierarchy structures. Logical databases also make selection screens available and contain authorization checks.

A function group is an ABAP program with type F, which is a program created exclusively for containing function modules. Function modules are modular units with interfaces that can be called from any ABAP Program. Function modules that operate on the same objects are combined to form function groups.

Each function group can contain:

Data objects , which can be seen and changed by all the function modules in the group. These data objects remain active as long as the function group remains active.

Subroutines, which can be called by any of the function modules in the group.

Screens , which can be called by any of the function modules in the group.

Function modules are modular units with interfaces. The interface can contain the following elements:

Import parameters are parameters passed to the function module. In general, these are assigned standard ABAP Dictionary types. Import parameters can also be optional.

Export parameters are passed from the function module to the calling program. Export parameters are always optional and for that reason do not need to be accepted by the calling program.

Changing Parameters are passed to the function module and can be changed by it. The result is returned to the calling program after the function module has executed. Changing parameters can be optional.

Exceptions are used to intercept errors. If an error triggers an exception in a function module, the function module stops. You can assign exceptions to numbers in the calling program, which sets the system field SY-SUBRC to that value. This return code can then be handled by the program.

Each function module can contain local data objects and access global data objects belonging to its function group. All the subroutines and screens in the function group can be called by the function module.

The global data in the function group remain after the function module has been called. The function group remains active for as long as the calling program is active. Thus, if a function module is called that writes values to the global data, other function modules in the same function group can access this data when they are called by the program.

In many programs a standard dialog box appears after the user has chosen Cancel. This dialog box always contains the sentence: "Data will be lost." The two lines following it are context-specific, as is the title. The user can choose from one of two options - "Yes" or "No."

This dialog box is encapsulated in a function module.You could avoid programming this dialog box, if you could find an existing function module with the following properties:

Import parameters for the title and the two variable text lines

An export parameter to record whether the user has chosen "Yes" or "No"

The ability to call a screen in the function group that displays the two variable text lines and the title, and contains the "Yes" and "No" buttons.

Scenario: You are creating a program in the Object Navigator and leave the Attributes screen. You want to know if it is encapsulated in reusable form.

1. First method: In the Debugger, set a breakpoint at CALL SCREEN. If successful, the actual processing block (subroutine, function module or event block) will be listed under ' CALLS' in the Debugging mode. You can then examine the call and the parameters passed to the interface.

2. Second method: In the Debugger, set a breakpoint at CALL FUNCTION. If successful, the actual processing block (subroutine, function module or event block) will be listed under ' CALLS' in the Debugging mode. You can then examine the call and the parameters passed to the interface.

3. Third method: Click a text field in the standatrd dialog box, then press F1 and choose Technical info. Navigate to the screen and display a where-used list for programs, then look at the function modules that use it.

4. Fourth method: In the Save dialog box, display the F1 help and then Technical info. Navigate to the screen, examine the flow logic and its modules.

5. Fifth method: In the component hierarchy, mark the component that you are interested in (in this case, Basis Services), select it, navigate to the Repository Information System, look under Programming -> Function Builder -> Function modules and select Only released.

Once you have found a function module, you must find out more about its interface.Non-optional parameters in the function module must be passed in the CALL FUNCTION statement. To find out how to handle the other parameters, refer to the function module documentation and the documentation on interface parameters.

If the documentation is not specific enough; or is not available in your logon language, you can analyze the source code for the function module by choosing the Source code tab.You can test function modules using the test environment. An input template allows you to specify the IMPORT parameters. The result is transferred to the EXPORT parameters and displayed.If an error occurs, the system notes which exception was triggered.

The runtime for the function module is displayed in microseconds. These values are subject to the same conditions as the runtime analysis transaction. You should therefore repeat the test several times using the same data.You can store test data in a test data directory.You can use the Function Builder test function to test function modules with table parameters.You can create test sequences.

You call function modules from ABAP programs using the CALL FUNCTION statement. The name of the function module is displayed in single quotation marks. After EXPORTING, the system assigns the parameters that are passed to the function module. After IMPORTING, the system assigns the parameters that are passed from the function module to the program.

Most function modules support additional exceptions. If so, after EXCEPTIONS, the exceptions are assigned to values that will be set in the system field sy-subrc, if a system error occurs. On the left side, the system displays the names of the interface parameters, while on the right, it displays the program's data objects.To do this, use a statement pattern in the ABAP Editor (the Pattern button), and enter the name of the function module.The system then generates an ABAP statement CALL FUNCTION '', including the interface of the function module, and inserts it in the program at the current cursor position.Fill in the actual parameters, and write the statements that will handle any exceptions that occur.

Interface parameter values are assigned explicitly by the name of the actual parameter. From the point of view of the calling program the parameters that are to be passed to the function module are exported; those passed from the function module to the program are imported. You do not have to assign an actual parameter to an optional parameter. In this case, you can delete the line containing the optional parameter.Note that - during parameter assignment - the function module parameter is always on the left and the actual parameter on the right.

Integrated software development process

Each phase in the development process (Analysis, specification, design, and implementation) is described in the same "language." Ideally, this means that changes you make to the design during implementation can be applied retrospectively to the data model.

Encapsulation (information hiding) he ability to hide the implementation of an object from other system components. The components cannot make assumptions about the internal status of the object, and do not depend on using a particular implementation to communicate with the object.

Polymorphism :In object technology, the fact that objects of different classes react differently to the same message.

Inheritance

Defines the implementation relationship between classes, such that one class (the subclass) shares the structure and behaviour that have already been defined in one or more superclasses.

Objects are central to the object-oriented approach and represent concrete or abstract entities in the real world. They are defined according to their properties, which are depicted using their internal structure and attributes (data). Object behavior is described using methods and events (functions).

Each object forms a capsule, which encompasses both its character and behavior. Objects should enable the model of a problem area to be reflected as closely as possible in the design model for its solution.

In Object-oriented programming, this is implemented such that each class is defined as an object type. Instances of this class are created at runtime - that is, the system creates objects of an object type (and thus, of the class).

An ABAP program that changes bookings using objects has the following program flow:

The program starts and the program context is loaded. Memory areas are made available for all the program's global data objects. Reference variables are also made available for each object. You can view a summary of the data objects that are made available when you run the program by expanding the Fields and Dictionary structures subtrees in the program object list. You can also navigate to the source text in which the data objects have been defined - for example, using a DATA or TABLES statement. The reference variables are defined using a DATA: TYPE REF TO . statement.

The objects are generated at runtime, as soon as the CREATE OBJECT statement is processed. In this statement, a special method called CONSTRUCTOR is called implicitly. Any parameters required by the constructor must be specified in the CREATE OBJECT statement. In this example, only the key attributes need to be passed to the statement.

As soon as the CALL METHOD statement is processed, the method is called. Unlike calling a function, when a method is called, the object in which the method is to be processed must be stated explicitly. The system specifies a reference variable pointing to the object. The reference variable name is followed by a -> and the method name.

Office Integration:The system offers a new object-oriented interface, which will help you to make use of R/3 office product functions.

Business AddIns:

An object-oriented enhancements technology, which combines the advantages of existing technologies. If Business AddIns are included in standard programs, you can enhance the program using special methods, without having to carry out a modification.

Controls:

The R/3 System allows you to create custom controls using ABAP objects. The application server is the Automation Client, which drives the custom controls (automation server) at the frontend. This task is performed by the Central Control Framework.Pilot projects are already object-oriented.This task is performed by the Central Control Framework.

The R/3 System allows you to create Custom Controls using ABAP objects. The application server is the Automation Client, which drives the custom controls (automation server) at the frontend.If Custom Controls are to be included on the frontend, then the SAPGUI acts as a container for them.Custom controls can be ActiveX Controls and JavaBeans.

The system has to use a Remote Function Call (RFC) to transfer methods for creating and using a control (ABAP OO) to the front end.In the control, you can adjust the column width by dragging, or use the 'Optimum width' function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position.

Standard functions are available in the control toolbar. The details display displays the fields in the line on which the cursor is positioned in a modal dialog box.The sort function in the ALV Control is available for as many columns as required. You can set complex sort criteria and sort columns in either ascending or descending order.You can use the 'Search' function to search for a string (generic search without *) within a selected area by line or column.

You can use the 'Sum' function to request totals for one or more numeric columns. You can use the 'Subtotal' function to structure control level lists: select the You can use the 'Subtotal' function to structure control level lists: select the columns (non-numeric columns only) that you want to use and the corresponding control lFor 'Print' and 'Download' the whole list is always processed, not just the sections displayed on the screen.You also have the option of setting display variants. Saving variants: see 'Advanced Techniques'.

An SAP Container can contain other controls (for example, SAP ALV Grid Control, Tree Control, SAP Picture Control, SAP Splitter Control, and so on). It administers these controls logically in one collection and provides a physical area for the display.Every control exists in a container. Since containers are themselves controls, they can be nested within one another. A container is its control's parent.

There are object types available in the Class Builder for administering Custom Controls and the ALV Grid Control. At runtime, the system creates two objects - one of type CL_GUI_CUSTOMER_CONTAINER and one of type CL_GUI_ALV_GRID. These objects contain the methods needed to administer the controls. You can find more information on object types (classes) and their associated methods in the Class Builder.

You can navigate to the Class Builder by entering the name of a class in the Class input field on the Object Navigator initial screen and choosing Display. The system displays a tree structure for the class you have chosen. Double-click the root node to display the Class Builder work area. Choose the Methods tab and select the method for which you want more information. Choose the Parameters button, to display more information on the interface parameters.

The CL_GUI_CUSTOM_CONTAINER contains only the CONSTRUCTOR method. When you create an object in a program using CREATE OBJECT you must pass the non-optional parameter CONTAINER_NAME. The name of the container area on the screen must be passed to this parameter.

CL_GUI_ALV_GRID contains many methods. To display an internal table of the ABAP Dictionary Structure row type, using an ALV Grid Control, you only need to know the details of three methods:

CONSTRUCTOR: The reference variable pointing to the object (with which the container control communicates) must be passed to the constructor.

The first time a table's contents are displayed using an ALV Grid Control, display is implemented using the SET_TABLE_FOR_FIRST_DISPLAY method. The internal table is passed to the parameter it_outtab. In this case, it is not enough simply to pass the non-optional parameter it_outtab. Information about the row structure must also be passed to the object. In the case of numeric fields containing a unit, the relationships between fields must be passed - either explicitly using a field list, or implicitly, provided the internal table is of the ABAP Dictionary Structure type.
In the latter case, the name of the Dictionary Structure is passed to the I_STRUCTURE_NAME parameter.

REFRESH_TABLE_DISPLAY can be called if the internal table has already been displayed using the Grid Control, and if the content of the internal table differs from that shown on the screen. In this case, the frontend control already knows the row type of the internal table and reference fields.

To reserve an area of the screen for an EnjoySAP control, open the Screen Painter and choose the Layout button.In the toolbar to the left of the editing area, choose the Custom control button. (This works similarly to the Subscreen button).

On the editing area of the screen, specify the size and position of the screen area as follows: Click the editing area where you want to place the top left corner of the custom control and hold down the mouse key. Drag the cursor down and right to where you want the bottom right corner. Once you release the mouse key, the bottom right corner is fixed in position.You can change the size and position of the area at any time by dragging and dropping the handles. Again, this area behaves similarly to a subscreen area.

Use the Resizing vertical and Resizing horizontal to specify whether or not the area of the custom control should be resized when the main screen is resized. You can also set minimum values for these attrbutes using Min. row and Min. column. You determine the maxium size of the area when you create it.The program requires two reference variables.

The first reference variable, container_r points to the object that communicates with the container control. It is typed with the global class cl_gui_custom_container.The second, grid_r points to the object that communicates with the ALV Grid control. It is typed with the global class cl_gui_alv_grid.The CREATE OBJECT creates an object at runtime. You only need to enter the reference variable, since it already has the same object type as the class.

To generate the object that communicates with the container control, you only need to include the name of the container area on the screen, provided this occurs in a PBO module of the screen on which the container area has been defined. If the CREATE OBJECT statement has been implemented in another ABAP processing block, you must include the number of the container screen and the program name.

To generate the object that communicates with the ALV grid control, you must pass the reference variable that points to the custom container object. This "tells" the object the container in which it is to be included.

To display data in an ALV grid control, you must make them available in an internal table. The system then calls the method that receives the content and structure of the internal table. The method is called set_table_for_first_display. Provided the internal table has the type ABAP Dictionary Structure, the name of the structure is passed to the i_structure_name parameter.

The method then gets the information it needs - column names, column types, and column links for currency fields - directly from the ABAP Dictionary.If only the content of the internal table changes while the program is running, the program must call the refresh_table_display method before sending the screen with the container area again.A BAPI is a point of entry to the R/3 System - that is, a point at which the R/3 System provides access to business data and processes.

Each object in the BOR can have many methods, one or more of which can be implemented as BAPIs.

BAPIs can have various functions:
Creating an object
Retrieving the attributes of an object
Changing the attributes of an object

A BAPI is an interface that can be used for various applications. For example:

Internet Application Components, which make individual R/3 functions available on the
Internet or an intranet for users with no R/3 experience.
R/3 component composition, which allows communication between the business objects of
different R/3 components (applications).
VisualBasic/JAVA/C++ - external clients (for example, alternative GUIs) that can access business data and processes directly.

You can display more information on business objects and the BAPIs that belong to them using BAPI Explorer Information. The screen is in two parts: a hierarchy area and a details window. The hierarchy area displays the component hierarchy. You can expand an application component to find out which business objects belong to it. If you expand a single business object, the system displays a sub-tree, showing you which key attributes and API methods belong to it. (API stands for Application Programming Interface).

You can display more information on business objects and the BAPIs that belong to them using BAPI Explorer Information. The screen is in two parts: a hierarchy area and a details window. The hierarchy area displays the component hierarchy. You can expand an application component to find out which business objects belong to it. If you expand a single business object, the system displays a sub-tree, showing you which key attributes and API methods belong to it. (API stands for Application Programming Interface).

Symbols are used to indicate business objects, key attributes, and BAPIs. You can display the key to these symbols using the Display Legend button.If you expand a sub-tree for a business object in the BAPI Explorer, the system displays the following:

Key attributes, which provide a unique identifier for each business object

Instance -specific methods , which are methods that are bound to the instance identified by the key attributes. The business object type FlightBooking has one instance-specific method, GetDetail (which returns a structure with booking details). Key attribute values must be passed to this method.

If you expand a substructure for a method, the system returns the names of its import and export parameters. You can obtain more detailed information on the typing of interface parameters by choosing the Tools tab, then choosing the ABAP Dictionary. BAPI interface parameters are always typed using ABAP Dictionary types.

BAPIs usually have an export parameter called RETURN. This can be a structure or internal table.The Return Parameter contains information on errors that occurred while the BAPI was being processed. There are no exceptions for BAPIs.

To display complete information on a Business object type, use the Business Object Builder tool. The system displays a tree structure for the business object type, including non-API methods.To search for a business object, use the Business Object Repository (BOR) tool. This tool displays the component hierarchy with all the business objects that belong to it. You can navigate from this tree structure to the Business Object Builder. The system displays the relevant business object automatically.BAPIs with standardized names contain standard methods. Three of the most important are listed here.

In Release 4.6 BAPIs have been implemented using function modules. You can display the function module for the BAPI you have chosen using the BAPI Explorer.

Select the BAPI in the hierarchy area.

In the detailed information display window, choose the Tools tab.

Choose Function Builder: The system displays the name of the function module.

Choose Display

If you would like to use a BAPI in an R/3 System, you can directly call the function module containing it. Note that information about any errors that occur are passed to the program using the interface parameter RETURN. BAPI function modules do not contain either exceptions or user dialogs. They exist only to encapsulate business logic .

Every BAPI contains an interface parameter, RETURN, which contains information about errors that occur. This parameter is always of an ABAP Dictionary type. This means that you must include a structure of an identical type in your program.Use logical databases to read logically consistent data from databases. Each logical database has a structure containing a hierarchy of those tables and views that are to be read.

You can attach exactly one logical database to each type 1 program. The logical database then supplies your program with entries from tables and views. This means that you only need to program the data processing statements.Every logical database is an encapsulated data collection program for frequent database access.The database access has been optimized using Open SQL.If you are working with a logical database, you do not need to program a selection screen for user entry, since this is created automatically.The system performs authorization checks according to the SAP authorization concept.

The NODES statement performs two functions:

It defines a data object (a structure) as a table work area that has the same structure as the ABAP Dictionary Structure , that is a node of the hierarchical structure of the logical database. This structure is then filled at runtime with data records that the logical database has read from the database and made available to the program.

It determines how detailed the selection screen is : The selection screen that has been defined in the logical database should contain only those key information input fields that the program needs. The NODES statement allows you to ensure only information from relevant tables is available to the selection screen.

Logical databases read according to their structure from top to bottom. The depth of data read depends on a program's GET statements. The level is determined by the deepest GET statement (from the logical database's structural view).You can include a logical database in every type 1 program using the program attributes.Each node in the logical database's hierarchy also provides you with a GET event block (in addition to the other event blocks). You can program individual record processing within these GET event blocks.

Logical databases are included in type 1 programs as program attributes. Only one logical database can be attached per program.You can tell a logical database exactly which fields you need from the database using the GET addition FIELDS. If the logical database supports this action, then it will read only those fields specified from the database.

If you need database table data for a list that is not supplied by your logical database, you can program any additional database access needed using SELECT.

RELATED POSTS

ABAP PROJECT OVER VIEW

No comments :

Post a Comment