Monday, September 26, 2011

COBOL : Concatenating of two strings



The below code snippet explains how to concatenate two strings.


Suppose we have the variables which is declared below    
                                                        
VAR1      PIC X(33) VALUE 'VALUE 1'.                    
VAR2      PIC X(33) VALUE 'VALUE 2'         
                                                        
I need to String this as 'VALUE 1*VALUE 2'
and not as 'VALUE 1                         *VALUE  2'


Solution
INSPECT FUNCTION REVERSE(VAR1)                 
         TALLYING WS-COUNT FOR LEADING SPACE. 

COMPUTE WS-LENGTH = LENGTH OF VAR1 - WS-COUNT. 
                
STRING VAR1(1:WS-LENGTH)
            '*'
      VAR2                               
      DELIMITED BY SIZE                       
      INTO WS-RESULT                            
END-STRING.          

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.