COBOL SEQQUENTIAL FILE TO CSV
COBOL SEQQUENTIAL FILE TO CSV
(OP)
Hello ,
im trying to convert sequential cobol file to csv using data i found online.
I looking for a way to replace the first space with a coma and delete the others , is it possible ?
im trying to convert sequential cobol file to csv using data i found online.
CODE
IDENTIFICATION DIVISION. PROGRAM-ID. CPYFILES. AUTHOR. M. 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(180). FD MY-OUTPUT-FILE. 01 MY-OUTPUT-LINE PIC X(181). 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 i pic 9(3) value zero . 01 j pic 9(3) value 1 . 01 k pic 9(3) value 1 . PROCEDURE DIVISION. OPEN INPUT MY-INPUT-FILE OPEN EXTEND MY-OUTPUT-FILE SET NOT-END-OF-INPUT-FILE TO TRUE PERFORM UNTIL END-OF-INPUT-FILE READ MY-INPUT-FILE NOT AT END PERFORM VARYING i from 1 by 1 until i>180 If MY-INPUT-LINE(i:1)= SPACE continue ELSE MOVE MY-INPUT-LINE(i:1) to MY-OUTPUT-LINE (j:1) END-IF END-PERFORM 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.
I looking for a way to replace the first space with a coma and delete the others , is it possible ?
RE: COBOL SEQQUENTIAL FILE TO CSV
Input:
CODE -->
Output:
CODE -->
RE: COBOL SEQQUENTIAL FILE TO CSV
RE: COBOL SEQQUENTIAL FILE TO CSV
RE: COBOL SEQQUENTIAL FILE TO CSV
CODE
RE: COBOL SEQQUENTIAL FILE TO CSV
RE: COBOL SEQQUENTIAL FILE TO CSV
I've extended the basic read/write file example by enhancing the logic similar to that used for skipping spaces with counting spaces.
txt2csv.cbl
CODE
From the input file:
my_input.txt
CODE
the program creates this output file:
my_output.csv
CODE
RE: COBOL SEQQUENTIAL FILE TO CSV
Frank Clarke
--America's source for adverse opinions since 1943.
RE: COBOL SEQQUENTIAL FILE TO CSV
CODE
When using the function length was it necessary to put FUNCTION TRIM(WS-LINE instead of just WS-LINE , because it has already the trim data of the input ?
And I also don't understand the need to initialize MY-INPUT-LINE , i thought INITIALIZE was only used to replace characters in a variable .
RE: COBOL SEQQUENTIAL FILE TO CSV
For example, this satetment
CODE
CODE
CODE
The LENGTH without TRIM, i.e.:
CODE
CODE
CODE
CODE
The best way to see what the specific statement causes is to comment it out or modify it and try to run the program to see what happens.
RE: COBOL SEQQUENTIAL FILE TO CSV
RE: COBOL SEQQUENTIAL FILE TO CSV
RE: COBOL SEQQUENTIAL FILE TO CSV
CODE
I tried adding the third line to remove leading zeros from another file i have but it gives an error with "LEADING" , I researched the syntax for Trim function and it seems to be wright .
CODE
I tried using the unstring function but it also doesnt work .
RE: COBOL SEQQUENTIAL FILE TO CSV
As far as I know TRIM removes only leading and/or trailing spaces. Here is the syntax https://www.ibm.com/docs/en/cobol-zos/6.2?topic=fu...
RE: COBOL SEQQUENTIAL FILE TO CSV
This is the web site i went to ., after that i found that excel does it automatically for csv data , sorry to have wasted your time .
But the problem i found is that i want comas between more than 2 space i.e the columns of my txt file . I tried to do it with a 3rd index but i havnt found the solution yet .
RE: COBOL SEQQUENTIAL FILE TO CSV
You can remove the 8 leading zeros as follows:
CODE
Output:
CODE
RE: COBOL SEQQUENTIAL FILE TO CSV