• ABAP 函数编写


    MM模块写了不少报表,发现有很多地方都需要根据物料号和批次获取坯料或者铝箔成品的规格型号,代码很多地方都是重复,并且总体显示代码段偏长不直观,于是决定编写一个函数Z_GET_SPEC_FROM_BATCH.

    1、创建一个和数组Z_MM_GROUP,开发类为ZMM;

    2、创建函数Z_GET_SPEC_FROM_BATCH,代码如下:

      FUNCTION Z_GET_SPEC_FROM_BATCH.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     REFERENCE(P_MATNR) TYPE  MATNR
    *"     REFERENCE(P_CHARG) TYPE  CHARG_D
    *"  EXPORTING
    *"     REFERENCE(P_SPEC) TYPE  C
    *"----------------------------------------------------------------------
      data:
          S_VAL_NUM TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM,
          VAL_NUM LIKE BAPI1003_ALLOC_VALUES_NUM,
          S_VAL_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR.

      call function 'Z_FIG001_GET_CHAR_FROM_BATCH'
            exporting
              P_MATNR           = P_MATNR
              P_CHARG           = P_CHARG
            TABLES
              P_VAL_NUM         = S_VAL_NUM
              P_VAL_CHAR        = S_VAL_CHAR
            exceptions
              no_form            = 1
              no_function_module = 2
              others             = 3.
        if sy-subrc <> 0.
            P_SPEC = ''.
        else.
            datam(16type c,
                  n(16type c.
            loop at S_VAL_NUM into VAL_NUM.
                if VAL_NUM-CHARACT eq 'P0015'.    "宽度
                    CALL FUNCTION 'QSS0_FLTP_TO_CHAR_CONVERSION'
                    EXPORTING
                      I_NUMBER_OF_DIGITS = '2'
                      I_FLTP_VALUE       = VAL_NUM-VALUE_FROM
                    IMPORTING
                      E_CHAR_FIELD       = m.
                elseif VAL_NUM-CHARACT eq 'P0016'.   "厚度
                    CALL FUNCTION 'QSS0_FLTP_TO_CHAR_CONVERSION'
                    EXPORTING
                      I_NUMBER_OF_DIGITS = '2'
                      I_FLTP_VALUE       = VAL_NUM-VALUE_FROM
                    IMPORTING
                      E_CHAR_FIELD       = n.
                endif.
            endloop.
            CONDENSE m.
            CONDENSE n.
            CONCATENATE n '*' m INTO P_SPEC.
        endif.
    ENDFUNCTION.

     

  • 相关阅读:
    pat乙级1034
    getline()读入一整行
    c++ 输入split
    13.缓存、三级缓存、内存溢出、AsyncTask
    12、json、GridView、缓存
    11.webview、shareSDK
    10.下拉刷新、加载更多、标记已读、轮播条、缓存
    9.indicate、xutils、json
    8.滑动事件处理
    7.ViewPagerIndicator
  • 原文地址:https://www.cnblogs.com/tianfu/p/1679024.html
Copyright © 2020-2023  润新知