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

Problem in Writing a Record to KSDS using Cobol pgm


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

New User


Joined: 14 Oct 2009
Posts: 6
Location: bangalore

PostPosted: Wed Oct 14, 2009 6:39 pm
Reply with quote

Hi
I am trying to write a cobol pgm which reads a sequential file and write to a ksds file.
my program is running successful but i am not able to write the records into ksds
i checked with my program by placing display statements everywhere and found that write statement is not running well
can you please find the error(logical one) in my program...
iam copying my program here

Code:

*PROGRAM TO READ SEQUENTIAL FILE AND WRITE THE CONTENTS TO KSDS
  IDENTIFICATION DIVISION.
  PROGRAM-ID.    SEQ2KSDS.
  ENVIRONMENT DIVISION.
  INPUT-OUTPUT SECTION.
  FILE-CONTROL.
      SELECT SOURCE-FILE ASSIGN TO DD1
             ORGANIZATION IS SEQUENTIAL
             ACCESS MODE IS SEQUENTIAL
             FILE STATUS IS WS-SEQ-STAT-CODE.
      SELECT DESTINATION-FILE ASSIGN TO DD2
             ORGANIZATION IS INDEXED
             ACCESS MODE IS SEQUENTIAL
             RECORD KEY IS DEST-EMP-NO
             FILE STATUS IS WS-KSDS-STAT-CODE.
  DATA DIVISION.
  FILE SECTION.
  FD SOURCE-FILE.
  01 SOURCE-REC.
      05 SOURCE-EMP-NO PIC 9(5).
      05 FILLER        PIC X(1).
      05 SOURCE-EMP-NM PIC X(25).
      05 FILLER        PIC X(49).
  FD DESTINATION-FILE.
  01 DESTINATION-REC.
      05 DEST-EMP-NO   PIC 9(5).
      05 FILLER        PIC X(1).
      05 DEST-EMP-NM   PIC X(25).
      05 FILLER        PIC X(49).
  WORKING-STORAGE SECTION.
  01 WS-KSDS-STAT-CODE PIC 9(2) VALUE ZERO.
  01 WS-SEQ-STAT-CODE  PIC 9(2) VALUE ZERO.
  01 WS-EOF            PIC X(1) VALUE 'N'.
  01 WS-CNT-INSERT     PIC 9(3) VALUE ZERO.
  01 WS-CNT-INV-INS    PIC 9(3) VALUE ZERO.
  PROCEDURE DIVISION.
  000-MAIN-PARA.
      DISPLAY 'INSIDE MAIN PARA.'.
      PERFORM 001-INITIALIZATION-PARA.
      PERFORM UNTIL WS-EOF = 'Y'
         READ SOURCE-FILE
             AT END
                MOVE 'Y' TO WS-EOF
             NOT AT END
                PERFORM 002-WRITE-REC-TO-DEST-PARA
         END-READ
      END-PERFORM
      PERFORM 003-DISPLAY-STATS-PARA.
      PERFORM 004-CLOSE-FILES.
      STOP RUN.
  001-INITIALIZATION-PARA.
      DISPLAY 'OPENING FILES.'.
      OPEN INPUT SOURCE-FILE
          OUTPUT DESTINATION-FILE.
      DISPLAY 'OPENED FILES SUCCESSFULLY.'.
  002-WRITE-REC-TO-DEST-PARA.
      DISPLAY 'INSIDE WRITE REC PARA.'.
      MOVE SOURCE-EMP-NO TO DEST-EMP-NO.
      MOVE SOURCE-EMP-NM TO DEST-EMP-NM.
      WRITE DESTINATION-REC
 *          RECORD KEY IS DEST-EMP-NO
            INVALID KEY
               DISPLAY 'ERROR IN WRITING RECORD :' SOURCE-EMP-NO
               ADD 1 TO WS-CNT-INV-INS
            NOT INVALID KEY
               DISPLAY SOURCE-EMP-NO ' IS INSERTED'
               ADD 1 TO WS-CNT-INSERT
      END-WRITE.
  003-DISPLAY-STATS-PARA.
      DISPLAY '--------------------------------------------------'.
      DISPLAY '***** TRANSACTION FILE PROCESSING STATISTICS '.
      DISPLAY '--------------------------------------------------'.
      DISPLAY 'NUMBER OF RECORDS INSERTED :'   WS-CNT-INSERT.
      DISPLAY 'NUMBER OF INVALID INS RECS :'   WS-CNT-INV-INS.
      DISPLAY '--------------------------------------------------'.
      DISPLAY '*******   END OF PROCESSING   ********************'.
  004-CLOSE-FILES.
      CLOSE SOURCE-FILE
            DESTINATION-FILE.

and the jcl used to run this is
Code:

//STEP1 EXEC PGM=SEQ2KSDS
//STEPLIB DD DSN=IDCL15.AUG14.LOAD(SEQ2KSDS),DISP=SHR
//DD1     DD DSN=IDCL15.AUG14.DATA,DISP=SHR
//DD2     DD DSN=IDCL15.AUG14.KSDS.V1,DISP=SHR
//SYSOUT  DD SYSOUT=*
//
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 14, 2009 6:58 pm
Reply with quote

Quote:
003710 DISPLAY 'OPENED FILES SUCCESSFULLY.'.
This is a lie. Since you do not use file status codes, you do not actually know that the files were opened successfully. Change your program to use file status codes and display them to help debug your problem.

Also, what error message(s) are you getting out when running the program?
Back to top
View user's profile Send private message
shyam6385

New User


Joined: 14 Oct 2009
Posts: 6
Location: bangalore

PostPosted: Wed Oct 14, 2009 7:39 pm
Reply with quote

hi,
I checked running my program with file status codes...
ya what you said is right
the ksds file is not opening
file status is showing as 39
that means record length mismatch..

so how to over come this problem..
please help..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 14, 2009 7:41 pm
Reply with quote

That's easy -- change your program record length to match the physical file. If you're not sure the size of the records in the physical file, run a LISTCAT to find out.

However, note that a 39 does not always mean the record length doesn't match -- read the manual description of file status 39 for a better idea of the various conditions that can cause it. For example, if the physical file has alternate index(es), you must indicate this in your COBOL program and change the JCL appropriately. Not doing so would also cause a file status 39.
Back to top
View user's profile Send private message
shyam6385

New User


Joined: 14 Oct 2009
Posts: 6
Location: bangalore

PostPosted: Wed Oct 14, 2009 7:54 pm
Reply with quote

Hi,
i tried that also
now the file is opening
but
it is showing this
IGZ0003W A logic error occurred for file DD2 in program SEQ2KSDS at relative location X'08DE'.


what is it?
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 Oct 14, 2009 8:37 pm
Reply with quote

Hello,

Suggest you post the VSAM DEFINE for this. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 14, 2009 8:51 pm
Reply with quote

When you compile your program, you either get an offset listing giving the offsets for each COBOL verb in your program, or a pseudo assembler for each statement in your PROCEDURE DIVISION. Whichever one you got, you can use to find the relative location, which tells you which statement has the problem and you can proceed from there.

However, if you displayed the file status value each time you did anything to the file,you could get an early start on debugging the problem.
Back to top
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 193
Location: chennai

PostPosted: Thu Oct 15, 2009 10:14 am
Reply with quote

Hi shyam6385

Look at your program. You are not reading the input file.
So use a read file statement, move the data to the destination and then write.

Before doing this you should solve the OPEN file issues.

Regards
Raghu
Back to top
View user's profile Send private message
shyam6385

New User


Joined: 14 Oct 2009
Posts: 6
Location: bangalore

PostPosted: Thu Oct 15, 2009 2:25 pm
Reply with quote

thank u one and all..
i have done with that program..
and a special thanks to Donald Knuth
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Oct 27, 2009 12:14 pm
Reply with quote

Quote:
and a special thanks to Donald Knuth

at first glance ...
why? the TAOCP does not contain anything related to the content of this topic

after rereading... I got the meaning icon_redface.gif

Robert Sample made the post icon_biggrin.gif
Donald Knuth is the author of the quote, ( which is part of the signature )

P.S.
Hi Robert ...
that' s something to be proud of.. nobody ever called me John ( Von Neumann )
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Oct 27, 2009 3:50 pm
Reply with quote

Thanks John (enrico) -- I feel honored to be mentioned in such distinguished company, but saddened that an IT "professional" does not recognize the name.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Oct 28, 2009 4:21 pm
Reply with quote

I wonder why did not he name you "TANSTAAFL"? icon_biggrin.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 28, 2009 5:46 pm
Reply with quote

LOL, Anuj -- it's happened (more than once) already.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top