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

Logic to read a table using cursor


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Nov 14, 2012 1:38 pm
Reply with quote

Hi,

My requirement is i have to read a table using cursor and table will have some currency information...If retrieved currency is 2 then i have to create two files and if it is 4 i have to created 4 files..Could anyone let me know how to proceed on this

Regards
Karthik
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Wed Nov 14, 2012 1:45 pm
Reply with quote

Yes, you need to start writing the code in the language of your (site's) choice. Please refer the suitable language manual for the same.

Assuming DB2 table, IBM manual on DB2 Application programming has the information on how to DECLARE CURSOR, its FETCH and related stuffs.
Back to top
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Nov 14, 2012 1:50 pm
Reply with quote

Hi Gnanas,

I have written program,,,but just want to know how can i create files dynamically based on the number of rows fetched from the table..is there any way to do it.

Thanks for your help
Regards
Karthik
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 14, 2012 1:53 pm
Reply with quote

Completely different question.

What have you written the program in? Not in JCL, I'd guess. So let us know, and we can move the topic to the correct forum.

What is the problem with having four files and two of them are "empty" (best to contain good headers and trailers and no data so they are "logically empty" rather than physically empty)?
Back to top
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Nov 14, 2012 2:16 pm
Reply with quote

Hi Bill,

1.The program is simple to retrieve the records from one column of the table,say currency.

2.I have given a example,the table may have 10 currencies or 2 currencies and so on.so depending on the row retrieved i have to create the file dynamically .

Regards
Karthik
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 14, 2012 2:33 pm
Reply with quote

OK, we still don't know what language, but have a search for BPXWDYN then if you really want to go that route.
Back to top
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Wed Nov 14, 2012 2:41 pm
Reply with quote

Hi Bill,

Program is written in cobol.

Is there anyway to control the dynamic allocation by executing above program with JCL?

Regards
Karthik
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Nov 14, 2012 2:44 pm
Reply with quote

Perhaps you can describe what you mean by that? Bear in mind how JCL works (once it has been CONVERTED/INTERPRETED the JCL itself is tossed away).
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 14, 2012 7:58 pm
Reply with quote

Hello,

If you do not want to allocate files dynamically, you could have the cobol program read the "currency" and set a condition code based on the value (2, 4, 10, whatever).

Then subsequent steps would run depending on the condition code.

The remainder of the steps would need to be set up for the maximum possible.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Nov 14, 2012 9:06 pm
Reply with quote

i admittedly do not like dynamic allocation of output files in COBOL,
because you can not tell from
the JCL
or the COBOL SELECT statements
or the COBOL FD's
how many files are being output.

my preference would be the append a record (file type/number)
to each output record
and then use a sort product to generate the variable number of output files.

there are numerous examples of sort solution to this problem.

also, I don't know how many dynamically allocated output files
can be open simultaneously in a COBOL program.
don't know if it is an issue.

and as far as the COBOL logic is concerned,
you would probably be best served by sorting your results set by currency number.
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Thu Nov 15, 2012 9:11 am
Reply with quote

Karthik,

Below mentioned code will dynamically generate output file for the number of records in the input file. You can replace the input file with cursor.

Code:
******************************************************************
      **                                                               *
      **   I D E N T I F I C A T I O N    D I V I S I O N              *
      **                                                               *
      ******************************************************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID.    DYN.                                             
       AUTHOR.        TCSL.                                             
       DATE-WRITTEN.  08/27/2010.                                       
                                                                       
      *                                                                 
       ENVIRONMENT DIVISION.                                           
       CONFIGURATION SECTION.                                           
       SOURCE-COMPUTER.        IBM-370.                                 
       OBJECT-COMPUTER.        IBM-390.                                 
      *                                                                 
       INPUT-OUTPUT SECTION.                                           
       FILE-CONTROL.                                                   
            SELECT INFILE    ASSIGN  TO  INFILE.                       
            SELECT OUTPUT-FILE   ASSIGN  TO  OUTFILE.                   
      *                                                                 
       DATA DIVISION.                                                   
       FILE SECTION.                                                   
      *                                                                 
       FD  INFILE                                                       
           LABEL RECORD IS STANDARD                                     
           RECORDING MODE IS F                                         
           BLOCK CONTAINS 0 RECORDS.                                   
      *                                                                 
       01  INPUT-REC                        PIC X(80).                 
      *                                                                 
       FD  OUTPUT-FILE                                                 
           LABEL RECORD IS STANDARD                                     
           RECORDING MODE IS F                                         
           BLOCK CONTAINS 0 RECORDS.                                   
      *                                                                 
       01  OUTPUT-REC                       PIC X(80).                 
      *                                                                 
      ******************************************************************
      *                   WORKING STORAGE SECTION                      *
      ******************************************************************
                                                                       
       WORKING-STORAGE SECTION.                                         
      *                                                                 
       01 WS-ENVIRONMENT-VARIABLE       PIC X(150) VALUE SPACE.         
       01 WS-PUTENV-RETURN-CODE         PIC S9(9) COMP.                 
       01 WS-PUTENV-POINTER             POINTER.                       
       01 WS-ENV-1                      PIC X(12) VALUE                 
                                                       'OUTFILE=DSN('. 
       01 WS-DSN                        PIC X(40) VALUE SPACE.         
       01 WS-ENV-2                      PIC X(27) VALUE                 
          ') NEW CATALOG TRACKS SPACE('.                               
       01 WS-ENV-PRI-TRACKS                  PIC 9(04).                 
       01 WS-ENV-3                           PIC X(33) VALUE           
           ',1) UNIT(SYSDA)'.                                           
      *                                                                 
       01 WS-DSN-NAME.                                                 
          05 FILLER                          PIC X(18) VALUE           
             'XXXXXXX.SAI.TEST.V'.                                     
          05 WS-DSN-NUMBER                   PIC 9(04) VALUE ZEROES.   
      *                                                                 
       01 WS-LIT-ZERO                        PIC 9     VALUE ZERO.     
       01 WS-END-FILE                        PIC X(03) VALUE SPACE.     
      *                                                                 
       LINKAGE SECTION.                                                 
      *                                                                 
       PROCEDURE DIVISION.                                             
      *                                                                 
       0000-MAINLINE.                                                   
      *                                                                 
           DISPLAY '<OPENING THE FILE>'                                 
           OPEN INPUT INFILE.                                           
           DISPLAY '<STARTING THE READ PROCESS>'                 
           MOVE 'NO' TO WS-END-FILE.                             
           PERFORM 1000-PROCESS THRU 1000-EXIT                   
           UNTIL WS-END-FILE = 'YES'.                           
           CLOSE INFILE.                                         
      *                                                         
           STOP RUN.                                             
      *                                                         
       0000-EXIT.                                               
           EXIT.                                                 
      *                                                         
       1000-PROCESS.                                             
      *                                                         
           READ INFILE                                           
                AT END MOVE 'YES' TO WS-END-FILE.               
           IF WS-END-FILE = 'NO'                                 
              PERFORM 2000-DYN-FILE THRU 2000-EXIT               
           END-IF.                                               
      *                                                               
       1000-EXIT.                                                     
           EXIT.                                                     
      *                                                               
       2000-DYN-FILE.                                                 
      *                                                               
              ADD +1                         TO WS-DSN-NUMBER.       
              MOVE +100                      TO WS-ENV-PRI-TRACKS.   
              MOVE WS-DSN-NAME               TO WS-DSN.               
              INITIALIZE WS-ENVIRONMENT-VARIABLE.                     
              STRING WS-ENV-1          DELIMITED BY SIZE             
                     WS-DSN            DELIMITED BY ' '               
                     WS-ENV-2          DELIMITED BY SIZE             
                     WS-ENV-PRI-TRACKS DELIMITED BY SIZE             
                     WS-ENV-3          DELIMITED BY SIZE             
              INTO WS-ENVIRONMENT-VARIABLE.                           
              DISPLAY 'WS-ENVI-VARIABLE<'WS-ENVIRONMENT-VARIABLE'>'   
              SET WS-PUTENV-POINTER TO ADDRESS OF                     
                  WS-ENVIRONMENT-VARIABLE.                             
              DISPLAY '<CALLING PUTENV>'                               
              CALL 'PUTENV' USING BY VALUE WS-PUTENV-POINTER           
                            RETURNING WS-PUTENV-RETURN-CODE.           
              DISPLAY 'WS-PUTENV-RETURN-CODE<'WS-PUTENV-RETURN-CODE'>'
              IF WS-PUTENV-RETURN-CODE = WS-LIT-ZERO                   
                 OPEN OUTPUT OUTPUT-FILE                               
                 MOVE INPUT-REC TO OUTPUT-REC                         
                 WRITE OUTPUT-REC                                     
                 CLOSE OUTPUT-FILE                                     
              ELSE                                                     
                 DISPLAY 'PUTENV CALL ERRORED<'WS-PUTENV-RETURN-CODE'>'
              END-IF.                                                 
      *                                                               
       2000-EXIT.                                                     
           EXIT.     
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Thu Nov 15, 2012 9:14 am
Reply with quote

I used below mentioned JCL to execute the program mentioned in above post.

Code:
//XXXXXXX8  JOB (ACCOUNT),'XXXXXXX X3350',MSGCLASS=X,     
//          CLASS=A,NOTIFY=XXXXXXX,TIME=1440               
//*                                                       
//JOBLIB  DD DSN=XXXXXXX.ZZTEST.LOADLIB,DISP=SHR           
//*                                                       
//STEP06  EXEC PGM=DYN                                     
//SYSPRINT DD SYSOUT=*                                     
//SYSOUT   DD SYSOUT=*                                     
//INFILE   DD DSN=XXXXXXX.SAI.TEST,DISP=SHR   
Back to top
View user's profile Send private message
karthik3883

New User


Joined: 19 Oct 2007
Posts: 37
Location: chennai

PostPosted: Thu Nov 15, 2012 11:22 am
Reply with quote

Hi Sai,

Thanks a lot for your help.Will implement your logic and if i need anything i will comback to you.

Regards
Karthik
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 Error to read log with rexx CLIST & REXX 11
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top