cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle null value in string and xstring?

10-10-2018 10:45 AM
3971 views 5 comments
0 Likes
SAP Managed Tags
Subscribe

Hi Guys,

I am facing problem with null values in string and it's hex code xstring. I have some data in one field with data type LCHR. This field contains data like :

"SAPMSDYP MBatch-Input ####%PC 60317081539#?"

I have one abap program. I am just appending this data to a string variable and then converting this string to xstring data. The length of the string is 53 and after conversion to xstring the length of xstring data is more then the string data. In string data wherever the "#" is there it is coming as "0000" in raw data(xstring). After this conversion i am just sending this data to my java program using http_client. At java side if the incoming data is having null value in-between data then this java program will reject this data. The main problem is i have to handle these null value in my abap program only.

At debugging time in variable details box also its hex value is showing as 0000 that is sap's default string to hex conversion. And if i move the mouse cursor on this variable then in hint box this single '#' is showing as 5 characters as CString.

For string to xstring conversion i am using the below code: CL_ABAP_CONV_OUT_CE=>create(

encoding = 'UTF-8'

endian = 'L' ).

conv->convert( EXPORTING data = text

IMPORTING buffer = buffer1 ).

Here i have to handle this null("#") value either in string data or in xstring data in ABAP program only. I don't know how to do this.

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member184158
Active Contributor
0 Likes

Hallo Ompal shekhawat,

I think you have to check your XSTRING and if you found this 0x00, then you can remove it. By the way you may get this ### if there is new line 0x0a or break line 0x0D and you can remove them from your XSTRING.

So, just these could help you

Check if the string has 0x00 or 0x0a or 0x0D, then remove it.

So, I would like you to read about these ASCII chart:

common ascii codes to know

Char  Dec  Oct  Hex   WhatAreThey
---------------------------------------
(nul)   0 0000 0x00   Null 
(ht)    9 0011 0x09   Horizontal Tab
(nl)   10 0012 0x0a   New Line
(vt)   11 0013 0x0b   Vertical Tab
(cr)   13 0015 0x0d   Carriage Return
(sp)   32 0040 0x20   Space

Ref: http://www.bluesock.org/~willg/dev/ascii.html

For String, you can check this class

CL_ABAP_CHAR_UTILITIES=>NEWLINE


Best regards

Ebrahim Hatem

Former Member
0 Likes

Hi Ebrahim Hatem,

Thanks for the reply, I have tried all of the above solutions but nothing is working. In SAP GUI debugging window the hex value of # is showing as 0000 and in CString it shows as . I have tried all the above solution. Instead of this umlaut # if we have normal # then i am able to do any modification and for this normal # the SAP GUI will show the hex as 0023 which is correct. But this particular character is not normal #, only it looks like as #. Can you suggest me if it is null or anything other character. And this character is available in the table D345T and field is BLOCK(LCHR type).

Florian
SAP Champion
SAP Champion
0 Likes

Why don't you handle the # sign with abap before sending it to your java application? You can build a construct with string functions.

So you don't have to deal on the java-side:-)

Here are some keywords to point you the correct documentation.

String Functions, count, find, and match

~Florian

Former Member
0 Likes

Hi Florian,

I tried at ABAP side also but any of the string function is not able to modify / replace or change this character. I need the way where i can get its correct hex value.

~Shekhawat

Florian
SAP Champion
SAP Champion
0 Likes

You may have a look at the debugger to see the values unconverted. As Ebrahim suggest, I think this is the rootcause atm.