select
tra_code TRA_CODE,
tra_desc TRA_DESC,
tra_fromcode TRA_FROMCODE,
tra_fromcode_org TRA_FROMCODE_ORG,
tra_org TRA_ORG,
tra_date TRA_DATE,
tra_fromentity TRA_FROMENTITY,
tra_fromrentity TRA_FROMRENTITY,
tra_type TRA_TYPE,
tra_status TRA_STATUS,
tra_pers TRA_PERS
FROM r5transactions
WHERE tra_rtype = 'STTK'
AND tra_rstatus <> 'A'  AND tra_rstatus <> 'C'   AND tra_org = <parameter.org>
AND (<parameter.storesec> = 'OFF'
OR  EXISTS( SELECT 1 FROM r5storesecurity, r5stores, r5userorganization
WHERE ssc_store = tra_fromcode
AND   ssc_group = uog_group
AND   uog_user = <parameter.r5user>
AND   uog_org = str_org
AND   str_code = tra_fromcode
AND COALESCE( ssc_physinventory, '-' ) = '+' ) )
order by tra_code ASC
