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

Unicode X string problem

Former Member
0 Likes
1,347

We are migrating to a Unicode system. When the unicode flag is switched on I get an error which says that P_1STCHAR must be byte type field.

The SAP unicode help just confirms the error message without giving any suggestions.

IF P_1STCHAR Z HEX_FF is the line with the problem. Z is a relational operator for bit masks. This line is basically saying does P_1STCHAR contain a ZERO at the bit position specified in HEX_FF.

In a non unicode system P_1STCHAR can be a character type field (which it is in this case) but in a unicode system it must be a byte type field.

How can I fix this code?

FORM CHECK_NULL CHANGING P_1STCHAR  TYPE C
                         P_NULLFLAG TYPE C.
* New form...                                              
  DATA: HEX_FF(1) TYPE X  VALUE 'FF'.

* If every bit position in P_1STCHAR is 0 then we have
* a NULL insert issue.  Change the P_1STCHAR to X and
* mark the corresponding P_NULLFLAG with X.
  IF P_1STCHAR Z HEX_FF.  <<<< THIS IS PROBLEM LINE!!!
    WRITE  IND-ON TO: P_1STCHAR,
                      P_NULLFLAG.
  ELSE.
    CLEAR P_NULLFLAG.
  ENDIF.
ENDFORM.                    " CHECK_NULL

6 REPLIES 6
Read only

Former Member
0 Likes
796

Hi,

Prior to unicode allowed in ABAP.

Have a look at the statement.

Until now, there was a check in these statements to see if field f is character-type, where normally X fields, X strings, and flat structures were also seen as character-type. This is no longer meaningful in a Unicode program because, on the one hand, the types X and XSTRING are no longer regarded as character-type, and, on the other hand, bit-by-bit access to character-type fields or structures is no longer platform-independent. In a Unicode program, field f must therefore be of type X or XSTRING for these operations.

Read only

0 Likes
796

Thanks Manoj, Do you have any suggestions on how I could restructure the code so that it will check for a null entry in P_1STCHAR? So that the code will still have the same functionality as before?

Read only

0 Likes
796

Here is the code calling the null form.

*&---------------------------------------------------------------------*
*&      Form  APPEND_ZU131
*    Routine appends record in HOLDZU131 internal table.
*&---------------------------------------------------------------------*
FORM APPEND_ZU131 USING DATA_1
                        DATA_2.
*                       DATA_3                              
*                       DATA_4.                             

* FORM_NAME = 'APPEND_ZU131'.                               
* INCLUDE ZUINSTRT.                                         

* zu131-rec_number = zu131-rec_number + 1.                  
* zu131-data_1     = data_1.                                
* zu131-data_2     = data_2.                                
  ZU131N-REC_NUMBER = ZU131N-REC_NUMBER + 1.                
  ZU131N-DATA_1     = DATA_1.                               
  ZU131N-DATA_2     = DATA_2.                               
* ZU131-DATA_3     = DATA_3.                                
* ZU131-DATA_4     = DATA_4.                                

* Deal with 1st char.                                       
* If NULL (x'00'), save it and then change it.              
  PERFORM CHECK_NULL CHANGING:                              
     ZU131N-DATA_1+0(1)  ZU131N-FIRSTNULL1,                 
     ZU131N-DATA_2+0(1)  ZU131N-FIRSTNULL2.                 

* HOLDZU131 = ZU131.                                        
* APPEND HOLDZU131.                                         
* append zu131 to holdzu131.                     
  APPEND ZU131N TO HOLDZU131.                    

* Append does not set SY-SUBRC !                            
* IF SY-SUBRC NE 0.                                         
*   FORM_NAME = 'APPEND_ZU131'.                             
*   INCLUDE ZUINFAIL.                                       
*   RAISE INSERT_FAILED.                                    
* ENDIF.                                                    
* FORM_NAME = 'APPEND_ZU131'.                               
* INCLUDE ZUINENDD.                                         

ENDFORM.                               " APPEND_ZU131

Read only

sridhar_k1
Active Contributor
0 Likes
796

Convert P_1STCHAR to hex and using in If statement might work.

Try this code in Form ..endform.

data: uccp type syhex02,

hex_ff type syhex02 value 'FFFF'.

  • Get hex of P_1STCHAR

call method cl_abap_conv_out_ce=>uccp

exporting

char = p_1stchar

receiving

uccp = uccp.

if uccp z hex_ff.

write ind-on to: p_1stchar,

p_nullflag.

else.

clear p_nullflag.

endif.

Regards

Sridhar

Read only

0 Likes
796

Thanks, points awarded. Can't actually test it yet though. Thank you.

Read only

0 Likes
796

Small change to my previous post:

Use field symbols to convert char to hex instead of method CL_ABAP_CONV_OUT_CE=>UCCP, because sap may not have a unicode codepoint for every possible bit sequence, use the following code:

data: v_hex(2) type x,
      hex_ff type syhex02 value 'FFFF'.
field-symbols: <fs> type any.

assign p_1stchar to <fs> casting type x.
v_hex = <fs>

if v_hex Z hex_ff.
  write  ind-on to: p_1stchar,
                    p_nullflag.
else.
  clear p_nullflag.
endif.

Regards

Sridhar