Reading Manually Inputted Cobol File



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Reading Manually Inputted Cobol File

Postby SnIpY » Fri Mar 11, 2011 1:27 am

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?
SnIpY
 
Posts: 1
Joined: Fri Mar 11, 2011 1:21 am
Has thanked: 0 time
Been thanked: 0 time

Re: Reading Manually Inputted Cobol File

Postby Robert Sample » Fri Mar 11, 2011 1:49 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Reading Manually Inputted Cobol File

Postby enrico-sorichetti » Fri Mar 11, 2011 1:53 am

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Reading Manually Inputted Cobol File

Postby mickeywhite » Sat Mar 12, 2011 1:26 am

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
mickeywhite
 
Posts: 11
Joined: Tue Nov 02, 2010 8:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading Manually Inputted Cobol File

Postby Robert Sample » Sat Mar 12, 2011 1:37 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Reading Manually Inputted Cobol File

Postby Akatsukami » Sat Mar 12, 2011 2:00 am

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.)
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading Manually Inputted Cobol File

Postby dick scherrer » Sat Mar 12, 2011 3:04 am

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. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Reading Manually Inputted Cobol File

Postby Viswanathchandru » Tue Mar 22, 2011 9:31 am

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
Viswanathchandru
 
Posts: 271
Joined: Mon Oct 25, 2010 2:24 pm
Has thanked: 25 times
Been thanked: 0 time

Re: Reading Manually Inputted Cobol File

Postby NicC » Tue Mar 22, 2011 10:33 am

What do you mean by 'dynamically allocate'? Inside COBOL code or something else?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Reading Manually Inputted Cobol File

Postby Viswanathchandru » Tue Mar 22, 2011 11:03 am

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.
Viswanathchandru
 
Posts: 271
Joined: Mon Oct 25, 2010 2:24 pm
Has thanked: 25 times
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post