$PBExportHeader$f_storage_array.srf
global type f_storage_array from function_object
end type

forward prototypes
global subroutine f_storage_array (string arg_storagestr, string arg_storagestr_new, string arg_storagestr_audit)
end prototypes

global subroutine f_storage_array (string arg_storagestr, string arg_storagestr_new, string arg_storagestr_audit);Long ll_cnt,cnt,ll_cnt_new,ll_cnt_audit
String ls_storagestr,ls_storagestr_new,ls_storagestr_audit
Long ll_storageid
Long local_storageid[],local_storageid_new[],local_storageid_audit[]

ls_storagestr = arg_storagestr
ls_storagestr_new = arg_storagestr_new
ls_storagestr_audit = arg_storagestr_audit

IF Trim(arg_storagestr) = '' OR Trim(arg_storagestr) = '-1' THEN
	local_storageid[1] = 0
ELSE
	IF sys_power_issuper OR arg_storagestr = '0' THEN
		
		SELECT count(*) INTO :cnt
			FROM u_storage;
		IF sqlca.SQLCode <> 0 OR cnt = 0 THEN
			ll_cnt++
			local_storageid[ll_cnt] = 0
		ELSE			
			DECLARE cur_storage CURSOR FOR
				SELECT u_storage.storageID
				FROM u_storage
				Order By u_storage.storageID Desc;
				
			OPEN cur_storage;
			FETCH cur_storage INTO :ll_storageid;
			DO WHILE sqlca.SQLCode = 0
				ll_cnt++
				local_storageid[ll_cnt] = ll_storageid
				FETCH cur_storage INTO :ll_storageid;
			LOOP
			
			CLOSE cur_storage;
		END IF
	ELSE
		DO WHILE Len(ls_storagestr) <> 1
			ls_storagestr = Replace( ls_storagestr, 1, 1, '' )
			ll_storageid = Long(Left(ls_storagestr,Pos(ls_storagestr,',',1) - 1))
			ll_cnt++
			local_storageid[ll_cnt] = ll_storageid
			
			ls_storagestr = Replace ( ls_storagestr, 1, Pos(ls_storagestr,',',1) - 1, '' )
		LOOP
	END IF
END IF

IF Trim(arg_storagestr_new) = '' OR Trim(arg_storagestr_new) = '-1' THEN
	local_storageid_new[1] = 0
ELSE
	IF sys_power_issuper OR arg_storagestr_new = '0' THEN
		
		SELECT count(*) INTO :cnt
			FROM u_storage;
		IF sqlca.SQLCode <> 0 OR cnt = 0 THEN
			ll_cnt_new++
			local_storageid_new[ll_cnt_new] = 0
		ELSE			
			DECLARE cur_storage_new CURSOR FOR
				SELECT u_storage.storageID
				FROM u_storage
				Order By u_storage.storageID Desc;
				
			OPEN cur_storage_new;
			FETCH cur_storage_new INTO :ll_storageid;
			DO WHILE sqlca.SQLCode = 0
				ll_cnt_new++
				local_storageid_new[ll_cnt_new] = ll_storageid
				FETCH cur_storage_new INTO :ll_storageid;
			LOOP
			
			CLOSE cur_storage_new;
		END IF
	ELSE
		DO WHILE Len(ls_storagestr_new) <> 1
			ls_storagestr_new = Replace( ls_storagestr_new, 1, 1, '' )
			ll_storageid = Long(Left(ls_storagestr_new,Pos(ls_storagestr_new,',',1) - 1))
			ll_cnt_new++
			local_storageid_new[ll_cnt_new] = ll_storageid
			
			ls_storagestr_new = Replace ( ls_storagestr_new, 1, Pos(ls_storagestr_new,',',1) - 1, '' )
		LOOP
	END IF
END IF

IF Trim(arg_storagestr_audit) = '' OR Trim(arg_storagestr_audit) = '-1' THEN
	local_storageid_audit[1] = 0
ELSE
	IF sys_power_issuper OR arg_storagestr_audit = '0' THEN
		
		SELECT count(*) INTO :cnt
			FROM u_storage;
		IF sqlca.SQLCode <> 0 OR cnt = 0 THEN
			ll_cnt_audit++
			local_storageid_audit[ll_cnt_audit] = 0
		ELSE			
			DECLARE cur_storage_audit CURSOR FOR
				SELECT u_storage.storageID
				FROM u_storage
				Order By u_storage.storageID Desc;
				
			OPEN cur_storage_audit;
			FETCH cur_storage_audit INTO :ll_storageid;
			DO WHILE sqlca.SQLCode = 0
				ll_cnt_audit++
				local_storageid_audit[ll_cnt_audit] = ll_storageid
				FETCH cur_storage_audit INTO :ll_storageid;
			LOOP
			
			CLOSE cur_storage_audit;
		END IF
	ELSE
		DO WHILE Len(ls_storagestr_audit) <> 1
			ls_storagestr_audit = Replace( ls_storagestr_audit, 1, 1, '' )
			ll_storageid = Long(Left(ls_storagestr_audit,Pos(ls_storagestr_audit,',',1) - 1))
			ll_cnt_audit++
			local_storageid_audit[ll_cnt_audit] = ll_storageid
			
			ls_storagestr_audit = Replace ( ls_storagestr_audit, 1, Pos(ls_storagestr_audit,',',1) - 1, '' )
		LOOP
	END IF
END IF

sys_user_storageid = local_storageid
//sys_user_storageid_new  = local_storageid_new
//sys_user_storageid_audit  = local_storageid_audit

end subroutine

