Application Development 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: 

How to create Free text in Module Pool

spartans007
Participant
0 Kudos

Hello Everyone,

I am facing an issue creating free text field in Module Pool. I tried searching and going through many blogs but found nothing informative or proper coding required to create this.

Below is the image of what is needed to develop.

Can someone please help me with the steps and the coding required to create this in Module Pool Programming?

Also how to save the data and read the data from this text box?

Thanks & Regards,

Alex Dsouza

8 REPLIES 8

FredericGirod
Active Contributor

Check programs SAPTEXTEDIT_DEMO_1, SAPTEXTEDIT_DEMO_2, ...

spartans007
Participant
0 Kudos

I checked but was not able to read the data or save it

Sandra_Rossi
Active Contributor
0 Kudos

spartans007 Don't tell me that the demo programs don't read the entered text!? Just do the same. If you need more assistance, please post your code and tell us what happens, what is wrong, what you expect.

spartans007
Participant
0 Kudos

sandra.rossi I have done a sample code can you please review it?

 *&---------------------------------------------------------------------*
*& Report ZTEST_REMARK
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_remark.

CALL SCREEN 100.

CONSTANTS: line_length TYPE i VALUE 255.
DATA: editor_container        TYPE REF TO cl_gui_custom_container,
      text_editor             TYPE REF TO cl_gui_textedit,
      text                    TYPE string,
      g_mytable(line_length)  TYPE c OCCURS 0,
      gs_mytable(line_length) TYPE c.
*&---------------------------------------------------------------------*
*& Module DISPLAY OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE display OUTPUT.
  IF text_editor IS BOUND.
    text_editor->free( ).
    editor_container->free( ).
  ENDIF.

  CREATE OBJECT editor_container
    EXPORTING
*     parent                      =
      container_name              = 'CONTAINER'
*     style                       =
*     lifetime                    = lifetime_default
*     repid                       =
*     dynnr                       =
*     no_autodef_progid_dynnr     =
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*                                    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                                               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CREATE OBJECT text_editor
    EXPORTING
      wordwrap_mode          = cl_gui_textedit=>wordwrap_at_fixed_position
      wordwrap_position      = line_length
      parent                 = editor_container
    EXCEPTIONS
      error_cntl_create      = 1
      error_cntl_init        = 2
      error_cntl_link        = 3
      error_dp_create        = 4
      gui_type_not_supported = 5
      OTHERS                 = 6.
  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 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.

  DATA: name TYPE thead-tdname.
  DATA: lines TYPE STANDARD TABLE OF tline WITH HEADER LINE.
  REFRESH: lines[].
  CLEAR: lines, text.

  CONCATENATE 'SER' '11' INTO name.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      client                  = sy-mandt
      id                      = 'ZTEST'
      language                = sy-langu
      name                    = name
      object                  = 'ZFI_REMARK'
*     ARCHIVE_HANDLE          = 0
*     LOCAL_CAT               = ' '
*   IMPORTING
*     HEADER                  =
*     OLD_LINE_COUNTER        =
    TABLES
      lines                   = 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.
* Implement suitable error handling here
  ENDIF.

  CALL METHOD cl_gui_cfw=>flush
    EXCEPTIONS
      cntl_system_error = 1
      cntl_error        = 2
      OTHERS            = 3.
  IF sy-subrc <> 0.
*   Implement suitable error handling here
  ENDIF.

  REFRESH : g_mytable.
  LOOP AT lines.
    gs_mytable = lines-tdline.
    APPEND gs_mytable TO g_mytable.
    CLEAR: gs_mytable.
  ENDLOOP.

IF sy-ucomm = 'LOAD'.
      CALL METHOD text_editor->set_text_as_r3table
              EXPORTING table = g_mytable.

ENDIF.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  SAVE_TEXT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE save_text INPUT.
  IF text_editor IS BOUND AND sy-ucomm = 'SAVE'.

      CALL METHOD text_editor->get_text_as_r3table
              IMPORTING table = g_mytable.

    DATA: header   TYPE thead,
          it_lines TYPE TABLE OF tline,
          ls_lines TYPE tline,
          i_len    TYPE i.

    REFRESH : it_lines[].

    LOOP AT g_mytable INTO gs_mytable.
      ls_lines-tdline = gs_mytable.
      APPEND ls_lines TO it_lines.
      CLEAR: ls_lines, gs_mytable.
    ENDLOOP.

    header-tdobject = 'ZFI_REMARK'.
      CONCATENATE 'SER' '11' INTO header-tdname.
      header-tdid = 'ZTEST'.
      header-tdspras = 'E'.

      CALL FUNCTION 'DELETE_TEXT'
        EXPORTING
         CLIENT                = SY-MANDT
          id                    = 'ZTEST'
          language              = sy-langu
          NAME                  = header-tdname
          OBJECT                = 'ZFI_REMARK'
*         SAVEMODE_DIRECT       = ' '
*         TEXTMEMORY_ONLY       = ' '
*         LOCAL_CAT             = ' '
       EXCEPTIONS
         NOT_FOUND             = 1
         OTHERS                = 2
                .
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.



CALL FUNCTION 'SAVE_TEXT'
  EXPORTING
   CLIENT                  = SY-MANDT
    header                  = header
   INSERT                  = ' '
   SAVEMODE_DIRECT         = 'X'
*   OWNER_SPECIFIED         = ' '
*   LOCAL_CAT               = ' '
*   KEEP_LAST_CHANGED       = ' '
* IMPORTING
*   FUNCTION                =
*   NEWHEADER               =
  tables
    lines                   = it_lines
  EXCEPTIONS
   ID                      = 1
   LANGUAGE                = 2
   NAME                    = 3
   OBJECT                  = 4
   OTHERS                  = 5
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
 SET PF-STATUS 'ZSTATUS'.
 SET TITLEBAR 'ZTEST'.
ENDMODULE.

Sandra_Rossi
Active Contributor
0 Kudos

What issue do you have with this code?

spartans007
Participant

sandra.rossi It was not working. Got it fixed thanks!

spartans007
Participant
0 Kudos

Hello sandra.rossi ,

When i save the text it gets saved and it reads the text back fine.

But when i go and edit the text and save it. The edited text is getting saved in the backend.

But the container is getting cleared. I also debugged but was not able to find out why the read text is not working.

If i go to SE37 and do READ_TEXT i am able to see the updated text.

Also if i re run the program i get the updated text. But not sure why the container is getting cleared after edit.

Can you please help me on this? The code is same as above.

Regards,

Alex Dsouza.

Sandra_Rossi
Active Contributor
0 Kudos

I advise, if you want quick assistance, to create a tiny program of few lines of code, which reproduces the problem. You don't need READ_TEXT, SAVE_TEXT and so on to reproduce the container problem.

This is a program with container NOT CLEARED. I hope you see the interest of sharing a minimal example program for fast resolution. Good luck!

REPORT.
TABLES sscrfields.
DATA go_textedit TYPE REF TO cl_gui_textedit.
PARAMETERS dummy TYPE string.

AT SELECTION-SCREEN OUTPUT .
  IF go_textedit IS NOT BOUND.
    CREATE OBJECT go_textedit
      EXPORTING
        parent = cl_gui_container=>screen0.
    go_textedit->set_textstream( dummy ).
  ENDIF.

AT SELECTION-SCREEN ON EXIT-COMMAND.
  IF go_textedit IS BOUND.
    go_textedit->free( ).
    FREE go_textedit.
  ENDIF.

AT SELECTION-SCREEN.
  go_textedit->get_textstream( IMPORTING text = dummy ).
  cl_gui_cfw=>flush( ).
  IF sscrfields-ucomm = 'ONLI'.
    MESSAGE 'Any processing...' TYPE 'I'.
  ENDIF.
  sscrfields-ucomm = VALUE #( ).