IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Read and append the same file in COBOL.


IBM Mainframe Forums -> FAQ & Basics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Sat Oct 09, 2021 3:47 pm
Reply with quote

Hello Everyone,

Hope all doing good.

Can someone please help me to read and append the record in the same file in cobol ?

Thanks
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sat Oct 09, 2021 6:13 pm
Reply with quote

You want to duplicate the record ? Why ?
Back to top
View user's profile Send private message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Sat Oct 09, 2021 6:18 pm
Reply with quote

Rohit Umarjikar wrote:
You want to duplicate the record ? Why ?


Thanks much for you reply.

I am trying to search the record in the file
one by one until EOF, if record not found append that record in the same file.

Thanks
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sat Oct 09, 2021 6:28 pm
Reply with quote

There are many ways .. It’s very simple question so I will move to students forum. Can you not use DFSORT or SYNCSORT and do this task ?
Start from here and also use SEARCH button to find related posts.
ibmmainframes.com/about21963.html
Back to top
View user's profile Send private message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Sat Oct 09, 2021 7:26 pm
Reply with quote

Rohit Umarjikar wrote:
There are many ways .. It’s very simple question so I will move to students forum. Can you not use DFSORT or SYNCSORT and do this task ?
Start from here and also use SEARCH button to find related posts.
ibmmainframes.com/about21963.html

Thanks for reply.

I am trying to read a file and search the record in the file, if record not found in that file then append that search record in the Same file.

Note- I don’t want to use two steps for this. I am trying to do using cobol in one step.


Thanks.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sun Oct 10, 2021 3:11 am
Reply with quote

I am not quite sure what you are trying to do here. If you have two data sets to work on and one being the master and other is finder then if record from master don’t present in finder then you want to write to master ? If found then what ? Tell us the complete Pictor the requirement.
Back to top
View user's profile Send private message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Sun Oct 10, 2021 8:55 am
Reply with quote

Sir,

I have only one dataset. The record need to be search are passing from ‘JCL PARM’ in COBOL.

1. Search string passing through PARM
2. Open input file1
2. Read a file1, search the strings in the file until eof.
If ws-record of file1 = search string
Move ‘ Y’ to EOF.
Close file1
Else
Perform Append-para through exit- append
End-if.

Append-para.
Open extend file1
Move ‘search string’ to ws-file1.
Write file1-record.
Close file1.
Exit-append.
Exit.

Something like above, I am trying to do. Is it possible? What would be the Jcl disp parameter? Can I use two DD name for the same file name?

File1 DD DSN=abc, disp=shr
File2 DD DSN=abc, disp=mod

Thanks
Back to top
View user's profile Send private message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Sun Oct 10, 2021 9:40 am
Reply with quote

Sir,

I have only one dataset. The record need to be search are passing from ‘JCL PARM’ in COBOL.

1. Search string passing through PARM
2. Open input file1
2. Read a file1, search the strings in the file until eof.
If ws-record of file1 = search string
Move ‘ Y’ to EOF.
Close file1
Else
Perform Append-para through exit- append
End-if.

Append-para.
Open extend file1
Move ‘search string’ to ws-file1.
Write file1-record.
Close file1.
Exit-append.
Exit.

Something like above, I am trying to do. Is it possible? What would be the Jcl disp parameter? Can I use two DD name for the same file name?

File1 DD DSN=abc, disp=shr
File2 DD DSN=abc, disp=mod

Thanks
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sun Oct 10, 2021 7:11 pm
Reply with quote

DISP=MOD
www.ibm.com/docs/en/zos/2.1.0?topic=definition-status-subparameter
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Mon Oct 11, 2021 5:08 am
Reply with quote

sandeep.kumar wrote:
Sir,

I have only one dataset. The record need to be search are passing from ‘JCL PARM’ in COBOL.

1. Search string passing through PARM
2. Open input file1
2. Read a file1, search the strings in the file until eof.
If ws-record of file1 = search string
Move ‘ Y’ to EOF.
Close file1
Else
Perform Append-para through exit- append
End-if.

Append-para.
Open extend file1
Move ‘search string’ to ws-file1.
Write file1-record.
Close file1.
Exit-append.
Exit.

Something like above, I am trying to do. Is it possible? What would be the Jcl disp parameter? Can I use two DD name for the same file name?

File1 DD DSN=abc, disp=shr
File2 DD DSN=abc, disp=mod

Thanks

In order to use datasets in this manner, IBM has introduced the VSAM datasets, about 40+ years ago.

For a physically sequential dataset it is not normal way of use. It is possible, but is as inconvenient as walking on your head rather than on your feet.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Mon Oct 11, 2021 5:57 pm
Reply with quote

sandeep.kumar wrote:

Something like above, I am trying to do. Is it possible? What would be the Jcl disp parameter? Can I use two DD name for the same file name?
Code:

//ddname1 DD DSN=abc,disp=shr
//ddname2 DD DSN=abc,disp=mod

Thanks

Even in this case you don’t need two different ddnames.
Use only one single ddname with DISP=MOD
First time OPEN it for input in your COBOL code. For input, MOD is equivalent to OLD.
When your record has been found, or you have reached EOF, then do not forget to CLOSE it.
Next re-OPEN with the same ddname, but for output (as separate one within COBOL code). In this case DISP=MOD takes its effect, and the dataset after OPEN would be positioned after its last record. Whatever you WRITE at this moment should become the very last (new) record of your dateset.

As I mentioned in my previous message, this is possible but is not considered as normal way of usage for a sequential (PS) dataset.

P.S. You are kindly requested to format your messages in an accurate manner. Use code tags when needed, use CAPS characters when needed - especially when it is strictly required by the programming language syntax.

Otherwise the readers would not consider you as a serious software engineer… 36_8_9.gif
Back to top
View user's profile Send private message
sandeep.kumar

New User


Joined: 16 Aug 2021
Posts: 11
Location: India

PostPosted: Mon Oct 11, 2021 8:44 pm
Reply with quote

sergeyken wrote:
sandeep.kumar wrote:

Something like above, I am trying to do. Is it possible? What would be the Jcl disp parameter? Can I use two DD name for the same file name?
Code:

//ddname1 DD DSN=abc,disp=shr
//ddname2 DD DSN=abc,disp=mod

Thanks

Even in this case you don’t need two different ddnames.
Use only one single ddname with DISP=MOD
First time OPEN it for input in your COBOL code. For input, MOD is equivalent to OLD.
When your record has been found, or you have reached EOF, then do not forget to CLOSE it.
Next re-OPEN with the same ddname, but for output (as separate one within COBOL code). In this case DISP=MOD takes its effect, and the dataset after OPEN would be positioned after its last record. Whatever you WRITE at this moment should become the very last (new) record of your dateset.

As I mentioned in my previous message, this is possible but is not considered as normal way of usage for a sequential (PS) dataset.

P.S. You are kindly requested to format your messages in an accurate manner. Use code tags when needed, use CAPS characters when needed - especially when it is strictly required by the programming language syntax.

Otherwise the readers would not consider you as a serious software engineer… 36_8_9.gif


Thanks much for your help and suggestion. It’s worked. And sorry for format, i use phone. Can’t cut and paste exact format code. But next time will try to type in correct format with proper indentation.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> FAQ & Basics

 


Similar Topics
Topic Forum Replies
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top