SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

How to create text editor?



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Fri May 18, 2012 2:31 pm    Post subject: How to create text editor? Reply with quote

Example 1: use FM TXW_TEXTNOTE_EDIT

Code:
FORM note_display.
  IF gt_note IS INITIAL.           "no note
    MESSAGE s069(xw).
  ELSE.
    CALL FUNCTION 'TXW_TEXTNOTE_EDIT'
      EXPORTING
        edit_mode = space
      TABLES
        t_txwnote = gt_note.
  ENDIF.
ENDFORM.                    "note_display


Example 2:
Source from: http://scn.sap.com/thread/1501255

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

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

Code:
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 TO SCREEN 0.
    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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.