Spell checker for SAP GUI fields

This tip works like the MS Word spell checker.

This tip works like the MS Word spell checker. The code has been tested in 4.6C on Windows 2000 and Windows XP machines. For this program to work you should have Microsoft Word installed on your machine.

STEP A.
1. Download the file ( Testspellchk.zip) from this link:
http://www.geocities.com/athavan_raja/Testspellchk.zip
2. Unzip the file (Testspellchk.ocx) to your desktop.
3. Register the control. To register start„»run and in the dialog box type in regsvr32.exe and then drag and drop the file (Testspellchk.ocx) you saved onto your desktop in the dialog box and click OK. You will get a message that the registration is successful.

STEP B.
Create a Function module as follows:
a. Import parameter IN_WORD type string
b. Export parameter OUT_WORD TYPE STRING
c. Exception CNTL_ERROR.

Copy and paste the below given code to the Global Data of the function module:

class cl_spell definition
inheriting from cl_gui_control .

public section .

methods:
constructor
importing
!parent type ref to cl_gui_container
value(shellstyle) type i optional
value(disp_mode) type i optional
value(life_time) type i optional
value(name) type string optional
exceptions
cntl_error
cntl_install_error .

methods:
spellcheck
importing
wf_string type any optional
exporting
result type any .

endclass .

data: wf_rstring(120) ,
wf_len type i .
data: spell_checker type ref to cl_spell ,
my_container type ref to cl_gui_custom_container,
wf_t(120) ,
this_repid like sy-repid .

********implementation
class cl_spell implementation .

method constructor.

data: ctrl_name(80) type c ,
wf_clsid(100) type c .

if not cl_gui_object=>activex is initial .
wf_clsid = 'Testspellchk.spellchkctrl' .
else .
raise cntl_error .
endif .

call method super->constructor

exporting
clsid = wf_clsid
shellstyle = shellstyle
lifetime = life_time
name = name
parent = parent
exceptions
cntl_system_error = 1
others = 2 .

case sy-subrc .
when 1 .
raise cntl_install_error .
when 2 .
message w398(00) with 'Control Error' .

endcase .

endmethod .

method spellcheck .
clear wf_rstring .
call method me->call_method
exporting
method = 'SpellCheck'
p1 = wf_string
p_count = 1
queue_only = ' '
importing
result = wf_rstring .

call method cl_gui_cfw=>flush
exceptions cntl_system_error = 1
cntl_error = 2.

if sy-subrc ne 0 .
message w398(00) with 'Control Error' .
endif .
endmethod .

endclass .

Create a screen for the program and place a CUSTOM CONTROL on to the screen and name it OUTPUT_CONTAINER.

Enter the below given code into the Function Module.

FUNCTION Y_SPELL_CHECK.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(IN_WORD) TYPE  STRING
*"  EXPORTING
*"     VALUE(OUT_WORD) TYPE  STRING
*"  EXCEPTIONS
*"      CNTL_ERROR
*"----------------------------------------------------------------------



 if my_container is initial.
    create object my_container
        exporting
            container_name = 'OUTPUT_CONTAINER'
        exceptions
            others = 1.
    case sy-subrc.
      when 0.
      when others.
        raise cntl_error.
    endcase.
  endif .

  if spell_checker is initial.


    create object spell_checker
         exporting
              parent    = my_container .

    if sy-subrc ne 0.
      raise cntl_error.
    endif.
  endif .



  call method spell_checker->spellcheck
      exporting wf_string = in_word
      importing result = wf_rstring .


if not wf_rstring is initial .
clear wf_t .
clear wf_len .
wf_len = strlen( wf_rstring ) .
wf_len = wf_len - 1 .

wf_t = wf_rstring .
wf_t+wf_len(1) = ' ' .
out_word = wf_t .
endif .


if not spell_checker is initial .
        call method spell_checker->free.
        free spell_checker .
      endif .
      if not my_container is initial .
        call method my_container->free.
        free my_container .
      endif .





ENDFUNCTION.

Note: When you call this function module with a wrongly spelled word as input you will get a pop up like word for change/ignore the word.

If changed, the FM returns the changed word else it returns the original word.
This was first published in July 2003

Dig deeper on SAP Java and J2EE

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close