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

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: 1353
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: 3051
Location: NYC,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

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top