Home > SAP Tips > ABAP/Java developer tips > Spell checker for SAP GUI fields
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ABAP/JAVA DEVELOPER TIPS

Spell checker for SAP GUI fields


Athavan Raja
07.09.2003
Rating: -4.53- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
ABAP/Java developer tips
Fixing a common OPEN_FORM and START_FORM error in SAPscript
Select Text fields: Case-insensitive
Finding BADIs you can use
Is this the quickest way to find a BADI?
ABAP Objects in SAP Workflow to provide improved performance
Easily debug error messages in SAP processes
Accessing private attributes in ABAP Objects
Find a BADI in a minute
Top 10 SAP tips of 2007
How to transport an SAP query in R/3 4.6x

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



NetWeaver SAP White Papers
HomeNewsTopicsBlogsTipsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts