D3 Reporting with ODBC - Sample BASIC code
                    
                    
                    
001 subroutine Fondika.mcr(fecini,fecfin,cuentamd,empresa,ubic,gpofact,cvenom,encab,matriz)
002 * Excel * Reporte de Cves para Fondika *
003 *
004 * JCC * ADs * 6 Mar 09
005 *
006 *
007 *****
008   open 'ADsourcing,Varios,' to varios else stop
009   read MDS from varios,'CuentasMDS'
010   if cuentamd#'' then MDS=cuentamd
011   close varios
012   fechaini = iconv(fecini,'d/');  fechafin = iconv(fecfin,'d/')
013   nMDs = dcount(mds,char(254));  matriz='';  cvenom=cvenom'r%3'
014   encab=oconv(cvenom,'tforda,nconceptos,;x;;1')
015   root 'adsourcing,ubicaciones,','a1' to rt.ubic else stop 'no root'
016   if ubic#'' then
017     key('r',rt.ubic,ubic,id) then ubica=id else ubica='zz'
018   end else ubica=''
019   for md=1 to nMDs
020     cuenta = mds;  file = cuenta:',nvarios,'
021     femp=cuenta:',nemp,';  open femp to nemp else null
022     fcom=cuenta:',nempcompl,';  open fcom to comp else null
023     fsar=cuenta:',nsar,';  open fsar to nsar else null
024     pnap='t':cuenta:',napatron,;c;;6'
025     open file to varios else stop 'No Varios'
026     if fechafin'd2y' = date()'d2y' then registro='TN' else
027       registro='tn':(fechafin'd2y')'r%2'
028     end
029     read datos from varios,registro then
030       locate(fechaini,datos,6;valini;'ar') then null
031       locate(fechafin,datos,6;aqui;'ar') then null
032       if aqui > datosthen valfin=datoselse
033         valfin=aqui;  if datos> fechafin then valfin=aqui-1
034       end
035       for per=valini to valfin
036         periodo = (fechaini'd2y')'r%2':(per'r%2')
037         fm=cuenta:',nmovs,':periodo:','
038         open fm to nmovs then
039           root fm,'a0' to rt.nmovs.id else
040             execute 'create-index ':fm:' a0' capturing z
041             root fm,'a0' to rt.nmovs.id else matriz='Problema root'; return
042           end
043           indk='';  yanohay=0;  id=''
044           loop
045             key('n',rt.nmovs.id,indk,id) else yanohay=1
046           until yanohay do
047             read dmovs from nmovs,id then
048               read dnemp from nemp,id else dnemp=''
049               read dcomp from comp,id else dcomp=''
050               read dnsar from nsar,id else dnsar=''
051               if fechaini >= 14977 then varempr=oconv(id,pnap) else varempr=dcomp
052               if varempr=empresa ! empresa='' then
053                 if dnemp=ubica ! ubic='' then
054                   if dcomp=gpofact ! gpofact='' then
055                     locate(cvenom,dmovs,1;aquicve) then
056                       mdid=cuenta:',':id;  impor=dmovs
057                       tp=dmovs;* importe=impor*tp*(-1)
058                       importe=impor
059                       locate(mdid,matriz,8;aquiid) then
060                         matriz=matriz+importe
061                       end else
062                         matriz=insert(matriz,1,aquiid;cuenta)
063                         matriz=insert(matriz,2,aquiid;id)
064                         matriz=insert(matriz,3,aquiid;dnemp)
065                         matriz=insert(matriz,4,aquiid;dnsar)
066                         matriz=insert(matriz,5,aquiid;dnsar)
067                         matriz=insert(matriz,6,aquiid;datos)
068                         matriz=insert(matriz,7,aquiid;importe)
069                         matriz=insert(matriz,8,aquiid;mdid)
070                       end
071                     end
072                   end
073                 end
074               end
075             end
076           repeat
077         end;  close nmovs
078       next per;  close varios;  close nemp;  close comp;  close nsar
079     end
080   next md
081   * Pone mascara
082   for i=7 to 7
083     for j=1 to dcount(matriz,char(253))
084       matriz= matriz'r26'
085     next j
086   next i
087 return
                    
                    
                    
                        Featured:
                            
                                     
                                Jul/Aug 2009