Page 1 of 2

Reading Manually Inputted Cobol File

PostPosted: Fri Mar 11, 2011 1:27 am
by SnIpY
Hello,

I know how to read file when the file is fixed in cobol. But how can I let the user input a filename and the system checks if it exists and if it does, it loads that? All files will have the same structure..

I now have it like this:
 INPUT-OUTPUT SECTION.
       FILE-CONTROL.
         SELECT gegevens ASSIGN TO "projectenIIexport.csv"
           ORGANIZATION IS LINE SEQUENTIAL
           ACCESS MODE  IS SEQUENTIAL.


But that's hardcoded.. Any ideas?

Re: Reading Manually Inputted Cobol File

PostPosted: Fri Mar 11, 2011 1:49 am
by Robert Sample
Google is your friend. Google BPXWDYN and start looking at the 11,700 hits returned on how to allocate a file at run-time in COBOL. I'm not sure if you can test for file existence with BPXWDYN, though.

WARNING: BPXWDYN is not something for a novice COBOL coder to attempt to use. It is an advanced topic and successful use requires an understanding of COBOL, file allocation, and the TSO ALLOC command.

Re: Reading Manually Inputted Cobol File

PostPosted: Fri Mar 11, 2011 1:53 am
by enrico-sorichetti
I do not see how the issue might be MAINFRAME Cobol related
SELECT gegevens ASSIGN TO "projectenIIexport.csv"
ORGANIZATION IS LINE SEQUENTIAL

is related to a windoze/linux environment
or at most to a unix system services environment

check the manual on how to pass parameters to an executable!

for C style argument passing ( the only one viable for a PC environment )
google for cobol argc argv

Re: Reading Manually Inputted Cobol File

PostPosted: Sat Mar 12, 2011 1:26 am
by mickeywhite
That looks alot like microfocus Unix server cobol code. You can pass an argument(s) in the script to the program and the arguments can be the file names (or even variables in the script that represent file names)
       file-control.

        select i assign i-cmd
         organization is sequential.

        select o assign o-cmd
         organization is sequential.



           accept arg-knt from argument-number
           if  arg-knt <> 2
               display 'programX requires 2 arguments' upon syserr
               move -1 to return-code
               stop run
           end-if
           accept i-cmd from argument-value
           accept o-cmd from argument-value

           open input i
           open output o

Re: Reading Manually Inputted Cobol File

PostPosted: Sat Mar 12, 2011 1:37 am
by Robert Sample
enrico: the file name is suspiciously non-IBM but the rest of the original post code is stragiht from the COBOL Language Reference manual:
4.2.5 ORGANIZATION clause


The ORGANIZATION clause identifies the logical structure of the file. The logical structure is established at the time the file is created and cannot subsequently be changed.

You can find a discussion of the different ways in which data can be organized and of the different access methods that you can use to retrieve the data under "File organization and access modes" in topic 4.2.8.1.

ORGANIZATION
IS SEQUENTIAL (format 1) A predecessor-successor relationship among the records in the file is established by the order in which records are placed in the file when it is created or extended.

ORGANIZATION
IS INDEXED (format 2) The position of each logical record in the file is determined by indexes created with the file and maintained by the system. The indexes are based on embedded keys within the file's records.

ORGANIZATION
IS RELATIVE (format 3) The position of each logical record in the file is determined by its relative record number.

ORGANIZATION
IS LINE SEQUENTIAL (format 4) A predecessor-successor relationship among the records in the file is established by the order in which records are placed in the file when it is created or extended. A record in a LINE SEQUENTIAL file can consist only of printable characters.

If you omit the ORGANIZATION clause, the compiler assumes ORGANIZATION IS SEQUENTIAL.

If the file connector referenced by file-name-1 in the SELECT clause is an external file connector, the same organization must be specified for all file-control entries in the run unit that reference this file connector.

Re: Reading Manually Inputted Cobol File

PostPosted: Sat Mar 12, 2011 2:00 am
by Akatsukami
SnIpY wrote:Hello,

I know how to read file when the file is fixed in cobol. But how can I let the user input a filename and the system checks if it exists and if it does, it loads that? All files will have the same structure..

I now have it like this:
 INPUT-OUTPUT SECTION.
       FILE-CONTROL.
         SELECT gegevens ASSIGN TO "projectenIIexport.csv"
           ORGANIZATION IS LINE SEQUENTIAL
           ACCESS MODE  IS SEQUENTIAL.


But that's hardcoded.. Any ideas?

How is the user going to provide the data set name? ("File name" is something else in mainframe terminology, which may be at the heart of your dilemna.)

Re: Reading Manually Inputted Cobol File

PostPosted: Sat Mar 12, 2011 3:04 am
by dick scherrer
Hello,

For What Is Worth - I have not yet seen a mainframe cobol program where the "user" directly enters the file identification and uses that file (read/write) in the same cobol program. . .

I have seen a user enter this on a screen and then the code generates jcl to be submitted via the internal reader. . .

Re: Reading Manually Inputted Cobol File

PostPosted: Tue Mar 22, 2011 9:31 am
by Viswanathchandru
Hi folks,
Just out of interest.. Is that possible to dynamically allocate a File to a cobol program?. I have heard of using symbolic parameters. Can anyone help me on this. Apologies a ton if i'm wrong.

Thanks,
VIswa

Re: Reading Manually Inputted Cobol File

PostPosted: Tue Mar 22, 2011 10:33 am
by NicC
What do you mean by 'dynamically allocate'? Inside COBOL code or something else?

Re: Reading Manually Inputted Cobol File

PostPosted: Tue Mar 22, 2011 11:03 am
by Viswanathchandru
Hi NicC,
Thanks a lot for your reply and sorry for not being clear.
In the select statement we will allocate a DSN name to a particular DD statement in the JCL. My doubt is there any way to change the DSN file name without changing the name in the JCL for each time. Please let me know in case i need to give more inputs. Apologies a ton if m wrong.

Thanks,
Viswa.