Anda di halaman 1dari 31

In this exercise we see how to use table controls in screen painter.

We will look into two situations :


1. We will create a screen and use the table control object in that screen to display the data.
2. We will design two screens First screen will have two input fields and the second screen
will display the data in the table control object.
First create a program with the name convention SAPMZ<Intials> E.g. SAPMZTC7.
Click on the Save icon and Come out by clicking the Back icon.
Now create a screen
Click on the Screen Radio button and enter the screen number in the corresponding field.
Click on the Enter icon.
Enter a meaningful description for the screen and also select the type of screens (in this case
Normal) you are going to design.
Click on the SAVE icon to save the entries.
Click the Back icon to come back to the initial screen.
Select the program name and click on the Change icon.
Double click on Include MZ<INITIAL>TOP.
Declare the global variables in this include section.
Click on SAVE icon to save your code.
Click the back icon twice to come out.
Select the screen (in our case 1000) and click on Change icon or double click on it
Click on the FULLSCREEN button on the application toolbar to design the screen.
You can get the fields / data from dictionary table as well as the internal table. In our example we
will get the fields / data from the internal table.
Click on the Dict/Prog fields button on the application toolbar to include the fields on the screen
from the dictionary tables or internal tables declared in the program.
Enter the internal table name or the table name and click on the Get from program button
Select the fields whose data you want to display and click on the Enter icon.
Drag the selected fields on to the screen.
Add the GUI objects that you would want on the screen.
We will create this screen with a Text Object and a Table Control object. So click on the
corresponding icon on the object bar on the right and drag and place the object on the screen.
Now drag the fields one by one and place them in the Table control object.
Now you need to put the labels for each of the fields that you included in the Table Control
object.
Select the TEXT button on the toolbar and place it on the screen.
Now drag these text objects and place them over their corresponding fields.
Now you need to assign a table control name to the table control object. The name can be given
in the attribute of the object and also in the program.
Select the Table control object and click on the Attributes button on the application toolbar.
Here we have assigned the name TAB_CNTRL to the table control. We have to declare this name
in the controls statement in the data declaration section of your main program.
Now click the SAVE icon.
Now get into the flow logic of the screen.
Follow the menu path Goto Flow logic
Double click on MODULE STATUS_<SCREEN NUMBER>.
Click the Enter icon till you get into the ABAP/4 Editor (Module Pool)
Now write the code to retrieve the data and populate the internal table (if you have declared an
internal table).
Click on the Save icon to save the code.
Click on the BACK icon to come out.
Remove the comment mark on MODULE STATUS_<SCREEN NUMBER>line.
Click on the Save icon to save the code.
And write the following code in on screen.
Under process before output.
loop at itabna with control tab_cntrl cursor tab_cntrl-current_line.
endloop.
Note : The above code will work only with internal table.
Under process after input.
loop.
endloop.
Click on the Field List button and include the field FCODE in the field list.
Click on the SAVE icon to save the code.
Click on the Generate icon to generate the code.
Click on the Back icon to come out to the initial screen.
Now create a transaction code for your dialog program.
Select the program and click on the create icon
Select the Transaction radiobutton and enter a four-character code (eg. ZTC7) and click on the
create icon.
Select Dialog transaction radiobutton and click on the Enter icon
Enter the information in the fields and click the Save icon.
Click on the BACK icon to come out to the initial screen.
Now select the transaction code and execute it.
You should get output in the table control object.
Now we will do another example by including one more screen which we will use to select
the data i.e. we will do a selective display of data.
Select the program (SAPMZTC7) and create another screen with input fields.
Select the program and click on the create icon
Select the Screen radiobutton and enter the screen number (in our example 900) in the
corresponding field.
Click on the Create icon.
Enter the meaningful description for the screen. And also select screen type (in this case Normal).
Click on the Save icon.
Click on the FULLSCREEN button on the application toolbar to design the input screen.
Place the input fields from tables or the internal tables on the screen.
Click on the Dict/Prog fields button the application tool bar
Enter the table name (Eg. TABNA) and click on the Get From Dict. Button.
You will get the list of fields of the table TABNA.
Select the fields, which will form the select criteria and drag them on the screen.
Now follow the menu path Goto Flow Logic to write the flow logic for the screen.
Double click on MODULE USER_COMMAND_<SCREEN NUMBER> (in our example
MODULE USER_COMMAND_0900).
Get into the ABAP/4 editor.
Enter the following code
select * from tabna into itabna where id =tabna-id and country =tabna-country.
if tabna-id ne ' ' and tabna-country ne ' '.
call screen '901'.
endif.
Click on the Save icon.
Click on the Back icon to come out.
Remove comment sign on the MODULE USER_COMMAND_<SCREEN NUMBER> (Eg.
MODULE USER_COMMAND_0900) line.
And Save and generate the code.
Click on the Back icon to come out.
Now let us create another screen with table control object.
Follow the usual procedure to create the screen.
Create this screen as MODAL DIALOG BOX type.
Click on the Save icon.
Click on the FULLSCREEN button to design the screen.
Place the required objects on the screen and also select the fields for the output from the
dictionary table or the internal table.
Now you need to give a name to the table control.
Select the table control and click on the Attribute button on the toolbar.
Also place a command button on the screen and give a Function Code in the FctCode field of the
button.
Now you need to write the flow logic for this screen.
Follow the menu path Goto Flow Logic
Double click on the MODULE USER_COMMAND_<SCREEN NUMBER>(Eg. MODULE
USER_COMMAND_0901).
And get into the ABAP/4 editor.
And write the following code
CASE FCODE.
WHEN 'BACK'.
SET SCREEN 900.
ENDCASE.
As part of the module user_command_0901 input section.
Save the code.
Remove the comment on line containing MODULE USER_COMMAND_0901.
Now once again Save the code.
Click on the Field List button on the application toolbar and include the field FCODE in the fields
list.
Click on Save and Generate icons.
Click on the BACK icon to come back to the initial screen.
Now create a transaction code in the usual manner for this example.
Enter the necessary information and click on the Save icon.
Click on the Back icon to come back to the initial screen.
Now select the transaction code that you created and execute it.
You will get the first screen i.e. screen 900.
Enter the data for selection and press on the Enter key.
Now if you click on the BACK button on screen. You should get back to screen 900.

Anda mungkin juga menyukai