Skip to Content
avatar image
Former Member

BAPI_BATCH_CREATE

Hi,

I have to create batches to materials and also have to pass the object characteristics. I tried using the BATCHCONTROLFIELDS importing parameter for passing the object characteristics but was not successful. Can some one help me??

Thanks.

Mohan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Apr 04, 2006 at 01:13 PM

    hey mohan,

    u can check out this thread

    this is also the similar thread i think

    bapibatchcreate

    Regards

    naveen

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 04, 2006 at 01:31 PM

    Hai Mohan,

    Here is a sample code for the use of this BAPI. Check if this helps -

    ----


    • Report ZTESTBAPI *

    • This is a dummy program designed to show how to create a batch and *

    • then apply/change characteristics via BAPI control. *

    ----


    REPORT ztestbapi.

    TABLES: klah, ksml, cabn.

    • holds data for charcateristics with type NUM

    DATA: BEGIN OF numtab OCCURS 0.

    INCLUDE STRUCTURE bapi1003_alloc_values_num.

    DATA: END OF numtab.

    • holds data for charcateristics with type CHAR/DATE

    DATA: BEGIN OF chatab OCCURS 0.

    INCLUDE STRUCTURE bapi1003_alloc_values_char.

    DATA: END OF chatab.

    • holds data for charcateristics with type CURR

    DATA: BEGIN OF curtab OCCURS 0.

    INCLUDE STRUCTURE bapi1003_alloc_values_curr.

    DATA: END OF curtab.

    • Error return table

    DATA: BEGIN OF rettab OCCURS 0.

    INCLUDE STRUCTURE bapiret2.

    DATA: END OF rettab.

    DATA: BEGIN OF it_ksml OCCURS 0.

    INCLUDE STRUCTURE ksml.

    DATA: END OF it_ksml.

    • characteristic names

    DATA: BEGIN OF it_cabn OCCURS 0,

    atinn LIKE cabn-atinn,

    atnam LIKE cabn-atnam,

    atfor LIKE cabn-atfor,

    END OF it_cabn.

    DATA: BEGIN OF it_object OCCURS 0.

    INCLUDE STRUCTURE bapi1003_object_keys.

    DATA: END OF it_object.

    • example of an object key 00000000000730000007505847897897

    DATA: w_object LIKE bapi1003_key-object.

    • Change these defaults to suit your system

    PARAMETERS: p_matnr LIKE mara-matnr OBLIGATORY DEFAULT '7300000',

    p_werks LIKE t001w-werks OBLIGATORY DEFAULT '0750',

    p_charg LIKE mcha-charg OBLIGATORY DEFAULT '5847897898',

    p_lgort LIKE dfbatch-lgort OBLIGATORY DEFAULT '1000',

    p_klart LIKE klah-klart OBLIGATORY DEFAULT '022',

    p_class LIKE klah-class OBLIGATORY DEFAULT 'RETREAD'.

    INITIALIZATION.

    PERFORM get_characteristics.

    START-OF-SELECTION.

    PERFORM create_batch.

    PERFORM bapi_commit.

    PERFORM build_object_key.

    PERFORM extract_original_batch.

    END-OF-SELECTION.

    PERFORM update_original_batch.

    PERFORM bapi_commit.

    ----


    • FORM get_characteristics *

    ----


    FORM get_characteristics.

    • extract the characteristic names for KLART/CLASS

    CLEAR: klah, ksml, it_cabn.

    REFRESH it_cabn.

    SELECT SINGLE clint FROM klah

    INTO CORRESPONDING FIELDS OF klah

    WHERE klart = p_klart

    AND class = p_class.

    IF syst-subrc = 0.

    SELECT * FROM ksml

    INTO CORRESPONDING FIELDS OF ksml

    WHERE clint = klah-clint.

    SELECT SINGLE * FROM cabn

    INTO CORRESPONDING FIELDS OF cabn

    WHERE atinn = ksml-imerk.

    IF syst-subrc = 0.

    it_cabn-atinn = cabn-atinn.

    it_cabn-atnam = cabn-atnam.

    it_cabn-atfor = cabn-atfor.

    APPEND it_cabn.

    ENDIF.

    ENDSELECT.

    ENDIF.

    ENDFORM.

    ----


    • FORM create_batch *

    ----


    FORM create_batch.

    CLEAR: rettab.

    REFRESH: rettab.

    • create the batch using screen values, you will most likely have to

    • determine the next batch number from the number range.

    CALL FUNCTION 'BAPI_BATCH_CREATE'

    EXPORTING

    material = p_matnr

    batch = p_charg

    plant = p_werks

    batchstoragelocation = p_lgort

    TABLES

    return = rettab.

    ENDFORM.

    ----


    • FORM build_object_key *

    ----


    FORM build_object_key.

    • build the object key

    CLEAR: it_object, rettab.

    REFRESH: it_object, rettab.

    it_object-key_field = 'MATNR'.

    it_object-value_int = p_matnr.

    APPEND it_object.

    it_object-key_field = 'WERKS'.

    it_object-value_int = p_werks.

    APPEND it_object.

    it_object-key_field = 'CHARG'.

    it_object-value_int = p_charg.

    APPEND it_object.

    CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'

    EXPORTING

    objecttable = 'MCHA'

    IMPORTING

    objectkey_conc = w_object

    TABLES

    objectkeytable = it_object

    return = rettab.

    ENDFORM.

    ----


    • FORM extract_original_batch *

    ----


    FORM extract_original_batch.

    • extract the original characteristic data if exists

    CLEAR: numtab, chatab, curtab, rettab.

    REFRESH: numtab, chatab, curtab, rettab.

    CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'

    EXPORTING

    objectkey = w_object

    objecttable = 'MCHA'

    classnum = p_class

    classtype = p_klart

    TABLES

    allocvaluesnum = numtab

    allocvalueschar = chatab

    allocvaluescurr = curtab

    return = rettab.

    ENDFORM.

    ----


    • FORM update_original_batch *

    ----


    FORM update_original_batch.

    • Below are some examples of characteristics to update, obviously you

    • would change these to match the ones in your system

    • ATNAM is the characteristic name.

    • find characteristic format in it_cabn and call update routine

    READ TABLE it_cabn WITH KEY atnam = 'TREAD'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam 'HW203'.

    READ TABLE it_cabn WITH KEY atnam = 'ORRETREAD'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '11225HW203C'.

    READ TABLE it_cabn WITH KEY atnam = 'CASINGCODE'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '7100044'.

    READ TABLE it_cabn WITH KEY atnam = 'CASINGSTATUS'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam 'CUSTOMER'.

    READ TABLE it_cabn WITH KEY atnam = 'CASEVAL'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '0'.

    READ TABLE it_cabn WITH KEY atnam = 'CUSTOMER'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '0276933500'.

    READ TABLE it_cabn WITH KEY atnam = 'FROMLOC'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '0584'.

    READ TABLE it_cabn WITH KEY atnam = 'BRAND'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam 'BRI'.

    READ TABLE it_cabn WITH KEY atnam = 'NOCAPS'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '1'.

    READ TABLE it_cabn WITH KEY atnam = 'RETURNLOC'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '0584'.

    READ TABLE it_cabn WITH KEY atnam = 'RECDATE'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '26.07.2004'.

    READ TABLE it_cabn WITH KEY atnam = 'SENTDATE'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '26.07.2004'.

    READ TABLE it_cabn WITH KEY atnam = 'FLOC'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '0750'.

    READ TABLE it_cabn WITH KEY atnam = 'AUTOCLAVE'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam '4'.

    READ TABLE it_cabn WITH KEY atnam = 'REPAIRCODE'.

    PERFORM update_table USING it_cabn-atfor it_cabn-atnam 'MINOR'.

    • perform the update

    PERFORM bapi_change.

    ENDFORM.

    ----


    • FORM update_table *

    ----


    FORM update_table USING atfor atnam value.

    • depending on data format, start building the characteristics table

    • ready for update

    CASE atfor.

    WHEN 'NUM'.

    READ TABLE numtab WITH KEY charact = atnam.

    IF syst-subrc = 0.

    numtab-value_from = value.

    MODIFY numtab INDEX syst-tabix.

    ELSE.

    numtab-charact = atnam.

    numtab-value_from = value.

    APPEND numtab.

    ENDIF.

    WHEN 'CURR'.

    WHEN 'CHAR' OR 'DATE'.

    READ TABLE chatab WITH KEY charact = atnam.

    IF syst-subrc = 0.

    chatab-value_neutral = value.

    MODIFY chatab INDEX syst-tabix.

    ELSE.

    chatab-charact = atnam.

    chatab-value_neutral = value.

    APPEND chatab.

    ENDIF.

    ENDCASE.

    ENDFORM.

    ----


    • FORM bapi_change *

    ----


    FORM bapi_change.

    • Apply the characteristics to the batch.

    CALL FUNCTION 'BAPI_OBJCL_CHANGE'

    EXPORTING

    objectkey = w_object

    objecttable = 'MCHA'

    classnum = p_class

    classtype = p_klart

    TABLES

    allocvaluesnumnew = numtab

    allocvaluescharnew = chatab

    allocvaluescurrnew = curtab

    return = rettab.

    ENDFORM.

    ----


    • FORM bapi_commit *

    ----


    FORM bapi_commit.

    • commit the changes

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    ENDFORM.

    Regards,

    Srikanth.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 04, 2006 at 02:24 PM

    Hi All,

    I already saw the other post with regard to 'BAPI_BATCH_CREATE', but at my client, people are saying that I can use the same BAPI to pass a single object characteristic by populating the importing parameter 'BATCHCONTROLFIELDS'. As I have never used this Bapi,I didnot know how to use it for creation of a Batch to a material along with passing of Single Object characteristic from its material master.Hope I am clear to you.

    Thanks.

    Mohan

    Add comment
    10|10000 characters needed characters exceeded