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: 

write text with cl_gui_dialogbox_container

Former Member
0 Kudos

Hi all,

I have a dialogbox container cl_gui_dialogbox_container and I need a way to write something inside of it(WRITE 'hello world'), without using alv classes.

Are there some classes to use?

Should i create a dynpro?

can you help me?

Thanks.

Tony

1 ACCEPTED SOLUTION

Former Member

Hi Tony,

check sample code, which I have used to create a popup with text without creating a dynpro:

*----------------------------------------------------------------------*
*       CLASS lcl_dialogbox_handler DEFINITION
*----------------------------------------------------------------------*
* Definition of dialogbox event handler
*----------------------------------------------------------------------*
CLASS lcl_dialogbox_handler DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      close
        FOR EVENT close
        OF cl_gui_dialogbox_container.
ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* Implementation of dialogbox event handler
*---------------------------------------------------------------------*
CLASS lcl_dialogbox_handler IMPLEMENTATION.
  METHOD close.
* I will free textedit control and dialogbox
    CALL METHOD gr_textedit->free.
    FREE gr_textedit.
    CALL METHOD gr_dialogbox->free.
    FREE gr_dialogbox.
* finally flush
    CALL METHOD cl_gui_cfw=>flush
      EXCEPTIONS
        OTHERS = 1.
  ENDMETHOD." close
ENDCLASS.                    "lcl_dialogbox_handler IMPLEMENTATION

DATA: gr_textedit TYPE REF TO cl_gui_textedit,
      gr_dialogbox TYPE REF TO cl_gui_dialogbox_container,
        gt_text_data TYPE STANDARD TABLE OF char128.


* I will create a dialogbox for displaying text in textedit
  CREATE OBJECT gr_dialogbox
    EXPORTING
      width   = 800
      height  = 400
      top     = 50
      left    = 100
      caption = 'Close Window to end Display'.              "#EC NOTEXT

* I will create a textedit control to display text
  CREATE OBJECT gr_textedit
    EXPORTING
      parent = gr_dialogbox.

* Handler is necessary for closing popup
  SET HANDLER lcl_dialogbox_handler=>close FOR gr_dialogbox.

* I will set text to be displayed
  CALL METHOD gr_textedit->set_text_as_r3table
    EXPORTING
      table           = gt_text_data
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 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.

* I will make text read-only, changing it is meaningless
  gr_textedit->set_readonly_mode( 1 ).

I hope it helps.

Regards

Adrian

2 REPLIES 2

Former Member

Hi Tony,

check sample code, which I have used to create a popup with text without creating a dynpro:

*----------------------------------------------------------------------*
*       CLASS lcl_dialogbox_handler DEFINITION
*----------------------------------------------------------------------*
* Definition of dialogbox event handler
*----------------------------------------------------------------------*
CLASS lcl_dialogbox_handler DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      close
        FOR EVENT close
        OF cl_gui_dialogbox_container.
ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
* Implementation of dialogbox event handler
*---------------------------------------------------------------------*
CLASS lcl_dialogbox_handler IMPLEMENTATION.
  METHOD close.
* I will free textedit control and dialogbox
    CALL METHOD gr_textedit->free.
    FREE gr_textedit.
    CALL METHOD gr_dialogbox->free.
    FREE gr_dialogbox.
* finally flush
    CALL METHOD cl_gui_cfw=>flush
      EXCEPTIONS
        OTHERS = 1.
  ENDMETHOD." close
ENDCLASS.                    "lcl_dialogbox_handler IMPLEMENTATION

DATA: gr_textedit TYPE REF TO cl_gui_textedit,
      gr_dialogbox TYPE REF TO cl_gui_dialogbox_container,
        gt_text_data TYPE STANDARD TABLE OF char128.


* I will create a dialogbox for displaying text in textedit
  CREATE OBJECT gr_dialogbox
    EXPORTING
      width   = 800
      height  = 400
      top     = 50
      left    = 100
      caption = 'Close Window to end Display'.              "#EC NOTEXT

* I will create a textedit control to display text
  CREATE OBJECT gr_textedit
    EXPORTING
      parent = gr_dialogbox.

* Handler is necessary for closing popup
  SET HANDLER lcl_dialogbox_handler=>close FOR gr_dialogbox.

* I will set text to be displayed
  CALL METHOD gr_textedit->set_text_as_r3table
    EXPORTING
      table           = gt_text_data
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 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.

* I will make text read-only, changing it is meaningless
  gr_textedit->set_readonly_mode( 1 ).

I hope it helps.

Regards

Adrian

MarcinPciak
Active Contributor
0 Kudos

Writing with WRITE inside GUI controls like container is of course not possible. The only way you have is either using text editor as suggested above, or by means of other GUI control which can accept writiting to the output stream. This could be i.e. [Dynamic Documents|http://help.sap.com/saphelp_470/helpdata/en/10/246858055711d4a7410000e83dd863/frameset.htm]. See demo program DD_ADD_TEXT .

Regards

Marcin