Posted: Sun Oct 14, 2007 9:35 pm Post subject: Convert Xstring to Binary and Text
Requirement:
This is a sample code to show the conversion of a text internal table --> Xstring internal table --> Binary internal table --> Text internal table.
Processing:
It uses Function Modules 'SCMS_TEXT_TO_XSTRING', 'SCMS_XSTRING_TO_BINARY','SCMS_BINARY_TO_TEXT' for this purpose. Further, it downloads the itab in a text file on presentation server using Function Module GUI_DOWNLOAD.
Code:
REPORT Z_RMTIWARI_XSTRING_TEXT_CONVER .
*----------------------------------------------------------------------*
* Convert Xstring to Binary / Text - Date - 20.06.2005
*----------------------------------------------------------------------*
* Written By: Ram Manohar Tiwari
*----------------------------------------------------------------------*
* Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
TYPES : BEGIN OF TY_TEXT,
TEXT_FIELD(1000) TYPE C,
END OF TY_TEXT.
TYPES : BEGIN OF TY_BINARY,
BINARY_FIELD(1000) TYPE C,
END OF TY_BINARY.
DATA : LV_XSTRING type XSTRING.
DATA : LT_BINARY type table of TY_BINARY with header line.
DATA : LT_TEXT type table of TY_TEXT with header line.
DATA : LT_TEXT_OUT type table of TY_TEXT with header line.
DATA : X_OUTFILE type string.
* Populate a text itab.
LT_TEXT-text_field = 'Hello'.
append LT_TEXT.
LT_TEXT-text_field = 'Hi'.
append LT_TEXT.
LT_TEXT-text_field = 'How r u?'.
append LT_TEXT.
* Convert text to xstring.
CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'
* EXPORTING
* FIRST_LINE = 0
* LAST_LINE = 0
* MIMETYPE = ' '
IMPORTING
BUFFER = LV_XSTRING
TABLES
TEXT_TAB = LT_TEXT
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.