//TYPE TABLE OF = TYEP STANDARD TABLE OF
//意思是定义一个内表itab_add,内表的结构是跟类型t_address是一致的.
//也就是说:将来内表itab_add的每条记录都有no和street这两个字段.
DATA: it_rgk TYPE TABLE OF /BIC/AZSDG_RGK00, //(像工作区)it_rgk 的结构体与表 /BIC/AZSDG_RGK00 一致
wa_rgk TYPE /BIC/AZSDG_RGK00. //定义存放BU代表的内表TYPE 表
SELECT all INTO TABLE it_rgk FROM /BIC/AZSDG_RGK00
FOR ALL ENTRIES IN RESULT_PACKAGE //for all entries in 所有输入
WHERE /BIC/ZSD_CUSTM = RESULT_PACKAGE-/BIC/ZSD_CUSTM.
SORT it_rgk BY /BIC/ZSD_CUSTM DIVISION /BIC/ZECD_PPBM. // 将it_rgk内按照三个字段排序
LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELEDS> .
DATA: zmdm_bun TYPE /BIC/OIZMDM_BUN, //定义两个字段
zsd_mager TYPE /BIC/OIZSD_MAGER.
CLEAR zmdm_bun. //清空两个字段
CLEAR zsd_mager.
SELECT SINGLE /BIC/ZMDM_BUN
FROM /BIO/PDIVISION
INTO zmdm_bun
WHERE DIVISION = <RESULT_FIELEDS>-DIVISION.
SELECT SINGLE /BIC/ZSD_MAGER
FROM /BIC/AZSD_O6900
INTO zsd_mager
WHERE /bic/zmdm_bun = zmdm_bun and
/bic/zgvs_gm = <result_fields>-/bic/zgvs_gm and
/bic/zsd_store = <result_fields>-/BIC/ZSD_STORE.
IF zsd_mager <> ''. //如果字段中不为空也就是select语句已经添加进去了的时候执行
<RESULT_FIELEDS>-/BIC/ZSD_MAGER = zsd_mager.
ENDIF.
取网格
DATA: wa_wg TYPE /BIC/AZSD_WGDZ00. //定义一个存放网格的内表
SELECT SINGLE ALL
INTO wa_wg
FROM /BIC/AZSD_WGDZ00
WHERE /bic/zsd_cust = <result_fields>-/bic/zsd_cust.
IF SY-SUBRC = 0. // 如果select条件执行的话
<result_fields>-/bic/zsd_wg = wa_wg-/bic/zsd_wg. //将内表中的数据放在
<result_fields>-/bic/zsd_wgxw = wa_wg-/bic/zsd_wgxw .
<result_fields>-/bic/zsd_wgz = wa_wg-/bic/zsd_wgz.
ENDIF
取BU代表
READ TABLE it_rgk INTO wa_rgk //READ TABLE 语句读取内部表it_rgk的数据到工作区(结构体)wa_rgk
WITH KEY /BIC/ZSD_CUSTM = <RESULT_FIELDS>-/BIC/ZSD_CUSTM // WITH KEY 匹配内表的数据与数据源里面的数据一样的
DIVISION = <RESULT_FIELDS>-DIVISION
/BIC/ZECD_PPBM = <RESULT_FIELDS>-/BIC/Zecd_PPBM //WITH KEY 子句在READ语句中指定搜索键,而不是表键
BINARY SEARCH // BINARY SEARCH (二分法)
IF SY-SUBRC = 0.
<RESULT_FIELDS>-/BIC/ZBUJL_CO = wa_rgk-/BIC/ZBUJL_CO.
ELSE.
CLEAR wa_rgk.
READ TABLE it_rgk INTO wa_rgk
WITH KEY /BIC/ZSD_CUSTM = <RESULT_FIELDS>-/BIC/ZSD_CUSTM
DIVISION = <RESULT_FIELDS>-DIVISION
BINARY SEARCH.
<RESULT_FIELDS>-/BIC/ZBUJL_CO = wa_rgk-/BIC/ZBUJL_CO.
ENDIF.
ENDLOOP