2

i am facing issue while converting unicode data into national characters. When i convert the Unicode data into national using national-of function, some junk character like @ is appended after the string.

E.g Ws-unicode pic X(200) Ws-national pic N(600)

--let the value in Ws-Unicode is これらの変更は. getting from java end.

move function national-of ( Ws-unicode ,1208 ) to Ws-national.

--after converting value is like これらの変更は @.

i do not want the extra @ character added after conversion.

please help me to find out the possible solution, i have tried to replace N'@' with space using inspect clause. it worked well but failed in some specific scenario like if we have @ in input from user end. in that case genuine @ also converted to space.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Rama Gaur
  • 23
  • 2

1 Answers1

3

Below is a snippet of code I used to convert EBCDIC to UTF. Before I was capturing string lengths, I was also getting @ symbols:

STRING                                                       
   FUNCTION DISPLAY-OF (                                     
      FUNCTION NATIONAL-OF (                                 
         WS-EBCDIC-STRING(1:WS-XML-EBCDIC-LENGTH)
         WS-EBCDIC-CCSID                                     
      )                                                      
      WS-UTF8-CCSID                                          
   )                                                         
   DELIMITED BY SIZE                                         
INTO WS-UTF8-STRING
     WITH POINTER WS-XML-UTF8-LENGTH                         
END-STRING                                                   

SUBTRACT 1 FROM WS-XML-UTF8-LENGTH    

What this code does is string the UTF8 representation of the EBCIDIC string into another variable. The WITH POINTER clause will capture the new length of the string + 1 (+ 1 because the pointer is positioned to the next position after the string ended).

Using this method, you should be able to know exactly how long second string is and use that string with the exact length.

That should remove the unwanted @s.

EDIT:

One thing I forgot to mention, in my case, the @ signs were actually EBCDIC low values when viewing the actual hex on the mainframe

SaggingRufus
  • 1,814
  • 16
  • 32
  • Thanks for suggestion @Sagging, but in my case CCSID of input parm is already unicode, Ws-unicode is defined as"IN IPARM2 VARCHAR(200) FOR MIXED DATA CCSID UNICODE". But i will try to implement your suggestion today. thanks again – Rama Gaur Apr 28 '17 at 05:05
  • @RamaGaur it should still work. If you use the proper CCSIDs. The method of actually stringing it with pointer was all I was trying to get at. Then you know the exact length. – SaggingRufus Apr 28 '17 at 10:00
  • Thanks @Sagging, it has been sorted out with your help, Actually we are getting the Unicode data from user end, then saving the data into table( having national data type). So What i have done is "Move National-of (Ws-unicode(1:Ws-unicode-length), 1208) to Ws-national. its working now there is no extra @ character present in my string. i thinks @ characters were appearing when we were converting the space into national data – Rama Gaur May 02 '17 at 15:26
  • Awesome! I am glad that helped – SaggingRufus May 02 '17 at 15:36