Syntax
EXTRACT attribute [ MAPPER header ] AS extract_file [ RETAINAS { file_name | literal } ]
Parameters
Extract can be abbreviated as EX.
attribute
Attribute holds the current values that will be written to an extract file. The class that defines this attribute and its stereotype property, specifies the file format. Refer to Extract File Format for more information.
MAPPER header
This option is used to provide header records for an extract file in Business Information Server format. The header must be defined as an instance of a Frame class that has a Print presentation.
The frame specified as qualifier is the frame used to provide header records for the extract file. The header included in an extracted frame is that specified by the first Extract logic statement for that file. If the Business Information Server header contains a variable, an error occurs during the execution of the Extract logic statement. Business Information Server header information can be added to the extract file after it is created. MAPPER can be abbreviated as MP.
Writes records to the extract file in Business Information Server format.
Data columns are tab-delimited in Business Information Server extract files.
This command option only applies if the preceding qualifier specifies a frame.
AS extract_file
This option is used to define where and how the data is extracted. The extract_file must be an instance of a File class.
Extract file can be in one of the following categories:
Existing
Permanent
Temporary
Refer to Extract File Categories for more information about these categories.
RETAINAS file_name
Saves the extract file (for example, for use in other reports) as the specified external file name.
File_name can be a variable or literal containing a string expression.
For applications that run on Windows, file_name might be any valid Windows path name.
If a file_name is a string literal, each backslash character in the literal must be escaped by another backslash. For example
“C:\\Folder\\File.dat”.
Refer to String Literals for more information.
RETAINAS can be abbreviated as RAS or RTN.
For an MCP-based system, the RetainAs filename must be a string literal. It can contain any number of levels, but cannot exceed 18 characters (including slashes). System usercodes cannot be included. After removing the SetTitle command inserted by Migration for a migrated RetainAs qualifier, the RetainAs command in MCP Runtime behaves the same way for both AB Suite and EAE.
Note: Although MCP users can remove the SetTitle command inserted by migration, it must be left in place for Windows applications to retain EAE behavior for RetainAs.
For an MCP-based system, assignment of the RetainAs file name is not dynamic, but is always assigned to the last RETAINAS command option in the current logic, whether that command is executed or not.
For a Windows-based system, assignment of the RetainAs file name is dynamic.
If you are deploying applications to MCP and Windows from the same model, do not use the RetainAs qualifier. Instead, use the SetTitle verb or the file.Open() method before using Extract.
Do not specify the same file name with the RetainAs command option or SetTitle logic command for more than one extract file, if multiple extract files are used in a report, even if only one of them can be used by any command execution within the report. The RetainAs command option opens and closes an unaccessed extract file in order to clear it, and the written file with the same name is also cleared.
If multiple Extract logic statements reference the same extract file, the RetainAs command option should only be specified once, at its first occurrence in relation to that extract file.
For a Windows-based system, data is appended to the extract file in subsequent extracts and errors will occur if the RetainAs command option is specified again.
For an MCP-based system, only the file_name from the last RETAINAS command option in the logic unit will be used, all the others will be ignored.
Description
The Extract logic command writes the current values, held in the of attribute, into an extract file.
When you extract a Frame, the Main() method of that frame will be automatically executed prior to the extract. The purpose of this is to execute logic that will populate the attributes of the frame prior to it being extracted.
An extract file can be read by:
The same report that created it
Another report within the same application
Another application (on the same host or on a different host)
A stand-alone program (which might read the data into an external application)
Business Information Server
When using extract files:
Use the SetTitle logic command to close the current extract file and open another one. Alternatively, use the file.close() method to close the current extract file and use the file.open() method to open another one.
When switching from reading an extract file to appending data to it, the first Extract logic statement should be immediately followed by a CriticalPoint logic statement. Otherwise, duplicate records can be written if the report is aborted and then automatically recovered at this point.
Multiple Extracts
If an extract file has already been accessed by another logic statement, such as a Determine Actual logic statement or Sort method invocation, the Extract logic command appends data to the existing file, unless the Restart logic command is used.
The same attribute extracted to the same file from different frames is not distinguished when the file is read back in. For example, if an attribute Cust.Name appears in both Frame10 and Frame11, and these frames are extracted to A_File, a subsequent Determine Actual A_File ExtractedAs Frame10 logic statement and a reference to A_File.Cust.Name refers to extract file records extracted from both Frame10 and Frame11.
Examples
Example 1
Using a Frame “aStruct” you can write the values of the attributes to a file on disk. This logic must be executed as part of a report cycle, otherwise the file will not be closed (see Close() that allows this logic to exist anywhere).
aStruct.Name := "<Name>" aStruct.Address := "<Address>" aStruct.Phone := "<Phone_Number>" SetTitle outFile ("c:\\temp\\struct.txt") Extract aStruct As outFile
Example 2
: Selected CustInv records are extracted to A_File : A_File is sorted on attributes Customer, Product, Trandate and Trantime : The contents of A_File are printed to Frame1 : xEvent is an attribute under A_File templating from the Event EventSet Determine Actual A_file.xEvent.INVENTORY :sale records for customer, not invoiced If A_file.xEvent.AMOUNT > 1000 Extract A_File.xEvent as A_File End End A_File.Sort(key(A_File.xEvent.CUSTOMER, "Ascending"),\ key(A_File.xEvent.PRODUCT, "Ascending"),\ key(A_File.xEvent.TRANDATE, "Ascending"),\ key(A_File.xEvent.TRANTIME, "Ascending")) Determine Actual A_File Frame1.Customer := A_File.xEvent.CUSTOMER Frame1.Product := A_File.xEvent.PRODUCT Frame1.Amount := A_File.xEvent.AMOUNT Frame1.TranDate := A_File.xEvent.TRANDATE Frame1.TranTime := A_File.xEvent.TRANTIME Frame1.Print() End
Example 3
: For each customer in CUST, extract CustInv records to B_File using Frame 21 : B_File is sorted on attributes Customer : The contents of B_File are printed to Frame22 SetTitle B_File "CUSTTRANS" LookUp every CUST Move glb.ZEROS CustBalance Move CUST.CUSTOMER CustId Determine from Event.CUSTINV (CustId) If Event.CUSTOMER <> CustID Break End CustBalance := custBalance + Event.AMOUNT B_File.Frame21.Customer := Event.CUSTOMER B_File.Frame21.PBalance1 := CustBalance Extract B_File.Frame21 as B_File End End B_File.Sort(key(B_File.Frame21.Customer, "Descending")) Determine actual B_File Frame22.Customer := B_File.Frame21.Customer Frame22.PBalance2 := B_File.Frame21.PBalance1 Frame22.Print() End
Example 4
This example illustrates that assignment of the name of the extract file by the RetainAs command option is dynamic for Windows, but is declarative for MCP.
For a Windows application, the RetainAs command option determines the filename to be assigned to the extract file at the time of the Extract command’s execution.
For an MCP application, the assignment of the name of the extract file is always that of the last RetainAs command option specified in the current report.
If Field1 = "A" Extract Frame01 As A_File RetainAs "AA" End If Field1 = "B" Extract Frame01 As A_File RetainAs "BB" End If Field1 = "C" Extract Frame01 As A_File End
For Windows,
The extract file is retained under the name "AA" when the Field1 variable is set to “A”.
The extract file is retained under the name "BB" when the Field1 variable is set to “B”.
When the Field1 variable is set to “C”, a temporary extract file is created, which is deleted when the report terminates.
Note that the filename specified by RetainAs can be overridden by a previously executed SetTitle command.
For MCP,
The extract file A_File is retained under the name "BB", including the times when the Field1 variable is set to "A" or "C".
Note that the filename specified by RetainAs can be overridden by a previously executed SetTitle command.
To write code that is compatible with both MCP and Windows, use one of these two alternatives.
Alternative 1: SetTitle command
BeginCase Field1 Case "A", "B" SetTitle A_File Field1 & Field1 Extract Frame01 As A_File Case "C" Extract Frame01 As A_File EndCase
Alternative 2: File.Open() Method
BeginCase Field1 Case "A", "B" A_File.Open (Field1 & Field1, 1) Extract Frame01 As A_File Case "C" Extract Frame01 As A_File EndCase
Note: In Alternative 2, extract file A_File is opened in write mode. If you want to open the file in append mode, use the value 2 for the second parameter in the A_File.Open() method.
Example 5
This example illustrates how an extract file that has different record formats (such as header, trailer, and data records) can be read.
Note: For MCP, it is necessary for extract file C_File to have instances of Frame09 and Frame10 as members. This is what allows the different record formats to be read from the same file. This restriction makes the ExtractedAs command option redundant in MCP. The ExtractedAs command is redundant if the extract file has instances of all the frames and classes that will be read by the extract file.
Frame09
Attribute | Length | Template | Description |
---|---|---|---|
F09_RecTyp | 1 | String | Record Type |
F09_Data1 | 3 | String | Customer Reference |
F09_Data2 | 20 | String | Customer Name |
Frame10
Attribute | Length | Template | Description |
---|---|---|---|
F10_RecTyp | 1 | String | Record Type |
F10_Data1 | 6 | String | Transaction Reference |
F10_Data2 | 20 | String | Transaction Name |
Extract Frame09 As C_File Extract Frame10 As C_File Determine Actual C_File If C_File.Frame09.F09_RecTyp = "C" : Customer Record Message C_File.Frame09.F09_Data2 "- Customer Name" : Process customer record End If C_File.Frame10.F10_RecTyp = "T" : Transaction Record Message C_File.Frame10.F10_Data2 "- Transaction Amount" : Process transaction record End End