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: 

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

former_member212713
Contributor
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

2 REPLIES 2

former_member182046
Contributor
0 Kudos

Hi,

what you're trying to do cannot be fully achieved but approximated. The reason is that ABAP Dynpro doesn't work this way at the core. It's pretty static in that there is no way to create screen objects at run-time without serious hacking.

Every part of a dynpro that is displayed at run-time must be statically defined. This means that every field (text, radiobutton, input), button, listbox etc. must be painted with the screen painter. But at PBO (process before output) time, you can LOOP AT SCREEN and modify some properties of the dynpro elements, such as their visibility, whether or not they're active, whether they're output-only, required, highlighted, etc. When every dynpro element in a line is invisible, the whole line is invisible and the lines below move up.

When you accept some limitations to what possible screens you are going to create dynamically at run-time, it is possible to create a screen that covers the superset of all supported combinations and add functionality to switch elements on and off dynamically in order to arrive at just the combination of screen elements defined at run-time.

This way, you can create pseudo-dynamic dynpros. I used this to create a framework for object-oriented definition of selection-screens once, in which you could create objects for select-options, link them to a screen object, and query them for the data a user entered. At the core was a static selection-screen subscreen with many identical select-optionals whose appearance depended on the contents of some internal tables I had populated.

If you want to try this, too, a useful syntax construct is

SELECT-OPTIONS s_xxx TYPE (lv_typename).

If you want to be seriously dynamic, there's another way but it's going to be a rough patch. Check out the documentation for

IMPORT DYNPRO 
EXPORT DYNPRO
GENERATE DYNPRO 

This allows you to generate dynpros. They will be generated as static objects. It will take you quite some work to figure out how exactly to create the various types of screen elements, and you're going to be alone when you need support because the feature is not released for customers, but it's good to know it if you're really desperate or just feeling playful.

Regards,

Thorstem

Former Member
0 Kudos

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.