IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

String needs to be concatenated


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Tue Nov 14, 2006 3:28 pm
Reply with quote

Hi,

I have 3 fields as below
First name - x(12)
Mid name - x(1)
Last name - x(16)

These needs to be concatenated so as to look like below:

<<first name>> <<single space>> <<Mid name>><<single space>><<lastname>>

Any of these 3 fields can be spaces and can be of any length.
Suggest a way to do this.

T & R
Prabs
Back to top
View user's profile Send private message
prabs2006

Active User


Joined: 12 Jan 2006
Posts: 103

PostPosted: Tue Nov 14, 2006 3:42 pm
Reply with quote

Further to add, if mid name is space, the first name shud be followed by a space folowed by last name
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Nov 14, 2006 4:25 pm
Reply with quote

string firstname middlename lastname delimited by size into namedisp

and for first name declare it as justified right. still the spaces will be ther in first name ..in case u need to remove the spaces use inpect verb and remove from firstname.....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Nov 14, 2006 4:49 pm
Reply with quote

string firstname
delimited by space
middlename
delimited by space
lastname delimited by space
into ......
end-string
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Nov 14, 2006 4:59 pm
Reply with quote

Code:


77 one-space  pic x(01) value space.
If middlename = space
then
     string firstname
            delimited by space
         one-space
            delimited by size
        lastname
            delimited by space
        into namedisp
    end-string
else
     string firstname
            delimited by space
         one-space
            delimited by size
         middlename
            delimited by space
         one-space
            delimited by size
        lastname
            delimited by space
        into namedisp
    end-string
end-if
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Tue Nov 14, 2006 5:27 pm
Reply with quote

Hope the following program will work for you
Code:
ID DIVISION.
PROGRAM-ID. STR.
DATA DIVISION.
WORKING-STORAGE SECTION. 
01 FIRST-NAME PIC X(12) VALUE ALL SPACES.
01 MID-NAME PIC X(1) VALUE ALL SPACES.
01 LAST-NAME PIC X(16) VALUE ALL SPACES. 
01 FULLNAME PIC X(31).
01 C1 PIC 9(2) VALUE IS ZERO.
01 C3 PIC 9(2) VALUE IS ZERO. 
PROCEDURE DIVISION.
MAIN.
    ACCEPT FIRST-NAME.                                         
    ACCEPT MID-NAME.                                           
    ACCEPT LAST-NAME.                                           
    INSPECT FIRST-NAME TALLYING C1 FOR CHARACTERS BEFORE                              INITIAL SPACE.                                                     
    INSPECT LAST-NAME TALLYING C3 FOR CHARACTERS BEFORE INITIAL
    SPACE.                                                     
    MOVE FIRST-NAME(1:C1) TO FULLNAME(1:C1).                   
    IF MID-NAME NOT EQUAL TO SPACE                             
    MOVE MID-NAME(1:1) TO FULLNAME(C1 + 2:1)                   
    MOVE LAST-NAME(1:C3) TO FULLNAME(C1 + 4:C3)                 
    ELSE                                                       
    MOVE LAST-NAME(1:C3) TO FULLNAME(C1 + 2:C3) 
    END-IF.           
    DISPLAY FULLNAME.
    STOP RUN.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top