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

cobol string concatination


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

New User


Joined: 21 Feb 2005
Posts: 14
Location: hyderabad

PostPosted: Tue Jan 02, 2007 5:31 pm
Reply with quote

Hai ,
Please give me the solution for below logic.

i have input file record structure like this

05 EMPLOYEE-NAME.
10 FIRST-NAME PIC X(12).
10 MIDDLE-INIT PIC X.
10 LAST-NAME PIC X(17).

i want to concatinate like last-name,middle-init,last-name
but the problem is my input for LAST-NAME is varying from 4 to 17 like
"james "
"john j cranley "
"J M LOGAN INC "

sample output records:
last-name,middle-init,last-name
"JOHN J CRANLEY CO,,"

"MUTSCHELLER,JAMES,F"

"SOO,ROGER,"

TR
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue Jan 02, 2007 5:38 pm
Reply with quote

Hi TR,

Must be a training question 'cause an identical one was posted and solved right here. Just do some searching in the forum and very often the solution is there.
Back to top
View user's profile Send private message
b4uthammi
Warnings : 2

New User


Joined: 21 Feb 2005
Posts: 14
Location: hyderabad

PostPosted: Tue Jan 02, 2007 6:11 pm
Reply with quote

Hi Bitneuker,
Thanks for your early response.The posted query is not a training one.it is the one which i need to implement in one of my program(project).

yes, i have gone through the solution which is in the forum,but mine is different .

in the out put record i need to place ',' explicitly after every field.

Sample input data:

05 EMPLOYEE-NAME.
10 FIRST-NAME PIC X(12) VALUE 'JAME'
10 MIDDLE-INIT PIC X VALUE 'D'.
10 LAST-NAME PIC X(17) VALUE 'W A U & ASSOCIATE' .

expected output::

"W A U & ASSOCIATE,JAME,D"

THANKS,
TR
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue Jan 02, 2007 6:19 pm
Reply with quote

Have some reading about the string statement over here. The manual is at the forum (topline -> manuals)
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jan 02, 2007 6:49 pm
Reply with quote

b4uthammi wrote:
yes, i have gone through the solution which is in the forum,but mine is different .
I disagree, the solutions provided do exactly what you want.
Quote:
in the out put record i need to place ',' explicitly after every field.
With a very minor modification.....
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue Jan 02, 2007 7:00 pm
Reply with quote

Quote:
With a very minor modification.....
and following the link I posted before you may find out how......... icon_rolleyes.gif
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Tue Jan 02, 2007 8:09 pm
Reply with quote

You would have to code it as
STRING WS-first-name WS-mid-name WS-last-name
DELIMITED BY SIZE
INTO EMPLOYEE-NAME

Irrespective of the length of u r last name this will work.

If you want to put comma then

just define another structure of EMPLOYEE-NAME

as EMPLOYEE-NAME1


05 EMPLOYEE-NAME1.
10 FIRST-NAME PIC X(12).
10 ws-comma pic x(1) value ','.
10 MIDDLE-INIT PIC X.
10 ws-comma pic x(1) value ','.
10 LAST-NAME PIC X(17). EMPLOYEE-NAME1.

Move employee-name fields to employee-name1 fields and then use STRING.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Jan 02, 2007 8:17 pm
Reply with quote

vijayamadhuri wrote:
DELIMITED BY SIZE
Except that will not get the desired results icon_rolleyes.gif
Quote:
DELIMITED BY phrase
The DELIMITED BY phrase sets the limits of the string.
.
.
SIZE Transfers the complete sending area.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Jan 03, 2007 6:53 am
Reply with quote

TR,

The problem comes in determining the length of the significant characters in the string. This is where the ?INSPECT? and ?FUNCTION REVERSE? come in. Once you have the lengths of the individual strings then it?s pretty straight forward with ?STRING? or as priyesh.agrawal did with reference modification moves.

Take a look again at the post priyesh.agrawal made. The link is posted by Bitneuker Tue Jan 02, 2007 5:08 pm
Back to top
View user's profile Send private message
b4uthammi
Warnings : 2

New User


Joined: 21 Feb 2005
Posts: 14
Location: hyderabad

PostPosted: Wed Jan 03, 2007 12:23 pm
Reply with quote

Hi David,

It is working fine except for ','.
My requirement is after every string i want ','.

output::
last-name first-name middle-init
BEARDEN WARREN H

expected ouput:
BEARDEN,WARREN,H

Thanks in advance
TR
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jan 03, 2007 1:37 pm
Reply with quote

Hi b4uthammi

Your problem is already solved.MOVE ',' TO wherever you need

Thanks'
Arun
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 03, 2007 2:28 pm
Reply with quote

b4uthammi wrote:
It is working fine except for ','.
My requirement is after every string i want ','.
output::
last-name first-name middle-init
BEARDEN WARREN H
expected ouput:
BEARDEN,WARREN,H
Just for fun, post (using CODE) your code, I'll bet we can make it work exactly as you want it to. icon_smile.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jan 03, 2007 3:51 pm
Reply with quote

Hi

You can try STRING also


Code:

WORKING-STORAGE SECTION.       
77  FIR          PIC  X(20).   
77  MID         PIC  X(20).   
77  LAS         PIC  X(20).   
77  RESULT    PIC  X(60).   
77  FIR-LEN    PIC 99 VALUE 0.
77  MID-LEN   PIC 99 VALUE 0.
77  LAS-LEN   PIC 99 VALUE 0.

PROCEDURE DIVISION.                                       
    INSPECT FIR TALLYING FIR-LEN FOR CHARACTERS BEFORE '  '
    INSPECT MID TALLYING MID-LEN FOR CHARACTERS BEFORE '  '
    INSPECT LAS TALLYING LAS-LEN FOR CHARACTERS BEFORE '  '
    STRING FIR(1 : FIR-LEN) ','                           
           MID(1 : MID-LEN) ','                           
           LAS(1 : LAS-LEN)     DELIMITED BY SIZE         
    INTO RESULT                                     
    DISPLAY RESULT                                         
    STOP RUN.                                         



Thanks
Arun
Back to top
View user's profile Send private message
b4uthammi
Warnings : 2

New User


Joined: 21 Feb 2005
Posts: 14
Location: hyderabad

PostPosted: Wed Jan 03, 2007 4:47 pm
Reply with quote

Hai all,

My problem got resolved.now it is working fine with agarwal logic after few modifications.

Thanks
TR
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 03, 2007 5:07 pm
Reply with quote

b4uthammi wrote:
My problem got resolved.now it is working fine with agarwal logic after few modifications.
We've had so much fun trying to help, why don't you post your solution for all to enjoy?
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Thu Jan 04, 2007 2:04 am
Reply with quote

William Thompson wrote:
b4uthammi wrote:
My problem got resolved.now it is working fine with agarwal logic after few modifications.
We've had so much fun trying to help, why don't you post your solution for all to enjoy?


icon_wink.gif

Yes please...........
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Fri Jan 05, 2007 4:09 pm
Reply with quote

Concat Strings ... Here is a simple way to do it check out the below pgm
ID DIVISION.
PROGRAM-ID. PRAV.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INREC.
05 WS-VAR1 PIC X(4) VALUE 'KING'.
05 WS-VAR2 PIC X(2) VALUE 'K'.
05 WS-VAR3 PIC X(9) VALUE 'MARSHALL'.
PROCEDURE DIVISION.
PARA1.
DISPLAY WS-VAR1 ',' WS-VAR2 ',' WS-VAR3.
STOP RUN.

output would be
KING,K,MARSHALL
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Jan 05, 2007 11:28 pm
Reply with quote

Quote:

01 INREC.
05 WS-VAR1 PIC X(4) VALUE 'KING'.
05 WS-VAR2 PIC X(2) VALUE 'K'.
05 WS-VAR3 PIC X(9) VALUE 'MARSHALL'.


prav_06,

the problem was not so much how to string the variables together, as much as how to sting just the significant characters together.

If your input record were to read

Quote:

01 INREC.
05 WS-VAR1 PIC X(8) VALUE 'KING'.
05 WS-VAR2 PIC X(5) VALUE 'K'.
05 WS-VAR3 PIC X(10) VALUE 'MARSHALL'.


you display would yeald
Code:

'KING    ,K    ,MARSHALL '


and what was wanted was like your original display

Code:

KING,K,MARSHALL



icon_smile.gif
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Mon Jan 08, 2007 1:28 pm
Reply with quote

Hi David ,
I had tried running the pgm in my Mainframe machine it yeilded me an output
Quote:
King,K,Marshall
and not like
Quote:
'KING ,K ,MARSHALL
' , in the previous post i had just copied my output of my spool display. Kindly check the code.

Thanx,
Thamilzan.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Mon Jan 08, 2007 4:29 pm
Reply with quote

Hi Thamilzan

The problem was not just to display it in a particular way.It was to concatenate three variables(that might be having trailing spaces or spaces in between) into a single one and i think he has already got the solution.

Quote:
Hi David ,
I had tried running the pgm in my Mainframe machine it yeilded me an output Quote:
King,K,Marshall


How the trailing spaces got checked off by your mainframe machine!!!

Thanks
Arun
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 COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
Search our Forums:

Back to Top