Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

String needs to be concatenated

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: String needs to be concatenated
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    Post subject: Re: String Manipulations
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    Post subject:
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    Post subject: Re: String Manipulations
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    Post subject: Re: String Manipulations
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: 128
Location: kerala,india

PostPosted: Tue Nov 14, 2006 5:27 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us