Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views14 pages

Abap - Call Function Read - Text

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

https://s4hclub.

com/ ©

https://www.youtube.com/@s4hclubforyou ©

SAP ABAP FOR DUMMIES


CALL FUNCTION 'READ_TEXT'

### Understanding READ_TEXT

The `READ_TEXT` function module in SAP is used to retrieve text data from various text objects
within the system. It's a versatile function that can be employed in numerous scenarios to access
descriptive information related to different business objects.

### Function Parameters

To successfully use `READ_TEXT`, you need to provide the following key parameters:

CLIENT: The client in which the text is stored.


ID: The text ID, which identifies the type of text (e.g., 'KOPF' for header text).
LANGUAGE: The language in which the text is desired.
NAME: The name of the text object (e.g., the material number for material master text).
OBJECT: The text object type (e.g., 'MAT' for material master).

### Importing and Exporting Parameters

IMPORTING:
`CLIENT`
`ID`
`LANGUAGE`
`NAME`
`OBJECT`
`ARCHIVE_HANDLE` (optional, for archived texts)
EXPORTING:
`HEADER`: Structure to hold text header information.
`LINES`: Table to hold text lines.

### Example Usage

``
```abap
https://www.linkedin.com/in/mickaelquesnot/ ©

1
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

REPORT Z_READ_TEXT_EXAMPLE.

DATA: ls_header TYPE STEXT_HEADER,


lt_lines TYPE TABLE OF STEXT_LINE.

CALL FUNCTION 'READ_TEXT'


EXPORTING
CLIENT = SY-MANDT
ID = 'KOPF'
LANGUAGE = SY-LANGU
NAME = 'YOUR_MATERIAL'
OBJECT = 'MAT'
IMPORTING
HEADER = ls_header
LINES = lt_lines.

IF sy-subrc = 0.
WRITE:/ 'Header Text:', ls_header-TDLINE.
LOOP AT lt_lines.
WRITE:/ lt_lines-TDLINE.
ENDLOOP.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
```

### Additional Considerations

Error Handling: Check `sy-subrc` for errors.


Text Object Types: Refer to SAP documentation for available text object types.
Performance: Consider performance implications, especially for large amounts of text data.

By understanding the parameters and proper error handling, you can effectively use `READ_TEXT`
to retrieve text information in your SAP programs.

https://www.linkedin.com/in/mickaelquesnot/ ©

2
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

Do you have a specific use case in mind for `READ_TEXT`?

ABAP Code examples :

&---------------------------------------------------------------------
& Include ZXVVFU01
&---------------------------------------------------------------------

DATA GT_TLINE TYPE TABLE OF TLINE.


DATA GV_NAME LIKE THEAD-TDNAME.

Spike #22653
Ecritures Clients : Reprise du texte d'en-tête

IF NOT ( VBRK-KUNAG IS INITIAL AND VBRK-VBELN IS INITIAL ).

Spike #22535 OUVERT


Saisie de commande clients : Rendre la saisie de texte obligatoire (Ligis)

CLEAR : GT_TLINE[], GV_NAME.

GV_NAME = VBRK-VBELN.

CALL FUNCTION 'READ_TEXT'


EXPORTING
ID = 'TX11'
LANGUAGE = SY-LANGU
NAME = GV_NAME
OBJECT = 'VBBK'
TABLES
LINES = GT_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.
READ TABLE GT_TLINE INTO DATA(LS_TLINE) INDEX 1.
XACCHD-BKTXT = LS_TLINE-TDLINE.
ELSE.
CONCATENATE VBRK-VBELN VBRK-KUNAG INTO XACCHD-
BKTXT SEPARATED BY SPACE. "Sold-to Party Billing Document
ENDIF.

https://www.linkedin.com/in/mickaelquesnot/ ©

3
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

ENDIF.

Spike #22535
Saisie de commande clients : Rendre la saisie de texte obligatoire

LOOP AT IT_XTHEAD INTO DATA(GS_XTHEAD) WHERE TXPFL <> ' ' "Text is mandatory or sh
ould be displayed
AND TDTXTLINES <> ' '. "Number of Text Lines in Line Table

CLEAR LT_TLINE[].
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = GS_XTHEAD-TDID
LANGUAGE = GS_XTHEAD-TDSPRAS
NAME = GS_XTHEAD-TDNAME
OBJECT = GS_XTHEAD-TDOBJECT
TABLES
LINES = LT_TLINE
EXCEPTIONS
ID =1
LANGUAGE =2
NAME =3
NOT_FOUND =4
OBJECT =5
REFERENCE_CHECK =6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.

https://www.linkedin.com/in/mickaelquesnot/ ©

4
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

IF SY-SUBRC = 0.
READ TABLE LT_TLINE INTO DATA(LS_TLINE) INDEX 1.
LV_LENGTH = STRLEN( LS_TLINE-TDLINE ).
IF LV_LENGTH > 25.
LV_LENGTH = LV_LENGTH - 25.
Text module &1 for text ID &2 is &3 characters too long
MESSAGE E288(COCF) WITH LS_TLINE-TDLINE GS_XTHEAD-
TDID LV_LENGTH INTO IS_RETURN-MESSAGE.
CONDENSE IS_RETURN-MESSAGE.
EXIT.
ENDIF.

ENDIF.

ENDLOOP.

ENDMETHOD.

https://www.linkedin.com/in/mickaelquesnot/ ©

5
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

DEMO

https://www.linkedin.com/in/mickaelquesnot/ ©

6
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

7
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

8
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

9
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

10
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

11
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

12
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

13
https://s4hclub.com/ ©

https://www.youtube.com/@s4hclubforyou ©

https://www.linkedin.com/in/mickaelquesnot/ ©

14

You might also like