Skip to Content

 Introduction

Text objects are the container for containing long texts in Sap Systems. Text objects reduce the complexity involved in storing long texts and are robust for language translations. Basically Long texts consist of several, usually complete sentences that belong together, therefore cannot be kept in a db Table column because of limitation of 255 characters, that’s why Long texts are kept in Text objects which are uniquely indentified through their text names.

Text objects provide the following capabilities

Predominantly use Store Texts Lines contains more than 255 characters.

  • Dynamic behavior for activating or deactivating Text Objects.
  • A property bag for storing data (Long texts) which can easily translated & transported.

Text Objects & Text IDs

Text Objects can be created through SE75 Transaction code. One text object can contain multiple text ids.Each text id contains multiple Text Names. This logic can be understood through the following scenario.

E.g.:-A Tracker Tool which contains Developments Objects & their status information along with Developers & Testers comments.

Comments can be multiline so can’t not be kept in a table that‘s why text objects come into scenario.

Therefore, each development object should contain two text containers, one is for Developer comments and another one is for Testers Comments.

Now in this scenario, One text object can be created named as Z_DEVOBJ through SE 75 as shown below:-

Step 1:-Go to SE75 Transaction.

image

Step 2:-Click on change button, following screen will appear.

image

Step3:-Now click on Create button. Below screen will be popped up.

image 

Enter the name & Description of Text object. Here in this case, save mode is selected as update because comments data is need to be updated against each development objects table entry In editor ,Editor application is of type Standard Text(TX) and line width is 72 which can be selected as per requirement.

Style and Form can also be selected from this window, which will decide the display style of text.

Step 4:-Once the object is being created, double click on the text object.

Following window will open to create text ids.

image

Step 5:-Create Text ids as shown below.

image 

In this scenario, 2 text Ids will be created as dev comments and testers comments will belong to unique text ids.

Step6:-Once the text ids will be created, front end work is done.

Now the question is that how can you store these comments data against each Text ID.For storing & retrieving long texts, following function modules exist in sap.

1) Read_Text – This function module is used to read text from the text file or text memory.When header information and text lines have been read successfully, they are transferred to the work areas HEADER and LINES of type thead and tline. To get the name of existing text objects & Ids , header table STXH Table can also be viewed.

2) Save_Text – This function module can be used to save existing texts or to create new    texts to the text file or text memory depending upon specific text object. After saving all new text names, STXH & STXL tables can also be checked for verification purpose.

 3) Delete_Text – This function module can be used to delete existing one or more texts modules from the text file or text memory depending upon specific text object. Depending on the text objects, these texts are deleted or flagged in the text memory.

Now have a look on below code snippets to know how to use them:-

First step is to save text objects by using function module save_text.

FORM save_comments.

DATA: e_header TYPE thead, //Work Area to save Text Header information
      i_header TYPE STANDARD TABLE OF thead,//Header Table
      w_tline  TYPE tline,//Work Area to save Text Line

      //Table to keep Text Lines
      i_tline  TYPE STANDARD TABLE OF tline WITH HEADER LINE

     //To pass Text Header Information like Text Object name,Id,Language and no             of characters per line
      e_header-tdobject = ‘ZCHD_OBJ’.
      e_header-tdid = ‘Y0B1’.
      e_header-tdspras = sy-langu.
      e_header-tdlinesize = 72.

//Create Unique Text Name for each Development object ID  

CONCATENATE y0bs_Dev-objid e_header-tdid   INTO e_header-tdname.   

//Assign Dev Comments Data for each Development object ID  

 APPEND ‘Dev Comments for Obj1″ to i_tline-tdline.

//Calling Function Save_Text
CALL FUNCTION ‘SAVE_TEXT’

EXPORTING

    CLIENT                = SY-MANDT  //If Text Object is client dependent

    header                = e_header //Header Details

*   INSERT                = ‘ ‘       //Identify the New Text Module

    SAVEMODE_DIRECT       = ‘X ‘      //Saving Mode saves Text Immediately

*   OWNER_SPECIFIED       = ‘ ‘       //Creator of Text object

* IMPORTING

*   FUNCTION              =           //Processing Status of Text module

*   NEWHEADER             =           //Returns Changed Header Fields

    tables

    lines                 = i_tline  //All text lines belongs to Text module

* EXCEPTIONS

*   ID                    = 1

*   LANGUAGE             = 2

*   NAME                  = 3

*   OBJECT                = 4

*   OTHERS                = 5.
   IF sy-subrc <> 0.
   ENDIF.
   ENDFORM.                    “Save Comments

 

 

This function module saves Long Text into Text Object corresponding to Text Name & Text Id.

Basically this Text Name is uniquely identifies dev comments against each dev objects.

For e.g. – Two Dev object id 1 and 2 have their unique dev comments ,But having same Text Object ZCHD_OBJ and same Text ID -Y0B1.

That’s why to uniquely identifies the dev comments for dev obj 1 and 2, Text names are dynamically created .For e.g. in above code snippet objid & Text id combine together to identify comments for Dev comments for each Object.

After saving text names, their existence can be checked in STXH and STXL Tables where unique text name exists against each Text Objects & Text ID pair.

 

Now, let’s check how to retrieve text objects by using read_text.

FORM get_comments.  
   

DATA: e_header TYPE thead, //Work Area to save Text Header information

      i_tline TYPE STANDARD TABLE OF tline. //Header Table   

     

//To pass Text Header Information like Text Object name, Id, Language and no             of characters per line

      e_header-tdobject = ‘ZCHD_OBJ’.
      e_header-tdid = ‘Y0B1’.
      e_header-tdspras = sy-langu.
      e_header-tdlinesize = 72.

//Create Unique Text Name for each Development object ID  

CONCATENATE y0bs_Dev-objid e_header-tdid INTO e_header-tdname.

//Calling Function Read_Text

CALL FUNCTION ‘READ_TEXT’

  EXPORTING

    CLIENT                        = SY-MANDT       //If Text Object is client dependent

    id                            = e_header-tdid //Text Object ID

    language                      = e_header-tdspras //Text Object Language

    name                          = e_header-tdname  //Text Object Name

    object                        = ‘ZCHD_OBJ’ //Text object

*   ARCHIVE_HANDLE                = 0  //A handle to access Archieve

* IMPORTING

*   HEADER                        =     //Text header Details

  tables

    lines                         = i_tline

* EXCEPTIONS

*   ID                            = 1

*   LANGUAGE                      = 2

*   NAME                          = 3

*   NOT_FOUND                     = 4

*   OBJECT                        = 5

*   REFERENCE_CHECK               = 6

*   WRONG_ACCESS_TO_ARCHIVE       = 7

*   OTHERS                        = 8

          .

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

 

This function module reads Long Text from Text Object corresponding to Text Name & Text Id.As described earlier, this Text Name is uniquely identifies dev comments against each dev objects.

That’s why to uniquely identify the dev comments for dev obj 1 and 2, Text names should be unique. For e.g. in above code snippet objid & Text id combine together to identify comments for Dev comments for each Object.

Now let’s see how these long texts can be deleted through delete_text function module.

 

FORM Delete_Comments.  
   

DATA: e_header TYPE thead, //Work Area to save Text Header information

      i_tline TYPE STANDARD TABLE OF tline. //Header Table   

     

//To pass Text Header Information like Text Object name, Id, Language and no             of characters per line

      e_header-tdobject = ‘ZCHD_OBJ’.
      e_header-tdid = ‘Y0B1’.
      e_header-tdspras = sy-langu.
      e_header-tdlinesize = 72.

//Get Unique Text Name for each Development object ID  

CONCATENATE y0bs_Dev-objid e_header-tdid INTO e_header-tdname.

CALL FUNCTION ‘DELETE_TEXT’

  EXPORTING

   CLIENT                = SY-MANDT  //If Text Object is client dependent

    id                    = e_header-tdid  //Text Object ID

    language              = e_header-tdspras //Text Object Language

    name                  = e_header-tdname //Text Object Name

    object                = e_header-tdobject //Text object

*   SAVEMODE_DIRECT       = ‘ ‘    //Saving Mode saves Text Immediately

*   TEXTMEMORY_ONLY       = ‘ ‘    //Deletion is only apply to Text memory

* EXCEPTIONS

*   NOT_FOUND             = 1

*   OTHERS                = 2          .

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

This function module deletes Long Text from Text Object corresponding to Text Name & Text Id from text file or text memory as per requirement. STXH and STXL tables can be checked for verification.

Conclusion

This covers the steps that need to be followed for creating, saving & deleting the text objects data as per the project requirement.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply