BDC Demo On Using Table Control
BDC Demo On Using Table Control
*&---------------------------------------------------------------------*
*&
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:
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
IF init is initial.
init = 'X'.
CREATE OBJECT:
container EXPORTING container_name = 'PICTURE_CONTAINER',
picture
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.
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:
3) Go to SE38.
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.
*&---------------------------------------------------------------------*
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.
" STATUS_0130
OUTPUT
or Press Ctrl+F7.
Create A Tab Strip and Sub screens and place Sub screen in the appropriate tab strip.
, CHECK, ACTIVATE
Click on SAVE
, CHECK, ACTIVATE
Click on SAVE
, CHECK, ACTIVATE
, CHECK, ACTIVATE
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.
Go to transaction SE51.
Click on yes.
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.
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.
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.
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.
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:
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:
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.
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 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.
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.
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.
Now click on the Fn.Gr.Text button. Then the following screen appears.
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 Ok button.
The following screen appears.
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.