View previous topic :: View next topic
|
Author |
Message |
fredrick andrews
New User
Joined: 10 Jun 2010 Posts: 52 Location: chennai
|
|
|
|
Hi Everyone,
The requirement is to read each record from File 1 .
Find the matching record in file 2.
There will be more than one occurrence of it in File 2.
I will have to block delete it from the first matching record found and the record prior to the last matching record.
Input File 1:
Code: |
1111111111111
3333333333333 |
Input File 2:
Code: |
1111111111111
0000000000000
1111111111111
2222222222222
1111111111111
3333333333333
2222222222222
4444444444444
5555555555555
3333333333333
6666666666666
7777777777777
8888888888888
8888888888888
9999999999999 |
Sample Output :
Code: |
1111111111111
3333333333333
6666666666666
7777777777777
8888888888888
8888888888888
9999999999999 |
Can this be accomplished in Cobol ? If yes, how do I access the record previous to the matching record?
Is there any other way this can be done?
Any help is appreciated.
Thanks. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
I will have to block delete it |
if you want professional advice,
suggest you phrase your questions professionally.
you will need to explain what you mean by the above. |
|
Back to top |
|
|
fredrick andrews
New User
Joined: 10 Jun 2010 Posts: 52 Location: chennai
|
|
|
|
dbzTHEdinosauer wrote: |
Quote: |
I will have to block delete it |
if you want professional advice,
suggest you phrase your questions professionally.
you will need to explain what you mean by the above. |
Hi dbzTHEdinosauer,
Thanks for the reply.
By "block delete" I mean the usual way we delete more than 1 row.
DD
DD on the left and ENTER .
I seriously don't know what the exact term is , but I hope I have conveyed it now.
Input File 1:
Code: |
1111111111111
3333333333333 |
Input File 2:
Code: |
1111111111111 <- Matching record 1 DD1
0000000000000
1111111111111
2222222222222 DD1
1111111111111 <- Last Matching record 1
3333333333333 <- Matching record 2 DD2
2222222222222
4444444444444
5555555555555 DD2
3333333333333 <- Last Matching record 2
6666666666666
7777777777777
8888888888888
8888888888888
9999999999999 |
Sample Output :
Code: |
1111111111111
3333333333333
6666666666666
7777777777777
8888888888888
8888888888888
9999999999999 |
I've added the details in the Input file as well. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
from what I can tell, this could be done with an edit macro,
easily written in REXX.
in order to do it with a cobol program with the files as input
and not using ispf/lmm./tso services (i.e. an edit macro written in cobol)
you would have to save records in a cobol internal table.
i personally would use the edit macro approach.
you would edit file 2 and execio file 1. for each 'record' for file 1:
- label the first occurance
- search for the last occurance
- label the line previous to the last found
- delete label label
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
By "block delete" I mean the usual way we delete more than 1 row. |
Terminlogy is critical in IT, where similar terms may mean very different things. Files do not have "rows"; files have "records". Data bases have "rows". |
|
Back to top |
|
|
fredrick andrews
New User
Joined: 10 Jun 2010 Posts: 52 Location: chennai
|
|
|
|
dbzTHEdinosauer wrote: |
from what I can tell, this could be done with an edit macro,
easily written in REXX.
in order to do it with a cobol program with the files as input
and not using ispf/lmm./tso services (i.e. an edit macro written in cobol)
you would have to save records in a cobol internal table.
i personally would use the edit macro approach.
you would edit file 2 and execio file 1. for each 'record' for file 1:
- label the first occurance
- search for the last occurance
- label the line previous to the last found
- delete label label
|
I will go with the REXX edit macro...
Anyways, I'll have to learn that as well....
Appreciate your help. |
|
Back to top |
|
|
fredrick andrews
New User
Joined: 10 Jun 2010 Posts: 52 Location: chennai
|
|
|
|
Robert Sample wrote: |
Quote: |
By "block delete" I mean the usual way we delete more than 1 row. |
Terminlogy is critical in IT, where similar terms may mean very different things. Files do not have "rows"; files have "records". Data bases have "rows". |
Robert,
Yes, I concur. I stand corrected.
BTW,
Is there a way we can multi-quote posts in this forum? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Is there a way we can multi-quote posts in this forum? |
Yes, just do the same "thing" for the "next" quote":
Quote: |
Yes, I concur. I stand corrected. |
Or you can include multiple quotes within a quote. . .
Quote: |
Quote: |
Yes, I concur. I stand corrected. |
Quote: |
Is there a way we can multi-quote posts in this forum? |
|
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
having nothing better todo,
a very quick, rough edit macro:
Code: |
/* REXX */
/* */
/* EDIT THE DATASET FROM WHICH YOU WISH TO REMOVE DUPS */
/* AS PER YOUR EXAMPLE. */
/* AT COMMAND LINE ENTER: DELDUPS FILENAME */
/* */
/* FILENAME NEEDS TO BE A COMPLETE HLQ.NLQ.NLQ.NAME */
/* */
/* THE REXX WILL APPEND "'" SOTHAT THE FILENAME WILL */
/* BE PROPERLY QUALIFIED */
/* */
ADDRESS ISREDIT
"MACRO (FILENAME) "
/* */
/* TRACE ?R */
/* */
UPPER FILENAME
FILENAME = "'" !! FILENAME !! "'"
SAY FILENAME
/* */
IF SYSDSN(FILENAME) = 'OK' THEN
SAY FILENAME 'EXISTS AND WILL BE PROCESSED'
ELSE
SAY FILENAME 'DOES NOT EXIST'
/* */
ADDRESS TSO
"ALLOC DS("FILENAME") F(DATAIN) SHR"
RTNC = RC
IF RTNC <> 0 THEN
DO
"FREE F(DATAIN)"
SAY "PROBLEM WITH ALLOCATION"
EXIT
END
/* */
/* */
"EXECIO * DISKR DATAIN (STEM SAVRCD. FINIS"
RTNC = RC
"FREE F(DATAIN)"
IF RTNC <> 0 THEN
DO
SAY RTNC RETURNCODE OF EXECIOCMD
EXIT
END
/* */
/* ALL OF THE FILE IS IN STEM SAVRCD */
/* NUM OF RECORDS IS SAVRCD.0 */
/* */
/* TRACE ?R */
DO I=1 TO SAVRCD.0 BY 1
SRCH_KEY = SUBSTR(SAVRCD.I,1,13)
CALL DEL_UND_DESTROY
END
/* */
EXIT
DEL_UND_DESTROY: PROCEDURE EXPOSE SRCH_KEY
SAY SRCH_KEY
ADDRESS ISREDIT
/* TRACE ?R */
"FIND " SRCH_KEY "FIRST"
IF RC <> 0 THEN
RETURN
"LABEL .ZCSR = .A " 0
"FIND " SRCH_KEY "LAST"
IF RC <> 0 THEN
RETURN
"(LINENO) = LINENUM .ZCSR"
LINENO = LINENO - 1
"CURSOR = "LINENO 1
"LABEL .ZCSR = .B " 0
"DELETE ALL .A .B"
RETURN
|
no, I am not going to answer any questions.
other than on my machine : !! (two exclamation marks)
are what I need for || (concatenation operator)
|| is not recognized by my mainframe, but !! is. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
a small addition to improve the accuracy of the macro:
Code: |
DEL_UND_DESTROY: PROCEDURE EXPOSE SRCH_KEY
/* SAY SRCH_KEY */
ADDRESS ISREDIT
/* TRACE ?R */
"FIND " SRCH_KEY "FIRST"
IF RC <> 0 THEN
RETURN
"LABEL .ZCSR = .A " 0
"FIND " SRCH_KEY "LAST"
IF RC <> 0 THEN
RETURN
"(LINENO) = LINENUM .ZCSR"
LINENO = LINENO - 1
/* */
/* new starts here */
/* */
"(LINEDOTA) = LINENUM .A"
IF LINENO < LINEDOTA THEN RETURN
IF LINENO = LINEDOTA THEN
DO
"DELETE ALL .A .A"
RETURN
END
/* */
/* new ends here */
/* */
"CURSOR = "LINENO 1
"LABEL .ZCSR = .B " 0
"DELETE ALL .A .B"
RETURN
|
|
|
Back to top |
|
|
fredrick andrews
New User
Joined: 10 Jun 2010 Posts: 52 Location: chennai
|
|
|
|
dbzTHEdinosauer wrote: |
a small addition to improve the accuracy of the macro:
Code: |
DEL_UND_DESTROY: PROCEDURE EXPOSE SRCH_KEY
/* SAY SRCH_KEY */
ADDRESS ISREDIT
/* TRACE ?R */
"FIND " SRCH_KEY "FIRST"
IF RC <> 0 THEN
RETURN
"LABEL .ZCSR = .A " 0
"FIND " SRCH_KEY "LAST"
IF RC <> 0 THEN
RETURN
"(LINENO) = LINENUM .ZCSR"
LINENO = LINENO - 1
/* */
/* new starts here */
/* */
"(LINEDOTA) = LINENUM .A"
IF LINENO < LINEDOTA THEN RETURN
IF LINENO = LINEDOTA THEN
DO
"DELETE ALL .A .A"
RETURN
END
/* */
/* new ends here */
/* */
"CURSOR = "LINENO 1
"LABEL .ZCSR = .B " 0
"DELETE ALL .A .B"
RETURN
|
|
dbzTHEdinosauer ,
Thanks for that ...
Appreciate your help! |
|
Back to top |
|
|
|