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

Processing as a block!


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
fredrick andrews

New User


Joined: 10 Jun 2010
Posts: 52
Location: chennai

PostPosted: Wed Jan 26, 2011 3:55 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jan 26, 2011 4:08 pm
Reply with quote

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
View user's profile Send private message
fredrick andrews

New User


Joined: 10 Jun 2010
Posts: 52
Location: chennai

PostPosted: Wed Jan 26, 2011 4:31 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jan 26, 2011 5:54 pm
Reply with quote

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:
  1. label the first occurance
  2. search for the last occurance
  3. label the line previous to the last found
  4. delete label label
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jan 26, 2011 6:07 pm
Reply with quote

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
View user's profile Send private message
fredrick andrews

New User


Joined: 10 Jun 2010
Posts: 52
Location: chennai

PostPosted: Wed Jan 26, 2011 7:58 pm
Reply with quote

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:
  1. label the first occurance
  2. search for the last occurance
  3. label the line previous to the last found
  4. delete label label



I will go with the REXX edit macro...
Anyways, I'll have to learn that as well....
Appreciate your help. icon_smile.gif
Back to top
View user's profile Send private message
fredrick andrews

New User


Joined: 10 Jun 2010
Posts: 52
Location: chennai

PostPosted: Wed Jan 26, 2011 8:02 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jan 26, 2011 8:20 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jan 26, 2011 10:07 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jan 27, 2011 2:40 pm
Reply with quote

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
View user's profile Send private message
fredrick andrews

New User


Joined: 10 Jun 2010
Posts: 52
Location: chennai

PostPosted: Thu Jan 27, 2011 10:04 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts I need a 4 lines block where substrin... DFSORT/ICETOOL 12
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
No new posts Try to understand IMS control block IMS DB/DC 0
No new posts icetool empty file and not empty file... DFSORT/ICETOOL 5
No new posts CICS file processing using applicatio... CICS 3
Search our Forums:

Back to Top