Search code examples
db2cobolmainframedb2-zos

how to remove @ character from national data type in cobol


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.


Solution

  • 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