MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using of Multiple GET and PUT commands
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
rg_nath
Beginner


Joined: 03 Jul 2015
Posts: 23
Topics: 7

PostPosted: Mon Aug 31, 2015 7:22 am    Post subject: Using of Multiple GET and PUT commands Reply with quote

Hi,

Below given a sample pseudo code which i have.

Code:

**************************
 JOB INPUT NULL
    GET FILE1            (This is one record file & i didn't use STOP here as Easytrieve open an close files automatically)

   (then coded for extracting values to working storage section variable)

***********************************************************************

  GET FILE2   (This file is having 10 records)

*                         
  DO WHILE NOT EOF FILE2
*                       
   (Few IF conditions are written here to extracting FILE2 values)

      PUT TEMP1
*                 
      GET FILE2
*                 
  END-DO       

  MOVE X'FF' TO TEMP-REC FILL X'FF'

  PUT TEMP1 (as i want High-values at last record of TEMP1)

  SORT TEMP1 TO TEMP1 USING (COL1     +               
                             COL2     +               
                             COL3     +               
                             COL4     +               
                             COL5) BEFORE SEL-PARA
*                                                           
 SEL-PARA. PROC                                             
  SELECT                                                   
 END-PROC                                                   
*                               
  JOB INPUT (TEMP1 KEY (COL1))           
   IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1     
       WS_COL1 = COL1               
   END-IF                                       
*                                               
  JOB INPUT (TEMP1 KEY (COL1 COL2))
*                                               
   IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1     
       PUT HOLD1
   END-IF
*               
**********************************************************************
  JOB INPUT NULL
  GET FILE3

  (Read the required first record column value into WS variable)

*                     
  DO WHILE NOT EOF FILE3
*                     
     GET HOLD1
     DO WHILE NOT EOF HOLD1                       
       (IF condition satisfies ...
            do some move statemens and
           STOP)
         GET HOLD2
     END-DO                                       
     GET FILE3
  END-DO   
  STOP     
************************************************************************


After submitting the JOB with above Easytrieve code i have got the below error.

Code:

*******A010 INVALID FILE REFERENCE - FILE1
*******A014 PREMATURE TERMINATION DUE TO PREVIOUS ERROR(S)   


Can any one please help me to get resolve this error. please assist me that where i did mistake in above sample code. I hope the above code is handling multiple files with GET and PUT commands AND some where else i was done mistake in logic flow. i have tried as tril and error basis but unable to resolve.

-Nath
Back to top
View user's profile Send private message
rg_nath
Beginner


Joined: 03 Jul 2015
Posts: 23
Topics: 7

PostPosted: Mon Aug 31, 2015 7:50 am    Post subject: Reply with quote

Hi,

Code:

         GET HOLD2


Please read the above statement as below. Its my typo mistake in previous post.

Code:

         GET HOLD1


There is no HOLD2 file.

-Nath
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Mon Aug 31, 2015 9:06 am    Post subject: Reply with quote

Well, in the code you have shown, there is no FILE1. You've either shown the wrong code, or the wrong output.

Why don't you use automatic file processing more? You could have a start-procedure for your single-record file, for instance. Doing things manually when there is no need is just a waste of your time and everyone else's. Also, you have a sort-procedure which just has SELECT. Why?

If you still have a problem, it would be really great to know what you are trying to do.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 31, 2015 10:17 am    Post subject: Reply with quote

William Collins wrote:
Also, you have a sort-procedure which just has SELECT. Why?



I believe it is a DB2 select statement which OP did not show.

William Collins wrote:

If you still have a problem, it would be really great to know what you are trying to do.


An educated guess about the process is that OP has input parm file which has a processing date and he needs to extract all records from file 2 for that date and for all these records he needs to extract the information from a DB2 table and then finally write a report. But OP simply complicated a simple request into a giant problem.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 31, 2015 10:20 am    Post subject: Re: Using of Multiple GET and PUT commands Reply with quote

rg_nath wrote:

Can any one please help me to get resolve this error. please assist me that where i did mistake in above sample code. I hope the above code is handling multiple files with GET and PUT commands AND some where else i was done mistake in logic flow. i have tried as tril and error basis but unable to resolve.

-Nath


Do you realize that with every JOB statement the prior values are gone? And If I remember correctly easytrieve does indeed show you the exact line number that it thinks is invalid. So did you match it up and find out which statement is causing the error?
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Mon Aug 31, 2015 10:51 am    Post subject: Reply with quote

Well, I found FILE1 Smile

As Kolusu pointed out, once a JOB finishes, you can't reference any data on the files it used, because they are all closed.

I've rearranged your code a little. You should give names to all the activities (JOB and SORT).

The SELECT in the SORT is identifying the records to be sorted. If you want all the records, there is no need for a SELECT. You only need a SELECT if you have a sort-procedure, and there is no need to have a sort-procedure just to have a SELECT.

There is no need to process TEMP1 twice. Your first JOB which reads TEMP1 (see how useful names are instead) is simply storing the final key. If that is really what you want, it is easy to just save the key for each record in the next JOB.

The final JOB I can't do much with. I doubt it does what you expect, but since we don't know what you expect, I can't be certain.

If the first record on FILE3 matches a condition on HOLD1, then you STOP. If it doesn't match, you get to the end of HOLD1 and never enter the inner DO loop again, so there does not seem to be any point in continuing to read FILE3, as you do nothing with the records.

Code:
 JOB INPUT FILE2 +
    START PROCESS-ONE-RECORD-FILE +
    FINISH OUTPUT-TRAILER
PROCESS-ONE-RECORD-FILE. PROC
    GET FILE1            (This is one record file
END-PROC
OUTPUT-TRAILER. PROC
  MOVE X'FF' TO TEMP-REC FILL X'FF'

  PUT TEMP1 (as i want High-values at last record of TEMP1)
END-PROC


   (Few IF conditions are written here to extracting FILE2 values)

      PUT TEMP1

  SORT TEMP1 TO TEMP1
      USING (COL1     +               
                             COL2     +               
                             COL3     +               
                             COL4     +               
                             COL5)                             
*                               
  JOB INPUT (TEMP1 KEY (COL1))           
   IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1     
       WS_COL1 = COL1               
   END-IF                                       
*                                               
  JOB INPUT (TEMP1 KEY (COL1 COL2))
*                                               
   IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1     
       PUT HOLD1
   END-IF
*               
**********************************************************************
  JOB INPUT NULL
  GET FILE3

  (Read the required first record column value into WS variable)

*                     
  DO WHILE NOT EOF FILE3
*                     
     GET HOLD1
     DO WHILE NOT EOF HOLD1                       
       (IF condition satisfies ...
            do some move statemens and
           STOP)
         GET HOLD1
     END-DO                                       
     GET FILE3
  END-DO   
  STOP 
Back to top
View user's profile Send private message
rg_nath
Beginner


Joined: 03 Jul 2015
Posts: 23
Topics: 7

PostPosted: Mon Aug 31, 2015 11:36 am    Post subject: Reply with quote

Hi,
Thanks for all your inputs on my post. Below I have given my actual intention to code this for your better understanding. I am new to Easytrieve code and flow and I would like to know about this tool Smile

1. From FILE1, I would like to extract the record values into working storage variables.
2. Next by using FILE2, I want to take the values from FILE2 which are matching with some IF conditions for each records. At last, I had inserted High-Value in TEMP1 file
3. Then I have SORTed the TEMP1 file using keys and ‘BEFORE SEL-PARA’. Write the output in same file TEMP1.
4. Next I would like to take only MAX values from SORT output file TEMP1. For this I have used LAST-DUP condition. To use this we should code under JOB INPUT statement. And the output file is HOLD1.
5. After completion of above all process, I would like to take each record from FILE3 and write a report which are having match the values with HOLD1 file. (HOLD1 file is having report heading information)

Here I didn’t mention REPORT statement. First I would like to see my expected values from the files and then will write a code for REPORT.

-Nath
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 31, 2015 11:44 am    Post subject: Reply with quote

rg_nath wrote:
4. Next I would like to take only MAX values from SORT output file TEMP1. For this I have used LAST-DUP condition. To use this we should code under JOB INPUT statement. And the output file is HOLD1.


Is any of the column you sorting a numeric field or time stamp field? If you wanted to get the max value why not sort the max field Descending and always get the first record instead of getting the last duplicate?

And you have 2 Checks for LASTDUP where the first check is just on KEY COL1 and the next one has a key of COL1+COL2. So why do you need to 2 passes of the data?
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rg_nath
Beginner


Joined: 03 Jul 2015
Posts: 23
Topics: 7

PostPosted: Mon Aug 31, 2015 12:29 pm    Post subject: Reply with quote

Hi Kolusu,

There no column is sorting with numeric or date-time values.

Quote:
If you wanted to get the max value why not sort the max field Descending and always get the first record instead of getting the last duplicate?


Yes, I have used with ‘D’ option in SORT statement and I have got the MAX value record at first. As per my knowledge, after sort we need to use either LAST-DUP or FIRST-DUP for getting MAX value record into output file. Please assist/Suggest me if there is any way that we have to get only MAX value records to output without using FIRST-DUP or LAST-DUP.

Quote:
And you have 2 Checks for LASTDUP where the first check is just on KEY COL1 and the next one has a key of COL1+COL2. So why do you need to 2 passes of the data?


Actually, I have to take MAX value records by COL2 and then by COL1. After taking values I have to write output file as one record if COL1 value will change. Like below.
Code:

Col1        Col2           Col3
-------     ---------   --------
A             01           value1
A             01           value2
A             02           value3
A             03           value4
A             03           value5
B             01           Value6
B             01           Value7
B             02           Value8
B             02           Value9

I need the output below.
Code:

A   value2   value3   value5
B   Value7   Value9

So, for checking with first COL1 value I have used first LAST-DUP check. And based on this in second check, if COL1 is not matched then write into output file.

This is my own logic so you can see two LAST-DUP checks in my code.

-Nath
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Mon Aug 31, 2015 12:37 pm    Post subject: Reply with quote

Some advice.

If Easytrieve Plus can do it without manual coding, take advantage of that nearly all the time.

Don't read a file until you need the data. Unless you need data across two different "activities" (JOBs or SORTs) just GET a one-record file in a START procedure where you need it, and reference your fields from the file. If you need to access the same data in two or more activities, you can consider storing the data in the storage part of the Library (which is what you call the bit where files and field are, usually in the latter case, defined.

If something in Easytrieve Plus reminds you of COBOL - beware. Don't use MOVE unless you need to (your example is of a good use, but for fields you can run into difficulties as MOVE, unlike COBOL, does no data-conversion). Prefer assignments (the equals sign).

Getting a piece working at a time is good, but I don't think you've done that with what you have so far. Your number five does not work, and unless your HOLD1 data is robustly coded it doesn't even stand a chance of working.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Mon Aug 31, 2015 1:30 pm    Post subject: Reply with quote

rg_nath wrote:
Yes, I have used with ‘D’ option in SORT statement and I have got the MAX value record at first. As per my knowledge, after sort we need to use either LAST-DUP or FIRST-DUP for getting MAX value record into output file. Please assist/Suggest me if there is any way that we have to get only MAX value records to output without using FIRST-DUP or LAST-DUP.


rg_nath,

Stop and think for a second logically as to how you would program to notice a key change. You simply compare the key to a working storage variable and anytime it is different then you would write out the record. It is a simple programming technique and it should be the first technique on your list.

If you sorted the COL1+COL2 ascending and COL3 descending you will have the max record for the combo key as the first record.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Mon Aug 31, 2015 3:24 pm    Post subject: Reply with quote

This JOB from your original does nothing except leave the highest COL1 value in WS_COL1.

Code:
  JOB INPUT (TEMP1 KEY (COL1))           
   IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1     
       WS_COL1 = COL1               
   END-IF               


This will do the same:

Code:
  JOB INPUT TEMP1
       WS_COL1 = COL1               


Or, better, remove that JOB and put a START procedure on the next JOB, as we know the value is HIGH-VALUES, so just set WS_COL1 to that in the new START procedure.

That's probably not what you want.

The next JOB is not producing this output:

Code:
A   value2   value3   value5
B   Value7   Value9


It would be like this:

Code:

A   value2
A   value3
A   value5
B   Value7
B   Value9


If you want columnar output per COL1 key, you're going to need an OCCURS, and to output the record on change-of-key, remembering that end-of-file is a change-of-key, so you'd need a FINISH proc for the JOB.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 01, 2015 3:15 pm    Post subject: Reply with quote

rg_nath,

I just looked this once again and was wondering as to why you need to populate the last record with high-values?
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rg_nath
Beginner


Joined: 03 Jul 2015
Posts: 23
Topics: 7

PostPosted: Wed Sep 02, 2015 2:04 am    Post subject: Reply with quote

Hi Kolusu,

Quote:

why you need to populate the last record with high-values?


while getting the result of 'MAX value records' by using LAST-DUP logic, some how the last MAX value record was not populated in my output file as it was skipped. So, to get all my required MAX value records i have introduced High-Value record at last of input file (i.e. TEMP1 file). I know its not a good coding but for time being i have coded like that Smile

-Nath
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Wed Sep 02, 2015 3:20 am    Post subject: Reply with quote

You're saying this:

Code:
IF LAST-DUP TEMP1 OR NOT DUPLICATE TEMP1


doesn't work for the last record of a file? You mean for years upon years of Easytrieve Plus usage, no-one noticed? I don't think so.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group