Skip to Content
0
Former Member
May 06, 2013 at 09:48 AM

Want to code for voice recognition in sap??

339 Views

i have develop new field validation by using voice synthesizer using abap code ,

now i want to develop recognition code pls help.

*------------------------Declare Include-------------------*
INCLUDE ole2incl.
DATA : ole TYPE ole2_object,
voice TYPE ole2_object,
text TYPE string.

TABLES: MARA , MAKT.
TYPE-POOLS: SLIS.
TYPES: BEGIN OF TY_MARA,
MATNR TYPE MATNR,
MATKL TYPE MATKL,
END OF TY_MARA.
*---------TYPES DECLATRATION---------------*
TYPES : BEGIN OF TY_MAKT ,
MATNR TYPE MATNR ,
MAKTX TYPE MAKTX,
END OF TY_MAKT.

TYPES : BEGIN OF TY_FINAL,
MATNR TYPE MATNR ,
MAKTX TYPE MAKTX,
MATKL TYPE MATKL,
END OF TY_FINAL.

*-------------------INTERNAL TABLE------------------*
DATA: IT_MARA TYPE TABLE OF TY_MARA,
IT_MAKT TYPE TABLE OF TY_MAKT,
IT_FINAL TYPE TABLE OF TY_FINAL,
WA_MARA TYPE TY_MARA,
WA_MAKT TYPE TY_MAKT,
WA_FINAL TYPE TY_FINAL.
DATA V_MATNR TYPE MARA-MATNR.

DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
*-------------Selection Screen-------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-101.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR,
S_MATKL FOR MARA-MATKL.
SELECTION-SCREEN END OF BLOCK B1.

*--------------------Field Validation---------------------*
AT SELECTION-SCREEN.
SELECT SINGLE matnr FROM mara INTO v_matnr where matnr in s_matnr.
IF sy-subrc <> 0.
CREATE OBJECT voice 'SAPI.SpVoice'.
text = 'YOU ENTER WRONG MATERIAL'. " My field validation "SAPI Voice".
CALL METHOD OF voice 'Speak' = ole
EXPORTING #1 = text.
MESSAGE 'INVALID ENTRY' TYPE 'E'.
ENDIF.

*-----------------------Start of selection-----------------*
START-OF-SELECTION.
PERFORM SELECT.
PERFORM FIELDCAT.
PERFORM DISPLAY.

FORM SELECT.

SELECT MATNR MATKL INTO TABLE IT_MARA FROM MARA WHERE MATNR IN S_MATNR AND MATKL IN S_MATKL.
SELECT MATNR MAKTX INTO TABLE IT_MAKT FROM MAKT FOR ALL ENTRIES IN IT_MARA WHERE MATNR = IT_MARA-MATNR.
LOOP AT IT_MARA INTO WA_MARA.
WA_FINAL-MATNR = WA_MARA-MATNR.
WA_FINAL-MATKL = WA_MARA-MATKL.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MARA-MATNR.
WA_FINAL-MAKTX = WA_MAKT-MAKTX.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.

ENDFORM.
*-------------------Fieldcat---------------------*
FORM FIELDCAT.

WA_FIELDCAT-SELTEXT_M = 'MATERIAL'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-TABNAME = 'MARA'.
WA_FIELDCAT-OUTPUTLEN = 18.
WA_FIELDCAT-ROW_POS = 1.
APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-SELTEXT_M = 'MDESCRIPTION'.
WA_FIELDCAT-FIELDNAME = 'MAKTX'.
WA_FIELDCAT-TABNAME = 'MAKT'.
WA_FIELDCAT-OUTPUTLEN = 40.
WA_FIELDCAT-ROW_POS = 2.
APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-SELTEXT_M = 'M GROUP'.
WA_FIELDCAT-FIELDNAME = 'MATKL'.
WA_FIELDCAT-TABNAME = 'MARA'.
WA_FIELDCAT-OUTPUTLEN = 10.
WA_FIELDCAT-ROW_POS = 3.
APPEND WA_FIELDCAT TO IT_FIELDCAT.

ENDFORM.

*----------------------ALV Function Module-------------------*
FORM DISPLAY.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP '
I_GRID_TITLE = 'MATERIAL NO'
IT_FIELDCAT = IT_FIELDCAT[]
TABLES
t_outtab = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
ENDIF.

ENDFORM.
*---------------------Header & Logo --------------*
FORM TOP.
DATA : IT_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'MATERIAL NO'.
APPEND WA_HEADER TO IT_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
I_LOGO = 'ENJOYSAP_LOGO'
it_list_commentary = IT_HEADER
.
ENDFORM.