×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

COBOL ERROR : Transfering data from txt file to another

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 .


RE: COBOL ERROR : Transfering data from txt file to another

What COBOL compiler are you using ?

IMO the file record description is not correct
You have

CODE

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).

       FD NSTUDENT.
          01 Ndetail.
             02 NId PIC 9(7).
             02 NName.
                03 NSurname PIC X(10).
             02 NYOBirth PIC 9(8). 
You say that the line looks like
8712351SMITH MS19671012LM51F 
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

(OP)
Thank for responding .
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

(OP)
?

RE: COBOL ERROR : Transfering data from txt file to another

You have to define record properly, or as you wrote, you can put the whole line in one field.

RE: COBOL ERROR : Transfering data from txt file to another

Hello AMCM,

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

IDENTIFICATION DIVISION.
       PROGRAM-ID.  CPYFILES.
         AUTHOR.  MIKROM.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT MY-INPUT-FILE ASSIGN TO "c:\tmp\cobol\my_input.txt"
               ORGANIZATION IS LINE SEQUENTIAL.
       SELECT MY-OUTPUT-FILE ASSIGN TO "c:\tmp\cobol\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'.

       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
               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

(OP)
Thank you very much .
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

(OP)
I tried it with perform loop but it doesnt work :
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

Quote (AMCM)


I tried it with perform loop but it doesnt work :
What does not work? What you want to do?
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
[code] 
and
[/code] 

RE: COBOL ERROR : Transfering data from txt file to another

(OP)
HELLO , my data looks like this :
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

It works, but you declared both counters too small and forgot to set initial value of the second counter.
Here is corrected example

RE: COBOL ERROR : Transfering data from txt file to another

Regarding the other example with the CSV file, post your question in the new thread.

Please do not post your program code unformated or as image, but formatted between the tags
[code] 
and
[/code] 
so that we can try it right away without adjusting it manually

RE: COBOL ERROR : Transfering data from txt file to another

(OP)
OK Thank you .

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close