Portal | Manuals | 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: 174
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: 1344
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

Senior Member


Joined: 21 Sep 2010
Posts: 2343
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: 174
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 COBOL batch program using large size ... Akriti Mishra COBOL Programming 3 Thu Mar 26, 2020 11:37 pm
No new posts Trying to submit COBOL PGM - JCL ERRO... sandeep prajapati JCL & VSAM 5 Tue Mar 24, 2020 11:21 pm
No new posts Export columns from DB2 table with pi... Nilanjan Sikdar DB2 13 Sun Mar 22, 2020 12:03 pm
No new posts How to create UUID using COBOL PORYES COBOL Programming 0 Tue Mar 17, 2020 4:43 pm
This topic is locked: you cannot edit posts or make replies. Cobol db2 program going in loop sivasaras COBOL Programming 4 Sat Feb 29, 2020 7:44 pm

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