SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Search long text for a string (STXH / STXL )

Search long text for a string (STXH / STXL )

You have a requirement to get all the documents which contact a particular string in the long text.

FM - READ_TEXT would be quite performance expensive and also would require the object name which means you would have to scan through all the documents.

Alternatively you can copy the below code and do a quick scan on the long text.

 


  TYPES: BEGIN OF ty_stxl,
           tdname TYPE stxl-tdname,
           clustr TYPE stxl-clustr,
           clustd TYPE stxl-clustd,
         END OF ty_stxl.

  TYPES: BEGIN OF ty_stxl_raw,
           clustr TYPE stxl-clustr,
           clustd TYPE stxl-clustd,
         END OF ty_stxl_raw.

  DATA:  lt_stxl         TYPE STANDARD TABLE OF ty_stxl.
  DATA:  lt_stxl_raw     TYPE STANDARD TABLE OF ty_stxl_raw.
  DATA:  ls_stxl_raw     TYPE ty_stxl_raw.
  DATA:  lt_tline        TYPE STANDARD TABLE OF tline. 
  DATA:  lt_obj_name     TYPE LOP_TS_TDNAME.

  FIELD-SYMBOLS:  TYPE ty_stxl.
  FIELD-SYMBOLS:  TYPE tline.

*   select long text
  SELECT tdname clustr clustd
      INTO TABLE lt_stxl
      FROM stxl
      PACKAGE SIZE 3000
      WHERE relid    = 'TX'          " Standard text
        AND tdobject = 'Z_OBJECT'    "  Your text object
        AND tdid     = 'Z_TDID'.     "  Your text id

    LOOP AT lt_stxl ASSIGNING .

*     decompress text
      CLEAR: lt_stxl_raw[], lt_tline[].
      ls_stxl_raw-clustr = -clustr.
      ls_stxl_raw-clustd = -clustd.
      APPEND ls_stxl_raw TO lt_stxl_raw.
      IMPORT tline = lt_tline FROM INTERNAL TABLE lt_stxl_raw.

*    Compare the string
      LOOP AT lt_tline ASSIGNING .

         IF -tdline CP  P_DESCR. " 'P_DESCR' is your selection screen field value.
**	   do something.
          ENDIF.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.

    FREE lt_stxl.
  ENDSELECT.

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in