Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to create text editor?

Former Member
0 Likes
8,437

Hi friends

i want to dispaly the text in a custom table in to one text editor in change mode, The user do some modifications in the editor,and clicks on save,then it should update the data base.

please let me know how can i create this kind of text editor? which function module or method i need to call? what i need to pass to them?do i need to create it through custom control ?

i have searched in SDN but unable to get it.

Edited by: tummala swapna on Oct 13, 2009 12:36 PM

5 REPLIES 5
Read only

Former Member
0 Likes
2,400

Hi Tummala,

You can use class CL_GUI_TEXT_EDIT.

DATA :  go_editor TYPE REF TO cl_gui_textedit,

" Create text editor
CREATE OBJECT go_editor
  EXPORTING
    wordwrap_mode   = go_editor->wordwrap_at_fixed_position
    wordwrap_position      = 8000
    wordwrap_to_linebreak_mode = go_editor->true
    parent                 = go_container
  EXCEPTIONS
    OTHERS                 = 1.

" Put it in read-only mode
CALL METHOD go_editor->set_readonly_mode
  EXPORTING
    readonly_mode          = go_apercu_fichier->&1
  EXCEPTIONS
    OTHERS                 = 1.

Best regards,

Samuel

Read only

awin_prabhu
Active Contributor
0 Likes
2,400

Try below link,

Thanks,

Read only

venkat_o
Active Contributor
0 Likes
2,400

Hi Swapna, Steps to develop Text editor <li>Need to create screen <li>Place Custom container on the screen. <li>Bind the bind TextEdit Control with Custom container. <li>Check the demo programs

1.SAPTEXTEDIT_DEMO_1
2.SAPTEXTEDIT_DEMO_3
3.SAPTEXTEDIT_TEST_2
<li>Check the SAP help documentation. http://help.sap.com/saphelp_nw2004s/helpdata/en/f1/549e36cf0ecb7de10000009b38f889/frameset.htm Thanks Venkat.O

Read only

Former Member
0 Likes
2,400

Hi,

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.

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'.

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_POSITION
        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

Thanks,

Harini

Read only

Former Member
0 Likes
2,400

Hi,

Use FM:- TXW_TEXTNOTE_EDIT

Thanks & Regards

Rahul