You are on page 1of 7

HR-ABAP Automatic text identification for

Infotype Fields
Skip to end of sidebar
Go to start of sidebar
Skip to end of metadata
Created by Abhijit Zope, last modified on Sep 11, 2008

Go to start of metadata

Automatic text identification Interface: IF_TEXT_IDENTIFIER


Methods: IDENTIFY_TEXT, READ_TEXT
Standard class: CL_TEXT_IDENTIFIER

HR Text Identification Interface: IF_TEXT_IDENTIFIER


Methods: IDENTIFY_TEXT, READ_TEXT
class: CL_HR_TEXT_IDENTIFIER

CL_HR_TEXT_IDENTIFIER implemeted the interface IF_TEXT_IDENTIFIER and useful for fetch the text values
for infotype fields. This class is mostly used in SAP Queries, but can be help in reports also. I have given the
sample program which will illustrate how to use this class and fetch the single as well as multiple field's text
values for HR infotypes.

*&---------------------------------------------------------------------*
*& Report Z_ABHI_READ_INFTY_TEXT_VALUES
*&
*&---------------------------------------------------------------------*
*& SAMPLE PROGRAM TO READ TEXT VALUE FOR INFOTYPE FIELDS
*& (1) READ TEXT VALUES FOR MULTIPLE FIELDS OF INFOTYPE
*& (2) READ TEXT VALUE FOR SINGLE FIELD OF INFOTYPE
*&---------------------------------------------------------------------*
REPORT z_abhi_read_infty_text_values.
TABLES: pernr.
NODES: peras.
INFOTYPES: 0001.
TYPE-POOLS:txid.
TYPES: BEGIN OF ty_data,
p0001_pernr TYPE pernr_d,
p0001_werks LIKE p0001-werks,
text_p0001_werks LIKE t500p-name1,
p0001_btrtl LIKE p0001-btrtl,
text_p0001_btrtl LIKE t001p-btext,
p0001_kostl LIKE p0001-kostl,
text_p0001_kostl LIKE hrca_costc-name,
text_p0001_orgeh LIKE p1000-stext,
p0001_persg LIKE p0001-persg,
text_p0001_persg LIKE t501t-ptext,
p0001_persk LIKE p0001-persk,
text_p0001_persk LIKE t503t-ptext,
text_p0001_sachp LIKE t526-sachn,
END OF ty_data.
DATA: gt_data TYPE STANDARD TABLE OF ty_data,
gs_data LIKE LINE OF gt_data.
DATA:gv_x_molga TYPE molga,
gv_dummy_land1 TYPE land1.
DATA: text_p001_werks TYPE string.
START-OF-SELECTION.
GET peras.
rp_provide_from_last p0001 space pn-begda pn-endda.
gs_data-p0001_pernr = p0001-pernr.
gs_data-p0001_werks = p0001-werks.
gs_data-p0001_btrtl = p0001-btrtl.
gs_data-p0001_kostl = p0001-kostl.
gs_data-p0001_persg = p0001-persg.
gs_data-p0001_persk = p0001-persk.

*GET COUNTRY DETAILS


PERFORM get_country_info USING p0001-werks
CHANGING gv_x_molga
gv_dummy_land1.
********************************************************************
*(1) GET THE TEXT FOR INFOTYPE FIELDS (TO READ MULTIPLE VALUES)
********************************************************************
PERFORM get_text USING p0001
CHANGING gs_data.
APPEND gs_data TO gt_data.
CLEAR: gs_data.
********************************************************************
*(2) GET THE TEXT FOR INFOTYPE FIELD (TO READ SINGLE VALUE)
********************************************************************
PERFORM text_get_new USING 'P0001'
'WERKS'
p0001-werks
CHANGING text_p001_werks.
WRITE:/ p0001-werks,'-',text_p001_werks.

END-OF-SELECTION.
*DISPLAY RECORDS IN ALV
PERFORM display_data_alv.

*&---------------------------------------------------------------------*
*& Form get_country_info
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->WERKS text
* -->MOLGA text
* -->LAND1 text
*----------------------------------------------------------------------*
FORM get_country_info USING werks TYPE persa
CHANGING molga TYPE molga
land1 TYPE land1.
TYPES: BEGIN OF t_s_country_info,
persa TYPE persa,
molga TYPE molga,
land1 TYPE land1,
END OF t_s_country_info.
TYPES: t_t_country_info TYPE STANDARD TABLE OF t_s_country_info.
STATICS: country_info_buf TYPE t_t_country_info.
DATA: country_info_buf_wa TYPE t_s_country_info.
CLEAR molga.
CLEAR land1.
READ TABLE country_info_buf INTO country_info_buf_wa
WITH KEY persa = werks.
IF sy-subrc <> 0.
SELECT SINGLE molga land1 FROM t500p
INTO CORRESPONDING FIELDS OF country_info_buf_wa
WHERE persa = werks.
country_info_buf_wa-persa = werks.
APPEND country_info_buf_wa TO country_info_buf.
ENDIF.
molga = country_info_buf_wa-molga.
land1 = country_info_buf_wa-land1.
ENDFORM. "get_country_info
*&---------------------------------------------------------------------*
*& Form get_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P0001 text
* -->GS_DATA text
*----------------------------------------------------------------------*
FORM get_text USING p0001 TYPE p0001
CHANGING gs_data TYPE ty_data.
DATA: lv_txid_special_paras TYPE tfieldval,
lv_txid_special_paras_wa TYPE sfieldval,
lv_txid_results TYPE txid_t_text_identifier_result,
lv_txid_fieldnames TYPE ttfieldname,
lv_text_identifier_obj TYPE REF TO cl_hr_text_identifier.
FIELD-SYMBOLS: <lv_txid_results_wa> TYPE txid_s_text_identifier_result.
DATA: lv_evaluation_begda TYPE d,
lv_evaluation_endda TYPE d.
CONSTANTS: lv_c_tclas_a TYPE tclas VALUE 'A'.
CREATE OBJECT lv_text_identifier_obj.
** store special parameters for reading text fields{*}
CLEAR lv_txid_special_paras[].
** store BEGIN_DATE{*}
lv_txid_special_paras_wa-fieldname = 'BEGIN_DATE'.
GET REFERENCE OF p0001-begda INTO lv_txid_special_paras_wa-fieldvalue.
APPEND lv_txid_special_paras_wa TO lv_txid_special_paras.
** store END_DATE{*}
lv_txid_special_paras_wa-fieldname = 'END_DATE'.
GET REFERENCE OF p0001-endda INTO lv_txid_special_paras_wa-fieldvalue.
APPEND lv_txid_special_paras_wa TO lv_txid_special_paras.
** store TCLAS{*}
lv_txid_special_paras_wa-fieldname = 'TCLAS'.
GET REFERENCE OF lv_c_tclas_a INTO lv_txid_special_paras_wa-fieldvalue.
APPEND lv_txid_special_paras_wa TO lv_txid_special_paras.
** store INFTY_0001{*}
lv_txid_special_paras_wa-fieldname = 'INFTY_0001'.
GET REFERENCE OF p0001 INTO lv_txid_special_paras_wa-fieldvalue.
APPEND lv_txid_special_paras_wa TO lv_txid_special_paras.
** store MOLGA{*}
lv_txid_special_paras_wa-fieldname = 'MOLGA'.
GET REFERENCE OF gv_x_molga INTO lv_txid_special_paras_wa-fieldvalue.
APPEND lv_txid_special_paras_wa TO lv_txid_special_paras.

CLEAR lv_txid_fieldnames[].
APPEND 'WERKS' TO lv_txid_fieldnames.
APPEND 'BTRTL' TO lv_txid_fieldnames.
APPEND 'KOSTL' TO lv_txid_fieldnames.
APPEND 'ORGEH' TO lv_txid_fieldnames.
APPEND 'PERSG' TO lv_txid_fieldnames.
APPEND 'PERSK' TO lv_txid_fieldnames.
APPEND 'SACHP' TO lv_txid_fieldnames.

CALL METHOD lv_text_identifier_obj->read_text


EXPORTING
tabname = 'P0001'
* FIELDNAME =
fieldnames = lv_txid_fieldnames
record = p0001
record_specified = 'X'
* LANGUAGE = SY-LANGU
special_parameters = lv_txid_special_paras
* VALUESOURCE_TABLES =
IMPORTING
* TEXT =
* TEXT_FOR_VALUE_READ =
text_identifier_results = lv_txid_results
EXCEPTIONS
internal_error = 1
illegal_call = 2
illegal_table = 3
illegal_field = 4
no_text = 5
record_required = 6
illegal_record = 7
table_record_required = 8
illegal_table_record = 9
special_parameter_mismatch = 10
OTHERS = 11.
IF sy-subrc = 0.
LOOP AT lv_txid_results ASSIGNING <lv_txid_results_wa>.
CASE <lv_txid_results_wa>-fieldname.
WHEN 'WERKS'.
gs_data-text_p0001_werks = <lv_txid_results_wa>-text.
WHEN 'BTRTL'.
gs_data-text_p0001_btrtl = <lv_txid_results_wa>-text.
WHEN 'KOSTL'.
gs_data-text_p0001_kostl = <lv_txid_results_wa>-text.
WHEN 'ORGEH'.
gs_data-text_p0001_orgeh = <lv_txid_results_wa>-text.
WHEN 'PERSG'.
gs_data-text_p0001_persg = <lv_txid_results_wa>-text.
WHEN 'PERSK'.
gs_data-text_p0001_persk = <lv_txid_results_wa>-text.
WHEN 'SACHP'.
gs_data-text_p0001_sachp = <lv_txid_results_wa>-text.
ENDCASE.
ENDLOOP.
ENDIF.
ENDFORM. " GET_TEXT

*&---------------------------------------------------------------------*
*& Form display_data_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_data_alv.
DATA: lo_table TYPE REF TO cl_salv_table,
lo_functions TYPE REF TO cl_salv_functions,
lo_columns TYPE REF TO cl_salv_columns_table,
lo_column TYPE REF TO cl_salv_column_table,
lo_selections TYPE REF TO cl_salv_selections,
lt_column TYPE salv_t_column,
lo_display TYPE REF TO cl_salv_display_settings.
DATA: lo_sorts TYPE REF TO cl_salv_sorts.

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_table
CHANGING
t_table = gt_data ).
CATCH cx_salv_msg.
ENDTRY.
lo_functions = lo_table->get_functions( ).
lo_functions->set_all( if_salv_c_bool_sap=>true ).
lo_display = lo_table->get_display_settings( ).
lo_display->set_striped_pattern( cl_salv_display_settings=>true ).
lo_display->set_list_header( 'TEXT VALUES FOR INFOTYPE FIELDS' ).
lo_columns = lo_table->get_columns( ).
lo_columns->set_optimize( if_salv_c_bool_sap=>true ).
lo_table->display( ).
ENDFORM. "display_data_alv
*&---------------------------------------------------------------------*
*& Form text_get_new
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TABNAME text
* -->P_FIELD text
* -->P_VALUE text
* -->P_TEXT text
*----------------------------------------------------------------------*
FORM text_get_new USING p_tabname TYPE tabname
p_field TYPE fieldname
p_value TYPE any
CHANGING p_text TYPE any.
DATA: l_ref_text_read TYPE REF TO cl_hr_text_identifier.
DATA: l_text TYPE text255.
IF l_ref_text_read IS INITIAL.
CREATE OBJECT l_ref_text_read.
ENDIF.
CALL METHOD l_ref_text_read->if_text_identifier~read_text
EXPORTING
tabname = p_tabname
fieldname = p_field
fieldvalue = p_value
language = sy-langu
IMPORTING
text = l_text
EXCEPTIONS
internal_error = 1
illegal_call = 2
illegal_table = 3
illegal_field = 4
no_text = 5
record_required = 6
illegal_record = 7
table_record_required = 8
illegal_table_record = 9
special_parameter_mismatch = 10
OTHERS = 11.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF sy-subrc EQ 0.
p_text = l_text.
ELSE.
CLEAR p_text.
ENDIF.
ENDFORM. " text_get_new

References:
http://help.sap.com/saphelp_nw04/helpdata/en/d9/9958e0c50a11d396f80000e82de14a/frameset.htm
IF_TEXT_IDENTIFIER: Interface Documentaion