SAP ABAP; conversion abap; SAP Change Pointer; ABAP Add SearchHelp on Parameter; New ABAP Release 7.50; HTTP_POST and HTTP_GET;Enhancements in SAP; SAP Attachment;upload excel file to internal table in sap; Remember sap tables, TEXT_CONVERT_XLS_TO_SAP

Conversion ABAP: between Binary, String, XString and Table

Conversion ABAP between types is a main topics in an ABAP developer. Actually, SAP stores sometimes the same information/Data in different table or the module function requests a different types for the input or output.

This article will cover Conversion in ABAP Coding between the most used types : Binary, String and Table.
Will handling with data or attachment, few conversion function will be helpful in order to extract, save file.

Up to my experience, the most used conversions in ABAP will be:

  • Abap convert string to integer
  • Abap convert String to Decimal
  • Conversion from internal to external format
  • Convert Binary to Xstring: (attachment , … ).
  • Text lines into String conversion for  ( long text , … )
  • Convert String to XString
  • XString to SOLIX_TAB for attachment, file …

Conversion ABAP: string to Integer

Welcome to most useful conversion for ABAP Developer: How to convert STRING to INTEGER  in ABAP ?
First, the String is types STRING in ABAP and Integer is a just an ‘I‘ in ABAP Typing.
The simplest way is to use the standard function CONVERT_STRING_TO_INTEGER in any ABAP Code.
The CONVERT_STRING_TO_INTEGER also controls if the string is only a number or not :

  • sy-subrc = 1 : if the string’s integer length overload the length of ABAP integer.
  • sy-subrc = 2 : if the string doesn’t contain only number

The ABAP Code Snippet to user directly in your custom ABAP conversion program is :

ABAP convert String to Decimal

ABAP Decimal Type is more complicated than ABAP Integer because of the Decimal separator.
So, in order to convert String to Decimal in ABAP, you have to set with Decimal Separator is used.

Check also   SAP Mass Attachments Extraction for Sales Documents (ABAP)

In ABAP Workbench, you can use the standard function HRCM_STRING_TO_AMOUNT_CONVERT to made the Conversion ABAP.

ABAP Convert String to Decimal

Basic ABAP Conversion from internal to external format

ABAP Convert from Internal format into external format ( or vice versa ) can be done by CONVERSION_EXIT_ALPHA* function.
CONVERSION_EXIT_ALPHA_INPUT : convert external to internal
CONVERSION_EXIT_ALPHA_OUTPUT : convert internal to external

These functions are very useful to remove remove leading zeros in ABAP for example.

Conversion ABAP Binary to XSTRING 

In Order to convert BINARY to XSTRING, first get the BINARY data and get the length of the binary ABAP variable.
Then Call the standard function SCMS_BINARY_TO_XSTRING and pass the length and the binary value.
And Hop ! you get the XSTRING.

It can be useful when dealing/ conversion ABAP with Attachments or images (mime-type) that are stored as Binary in SAP tables

Check also   What is Open SQL ? Open SQL or Native SQL in SAP ABAP ?

Convert Text lines into string

As you know, SAP has a very particular way to handle long text.
Usually, the SAP text is splitted into lines.
Use the Standard Function CONVERT_TABLE_TO_STRING to collect all the text in one STRING variable in ABAP.

ABAP Convert String to XString

How to Convert String to Xstring in ABAP ? ( from String type to a binary format )
Just use the standard function SCMS_STRING_TO_XSTRING.

For the input

  • BUFFER is typed XSTRING
  • also mimetype : the type of the binary ( jpg … exe. .. )
  • encoding:the encoding of the output string ( it is useful when you deal with non-unicode character)
Check also   Important SAP WM Tcodes - Warehouse Management Transaction Codes

Convert XString to SOLIX_TAB

Once you get the binary, you can convert the Binary string the XSTRING to table of XSTRING with this function SCMS_STRING_TO_BINARY to do conversion abap.

Acutally, these conversion abap functions will be helpful for retrieving business object file and add it as attachment to an email.