Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COBOL - Array result in single variable with delimiter

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: COBOL - Array result in single variable with delimiter
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    Post subject: Reply to: COBOL - Array result in single variable with delimiter
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: 2467
Location: NY,USA

PostPosted: Fri Feb 21, 2020 7:00 am    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Undesired result while joining files. Khupe SYNCSORT 3 Tue Sep 22, 2020 8:05 pm
No new posts COBOL reading from SYSIN jzhardy COBOL Programming 1 Mon Sep 21, 2020 2:37 pm
No new posts how to read accounting information in... jzhardy COBOL Programming 1 Mon Sep 21, 2020 9:57 am
No new posts IWS/TWS build dinamic or variable APp... JCDM IBM Tools 0 Mon Sep 07, 2020 6:49 pm
No new posts NOT IN clause in COBOL pgm mramvivek COBOL Programming 8 Thu Aug 20, 2020 4:48 am

Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us