Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Creating Unprintable Characters String in an ABAP program

Former Member
0 Likes
3,536

Hello

I am tring to create a General Motors GM 1724-A format barcode label in Smartform.

The GM specifications state that the PDF4-417 must contain certain unprintable characters like ASCII 04, ASCII 29 and ASCII 30.

I want to create a sring of data in my Smartform Print Program and pass the entire string to the Smartform through an internal structure.

I have create 3 constants defned as hex (type x) '04', '1D' and '1E', but when I try to CONCACTONATE them into the structure field, the program comple erors out... You cannot CONCACTONATE a hex field.

When I moved those hex fields into a 1 char fields, they contain '0', '1' and '1'.

I cannot find a Function Module which will convert these hex into characters correctly.

Any suggestions would be appreciated.

Thanks

Peter

1 ACCEPTED SOLUTION
Read only

rainer_hbenthal
Active Contributor
0 Likes
2,219

On unicode systems, you can not mix types x with c/string.

Have a look at this:

types:
  char01        type c length 1.

data:
  s             type string,
  hex           type x length 4,
  char          type char01.

FIELD-SYMBOLS:
  <pc>.

hex = '0D'.

assign hex to <pc> casting type char01.
char = <pc>.

11 REPLIES 11
Read only

Former Member
0 Likes
2,219

I do something similar in putting a carriage return character into a file I am outputting.

This gives me no error when I concatenate the hex onto a character varaible.

So I would have thought the way you are trying would work.


data: c_cr type x value '0D'. 
data: wa_field(1000).

concatenate wa_field c_cr into wa_field.  

Read only

0 Likes
2,219

Hey, Thanks

I took your code and put it in a program, and when I attempted to activate it, I got the following error mesage:

"C_CR" must must be a character-type data object(data type C, N, D, T or STING).

Any idea?

Peter

Read only

0 Likes
2,219

Are you on Unicode, we are not, I wonder if this is why you get the error ?

Read only

0 Likes
2,219

Certainly is an Unicode issue.

I switched on the Unicode checks on the abap attributes, and I get the same error message.

So, Rainer's solution seems to work, or if you are not a Unicode site, you could just switch off the Unicode checks in the program attributes.

Read only

0 Likes
2,219

Switching off the unicode flag is not a good idea cause you're just postponing the problem. SAP clearly states that maintenance of non-unicode systems will come to an end.

Read only

rainer_hbenthal
Active Contributor
0 Likes
2,220

On unicode systems, you can not mix types x with c/string.

Have a look at this:

types:
  char01        type c length 1.

data:
  s             type string,
  hex           type x length 4,
  char          type char01.

FIELD-SYMBOLS:
  <pc>.

hex = '0D'.

assign hex to <pc> casting type char01.
char = <pc>.

Read only

Former Member
0 Likes
2,219

Well you directly have a replacement available in the class CL_ABAP_CHAR_UTILITIES for carriage return (0D). So you could try something like this



class: cl_abap_char_utilities definition load.

data: c_cr(1) type c .
data: wa_field(1000).

c_cr = cl_abap_char_utilities=>cr_lf+0(1).
 
concatenate wa_field c_cr into wa_field.  

Vikranth

Read only

0 Likes
2,219

The requirement was

The GM specifications state that the PDF4-417 must contain certain unprintable characters like ASCII 04, ASCII 29 and ASCII 30.

How does cl_abap_char_utilities helps in these cases?

Read only

Former Member
0 Likes
2,219

Clearly you need to check the unicode flag and allow the system to handle the hex values.

im able to check the conversion from hex to char using this FM

HR_RU_CONVERT_HEX_TO_STRING

allows u to convert hex values to char ..

probably you can concatenat the char in the string .. i hope i have understood ur requirement clearly..

Just check if this solves ur purpose.

Br,

Vijay.

Read only

Former Member
0 Likes
2,219

Rainer, Thank You!

The sample code you sent me worked, with one small change....

in your example, I changed :

hex = '0D'.

to

hex = '000D'.

and it worked like a charm.

Thanks, again.

Peter Graham

Cooper Standard Automotive

Read only

0 Likes
2,219

Hi Peter and Rainer,

I was looking at that thread and wondered why Peter had to add a leading 00. It must be because of his SAP system endianness (Peter has a big endian system, while Rainer has a little endian system).

So probably the best solution would be to use the following code which takes care of the endianness:


DATA char TYPE c LENGTH 1.
char = cl_abap_conv_in_ce=>uccp( '000D' ).

Sandra