SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Using ICON



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 15, 2007 9:23 pm    Post subject: Using ICON Reply with quote

Code:
report z.
include <LIST>.
tables icon.
*----------------------------------------------------------------------*
ranges r_names for icon-name.
types: t_icon    like icon-id,
       t_icons   type table of t_icon,
       t_name    like icon-name,
       t_names   like r_names occurs 0,
       t_flag(1) type c.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
class c_icon definition.
  public section.
    methods:      constructor importing
                    value(p_icon)  type t_icon default space
                    value(p_name)  type t_name optional
                    value(p_names) type t_names optional,
                  is_icon     returning value(p_icon)  type t_icon,
                  is_name     returning value(p_name)  type t_name,
                  is_namex    returning value(p_name)  type t_name,
                  m_array     importing value(p_size)  like sy-tabix
                              exporting       p_icons  type t_icons,
                  m_show,
                  m_showone,
                  m_showall.
    data:         a_row type i,
                  a_col type i.
  protected section.
    methods:      m_rand,
                  is_2only    returning value(p_2only) type t_flag,
                  is_num      returning value(p_num)   like sy-tabix,
                  is_len      returning value(p_len)   type i,
                  m_notfound.
    class-methods is_set2only returning value(p_2only) type t_flag.
  private section.
    data:         a_icon     type t_icons,
                  a_iconcurr type t_icon,
                  a_2only    type t_flag,
                  a_num      like sy-tabix.
    class-data:   f_2only    type t_flag value 'X',
                  c_notfound type t_icon value '@1D@'.
endclass.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
class c_icon implementation.
  method constructor.
    a_2only = f_2only.
    clear: a_row, a_col.
    if not p_icon is initial.
      if f_2only is initial.
        select single id from icon into a_iconcurr
               where id = p_icon.
      else.
        select single id from icon into a_iconcurr
               where id = p_icon
                 and oleng = 2.
      endif.
      if sy-subrc = 0.
        append a_iconcurr to a_icon.
        describe table a_icon lines a_num.
      else.
        call method m_notfound.
      endif.
    elseif not p_name is initial.
      if f_2only is initial.
        select id from icon into table a_icon
               where name = p_name.
      else.
        select id from icon into table a_icon
               where name  = p_name
                 and oleng = 2.
      endif.
      if sy-subrc = 0.
        describe table a_icon lines a_num.
        call method m_rand.
      else.
        call method m_notfound.
      endif.
    elseif not p_names[] is initial.
      if f_2only is initial.
        select id from icon into table a_icon
               where name in p_names.
      else.
        select id from icon into table a_icon
               where name in p_names
                 and oleng = 2.
      endif.
      if sy-subrc = 0.
        describe table a_icon lines a_num.
        call method m_rand.
      else.
        call method m_notfound.
      endif.
    else.
      if f_2only is initial.
        select id from icon into table a_icon.
      else.
        select id from icon into table a_icon
               where oleng = 2.
      endif.
      if sy-subrc = 0.
        describe table a_icon lines a_num.
        call method m_rand.
      else.
        call method m_notfound.
      endif.
    endif.
  endmethod.
  method is_icon.
    p_icon = a_iconcurr.
  endmethod.
  method is_name.
    select single name from icon into p_name
           where id = a_iconcurr.
    check sy-subrc <> 0.
    clear p_name.
  endmethod.
  method is_namex.
    p_name = is_name( ).
    check p_name(5) = 'ICON_'.
    p_name = p_name+5.
  endmethod.
  method m_array.
    data: w_icon like a_iconcurr,
          w_num  like a_num.
    w_icon = a_iconcurr.
    clear p_icons[].
    if a_num > p_size.
      do.
        call method m_rand.
        append a_iconcurr to p_icons.
        sort p_icons.
        delete adjacent duplicates from p_icons.
        describe table p_icons lines w_num.
        check w_num >= p_size.
        exit.
      enddo.
    else.
      loop at a_icon into a_iconcurr.
        append a_iconcurr to p_icons.
      endloop.
    endif.
    a_iconcurr = w_icon.
  endmethod.
  method m_show.
    if a_col is initial.
      write a_iconcurr as icon hotspot.
    else.
      write at a_col a_iconcurr as icon hotspot.
    endif.
  endmethod.
  method m_showone.
    call method: m_rand, m_show.
  endmethod.
  method m_showall.
    data w_icon like a_iconcurr.
    w_icon = a_iconcurr.
    loop at a_icon into a_iconcurr.
      call method m_show.
    endloop.
    a_iconcurr = w_icon.
  endmethod.
  method is_set2only.
    p_2only = f_2only.
  endmethod.
  method is_2only.
    p_2only = a_2only.
  endmethod.
  method is_num.
    p_num = a_num.
  endmethod.
  method is_len.
    select single oleng into p_len from icon
           where id = a_iconcurr.
    check sy-subrc <> 0.
    clear p_len.
  endmethod.
  method m_rand.
    data w_i type i.
    if a_num > 0.
      call function 'QF05_RANDOM_INTEGER'
        exporting
          ran_int_max         = a_num
          ran_int_min         = 1
        importing
          ran_int             = w_i
        exceptions
          invalid_input       = 1
          others              = 2.
      if sy-subrc = 0.
        read table a_icon index w_i into a_iconcurr.
      endif.
    endif.
  endmethod.
  method m_notfound.
    write: / c_notfound as icon, 'Icons not found...'.
  endmethod.
endclass.
*----------------------------------------------------------------------*

*======================================================================*
type-pools: vrm.
data: it_val type vrm_values,
      w_line like line of it_val.

selection-screen:  begin of line,
                   comment (14) ps_icon,
                   end of line,

                   begin of line,
                   position 10.
parameters         p_pict radiobutton group two.
selection-screen   comment (13) ps_pict.
parameters         p_text radiobutton group two.
selection-screen:  comment (13) ps_text,
                   end of line,

                   begin of line,
                   position 10,
                   comment (22) ps_diff.
parameters         p_diff like sy-tabix as listbox
                   visible length 16 obligatory default 5.
selection-screen:  end of line,

                   begin of line,
                   position 10,
                   comment (24) ps_them.
select-options     p_them for icon-name no intervals.
selection-screen   end of line.

*----------------------------------------------------------------------*


*======================================================================*
INITIALIZATION.
*----------------------------------------------------------------------*
  ps_icon = 'Icon quiz:'.
  ps_pict = 'Guess picture'.
  ps_text = 'Guess meaning'.
  ps_diff = 'Difficulty (2-easiest)'.
  ps_them = 'Theme (e.g. *WORKFLOW*)'.

  w_line-key  = 2.
  w_line-text = '??'.
  do 9 times.
    append w_line to it_val.
    add 1 to w_line-key.
    concatenate w_line-text '?' into w_line-text.
  enddo.

*======================================================================*
AT SELECTION-SCREEN OUTPUT.
*----------------------------------------------------------------------*
  call function 'VRM_SET_VALUES'
       exporting
            id     = 'P_DIFF'
            values = it_val.

*======================================================================*
START-OF-SELECTION.
*----------------------------------------------------------------------*
  data: o_1     type ref to c_icon,
        o_1saved    type ref to c_icon,
        w_name  type t_name,
        wr_name type t_names,
        w_icons type t_icons,
        w_icon  type t_icon,
        w_iconsaved type t_icon,
        w_num   like sy-tabix,
        w_numsaved  like sy-tabix,
        w_field(20),
        w_value(40),
        w_n_ok  like sy-tabix,
        w_n_all like w_n_ok.
  wr_name[] = p_them[].
  create object o_1saved exporting p_icon = space p_names = wr_name.

*======================================================================*
END-OF-SELECTION.
*----------------------------------------------------------------------*
  perform display_icons.

*======================================================================*
AT LINE-SELECTION.
*----------------------------------------------------------------------*
  get cursor field w_field value w_value.
  if sy-subrc <> 0.
    message s899(mm) with 'Click on your choice'.
  endif.
  if not p_pict is initial.
    if w_field <> 'W_NAME'.
      message s899(mm) with 'Click on the name for the icon'.
    else.
      add 1 to w_n_all.
      create object o_1 exporting p_icon = w_iconsaved.
      w_name = o_1->is_namex( ).
      subtract 1 from sy-lsind.
      if w_name = w_value.
        add 1 to w_n_ok.
      else.
        perform inform_about_error.
      endif.
      perform display_icons.
    endif.
  else.
    if w_field <> 'W_VALUE'.
      message s899(mm) with 'Click on the icon for the name'.
    else.
      add 1 to w_n_all.
      w_value+3 = '@'.
      subtract 1 from sy-lsind.
      if w_iconsaved = w_value.
        add 1 to w_n_ok.
      else.
        perform inform_about_error.
      endif.
      perform display_icons.
    endif.
  endif.

*&---------------------------------------------------------------------*
*&      Form  initial_show_pict
*&---------------------------------------------------------------------*
FORM initial_show_pict.
  perform statistic.
  write / 'Choose name for the icon:'.
  create object o_1 exporting p_icon = w_iconsaved.
  call method o_1->m_show.
  loop at w_icons into w_icon.
    create object o_1 exporting p_icon = w_icon.
    w_name = o_1->is_namex( ).
    write / w_name hotspot.
  endloop.
ENDFORM.                    " initial_show_pict
*&---------------------------------------------------------------------*
*&      Form  initial_show_text
*&---------------------------------------------------------------------*
FORM initial_show_text.
  perform statistic.
  write / 'Choose icon for the name:'.
  create object o_1 exporting p_icon = w_iconsaved.
  w_name = o_1->is_namex( ).
  write / w_name.
  loop at w_icons into w_icon.
    skip.
    call function 'ICON_CREATE'
      exporting
          name                  = w_icon
          text                  = space
          info                  = 'N/A'
          add_stdinf            = 'X'
      importing
          result                = w_value
      exceptions
          icon_not_found        = 1
          outputfield_too_short = 2
          others                = 3.
    if sy-subrc = 0.
      write w_value.
    else.
      create object o_1 exporting p_icon = w_icon.
      call method o_1->m_show.
      message s899(mm) with 'Cannot continue. FM error.'.
    endif.
  endloop.
ENDFORM.                    " initial_show_text
*&---------------------------------------------------------------------*
*&      Form  get_random_int
*&---------------------------------------------------------------------*
FORM get_random_int CHANGING p_int type i.
  call function 'QF05_RANDOM_INTEGER'
        exporting
          ran_int_max         = p_int
          ran_int_min         = 1
        importing
          ran_int             = p_int
        exceptions
          invalid_input       = 1
          others              = 2.
  if sy-subrc <> 0.
    p_int = 1.
  endif.
ENDFORM.                    " get_random_int
*&---------------------------------------------------------------------*
*&      Form  statistic
*&---------------------------------------------------------------------*
FORM statistic.
  write: 'Solved OK:', w_n_ok, 'from', w_n_all.
ENDFORM.                    " statistic
*&---------------------------------------------------------------------*
*&      Form  inform_about_error
*&---------------------------------------------------------------------*
FORM inform_about_error.
  write: / 'Not correct.'.
  loop at w_icons into w_icon.
    create object o_1 exporting p_icon = w_icon.
    w_name = o_1->is_namex( ).
    write / w_name.
    call method o_1->m_show.
  endloop.
  skip.
ENDFORM.                    " inform_about_error
*&---------------------------------------------------------------------*
*&      Form  display_icons
*&---------------------------------------------------------------------*
FORM display_icons.
  call method o_1saved->m_array exporting p_size = p_diff
                                importing p_icons = w_icons.
  describe table w_icons lines w_numsaved.
  if w_numsaved > 0.
    w_num = w_numsaved.
    perform get_random_int changing w_num.
    read table w_icons index w_num into w_iconsaved.
    if not p_pict is initial.
      perform initial_show_pict.
    else.
      perform initial_show_text.
    endif.
  endif.
ENDFORM.                    " display_icons
*--- End Of Code ---
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.