Showing posts with label Text. Show all posts
Showing posts with label Text. Show all posts

Jul 6, 2026

Replace Some Characters in the Middle of Text.

Requirement:

To replace the 5th character in a 10-character string (or any string), use the ABAP overlay statement or the replace section command. In ABAP, character offsets are zero-based, meaning the 5th character is at offset

Solution:

Here are the two best approaches for doing this:

Method 1: Using OVERLAY (Best for replacing specific offsets)
abap
DATA: gv_string TYPE string VALUE '1234567890'.

" The 5th character is at offset 4 (length 1). Replace it with 'X'
OVERLAY gv_string WITH '    X' ONLY ' '.

Method 2: Using REPLACE SECTION (Best for explicit length)
abap
DATA: gv_string TYPE string VALUE '1234567890'.

REPLACE SECTION OFFSET 4 LENGTH 1 OF gv_string WITH 'X'.

Method 3: Inline Expression (ABAP 7.40+)
abap
DATA(gv_string) = '1234567890'.

gv_string = |{ gv_string(4) }X{ gv_string+5 }|.

Output for all methods: 1234X67890

Mar 17, 2016

Upload Log Item Text to FI Document

Question:
I need to upload FI document posting using BAPI_ACC_DOCUMENT_POST. However item text that I received is too long and need to store at item long text. So can we use BAPI_ACC_DOCUMENT_POST to upload long text for item text? If this possible, may I know how to do this.

Answer: 
You cannot pass item long text using this BAPI, Call the function module SAVE_TEXT after successfull call of BAPI Call Save_Text with following parameters. Text_ID : 0001 (Notes) Text_object : DOC_ITEM (Line Item Text) Language : EN Text Name : Company code +Document NO + Fiscal Year + Line item ID


Aug 26, 2015

Function Example: READ_TEXT ABAP Wrapper Function

by Vicky Bolster

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.



ref: http://wiki.scn.sap.com/wiki/display/EIM/Function+Example+READ_TEXT+ABAP+wrapper+function