在SAP中,有时候需要把单值的结构变成区间的结构,也就是类似SELECTION-OPTION的功能,SAP提供了RANGES来实现该功能. (SAP 中SELECTION-OPTION 是个很强大的功能,在程序中也经常需要类似SELECTION-OPTION的功能,如果不画屏幕的话,SAP提供了RANGE来实现该功能) 实例如下: DATA: table_t LIKE TABLE OF spfli, table_wa LIKE spfli. RANGES:g_ranges FOR spfli-carrid. *"单值 *CLEAR G_ranges[]. *G_ranges-sign = 'I'. *G_ranges-option = 'EQ'. *G_ranges-low = 'AA'. *APPEND G_ranges. "区间 CLEAR g_ranges[]. g_ranges-sign = 'I'. g_ranges-option = 'BT'. g_ranges-low = 'AA'. g_ranges-high = 'HH'. APPEND g_ranges. SELECT * FROM spfli INTO TABLE table_t WHERE carrid IN g_ranges. LOOP AT table_t INTO table_wa. WRITE : / table_wa-carrid,table_wa-connid,table_wa-cityto. ENDLOOP. 此时G_ranges就相当于SELECTION-OPTION定义的类型。 *选项介绍: *1.SIGN 值为 I 和E。I是包含, E是排除, 一般使用I。 *2.OPTION 如果HIGH 为空 ,为单值选择 。有EQ、NE、GT、LE、LT等逻辑操作 对于*的CP包含 NP是排除 * 如果HIGH 不为空 为区间选择 有BT,NB可选 *3.LOW 低值 *4.HIGH 高值
image.png
image.png
获取范围例子 FORM frm_get_ranges . DATA:iv_conkey TYPE ze_conkey. [图片上传中...(image.png-a32e52-1553579561580-0)] RANGES:lr_conkey FOR zxx_enm_config-conkey1. REFRESH:gr_lgort. gr_lgort-sign = 'I'. gr_lgort-option = 'CP'. gr_lgort-low = '6*'. APPEND gr_lgort. CLEAR:gr_lgort. "1、201/202/543/544/551/552/Z03/Z04/Z05/Z06/Z11/Z12/Z15/Z16/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart1. iv_conkey = gv_bwart1. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart1[] = lr_conkey[]. "2、311/312/301/302/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart2. iv_conkey = gv_bwart2. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart2[] = lr_conkey[]. "3、201/202/551/552/Z03/Z04/Z11/Z12/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart3. iv_conkey = gv_bwart3. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart3[] = lr_conkey[]. "4、543/544/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart4. iv_conkey = gv_bwart4. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart4[] = lr_conkey[]. "5、Z05/Z06/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart5. iv_conkey = gv_bwart5. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart5[] = lr_conkey[]. "6、201/202/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart6. iv_conkey = gv_bwart6. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart6[] = lr_conkey[]. "7、551/552/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart7. iv_conkey = gv_bwart7. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart7[] = lr_conkey[]. "8、Z03/Z04/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart8. iv_conkey = gv_bwart9. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart8[] = lr_conkey[]. "9、Z11/Z12/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart9. iv_conkey = gv_bwart9. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart9[] = lr_conkey[]. "10、Z15/Z16/ CLEAR:iv_conkey. REFRESH:lr_conkey,gr_bwart10. iv_conkey = gv_bwart10. CALL FUNCTION 'Z_SPLIT_CHAR_TAB' EXPORTING iv_conkey = iv_conkey TABLES gr_conkey = lr_conkey. gr_bwart10[] = lr_conkey[]. ENDFORM.