COBOL ERROR : Transfering data from txt file to another
COBOL ERROR : Transfering data from txt file to another
(OP)
HELLO ,
IDENTIFICATION DIVISION.
PROGRAM-ID. SeqRead.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT StudentFile ASSIGN TO "C:\Users\Hp\Documents\NT5.txt"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NSTUDENT ASSIGN TO "C:\Users\Hp\Documents\FILE-2.txt"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentDetails.
88 EndOfStudentFile VALUE HIGH-VALUES.
02 StudentId PIC 9(7).
02 StudentName.
03 Surname PIC X(10).
02 YOBirth PIC 9(8).
02 CourseCode PIC X(4).
02 gender pic x(1) .
02 malecount pic 9(3) value zeros.
02 femalecount pic 9(3) value zeros.
FD NSTUDENT.
01 Ndetail.
02 NId PIC 9(7).
02 NName.
03 NSurname PIC X(10).
02 NYOBirth PIC 9(8).
02 NCourseCode PIC X(4).
02 Ngender pic x(1) .
02 Nmalecount pic 9(3) value zeros.
02 Nfemalecount pic 9(3) value zeros.
PROCEDURE DIVISION.
Begin.
OPEN INPUT StudentFile
OPEN OUTPUT NSTUDENT
PERFORM until EndOfStudentFile
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
MOVE StudentDetails to Ndetail
DISPLAY Ndetail
WRITE Ndetail
END-PERFORM
CLose NSTUDENT
CLose StudentFile.
STOP RUN.
Im learning cobol ( still a beginner) , i have written the above code trying to transfer data from a .txt file to another but nothing tranfers and i get one letter written 36 times on the new file .
thise is the result file : ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
The originzl file is 36 lines like this one : 8712351SMITH MS19671012LM51F.
There is no error showing before compiling .
IDENTIFICATION DIVISION.
PROGRAM-ID. SeqRead.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT StudentFile ASSIGN TO "C:\Users\Hp\Documents\NT5.txt"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT NSTUDENT ASSIGN TO "C:\Users\Hp\Documents\FILE-2.txt"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD StudentFile.
01 StudentDetails.
88 EndOfStudentFile VALUE HIGH-VALUES.
02 StudentId PIC 9(7).
02 StudentName.
03 Surname PIC X(10).
02 YOBirth PIC 9(8).
02 CourseCode PIC X(4).
02 gender pic x(1) .
02 malecount pic 9(3) value zeros.
02 femalecount pic 9(3) value zeros.
FD NSTUDENT.
01 Ndetail.
02 NId PIC 9(7).
02 NName.
03 NSurname PIC X(10).
02 NYOBirth PIC 9(8).
02 NCourseCode PIC X(4).
02 Ngender pic x(1) .
02 Nmalecount pic 9(3) value zeros.
02 Nfemalecount pic 9(3) value zeros.
PROCEDURE DIVISION.
Begin.
OPEN INPUT StudentFile
OPEN OUTPUT NSTUDENT
PERFORM until EndOfStudentFile
READ StudentFile
AT END SET EndOfStudentFile TO TRUE
MOVE StudentDetails to Ndetail
DISPLAY Ndetail
WRITE Ndetail
END-PERFORM
CLose NSTUDENT
CLose StudentFile.
STOP RUN.
Im learning cobol ( still a beginner) , i have written the above code trying to transfer data from a .txt file to another but nothing tranfers and i get one letter written 36 times on the new file .
thise is the result file : ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
The originzl file is 36 lines like this one : 8712351SMITH MS19671012LM51F.
There is no error showing before compiling .
RE: COBOL ERROR : Transfering data from txt file to another
IMO the file record description is not correct
You have
CODE
i.e.:
8712351 - this is StudentId or NId
SMITH MS - this shoud be Surname
19671012 - this should be YOBirth or NYOBirth
LM51F - what is this ?
And why you placed the 88-level field EndOfStudentFile into the record 01 StudentDetails ?
RE: COBOL ERROR : Transfering data from txt file to another
IM using Opencobol IDE
LM51 IS THE COURSE CODE and the F is the gender .
I Placed the boolean there in order not to use a W-S section , Sometimes i get errors whithout explanation the ide just crashes .
DO you think if i put the whole line in an X variable that has enough space for them all , will that be enough ? I just used a txt file i had from another program that displays student information .
RE: COBOL ERROR : Transfering data from txt file to another
RE: COBOL ERROR : Transfering data from txt file to another
RE: COBOL ERROR : Transfering data from txt file to another
Here I have written a short example program, which copies the text file
c:\tmp\cobol\my_input.txt
line by line into the text file
c:\tmp\cobol\my_output.txt
I have tested it in OpenCobolIDE
CPYFILES.COB
CODE
RE: COBOL ERROR : Transfering data from txt file to another
I Have one last question I'm trying to convert a file that is in columns to a csv format but when i read the line can I use the initialize function to replace spaces by "," ?
I tried it but it keeps giving me an error .
RE: COBOL ERROR : Transfering data from txt file to another
IDENTIFICATION DIVISION.
PROGRAM-ID. CPYFILES.
AUTHOR. MIKROM.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MY-INPUT-FILE ASSIGN TO
"C:\Users\Hp\Documents\my_input.txt"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT MY-OUTPUT-FILE ASSIGN TO
"C:\Users\Hp\Documents\my_output.txt"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD MY-INPUT-FILE.
01 MY-INPUT-LINE PIC X(80).
FD MY-OUTPUT-FILE.
01 MY-OUTPUT-LINE PIC X(80).
WORKING-STORAGE SECTION.
01 END-OF-FILE PIC X VALUE SPACE.
88 END-OF-INPUT-FILE VALUE 'T'.
88 NOT-END-OF-INPUT-FILE VALUE 'F'.
01 X-COUNTER INDEX usage
01 X-OP-COUNTER index usage
PROCEDURE DIVISION.
MAIN-PARA.
OPEN INPUT MY-INPUT-FILE
OPEN OUTPUT MY-OUTPUT-FILE
SET NOT-END-OF-INPUT-FILE TO TRUE
PERFORM UNTIL END-OF-INPUT-FILE
READ MY-INPUT-FILE
NOT AT END
MOVE MY-INPUT-LINE TO MY-OUTPUT-LINE
[PERFORM VARYING X-COUNTER FROM 1 BY 1
UNTIL X-COUNTER > 80
IF MY-INPUT-LINE(X-COUNTER:1) = ' '
CONTINUE
ELSE
MOVE MY-INPUT-LINE (X-COUNTER:1) TO
MY-OUTPUT-LINE(X-OP-COUNTER:1)
ADD 1 TO X-OP-COUNTER
END-IF
END-PERFORM.
DISPLAY 'OUTPUT-VAR:' MY-OUTPUT-LINE.]
WRITE MY-OUTPUT-LINE
AT END
SET END-OF-INPUT-FILE TO TRUE
END-READ
END-PERFORM
CLOSE MY-INPUT-FILE
CLOSE MY-OUTPUT-FILE
STOP RUN.
RE: COBOL ERROR : Transfering data from txt file to another
Post an example of your data how it looks before processing and how it should look after processing.
Please post your formatted program code between the tags and
RE: COBOL ERROR : Transfering data from txt file to another
22346AROMANIACS E2005010
22346AROMANIACS E1005010
22346AROMANIACS E2005010
22346AROMANIACS E1005010
22346AROMANIACS E1005010
12344AROMANTICS E1802325
12344AROMANTICS E3002005
12344AROMANTICS E1102115
12344AROMANTICS E3002105
I want to put it in csv format .
Below is an exemple of a simple code that i tried to delete space without replacing them but it doesnt work .This the code i wanted to add to the code you gave me .
RE: COBOL ERROR : Transfering data from txt file to another
Here is corrected example
RE: COBOL ERROR : Transfering data from txt file to another
Please do not post your program code unformated or as image, but formatted between the tags and so that we can try it right away without adjusting it manually
RE: COBOL ERROR : Transfering data from txt file to another