select top 20 "$rowid$" as rowids,
	vbeln, mandt, erdat, wadat_ist, ctlpc, kunnr, aedat,lfuhr,
	case wadat_ist when '00000000' then null else (to_date(wadat_ist)||' '||to_time(lfuhr)) end as wadat_ist2lfuhr
from sapabap1.likp where wadat_ist = '00000000';



select top 10
 a.vbeln, a.mandt, a.vbtyp, a.audat, a.waerk, a.kalsm, a.ctlpc, a.kunnr, a.bukrs_vf, a.bstnk, 
 a.bname, a.telf1, a.netwr, a.vkbur, a.knumv, a.vkorg, a.vtweg, a.kkber, a.auart, a.aedat, b.pernr, 
 case a.erdat when '00000000' then null else (to_date(a.erdat)||' '||to_time(a.erzet)) end as erdat2erzet
from sapabap1.vbak a 
left join (
	select q.vbeln,q.posnr,r.pernr from sapabap1.vbap q 
		left  join (
			select vbeln,posnr,pernr from sapabap1.vbpa where mandt = '800' and pernr != '00000000' group by vbeln,posnr,pernr
		) r on q.vbeln = r.vbeln and q.posnr = r.posnr 
	where q.mandt = '800'
) b on a.vbeln = b.vbeln
where a.mandt = '800' and a.erdat = '00000000'

select 
 a.vbeln, a.mandt, a.vbtyp, a.audat, a.waerk, a.kalsm, a.ctlpc, a.kunnr, a.bukrs_vf, a.bstnk, 
 a.bname, a.telf1, a.netwr, a.vkbur, a.knumv, a.vkorg, a.vtweg, a.kkber, a.auart, a.aedat, b.pernr, 
 case a.erdat when '00000000' then null else (to_date(a.erdat)||' '||to_time(a.erzet)) end as erdat2erzet,
 a.erdat, a.erzet
from sapabap1.vbak a 
left join (
	select q.vbeln,r.pernr from sapabap1.vbap q 
		left  join (
			select vbeln,posnr,pernr from sapabap1.vbpa where mandt = '800' and pernr != '00000000' group by vbeln,posnr,pernr
		) r on q.vbeln = r.vbeln and q.posnr = r.posnr 
	where q.mandt = '800'
	group by q.vbeln,r.pernr
) b on a.vbeln = b.vbeln
where a.vbeln = '0010042311' and a.mandt = '800'
		
----
select 
 a.vbeln, a.mandt, a.vbtyp, a.audat, a.waerk, a.kalsm, a.ctlpc, a.kunnr, a.bukrs_vf, a.bstnk, 
 a.bname, a.telf1, a.netwr, a.vkbur, a.knumv, a.vkorg, a.vtweg, a.kkber, a.auart, a.aedat, b.pernr, 
 case a.erdat when '00000000' then null else (to_date(a.erdat)||' '||to_time(a.erzet)) end as erdat2erzet,
 a.erdat, a.erzet
from sapabap1.vbak a 
left join (
	select q.vbeln,r.pernr from sapabap1.vbap q 
		left  join (
			select vbeln,posnr,pernr from sapabap1.vbpa where mandt = '800' and pernr != '00000000' group by vbeln,posnr,pernr
		) r on q.vbeln = r.vbeln and q.posnr = r.posnr 
	where q.mandt = '800' and r.pernr is not null
	group by q.vbeln,r.pernr
) b on a.vbeln = b.vbeln
where a.vbeln = '0010009580' and a.mandt = '800'

----------------------------













select 
	p.vbeln, p.posnr, p.matnr, p.mandt, p.matkl, p.spart, p.kwmeng, p.netwr, p.mwsbp, p.waerk, p.vrkme, p.abgru, 
	p.uebto, p.untto, p.werks, p.vstel, p.mvgr1, p.plavo, p.mvgr4, p.mvgr5, p.ulxh, p.zma_ftb_02, p.zma_ftb_03, 
	p.zma_ftb_45, p.zma_ftb_06, p.zma_ftb_07, p.zma_ftb_08, p.zma_jyb_02, p.zma_jyb_03, p.zma_jyb_45, 
	p.zma_jyb_06, p.zma_jyb_07, p.zma_ljb_03, p.zma_ljb_04, p.zma_ljb_06, p.zma_ljb_07, p.zma_ljb_08, 
	p.zma_ljb_11, p.zma_ljb_12, p.zma_ljb_13, p.zma_yhbg_02, p.zma_yhbg_04, p.zma_yhbg_05, p.zma_yhbg_06, 
	p.tbpz, p.ws, p.cu_maktx, p.cu_pcdst, p.ztype, p.barcode, p.gdno, p.lh, p.dgxx, p.zklx, p.erdat, p.erzet, p.netpr, p.aedat,q.pernr
from sapabap1.vbap p
left join (

	select 
		a.vbeln,b.posnr, b.pernr
	from sapabap1.vbak a 
	left join () b on a.vbeln = b.vbeln
	where b.pernr is not null and a.mandt = '800' and a.vbeln = '0010041154'
	group by a.vbeln, b.posnr,b.pernr


) q on p.vbeln = q.vbeln
where p.vbeln = '0010041154' and p.posnr = '000010' and p.mandt = '800' and p.erdat = '20190606';



select
	p.vbeln, p.posnr, p.matnr, p.mandt, p.matkl, p.spart, p.kwmeng, p.netwr, p.mwsbp, p.waerk, p.vrkme, p.abgru, 
	p.uebto, p.untto, p.werks, p.vstel, p.mvgr1, p.plavo, p.mvgr4, p.mvgr5, p.ulxh, p.zma_ftb_02, p.zma_ftb_03, 
	p.zma_ftb_45, p.zma_ftb_06, p.zma_ftb_07, p.zma_ftb_08, p.zma_jyb_02, p.zma_jyb_03, p.zma_jyb_45, 
	p.zma_jyb_06, p.zma_jyb_07, p.zma_ljb_03, p.zma_ljb_04, p.zma_ljb_06, p.zma_ljb_07, p.zma_ljb_08, 
	p.zma_ljb_11, p.zma_ljb_12, p.zma_ljb_13, p.zma_yhbg_02, p.zma_yhbg_04, p.zma_yhbg_05, p.zma_yhbg_06, 
	p.tbpz, p.ws, p.cu_maktx, p.cu_pcdst, p.ztype, p.barcode, p.gdno, p.lh, p.dgxx, p.zklx, p.erdat, p.erzet, p.netpr, p.aedat,q.pernr
from sapabap1.vbap p 
left join (
	select a.vbeln,a.posnr,a.pernr from sapabap1.vbpa a
		left join sapabap1.vbak b on a.vbeln = b.vbeln
	where a.mandt = '800' and a.pernr != '00000000' 
	group by a.vbeln,a.posnr,a.pernr
) q on p.vbeln = q.vbeln and p.posnr = q.posnr
where p.vbeln = '0010041154' and p.posnr = '000010' and p.mandt = '800' and p.erdat = '20190606';







select
	p.vbeln, p.posnr, p.matnr, p.mandt, p.matkl, p.spart, p.kwmeng, p.netwr, p.mwsbp, p.waerk, p.vrkme, p.abgru, 
	p.uebto, p.untto, p.werks, p.vstel, p.mvgr1, p.plavo, p.mvgr4, p.mvgr5, p.ulxh, p.zma_ftb_02, p.zma_ftb_03, 
	p.zma_ftb_45, p.zma_ftb_06, p.zma_ftb_07, p.zma_ftb_08, p.zma_jyb_02, p.zma_jyb_03, p.zma_jyb_45, 
	p.zma_jyb_06, p.zma_jyb_07, p.zma_ljb_03, p.zma_ljb_04, p.zma_ljb_06, p.zma_ljb_07, p.zma_ljb_08, 
	p.zma_ljb_11, p.zma_ljb_12, p.zma_ljb_13, p.zma_yhbg_02, p.zma_yhbg_04, p.zma_yhbg_05, p.zma_yhbg_06, 
	p.tbpz, p.ws, p.cu_maktx, p.cu_pcdst, p.ztype, p.barcode, p.gdno, p.lh, p.dgxx, p.zklx, p.erdat, p.erzet, p.netpr, p.aedat,q.pernr
from ${hana_user}.vbap p 
left join (
	select a.vbeln,a.posnr,a.pernr from ${hana_user}.vbpa a
		left join ${hana_user}.vbak b on a.vbeln = b.vbeln
	where a.mandt = #{mandt} and a.pernr != '00000000' 
	group by a.vbeln,a.posnr,a.pernr
) q on p.vbeln = q.vbeln and p.posnr = q.posnr
where p.vbeln = #{vbeln} and p.posnr = #{posnr} and p.mandt = #{mandt} and p.erdat = #{erdat}


select top 20 "$rowid$" as rowids,
	p.vbeln, p.posnr, p.matnr, p.mandt, p.matkl, p.spart, p.kwmeng, p.netwr, p.mwsbp, p.waerk, p.vrkme, p.abgru, 
	p.uebto, p.untto, p.werks, p.vstel, p.mvgr1, p.plavo, p.mvgr4, p.mvgr5, p.ulxh, p.zma_ftb_02, p.zma_ftb_03, 
	p.zma_ftb_45, p.zma_ftb_06, p.zma_ftb_07, p.zma_ftb_08, p.zma_jyb_02, p.zma_jyb_03, p.zma_jyb_45, 
	p.zma_jyb_06, p.zma_jyb_07, p.zma_ljb_03, p.zma_ljb_04, p.zma_ljb_06, p.zma_ljb_07, p.zma_ljb_08, 
	p.zma_ljb_11, p.zma_ljb_12, p.zma_ljb_13, p.zma_yhbg_02, p.zma_yhbg_04, p.zma_yhbg_05, p.zma_yhbg_06, 
	p.tbpz, p.ws, p.cu_maktx, p.cu_pcdst, p.ztype, p.barcode, p.gdno, p.lh, p.dgxx, p.zklx, p.erdat, p.erzet, p.netpr, p.aedat,q.pernr
from sapabap1.vbap p 
left join (
	select a.vbeln,a.posnr,a.pernr from sapabap1.vbpa a
		left join sapabap1.vbak b on a.vbeln = b.vbeln
	where a.mandt = '800' and a.pernr != '00000000' 
	group by a.vbeln,a.posnr,a.pernr
) q on p.vbeln = q.vbeln and p.posnr = q.posnr
where p."$rowid$" > 10 and p.mandt = '800'
order by p."$rowid$"
