Application Development 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: 

Job is executed twice every after event

Former Member
0 Kudos

Hello,

I have a job and I want that my job starts every after event, so I configure the job start conditions giving the event name in "After event" screen.

The program that triggers the event is executed every time that an order is released and saved (trough a user-exit ZXWOCU07).

Sometimes the job is executed twice and not one like I want (I don't save the order twice, just one).

Before calling bp_event_raise I have this code


export caufvd_imp = caufvd_imp
          uname = uname
          to database indx(st) id 'TEST'.

and report's job have something like this


import caufvd_imp = caufvd_imp
          uname = uname      
          from database indx(st) id 'TEST'.

Thanks.

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos

Hi,

I don't know this exit in detail but in the past I have seen that some exits are actually processed twice by the applications, based on whatever condition. You can try setting some counter or flag in the exit and only fire the event when the counter is 1 or the flag is not set. Maybe this will cure the symptom.

Greetings

Thomas

9 REPLIES 9

ThomasZloch
Active Contributor
0 Kudos

Hi,

I don't know this exit in detail but in the past I have seen that some exits are actually processed twice by the applications, based on whatever condition. You can try setting some counter or flag in the exit and only fire the event when the counter is 1 or the flag is not set. Maybe this will cure the symptom.

Greetings

Thomas

0 Kudos

Hi!

Thanks for your answer but I have something like this, not with a flag but I'm consulting a table:


   SELECT SINGLE aufnr
           INTO w_zpmg02-aufnr
           FROM zpmg02
          WHERE aufnr = caufvd_imp-aufnr.
    IF sy-subrc <> 0.
      CLEAR w_zpmg02.
      w_zpmg02-aufnr = caufvd_imp-aufnr.
      INSERT INTO zpmg02 VALUES w_zpmg02.

      DATA: uname LIKE sy-uname.
      uname = sy-uname.
      EXPORT caufvd_imp = caufvd_imp uname = uname
                    TO DATABASE indx(st) ID 'TEST'.

      CALL FUNCTION 'BP_EVENT_RAISE' 
        EXPORTING
          eventid = 'ZPM_GD_CREAR_LISTAS'.
    ENDIF.

0 Kudos

There might be a problem because you cannot do a COMMIT WORK in the user exit, so the select might return SY-SUBRC = 4 within the same LUW even though you have inserted that value beforehand. So a static flag might still be an option. Also check Rashid's suggestions.

Thomas

0 Kudos

Thanks for the answers.

I'm going to try your suggestions and wait for the strange behavior.

I'll tell you.

Thanks a lot.

0 Kudos

Hi Thomas!

When you talked about static flag, did you mean a global variable? Because I've tried and it hasn't worked.

On the other hand, I can't define the job trigger condition with some argument with the event, because the order is changing in every execution.

Any other ideas?

Thanks a lot.

0 Kudos

Hi Vande,

I am pretty late in the discussion, Can you please tell what event you are triggering.

Generally we can use the Business object BUS2007 Event RELEASE or CREATED to trigger the background job.

The Exit you are trying the use will trigger everytime a user saves a order. Even after releasing it, the user will have to Save the order. That will execute the code again.

Thanks

Romit

0 Kudos

Hi Romit!

I created an event with sm62 and I defined the job in order that it executes every time that the event is called.

The event is called when an order is saved trough a user-exit ZXWOCU07.

The problem is that sometimes when I save the order the user is executed two times and the job is also executed twice.

I tried to set static flag (global variable) in order that this behavior change and only executes the user once, like Thomas suggest. But it didn't work.

On the other hand, Rashid suggest to add some argument when I define the trigger but I dont know how to add the number order and also if the user is executed twice the problem wont be solved.

The behavior that I want is that user executes the job the first time that the order is released and save it.

Any idea?

Thanks a lot.

0 Kudos

>

> When you talked about static flag, did you mean a global variable?

No, I thought about a flag declared inside the user exit using STATIC instead of DATA. It will "remember" its value next time you enter the exit within the same transaction. Not that tidy, but if it helps...

Thomas

Rashid_Javed
Contributor
0 Kudos

Well It is a bit confusing as you mentioned that 'sometimes' it is executed twice. From my experience with events, i once had a condition that job was always starting twice but that was due to the fact that we had two different jobs defined on same event, one was with event argument and other was without argument. Now if you trigger the event with argument, the other job (trigger was same event without argument) also starts automatically.

Anyways, what i suggest is that

1: Check your system, if more than one jobs are defined with same event.

2: While defining the job trigger condition add some argument with the event.

3: While calling BP_EVENT_RAISE trigger the event with some specific argument (for example order no can be a good argument)

4: In the resultant job that is triggered through this event, you can use the function module GET_JOB_RUNTIME_INFO to know what specific event and argument has triggered this job. You can match this information with some information that you may have exported in you main program (that triggers this job). As you are already exporting/importing info to INDX, you can add event arguments to export and check it later with info you get from GET_JOB_RUNTIME_INFO.

Hope this will help you.

RJv