Page tree
Skip to end of metadata
Go to start of metadata

The reason we cannot use the READ_TEXT function in an ABAP mapping is twofold:

  • It requires table parameters - which cannot be used in ABAP dataflows
  • It does raise exceptions if no data is found - a condition which would be okay for us

Therefore the solution could be to write a new SAP function module using the READ_TEXT function inside but doing exactly what we want it to do.

The code I came up with is:

FUNCTION Z_AW_READ_TEXT_ALL.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(ID) TYPE  THEAD-TDID
*"     REFERENCE(LANGUAGE) TYPE  THEAD-TDSPRAS
*"     REFERENCE(NAME) TYPE  THEAD-TDNAME
*"     REFERENCE(OBJECT) TYPE  THEAD-TDOBJECT
*"  EXPORTING
*"     REFERENCE(TEXT) TYPE  CHAR2000
*"----------------------------------------------------------------------

DATA BEGIN OF TEXTHEADER.
        INCLUDE STRUCTURE THEAD.
DATA END OF TEXTHEADER.

DATA BEGIN OF TEXTLINES OCCURS 10.
        INCLUDE STRUCTURE TLINE.
DATA END OF TEXTLINES.

CLEAR TEXTHEADER.

data: l_name type TDOBNAME."TR
l_name = name."TR
CALL FUNCTION 'READ_TEXT'
       EXPORTING
            OBJECT                  = OBJECT
            ID                      = ID
            LANGUAGE                = LANGUAGE
            NAME                    = l_NAME "TR
       IMPORTING
            HEADER                  = TEXTHEADER
       TABLES
            LINES                   = TEXTLINES
       EXCEPTIONS
            ID                      = 1
            LANGUAGE                = 2
            NAME                    = 3
            NOT_FOUND               = 4
            OBJECT                  = 5
            REFERENCE_CHECK         = 6
            WRONG_ACCESS_TO_ARCHIVE = 7
            OTHERS                  = 8.

LOOP AT TEXTLINES.
   CONCATENATE TEXT TEXTLINES into TEXT SEPARATED BY space.
ENDLOOP.


ENDFUNCTION.

This function does not have any exceptions by itself, so even if the READ_TEXT function does raise one, it will finish successfully and return an empty text.


This function we can now import into the SAP datastore and use it like any other SAP function inside a SAP dataflow.


In this example I used it in a second query, the first query got an extra column called VBELN_POSNR which is the concatenation of those two column (mapping: VBELN || POSNR).

Warning

I have uncovered a couple of bugs in the product when playing with this exercise. The basic problem is always the datatype. You import a function and when opening it in the object library the column length is wrong, e.g. all varchar(10). So you have to adjust it manually by editing this column.
Or the function expects a varchar(70) but we assign the concat of VBELN || POSNR which is a varchar(16) to it. Result is an execution error when running the ABAP. So you need to make this column you pass into, a varchar(70).



  • No labels

3 Comments

  1. Unknown User (99dlhvoh)

    Wrapper function was my choice for this sittuation.

    The data type mismatch error for the function can be solved by concatenating enough spaces to the "name" field to complete 70 characters. 

    For my case it would be : EBAN.BANFN || '                                                            '

    EBAN:BANFN is Char10 so thats 60 spaces. This gets the job done.

    Creating another query and making that varchar 70 does not work. When data services generates the abap it still makes the variable char10. Maybe that's a bug? I'm using 4.0 latest sp and patch up to date.

  2. Unknown User (105keslie)

  3. Anonymous

    Need some help with this - will this function allow me to get the decrypted value of CLUSTD if I input the ID, LANGUAGE, OBJECT, and NAME?  I have the ID, LANGUAGE, OBJECT as Constants and the NAME is what changes.  However, when I set this up using ETL, I get the Function Datatype error becuase the source for NAME is VARCHAR(10) and I believe the function needs VARCHAR(70).  I see you've written to concatenate EKKO.EBELN (the field I need in this case to be NAME) but I can only choose from a drop down list of all EKKO fields.  Anyone able to help?