View previous topic :: View next topic
|
Author |
Message |
senthilnathanj
New User
Joined: 31 Jul 2007 Posts: 47 Location: chennai
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
why keep speculating ?
let' s wait for the TS to come back with some more details ...
or disappear forever |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
When the TS started the duplicate (now locked) topic nothing additional to help us help TS was posted. . .
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
|