cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with events and function module.

0 Kudos

Hello guys.

I have the following scenario: I need to change a date field from order maintenance when the order is released.

When the release occurs, I need that field date, marked red as shown bellow, from transaction IW32, gets the release date.

In Tcode SWETYPV, for BOR BUS2007, I created a rule that call a ZFM when maintenance order is released.

The ZFM code:

FUNCTION ZPM_DATA_BASE.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  IMPORTING
*"     VALUE(OBJTYPE) TYPE  SWETYPECOU-OBJTYPE
*"     VALUE(OBJKEY) TYPE  SWEINSTCOU-OBJKEY
*"     VALUE(EVENT) TYPE  SWETYPECOU-EVENT
*"     VALUE(RECTYPE) TYPE  SWETYPECOU-RECTYPE
*"  TABLES
*"      EVENT_CONTAINER STRUCTURE  SWCONT OPTIONAL
*"----------------------------------------------------------------------


  DATA: T_METHODS TYPE STANDARD TABLE OF BAPI_ALM_ORDER_METHOD,
        T_HEADER TYPE STANDARD TABLE OF BAPI_ALM_ORDER_HEADERS_I,
        T_HEADER_UP TYPE STANDARD TABLE OF BAPI_ALM_ORDER_HEADERS_UP,
        T_return TYPE STANDARD TABLE OF BAPIRET2.


  DATA: W_METHOD LIKE LINE OF T_METHODS,
        W_HEADER LIKE LINE OF T_HEADER,
        W_HEADER_UP LIKE LINE OF T_HEADER_UP,
        w_return like LINE OF T_RETURN,
        V_DATA TYPE JCDS-UDATE,
        V_OBJNR TYPE AUFK-OBJNR,
        V_AUART TYPE AUFK-AUART,
        V_objkey TYPE aufk-AUFNR.


  CONCATENATE '00' OBJKEY into V_OBJKEY.


  W_METHOD-REFNUMBER = '000001'.
  W_METHOD-OBJECTTYPE = 'HEADER'.
  W_METHOD-METHOD = 'CHANGE'.
  W_METHOD-OBJECTKEY = v_OBJKEY.


  APPEND W_METHOD TO T_METHODS.
  CLEAR W_METHOD.
  W_METHOD-METHOD = 'SAVE'.
  APPEND W_METHOD TO T_METHODS.
  CONCATENATE 'OR00' OBJKEY INTO V_OBJNR.

  SELECT UDATE
       FROM JCDS
       INTO V_DATA
       WHERE OBJNR = V_OBJNR AND STAT = 'I0002'.
  ENDSELECT.


  CHECK SY-SUBRC = 0.
  W_HEADER-ORDERID = V_OBJKEY.
  W_HEADER-START_DATE = V_DATA.
  APPEND W_HEADER TO T_HEADER.
  W_HEADER_UP-START_DATE = 'X'.


  APPEND W_HEADER_UP TO T_HEADER_UP.

  SELECT AUART
    FROM AUFK
    INTO V_AUART
    WHERE AUFNR = OBJKEY.
  ENDSELECT.

    CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
* EXPORTING
*   IV_MMSRV_EXTERNAL_MAINTENACE       =
      TABLES
        IT_METHODS                         = T_METHODS
        IT_HEADER                          =  T_HEADER
        IT_HEADER_UP                       = T_HEADER_UP
*   IT_HEADER_SRV                      =
*   IT_HEADER_SRV_UP                   =
*   IT_USERSTATUS                      =
*   IT_PARTNER                         =
*   IT_PARTNER_UP                      =
*   IT_OPERATION                       =
*   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_UP                        =
*   IT_TASKLISTS                       =
*   EXTENSION_IN                       =
   RETURN                             = T_RETURN
*   ET_NUMBERS                         =
*   IT_REFORDER_ITEM                   =
*   IT_REFORDER_ITEM_UP                =
*   IT_REFORDER_SERNO_OLIST_INS        =
*   IT_REFORDER_SERNO_OLIST_DEL        =
*   IT_PRT                             =
*   IT_PRT_UP                          =
*   IT_REFORDER_OPERATION              =
*   IT_SERVICEOUTLINE                  =
*   IT_SERVICEOUTLINE_UP               =
*   IT_SERVICELINES                    =
*   IT_SERVICELINES_UP                 =
*   IT_SERVICELIMIT                    =
*   IT_SERVICELIMIT_UP                 =
*   IT_SERVICECONTRACTLIMITS           =
*   IT_SERVICECONTRACTLIMITS_UP        =
*   ET_NOTIFICATION_NUMBERS            =
*   IT_PERMIT                          =
*   IT_PERMIT_UP                       =
*   IT_PERMIT_ISSUE                    =
*   IT_ESTIMATED_COSTS                 =

             .
    READ TABLE T_RETURN INTO W_RETURN WITH KEY TYPE = 'E'.
    if sy-SUBRC <> 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    endif.

ENDFUNCTION.

When I test a FM in SE37, it works perfectly. But when I release the order, anything happens.

We can see in SWEL that the FM is being called by event.

I dont know either why the FM is being called two times. 😞

And we can see in image bellow that the event is called correctly but the objectkey (order number in this case) is not passed to ZFM.

I dont know if this is the only problem. It's my first time with this.

Help me please.

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos
CONCATENATE '00' OBJKEY into V_OBJKEY.

CONCATENATE 'OR00' OBJKEY INTO V_OBJNR.

The error is in above lines. The objkey comes with '00' on left. So, the first line is unnecessary. I dont use V_OBJKEY anymore, just OBJKEY.

In second line I changed 'OR00' to 'OR'.

The FM works fine. But when the order is released and saved, IW32 still block the order, so when i call the BAPI, returns an erro. I corrected this put the code "Wait up to X seconds" above the BAPI code.

It's not an elegant way, but it works.

Regards.

0 Kudos

It happens because I'm trying to change an object by an event of the same object. so the object gets blocked. It's a kind of synchronization problem.

Sandra_Rossi
Active Contributor

Thanks for the feedback. You shouldn't implement a workflow to change the object that is released. I'm surprised that there isn't a user exit to modify the concerned date (AUFK-SDATE?) at the time you release the order.

Answers (1)

Answers (1)

p244500
Active Contributor
0 Kudos

I guess FM BAPI_ALM_ORDER_MAINTAIN also will trigger your event. that's why it trigger two time. if you can avoide it, this will work.

0 Kudos

Hello, Ty. But I think It doesnt make sense because set up in SWETYPV responds an event, not raise an event.

p244500
Active Contributor
0 Kudos

You can check standard workflow WS20000014,released process how it work. you can config that workflow and try it for the released.