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: 8057
Location: East Dubuque, Illinois, USA

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: 8057
Location: East Dubuque, Illinois, USA

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: 8057
Location: East Dubuque, Illinois, USA

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: 8057
Location: East Dubuque, Illinois, USA

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 Sorting of hex values Saurabh_mi DFSORT/ICETOOL 10 Thu May 25, 2017 3:49 pm
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Compare two files and subtract values ameetmund DFSORT/ICETOOL 7 Fri Mar 31, 2017 3:35 pm


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