使用BAPI修改Material Master Data的Classification

BAPI :

BAPI_OBJCL_GETDETAIL  读取Classification

BAPI_OBJCL_CHANGE    修改Classification

如果Material Master data的Classification不存在,则在创建新的classification之后,

需要更新mara中  pstat ,vpsta 字段,将‘C‘ 添加到该字符串之后。

CONCATENATE wa_mara-pstat 'C' INTO wa_mara-pstat.
CONCATENATE wa_mara-vpsta 'C' INTO wa_mara-vpsta.

DATA :wa_class_char LIKE bapi1003_alloc_values_char,"Alphanumeric Values
         wa_class_curr LIKE bapi1003_alloc_values_curr,"Currency Values
         wa_class_err LIKE bapiret2."Error Messages
         i_class_num LIKE TABLE OF wa_class_plmd,
         i_class_char LIKE TABLE OF wa_class_char,
         i_class_curr LIKE TABLE OF wa_class_curr,
         i_class_err LIKE TABLE OF wa_class_err.

*'C'表示classification
FIND 'C' IN wa_mara-vpsta.

IF sy-subrc <> 0.
      CONCATENATE wa_mara-pstat 'C' INTO wa_mara-pstat.
      CONCATENATE wa_mara-vpsta 'C' INTO wa_mara-vpsta.
ELSE.
*读取classification的信息
  CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
        EXPORTING
          objectkey              = g_objectkey
          objecttable            = 'MARA'
          classnum               = 'MATL_INFO'
          classtype              = '001'
*       KEYDATE                 = SY-DATUM
*       UNVALUATED_CHARS       = ' '
*       LANGUAGE               = SY-LANGU
*     IMPORTING
*       STATUS                 =
*       STANDARDCLASS          =
        TABLES
          allocvaluesnum         = i_class_num
          allocvalueschar        = i_class_char
          allocvaluescurr        = i_class_curr
          return                 = i_class_err
                .
ENDIF.
*------------------------------------------------------*
*
*修改或新增 classification
*
*------------------------------------------------------*
*更新Classification
 CALL FUNCTION 'BAPI_OBJCL_CHANGE'
    EXPORTING
      objectkey                = g_objectkey
      objecttable              = 'MARA'
      classnum                 = 'MATL_INFO'
      classtype                = '001'
*   STATUS                   = '1'
*   STANDARDCLASS            =
*   CHANGENUMBER             =
*   KEYDATE                  = SY-DATUM
*   NO_DEFAULT_VALUES        = ' '
* IMPORTING
*   CLASSIF_STATUS           =
    TABLES
      allocvaluesnumnew        = i_class_num
      allocvaluescharnew       = i_class_char
      allocvaluescurrnew       = i_class_curr
      return                   = i_class_err
            .
    READ TABLE i_class_err INTO wa_class_err  WITH KEY type = 'E'.
    IF syst-subrc = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ELSE.
  ELSE.
*****UPDATE MARA TBALE***********
    UPDATE mara FROM wa_mara.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  ENDIF.

 

 

posted on 2012-05-17 11:30  T_BUG  阅读(2609)  评论(0编辑  收藏  举报