Home > ABAP, API > Long Text in SAP

Long Text in SAP

January 26th, 2010 Leave a comment Go to comments

Long text is used in various components to store comments or additional text freely. It is stored in ITF (Interchange Text Format) format and comprises of text header and text lines.

The text header contains all administrative information on a long text. Below diagram shows some important fields in the text header.

Text name (TDNAME): Customer-defined name of a text. It can be a maximum of 70 characters in length.

Language (TDSPRAS): The language key is an abbreviation for the language of the object being processed.

Text ID (TDID): The text ID defines the various types of texts related to a text object. The text ID must be defined in table TTXID together with the text object.

Text Object (TDOBJECT): It contains the name of the text object to which the text is allocated. This object must be defined in table TTXOB.

Technical Details:

Table:

STXH: Store text header
STXL: Store text lines in ITF format
STXB: Store text lines in other formats

Function Group:

STXD – SAPscript program interface 1.
STXK - SAPscript text conversions

Code Snips:

Read Text:

data: begin of tlinetab occurs 100.    "table to process comments
        include structure tline.
data: end of tlinetab.
data: tdname           like thead-tdname.
  call function 'READ_TEXT'
       exporting
            id                      = '0002'
            language                = sy-langu
            object                  = 'KNA1'
            name                    = cur_kunnr
       importing
            header                  = thead
       tables
            lines                   = tlinetab
       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.
    loop at tlinetab.
      write / tlinetab-tdline.
      add 1 to line_cnt.
    endloop.
  endif.

Save Text:

  DATA: FHEADER LIKE THEAD.
 
  DATA: BEGIN OF TLINETAB OCCURS 10.
          INCLUDE STRUCTURE TLINE.
  DATA: END OF TLINETAB.
 
  CALL FUNCTION 'INIT_TEXT'
       EXPORTING
            ID       = FID
            LANGUAGE = FLANGUAGE
            NAME     = FNAME
            OBJECT   = FOBJECT
       IMPORTING
            HEADER   = FHEADER
       TABLES
            LINES    = TLINETAB
       EXCEPTIONS
            ID       = 01
            LANGUAGE = 02
            NAME     = 03
            OBJECT   = 04.
 
  IF SY-SUBRC <;>; 0.
    RAISE NO_INIT.
  ENDIF.
 
  IF FFORMAT <;>; SPACE.
   LOOP AT FLINES.
     FLINES-TDFORMAT = FFORMAT.
     MODIFY FLINES.
   ENDLOOP.
  ENDIF.
 
  FHEADER-TDMACODE2 = 'CREATE_TEXT'.
 
  CALL FUNCTION 'SAVE_TEXT'
       EXPORTING
            HEADER          = FHEADER
            INSERT          = ' '
            SAVEMODE_DIRECT = SAVE_DIRECT
       IMPORTING
            NEWHEADER       = FHEADER
       TABLES
            LINES           = FLINES
       EXCEPTIONS
            ID              = 01
            LANGUAGE        = 02
            NAME            = 03
            OBJECT          = 04.
 
  IF SY-SUBRC = 0.
    CALL FUNCTION 'COMMIT_TEXT'
       EXPORTING
            OBJECT   = FOBJECT
            NAME     = FNAME.
  ELSE.
    RAISE NO_SAVE.
  ENDIF.

Or try function module ‘CREATE_TEXT’. It provides one stop solution to create the long text.

Reference:

http://help.sap.com/saphelp_nw70/helpdata/en/d6/0db57e494511d182b70000e829fbfe/frameset.htm

  1. No comments yet.
  1. No trackbacks yet.