drop table vbapadv;
CREATE TABLE vbapadv (
vbeln text,
posnr text,
matnr text,
mandt text,
matkl text,
spart text,
kwmeng numeric(15,3),
netwr numeric(15,2),
mwsbp numeric(13,2),
waerk text,
vrkme text,
abgru text,
uebto numeric(3,1),
untto numeric(3,1),
werks text,
vstel text,
mvgr1 text,
plavo text,
mvgr4 text,
mvgr5 text,
ulxh text,
zma_ftb_02 text, 
zma_ftb_03 text, 
zma_ftb_45 text, 
zma_ftb_06 text, 
zma_ftb_07 text, 
zma_ftb_08 text, 
zma_jyb_02 text, 
zma_jyb_03 text, 
zma_jyb_45 text, 
zma_jyb_06 text, 
zma_jyb_07 text, 
zma_ljb_03 text, 
zma_ljb_04 text, 
zma_ljb_06 text, 
zma_ljb_07 text, 
zma_ljb_08 text, 
zma_ljb_11 text, 
zma_ljb_12 text, 
zma_ljb_13 text, 
zma_yhbg_02 text, 
zma_yhbg_04 text, 
zma_yhbg_05 text, 
zma_yhbg_06 text, 
tbpz text,
ws text,
cu_maktx text,
cu_pcdst text,
ztype text,
barcode text,
gdno text,
lh text,
dgxx text,
zklx text,
erdat text,
erzet text,
erdat1 date,
erdat2 timestamp,

--aufk
aufk_kdauf text,
aufk_kdpos text,
aufk_mandt text,
aufk_aufnr text,
aufk_erdat text,
aufk_erfzeit text,
aufk_ernam text,
aufk_aenam text,
aufk_bukrs text,
aufk_erdat1 date,
aufk_erdat2 timestamp,

--SalesContractProcess
scp_id text, 
scp_xiaoShouDDBH text,
scp_xuFangGSID text,
scp_xuFangGS text,
scp_gongFangGSt text,
scp_xiaoShouBMt text,
scp_shouHuoGSID text,
scp_shouHuoGS text,
scp_fuKuanTJt text,
scp_caiGouDDBH text,
scp_dangQianXYED text,
scp_yvQiK text,
scp_dengJi text,
scp_biZhongt text,
scp_yongJin text,
scp_zongHeMLL text,
scp_sysProcessname text,
scp_sysIncident integer,

--mara
mara_matnr text,
mara_mandt text,
mara_ersda text,
mara_ernam text,
mara_laeda text,
mara_aenam text,
mara_vpsta text,
mara_pstat text,
mara_mtart text,
mara_mbrsh text,
mara_matkl text,
mara_bismt text,
mara_meins text,
mara_bstme text,
mara_wrkst text,
mara_brgew text,
mara_ntgew text,
mara_gewei text,
mara_spart text,
mara_kzkfg text,
mara_extwg text,
mara_cuobf text,
mara_ersda1 date,
mara_laeda1 date,

--makt
makt_matnr text,
makt_mandt text,
makt_spras text,
makt_maktx text,

--zsd06
zsd06_vbeln text,
zsd06_posnr text,
zsd06_mandt text,
zsd06_datum text,
zsd06_uname text,
zsd06_include text,
zsd06_crt_uname text,
zsd06_crt_datum text,
zsd06_crt_time text,
zsd06_cha_name text,
zsd06_cha_datum text,
zsd06_cha_time text,
zsd06_datum1 date,
zsd06_crt_datum1 timestamp,
zsd06_cha_datum1 timestamp,

--vbak
vbak_vbeln text,
vbak_mandt text,
vbak_vbtyp text,
vbak_audat text,
vbak_waerk text,
vbak_kalsm text,
vbak_ctlpc text,
vbak_kunnr text,
vbak_bukrs_vf text,
vbak_bstnk text,
vbak_bname text,
vbak_telf1 text,
vbak_netwr numeric(15,2),
vbak_vkbur text ,
vbak_audat1 date,
vbak_knumv text,
vbak_vkorg text,

--likp
likp_vbeln	 text,
likp_mandt	 text,
likp_erdat	 text,
likp_wadat_ist text,
likp_ctlpc	 text,
likp_kunnr	 text,
likp_erdat1 date,
likp_wadat_ist1 date,

--handover
handover_vbeln text,
handover_task_id text,
handover_handover_id text,
handover_handover_type integer,
handover_order_type integer,
handover_task_no text,
handover_sale_no text,
handover_delivery_type integer,
handover_handover_state integer,
handover_f_plant text,
handover_plant text,
handover_customer_id integer,
handover_customer_name text,
handover_fmenge integer,
handover_delivery_num integer,
handover_port integer,
handover_piect_total integer,
handover_total_net_weight numeric(11,0),
handover_weight_total numeric(9,2),
handover_settlement_weight numeric(9,2),
handover_weight_state integer,
handover_vrkme text,
handover_average_freight numeric(9,2),
handover_order_remark text,
handover_delivery_time timestamp,
handover_erdat timestamp,
handover_plan_product_time timestamp,
handover_open_ready_time timestamp,
handover_already_ready_time timestamp,
handover_appearance_time timestamp,
handover_sign_time timestamp,
handover_edatu timestamp,
handover_area_no text,
handover_area_name text,
handover_fmenge_time timestamp,
handover_klabc text,
handover_sales_man text,
handover_sales_department text,
handover_is_valid integer,
handover_created_user_id text,
handover_created_time timestamp,
handover_modified_user_id text,
handover_modified_time timestamp,
handover_remark text,
handover_is_auto_created integer,
handover_delivery_state text,
handover_operate_tag integer,
handover_transport_time integer,
handover_is_date_success integer,
handover_is_num_success integer,
handover_is_sign_success integer,
handover_weighing_weight numeric(9,2),
handover_delivery_issued_time timestamp,

--SysSAPreturnNo
ssspn_id integer,
ssspn_processName text,
ssspn_shiLiH integer,
ssspn_sapNo text,
ssspn_chuangJianSJ timestamp,

--zmdpc
zmdpc_vbeln text,
zmdpc_posnr text,
zmdpc_f_plant text,
zmdpc_plant text,
zmdpc_x_plant text,
zmdpc_mandt text,

--vbpa
vbpa_mandt text,
vbpa_vbeln text,
vbpa_posnr text,
vbpa_parvw text,
vbpa_pernr text,

kpsj date,
htsl numeric(15,3),
pssj date,
jhsj date,
pcsj date,
rksj date,
ccsj timestamp,
pcsl numeric(15,3),
rksl numeric(15,3), 
jhsl numeric(15,3),
ccsl numeric(15,3),
kpsl numeric(15,3),
wlsj timestamp,
PRIMARY KEY (vbeln, posnr, mandt, erdat1)
) 
Distributed by (vbeln, posnr, mandt, erdat1)
partition by range(erdat1)
(start (date '2015-01-01') inclusive
end (date '2030-01-01') exclusive
every (interval '1 month')
);

alter table vbapadv add column kna1_kunnr text;
alter table vbapadv add column kna1_name1 text;
alter table vbapadv add column kna1_name2 text;
alter table vbapadv add column kna1_mandt text;

alter table vbapadv add column t023t_mandt text;
alter table vbapadv add column t023t_spras text;
alter table vbapadv add column t023t_matkl text;
alter table vbapadv add column t023t_wgbez text;
alter table vbapadv add column t023t_wgbez60 text;

alter table vbapadv add column netpr numeric(11,2);

alter table vbapadv add column makt_maktxSize text;

alter table vbapadv add column scp_ziShiYBv text;

alter table vbapadv add column vbak_vtweg text;
alter table vbapadv add column vbak_kkber text;
alter table vbapadv add column vbak_auart text;

alter table vbapadv add column aedat text;

alter table vbapadv drop column vbpa_mandt;
alter table vbapadv drop column vbpa_vbeln;
alter table vbapadv drop column vbpa_posnr;
alter table vbapadv drop column vbpa_parvw;
alter table vbapadv drop column vbpa_pernr;
alter table vbapadv add column pernr text;

alter table vbapadv add column aufk_auart text;
alter table vbapadv add column aufk_werks text;

