cancel
Showing results for 
Search instead for 
Did you mean: 

Free text box

Former Member
0 Kudos

Hello,

I'm writing a program where I want a long text box where the user can enter long descriptions. Does anyone know how to do this not using OO programming?

I thought I could do it using a table control but this won't wrap my text onto the next line.

Any ideas?

Thanks,

Gill

xlg00ru
Explorer
0 Kudos

If you want to create a long text box where the user can enter descriptions that wrap onto the next line, you can use the SAP GUI's text editor control (SELECTION-SCREEN COMMENT). Here's an example of how you can implement it without using object-oriented (OO) programming:

In this example, the SELECTION-SCREEN COMMENT is used to define the p_description parameter as a long text box where the user can enter descriptions. The entered description will wrap onto the next line automatically.

When the program is executed, the entered description will be displayed using the WRITE statement in the START-OF-SELECTION section.

You can customize the appearance and behavior of the text box by using additional options provided by the SELECTION-SCREEN COMMENT statement. For example, you can specify the width and height of the text box, enable scrollbars, or set default text values.

Please note that this approach uses the SAP GUI's text editor control, which is suitable for simple text input requirements. If you need more advanced features such as rich text formatting or extensive text editing capabilities, you may need to consider using a custom control or a dedicated text editing library.

Accepted Solutions (1)

Accepted Solutions (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I know that you said, no OO, but I believe that this is the only way to do it. Here is a sample program which shows how easy it would be to do.

Create screen 100, and create a custom container in that screen. Name it CONTAINER. Create gui status 100 with Fcodes CHANGE, DISPLAY, and SAVE.



REPORT ZRICH_0001
       NO STANDARD PAGE HEADING.

* Miscellanous Variables
DATA: OK_CODE LIKE SY-UCOMM,
      SAVE_OK LIKE SY-UCOMM.

* Variable for "Text Container" Abap Object
DATA: EDITOR TYPE REF TO CL_GUI_TEXTEDIT,
      X_EDITOR TYPE REF TO C_TEXTEDIT_CONTROL,
      CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA: WA_TEXT LIKE TLINE-TDLINE.

DATA: BEGIN OF LINES OCCURS 0.
        INCLUDE STRUCTURE TLINE.
DATA: END OF LINES.

DATA: TEXTLINES LIKE TLINE-TDLINE OCCURS 0.

* Constants
CONSTANTS: TRUE(1) TYPE C VALUE 'X',
           FALSE(1) TYPE C VALUE ' ',
           YES(1) TYPE C VALUE 'J',
           NO(1) TYPE C VALUE 'N'.

START-OF-SELECTION.

  CALL SCREEN 100.

************************************************************************
*      Module  STATUS_0100  OUTPUT
************************************************************************
MODULE STATUS_0100 OUTPUT.

  CLEAR: TEXTLINES.  REFRESH:  TEXTLINES.
  CLEAR: LINES. REFRESH LINES.

* Initialize container
  IF NOT CONTAINER IS INITIAL.
    CALL METHOD CONTAINER->FREE.
  ENDIF.

* Create Text Container
  CREATE OBJECT CONTAINER
      EXPORTING CONTAINER_NAME = 'CONTAINER'.
  CREATE OBJECT EDITOR
      EXPORTING PARENT = CONTAINER.

  PERFORM SET_TEXT.

  CASE SAVE_OK.
    WHEN 'CHANGE'.
      SET PF-STATUS '0100' EXCLUDING 'CHANGE'.
      CALL METHOD EDITOR->SET_READONLY_MODE
         EXPORTING READONLY_MODE = EDITOR->FALSE.

    WHEN OTHERS.
      SET PF-STATUS '0100' EXCLUDING 'DISPLAY'.
      CALL METHOD EDITOR->SET_READONLY_MODE
           EXPORTING READONLY_MODE = EDITOR->TRUE.
  ENDCASE.

  SET TITLEBAR '0100'.

ENDMODULE.

************************************************************************
*      Module  USER_COMMAND_0100  INPUT
************************************************************************
MODULE USER_COMMAND_0100 INPUT.

  DATA: MODIFIED TYPE I.

  SAVE_OK = OK_CODE.
  CASE OK_CODE.
    WHEN 'CHANGE' OR 'DISPLAY'.
      CLEAR OK_CODE.
    WHEN 'SAVE'.
      CLEAR OK_CODE.

* Retrieve text from container
      CALL METHOD EDITOR->GET_TEXT_AS_R3TABLE
         EXPORTING
               ONLY_WHEN_MODIFIED = C_TEXTEDIT_CONTROL=>FALSE
         IMPORTING
               TABLE              = TEXTLINES
               IS_MODIFIED        = MODIFIED
         EXCEPTIONS
               OTHERS             = 1.

* Write out contents of text editor
      LEAVE TO LIST-PROCESSING.
      LOOP AT TEXTLINES INTO WA_TEXT.
        WRITE:/ WA_TEXT.

      ENDLOOP.

    WHEN 'BACK'.
      CLEAR OK_CODE.
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.

************************************************************************
*      FORM  SET_TEXT
************************************************************************
FORM SET_TEXT.

  LINES-TDLINE = 'Here we are filling the text editor - Line 1'.
  APPEND LINES.

  LINES-TDLINE = 'Here we are filling the text editor - Line 2'.
  APPEND LINES.

  LOOP AT LINES .
    SHIFT LINES LEFT DELETING LEADING SPACE.
    APPEND LINES TO TEXTLINES .
  ENDLOOP.

* Fill container with text lines
  CALL METHOD EDITOR->SET_TEXT_AS_R3TABLE
     EXPORTING
           TABLE              = TEXTLINES
           EXCEPTIONS
           OTHERS             = 1.

ENDFORM.

Regards,

Rich Heilman

Answers (1)

Answers (1)

Peter_Inotai
Active Contributor
0 Kudos

I'd recommend Rich's way to implement it.

However there is also a lazy version: use statement 'EDITOR-CALL FOR itab.' Please keep in mind, that it's obsolete in release 6.40.

Peter

Former Member
0 Kudos

Thanks all for your help.

It's solved now and working.