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

How to avoidOverwrite the file


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

New User


Joined: 31 Jul 2007
Posts: 47
Location: chennai

PostPosted: Sun Oct 16, 2011 7:28 am
Reply with quote

SELECT A,B,C FROM XXX.EMP;
For Example:
values in the table
1 2 3
4 5 6
First I've retrieved all the rows in the table using cursor.
Logic:


Code:

PERFORM UNTIL SQLCODE = 100
IF A NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
IF B NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
IF C NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
FETCH CURS01 INTO :A,:B,:C
END-PERFORM

Excepted Output:
in the Output File:
1 2 3
4 5 6
---------------
I'm getting only
3
6
----------------
It's overwriting the file. How to change the logic.
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: Sun Oct 16, 2011 8:41 am
Reply with quote

Hello,

What you have posted shows nothing we can use to help. . .

The code posted shows IFs and WRITEs before the cursor iseven fetched. . .

How is the file defined? How many times is it opened and closed?

If you are doing multiple writes between fetches, how could there ever be more than one value in an output record?
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: Sun Oct 16, 2011 1:55 pm
Reply with quote

The code you have posted is obviously "pseudo-code".

If that were working, your output would be:

1
2
3
4
5
6

Since you do a write for each field (you can do that in pseudo-code, but not in real code without some more statements).

There is not much point in us de-bugging pseudo-code, because that is not where your problem is.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Sun Oct 16, 2011 8:08 pm
Reply with quote

senthilnathanj wrote:
Code:


IF A NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
IF B NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
IF C NOT= SPACE THEN
    WRITE FOUTFILE
END-IF
FETCH CURS01 INTO :A,:B,:C
END-PERFORM

Excepted Output:
in the Output File:
1 2 3
4 5 6
---------------
I'm getting only
3
6
----------------
It's overwriting the file. How to change the logic.



With what little you have given us i would suggest:
Code:
PERFORM UNTIL SQLCODE = 100
IF A NOT = SPACES
 OR B NOT = SPACES
 OR C NOT = SPACES
   WRITE FOUTFILE
END-IF
FETCH CURS01 INTO :A,:B,:C
END-PERFORM

[/code]
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: Sun Oct 16, 2011 9:20 pm
Reply with quote

Code:
01  FOUTFILE-RECORD.
    05  A PIC X.
    05  B REDEFINES A PIC X.
    05  C REDEFINES B PIC X.


Assuming that A, B and C receive data, and that the are all defined in the output record, then something like the above would generate the output you are getting, except for the number of records...

Or:

Code:
01  A PIC X.
01  B PIC X.
01  C PIC X.


underneath the FD. This would cause an "implicit redefines" so A B and C all occupy the same storage space, A would get a value, B would get a value overwriting A, C would get a value overwriting B (and A).

In your output you show nothing in place of the expected A and B values and only what we can assume is the C value appearing.

However, you only get two output records from six writes, implying that A and B are always space on what you have shown so far.

You have to show us more. Dick has pointed out that you have writes before the FETCH - is that why you put the IFs in? You need the/a FETCH before you try to use the data from the FETCH.

You will have to show your FD (for FOUTFILE) and definitions associated with it and all the relevant code in the PROCEDURE DIVISION.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Oct 16, 2011 9:48 pm
Reply with quote

why keep speculating ?
let' s wait for the TS to come back with some more details ...
or disappear forever icon_wink.gif
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: Mon Oct 17, 2011 5:11 am
Reply with quote

Hello,

When the TS started the duplicate (now locked) topic nothing additional to help us help TS was posted. . . icon_sad.gif

We still need to see how the output file is defined and when it is opened and closed.

I'm sure ALL of the problem is in the file definition or processing code, but so far, TS has not been able/willing to provide these.

Suggest the code be modified to do a DISPLAY every time a WRITE is executed to help determine if something is lost or never written. . .
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Oct 17, 2011 5:27 am
Reply with quote

The field names in the new posting "NO,NAME,COURSE" make it look like a class assignment, or there are a lot of companies trying to track their employees class attendance and assigning very junior programmers to handle the programming.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 17, 2011 12:19 pm
Reply with quote

just for reference here is the link to the locked topic
www.ibmmainframes.com/viewtopic.php?t=56463&highlight=
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top