IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search Log in to check your private messages Log in
 

COBOL - Array result in single variable with delimiter


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

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Feb 20, 2020 5:29 pm
Reply with quote

Hi Team,

I have the information retrieved by means of below code

Code:
01 WS-NAME-AGE     OCCURS 3 TIMES    INDEXED BY i.
     10  WS-NAME-ARR      PIC X(20)
     10  WS-AGE-ARR       PIC 9(03)

PERFORM 0500-OPEN-NAME-TBL
PERFORM 1000-FETCH-NAME-TBL
PERFORM VARYING i FROM 1 BY 1
      UNTIL I > 3 OR SQLCODE NOT = 0
      MOVE WS-NAME   TO WS-NAME-ARR (i)
      MOVE WS-AGE   TO WS-AGE-ARR (i)         
      PERFORM 1000-FETCH-NAME-TBL
END-PERFORM

Code:
Output is
RAM                  25
RAJU                 30
ARUN                15


I would like to have the above result in single variable declared as 75 bytes
Code:
RAM                  ;25,RAJU                ;0,ARUN                ,15


Could you please let me know how to achieve this result.

Thanks
Vinu
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1348
Location: Israel

PostPosted: Thu Feb 20, 2020 6:54 pm
Reply with quote

It is so easy and obvious that I almost didn't submit an answer...
Code:
01  WS-SINGLE-VAR.
  05 WS-NAME-AGE     OCCURS 3 TIMES    INDEXED BY i.
     10  WS-NAME-ARR      PIC X(20).
     10  WS-SEP-MID       PIC X.
     10  WS-AGE-ARR       PIC 9(03).
     10  WS-SEP-END       PIC X.

PERFORM 0500-OPEN-NAME-TBL
PERFORM 1000-FETCH-NAME-TBL
PERFORM VARYING i FROM 1 BY 1
      UNTIL I > 3 OR SQLCODE NOT = 0
      MOVE WS-NAME   TO WS-NAME-ARR (i)
      MOVE WS-AGE   TO WS-AGE-ARR (i)         
      MOVE ';' TO WS-SEP-MID (i)
      PERFORM 1000-FETCH-NAME-TBL
      IF (SQLCODE = 0) AND (I < 3)) THEN
          MOVE ',' TO WS-SEP-END (i)
      END-IF
END-PERFORM
DISPLAY WS-SINGLE-VAR

With this code, the DISPLAY will show:
Code:
RAM                 ;25,RAJU                ;30,ARUN                ;15
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2508
Location: NY,USA

PostPosted: Fri Feb 21, 2020 7:00 am
Reply with quote

Even more simple , What stops doing concat in SELECT itself and get in one line in fetch ?
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Fri Feb 21, 2020 5:58 pm
Reply with quote

Thanks very much Marso. That helps.
Rohit - I will try this logic too.

Thanks
Vinu
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

 

Search our Forum:

Similar Topics
Topic Forum Replies
No new posts FILE STATUS - 39 ON VARIABLE LENGTH V... COBOL Programming 1
No new posts COBOL Performance Tuning COBOL Programming 6
No new posts JCL for replacing code in Cobol JCL & VSAM 8
No new posts COBOL VS SORT Utility for file format... COBOL Programming 6
No new posts Need to split single line into two li... DFSORT/ICETOOL 7

Back to Top