Home > Mobile >  Convert ITAB to XSTRING and back
Convert ITAB to XSTRING and back

Time:05-27

I need to save an itab as an xstring or something like this and save it in dbtab. Later I need to gather this xstring from dbtab and convert it in the itab before with exactly the same input from before.

I tried a lot of fuba´s like: SCMS_STRING_TO_XSTRING or SCMS_XSTRING_TO_BINARY but I didn´t find something to convert it back.

Does somebody have tried something like this before and have some samples for me ?

Unfortunately I didn´t find something on other blogs or else.

CodePudding user response:

use

import ... from data buffer

and

export ... to data buffer

to (re)store any variable as xstring.

Or you can use

import|export ... from|to database ...

CodePudding user response:

I did some methods to do this:

First I loop at the table and concatenate it into a string. Then convert the string into an xstring.

 LOOP AT IT_TABLE ASSIGNING FIELD-SYMBOL(<LS_TABLE>).
CONCATENATE LV_STRING <LS_TABLE> INTO LV_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>NEWLINE.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      TEXT   = IV_STRING
    IMPORTING
      BUFFER = LV_XSTRING.

Back would be like: Convert xstring back to string String into table

 TRY.
    CL_BCS_CONVERT=>XSTRING_TO_STRING(
        EXPORTING
          IV_XSTR   = IV_XSTRING
          IV_CP     =  1100                " SAP character set identification
        RECEIVING
          RV_STRING = LV_STRING
      ).
  CATCH CX_BCS.
ENDTRY.

SPLIT IV_STRING AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO: TABLE <LT_TABLE> .

READ TABLE <LT_TABLE> ASSIGNING FIELD-SYMBOL(<LS_TABLE>) INDEX 1.
IF <LS_TABLE> IS INITIAL.
  DELETE TABLE <LT_TABLE> FROM <LS_TABLE>.
ENDIF.
  • Related