Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

create a text field , a box and an input/output field objects in run time

Hello;

I write code with ABAP Object Oriented.

I would like to create a text field , a box and an input/output field objects in run time proses.

Which classes are using in program. And please send exam or exam's link.

Thaks.

replied

Hey Melih,

Our normal ALV class ( cl_gui_alv_grid ) can also be used to

create dynamic buttons/io fields/dropdown list boxes/....

This cannot be the solution but surely can be a very useful

workaround.

Believe me, after removing the toolbar stuffs and combining

them with splitters they look very much like dynamically created

screen elements.

Once i hav used it to create dynammic buttons.Im attaching it

as example here...

Screen flow logic

PROCESS BEFORE OUTPUT.
  MODULE pbo_0100.

PROCESS AFTER INPUT.
  MODULE pai_0100 AT EXIT-COMMAND.

No need of any custom container on screen.

Program

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS : toolbar_handle FOR EVENT toolbar      OF cl_gui_alv_grid IMPORTING e_object,
              click_handle   FOR EVENT button_click OF cl_gui_alv_grid IMPORTING es_col_id.

ENDCLASS.                    "lcl_event_handler DEFINITION

DATA : go_splitter   TYPE REF TO cl_gui_splitter_container,
       go_container1 TYPE REF TO cl_gui_container,
       go_container2 TYPE REF TO cl_gui_container,
       go_buttons    TYPE REF TO cl_gui_alv_grid,
       event_handler TYPE REF TO lcl_event_handler.

PARAMETER buttons TYPE num10 OBLIGATORY DEFAULT '10'.


CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  pbo_0100  OUTPUT                                       *
*&---------------------------------------------------------------------*
MODULE pbo_0100 OUTPUT.
  SET PF-STATUS 'BASIC'. " Just a BACK button function type = 'E'
  PERFORM split_the_screen.
  PERFORM create_buttons.

ENDMODULE.                 " pbo_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  pai_0100  INPUT                                        *
*&---------------------------------------------------------------------*
MODULE pai_0100 INPUT.
  SET SCREEN 0. LEAVE SCREEN.
ENDMODULE.                 " pai_0100  INPUT

*&--------------------------------------------------------------------*
FORM split_the_screen.
  CHECK go_splitter IS NOT BOUND.
  CREATE OBJECT go_splitter EXPORTING parent = cl_gui_container=>default_screen.
  go_splitter->set_grid( rows = 1 columns = 2 ).
  go_splitter->set_column_width(  id = 2 width = 10 ).
  go_container1 = go_splitter->get_container( row = 1 column = 1 ).
  go_container2 = go_splitter->get_container( row = 1 column = 2 ).
  go_splitter->set_border( '0' ).
ENDFORM.                    "split_the_screen
*&--------------------------------------------------------------------*
FORM create_buttons.

  TYPES : BEGIN OF ty_buttons,
          celltab TYPE lvc_t_styl,
          button TYPE char9,
          END   OF ty_buttons.

  DATA  : lt_buttons  TYPE TABLE OF ty_buttons WITH HEADER LINE,
          lt_fieldcat TYPE lvc_t_fcat          WITH HEADER LINE,
          ls_layout   TYPE lvc_s_layo,
          ls_cellline TYPE lvc_s_styl,
          lt_celltab  TYPE lvc_t_styl,
          lv_index    TYPE char2.

  lt_fieldcat-fieldname = 'BUTTON'.
  lt_fieldcat-outputlen = 9.
  APPEND lt_fieldcat.
  CLEAR  lt_fieldcat.

  ls_layout-stylefname = 'CELLTAB'.
  ls_layout-no_headers = abap_true.

  ls_cellline-style     = '20000000'.
  INSERT ls_cellline INTO lt_celltab INDEX 1.

  DO buttons TIMES.
    lt_buttons-celltab = lt_celltab.
    MOVE sy-index TO lv_index.
    CONCATENATE `Button ` lv_index INTO lt_buttons-button.
    APPEND lt_buttons.
  ENDDO.

  CHECK go_buttons IS NOT BOUND.
  CREATE OBJECT go_buttons EXPORTING i_parent = go_container2.
  CREATE OBJECT event_handler.
  SET HANDLER : event_handler->toolbar_handle FOR go_buttons,
                event_handler->click_handle   FOR go_buttons.
  go_buttons->set_table_for_first_display( EXPORTING is_layout       = ls_layout
                                           CHANGING  it_outtab       = lt_buttons[]
                                                     it_fieldcatalog = lt_fieldcat[] ).
ENDFORM.                    "create_buttons

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION                        *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD toolbar_handle.
    FREE e_object->mt_toolbar.
  ENDMETHOD. "toolbar_handle
  METHOD click_handle.
    BREAK-POINT.
  ENDMETHOD.                    "click_handle
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

Cheers,

Jose.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question