In this code sample I am using Range Where to retrieve a set of records from a specific table and then using while loop to iterate through the retrieved records. Hope this helps..
{display open invoice records from PM_Transaction_Open}
range clear table PM_Transaction_OPEN;
range table PM_Transaction_OPEN where physicalname('Vendor ID' of table PM_Transaction_OPEN) + CH_SPACE + CH_EQUAL + SQL_FormatStrings('Vendor ID')
+ CH_SPACE + SQL_AND + CH_SPACE
+ physicalname('Document Type' of table PM_Transaction_OPEN) + CH_SPACE + CH_EQUAL + "1";
get first table PM_Transaction_OPEN;
while err() = OKAY do
debug "Voucher Number : "+'Voucher Number' of table PM_Transaction_OPEN+" , Vendor ID : "+'Vendor ID' of table PM_Transaction_OPEN;
copy from table PM_Transaction_OPEN to table IMT_PMBNKTRF_TMP;
{save payment number}
'Payment Number' of table IMT_PMBNKTRF_TMP = 'Payment Number';
{lets save currency id from MC_Currency_SETP}
clear table MC_Currency_SETP;
'Currency ID' of table MC_Currency_SETP = 'Currency ID' of table PM_Transaction_OPEN;
get table MC_Currency_SETP by MC_Currency_SETP_Key1;
if err() = OKAY then
'Currency Index' of table IMT_PMBNKTRF_TMP = 'Currency Index' of table MC_Currency_SETP;
end if;
{if currency id is not functional currency id, get original currency trx amount from MC_PM_Transactions and save to temp table}
if 'Currency ID' of table PM_Transaction_OPEN <> 'Functional Currency' of globals then
clear table MC_PM_Transactions;
'Document Type' of table MC_PM_Transactions = 'Document Type' of table PM_Transaction_OPEN;
'Voucher Number' of table MC_PM_Transactions = 'Voucher Number' of table PM_Transaction_OPEN;
get table MC_PM_Transactions by MC_PM_Transactions_Key1;
if err() = OKAY then
'Current Trx Amount' of table IMT_PMBNKTRF_TMP = 'Originating Current Trx Amount' of table MC_PM_Transactions;
end if;
end if;
{check if this record already in IMT_PMBNKTRF_DTL file, if yes: override the CheckBox Value and Applied Amount}
clear table IMT_PMBNKTRF_DTL;
'Payment Number' of table IMT_PMBNKTRF_DTL = 'Payment Number';
'Document Number' of table IMT_PMBNKTRF_DTL = 'Document Number' of table PM_Transaction_OPEN;
'Voucher Number' of table IMT_PMBNKTRF_DTL = 'Voucher Number' of table PM_Transaction_OPEN;
get table IMT_PMBNKTRF_DTL by IMT_PMBNKTRF_DTL_KEY2;
if err() = OKAY then
imtPMApplySelect of table IMT_PMBNKTRF_TMP = imtPMApplySelect of table IMT_PMBNKTRF_DTL;
'Applied Amount' of table IMT_PMBNKTRF_TMP = 'Applied Amount' of table IMT_PMBNKTRF_DTL;
end if;
save table IMT_PMBNKTRF_TMP;
clear table IMT_PMBNKTRF_TMP;
get next table PM_Transaction_OPEN;
end while;
fill window imtSelectInvoices_SW;