Читайте также: |
|
You only have to call this method if the table content, which has changed in the meantime, is to be loaded for updating the display of the grid control in case the screen is processed again.
Displaying an Internal Table in ALV Grid Control on a Screen
Figure 213: Creating a Screen Element "Custom Control Area"
1. In the Graphic Layout Editor, you can define a control area on your screen.
To do so, choose the pushbutton Custom Control from the toolbar. Now select it and specify the size and position of the area on the screen 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 diagonally down to the right to where you want the bottom right corner. Once you release the mouse button, the bottom right corner is fixed in position.
Enter a new name for the screen element (here: CONTAINER_1).
Use the Resizing Vertical and Resizing Horizontal attributes to specify whether or not the area of the custom control should be resized when the main screen is resized. When you set these attributes, you can also set the minimum values for the area using the additional attributes Min. Lines and Min. Columns.
Continued on next page
2. Two reference variables are required in the ABAP program:
• A reference variable that is to point to a container instance that is yet to be created (name here: CONTAINER_R)
• A reference variable that is to point to a grid control instance that is yet to be created (name here: GRID_R)
Figure 215: Creating Instances
Continued on next page
3. You create the instances with the CREATE OBJECT statement. You should definitely have your statement generated in your source code in order to avoid typing errors and omissions. To do so, display the object list of the respective class in the navigation area of the Object Navigator, drag and drop the class name in your source code.
In the generated call, you must now insert the name of the reference variable for xxxxxxxx and supply the parameters with values. The call syntax is very similar to that of the function module. However, the parameter to be supplied with values with CREATE OBJECT are the interface parameters of the respective constructor.
It is mandatory to implement the creation of the control instances before
displaying the screen. This is frequently done in a PBO module.
You only have to instantiate the controls on a screen once. This means that this step is omitted when a screen is processed again. This is easily done by querying one of the two reference variables:
IF container_r IS INITIAL.
Figure 216: Calling Methods
4. To transfer the content of an internal table and its row description to the SAP Grid Control, call method SET_TABLE_FOR_FIRST_DISPLAY of the grid control instance. Here, you should also have the call generated by
Continued on next page
means of drag-and-drop. In the generated call, you then have to use the name of the grid control reference variable instead of xxxxxxxx and supply
the parameters with values:
• You then transfer the filled internal table to parameter IT_OUTTAB.
• Here the internal table has been typed with the transparent table SPFLI as row type. Therefore, it is sufficient to pass this name to the I_STRUCTURE_NAME parameter. The corresponding Dictionary information is then loaded automatically and transferred to the control.
If the content of the internal table changes during the program, you must call the REFRESH_TABLE_DISPLAY method in order to update the grid display before the next screen is displayed.
345 Exercise 19: Using Methods
Exercise Duration: 40 Minutes
Exercise Objectives
After completing this exercise, you will be able to:
• Display simple lists using an ALV Grid Control
Business Example
Your previous lists are to be displayed in ALV Grid Control.
System Data
System: Will be assigned Client: Will be assigned User ID: Will be assigned Password: Will be assigned
Set up instructions: No special instructions when using a standard training system
Task 1:
Prepare data and screen for control display
1. Copy the program SAPBC400RUT_ALV_GRID including all of its components to the new name ZBC400_##_ALV_GRID.
2. Get to know the program.
In the template, there is an internal table that matches the database table
SPFLI and also a screen with the number 100.
3. Fill the internal table with data records from the data table SPFLI using an array fetch.
4. Create a container control area on the screen 100 (name proposal:
CONTAINER_1).
Task 2:
Create container and control, data transfer to the control
1. Define a reference variable for each of the classes CL_GUI_CUS- TOM_CONTAINER and CL_GUI_ALV_GRID.
2. Implement the control or container instance creation at the event PROCESS BEFORE OUTPUT of screen 100. Only supply the required parameters.
Continued on next page
3. At the point PROCESS BEFORE OUTPUT, call method SET_TABLE_FOR_FIRST_DISPLAY to transfer the data to the grid control. Supply the parameter I_STRUCTURE_NAME (row type of the internal table) with the name of a suitable Dictionary type and the parameter IT_OUTTAB with the actual internal table.
4. Ensure that the creation of the instances as well as the method call only happens when the screen is processed for the first time.
Solution 19: Using Methods
Task 1:
Prepare data and screen for control display
1. Copy the program SAPBC400RUT_ALV_GRID including all of its components to the new name ZBC400_##_ALV_GRID.
a) Carry out this step as usual.
2. Get to know the program.
In the template, there is an internal table that matches the database table
SPFLI and also a screen with the number 100. a) Carry out this step as usual.
3. Fill the internal table with data records from the data table SPFLI using an array fetch.
a) See source code excerpt in the model solution.
4. Create a container control area on the screen 100 (name proposal:
CONTAINER_1).
a) Carry out this step as described in the training material.
Task 2:
Create container and control, data transfer to the control
1. Define a reference variable for each of the classes CL_GUI_CUS- TOM_CONTAINER and CL_GUI_ALV_GRID.
a) See source code excerpt in the model solution.
2. Implement the control or container instance creation at the event PROCESS BEFORE OUTPUT of screen 100. Only supply the required parameters.
a) See source code excerpt in the model solution.
3. At the point PROCESS BEFORE OUTPUT, call method SET_TABLE_FOR_FIRST_DISPLAY to transfer the data to the grid control. Supply the parameter I_STRUCTURE_NAME (row type of the internal table) with the name of a suitable Dictionary type and the parameter IT_OUTTAB with the actual internal table.
a) See source code excerpt in the model solution.
4. Ensure that the creation of the instances as well as the method call only happens when the screen is processed for the first time.
a) See source code excerpt in the model solution.
Continued on next page
Result
Source code excerpt SAPBC400RUS_ALV_GRID
REPORT sapbc400rus_alv_grid.
...
DATA:
Дата добавления: 2015-11-16; просмотров: 345 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
DATAreference_name TYPE REF TOclass_name. | | | container_r TYPE REF TO CL_GUI_CUSTOM_CONTAINER, grid_r TYPE REF TO CL_GUI_ALV_GRID. |