美文网首页
ABAP range创建

ABAP range创建

作者: 林之禾 | 来源:发表于2019-03-26 13:39 被阅读0次
    DATA:gv_bwart1  TYPE string VALUE '201/202/543/544/551/552/Z03/Z04/Z05/Z06/Z11/Z12/Z15/Z16/',
         gv_bwart2  TYPE string VALUE '311/312/301/302/', "库存地点、生产领料
         gv_bwart3  TYPE string VALUE '201/202/551/552/Z03/Z04/Z11/Z12/Z15/Z16', "成本中心
         gv_bwart4  TYPE string VALUE '543/544/', "供应商、委外消耗
         gv_bwart5  TYPE string VALUE 'Z05/Z06/', "内部订单、研发领料
         gv_bwart6  TYPE string VALUE '201/202/', "部门消耗
         gv_bwart7  TYPE string VALUE '551/552/', "库存报废
         gv_bwart8  TYPE string VALUE 'Z03/Z04/', "机台领料
         gv_bwart9  TYPE string VALUE 'Z11/Z12/', "试模领料
         gv_bwart10 TYPE string VALUE 'Z15/Z16/'. "模具报废
    
    RANGES:gr_bwart1  FOR mseg-bwart,"'201/202/543/544/551/552/Z03/Z04/Z05/Z06/Z11/Z12/Z15/Z16',
           gr_bwart2  FOR mseg-bwart,"'311/312/301/302/', "库存地点、生产领料
           gr_bwart3  FOR mseg-bwart,"'201/202/551/552/Z03/Z04/Z11/Z12/Z15/Z16/', "成本中心
           gr_bwart4  FOR mseg-bwart,"'543/544/', "供应商、委外消耗
           gr_bwart5  FOR mseg-bwart,"'Z05/Z06/', "内部订单、研发领料
           gr_bwart6  FOR mseg-bwart,"'201/202/', "部门消耗
           gr_bwart7  FOR mseg-bwart,"'551/552/', "库存报废
           gr_bwart8  FOR mseg-bwart,"'Z03/Z04/', "机台领料
           gr_bwart9  FOR mseg-bwart,"'Z11/Z12/'. "试模领料
           gr_bwart10 FOR mseg-bwart,"'Z15/Z16/'. "模具报废
           gr_lgort FOR mseg-lgort.
    
    在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.
    
    
    
    

    相关文章

      网友评论

          本文标题:ABAP range创建

          本文链接:https://www.haomeiwen.com/subject/rmegvqtx.html