写代码时经常遇到一些两个字段拼接起来取连另外一个表的情况,比如MSEG表物料凭证号+年关联BKPF的AWKEY 字段是mseg~MBLNR + mseg~mjahr = BKPF~AWKEY。这时候普通的连表会提示长度不一致的问题我们可以用下面的方法连表
SELECT mseg~bukrs ,
mseg~lifnr ,
mseg~shkzg ,
mseg~ebeln ,
mseg~ebelp ,
mseg~ERFMG AS menge ,
mseg~dmbtr ,
BKPF~WAERS ,
BKPF~KURSF
FROM mseg
LEFT JOIN BKPF ON ( CONCAT( mseg~MBLNR , mseg~mjahr ) ) = BKPF~AWKEY
WHERE mseg~bukrs IN @s_bukrs
AND mseg~lifnr IN @s_lifnr
AND mseg~mjahr IN @s_mjahr
AND mseg~budat_mkpf IN @lr_budat
AND mseg~bwart IN ('101','102','161','162')
INTO TABLE @gt_mseg.