cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic programming - Custom field layout

matteo_montalto
Contributor
0 Kudos

Hello gurus,

in our SRM system, we organize dinamically our custom fields layout via a simple routine in WDDOMODIFYVIEW, with the following logic:

  • we defined two different containers, let's call them left_container and right_container, in order to organize fields in two columns;

     lv_container_name_left = 'LEFT_CONTAINER'.

     lv_container_name_right = 'RIGHT_CONTAINER'.

     wd_this->mo_dodm_ctr_h_bd->/sapsrm/if_cll_do_mapper~init_field_extensions(

       EXPORTING

         iv_container_name       = lv_container_name_left

         iv_container_name_right = lv_container_name_right

         iv_view                 = view ).

  • we get the list of custom fields using a custom method; we then loop over them and, using the information we retrieve from a customer table, we place each single item in the left or the right container: here's a sketch of code:

     LOOP AT lt_header_csf INTO ls_header_csf.

* Concatenate attribute id and label

       CONCATENATE ls_header_csf-field_name '_ATTR'  INTO lv_attr_id.

       CONCATENATE ls_header_csf-field_name '_LABEL' INTO lv_label_id.

       lo_ui_element_attr  ?= view->get_element( lv_attr_id ).

       lo_ui_element_label ?= view->get_element( lv_label_id ).

....

       lo_container ?= view->get_element( lv_container_name_cuf ).

       IF lo_container IS BOUND.

         lo_container->set_visible( cl_wd_uielement=>e_visible-visible ).

       ENDIF.

....     

       CASE ls_header_csf-container_pos. "info from customer configuration table

         WHEN zr7_cl_pdo=>gc_left.

           lo_container ?= view->get_element( lv_container_name_left ).

         WHEN zr7_cl_pdo=>gc_right.

           lo_container ?= view->get_element( lv_container_name_right ).

         WHEN OTHERS.

           lo_container ?= view->get_element( lv_container_name_left ).

       ENDCASE.

* finally, we add the couple description label - field to the container:

       lo_container->add_child( the_child = lo_ui_element_label ).

      lo_container->add_child( the_child = lo_ui_element_attr ).

    ENDLOOP.

The above logic works fine and results are visible in the attached screenshot (custfields.png) ; as you can see, fields are organized in two distinct columns:

Now, the question: we'd like to have two custom fields aligned on the same row on the same container; specifically, we'd like to have "Min.Amount Guaranteed" and "Currency", which are the last two fields on the right container, on a single line. Photoshop helps here; we like to obtain this:

I thought this could be obtained creating a new transparent container, adding on this the two fields and then adding the transparent container to the right container. Here's a sketch of code I tried:

"create a transparent container

    IF ls_header_csf-field_name = 'ZZ_MIN_GAR'. " processed before ZZ_MIN_CURRENCY in the loop

      DATA: transparent_container TYPE REF TO CL_WD_TRANSPARENT_CONTAINER.

      transparent_container = cl_wd_transparent_container=>new_transparent_container( ).

      transparent_container->add_child( the_child = lo_ui_element_label ).

      transparent_container->add_child( the_child = lo_ui_element_attr ).

     ELSEIF ls_header_csf-field_name = 'ZZ_MIN_CURRENCY'. "processed after ZZ_MIN_GAR in the loop

      transparent_container->add_child( the_child = lo_ui_element_label ).

     transparent_container->add_child( the_child = lo_ui_element_attr ).

* add the transparent container to the right container 

    lo_container->add_child( the_child = transparent_container ).

...

However, I got a dump (lately, as on the single instructions it doesn't provide and sy-subrc <> 0): I'm definitely missing something, like configuration of the transparent container so that data in it should be organized with a matrix layout, and so on.

Could anyone of you gurus provide me an help or suggestion in order to achieve the desiderata?

Thanks you very much,

kind regards.

Message was edited by: Matteo Montalto

Accepted Solutions (0)

Answers (1)

Answers (1)

matteo_montalto
Contributor
0 Kudos

Ok, did it!

Here's how:

I created two different transparent container as sub-container of the right container, as shown below:

Then I managed via code that the first couple label-field has to be assigned to INLINE_CONTAINER_LEFT, while the second couple label-field (currency) has to be assigned to INLINE_CONTAINER_RIGHT. Here's the code:

IF ls_header_csf-field_name = 'ZZ_MIN_GAR'.

         DATA: new_container            TYPE REF TO cl_wd_uielement_container.

         DATA: top_container            TYPE REF TO cl_wd_uielement_container.

         new_container ?= view->get_element( 'INLINE_CONTAINER_LEFT' ).

         new_container->add_child( the_child = lo_ui_element_label ).

         new_container->add_child( the_child = lo_ui_element_attr ).

         top_container ?= new_container->get__parent( ).

         top_container->remove_child( id = 'INLINE_CONTAINER_LEFT' ).

         lo_container->add_child( the_child = new_container ).

....

         IF ls_header_csf-field_name = 'ZZ_MIN_CURRENCY'.

           new_container ?= view->get_element( 'INLINE_CONTAINER_RIGHT' ).

           new_container->add_child( the_child = lo_ui_element_label ).

           new_container->add_child( the_child = lo_ui_element_attr ).

           top_container ?= new_container->get__parent( ).

           top_container->remove_child( id = 'INLINE_CONTAINER_RIGHT' ).

           lo_container->add_child( the_child = new_container ).

And that worked but... there's a little thing I'd like to solve.

Up to now, the resulting view is shown as below:

As you can see, the couple field-label are not aligned to the previous one (which are in TC_CTR_CAA_RIGHT); I'd like to have "Min.Amount Guaranteed" aligned w.r.t. the previous fields, and "Currency" on its right.
Tried also to work on width parameters on the Transparent Container but every change I made didn't affect the spacing in the view. Could anyone help me with that?

Thanks,

M.