You are on page 1of 75

Demo on using Table Control

By Raghav Vakada, MouriTech Solutions


*&---------------------------------------------------------------------*
*& Report Z_DB_TABLECONTROL
*
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*
REPORT Z_DB_TABLECONTROL.
TABLES: MARA.
CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.
TYPES: BEGIN OF ST_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
LAEDA TYPE MARA-LAEDA,
END OF ST_MARA.
DATA: IT_ST TYPE TABLE OF ST_MARA,
WA_ST TYPE ST_MARA,
IT_MARA TYPE MARA,
WA_MARA TYPE MARA,
OK_CODE LIKE SY-UCOMM.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*&
Module V1 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE V1 INPUT.
CASE OK_CODE.
WHEN 'SAVE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
INSERT INTO MARA VALUES WA_MARA.
WHEN 'DELETE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
DELETE MARA FROM WA_MARA.
WHEN 'MODIFY'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
MODIFY MARA FROM WA_MARA.
ENDCASE.
ENDMODULE.
" V1 INPUT

*&---------------------------------------------------------------------*
*&
Module EXIT INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
IF OK_CODE = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
" EXIT INPUT
Create a screen by number 130 and provide the following attributes:

LAYOUT:

ELEMENT LIST:

FLOW LOGIC.

EXECUTE:

Display Logo on Screen


By Suresh Kumar Parvathaneni
You can display logo(s) on your screen using the custom control function. A custom control is an
area on the screen, created using the screen painter. Custom controls are used to embed
controls. Container controls are instances of special global classes from the SAP Control
Framework. The global class for custom controls is called CL_GUI_CUSTOM_CONTAINER. To
link a custom control to a container control, pass the custom control name to the
CONTAINER_NAME parameter of the container control constructor when you instantiate it. The
following is a sample program to demonstrate the logo display using the custom control. This
program was written in SAP4.6C. Design a screen with the custom control, by name
PICTURE_CONTAINER. It has the following flow logic:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
The GUI status SCREEN100 has the functions BACK, EXIT, and CANCEL (all with type E).

Code
REPORT ZSURESH_TEST .
* Type declarations.....................
TYPES pict_line(256) TYPE c.
* data declarations......................
DATA :init,
container TYPE REF TO cl_gui_custom_container,
editor

TYPE REF TO cl_gui_textedit,

picture TYPE REF TO cl_gui_picture,


pict_tab TYPE TABLE OF pict_line,
url(255) TYPE c.
CALL SCREEN 100.
* Dialog modules......................................
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN100'.

IF init is initial.
init = 'X'.
CREATE OBJECT:
container EXPORTING container_name = 'PICTURE_CONTAINER',
picture

EXPORTING parent = container.

ENDIF.
IMPORT pict_tab = pict_tab FROM DATABASE abtree(pi) ID 'ENJOY'.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type

= 'IMAGE'

subtype = 'GIF'
TABLES
data

= pict_tab

CHANGING
url

= url.

CALL METHOD picture->load_picture_from_url EXPORTING url = url.


CALL METHOD picture->set_display_mode
EXPORTING display_mode = picture->display_mode_fit_center.
ENDMODULE.
MODULE cancel INPUT.
LEAVE TO SCREEN 0.
ENDMODULE.

Working with Check box (Module pool programming)


By Vikram Chellappa, Mouri Tech Solutions

Scenario: We would design a screen with an input field for customer number and three
check boxes for Name, City and Address. Upon entering the customer number and
selecting any of the check boxes, the corresponding data should be displayed
1) Go to Tcode SE38 .

Click on create and save the program. We would write the code later.
2) Go to Tcode SE51

In the Layout:
Drag and drop the fields as shown below. (The properties of each field can be seen on the right
hand side of the screenshot)

Customer Number:

Input field:

Check box: Name

Check box: CITY

Check box: Address

Push button: Display

Push button: Cancel

3) Go to SE38.

Enter the following code:


*&---------------------------------------------------------------------*
*& Report ZSCREEN_NEXTSCREEN
*&
*
*&---------------------------------------------------------------------*
*&
*
*&
*
*&---------------------------------------------------------------------*

REPORT ZSCREEN_NEXTSCREEN .
DATA : KUNNR TYPE KUNNR,
NAME TYPE C,
CITY TYPE C,
ADDRESS TYPE C,
OK_CODE LIKE SY-UCOMM.
DATA : NAME1 TYPE NAME1,
ORT01 TYPE ORT01,
ADRNR TYPE ADRNR.
DATA : W_NAME1 TYPE NAME1,
W_ORT01 TYPE ORT01,
W_ADRNR TYPE ADRNR.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&
Module CHECK_VALUES INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE CHECK_VALUES INPUT.
IF OK_CODE EQ 'DISPLAY'.
LEAVE TO LIST-PROCESSING.
SELECT SINGLE NAME1 ORT01 ADRNR FROM KNA1 INTO (W_NAME1, W_ORT01,
W_ADRNR) WHERE KUNNR = KUNNR.
IF NAME EQ 'X'.
WRITE : W_NAME1.
NAME1 = W_NAME1.

ENDIF.
IF CITY EQ 'X'.
WRITE : W_ORT01.
ORT01 = W_ORT01.
ENDIF.
IF ADDRESS EQ 'X'.
ADRNR = W_ADRNR.
WRITE : W_ADRNR.
ENDIF.
ELSEIF OK_CODE EQ 'CANCEL' OR OK_CODE EQ 'BACK'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
" CHECK_VALUES INPUT
" PBO OUTPUT
Execute the program

Demo on Tabstrips
By Vikram Chellappa, Mouri Tech Solutions
In this document, we would work on creating a simple screen with a tabstrip on it.
Go to SE38 T-code.
Create a Z program.

Paste the below code in the source code.


REPORT ZTABSTRIP.
************************************************************************
*
DATA DECLARATIONS
*
************************************************************************
DATA : NUMBER1 TYPE I,
NUMBER2 TYPE I,
RESULT TYPE I,
N1 TYPE I,
N2 TYPE I,
OK_CODE LIKE SY-UCOMM.
CONTROLS TABSTRIP TYPE TABSTRIP.
CALL SCREEN 100.
CALL SCREEN 110.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*&
Module STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'BACK'.
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'TAB1'.
TABSTRIP-ACTIVETAB = 'TAB1'.
WHEN 'TAB2'.
TABSTRIP-ACTIVETAB = 'TAB2'.
RESULT = NUMBER1 + NUMBER2.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0130 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0130 INPUT.
RESULT = NUMBER1 + NUMBER2.
ENDMODULE.
" USER_COMMAND_0130 INPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0110 INPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0110 INPUT.
N1 = NUMBER1.
N2 = NUMBER2.
ENDMODULE.
" USER_COMMAND_0110 INPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_0110 OUTPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0110 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
ENDMODULE.
" STATUS_0110 OUTPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_0130 OUTPUT
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
MODULE STATUS_0130 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
RESULT = NUMBER1 + NUMBER2.

ENDMODULE.

Double Click on "call screen 100".

Enter Short descriptions.

" STATUS_0130

OUTPUT

Come to Flow logic.

Click on Layout Button.

or Press Ctrl+F7.

Create A Tab Strip and Sub screens and place Sub screen in the appropriate tab strip.

Enter the name of the created TABSTRIP and sub SCREEN.

Enter the required Name, Text, Function code.

Enter the OK_CODE.

Double click on CALL SCREEN 110.


Give the short description.
Click on SAVE

, CHECK, ACTIVATE

Click on Flow logic and come to layout.


Create 2 Input fields. Enter the name description and Format.

Click on SAVE

, CHECK, ACTIVATE

Double click on CALL SCREEN 130.

Give the SHORT DESCRIPTION. Click on LAYOUT

Create a text for Result.

Click on SAVE

, CHECK, ACTIVATE

Come Back To Source Code.


Click on SAVE
And EXECUTE.
Result:-

, CHECK, ACTIVATE

Enter the Value on A = 50 and B = 50.

View the Result on Tab2.

Working with Screen Painter


By Vikram Chellappa, Mouri Tech Solutions

SCREEN PAINTER:Screen painter is a tool in ABAP dev workbench used to create the screens using the
T-code SE51. In the screen painter, you can define the following interface elements with
their associated attributes.
1. Input/Output Fields
2. Field Names
3. Checkboxes
4. Radio Buttons
5. Group Boxes
6. Sub screens.
7. Pushbuttons with No Fixed Position
and others
STEP-BY-STEP DEMO FOR SCREEN PAINTER.
Create a Z program in SE38.

Click on Save. We will write the code later in this.

Go to transaction SE51.

Enter the created program name and screen number.

Enter the short description and click on save.

Click on flowlogic tab.

Uncomment the statement MODULE STATUS_0100 .

Double click the status_0100.


The below screen will be displayed,
Click on yes.

Following pop-up screen appears. Select the zdemo_screen_painter main program


and click on continue.

Click on yes.

Screen would be displayed as follows:

Now come back to the transaction SE51. Select flow logic. Click in layout.

Screen painter window will be displayed like this. Here we will design the required
screen fields.

Click on the middle icon

dictionary / program fields window. Or F6.

Following screen appears:

Enter the table name in the table field name.


Click on get from dictionary.

Select the required fields from MARA table from dictionary. Click on OK or continue.

After placing the required fields, you can view the below screen.

Create the push button from the toolbox.

Select the pushbutton, drag and drop the button onto the screen.

Create the other required buttons in the same procedure mentioned above and assign the name,
text, and function code for each one.

After creating the screen click on save check and activate.


press flow logic button.

Click on tab Element List enter OK_CODE.

Paste the below Code in created z program created earlier:


*&-------------------------------------------------------------------*
*& Report ZDEMO_SCREEN_PAINTER
*&
*&-------------------------------------------------------------------*
*& Demo for Screen Painter.
*&
By Vikramchellappa.
*&-------------------------------------------------------------------*
REPORT ZDEMO_SCREEN_PAINTER.
******************************************************************
* TABLE DECLARATIONS.
******************************************************************
TABLES: MARA.
******************************************************************
* DATA DECLARATIONS.
*****************************************************************
DATA: MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
DISPLAY TYPE C,
SAVE TYPE C,
DELETE TYPE C,
CLEAR TYPE C,
EXIT TYPE C,
OK_CODE LIKE SY-UCOMM.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'ZMENU'.
* SET TITLEBAR 'ZMENU_PAINTER'.
CASE SY-UCOMM.

WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'DISPLAY'.
SELECT SINGLE ERSDA ERNAM MTART MATKL FROM MARA
INTO (MARA-ERSDA, MARA-ERNAM, MARA-MTART, MARA-MATKL)
WHERE MATNR = MARA-MATNR.
WHEN 'CLEAR'.
CLEAR MARA.
ENDCASE.
ENDMODULE.
" STATUS_0100 OUTPUT Output:Enter Material number On Material Field. Click on Display.

Material Information is displayed as shown below:

Display images on the screen


By Aditya Niyogi, L&T Infotech
Step 1: Upload picture into SAP using the transaction SE78. Test picture.

Step 2: Create a custom screen section in the screen.

Step 3: In the PBO module of the screen, attach the following code. Please note that the object
name is winny, please pass your own object name to the method:
*&---------------------------------------------------------------------*
*&
Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
DATA: W_LINES TYPE I.
TYPES PICT_LINE(256) TYPE C.
DATA :
CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
EDITOR TYPE REF TO CL_GUI_TEXTEDIT,
PICTURE TYPE REF TO CL_GUI_PICTURE,
PICT_TAB TYPE TABLE OF PICT_LINE,
URL(255) TYPE C.
DATA: GRAPHIC_URL(255).
DATA: BEGIN OF GRAPHIC_TABLE OCCURS 0,
LINE(255) TYPE X,
END OF GRAPHIC_TABLE.
DATA: L_GRAPHIC_CONV TYPE I.
DATA: L_GRAPHIC_OFFS TYPE I.
DATA: GRAPHIC_SIZE TYPE I.
DATA: L_GRAPHIC_XSTR TYPE XSTRING.
.
CALL METHOD CL_GUI_CFW=>FLUSH.
CREATE OBJECT:

CONTAINER EXPORTING CONTAINER_NAME = 'PICTURE_CONTAINER',


PICTURE EXPORTING PARENT = CONTAINER.
CALL METHOD CL_SSF_XSF_UTILITIES=>GET_BDS_GRAPHIC_AS_BMP
EXPORTING
P_OBJECT
= 'GRAPHICS'
P_NAME
= 'WINNY'
P_ID
= 'BMAP'
P_BTYPE
= 'BCOL'
RECEIVING
P_BMP
= L_GRAPHIC_XSTR
* EXCEPTIONS
*
NOT_FOUND
= 1
*
INTERNAL_ERROR = 2
*
others
= 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
GRAPHIC_SIZE = XSTRLEN( L_GRAPHIC_XSTR ).
L_GRAPHIC_CONV = GRAPHIC_SIZE.
L_GRAPHIC_OFFS = 0.
WHILE L_GRAPHIC_CONV > 255.
GRAPHIC_TABLE-LINE = L_GRAPHIC_XSTR+L_GRAPHIC_OFFS(255).
APPEND GRAPHIC_TABLE.
L_GRAPHIC_OFFS = L_GRAPHIC_OFFS + 255.
L_GRAPHIC_CONV = L_GRAPHIC_CONV - 255.
ENDWHILE.
GRAPHIC_TABLE-LINE = L_GRAPHIC_XSTR+L_GRAPHIC_OFFS(L_GRAPHIC_CONV).
APPEND GRAPHIC_TABLE.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
TYPE
= 'IMAGE'
SUBTYPE = 'X-UNKNOWN'
SIZE
= GRAPHIC_SIZE
LIFETIME = 'T'
TABLES
DATA
= GRAPHIC_TABLE
CHANGING
URL
= URL.
CALL METHOD PICTURE->LOAD_PICTURE_FROM_URL
EXPORTING
URL = URL.
CALL METHOD PICTURE->SET_DISPLAY_MODE
EXPORTING
DISPLAY_MODE = PICTURE->DISPLAY_MODE_FIT_CENTER.
ENDMODULE.
" STATUS_9000 OUTPUT
Output:

Text Edit control - Usage and Demo


By Saikumar Bonakurthi, Enteg Infotech
As an ABAP developer, we all know that if we drop a field of type char and length 255 in to the
conventional screen painter it will be displayed in a single line. It will not be good interface unless
we provide a multi-line input field in the screen. This can be achieved by text editor control.
The following is our attempt to explain how to implement the text editor control on classic
dynpros.
Text editor is displayed on screen using custom control. So we need a container for the custom
control. And text editor control is implemented using class CL_GUI_TEXTEDIT.
Our declaration part contains
DATA: LINE_LENGTH
TYPE I VALUE 254,
EDITOR_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
TEXT_EDITOR
TYPE REF TO CL_GUI_TEXTEDIT,
TEXT
TYPE STRING.
Then call the screen (can be any number)
START-OF-SELECTION.
CALL SCREEN '100'.
Go to screen 100 by double clicking on '100'.
Create a custom control on screen with name TEXTEDIT.

Uncomment both PBO and PAI modules in flow logic screen


PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
Define and implement both the modules in the main program itself.
In PBO create object container EDITOR_CONTAINER. Then create text editor object by
exporting the container EDITOR_CONTAINER.
CREATE OBJECT EDITOR_CONTAINER
EXPORTING
CONTAINER_NAME
= 'TEXTEDITOR'
EXCEPTIONS
CNTL_ERROR
=1
CNTL_SYSTEM_ERROR
=2
CREATE_ERROR
=3
LIFETIME_ERROR
=4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
CREATE OBJECT TEXT_EDITOR
EXPORTING
PARENT
= EDITOR_CONTAINER
WORDWRAP_MODE = CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITION
WORDWRAP_POSITION
= LINE_LENGTH
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
You can hide the toolbar and as well as status bar for the text editor control.
CALL METHOD TEXT_EDITOR->SET_TOOLBAR_MODE
EXPORTING
TOOLBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
CALL METHOD TEXT_EDITOR->SET_STATUSBAR_MODE
EXPORTING
STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
Define and create a GUI Status in the PBO.
SET PF-STATUS 'STATUS_0100'.
Very minimum set of tool bar buttons defined in this example

In PAI of the screen 100, handle the save and other user commands.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SAVE'.
CALL METHOD TEXT_EDITOR->GET_TEXTSTREAM
*
EXPORTING
*
ONLY_WHEN_MODIFIED = CL_GUI_TEXTEDIT=>TRUE
IMPORTING
TEXT
= TEXT
*
IS_MODIFIED
=
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
NOT_SUPPORTED_BY_GUI = 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR
=2
OTHERS
= 3.
MESSAGE TEXT TYPE 'I'.
ENDCASE.
To read the text that is typed in the editor we need to call the method GET_TEXTSTREAM of the
editor instance.
We are just displaying the text typed in the editor in an informative message; the same can be
inserted / updated into a database table also.
The complete coding of the executable program is given below..
REPORT ZTEXT_EDITOR.
DATA: LINE_LENGTH
TYPE I VALUE 254,
EDITOR_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

TEXT_EDITOR
TYPE REF TO CL_GUI_TEXTEDIT,
TEXT
TYPE STRING.
START-OF-SELECTION.
CALL SCREEN '100'.
**&---------------------------------------------------------------------*
**&
Module STATUS_0100 OUTPUT
**&---------------------------------------------------------------------*
**
text
**----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
IF TEXT_EDITOR IS INITIAL.
CREATE OBJECT EDITOR_CONTAINER
EXPORTING
CONTAINER_NAME
= 'TEXTEDITOR'
EXCEPTIONS
CNTL_ERROR
=1
CNTL_SYSTEM_ERROR
=2
CREATE_ERROR
=3
LIFETIME_ERROR
=4
LIFETIME_DYNPRO_DYNPRO_LINK = 5.
CREATE OBJECT TEXT_EDITOR
EXPORTING
PARENT
= EDITOR_CONTAINER
WORDWRAP_MODE
= CL_GUI_TEXTEDIT=>WORDWRAP_AT_FIXED_POSITIO
N
WORDWRAP_POSITION
= LINE_LENGTH
WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
*3)HIDE TOOLBAR AND STATUSBAR
CALL METHOD TEXT_EDITOR->SET_TOOLBAR_MODE
EXPORTING
TOOLBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
CALL METHOD TEXT_EDITOR->SET_STATUSBAR_MODE
EXPORTING
STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
ENDIF.
ENDMODULE.
" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT'.

LEAVE PROGRAM.
WHEN 'SAVE'.
CALL METHOD TEXT_EDITOR->GET_TEXTSTREAM
*
EXPORTING
*
ONLY_WHEN_MODIFIED = CL_GUI_TEXTEDIT=>TRUE
IMPORTING
TEXT
= TEXT
*
IS_MODIFIED
=
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
NOT_SUPPORTED_BY_GUI = 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR
=2
OTHERS
= 3.
MESSAGE TEXT TYPE 'I'.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0100 INPUT
The final Screen shot of the editor:

Splitter Controls and Graphs


By Swarna S, Tata Consultancy Services

*&----------------------------------------------------------------*& Report Z_SPLIT_GRAPH


*& Author: Swarna.S.(Tata Consultancy Services)
* Published at SAPTechnical.COM
*&----------------------------------------------------------------*& AS : Sample code for creating a splitter screen and graph.
*& The screen is divided into two by splitter control and can be resized
*& Two graphs are drawn on the two splitter containers.
*& The sample code also describes creating graphs in ABAP.
*&----------------------------------------------------------------REPORT z_split_graph .
*type pool declarations for graphical frame work
TYPE-POOLS: GFW.
*OK code declaration
DATA: OK_CODE TYPE SY-UCOMM.
*structure declaration for graph 1 values
types : begin of ty_grvalwa1.
include structure gprval.
types : end of ty_grvalwa1.
*structure declaration for graph 1 column names
types : begin of ty_col1_texts.

include structure gprtxt.


types : end of ty_col1_texts.
*data declarations for graph 1
data : grval1 TYPE standard TABLE OF ty_grvalwa1,
grvalwa1 type ty_grvalwa1,
COL1_TEXTS TYPE standard TABLE OF ty_col1_texts,
col1_wa type ty_col1_texts.
*structure declaration for graph 2 values
types : begin of ty_grvalwa2.
include structure gprval.
types : end of ty_grvalwa2.
*structure declaration for graph 2 column names
types : begin of ty_col2_texts.
include structure gprtxt.
types : end of ty_col2_texts.
*data declarations for graph2
data : grval2 TYPE standard TABLE OF ty_grvalwa2,
grvalwa2 type ty_grvalwa2,
COL2_TEXTS TYPE standard TABLE OF ty_col2_texts,
col2_wa type ty_col2_texts.
*data declarations for containers,splitters,and custom container
data :CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
CONT1 type ref to cl_gui_container,
CONT2 type ref to cl_gui_container.
*Initialisation event
INITIALIZATION.
*start of selection event
START-OF-SELECTION.
*Call screen for the container for output
CALL SCREEN 600.
*PBO module for the output display
*&----------------------------------------------------------------*
*&
Module PBO_0600 OUTPUT
*&----------------------------------------------------------------*
MODULE PBO_0600 OUTPUT.
*Setting the GUI status for the splitter screen(EXIT button)
SET PF-STATUS 'SPLITGRAPH'.
*Setting the title for the splitter control
SET titlebar 'SPLITGRAPH'.
*Creating custom container
CREATE OBJECT CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER'.
*creating the splitter control
CREATE OBJECT splitter
EXPORTING
PARENT = CUSTOM_CONTAINER
ROWS
= 1
COLUMNS = 2
ALIGN
= 15.
*calling the container method of the splitter class
*for the first graphic
CALL METHOD SPLITTER->GET_CONTAINER
EXPORTING
ROW
= 1
COLUMN
= 1

RECEIVING
CONTAINER = CONT1.
*calling the container method of the splitter class
*for the second graphic
CALL METHOD SPLITTER->GET_CONTAINER
EXPORTING
ROW
= 1
COLUMN
= 2
RECEIVING
CONTAINER = CONT2.
*Graphic 1 display
REFRESH : grval1,Col1_texts.
grvalwa1-rowtxt = 'Rice'.
grvalwa1-val1 = 1100.
grvalwa1-VAL2 = 4500.
APPEND grvalwa1 to grval1.
grvalwa1-ROWTXT = 'Coffee'.
grvalwa1-VAL1 = 2000.
grvalwa1-VAL2 = 6000.
APPEND grvalwa1 to grval1.
grvalwa1-ROWTXT = 'Tea'.
grvalwa1-VAL1 = 3500.
grvalwa1-VAL2 = 7000.
APPEND grvalwa1 to grval1.
grvalwa1-ROWTXT = 'Cereals'.
grvalwa1-VAL1 = 6000.
grvalwa1-val2 = 7000.
APPEND grvalwa1 to grval1.
col1_wa-coltxt = '2005'.
APPEND col1_wa to COL1_TEXTS.
COL1_wa-COLTXT = '2006'.
APPEND col1_wa to COL1_TEXTS.
*Function module to display graph (Graph 1)
CALL FUNCTION 'GFW_PRES_SHOW_MULT'
EXPORTING
PARENT
= CONT1
PRESENTATION_TYPE = GFW_PRESTYPE_LINES
SHOW
= GFW_FALSE
TABLES
VALUES
= grval1
COLUMN_TEXTS
= COL1_TEXTS
EXCEPTIONS
ERROR_OCCURRED
= 1.
*Graphic 2 display
REFRESH : grval2,col2_texts.
grvalwa2-ROWTXT = 'Wheat'.
grvalwa2-VAL1 = 3000.
grvalwa2-VAL2 = 5500.
APPEND grvalwa2 to grval2.
grvalwa2-ROWTXT = 'Corn'.
grvalwa2-VAL1 = 2700.
grvalwa2-VAL2 = 8000.
APPEND grvalwa2 to grval2.
grvalwa2-ROWTXT = 'Maize'.
grvalwa2-VAL1 = 3250.
grvalwa2-VAL2 = 5000.
APPEND grvalwa2 to grval2.

grvalwa2-ROWTXT = 'Barley'.
grvalwa2-VAL1 = 6500.
grvalwa2-VAL2 = 9000.
APPEND grvalwa2 to grval2.
COL2_wa-COLTXT = '2005'.
APPEND col2_wa to COL2_TEXTS.
COL2_wa-COLTXT = '2006'.
APPEND col2_wa to COL2_TEXTS.
*Function module to display Graph 2
CALL FUNCTION 'GFW_PRES_SHOW_MULT'
EXPORTING
PARENT
= CONT2
PRESENTATION_TYPE = GFW_PRESTYPE_LINES
SHOW
= GFW_TRUE
TABLES
VALUES
= grval2
COLUMN_TEXTS
= COL2_TEXTS
EXCEPTIONS
ERROR_OCCURRED
= 1.
ENDMODULE.
" PBO_0600 OUTPUT
*PAI module : Based on user input,action is performed
*EXIT called to leave program when user clicks it
*&----------------------------------------------------------------*
*&
Module PAI_0600 INPUT
*&----------------------------------------------------------------*
MODULE PAI_0600 INPUT.
OK_CODE = SY-UCOMM.
IF OK_CODE EQ 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
" PAI_0600 INPUT
Screen shots of the output.

Screen shot of the splitter containers can be resized as shown below:

Table Control using Wizard in Module Pool Programming


By Venkatraman N, IBM
Pre-requisites:
The readers must be able to create a module pool program and they should be familiar with
screen programming.
Purpose of this tutorial:
This is to demonstrate the step by step tutorial of how to make use of table control with wizard,
where the developers effort to write code with table control without wizard is avoided.
Introduction:
Table control with wizard is the control provided by SAP, in which the users are not needed to
code separately for table control operations. It generates automatically system generated code
for the following table control operations.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

Insertion
Deletion
Scrolling
First
Last
Next
Previous
Select
Select all
Deselect
Deselect all

Step 1: Create an internal table and work area, which we are going to deploy in table control.

Step 2: Create a screen called 9000.

Input the screen number as 9000.

Fill up the screen attribute values.

Step 3: Go to the layout of the screen, where you can find the table control with wizard. Drag and
drop the table control with wizard to the layout of the screen.

Once you drag and drop the control a popup will appear.

Press Continue. In the next screen enter the table control name as TBC_9000 or your own
name.

In the next screen you input the internal table and work area which has been created earlier.
Note: Before it is done, you must activate the page, in which you have declared the internal table
and work area. Then only this table control screen will take its properties.

The next screen will automatically retrieve the fields available in the internal table and show.
We have to select those fields, which and all should be displayed in table control.

If you have declared any character field for table control line selection, that should not be
selected in this screen.

Select the input/output attributes as Input control and give the field for selection of table
control rows. Select the multiple line selection.

Click on Continue. The table control with auto generated code will automatically be
created.

This will automatically create PBO & PAI modules for table control operations.

Step 4: For testing this tutorial, write a simple query to populate the internal table of table
control and test the input controls associated with it.

The expected output will be like

Summary :
As a result of this tutorial, the user will be able to
1. Use table control with wizard in module pool programming and
2. Create table control operations with system generated code.

Open the text editor when click the button in table control
By Phani Diwakar, Yash Technologies
The requirement is for every combination of vendor and contract number, payment term text
should be maintained in the Z-Table. This payment term text is opened in text editor so that user
can enter long text (more than 500 characters). To achieve this, we put the button in payment
term text field in table control and whenever user clicks on button text editor will be opened.
Step1: Create Z-Table with name ZCONTRACT with the following fields.

Step2: Create the table maintenance generator for the above created table ZCONTRACT (Please
refer http://www.saptechnical.com/Tutorials/ABAP/TableMaintenance/demo.htm)
Step3: Go to SM30 and provide the Table/View name created and click on Maintain button as
shown.

The following screen will appear.

Step4: Now we have to add the field payment term text as follows.
Now open the table ZCONTRACT in change mode and go to table maintenance generator as
shown.

The following screen will appear.

Now click on the Fn.Gr.Text button. Then the following screen appears.

Click on the Main program button.


Now go to screen 0001 as shown.

Now go to layout editor.


Drag and drop the button and text field to layout editor from the panel as shown.

Properties of the button:

Properties of text field

Save and activate the screen painter.


Now go to flow logic.

Write the following code.


*----------------------------------------------------------------*
***INCLUDE LZCONTRACTI01 .
*----------------------------------------------------------------*
*&--------------------------------------------------------------*
*&
Module TEXT_EDITOR INPUT
*&---------------------------------------------------------------*
*
text
*----------------------------------------------------------------*
MODULE text_editor INPUT.
DATA g_aftnr LIKE thead-tdname.
DATA g_vendor TYPE lifnr.
DATA st_thead LIKE thead.
DATA wa_lines TYPE tline.
DATA it_lines TYPE TABLE OF tline.
DATA g_tdname LIKE stxh-tdname.
DATA g_lineno TYPE sy-index.
DATA g_ok_code TYPE sy-ucomm.
DATA g_lin_no.
CLEAR : g_lineno,
g_tdname,
st_thead,
it_lines,
wa_lines,
g_lin_no.
REFRESH it_lines.
g_ok_code = sy-ucomm.
CLEAR sy-ucomm.

IF g_ok_code EQ 'PTERM'.
GET CURSOR LINE g_lineno.
g_lineno = g_lineno + tctrl_zcontract-top_line - 1.
READ TABLE extract INDEX g_lineno.
g_vendor = extract+3(10).
g_aftnr = extract+13(10).
CONCATENATE g_vendor g_aftnr INTO g_tdname.
PERFORM read_text.
IF sy-subrc NE 0.
PERFORM enter_st_head.
PERFORM edit_text.
ELSE.
PERFORM edit_text.
ENDIF.
ENDIF.
PERFORM create_text.
ENDMODULE.
" TEXT_EDITOR INPUT
*&----------------------------------------------------------------*
*&
Form READ_TEXT
*&----------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*-----------------------------------------------------------------*
FORM read_text .
CALL FUNCTION 'READ_TEXT'
EXPORTING
*
CLIENT
= SY-MANDT
id
= 'ZTS'
language
= sy-langu
name
= g_tdname
object
= 'ZTEST_ID'
*
ARCHIVE_HANDLE
= 0
*
LOCAL_CAT
= ' '
IMPORTING
header
= st_thead
TABLES
lines
= it_lines
EXCEPTIONS
id
= 1
language
= 2
name
= 3
not_found
= 4
object
= 5
reference_check
= 6
wrong_access_to_archive
= 7
OTHERS
= 8
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" READ_TEXT
*&----------------------------------------------------------------*
*&
Form ENTER_ST_HEAD
*&----------------------------------------------------------------*

*
text
*-----------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------*
FORM enter_st_head .
st_thead-tdobject
= 'ZTEST_ID'.
st_thead-tdid
= 'ZTS' .
st_thead-tdspras
= sy-langu.
st_thead-tdlinesize = '072'.
st_thead-tdtxtlines = '1'.
ENDFORM.
" ENTER_ST_HEAD
*&---------------------------------------------------------------*
*&
Form EDIT_TEXT
*&---------------------------------------------------------------*
*
text
*-----------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*-----------------------------------------------------------------*
FORM edit_text .
CALL FUNCTION 'EDIT_TEXT'
EXPORTING
*
DISPLAY
= ' '
*
EDITOR_TITLE
= ' '
header
= st_thead
*
PAGE
= ' '
*
WINDOW
= ' '
*
SAVE
= 'X'
*
LINE_EDITOR
= ' '
*
CONTROL
= ' '
*
PROGRAM
= ' '
*
LOCAL_CAT
= ' '
IMPORTING
*
FUNCTION
=
newheader
= st_thead
*
RESULT
=
TABLES
lines
= it_lines
EXCEPTIONS
id
= 1
language
= 2
linesize
= 3
name
= 4
object
= 5
textformat
= 6
communication
= 7
OTHERS
= 8
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" EDIT_TEXT
*&---------------------------------------------------------------*
*&
Form CREATE_TEXT
*&---------------------------------------------------------------*

*
text
*----------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------*
FORM create_text .
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid
= 'ZTS'
flanguage
= sy-langu
fname
= g_tdname
fobject
= 'ZTEST_ID'
save_direct = 'X'
fformat
= '*'
TABLES
flines
= it_lines
EXCEPTIONS
no_init
= 1
no_save
= 2
OTHERS
= 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
" CREATE_TEXT

Now we have to create OBJECT and OBJECT ID using the transaction code SE75 as follows.
Initial screen of SAPscript Settings (SE75) is as shown below.

Click on Change button.


The following screen appears.

Select create button to create object.

Click on Ok button.
The following screen appears.

Click on the SAVE button.


Click on Text IDs button to create Text ID.

Click on Create button.

Click on Ok button.
Click on SAVE button.
Step5: Execute the transaction code created for table maintenance.

Click on the button Maintain Text then text editor will be opened.

You might also like