concatenation of all table elements in a variable



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

concatenation of all table elements in a variable

Postby anchal » Wed Jun 23, 2010 11:28 am

I want to Concatenate all elements of a table elements are mon,tue,wed till sun.i want to display them in a single line with appropriate spaces but not able to do.please help me out it's urgent for me.

I have written the following code:-


01 WS-WEEKS.
05 DAY1 PIC X(3) VALUE 'MON'.
05 DAY2 PIC X(3) VALUE 'TUE'.
05 DAY3 PIC X(3) VALUE 'WED'.
05 DAY4 PIC X(3) VALUE 'THR'.
05 DAY5 PIC X(3) VALUE 'FRI'.
05 DAY6 PIC X(3) VALUE 'SAT'.
05 DAY7 PIC X(3) VALUE 'SUN'.
01 WS-WEEKS-TABLE REDEFINES WS-WEEKS.
05 WS-DAYS PIC X(03) OCCURS 7 TIMES.

01 I PIC 9(2) VALUE ZEROS.
01 STR PIC X(35) VALUE SPACES.
01 SPC PIC X(3) VALUE SPACES.


then i m doing this:-

PERFORM VARYING I FROM 1 BY 1 UNTIL I > 7
STRING WS-DAYS(I)
SPC
STR DELIMITED BY SPC
INTO STR

output desired is:-

mon tue wed thr fri sat sun
anchal
 
Posts: 5
Joined: Wed Jun 23, 2010 11:13 am
Has thanked: 0 time
Been thanked: 0 time

Re: concatenation of all table elements in a variable

Postby Robert Sample » Wed Jun 23, 2010 5:32 pm

Why not use something like
01 WS-WEEKS.
05 DAY1 PIC X(4) VALUE 'MON'.
05 DAY2 PIC X(4) VALUE 'TUE'.
05 DAY3 PIC X(4) VALUE 'WED'.
05 DAY4 PIC X(4) VALUE 'THR'.
05 DAY5 PIC X(4) VALUE 'FRI'.
05 DAY6 PIC X(4) VALUE 'SAT'.
05 DAY7 PIC X(4) VALUE 'SUN'.
.
.
.
MOVE WS-WEEKS TO <output area>.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: concatenation of all table elements in a variable

Postby anchal » Thu Jun 24, 2010 9:59 am

Thanks Robert.
anchal
 
Posts: 5
Joined: Wed Jun 23, 2010 11:13 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post