Saturday, November 21, 2015

Function Module of Characteristics

Use this FM below to read Characteristics.
Note :
if you want to get the characteristics from MSC1N / MSC2N, just fill objecttable with 'MCH1' otherwise fill with 'MARA' for Material Master
You can fill v_object manually with :
v_object(18) -> Material Code
v_object+18 -> Batch ( if read from MSC1N / MSC2N )
or use this FM 

call function 'BAPI_OBJCL_CONCATENATEKEY'
      exporting
        objecttable    v_objecttable
      importing
        objectkey_conc v_objectkey
      tables
        objectkeytable t_objectkey
        return         t_ret. 


call function 'CLAF_CLASSIFICATION_OF_OBJECTS'
    exporting
      class              v_classnum
      classtype          '023'
      object             v_object
      objecttable        'MCH1'
      initial_charact    ''
    tables
      t_class            t_class
      t_objectdata       t_objectdata
    exceptions
      no_classification  1
      no_classtypes      2
      invalid_class_type 3
      others             4.
  if sy-subrc <> 0.
  endif.

Use this FM below to Get Characteristic Name and Type

call function 'BAPI_CLASS_GET_CHARACTERISTICS'
      exporting
        classnum        v_classnum
        classtype       v_classtype
      importing
        return          v_ret1
      tables
        characteristics t_charact
        char_values     t_charval. 


Use this FM below to convert Characteristics Name to Number

call function 'CONVERSION_EXIT_ATINN_INPUT'
          exporting
            input        t_charact-name_char
         importing
           output        v_atinn.


Use this FM below to read Characteristics from Variant Configuration
Note :
You can fill v_instance with VBAP-CUOBJ 

  call function 'VC_I_GET_CONFIGURATION'
    exporting
      instance            v_instance
      iv_no_dialog        'X'
    tables
      configuration       t_config
    exceptions
      instance_not_found  1
      internal_error      2
      no_class_allocation 3
      instance_not_valid  4
      others              5.
  if sy-subrc <> 0.

  endif.  


Use this FM below to save characteristics value


clear t_alloc_char1.
      t_alloc_char1-charact t_charact-name_char.
      t_alloc_char1-charact_descr t_charact-descr_char
      t_alloc_char1-value_char t_objectdata-ausp1.
      append t_alloc_char1.  


clear t_alloc_num1.
      t_alloc_num1-charact t_charact-name_char.
      t_alloc_num1-unit_from t_charact-unit.
      t_alloc_num1-unit_from_iso t_charact-base_uom_iso.
      t_alloc_num1-value_relation 1.
      t_alloc_num1-charact_descr t_charact-descr_char
      t_alloc_num1-value_from t_objectdata-atflv.
      append t_alloc_num1.  


Note :

          if cabn-atson 'X'"Additional Values is ticked
            if cabn-atein eq ''"Multiple Values is ticked.
              split <fs> at ',' into table t_value.
              loop at t_value.
                t_alloc_char1-value_char t_value-atwrt.
                append t_alloc_char1.
              endloop.
              if v_subrc 4.
                exit.
              endif.
            elseif cabn-atein 'X'"Single Values is ticked
              clear t_value-atwrt.
              t_value-atwrt <fs>.
              t_alloc_char1-value_char t_value-atwrt.
              append t_alloc_char1.
            endif.
          else.
            if cabn-atein eq ''"Multiple Values is ticked.
              split <fs> at ',' into table t_value.
              loop at t_value.
                if t_cawn[] is not initial.
                  clear t_cawn.
                  read table t_cawn with key atwrt t_value-atwrt.
                  if sy-subrc ne 0.
                    concatenate 'Value not Allowed'
                    t_charact-name_char
                    t_charact-descr_char
                    into t_itab-remark separated by space.
                    t_itab-status v_ret-type.
                    v_subrc 4.
                    exit.
                  else.
                    t_alloc_char1-value_char t_value-atwrt.
                    append t_alloc_char1.
                  endif.
                else.
                  t_alloc_char1-value_char t_value-atwrt.
                  append t_alloc_char1.
                endif.
              endloop.
              if v_subrc 4.
                exit.
              endif.
            elseif cabn-atein 'X'"Single Values is ticked
              clear t_value-atwrt.
              t_value-atwrt <fs>.
              if t_cawn[] is not initial.
                clear t_cawn.
                read table t_cawn with key atwrt t_value-atwrt.
                if sy-subrc ne 0.
                  concatenate 'Value not Allowed'
                  t_charact-name_char
                  t_charact-descr_char
                  into t_itab-remark separated by space.
                  t_itab-status v_ret-type.
                  v_subrc 4.
                  exit.
                else.
                  t_alloc_char1-value_char t_value-atwrt.
                  append t_alloc_char1.
                endif.
              else.
                t_alloc_char1-value_char t_value-atwrt.
                append t_alloc_char1.
              endif.
            endif.
          endif. 

 

refresh t_alloc.
    clear t_alloc.
    t_alloc-class_type v_classtype.
    t_alloc-objectkey v_objectkey.
    t_alloc-classnum v_classnum.
    t_alloc-objecttable v_objecttable.
    append t_alloc.


call function 'BAPI_BATCH_SAVE_REPLICA'
        exporting
          material            v_matnr
          batch               v_batch
          plant               v_werks
*          batchattributes     = v_batch_attrib
*          batchattributesx    = v_batch_attribx
*         BATCHSTATUS         =
*         BATCHSTATUSX        =
*         BATCHCONTROLFIELDS  =
*         BATCHSTORAGELOCATION       =
*         INTERNALNUMBERCOM   =
*         EXTENSION1          =
*         MATERIAL_EVG        =
        tables
          return              t_ret
          classallocations    t_alloc
          classvaluationschar t_alloc_char1
          classvaluationscurr t_alloc_curr1
          classvaluationsnum  t_alloc_num1.  

No comments:

Post a Comment