Loop in Windows bteq to use different export files for the select statement dataset

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
N/A

Loop in Windows bteq to use different export files for the select statement dataset

Hi 

I have a query where i need to have different export files for different values in where clause but the output is just last file from the list.

Have tried to write a bte script in windows 

.logon xxxx/usr,pwd
.os rm -f 'sp_value.txt' 'sp.txt'
.Set Echoreq off
.set width 720;
.Set Titledashes off
.Set Separator '|'
.Set Format off
.Set Null ''

.Export REPORT File = 'sp_value.txt'

sel distinct company_address as File_name
from MgrS_ANALYSIS_DEV.CUST_PURCHASE_DATA order by 1;

.Export Reset


.IMPORT vartext '|' FILE = 'sp_value.txt';
.run file = 'sp_value.txt',SKIP=1;
.REPEAT *
using (File_name varchar(100))
sel top 5 PURCHASE_DATE,COMPANY_NAME,QUANTITY_PURCHASE from MgrS_ANALYSIS_DEV.CUST_PURCHASE_DATA where company_address = :File_name;
.export reset

.Logoff
.Quit

 

Contents of sp_value.txt

File_name
.Export REPORT File = 'er_to_sap_file_for_110417_1.txt'
.Export REPORT File = 'er_to_sap_file_for_110417_2.txt'

 

The output is only one file 'er_to_sap_file_for_110417_2.txt'

with contents

PURCHASE_DATE|COMPANY_NAME |QUANTITY_PURCHASE
16/11/2016|xxxxxxxxx | 1
12/04/2016|yyyyyyyyyy | 1
PURCHASE_DATE|COMPANY_NAME |QUANTITY_PURCHASE
25/11/2016|zzzzzzzzzz | 2
14/09/2016|rrrrrrrrrrrrr | 2

 

Can anybody help to have the extract in different files.