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: 

Function module is not getting executed when report is run in Background

0 Kudos

Hello,

I need to schedule a job for custom Function module for which I have created a report in which I have called the same custom Function module.

When I am executing the report in background , Job is getting scheduled but the Function module is not getting executed.

When I re-run the same job using JDBG then the FM is getting executed and also when I run the report in foreground FM is getting executed.

I am facing issue only when I execute the report in background.

Kindly provide suggestions on how to proceed

Thank you!

BestRegards,

Aamukta Malyada A

23 REPLIES 23

matt
Active Contributor

There's really insufficient information here for a meaningful answer. How about posting the relevant code?

How do you know the FM isn't being executed in background?

0 Kudos

Hi Matthew,

In the custom FM ,I have written a piece of code for RFC creation.

When I execute the report in background that RFC was not created where as when I execute the report in foreground RFC was created

matt
Active Contributor

...and How about posting the relevant code?

Have you checked for dumps, or in SM21? Have you looked at the job logs of the background report?

matt
Active Contributor

Have you implemented logging into your program? If not, do it, and log all relevant events, especially non-zero return codes.

0 Kudos

Sorry I did not get the concept of logging into the program

Can you please explain

Former Member
0 Kudos

SLG1 t-code is the application log. There are various function modules and classes which you can write custom logs to this. I havent read this blog but looks like it will give you the basics;

https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/

0 Kudos

Thank you, I will try this as well to check the logs

I was adding messages and exceptions in function module as well

former_member186746
Active Contributor
0 Kudos

Hi,

Did you write the custom function module? Either the FM tries to do something in the foreground for which it needs user interaction, or there is a piece of code checking sy-batch, or when you execute it in the background it uses a different user and that one is missing authorizations or missing user parameters.

Kind regards, Rob Dielemans

0 Kudos

Yes, I have created the custom FM, I have passed all the required parameters

0 Kudos

Hi,

I'm not interested in parameters I'm interested in which ABAP code that you have written behaves differently depending on foreground or background. For instance: do you use a popup function module?

Kind regards, Rob Dielemans

0 Kudos

Hello,

Inside the Function module I am creating a RFC for different system (say ABC) and updating a custom Table in that system(ABC) and No pop up FM's are used or any code that requires information from fore ground.

iklovski
Active Contributor
0 Kudos

Hi,

It should be dumping then... some FM, indeed, are not meant to be executed in background. But, then you would receive a dump... Otherwise, I wonder how you claim that it was not executed. Log the action through ST05 and see what happens...

Regards,

Eli

0 Kudos

I am not getting any dump and I will try checking ST05 now

raghug
Active Contributor

Umm, you check for dumps in ST22

kiran_k8
Active Contributor
0 Kudos

Hi,

Can you also provide info on the scenario which necessitated creation of RFCs in the background through a Custom FM rather than using SM59.

Are you are creating RFC using a BDC on SM59 ?

K.Kiran.

0 Kudos

Hi Matthew,

Here is the code I used

REPORT ztest.
DATA:
lv_tasklist TYPE stc_scenario_id,
* ls_sid TYPE syst_sysid,
it_return TYPE bapirettab.

lv_tasklist = 'Ztasklist_test'

CALL FUNCTION 'Ztest'
EXPORTING
tasklist_name = lv_tasklist
system_id = sy-sysid
TABLES
it_return = it_return
EXCEPTIONS
errors_occurred = 1
no_data = 2
rfc_failed = 3
failed_updation = 4
OTHERS = 5.
COMMIT WORK.

IF sy-subrc = 0.
WRITE: 'Entries updated'.
* Implement suitable error handling here
ENDIF.

0 Kudos

I have created RFC Using Standard FM for RFC creation. and I created RFC in the FM as I need too update table in a different system

In order to connect to that system I have created a RFC in the FM

former_member186746
Active Contributor
0 Kudos

Hi,

The exceptions of your FM is immediately followed by a commit work, which means that sy-subrc will either be 0 or 4.

Kind regards, Rob Dielemans

former_member186746
Active Contributor
0 Kudos

Correction sy-subrc is always 0

0 Kudos

Yes,

But the Issue I am facing is the Function module is not getting Executed in Background

Jelena
Active Contributor

And still there is no answer on how exactly you established that FM does not work and no code posted of what the FM does...

What have you tried so far to troubleshoot this? Quick Google search for "does not work in background site:sap.com" should've found all the answers regarding what the differences are. And if you can't debug in background then how about adding some messages to display in the job log? ("Logging" is a common programming concept.)

How did you get a job at SAP? If you are an intern/trainee then there should be a trainer assigned to you. SCN is not a replacement for this, sorry.

Former Member

Your report does not explicitly change whether your Function Module is called if the report is run as a background/scheduled job.

Providing your job is finishing and in succeed status i would suggest it IS getting executed but something within the Ztest function module is not working properly, or you are handling an exception which equates to a 'successful' run. So you would need to paste the code for the ztest function module for these kind sirs/madams to assist you further.

Hint: Transaction SE37 to get your Function module code.

Hint 2: If you are in a development environment, put an infinite loop in your report code prior to the function call. Schedule the job and when it is running, go to SM50 and find the dialog process for the program - the user the job is scheduled under will be the indicator in this case. Highlight the line and go to administration -> Program -> Debugging. Step through and you will see.

Hint 3: Take an ABAP course.

ALSO: Have you considered that the foreground and background execution users are different.

matt
Active Contributor

I think we're all well aware what your problem is. You do not need to keep restating it.

If you don't check the sy-subrc at the correct point, then you're not going to trap any issues.

Since you refuse to supply relevant details, I'm going to close this question.