Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TXT File Created By Cobol Program

Status
Not open for further replies.

klophockey

Programmer
May 25, 2016
41
US
The .dat file output of a Cobol program is normal.

Is there a way to generate a .txt file out of a Cobol program?

I would appreciate a coding example that worked for you.

Thank you
 
depending on your COBOL brand/version you will need to look at defining a file as Line Sequential - or just sequential with some quirks.

standard sequence - open file output, write records, close file - no need for an example.

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Thank you very much for responding.

I had done some research and did see references to defining a file as Line Sequential.

I was thinking that would be the way to resolve my question but did want to hear from experts who may have directed me differently.

I appreciate the time you took to share your information with me.
 
SI A ALGUIEN LE PUEDE SERVIR DE AYUDA, ADJUNTO PROGRAMA COBOL PARA CONVERTIR FICHEROS DAT A TXT O GENERAR ESTE TIPO DE FICHERO.

IDENTIFICATION DIVISION.
PROGRAM-ID. COPIA.
* convierte fichero en formato .DAT a .TXT.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT ENTRADA
ASSIGN TO RANDOM, "DATOS01"
ORGANIZATION IS SEQUENTIAL.
SELECT SALIDA
ASSIGN TO RANDOM, "SALIDA.TXT"
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD ENTRADA.
01 REG-ENTRADA PIC X(16).
FD SALIDA.
01 REG-SALIDA.
02 REG-SAL PIC X(16).
02 CONTROL-SAL PIC X.
WORKING-STORAGE SECTION.
01 W-CONTROL PIC X VALUE X"0D".
* este campo con formato hexadecimal sirve para delimitar el
* registro. IMPRESCINDIBLE.
01 W-LEIDOS PIC 9(4) VALUE 0.
01 W-GRABADOS PIC 9(4) VALUE 0.
PROCEDURE DIVISION.
ABRIR-FICHEROS.
OPEN INPUT ENTRADA.
OPEN OUTPUT SALIDA.
LEE-ENTRADA.
READ ENTRADA
AT END
GO TO CERRAR-FICHEROS.
ADD 1 TO W-LEIDOS.
GRABA-SALIDA.
MOVE REG-ENTRADA TO REG-SAL.
MOVE W-CONTROL TO CONTROL-SAL.
WRITE REG-SALIDA.
ADD 1 TO W-GRABADOS.
GO TO LEE-ENTRADA.
CERRAR-FICHEROS.
DISPLAY "REGISTROS LEIDOS " W-LEIDOS.
DISPLAY "REGISTROS GRABADOS " W-GRABADOS.
CLOSE ENTRADA.
CLOSE SALIDA.
STOP RUN.

 
 https://files.engineering.com/getfile.aspx?folder=4174fc02-7141-4500-afb8-2d35cb51f28c&file=COPIA.exe
Also keep in mind if the file needs to retain special characters (like tabs, form feeds...) or trailing spaces. Some compilers/runtimes (like Micro Focus) like to strip trailing spaces or automatically precede special characters with their own special characters.
 
Thanks very much for the input to this question.
I was successful in getting done what I wanted to do.

NOT TO INSULT ANYONE's INTELLIGENCE....Just wanting to share what I learned from those who shared with me and my actual coding experience.

Here is how I did it:

Create a program to open a file. That's all it does. It gets the file created for the Processing programs to open and add data lines to it.
FILE-CONTROL.
SELECT MytestFile ASSIGN TO "Mytext.txt"
ORGANIZATION IS LINE SEQUENTIAL.
.
.
Open OUTPUT MytextFile.
Close MytextFile.

The 'OPEN' program to create the text file is EXECUTED FIRST IN THE STREAM OF PROGRAMS OF A GIVEN PROCESS.


THEN IN SUBSEQUENT PROGRAMS WHERE YOU WANT TO PUT OUT DATA THAT NEEDS TO BE CAPTURED TO BE QUERIED AS A WHOLE TO SEE IF EVERYTHING 'PASSED' IN THE PROCESS

PROGRAM # 1
FILE-CONTROL.
SELECT MytextFile ASSIGN TO "Mytext.txt"
ORGANIZATION IS LINE SEQUENTIAL.
.
.
* The MytextFile file is opened EXTEND so data can added to it
* This file is used to capture test case results data for RMCobol
* because Display verbs are not written to a file in RMCobol.

Open EXTEND MytextFile.
Move spaces to W-MessageArea.
Move "Begin program1 Program Testing" to W-ResultMsg.
Write MyresultDetails from W-MessageArea.

THIS WILL PUT OUT A ERROR THAT WAS FOUND
Move spaces to W-Fail-Msg
Move
"FAIL - Value is not numeric - Big Number paragraph "
to W-Fail-Msg
Perform RMCbl-Results-Fail-Msg
Move spaces to W-Fail-Msg
Move "Fail Reason" to W-Fail-Reason-Lit
Move status-code to W-Fail-Reason-Code
Perform RMCbl-Results-Fail-Msg

RMCbl-Results-Fail-Msg.
Move spaces to W-MessageArea.
Move W-Fail-Msg to W-MessageArea.
Write MyresultDetails from W-MessageArea.

THEN - WHEN ALL PROCESSING IS COMPLETED IN THE PROGRAM, THE MytextFile file will be closed automatically by the program.

IN THE NEXT PROGRAM IN THE PROCESS, Open it just like program #1 and it will continue to add data lines to the Mytext.txt file right after the ones that were added in program # 1.

When I was done with my process execution, the Mytext.txt file was available for me to query looking for Pass or Fail to know how the process ran.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top