2 Replies Latest reply: Jun 19, 2012 2:38 PM by Patrick Paris RSS

Add Operation to Production Order

Patrick Paris
Currently Being Moderated

Hi, I'm looking for a way to add a new operation to an existing production order (order type 10). As I read on previous discussions, I tried FM BAPI_ALM_ORDER_MAINTAIN but I'm unable to make it work, I always get a dump "NOT_FOUND" when CO_BT_AFVG_READ_WITH_LOGKEY is called.

 

Anybody has already di this ? If so, can you help a me with that ?

 

Here's my code :

 

DATA: lv_aufnr        TYPE aufnr,
         lv_openum       TYPE vornr,
         it_methods      TYPE bapi_alm_order_method OCCURS 0 WITH HEADER LINE,
         it_header       TYPE bapi_alm_order_headers_i OCCURS 0 WITH HEADER LINE,
         it_header_up    TYPE bapi_alm_order_headers_up OCCURS 0 WITH HEADER LINE,
         it_partner      TYPE bapi_alm_order_partn_mul OCCURS 0 WITH HEADER LINE,
         it_partner_up   TYPE bapi_alm_order_partn_mul_up OCCURS 0 WITH HEADER LINE,
         it_operation    TYPE bapi_alm_order_operation OCCURS 0 WITH HEADER LINE,
         it_operation_up TYPE bapi_alm_order_operation_up OCCURS 0 WITH HEADER LINE,
         it_srule        TYPE bapi_alm_order_srule OCCURS 0 WITH HEADER LINE,
         it_srule_up     TYPE bapi_alm_order_srule_up OCCURS 0 WITH HEADER LINE,
         it_return       TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
         lv_return       TYPE bapiret2,
         et_numbers      TYPE bapi_alm_numbers OCCURS 0 WITH HEADER LINE,
         lv_message      TYPE string,
         lv_messages     TYPE string.


   lv_aufnr = 20000080.
   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
     EXPORTING
       INPUT  = lv_aufnr
     IMPORTING
       OUTPUT = lv_aufnr.

   lv_openum = 30.
   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
     EXPORTING
       INPUT  = lv_openum
     IMPORTING
       OUTPUT = lv_openum.

   it_methods-refnumber  = 1.
   it_methods-objecttype = 'OPERATION'.
   it_methods-method     = 'CREATE'.
   it_methods-objectkey  = lv_aufnr.
   APPEND it_methods.

   it_methods-refnumber  = 1.
   it_methods-objecttype = ''.
   it_methods-method     = 'SAVE'.
   it_methods-objectkey  = lv_aufnr.
   APPEND it_methods.

   it_operation-activity = lv_openum.
   it_operation-control_key = 'ZP06'.
   it_operation-work_cntr = 'PU01'.
   it_operation-plant = '3101'.
   it_operation-description = 'Test BAPI'.
   it_operation-langu = 'E'.
   APPEND it_operation.

   it_operation_up-activity           = 'X'.
   it_operation_up-control_key        = 'X'.
   it_operation_up-work_cntr          = 'X'.
   it_operation_up-plant              = 'X'.
   it_operation_up-description        = 'X'.
   it_operation_up-langu              = 'X'.
   APPEND it_operation_up.

   CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
     TABLES
       IT_METHODS              = it_methods
       IT_HEADER               = it_header
       IT_HEADER_UP            = it_header_up
*      IT_HEADER_SRV           =
*      IT_HEADER_SRV_UP        =
*      IT_USERSTATUS           =
       IT_PARTNER              = it_partner
       IT_PARTNER_UP           = it_partner_up
       IT_OPERATION            = it_operation
       IT_OPERATION_UP         = it_operation_up
*      IT_RELATION             =
*      IT_RELATION_UP          =
*      IT_COMPONENT            =
*      IT_COMPONENT_UP         =
*      IT_OBJECTLIST           =
*      IT_OBJECTLIST_UP        =
*      IT_OLIST_RELATION       =
*      IT_TEXT                 =
*      IT_TEXT_LINES           =
       IT_SRULE                = it_srule
       IT_SRULE_UP             = it_srule_up
*      IT_TASKLISTS            =
*      EXTENSION_IN            =
       RETURN                  = it_return
       ET_NUMBERS              = et_numbers.

   IF sy-subrc = 0.

     CLEAR lv_messages.
     LOOP AT it_return INTO lv_return.

       CONCATENATE lv_return-type lv_return-message INTO lv_message SEPARATED BY ': '.
       CONCATENATE lv_messages lv_message INTO lv_messages SEPARATED BY cl_abap_char_utilities=>vertical_tab.

     ENDLOOP.

     IF lv_messages IS NOT INITIAL.
       MESSAGE lv_messages TYPE 'I'.
     ENDIF.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         wait = 'X'.

     CALL FUNCTION 'DEQUEUE_ALL'
       EXPORTING
         _SYNCHRON = 'X'.

     COMMIT WORK AND WAIT.

   ELSE.

     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   ENDIF.

Actions