Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Creating a batch with characteristics

Former Member
0 Likes
8,714

I need to create a batch and include the characteristic values. I've found FM VB_CREATE_BATCH, which includes the segment CHAR_OF_BATCH, but this doesnt appear to allow me to assing values to the characteristics. Does anyone know of a way to do this?

3 REPLIES 3
Read only

Former Member
0 Likes
3,456

Hi,

You need to follow the below steps here.

1. Lock the Material and Plant combination
    CALL FUNCTION 'ENQUEUE_MATERIAL'
      EXPORTING
        matnr          = lv_matnr
        werks          = lv_werks
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.

2. Create Batch by calling BAPI
      CALL FUNCTION 'BAPI_BATCH_CREATE'
        EXPORTING
          material             = lv_matnr
          batch                = lv_charg
          plant                = lv_werks
          batchstoragelocation = lv_lgort
          batchattributes      = lw_batch_attr (here prod_date should be the production date of batch)
        TABLES
          return               = lt_rettab.

3. Create Key
* Fetch Object key by passing Material, Plant and Batch
* Fill Material Number
  lw_object-key_field = 'MATNR'.
  lw_object-value_int = lv_matnr.
  APPEND lw_object TO lt_object.
  CLEAR : lw_object.
 
* Fill Plant
  lw_object-key_field = 'WERKS'.
  lw_object-value_int = lv_werks.
  APPEND lw_object TO lt_object.
  CLEAR : lw_object.
 
* Fill Batch
  lw_object-key_field = 'CHARG'.
  lw_object-value_int = lv_charg.
  APPEND lw_object TO lt_object.
  CLEAR : lw_object.

* Concatenate Object Key
  CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'
    EXPORTING
      objecttable    = 'MCH1'
    IMPORTING
      objectkey_conc = lv_object
    TABLES
      objectkeytable = lt_object
      return         = lt_rettab.

to be continued...

Read only

3,456
4. Fetch Batch Characteristics, these will be empty for new batches
* Fetch object characterstics.
      CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
        EXPORTING
          objectkey        = lv_object
          objecttable      = 'MCH1'
          classnum         = this is class name 'Z_MATERIAL_CHEESE' etc
          classtype        = this is class type '023' etc values
          keydate          = sy-datum
          unvaluated_chars = 'X'
          language         = sy-langu
        TABLES
          allocvaluesnum   = lt_alloc_num
          allocvalueschar  = lt_alloc_char
          allocvaluescurr  = lt_alloc_curr
          return           = lt_rettab.

5. Modify the above num, char and curr internal tables with your values

6. Create Batch characteristics
      CALL FUNCTION 'BAPI_OBJCL_CREATE'
        EXPORTING
          objectkeynew      = lv_object
          objecttable      = 'MCH1'
          classnum         = this is class name 'Z_MATERIAL_CHEESE' etc
          classtype        = this is class type '023' etc values
          keydate          = sy-datum
          no_default_values = 'X'
        TABLES
          allocvaluesnum    = lt_alloc_num
          allocvalueschar   = lt_alloc_char
          allocvaluescurr   = lt_alloc_curr
          return            = lt_rettab.

Go through each of the above mentioned BAPIs documentation and proceed. I followed this way in so many developments. Hope this helps you !!!

Regards,

Ganga

Read only

WenjingLiu
Participant
0 Likes
3,456

Dear Ganga Bhavani Reguri,

I have tried your way. It didn't work. Maybe there is something that I have missed. However, I have tried this one. It worked. http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=195789188

The difference is that yours uses FUNCTION 'BAPI_OBJCL_CONCATENATEKEY' to get object key, while the other one uses FUNCTION 'VB_BATCH_2_CLASS_OBJECT'.

Best regards,

Arwen