Senin, 23 Juli 2012

Belajar ABAP (2)

REPORT yrp_andy_latihan1 .
write:/ '------------------------- Date ------------------'.
write:/ sy-datum.
write:/ sy-datlo.
write:/ sy-dayst.
write:/ sy-fdayw.
write:/ sy-timlo.
write:/ sy-uzeit.
write:/ '------------------------- Date ------------------'.
Kamis, 12 Juli 2012

Belajar ABAP (1)

Akhirnya dateng juga kesempetan gwe belajar ABAP. Mumpung dikasih kesempatan buat ngoprek ABAP dikantor, harus dimanfaatin bener2 nih :D ini koding pertama gwe...

REPORT yrp_andy_latihan1 .
* Definisi data
DATA : dg_a TYPE i, dg_b TYPE i, dg_c TYPE p DECIMALS 2, dg_d TYPE p
DECIMALS 2.

DATA: dg_name LIKE sy-uname, dg_tanggal LIKE sy-datum.

* initialisasi
dg_a = 10.
dg_b = 5.
dg_c = dg_a / dg_b.
dg_d = dg_a * dg_b.
dg_name = sy-uname.
dg_tanggal = sy-datum.

* output
WRITE:/ 'Hasil ', dg_a, ' + ', dg_b, '=', dg_c.
WRITE:/ 'Hasil ', dg_a, ' * ', dg_b, '=', dg_d.
WRITE:/ 'USERNAME : ', dg_name.
WRITE:/ 'Tanggal : ', dg_tanggal.
Minggu, 12 Februari 2012

Penggunaan Cross Apply


Sabtu, 11 Februari 2012

Parsing data

update profil_dokter
set isi_profil=replace(isi_profil,
(
    substring(
        substring(isi_profil,instr(isi_profil,"
        1,
        instr(substring(isi_profil,instr(isi_profil,"')
    )
),"")
where isi_profil !='' and isi_profil like '%src="%'

Akal-akalan

create table x as
select id_dokter, substring(gambar,1,instr(gambar,'"')-1) pathgambar
from (
    select id_dokter, path, substring(path,instr(path, "src")+6) gambar
    from (
        select id_dokter, isi_profil, gambar,
        substring(isi_profil,instr(isi_profil,"
        from profil_dokter where isi_profil !='' and isi_profil like '%src="%'
    )a
)x
 

UPDATE profil_dokter a
inner join (
SELECT id_dokter, reverse(substring(REVERSE(pathgambar), 1, instr(REVERSE(pathgambar),'/')-1)) gambar_dokter
from x
)y on (a.id_dokter=y.id_dokter)
set gambar=gambar_dokter

Bermain-main dengan path

select id_dokter, gambar, substring(gambar,1,instr(gambar,'"')-1) pathgambar
from (
    select id_dokter, path, substring(path,instr(path, "src")+6) gambar
    from (
        select id_dokter, isi_profil, gambar,
        substring(isi_profil,instr(isi_profil,"
        from profil_dokter where isi_profil !='' and isi_profil like '%src="%'
    )a
)x
Senin, 06 Februari 2012

Subquery lagi

update k set incentive=(case when percentage_am=1 then k.incentive else k.incentive/2 end)
    from trmasterincentive_summary k
    inner join (
        select x.idstructure, incentive,
        case when (cast(y.jumlahAM_ach as float)) / (cast (y.JumlahAM as float)) > 0.6
        then 1
        else 0
        end percentage_am
        from trmasterincentive_summary x
        inner join (
            select a.idstructure,
            (select COUNT(distinct idstructure_am) from structorg where year=2011 and month=11 and idcat=10 and idstructure_sm=a.idstructure)JumlahAM,
            (
                select COUNT(distinct idstructure_am)
                from trmasterincentive_summary p
                inner join structorg q on (p.idstructure=q.idstructure_am and q.idstructure_sm=a.idstructure)
                where idjob in(3,29) and percentage>=90
            )jumlahAM_ach
            from trmasterincentive_summary a
            where idlogstructure=176 and idjob in(1,24) and percentage>=90
        ) y on (x.idstructure=y.idstructure)
    ) l on (k.idstructure=l.idstructure)
Rabu, 01 Februari 2012

Query Terburuk

query terburuk yang pernah gwe buat... execution timenya 30menit... :((

Senin, 30 Januari 2012

Penggunaan Sub Query untuk mengghitung incentive perkategori

select c.* from (
    select idstructure, sum(salesgrosspharma1) salesgrosspharma1, sum(targetpharma1) targetpharma1, sum(PercentagePharma1)PercentagePharma1,
    sum(salesgrosspharma2) salesgrosspharma2, sum(targetpharma2) targetpharma2, sum(PercentagePharma2) PercentagePharma2,
    sum(salesgrosspharma3) salesgrosspharma3, sum(targetpharma3) targetpharma3, sum(PercentagePharma3) PercentagePharma3
    from (
        select idstructure,
        case
            when idsubcat=21 then (select salesgross from TrMasterIncentiveSubCat where idsubcat=21 and idstructure=a.idstructure)
            else 0
        end salesgrossPharma1,
        case
            when idsubcat=21 then (select target from TrMasterIncentiveSubCat where idsubcat=21 and idstructure=a.idstructure)
            else 0
        end targetPharma1,
        case
            when idsubcat=21 then (select percentage from TrMasterIncentiveSubCat where idsubcat=21 and idstructure=a.idstructure)
            else 0
        end PercentagePharma1,
        case
            when idsubcat=22 then (select salesgross from TrMasterIncentiveSubCat where idsubcat=22 and idstructure=a.idstructure)
            else 0
        end salesgrossPharma2,
        case
            when idsubcat=22 then (select target from TrMasterIncentiveSubCat where idsubcat=22 and idstructure=a.idstructure)
            else 0
        end targetPharma2,    
        case
            when idsubcat=22 then (select percentage from TrMasterIncentiveSubCat where idsubcat=22 and idstructure=a.idstructure)
            else 0
        end PercentagePharma2,        
        case
            when idsubcat=23 then (select salesgross from TrMasterIncentiveSubCat where idsubcat=23 and idstructure=a.idstructure)
            else 0
        end salesgrossPharma3,
        case
            when idsubcat=23 then (select target from TrMasterIncentiveSubCat where idsubcat=23 and idstructure=a.idstructure)
            else 0
        end targetPharma3,
        case
            when idsubcat=23 then (select percentage from TrMasterIncentiveSubCat where idsubcat=23 and idstructure=a.idstructure)
            else 0
        end PercentagePharma3
        from TrMasterIncentiveSubCat a
    )b
    group by idstructure
) c inner join trrekapidcovjob d on (c.idstructure=d.idstructure)
where idlogincentive=167
Rabu, 25 Januari 2012

Update subquery

update trmasterincentive set average_incentivenp=incentivenp
from trmasterincentive a
inner join (
    select a.idstructure, incentive, cast(incentive*score as int) incentiveNP
    from (
        select idstructure, percentage, sum(incentive) incentive from _incentiveNPPercentage
        group by idstructure, percentage
    )a inner join trmasterincentive b on (a.idstructure=b.idstructure)
    inner join mscore c on (status=10 and a.percentage between fromrange and torange)
) b on (a.idstructure=b.idstructure)
Senin, 23 Januari 2012

Sub Query

select * from trmasterincentive x
inner join (
    select idstructure, average_incentive, fromrange, torange, score,
    case when average_incentive between fromrange and torange then score
    else average_incentive
    end new_average_incentive
    from _average_incentive a
    inner join mscore b on (a.idscheme=b.idscheme and status=6 and isactive='T')
) y on (x.idstructure=y.idstructure)
Kamis, 19 Januari 2012

Query Iseng

update TrMasterIncentive set idscheme=idscheme2 from TrMasterIncentive aaa inner join (
    select *
    from (
        select distinct b.idstructure, a.idscheme, c.idscheme idscheme2, c.iscombo
        from TrMasterIncentive a
        inner join TrRekapIdCovJob b on (a.idstructure=b.idstructure)
        inner join mscheme c on (b.idjob=c.idjob and b.idsubcat=c.idsubcat AND IsActive = 'T' and b.iscombo=0 and ('2012-01-01' between c.StartDate and c.EndDate))
        where idcat=10 and a.idlogincentive=162
        union
        select distinct b.idstructure, a.idscheme, c.idscheme idscheme2, c.iscombo
        from TrMasterIncentive a
        inner join TrRekapIdCovJob b on (a.idstructure=b.idstructure)
        inner join mscheme c on (b.idjob=c.idjob and b.idsubcat=c.idsubcat AND IsActive = 'T' and b.iscombo=1 and ('2012-01-01' between c.StartDate and c.EndDate))
        where b.iscombo=1 and a.idlogincentive=162
        union
        select distinct b.idstructure, a.idscheme, c.idscheme idscheme2, c.iscombo
        from TrMasterIncentive a
        inner join TrRekapIdCovJob b on (a.idstructure=b.idstructure)
        inner join mscheme c on (b.idjob=c.idjob and b.idsubcat=c.idsubcat AND IsActive = 'T' and ('2012-01-01' between c.StartDate and c.EndDate))
        where b.idjob in(1,24) and a.idlogincentive=162
    ) xyz
) bbb on (aaa.idstructure=bbb.idstructure)
Kamis, 13 Oktober 2011

Cetak Tanggal Dalam Sebulan

declare @month int, @year int
set @month = 2
set @year = 2009

SELECT
    CAST(CAST(@year AS VARCHAR) + '-' + CAST(@month AS VARCHAR) + '-01' AS DATETIME) + number
FROM master..spt_values
WHERE type = 'P'
AND (CAST(CAST(@year AS VARCHAR) + '-' + CAST(@month AS VARCHAR) + '-01' AS DATETIME) + number )
<
DATEADD(mm,1,CAST(CAST(@year AS VARCHAR) + '-' + CAST(@month AS VARCHAR) + '-01' AS DATETIME) )
Rabu, 12 Oktober 2011

Hari minggu

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER function [dbo].[fget_sunday_of_year](@year int)
RETURNS @tabel TABLE (date datetime)
AS
BEGIN
  DECLARE @date datetime, @n int, @i int;
  SET @i=1;
  SET @date=(SELECT cast(year(cast(@year as varchar(4))) as varchar(4))+'-12-31');
  SET @n=(SELECT DATEPART(wk, @date));
  SET @date=(SELECT    DATEADD(DAY, (7 - DATEDIFF(DAY, '17530101', DATEADD(YEAR, DATEDIFF(YEAR, 0, @date), '19000101')) % 7) % 7, DATEADD(YEAR, DATEDIFF(YEAR, 0, @date), '19000101'))-1 AS date)

  INSERT @tabel
  SELECT @date

  WHILE(@i<@n-1)
  BEGIN
   SET @date=(SELECT @date+7);
   INSERT @tabel
   SELECT @date;
   SET @i=@i+1;
  END
RETURN;
END;
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO



 
Rabu, 17 Agustus 2011

Panjang URL

Sekedar mo ngingetin... yang hoby ngelempar parameter di url hati2 dengan panjang urlnya... setelah saya google ternyata IE membatasi panjang URLnya 2048 karakter
Senin, 08 Agustus 2011

Iseng-iseng bikin cube

Akhirnya bisa juga gwe buat cube... cihuyyy... :D


Roll Up & Cube

Berikut sampel penggunaan Roll Up dan Cube untuk menganalisis data:

select customername, sum(salesvalue) sales, vsn
from invoices a
inner join customers b on (a.customerid=b.customerid)
inner join products c on (a.vsnid=c.vsnid)
where year(edate)=2011 and month(edate)=8
group by customername, vsn

select
    case when grouping(customername)=1 then 'All Customer'
    else customername
    end customername,
    case when grouping(vsn)=1 then 'All product'
    else vsn
    end vsn, sum(salesvalue)
from invoices a
inner join customers b on (a.customerid=b.customerid)
inner join products c on (a.vsnid=c.vsnid)
where year(edate)=2011 and month(edate)=8
group by customername, vsn
with rollup

select
    case when grouping(customername)=1 then 'All Customer'
    else customername
    end customername,
    case when grouping(vsn)=1 then 'All product'
    else vsn
    end vsn, sum(salesvalue)
from invoices a
inner join customers b on (a.customerid=b.customerid)
inner join products c on (a.vsnid=c.vsnid)
where year(edate)=2011 and month(edate)=8
group by customername, vsn
with cube
Selasa, 26 Juli 2011

Cek Mobile Browser

ini contoh script gwe lupa darimana untuk ngecek browser versi mobile....


http://www.ziddu.com/download/15826372/browser.txt.html

Query Iseng

Gara2 salah design database gwe harus buat query cukup panjang... :(

select employeeid, employeename, asmid, asmname, smid, smname, teamid, teamname, year, joindate,
sum(jan) jan, sum(feb) feb, sum(mar) mar, sum(apr) apr, sum(may) may, sum(jun) jun,
sum(jul) jul, sum(aug) aug, sum(sep) sep, sum(oct) oct, sum(nov) nov, sum(dec) dec,
sum(jan)+sum(feb)+sum(mar)+sum(apr)+sum(may)+sum(jun)+sum(jul)+sum(aug)+sum(sep)+sum(oct)+sum(nov)+sum(dec) total, region, areaname
from (
    select employeeid, employeename, asmid, asmname, smid, smname, teamid, teamname, year, joindate,
    case when month=1 then sum(jan) else 0 end jan,
    case when month=2 then sum(feb) else 0 end feb,
    case when month=3 then sum(mar) else 0 end mar,
    case when month=4 then sum(apr) else 0 end apr,
    case when month=5 then sum(may) else 0 end may,
    case when month=6 then sum(jun) else 0 end jun,
    case when month=7 then sum(jul) else 0 end jul,
    case when month=8 then sum(aug) else 0 end aug,
    case when month=9 then sum(sep) else 0 end sep,
    case when month=10 then sum(oct) else 0 end oct,
    case when month=11 then sum(nov) else 0 end nov,
    case when month=12 then sum(dec) else 0 end dec,
    (select distinct regionname from vstructorg x where x.tahun=yy.year and x.bulan=bulan and employeeid=psrid and x.asmid=yy.asmid) region,
    (select distinct areaname from vstructorg x where x.tahun=yy.year and x.bulan=bulan and employeeid=psrid and x.asmid=yy.asmid) areaname
    from jupiter_clubmember_summary yy
    group by employeeid, employeename, asmid, asmname, smid, smname, teamid, teamname, month, year, joindate
) a
group by employeeid, employeename, asmid, asmname, smid, smname, teamid, teamname, year, joindate, region, areaname
Sabtu, 16 Juli 2011

Query Iseng

select * from (
   select a.kodebarang, namabarang, max(tanggal) tanggal
   from harga a
   inner join barang b on (a.kodebarang=b.kodebarang)
  group by a.kodebarang, namabarang
) x
inner join harga y on (x.kodebarang=y.kodebarang and x.tanggal=y.tanggal)
order by x.kodebarang

About Me

Koral Web
Kami adalah web developer. Beberapa produk yang pernah kami buat antara lain website, aplikasi klinik, aplikasi apotik, aplikasi EDMS (Electronic Database Management System), Energy Consumption Management System, RKBI (Rencana Kunjungan Barang Import) dan lain-lain sesuai dengan request dari client kami. Jika Anda tertarik untuk membuat system atau aplikasi, jangan sungkan-sungkan menghubungi kami.
Lihat profil lengkapku

Bahasa Pemrogramanmu?

Nasihat

Barangsiapa capek lelah dan letihnya bukan karena Allah maka celakalah dia
Diberdayakan oleh Blogger.

Blog Archieve

SMS Gratis