select count(1) from sapabap1.kna1 where updat = '00000000' union all
select count(1) from sapabap1.kna1 where updat != '00000000' union all
select count(1) from sapabap1.kna1 where updat is null;

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$" > 0 and p.mandt = '800'
order by p."$rowid$"