Focal Point
[CLOSED] Batch Focexec

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3047048276

September 26, 2014, 04:47 PM
TomDx
[CLOSED] Batch Focexec
FOCUS 7.7.03
z/OS 01.13.00
JES2 z/OS1.13


My expertise with Focus is basically limited to using table commands in a Batch environment. What I need
to do is manually read a record from an external file and write if out to a new file. In addition, if a given
field in that record has a certain value I need to modify that field and write the record out a second time.
I need to do this for every record in the file I'm reading (about 10k records)

Can someone help?

I've reviewed all the documentaion available to be, and can't find what I need.

Thanks

Tom

This message has been edited. Last edited by: <Kathryn Henning>,


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 26, 2014, 04:56 PM
susannah
first you need to say what kind of file you're writing out to.
Is every record so different that it can't be fixed with just a DEFINE FILE ... ??
DEFINE FILE CAR
newvalue/I8 = IF RCOST GT 100 THEN 200 ELSE RCOST ;
END
...kind of a thing




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
September 26, 2014, 05:33 PM
TomDx
The file I am reading from is a 1200 byte sequential file. The file I want to create is the exact same format. I know how to read a file with a table command... what I can't figure out is how to read, modify, and write out individual records manually to a new file.

Thanks!


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 26, 2014, 05:43 PM
Alan B
Initially create an MFD for the sequential file, and then print all fields into a SAVE file. This should be the first step.

Next create DEFINE fields for the fields that you need to change, with the logic for the changes required, and use the PUTDDREC function to write out the changed data to the scone file.

That is the basic approach I would initially take.


Alan.
WF 7.705/8.007
September 26, 2014, 06:15 PM
TomDx
I have the Master of the input file, but how do I read only 1 record at a time in a batch procedure so that I can make modifications and then rewrite the record?


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 27, 2014, 04:03 AM
Alan B
Using DEFINE FILE fn handles data one record at a time. Therefore you can change one or more fields one record at a time.

Using the PRINT verb in TABLE FILE fn also handles data one record at a time, so the COMPUTE verb can also be used to change one or more fields one record at a time.

The example in the documentation for PUTDDREC gives a good example for what you need to achieve if you use ON TABLE SAVE within the request.


Alan.
WF 7.705/8.007
September 27, 2014, 10:09 AM
TomDx
Ok, I got that... but how would I write out the same record twice? For example, if my input file contains the following records...

A1234
A5678
B1234
B5678

What I need to do is read the input file and write each record to a new file... in additon, for any record that has an 'A' in position 1, I need to change the 'A' to an 'X' and write the record to the new file. So using the above input, my output file needs to look like this...

A1234
A5678
B1234
B5678
X1234
X5678

What I can't figure out is how to read any given record and write that record out multiple times if needed.

Thanks


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 27, 2014, 11:21 AM
Alan B
Ah, OK. Examples are always better, particularly over the weekend...

Just run a TABLE request over the incoming file twice in the same focexec. FILEDEF or ALLOC the file with APPEND or MOD.

The first request will just create the vanilla output file with a simple ON TABLE SAVE AS filename, the second run modifies the records as required, limiting the records that are needed to be changed with a WHERE clause, and output to the same SAVE file.


Alan.
WF 7.705/8.007
September 27, 2014, 01:36 PM
TomDx
I'll give that a try...

Thanks!


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 28, 2014, 10:41 AM
Danny-SRL
Tom,
If your input file is not very large, then do what Alan suggests. You will read your input file twice, but it is not too heavy.
However, if you have a large file, then I would suggest using MacGuyver. You can duplicate records and thus for each input you can get more than one output.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

September 28, 2014, 04:15 PM
TomDx
What is 'MacGuyver'?... Sorry, I've never heard of it.


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 28, 2014, 05:32 PM
Waz
Do a search on the forum, its been explained many times


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

September 28, 2014, 06:25 PM
TomDx
I found it... now I just have to make it work.

Thanks all..


FOCUS 7.7.03

z/OS 01.13.00 HBB7780
September 29, 2014, 04:23 AM
Alan B
For the number of records here, and the relative simplicity of what you require, I would expect MacGuyver to be over kill.

These are the 2 approaches I think are effective:
-* Create input file for example
TABLE FILE CAR
PRINT COUNTRY CAR MODEL BODYTYPE RETAIL_COST DEALER_COST SALES
ON TABLE HOLD AS INPUT FORMAT ALPHA
END
-RUN

-* Use PUTDDREC and SAVE to same output file

FILEDEF OUTPUT1 DISK BASEAPP/OUTPUT1.DAT (LRECL 82 RECFM V

DEFINE FILE INPUT
NEW_COUNTRY/A10 = IF COUNTRY EQ 'W GERMANY' THEN 'GERMANY' ELSE ' ';
NEW_RECORD/A82 = NEW_COUNTRY | CAR | MODEL | BODYTYPE | FPRINT(RETAIL_COST, 'D7c', 'A7') | FPRINT(DEALER_COST, 'D7c', 'A7') |FPRINT(SALES, 'I6', 'A6');
END

TABLE FILE INPUT
PRINT COUNTRY CAR MODEL BODYTYPE RETAIL_COST DEALER_COST SALES 
COMPUTE NEW_OUTPUT/I4 =  IF COUNTRY EQ 'W GERMANY' THEN PUTDDREC('OUTPUT1',82, NEW_RECORD,82,'I4') ; NOPRINT 
ON TABLE SET HOLDLIST PRINTONLY 
ON TABLE SAVE AS OUTPUT1
END

-* Use 2 SAVEs to same output file

FILEDEF OUTPUT2 DISK BASEAPP/OUTPUT2.DAT (LRECL 82 RECFM V

DEFINE FILE INPUT
NEW_COUNTRY/A10 = IF COUNTRY EQ 'W GERMANY' THEN 'GERMANY' ELSE ' ';
END

TABLE FILE INPUT
PRINT COUNTRY CAR MODEL BODYTYPE RETAIL_COST DEALER_COST SALES 
ON TABLE SET HOLDLIST PRINTONLY 
ON TABLE SAVE AS OUTPUT2
END
FILEDEF OUTPUT2 DISK BASEAPP/OUTPUT2.DAT (LRECL 82 RECFM V APPEND
TABLE FILE INPUT
PRINT NEW_COUNTRY CAR MODEL BODYTYPE RETAIL_COST DEALER_COST SALES 
WHERE NEW_COUNTRY NE ' '
ON TABLE SET HOLDLIST PRINTONLY 
ON TABLE SAVE AS OUTPUT2
END



Alan.
WF 7.705/8.007