Skip to Content

I was working on a Dynamic WebDynpro project that built every control at runtime.  The project was a dynamic question/response application where each response to a question dictated which screen element to build next.  In order to facilitate the creation of the screen elements, I built a method of my assistance class which would always provide me back the next available control ID to assign my control.  There are some functions which perform this type of functionality, but I wanted one which gave me only letters in the range A..Z. 

Some examples of next available control name are:

Last Used ID                 Next Available ID

A                                   B

Z                                   AA

AA                                AB

ZZ                                 AAA

AAA                              AAB

Here’s the code I used for the method:

method get_next_unique_gui_id.

  types: begin of output_chars,

           letter type c length 1,

         end of output_chars.

  data: output_chars type standard table of output_chars.

  data: wa_output_chars like line of output_chars.

  data: v_next type i,

        i_strlen type i,

        i type i,

        j type i,

        p_chk_char type c,

        p_out_char type c,

        i_strlen_in_chars type i,

        p_in_chars type string,

        bool_skip_previous type wdy_boolean.

  if unique_gui_ctrl_id is initial.

    unique_gui_ctrl_id = ‘A’.

  else.

    i_strlen = strlen( syabcde ).

    i_strlen_in_chars = strlen( unique_gui_ctrl_id ).

    i = i_strlen_in_chars.

    bool_skip_previous = abap_false.

    p_in_chars = unique_gui_ctrl_id.

    while i gt 0.

      i = i 1.

      p_chk_char = p_in_chars+i(1).

      if bool_skip_previous = abap_false.

        if syabcde cs p_chk_char.

          v_next = syfdpos + 1.

          if v_next = i_strlen.

            v_next = 0.

            p_out_char = syabcde+v_next(1).

            wa_output_charsletter = p_out_char.

            insert wa_output_chars into output_chars index 1.

            bool_skip_previous = abap_false.

            if i eq 0.

              p_out_char = ‘A’.

              wa_output_charsletter = p_out_char.

              insert wa_output_chars into output_chars index 1.

            endif.

          else.

            p_out_char = syabcde+v_next(1).

            wa_output_charsletter = p_out_char.

            insert wa_output_chars into output_chars index 1.

            bool_skip_previous = abap_true.

            j = i 1.

          endif.

        endif.

      else.

        while j ge 0.

          p_out_char = p_in_chars+j(1).

          wa_output_charsletter = p_out_char.

          insert wa_output_chars into output_chars index 1.

          j = j 1.

        endwhile.

      endif.

    endwhile.

    clear unique_gui_ctrl_id.

    loop at output_chars into wa_output_chars.

      concatenate unique_gui_ctrl_id wa_output_charsletter into unique_gui_ctrl_id.

    endloop.

  endif.

  o_unique_gui_ctrl_id = unique_gui_ctrl_id.

endmethod.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply