Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Appending a variable with values separated by commas

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 60
Location: San Diego

PostPosted: Wed Jan 14, 2009 11:12 pm    Post subject: Appending a variable with values separated by commas
Reply with quote

I want to find out a method how i can code this one in COBOL:

i fetch records one at a time from a DB2 table and for each fetch i append one of the column value to variable and then suffix with a comma excepting the last record fetched.

example:
open cursor1
fetch into cursor1 :K1

1st fetch,
var1 = K1
2nd fetch
var1= K1,K1
3rd fetch
var1 = K1,K1,K1
...etc.,
last fetch
var1 = K1,K1,K1,...K1

any tips for this will be greatly appreciable.

[/code]
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Wed Jan 14, 2009 11:38 pm    Post subject:
Reply with quote

How is variable K1 defined? Do you care about extra spaces around the comma?
Back to top
View user's profile Send private message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 60
Location: San Diego

PostPosted: Wed Jan 14, 2009 11:44 pm    Post subject:
Reply with quote

K1 is defined numerical. spaces around comma is not a problem. Just looking for a simple append mechanism in COBOL
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Jan 15, 2009 12:23 am    Post subject:
Reply with quote

Will these resultant concatenated values of K1 separated by commas end up to be a variable length record to be written out? If so, I'd populate the record using reference modification.
Back to top
View user's profile Send private message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 60
Location: San Diego

PostPosted: Thu Jan 15, 2009 12:43 am    Post subject:
Reply with quote

nope iam not using this to create variable length records, but to compare fields in 2 files in JCL , where some times the number of fields to be compared will vary based on the fetch from table.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Thu Jan 15, 2009 12:54 am    Post subject:
Reply with quote

Reference modification will work fine. This code
Code:
           05  I                       PIC 9(04) VALUE 1.
           05  WS-VAR1                 PIC 999.99.
           05  WS-VAR2                 PIC 999.99.
           05  WS-VAR-OUT              PIC X(2048) VALUE SPACE.

       LINKAGE SECTION.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE 123.45                 TO  WS-VAR1.
           MOVE  98.76                 TO  WS-VAR2.
           MOVE WS-VAR1                TO  WS-VAR-OUT (I : 6).
           ADD 6                       TO  I.
           MOVE ','                    TO  WS-VAR-OUT (I : 1).
           ADD 1                       TO  I.
           MOVE WS-VAR2                TO  WS-VAR-OUT (I : 6).
           ADD 6                       TO  I.
           MOVE ','                    TO  WS-VAR-OUT (I : 1).
           ADD 1                       TO  I.
           MOVE WS-VAR1                TO  WS-VAR-OUT (I : 6).
           ADD 6                       TO  I.
           MOVE ','                    TO  WS-VAR-OUT (I : 1).
           ADD 1                       TO  I.
           MOVE WS-VAR2                TO  WS-VAR-OUT (I : 6).
           ADD 6                       TO  I.
           DISPLAY WS-VAR-OUT (1 : I) .
produces this output:
Code:
 123.45,098.76,123.45,098.76
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Jan 15, 2009 12:55 am    Post subject:
Reply with quote

I guess my question concerning the record was unnecessary. I'd still use reference modification to populate VAR1, which needs to be large enough to receive the results of all the fetches. Instead of using K1,K1,K1,...K1 as your example output, please show a more realistic output example.
Back to top
View user's profile Send private message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 60
Location: San Diego

PostPosted: Thu Jan 15, 2009 6:26 pm    Post subject:
Reply with quote

The output is same as robert as put above nonly that it is not in decimal and as the declaration of the 2 variable are:
WS-VAR1 PIC 999
WS-VAR2 PIC 999
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Thu Jan 15, 2009 6:56 pm    Post subject:
Reply with quote

So use 3 instead of 6 as the increment to I.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Jan 15, 2009 8:25 pm    Post subject:
Reply with quote

Or better yet, use the LENGTH OF special register instead of a hard-coded number in case the picture sizes changes in the future.
Code:
MOVE WS-VAR1          TO WS-VAR-OUT (I:LENGTH OF WS-VAR1)
ADD LENGTH OF WS-VAR1 TO I
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Thu Jan 15, 2009 8:26 pm    Post subject:
Reply with quote

Good point, Terry. I should have thought of that when I was coding it up.
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 Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts setting new limit Key values for inde... srilata83 DB2 1 Fri Feb 10, 2017 9:24 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us