View previous topic :: View next topic
|
Author |
Message |
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
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 |
|
|
prabs2006
Active User
Joined: 12 Jan 2006 Posts: 103
|
|
|
|
Further to add, if mid name is space, the first name shud be followed by a space folowed by last name |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
string firstname
delimited by space
middlename
delimited by space
lastname delimited by space
into ......
end-string |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
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 |
|
|
|