22年写的一个客户主数据报表,里面最近一次SO创建时间,查这个运行很慢。如不需要,可以去掉此栏位。
用到的表:
kna1, knb1,knvp客户主记录伙伴功能,
knvv客户主记录销售数据,
knkk客户主数据信贷管理: 控制范围数据,
bnka银行主记录
,t171t,tvzbt,tbrct,t016t.
************************************************************************
* Program Name : ZCSDR_133
* Descriptions : 客户主数据报表
* Updates Tables :
* Input Parameters :
* Output Parameters :
* Return Codes :
* Special Logic :
* Includes :
************************************************************************
* Modification Log
************************************************************************
* Date Ver. Programmer Descriptions
* ---------- ---- ------------ -----------------------------------------
* 20220810 new created
************************************************************************
REPORT zcsdr_133 NO STANDARD PAGE HEADING
MESSAGE-ID 00 LINE-SIZE 100 LINE-COUNT 65.
************************************************************************
* Tables Definitions
************************************************************************
TABLES: kna1, knb1,knvp, knvv,knkk,bnka,t171t,tvzbt,tbrct,t016t,zctsd141.
TYPE-POOLS: slis.
************************************************************************
* Data Definitions
************************************************************************
TYPES: BEGIN OF ty_show,
kunnr TYPE kna1-kunnr,"客户
name1 TYPE kna1-name1,"客户名称
vkorg TYPE knvv-vkorg,"销售组织
vtweg TYPE knvv-vtweg,"分销渠道
spart TYPE knvv-spart,"产品组
mcod1 TYPE kna1-mcod1,"名称1
mcod2 TYPE kna1-mcod2,"名称2
* sort1 TYPE zagl_cust_main-sort1,"简称
sort1 TYPE kna1-sortl, "简称
parvw_t1(20) TYPE c,"母公司
stceg TYPE kna1-stceg,"税务登记号
landx TYPE t005t-landx,"国家名称
land1 TYPE kna1-land1,"国家代码
ort01 TYPE kna1-ort01,"城市
regio TYPE kna1-regio,"地区
street TYPE adrc-street,"注册地址
ktokd TYPE kna1-ktokd,"客户类型
ktokd_t(20) TYPE c,"客户类型 :账户组的文本
ernam TYPE kna1-ernam,"创建者
erdat TYPE kna1-erdat,"创建时间
zdate1 TYPE zctsd141-zdate1,"agile扩展日期 new modify、:不要时间只要日期
* ztime1 TYPE zctsd141-ztime1,"agile扩展时间
zdate2 TYPE zctsd141-zdate2,"agile最后一次修改日期
* ztime2 TYPE zctsd141-ztime2,"agile最后一次修改时间 new modify、:不要时间只要日期
bzirk TYPE knvv-bzirk,"销售地区
bztxt TYPE t171t-bztxt,"销售地区描述
text3(20) TYPE c,"销售代表
inco1 TYPE knvv-inco1,"国际贸易条款(部分1)
inco2 TYPE knvv-inco2,"国际贸易条款(部分2)
waers TYPE knvv-waers,"币别
zterm TYPE knvv-zterm,"付款条件代码
vtext TYPE tvzbt-vtext,"付款条件描述
vsbed TYPE knvv-vsbed,"装运条件
brsch TYPE kna1-brsch,"行业代码
brtxt TYPE t016t-brtxt,"行业描述
* cassd TYPE knvv-cassd,"冻结(僵尸)
aufsd TYPE knvv-aufsd,"冻结(Y/N)
klimk TYPE knkk-klimk,"授信额度(美金)
banka TYPE bnka-banka,"银行名称
bankl TYPE bnka-bankl,"银行代码
swift TYPE bnka-swift,"银行Swift代码
bankn TYPE knbk-bankn,"银行账号
zdate TYPE zctsd141-zdate1,"最近一次创建SO日期
ktgrd TYPE knvv-ktgrd,"账户分配组
ctlpc TYPE knkk-ctlpc,"SAP风险等级控制
kkber TYPE knkk-kkber,"贷方控制范围
taxkd TYPE knvi-taxkd,"税分类
akont TYPE knb1-akont,"统驭科目
vwerk TYPE knvv-vwerk,"交货工厂
zcsr TYPE kna1-name1,"CSR
zaglname TYPE zagl_kna1-zaglname, " 客户注册英文全名(Agile回传)
zbu TYPE zagl_kna1_ldc-zbu," BU(Agile回传)
box TYPE c,
END OF ty_show.
TYPES: BEGIN OF ty_knvv ,
kunnr TYPE knvv-kunnr,"客户
vkorg TYPE knvv-vkorg,"销售组织
vtweg TYPE knvv-vtweg,"分销渠道
spart TYPE knvv-spart,"产品组
bzirk TYPE knvv-bzirk,"销售地区
inco1 TYPE knvv-inco1,"国际贸易条款(部分1)
inco2 TYPE knvv-inco2,"国际贸易条款(部分2)
waers TYPE knvv-waers,"币别
zterm TYPE knvv-zterm,"付款条件代码
vsbed TYPE knvv-vsbed,"装运条件
* cassd TYPE knvv-cassd,"冻结(僵尸)
aufsd TYPE knvv-aufsd,"冻结(Y/N)
bukrs TYPE knb1-bukrs,"公司代码
zwels TYPE knb1-zwels,"付款方式
ernam TYPE knvv-ernam,"创建者
erdat TYPE knvv-erdat,"创建日期
ktgrd TYPE knvv-ktgrd,"账户分配组
akont TYPE knb1-akont,"统驭科目
vwerk TYPE knvv-vwerk,"交货工厂
END OF ty_knvv.
TYPES: BEGIN OF ty_kna1 ,
kunnr TYPE kna1-kunnr,"客户
name1 TYPE kna1-name1,"客户名称
stceg TYPE kna1-stceg,"税务登记号
land1 TYPE kna1-land1,"国家代码
mcod1 TYPE kna1-mcod1,"名称1
mcod2 TYPE kna1-mcod2,"名称2
ort01 TYPE kna1-ort01,"城市
regio TYPE kna1-regio,"地区
brsch TYPE kna1-brsch,"行业代码
ktokd TYPE kna1-ktokd,"账户组
adrnr TYPE kna1-adrnr,"地址号
sort1 TYPE kna1-sortl,"简称
END OF ty_kna1.
TYPES: BEGIN OF ty_bnka ,
banka TYPE bnka-banka,"银行名称
bankl TYPE bnka-bankl,"银行代码
swift TYPE bnka-swift,"银行Swift代码
END OF ty_bnka.
TYPES: BEGIN OF ty_knbk ,
kunnr TYPE knbk-kunnr,"客户代码
banks TYPE knbk-banks,"银行国家
bankl TYPE knbk-bankl,"银行代码
bankn TYPE knbk-bankn,"银行账户
END OF ty_knbk.
TYPES: BEGIN OF ty_knvp ,
kunnr TYPE knvp-kunnr,"客户代码
vkorg TYPE knvp-vkorg,"销售组织
vtweg TYPE knvp-vtweg,"分销渠道
spart TYPE knvp-spart,"产品组
parvw TYPE knvp-parvw,"合作伙伴功能
parza TYPE knvp-parza,"合作伙伴计数器
kunn2 TYPE knvp-kunn2,"客户
lifnr TYPE knvp-lifnr,"供应商
END OF ty_knvp.
TYPES: BEGIN OF ty_zagl_cust_main ,
kunnr TYPE zagl_cust_main-kunnr,"客户代码
erdat TYPE zagl_cust_main-erdat,"创建时间
times TYPE zagl_cust_main-times,"记录的创建时间
* sort1 TYPE zagl_cust_main-sort1,"简称
END OF ty_zagl_cust_main.
TYPES: BEGIN OF ty_knkk ,
kunnr TYPE knkk-kunnr,
kkber TYPE knkk-kkber,"贷方控制范围
klimk TYPE knkk-klimk,"信贷限额
ctlpc TYPE knkk-ctlpc,"SAP风险等级控制
waers TYPE t014-waers,"货币
END OF ty_knkk .
TYPES: BEGIN OF ty_adrc ,
addrnumber TYPE adrc-addrnumber,"地址号
street TYPE adrc-street,"街道
END OF ty_adrc .
*TYPES: BEGIN OF ty_vbak , "
* vbeln TYPE vbak-vbeln,"销售凭证
* erdat TYPE vbak-erdat,"SO创建日期
* vkorg TYPE vbak-vkorg,"销售组织
* vtweg TYPE vbak-vtweg,"分销渠道
* spart TYPE vbak-spart,"产品组
* kunnr TYPE vbak-kunnr,"售达方
*END OF ty_vbak .
TYPES: BEGIN OF ty_vbak , "
vbeln TYPE vbak-vbeln,"销售凭证
erdat TYPE vbak-erdat,"SO创建日期
vkorg TYPE vbak-vkorg,"销售组织
kunnr TYPE vbpa-kunnr,"客户
END OF ty_vbak .
TYPES:BEGIN OF ty_knvi , "
kunnr TYPE knvi-kunnr,"客户
aland TYPE knvi-aland,"国家
tatyp TYPE knvi-tatyp,"税收类别
taxkd TYPE knvi-taxkd,"税分类
END OF ty_knvi.
TYPES:BEGIN OF ty_t001 , "
bukrs TYPE t001-bukrs,"公司代码
land1 TYPE t001-land1,"国家
END OF ty_t001.
TYPES:BEGIN OF ty_zagl_cust_ldc,"
kunnr TYPE zagl_cust_ldc-kunnr,"客户
erdat TYPE zagl_cust_ldc-erdat,"创建日期
times TYPE zagl_cust_ldc-times,"记录的创建时间
bukrs TYPE zagl_cust_ldc-bukrs,"公司代码
vkorg TYPE zagl_cust_ldc-vkorg,"销售组织
vtweg TYPE zagl_cust_ldc-vtweg,"分销渠道
spart TYPE zagl_cust_ldc-spart,"产品组
kkber TYPE zagl_cust_ldc-kkber,"贷方控制范围
klimk TYPE zagl_cust_ldc-klimk,"信贷限额
systype TYPE zagl_cust_ldc-systype,"信息类型
END OF ty_zagl_cust_ldc.
TYPES:BEGIN OF ty_zagl_kna1,"
kunnr TYPE zagl_kna1-kunnr,
zaglname TYPE zagl_kna1-zaglname,"客户注册英文全名(Agile回传)
END OF ty_zagl_kna1.
TYPES:BEGIN OF ty_zagl_kna1_ldc,"
kunnr TYPE zagl_kna1_ldc-kunnr,
vkorg TYPE zagl_kna1_ldc-vkorg,
vtweg TYPE zagl_kna1_ldc-vtweg,
spart TYPE zagl_kna1_ldc-spart,
zbu TYPE zagl_kna1_ldc-zbu,"BU(Agile回传)
END OF ty_zagl_kna1_ldc.
*----------------------------------------------------------------------*
* 内表定义
*----------------------------------------------------------------------*
DATA: t_show TYPE STANDARD TABLE OF ty_show ,
w_show TYPE ty_show.
DATA:
t_kna1 TYPE STANDARD TABLE OF ty_kna1 ,
t_kna11 TYPE STANDARD TABLE OF ty_kna1 ,
w_kna1 TYPE ty_kna1.
*DATA: t_kna1_1 TYPE STANDARD TABLE OF ty_kna1 ,
* w_kna1_1 TYPE ty_kna1.
DATA: t_knvv TYPE STANDARD TABLE OF ty_knvv ,
t_knvv1 TYPE STANDARD TABLE OF ty_knvv ,
w_knvv TYPE ty_knvv.
DATA: t_bnka TYPE STANDARD TABLE OF ty_bnka ,
w_bnka TYPE ty_bnka.
DATA: t_knbk TYPE STANDARD TABLE OF ty_knbk ,
w_knbk TYPE ty_knbk.
DATA: t_knvp TYPE STANDARD TABLE OF ty_knvp ,
w_knvp TYPE ty_knvp.
DATA: t_zagl_cust_main TYPE STANDARD TABLE OF ty_zagl_cust_main ,
w_zagl_cust_main TYPE ty_zagl_cust_main.
DATA: t_zagl_kna1 TYPE STANDARD TABLE OF ty_zagl_kna1 ,"
w_zagl_kna1 TYPE ty_zagl_kna1.
DATA: t_zagl_kna1_ldc TYPE STANDARD TABLE OF ty_zagl_kna1_ldc ,"
w_zagl_kna1_ldc TYPE ty_zagl_kna1_ldc.
DATA: t_knkk TYPE STANDARD TABLE OF ty_knkk ,
w_knkk TYPE ty_knkk.
DATA: t_adrc TYPE STANDARD TABLE OF ty_adrc ,
w_adrc TYPE ty_adrc.
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak , "
w_vbak TYPE ty_vbak.
DATA: t_knvi TYPE STANDARD TABLE OF ty_knvi , "
w_knvi TYPE ty_knvi.
DATA: t_t001 TYPE STANDARD TABLE OF ty_t001 , "
w_t001 TYPE ty_t001.
DATA: t_zagl_cust_ldc TYPE STANDARD TABLE OF ty_zagl_cust_ldc , "
w_zagl_cust_ldc TYPE ty_zagl_cust_ldc.
DATA: t_t016t TYPE TABLE OF t016t.
DATA: w_t016t TYPE t016t.
DATA: t_tvzbt TYPE TABLE OF tvzbt.
DATA: w_tvzbt TYPE tvzbt.
DATA: t_t005t TYPE TABLE OF t005t.
DATA: w_t005t TYPE t005t.
DATA: t_tpart TYPE TABLE OF tpart.
DATA: w_tpart TYPE tpart.
DATA: t_t077x TYPE TABLE OF t077x.
DATA: w_t077x TYPE t077x.
DATA: t_zctsd141_1 TYPE TABLE OF zctsd141.
DATA: w_zctsd141_1 TYPE zctsd141.
DATA: t_zctsd141_zcsr TYPE TABLE OF zctsd141.
DATA: w_zctsd141_zcsr TYPE zctsd141.
DATA: t_zctsd141_2 TYPE TABLE OF zctsd141.
DATA: w_zctsd141_2 TYPE zctsd141.
DATA: t_t171t TYPE TABLE OF t171t.
DATA: w_t171t TYPE t171t.
*----------------------------------------------------------------------*
* 变量定义
*----------------------------------------------------------------------*
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gs_layout TYPE slis_layout_alv,
gs_print TYPE slis_print_alv, "ALV打印格式
g_repid LIKE sy-repid.
DATA: v_stru_disvar TYPE disvariant, "ALV 显示格式
it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE, "ALV 排序内表
git_events TYPE slis_t_event, "ALV 事件
git_listheader TYPE slis_t_listheader. "ALV 表头
DATA l_tmp TYPE lvc_title.
*END OF ALV
CONSTANTS cns_pf_status TYPE slis_formname VALUE 'ALV_PF_STATUS'.
CONSTANTS cns_user_command TYPE slis_formname VALUE 'ALV_USER_COMMAND'.
*----------------------------------------------------------------------*
* 宏定义
*----------------------------------------------------------------------*
DEFINE def_fieldcat.
clear gt_fieldcat.
gt_fieldcat-fieldname = &1.
gt_fieldcat-reptext_ddic = &2.
gt_fieldcat-no_zero = &3.
append gt_fieldcat.
END-OF-DEFINITION.
***********************************************************************
* Selection Screen
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr ,"客户
s_vkorg FOR knvv-vkorg ,"销售组织
s_bukrs FOR knb1-bukrs ,"公司代码
s_ktokd FOR kna1-ktokd ,"账户组
* s_idnrk FOR marc-matnr ,"客户类型
s_erdat FOR kna1-erdat ,"创建时间
s_zdate1 FOR zctsd141-zdate1 ,"agile扩展时间
* s_cassd FOR knvv-cassd ,"销售冻结
s_aufsd FOR knvv-aufsd ,"销售冻结
s_zwels FOR knb1-zwels ,"付款方式
s_text3 FOR kna1-name1"销售代表
.
SELECTION-SCREEN END OF BLOCK b1 .
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02 .
PARAMETERS : p_1 TYPE c AS CHECKBOX."
SELECTION-SCREEN END OF BLOCK b2 .
************************************************************************
* Includes Module
************************************************************************
************************************************************************
* Initialization
************************************************************************
INITIALIZATION.
DATA:ls_date TYPE sy-datum.
ls_date = sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = ls_date
days = 0
months = 0
signum = '-'
years = 5
IMPORTING
calc_date = ls_date.
************************************************************************
* At Selection Screen Output
************************************************************************
************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN.
AT USER-COMMAND.
AT LINE-SELECTION.
************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.
END-OF-PAGE.
************************************************************************
* Main Process
************************************************************************
START-OF-SELECTION.
PERFORM check_purview.
PERFORM frm_get_data.
IF t_show[] IS NOT INITIAL.
PERFORM frm_alv_show.
ELSE.
MESSAGE '没有符合的数据,请重新查询!' TYPE 'S' DISPLAY LIKE 'E' .
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_data .
IF s_bukrs IS NOT INITIAL."
CLEAR s_vkorg.
MOVE s_bukrs TO s_vkorg.
APPEND s_vkorg."必须要,不然值赋不上去
ENDIF.
SELECT knvv~kunnr "客户
vkorg "销售组织
vtweg "分销渠道
spart "产品组
bzirk "销售地区
inco1 "国际贸易条款(部分1)
inco2 "国际贸易条款(部分2)
waers "币别
knvv~zterm "付款条件代码
vsbed "装运条件
* cassd "冻结(僵尸)
aufsd "冻结(Y/N)
bukrs "公司代码
zwels "付款方式
knvv~ernam"创建者
knvv~erdat "创建日期
knvv~ktgrd"账户分配组
knb1~akont"统驭科目
knvv~vwerk"交货工厂
INTO TABLE t_knvv
FROM knvv
JOIN knb1 ON knvv~kunnr = knb1~kunnr
AND knvv~vkorg = knb1~bukrs
WHERE knvv~kunnr IN s_kunnr
AND vkorg IN s_vkorg
* AND cassd IN s_cassd "冻结(僵尸)
AND aufsd IN s_aufsd "冻结(Y/N)
AND knvv~erdat IN s_erdat "创建日期
AND zwels IN s_zwels ."付款方式
SORT t_knvv BY kunnr vkorg spart.
IF t_knvv[] IS NOT INITIAL.
SELECT kunnr "客户
name1 "客户名称
stceg "税务登记号
land1 "国家代码
mcod1 "名称1
mcod2 "名称2
ort01 "城市
regio "地区
brsch "行业代码
ktokd "账户组
adrnr "地址号
sortl
INTO TABLE t_kna1
FROM kna1
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr
AND ktokd IN s_ktokd. "账户组
SELECT kunnr "客户
erdat "创建日期
times "记录的创建时间
bukrs "公司代码
vkorg "销售组织
vtweg "分销渠道
spart "产品组
kkber "贷方控制范围
klimk "信贷限额
systype "信息类型
INTO TABLE t_zagl_cust_ldc
FROM zagl_cust_ldc
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr
AND vkorg = t_knvv-vkorg
AND vtweg = t_knvv-vtweg
AND spart = t_knvv-spart
AND systype = 'S' .
* DELETE ADJACENT DUPLICATES FROM t_zagl_cust_ldc COMPARING KUNNR VKORG VTWEG SPART.
SORT t_zagl_cust_ldc DESCENDING BY kunnr vkorg vtweg spart erdat times.
SELECT kunnr
banks
bankl
bankn
INTO TABLE t_knbk
FROM knbk
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr
.
SORT t_knbk BY kunnr .
SELECT banka
bankl
swift
INTO TABLE t_bnka
FROM bnka
FOR ALL ENTRIES IN t_knbk
WHERE banks = t_knbk-banks
AND bankl = t_knbk-bankl.
SORT t_bnka BY bankl.
ENDIF.
"行业描述
SELECT * FROM t016t INTO TABLE t_t016t.
"付款条件描述
SELECT * FROM tvzbt INTO TABLE t_tvzbt.
"国家名称
SELECT * FROM t005t INTO TABLE t_t005t.
"帐户组名
SELECT * FROM t077x INTO TABLE t_t077x.
"销售地区描述
SELECT * FROM t171t INTO TABLE t_t171t.
"客户主记录伙伴功能 SP:售达方 SH:送达方
SELECT kunnr
vkorg
vtweg
spart
parvw"合作伙伴功能
parza
kunn2
lifnr
INTO TABLE t_knvp
FROM knvp
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr.
SORT t_knvp BY kunnr vkorg vtweg spart.
"合作伙伴功能: 文本
SELECT * FROM tpart INTO TABLE t_tpart.
"检索项:简称
SELECT kunnr erdat times
* sort1 "改取主数据
* zaglname "客户注册英文全名(Agile回传)
FROM zagl_cust_main
INTO TABLE t_zagl_cust_main
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr.
"倒序
SORT t_zagl_cust_main DESCENDING BY kunnr erdat times .
"zaglname 改成取ZAGL_KNA1 的
SELECT kunnr zaglname INTO TABLE t_zagl_kna1
FROM zagl_kna1
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr.
"zbu 取ZAGL_KNA1_LDC
SELECT kunnr vkorg vtweg spart zbu INTO TABLE t_zagl_kna1_ldc
FROM zagl_kna1_ldc
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr.
"信贷限额
SELECT knkk~kunnr
knkk~kkber
knkk~klimk
knkk~ctlpc "风险类别
t014~waers "货币
INTO TABLE t_knkk
FROM knkk
JOIN t014 ON knkk~kkber = t014~kkber
FOR ALL entries IN t_knvv
WHERE knkk~kunnr = t_knvv-kunnr
AND knkk~kkber = t_knvv-vkorg.
SORT t_knkk BY kunnr kkber.
"地址
SELECT addrnumber
street
INTO TABLE t_adrc
FROM adrc
FOR ALL ENTRIES IN t_kna1
WHERE addrnumber = t_kna1-adrnr.
SORT t_adrc BY addrnumber.
"扩展时间
SELECT *
FROM zctsd141
INTO TABLE t_zctsd141_1
WHERE zdate1 IN s_zdate1
AND zagltype = 'CTRQ'.
SORT t_zctsd141_1 DESCENDING BY kunnr vkorg zdate1 ztime1.
"最后一次修改时间时间
SELECT *
FROM zctsd141
INTO TABLE t_zctsd141_2
WHERE zdate1 IN s_zdate1
AND zagltype IN ('CTCM','CTCD','CTMM').
SORT t_zctsd141_2 DESCENDING BY kunnr vkorg zdate2 ztime2.
* "获取CSR信息
* select *
* from zctsd141
* into table t_zctsd141_zcsr.
* sort t_zctsd141_zcsr descending by kunnr vkorg zdate2 ztime2.
"获取 “税分类”
SELECT kunnr
aland
tatyp
taxkd
FROM knvi
INTO TABLE t_knvi
FOR ALL ENTRIES IN t_knvv
WHERE kunnr = t_knvv-kunnr
.
"获取 国家 20220929 原因:xd03上的销售区域数据的国家是根据t001表取得
SELECT bukrs
land1
FROM t001
INTO TABLE t_t001
FOR ALL ENTRIES IN t_knvv
WHERE bukrs = t_knvv-vkorg.
"客户最近一次创建SO日期
t_knvv1[] = t_knvv[].
DELETE ADJACENT DUPLICATES FROM t_knvv1 COMPARING kunnr .
SELECT vbak~vbeln erdat vkorg vbpa~kunnr
INTO TABLE t_vbak
FROM vbak
JOIN vbpa ON vbak~vbeln = vbpa~vbeln
FOR ALL entries IN t_knvv1
WHERE vbpa~kunnr = t_knvv1-kunnr
AND vbpa~parvw IN ('AG','WE')"售达方&送达方
.
SORT t_vbak BY kunnr vkorg erdat DESCENDING.
DELETE ADJACENT DUPLICATES FROM t_vbak COMPARING kunnr vkorg erdat .
"客户最近一次创建SO日期
"减少内表数量
* IF p_1 = 'X'."当勾选时只查客户类型为售达方的数据
* PERFORM get_cust_zombie."获取5年内未下过so的僵尸客户数据
*
* LOOP AT t_knvv INTO w_knvv.
* READ TABLE t_vbak1 INTO w_vbak1 WITH KEY kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg
* vtweg = w_knvv-vtweg spart = w_knvv-spart.
* IF sy-subrc = 0.
* ENDIF.
* ENDLOOP.
* ENDIF.
* SELECT vbeln erdat vkorg vtweg spart kunnr
* FROM vbak
* INTO TABLE t_vbak
* FOR ALL ENTRIES IN t_knvv
* WHERE vkorg = t_knvv-vkorg
* AND vtweg = t_knvv-vtweg
* AND spart = t_knvv-spart
* AND kunnr = t_knvv-kunnr.
* SORT t_vbak BY kunnr vkorg vtweg spart erdat DESCENDING.
* DELETE ADJACENT DUPLICATES FROM t_vbak COMPARING vkorg vtweg spart kunnr.
LOOP AT t_knvv INTO w_knvv.
w_show-kunnr = w_knvv-kunnr."客户
"简称
* READ TABLE t_zagl_cust_main INTO w_zagl_cust_main
* WITH KEY kunnr = w_knvv-kunnr BINARY SEARCH.
READ TABLE t_zagl_cust_main INTO w_zagl_cust_main "
WITH KEY kunnr = w_knvv-kunnr.
* IF sy-subrc = 0.
* w_show-sort1 = w_zagl_cust_main-sort1. "改取主数据,注释掉这个
* w_show-zaglname = w_zagl_cust_main-zaglname."客户注册英文全名(Agile回传)
* ENDIF.
READ TABLE t_zagl_kna1 INTO w_zagl_kna1
WITH KEY kunnr = w_knvv-kunnr .
IF sy-subrc = 0.
w_show-zaglname = w_zagl_kna1-zaglname."客户注册英文全名(Agile回传)
ENDIF.
w_show-vkorg = w_knvv-vkorg."销售组织
w_show-vtweg = w_knvv-vtweg."分销渠道
w_show-spart = w_knvv-spart."产品组
w_show-bzirk = w_knvv-bzirk."销售地区
"销售地区描述
READ TABLE t_t171t INTO w_t171t WITH KEY bzirk = w_knvv-bzirk spras = sy-langu .
IF sy-subrc = 0.
w_show-bztxt = w_t171t-bztxt."
ENDIF.
w_show-inco1 = w_knvv-inco1."国际贸易条款(部分1)
w_show-inco2 = w_knvv-inco2."国际贸易条款(部分2)
w_show-waers = w_knvv-waers."币别
w_show-zterm = w_knvv-zterm."付款条件代码
"付款条件描述
READ TABLE t_tvzbt INTO w_tvzbt WITH KEY zterm = w_show-zterm spras = sy-langu .
IF sy-subrc = 0.
w_show-vtext = w_tvzbt-vtext."
ENDIF.
w_show-vsbed = w_knvv-vsbed."装运条件
* w_show-cassd = w_knvv-cassd."冻结(僵尸)
w_show-aufsd = w_knvv-aufsd."冻结(Y/N)
IF w_show-aufsd = '01'.
w_show-aufsd = 'Y'.
ELSEIF w_show-aufsd = ''.
w_show-aufsd = 'N'.
ENDIF.
* w_show-bukrs = w_knvv-bukrs."公司代码
* w_show-zwels = w_knvv-zwels."付款方式
w_show-ernam = w_knvv-ernam."创建者
w_show-erdat = w_knvv-erdat."创建日期
w_show-ktgrd = w_knvv-ktgrd."账户分配组
w_show-akont = w_knvv-akont."统驭科目
w_show-vwerk = w_knvv-vwerk."交货工厂
* w_show-zcsr = w_zctsd141_zcsr.
READ TABLE t_kna1 INTO w_kna1 WITH KEY kunnr = w_knvv-kunnr BINARY SEARCH.
IF sy-subrc = 0.
w_show-name1 = w_kna1-name1."客户名称
w_show-land1 = w_kna1-land1."国家代码
w_show-stceg = w_kna1-stceg."税务登记号
w_show-sort1 = w_kna1-sort1."简称
"国家名称
READ TABLE t_t005t INTO w_t005t WITH KEY land1 = w_show-land1 spras = sy-langu .
IF sy-subrc = 0.
w_show-landx = w_t005t-landx."国家名称
ENDIF.
w_show-mcod1 = w_kna1-mcod1."名称1
w_show-mcod2 = w_kna1-mcod2."名称2
w_show-ort01 = w_kna1-ort01."城市
w_show-regio = w_kna1-regio."地区
w_show-brsch = w_kna1-brsch."行业代码
"行业描述
READ TABLE t_t016t INTO w_t016t WITH KEY brsch = w_show-brsch spras = sy-langu .
IF sy-subrc = 0.
w_show-brtxt = w_t016t-brtxt."行业描述
ENDIF.
"客户类型
w_show-ktokd = w_kna1-ktokd.
"客户类型描述 :通过 账户组来判断
READ TABLE t_t077x INTO w_t077x WITH KEY ktokd = w_kna1-ktokd spras = sy-langu .
IF sy-subrc = 0.
w_show-ktokd_t = w_t077x-txt30.
ENDIF.
ENDIF.
"银行数据
READ TABLE t_knbk INTO w_knbk WITH KEY kunnr = w_show-kunnr BINARY SEARCH.
IF sy-subrc = 0.
w_show-bankl = w_knbk-bankl.
w_show-bankn = w_knbk-bankn.
READ TABLE t_bnka INTO w_bnka WITH KEY bankl = w_knbk-bankl BINARY SEARCH.
IF sy-subrc = 0.
w_show-banka = w_bnka-banka.
w_show-swift = w_bnka-swift.
* w_show-BNKLZ = w_bnka-BNKLZ.
ENDIF.
ENDIF.
"合作伙伴功能 Z3:母公司
READ TABLE t_knvp INTO w_knvp WITH KEY kunnr = w_knvv-kunnr parvw = 'Z3' BINARY SEARCH.
IF sy-subrc = 0.
w_show-parvw_t1 = w_knvp-kunn2.
ENDIF.
"合作伙伴功能 Z4:销售代表
READ TABLE t_knvp INTO w_knvp WITH KEY kunnr = w_knvv-kunnr parvw = 'Z4'
vkorg = w_knvv-vkorg"销售组织
vtweg = w_knvv-vtweg"分销渠道
spart = w_knvv-spart"产品组
.
IF sy-subrc = 0.
DATA :ls_name1 TYPE kna1-name1.
SELECT SINGLE name1 INTO ls_name1 FROM kna1 WHERE kunnr = w_knvp-kunn2 .
IF sy-subrc = 0.
w_show-text3 = ls_name1.
ENDIF.
ENDIF.
"合作伙伴功能 Z8:CSR
READ TABLE t_knvp INTO w_knvp WITH KEY kunnr = w_knvv-kunnr parvw = 'Z8'
vkorg = w_knvv-vkorg"销售组织
vtweg = w_knvv-vtweg"分销渠道
spart = w_knvv-spart"产品组
.
IF sy-subrc = 0.
DATA :ls_name2 TYPE kna1-name1.
SELECT SINGLE name1 INTO ls_name2 FROM kna1 WHERE kunnr = w_knvp-kunn2 .
IF sy-subrc = 0.
w_show-zcsr = ls_name2.
ENDIF.
ENDIF.
"信贷限额
READ TABLE t_knkk INTO w_knkk WITH KEY kunnr = w_knvv-kunnr kkber = w_knvv-vkorg BINARY SEARCH.
IF sy-subrc = 0.
w_show-klimk = w_knkk-klimk.
"将货币不为USD的全部改为取ZAGL_CUST_LDC表
IF w_knkk-waers <> 'USD'.
READ TABLE t_zagl_cust_ldc INTO w_zagl_cust_ldc WITH KEY kunnr = w_knvv-kunnr kkber = w_knkk-kkber.
IF sy-subrc = 0.
w_show-klimk = w_zagl_cust_ldc-klimk.
ENDIF.
ENDIF.
w_show-ctlpc = w_knkk-ctlpc."SAP风险等级控制
w_show-kkber = w_knkk-kkber."贷方控制范围
ENDIF.
"地址
READ TABLE t_adrc INTO w_adrc WITH KEY addrnumber = w_kna1-adrnr BINARY SEARCH.
IF sy-subrc = 0.
w_show-street = w_adrc-street.
ENDIF.
"agile创建日期
READ TABLE t_zctsd141_1 INTO w_zctsd141_1 WITH KEY kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg .
IF sy-subrc = 0.
w_show-zdate1 = w_zctsd141_1-zdate1.
* w_show-ztime1 = w_zctsd141_1-ztime1.
ENDIF.
* "CSR
* read table t_zctsd141_zcsr into w_zctsd141_zcsr with key kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg .
* if sy-subrc = 0.
* w_show-zcsr = w_zctsd141_zcsr-zcsr.
*
* endif.
* w_show-zcsr = w_zctsd141_1-zcsr.
"agile最后一次修改日期
READ TABLE t_zctsd141_2 INTO w_zctsd141_2 WITH KEY kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg .
IF sy-subrc = 0.
w_show-zdate2 = w_zctsd141_2-zdate2.
* w_show-ztime2 = w_zctsd141_2-ztime2.
ENDIF.
"客户最近一次创建SO的日期
READ TABLE t_vbak INTO w_vbak WITH KEY kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg
.
IF sy-subrc = 0.
w_show-zdate = w_vbak-erdat.
ENDIF.
"税分类
"1.先取t001表的国家
READ TABLE t_t001 INTO w_t001 WITH KEY bukrs = w_knvv-vkorg.
IF sy-subrc = 0.
"2.再根据客户 和 t001表的国家 取knvi的 税分类
READ TABLE t_knvi INTO w_knvi WITH KEY kunnr = w_knvv-kunnr aland = w_t001-land1 .
IF sy-subrc = 0.
w_show-taxkd = w_knvi-taxkd.
ENDIF.
ENDIF.
"BU(Agile回传)
READ TABLE t_zagl_kna1_ldc INTO w_zagl_kna1_ldc WITH KEY kunnr = w_knvv-kunnr vkorg = w_knvv-vkorg
vtweg = w_knvv-vtweg spart = w_knvv-spart.
IF sy-subrc = 0.
w_show-zbu = w_zagl_kna1_ldc-zbu.
ENDIF.
APPEND w_show TO t_show.
DELETE t_show WHERE ktokd NOT IN s_ktokd.
DELETE t_show WHERE text3 NOT IN s_text3.
DELETE t_show WHERE zdate1 NOT IN s_zdate1.
CLEAR:w_show.
ENDLOOP.
IF p_1 = 'X'."当选中只显示5年及以上未创建SO的客户
DELETE t_show WHERE zdate > ls_date."不显示5年以内创建过so的客户
* DELETE t_show WHERE ktokd <> 'Z001'.
ENDIF.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_ALV_SHOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_alv_show .
PERFORM init_layout.
PERFORM init_fieldcat.
PERFORM frm_output.
ENDFORM. " FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*& Form INIT_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_layout .
gs_layout-detail_popup = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-f2code = 'ETA'.
gs_layout-box_fieldname = 'BOX'.
gs_layout-zebra = 'X'.
ENDFORM. " INIT_LAYOUT
*&---------------------------------------------------------------------*
*& Form INIT_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_fieldcat .
REFRESH gt_fieldcat[].
def_fieldcat 'KUNNR' text-001 '' ."客户
def_fieldcat 'NAME1' text-002 '' ."客户注册中文全名
def_fieldcat 'ZAGLNAME' text-048 '' ."客户注册英文全名
def_fieldcat 'VKORG' text-003 '' ."销售组织
def_fieldcat 'VTWEG' text-004 '' ."分销渠道
def_fieldcat 'SPART' text-005 '' ."产品组
def_fieldcat 'MCOD1' text-006 '' ."名称1
def_fieldcat 'MCOD2' text-007 '' ."名称2
def_fieldcat 'SORT1' text-008 '' ."简称
def_fieldcat 'PARVW_T1' text-009 '' ."母公司
def_fieldcat 'STCEG' text-010 '' ."税务登记号
def_fieldcat 'LANDX' text-011 '' ."国家
def_fieldcat 'LAND1' text-012 '' ."国家代码
def_fieldcat 'ORT01' text-013 '' ."城市
def_fieldcat 'REGIO' text-014 '' ."地区
def_fieldcat 'STREET' text-015 '' ."注册地址
def_fieldcat 'KTOKD_T' text-016 '' ."客户类型
def_fieldcat 'ERNAM' text-017 '' ."创建者
def_fieldcat 'ERDAT' text-018 '' ."创建日期
def_fieldcat 'ZDATE1' text-019 '' ."Agile扩展日期
* def_fieldcat 'ZTIME1' text-038 '' ."Agile扩展时间
def_fieldcat 'ZDATE2' text-020 '' ."Agile最后一次修改日期
* def_fieldcat 'ZTIME2' text-039 '' ."Agile最后一次修改时间
def_fieldcat 'BZIRK' text-021 '' ."销售地区
def_fieldcat 'BZTXT' text-022 '' ."销售地区
def_fieldcat 'TEXT3' text-023 '' ."销售代表
def_fieldcat 'INCO1' text-024 '' ."国际贸易条款(部分1)
def_fieldcat 'INCO2' text-025 '' ."国际贸易条款(部分2)
def_fieldcat 'WAERS' text-026 '' ."币别
def_fieldcat 'ZTERM' text-027 '' ."付款条件代码
def_fieldcat 'VTEXT' text-028 '' ."付款条件描述
def_fieldcat 'VSBED' text-029 '' ."装运条件
def_fieldcat 'BRSCH' text-030 '' ."行业代码
def_fieldcat 'BRTXT' text-031 '' ."行业描述
* def_fieldcat 'CASSD' text-032 '' ."冻结(僵尸)
def_fieldcat 'AUFSD' text-032 '' ."冻结(Y/N)
def_fieldcat 'KLIMK' text-033 '' ."授信额度(美金)
def_fieldcat 'BANKA' text-034 '' ."银行名称
def_fieldcat 'BANKL' text-035 '' ."银行代码
def_fieldcat 'SWIFT' text-036 '' ."银行Swift代码
def_fieldcat 'BANKN' text-037 '' ."银行帐号
def_fieldcat 'ZDATE' text-040 '' ."最近一次创建SO日期
def_fieldcat 'KTGRD' text-041 '' ."账户分配组
def_fieldcat 'CTLPC' text-042 '' ."SAP风险等级控制
def_fieldcat 'KKBER' text-043 '' ."信用额度维护工厂
def_fieldcat 'TAXKD' text-044 '' ."税分类
def_fieldcat 'AKONT' text-045 '' ."统驭科目
def_fieldcat 'VWERK' text-046 '' ."交货工厂
def_fieldcat 'ZCSR' text-047 '' . "CSR
def_fieldcat 'ZBU' text-049 '' . "BU
ENDFORM. " INIT_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_output .
g_repid = syst-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
* i_callback_pf_status_set = cns_pf_status
* i_callback_user_command = cns_user_command
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_save = 'X'
is_variant = v_stru_disvar
it_events = git_events[]
it_sort = it_sort[]
is_print = gs_print
TABLES
t_outtab = t_show "I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " FRM_OUTPUT
*&---------------------------------------------------------------------*
*& Form CHECK_PURVIEW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_purview .
*******************权限检查 20130503
ENDFORM. " CHECK_PURVIEW