<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.huazheng.project.hana.mapper.SapMapper">
	
    <select id="selectVbapNew" parameterType="Vbap" resultType="Vbap">
		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 ${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."$rowid$" > 10 and p.mandt = #{mandt}
    	order by p."$rowid$"
    </select>
    
	<select id="selectBsidNew" parameterType="Bsid" resultType="Bsid">
    	select top 20 a."$rowid$" as rowids,
    		a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
    		a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm, b.pernr 
    	from ${hana_user}.bsid a
		left join (
			select 
				aa.vbeln, aa.aubel, bb.pernr
			from ${hana_user}.vbrp aa
			left join (
				select vbeln,pernr,posnr from ${hana_user}.vbpa where mandt = '800' and pernr != '00000000' group by vbeln,pernr,posnr
			) bb on aa.aubel = bb.vbeln and aa.aupos = bb.posnr
			where bb.pernr is not null and aa.mandt = '800'
			group by aa.vbeln, aa.aubel, bb.pernr
		) b on a.vbeln = b.vbeln
		where a."$rowid$" &gt; #{rowids} and a.mandt = '800'
		order by a."$rowid$"
    </select>
    <select id="selectBsadNew" parameterType="Bsad" resultType="Bsad">
		select top 20 a."$rowid$" as rowids,
    		a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
    		a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm, b.pernr 
    	from ${hana_user}.bsad a
		left join (
			select 
				aa.vbeln, aa.aubel, bb.pernr
			from ${hana_user}.vbrp aa
			left join (
				select vbeln,pernr,posnr from ${hana_user}.vbpa where mandt = '800' and pernr != '00000000' group by vbeln,pernr,posnr
			) bb on aa.aubel = bb.vbeln and aa.aupos = bb.posnr
			where bb.pernr is not null and aa.mandt = '800'
			group by aa.vbeln, aa.aubel, bb.pernr
		) b on a.vbeln = b.vbeln
		where a."$rowid$" &gt; #{rowids} and a.mandt = '800'
		order by a."$rowid$"
    </select>
    <select id="selectPa0002New" parameterType="Pa0002" resultType="Pa0002">
    	select top 20 "$rowid$" as rowids,
    		mandt,pernr,subty,objps,sprps,endda,begda,seqnr,nachn,vorna,aedtm
    	from ${hana_user}.Pa0002
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectVbpaNew" parameterType="Vbpa" resultType="Vbpa">
    	select top 20 "$rowid$" as rowids,
    		mandt, vbeln, posnr, parvw, pernr
    	from ${hana_user}.Vbpa 
    	where "$rowid$" &gt; #{rowids} and parvw = 'VE' ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectTvkbtNew" parameterType="Tvkbt" resultType="Tvkbt">
    	select top 20 "$rowid$" as rowids,
			mandt,spras,vkbur,bezei
    	from ${hana_user}.Tvkbt 
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectAufmNew" parameterType="Aufm" resultType="Aufm">
    	select top 20 "$rowid$" as rowids,
    		mblnr, mjahr, zeile, bldat, budat, bwart, matnr, werks, lgort, 
			charg, sobkz, lifnr, kdauf, kdpos, shkzg, menge, bwtar, aufnr, mandt
    	from ${hana_user}.aufm 
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectVbrkNew" parameterType="Vbrk" resultType="Vbrk">
    	select top 20 "$rowid$" as rowids,
    		vbeln,fkart,waerk,erdat,erzet,zterm,kunrg,bstnk_vf,
			zbillty,zbz01,zbz02,zdc_flg,bukrs,ktgrd,fkdat,inco1,
			inco2,netwr,mwsbk,aedat,mandt
    	from ${hana_user}.Vbrk
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectVbrpNew" parameterType="Vbrp" resultType="Vbrp">
    	select top 20 "$rowid$" as rowids,
    		vbeln,posnr,fkimg,meins,vgbel,vgpos,aubel,aupos,matnr,
			arktx,matkl,spart,zarktx_js,zfkimg_js,zvrkme_js, mandt,netwr,mwsbp
    	from ${hana_user}.Vbrp
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectS066New" parameterType="S066" resultType="S066">
    	select top 20 "$rowid$" as rowids,
    	    mandt, ssour, vrsio, kkber, knkli, spmon, sptag as sptags, spwoc, spbup, oeikw,
    		spwoc as spwocs, spbup as spbups, spmon as spmons
    	from ${hana_user}.S066
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectS067New" parameterType="S067" resultType="S067">
    	select top 20 "$rowid$" as rowids,
    	    mandt, ssour, vrsio, kkber, knkli, spmon, sptag as sptags, spwoc, spbup, olikw, ofakw,
    		spwoc as spwocs, spbup as spbups, spmon as spmons
    	from ${hana_user}.S067
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
	<select id="selectVbukNew" parameterType="Vbuk" resultType="Vbuk">
    	select top 20 "$rowid$" as rowids,
    	    vbeln, wbstk, kostk, mandt
    	from ${hana_user}.vbuk
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectLikpNew" parameterType="Likp" resultType="Likp">
    	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 ${hana_user}.likp
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectKonvNew" parameterType="Konv" resultType="Konv">
    	select top 20 "$rowid$" as rowids,
			mandt,knumv,kposn,stunr,zaehk,kntyp,kbetr
    	from ${hana_user}.konv
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectLipsNew" parameterType="Lips" resultType="Lips">
    	select top 20 "$rowid$" as rowids,
       		vbeln, posnr, vgbel, vgpos, mandt, matnr, matkl, arktx, werks, lgort, 
    		charg, lfimg, uebto, untto, erdat, erzet, aedat
    	from ${hana_user}.lips
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectAfkoNew" parameterType="Afko" resultType="Afko">
    	select top 20 "$rowid$" as rowids,
       		aufnr, mandt, gltrp, gamng, plnbez, gmein, plnnr, plnal, 
    		stlnr, cy_seqnr, gstrp, aufpl, aplzt
    	from ${hana_user}.afko
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectAfpoNew" parameterType="Afpo" resultType="Afpo">
    	select top 20 "$rowid$" as rowids,
       		kdauf, kdpos, aufnr, mandt, posnr, psmng, wemng, meins, matnr, 
    		uebto, untto, pwerk, verid, dwerk, dauat, krsnr, sernr, plnum
    	from ${hana_user}.Afpo
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectVbepNew" parameterType="Vbep" resultType="Vbep">
    	select top 20 "$rowid$" as rowids,
       		vbeln, posnr, edatu, ettyp, wmeng, bmeng, mandt, etenr
    	from ${hana_user}.vbep
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectT023tNew" parameterType="T023t" resultType="T023t">
    	select top 20 "$rowid$" as rowids,
       		mandt,spras,matkl,wgbez,wgbez60
    	from ${hana_user}.T023t
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectKna1New" parameterType="Kna1" resultType="Kna1">
    	select top 20 "$rowid$" as rowids,
       		kunnr, name1, name2, mandt, ktokd
    	from ${hana_user}.Kna1
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectKnvvNew" parameterType="Knvv" resultType="Knvv">
    	select top 20 "$rowid$" as rowids,
       		mandt, kunnr, vkorg, vtweg, spart, waers, klabc
    	from ${hana_user}.Knvv
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectKnkkNew" parameterType="Knkk" resultType="Knkk">
    	select top 20 "$rowid$" as rowids,
       		mandt,kunnr,kkber,klimk,skfor,ssobl,aedat
    	from ${hana_user}.Knkk
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectMaraNew" parameterType="Mara" resultType="Mara">
    	select top 20 "$rowid$" as rowids,
       		matnr, mandt, ersda, ernam, laeda, aenam, vpsta, pstat, mtart, mbrsh, matkl, 
    		bismt, meins, bstme, wrkst, brgew, ntgew, gewei, spart, kzkfg, extwg, cuobf 
    	from ${hana_user}.Mara
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectMaktNew" parameterType="Makt" resultType="Makt">
    	select top 20 "$rowid$" as rowids,
       		matnr, mandt, spras, maktx
    	from ${hana_user}.Makt
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectZsd06New" parameterType="Zsd06" resultType="Zsd06">
    	select top 20 "$rowid$" as rowids,
       		vbeln, posnr, mandt, datum, uname, crt_uname, crt_datum, 
    		crt_time, cha_name, cha_datum, cha_time
    	from ${hana_user}.Zsd_06
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectZmdpcNew" parameterType="Zmdpc" resultType="Zmdpc">
    	select top 20 "$rowid$" as rowids,
       		vbeln,posnr,f_plant,plant,x_plant,mandt
    	from ${hana_user}.Zmdpc
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectVbakNew" parameterType="Vbak" resultType="Vbak">
		select top 20 "$rowid$" as rowids,
			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 ${hana_user}.vbak a 
		left join (
			select q.vbeln,r.pernr from ${hana_user}.vbap q 
				left  join (
					select vbeln,posnr,pernr from ${hana_user}.vbpa where mandt = #{mandt} and pernr != '00000000' group by vbeln,posnr,pernr
				) r on q.vbeln = r.vbeln and q.posnr = r.posnr 
			where q.mandt = #{mandt} and r.pernr is not null
			group by q.vbeln,r.pernr
		) b on a.vbeln = b.vbeln
		where "$rowid$" &gt; #{rowids} and a.mandt = '800'
		order by "$rowid$"
    </select>
    <select id="selectAufkNew" parameterType="Aufk" resultType="Aufk">
    	select top 20 "$rowid$" as rowids,
       		kdauf,kdpos,mandt,aufnr,erdat,erfzeit,ernam,aenam,bukrs,loekz,auart,werks
    	from ${hana_user}.aufk
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectT001wNew" parameterType="T001w" resultType="T001w">
    	select top 20 "$rowid$" as rowids,
       		mandt, werks, name1, bwkey
    	from ${hana_user}.T001w
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectMskaNew" parameterType="Mska" resultType="Mska">
    	select top 20 "$rowid$" as rowids,
       		vbeln, posnr, mandt, matnr, werks, lgort, charg, sobkz, kaspe, kalab
    	from ${hana_user}.Mska
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    <select id="selectZsdfhzlNew" parameterType="Zsdfhzl" resultType="Zsdfhzl">
    	select top 20 "$rowid$" as rowids,
       		vbeln, posnr, mandt, vgbel, vgpos, uname, matnr, fmenge, cdate, ctime, fh_date, werks, cha_datum
    	from ${hana_user}.zsd_fhzl
    	where "$rowid$" &gt; #{rowids} ${hana_mandt}
    	order by "$rowid$"
    </select>
    
    
    <select id="selectAfkoById" parameterType="Afko" resultType="Afko">
    	select
    		aufnr, mandt, gltrp, gamng, plnbez, gmein, plnnr, plnal, 
    		stlnr, cy_seqnr, gstrp, aufpl, aplzt
    	from ${hana_user}.afko where aufnr = #{aufnr} and mandt = #{mandt}
    </select>
	<select id="selectAfpoById" parameterType="Afpo" resultType="Afpo">
    	select 
    		kdauf, kdpos, aufnr, mandt, posnr, psmng, wemng, meins, matnr, 
    		uebto, untto, pwerk, verid, dwerk, dauat, krsnr, sernr, plnum
    	from ${hana_user}.afpo 
    	where aufnr = #{aufnr} and posnr = #{posnr} and mandt = #{mandt}
    </select>
    <select id="selectAufkById" parameterType="Aufk" resultType="Aufk">
    	select kdauf,kdpos,mandt,aufnr,erdat,erfzeit,ernam,aenam,bukrs,loekz,auart,werks
    	from ${hana_user}.aufk 
    	where mandt = #{mandt} and aufnr = #{aufnr}
    </select>
	<select id="selectAufmById" parameterType="Aufm" resultType="Aufm">
    	select 
			mblnr, mjahr, zeile, bldat, budat, bwart, matnr, werks, lgort, 
			charg, sobkz, lifnr, kdauf, kdpos, shkzg, menge, bwtar, aufnr, mandt
    	from ${hana_user}.aufm 
    	where mblnr = #{mblnr} and mandt = #{mandt}  and mjahr = #{mjahr} and zeile = #{zeile}
    </select>
    <select id="selectKna1ById" parameterType="Kna1" resultType="Kna1">
    	select kunnr, name1, name2, mandt, ktokd
    	from ${hana_user}.kna1 
    	where kunnr = #{kunnr} and mandt = #{mandt}
    </select>
	<select id="selectKnkkById" parameterType="Knkk" resultType="Knkk">
    	select mandt,kunnr,kkber,klimk,skfor,ssobl,aedat
    	from ${hana_user}.Knkk 
    	where kunnr = #{kunnr} and kkber = #{kkber} and mandt = #{mandt}
    </select>
	<select id="selectKnvvById" parameterType="Knvv" resultType="Knvv">
    	select mandt, kunnr, vkorg, vtweg, spart, waers, klabc
    	from ${hana_user}.Knvv 
    	where mandt = #{mandt} and kunnr = #{kunnr} and vkorg = #{vkorg} and vtweg = #{vtweg} and spart = #{spart}
    </select>
	<select id="selectKonvById" parameterType="Konv" resultType="Konv">
    	select mandt,knumv,kposn,stunr,zaehk,kntyp,kbetr
    	from ${hana_user}.Konv 
    	where mandt = #{mandt} and knumv = #{knumv} and kposn = #{kposn} and stunr = #{stunr} and zaehk = #{zaehk}
    </select>
   	<select id="selectLikpById" parameterType="Likp" resultType="Likp">
    	select 
    		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 ${hana_user}.likp 
    	where vbeln = #{vbeln} and mandt = #{mandt}
    </select>
	<select id="selectLipsById" parameterType="Lips" resultType="Lips">
    	select 
    		vbeln, posnr, vgbel, vgpos, mandt, matnr, matkl, arktx, werks, lgort, 
    		charg, lfimg, uebto, untto, erdat, erzet, aedat
    	from ${hana_user}.lips 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt}
    </select>
	<select id="selectMaktById" parameterType="Makt" resultType="Makt">
    	select matnr, mandt, spras, maktx from ${hana_user}.makt 
    	where matnr = #{matnr} and mandt = #{mandt} and spras = #{spras}
    </select>
    <select id="selectMaraById" parameterType="Mara" resultType="Mara">
    	select 
    		matnr, mandt, ersda, ernam, laeda, aenam, vpsta, pstat, mtart, mbrsh, matkl, 
    		bismt, meins, bstme, wrkst, brgew, ntgew, gewei, spart, kzkfg, extwg, cuobf 
    	from ${hana_user}.mara 
    	where matnr = #{matnr} and mandt = #{mandt}
    </select>
	<select id="selectMskaById" parameterType="Mska" resultType="Mska">
    	select 
    		vbeln, posnr, mandt, matnr, werks, lgort, charg, sobkz, kaspe, kalab
    	from ${hana_user}.mska 
    	where mandt = #{mandt} and matnr = #{matnr} and werks = #{werks} and lgort = #{lgort} 
			and charg = #{charg} and sobkz = #{sobkz} and vbeln = #{vbeln} and posnr = #{posnr}
    </select>
    <select id="selectPa0002ById" parameterType="Pa0002" resultType="Pa0002">
    	select mandt,pernr,subty,objps,sprps,endda,begda,seqnr,nachn,vorna,aedtm
    	from ${hana_user}.Pa0002 
    	where mandt = #{mandt} and pernr = #{pernr} and subty = #{subty} and objps = #{objps}
			and sprps = #{sprps} and endda = #{endda} and begda = #{begda} and seqnr = #{seqnr}
    </select>
	<select id="selectS066ById" parameterType="S066" resultType="S066">
    	select mandt, ssour, vrsio, kkber, knkli, spmon, sptag as sptags, spwoc, spbup, oeikw,
    		spwoc as spwocs, spbup as spbups, spmon as spmons
    	from ${hana_user}.S066 
    	where mandt = #{mandt} and ssour = #{ssour} and vrsio = #{vrsio} and kkber = #{kkber} and
			knkli = #{knkli} and spmon = #{spmons} and sptag = #{sptags} and spwoc = #{spwocs} and spbup = #{spbups}
    </select>
    <select id="selectS067ById" parameterType="S067" resultType="S067">
    	select mandt, ssour, vrsio, kkber, knkli, spmon, sptag as sptags, spwoc, spbup, olikw, ofakw,
    		spwoc as spwocs, spbup as spbups, spmon as spmons
    	from ${hana_user}.S067
    	where mandt = #{mandt} and ssour = #{ssour} and vrsio = #{vrsio} and kkber = #{kkber} and
			knkli = #{knkli} and spmon = #{spmons} and sptag = #{sptags} and spwoc = #{spwocs} and spbup = #{spbups}
    </select>
    <select id="selectT001wById" parameterType="T001w" resultType="T001w">
    	select mandt, werks, name1, bwkey
    	from ${hana_user}.T001w 
    	where werks = #{werks} and mandt = #{mandt}
    </select>
	<select id="selectT023tById" parameterType="T023t" resultType="T023t">
    	select mandt,spras,matkl,wgbez,wgbez60
    	from ${hana_user}.T023t 
    	where mandt = #{mandt} and spras = #{spras} and matkl = #{matkl}
    </select>
    <select id="selectVbakById" parameterType="Vbak" resultType="Vbak">
		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 ${hana_user}.vbak a 
		left join (
			select q.vbeln,r.pernr from ${hana_user}.vbap q 
				left  join (
					select vbeln,posnr,pernr from ${hana_user}.vbpa where mandt = #{mandt} and pernr != '00000000' group by vbeln,posnr,pernr
				) r on q.vbeln = r.vbeln and q.posnr = r.posnr 
			where q.mandt = #{mandt} and r.pernr is not null
			group by q.vbeln,r.pernr
		) b on a.vbeln = b.vbeln
		where a.vbeln = #{vbeln} and a.mandt = #{mandt}
    </select>
	<select id="selectVbepById" parameterType="Vbep" resultType="Vbep">
    	select vbeln, posnr, edatu, ettyp, wmeng, bmeng, mandt, etenr
    	from ${hana_user}.vbep 
    	where vbeln = #{vbeln} and posnr = #{posnr} and etenr = #{etenr} and mandt = #{mandt}
    </select>
	<select id="selectVbpaById" parameterType="Vbpa" resultType="Vbpa">
    	select mandt, vbeln, posnr, parvw, pernr
    	from ${hana_user}.Vbpa 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt} and parvw = #{parvw}
    </select>
    <select id="selectVbrkById" parameterType="Vbrk" resultType="Vbrk">
    	select 
			vbeln,fkart,waerk,erdat,erzet,zterm,kunrg,bstnk_vf,
			zbillty,zbz01,zbz02,zdc_flg,bukrs,ktgrd,fkdat,inco1,
			inco2,netwr,mwsbk,aedat,mandt
    	from ${hana_user}.Vbrk 
    	where vbeln = #{vbeln} and mandt = #{mandt} 
    </select>
	<select id="selectVbrpById" parameterType="Vbrp" resultType="Vbrp">
    	select vbeln,posnr,fkimg,meins,vgbel,vgpos,aubel,aupos,matnr,
			arktx,matkl,spart,zarktx_js,zfkimg_js,zvrkme_js, mandt,netwr,mwsbp
    	from ${hana_user}.Vbrp 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt} 
    </select>
	<select id="selectVbukById" parameterType="Vbuk" resultType="Vbuk">
    	select vbeln, wbstk, kostk, mandt
    	from ${hana_user}.vbuk 
    	where vbeln = #{vbeln} and mandt = #{mandt}
    </select>
	<select id="selectZmdpcById" parameterType="Zmdpc" resultType="Zmdpc">
    	select vbeln,posnr,f_plant,plant,x_plant,mandt
    	from ${hana_user}.Zmdpc 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt}
    </select>
    <select id="selectZsd06ById" parameterType="Zsd06" resultType="Zsd06">
    	select vbeln, posnr, mandt, datum, uname, crt_uname, crt_datum, 
    	crt_time, cha_name, cha_datum, cha_time
    	from ${hana_user}.zsd_06 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt}
    </select>
    <select id="selectZsdfhzlById" parameterType="Zsdfhzl" resultType="Zsdfhzl">
    	select vbeln, posnr, mandt, vgbel, vgpos, uname, matnr, fmenge, cdate, ctime, fh_date, werks, cha_datum
    	from ${hana_user}.zsd_fhzl 
    	where vbeln = #{vbeln} and posnr = #{posnr} and mandt = #{mandt}
    </select>
	<select id="selectBsidById" parameterType="Bsid" resultType="Bsid">
    	select 
    		a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
   		a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm, b.pernr 
    	from ${hana_user}.Bsid a
    	left join (
			select 
				aa.vbeln, aa.aubel, bb.pernr
			from ${hana_user}.vbrp aa
			left join (
				select vbeln,pernr,posnr from ${hana_user}.vbpa where mandt = #{mandt} and pernr != '00000000' group by vbeln,pernr,posnr
			) bb on aa.aubel = bb.vbeln and aa.aupos = bb.posnr
			where bb.pernr is not null and aa.mandt = #{mandt}
			group by aa.vbeln, aa.aubel, bb.pernr
		) b on a.vbeln = b.vbeln
    	where a.mandt = #{mandt}
			and a.bukrs = #{bukrs} and a.kunnr = #{kunnr} and a.umsks = #{umsks} and a.umskz = #{umskz} 
			and a.augdt = #{augdts} and a.augbl = #{augbl} and a.zuonr = #{zuonr} and a.gjahr = #{gjahr} 
			and a.belnr = #{belnr} and a.buzei = #{buzeis}
    </select>
    <select id="selectBsadById" parameterType="Bsad" resultType="Bsad">
    	select 
    		a.vbeln,a.mandt,a.bukrs,a.kunnr,a.umsks,a.umskz,a.augdt as augdts,a.augbl,a.zuonr,a.gjahr,a.belnr,a.buzei,a.buzei as buzeis,
   		a.blart,a.waers,a.wrbtr,a.shkzg,a.budat as budats,a.zfbdt as zfbdts,a.zterm, b.pernr 
    	from ${hana_user}.Bsad a
    	left join (
			select 
				aa.vbeln, aa.aubel, bb.pernr
			from ${hana_user}.vbrp aa
			left join (
				select vbeln,pernr,posnr from ${hana_user}.vbpa where mandt = #{mandt} and pernr != '00000000' group by vbeln,pernr,posnr
			) bb on aa.aubel = bb.vbeln and aa.aupos = bb.posnr
			where bb.pernr is not null and aa.mandt = #{mandt}
			group by aa.vbeln, aa.aubel, bb.pernr
		) b on a.vbeln = b.vbeln
    	where a.mandt = #{mandt}
			and a.bukrs = #{bukrs} and a.kunnr = #{kunnr} and a.umsks = #{umsks} and a.umskz = #{umskz} 
			and a.augdt = #{augdts} and a.augbl = #{augbl} and a.zuonr = #{zuonr} and a.gjahr = #{gjahr} 
			and a.belnr = #{belnr} and a.buzei = #{buzeis}
    </select>


	<select id="selectVbapById" parameterType="Vbap" resultType="Vbap">
		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>


    <select id="selectTvkbtById" parameterType="Tvkbt" resultType="Tvkbt">
    	select mandt,spras,vkbur,bezei
    	from ${hana_user}.Tvkbt 
		where mandt = #{mandt} and spras = #{spras} and vkbur = #{vkbur}
    </select>
    
</mapper>
