Application Development and Automation 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: 
Read only

running bapi in back ground

Former Member
0 Likes
1,757

hi all,

i had to upload material master basic view, iam updating using bapi,

i want to run this program in background. i am getting problem wen calling bapi. its not executing this bapi.

wen i run the same program its working fine.

could any body help me in this regard

below is the code

&----


*& Report ZTEST_BAPI_BASIC

*&

&----


*&

*&

&----


report ztest_bapi_basic.

types : begin of ty_mara,

matnr type mara-matnr,

mbrsh type mara-mbrsh,

mtart type mara-mtart,

meins type mara-meins,

maktx type makt-maktx,

end of ty_mara.

data: begin of it_makt occurs 0.

include structure bapi_makt.

data end of it_makt.

data:begin of it_ret occurs 0.

include structure bapiret2.

data end of it_ret.

data : t_mara type standard table of ty_mara,

st_mara type ty_mara.

data: bapi_head like bapimathead,

bapi_clientdata like bapi_mara,

bapi_clientdatax like bapi_marax.

selection-screen : begin of block b1 with frame title text-001. "SELECTION SCREEN

parameters: p_fnam like rlgrap-filename.

selection-screen : end of block b1.

at selection-screen on value-request for p_fnam.

call function 'F4_FILENAME' "FUNCTION MODULE TO LOCATE THE FILE ON THE DISK

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = ' '

importing

file_name = p_fnam.

start-of-selection.

perform upload.

perform bapi.

&----


*& Form UPLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form upload .

data : filename type string.

filename = p_fnam.

call function 'GUI_UPLOAD'

exporting

filename = filename

filetype = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • HEADER =

tables

data_tab = t_mara

  • EXCEPTIONS

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " UPLOAD

&----


*& Form BAPI

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form bapi .

sort t_mara by matnr.

loop at t_mara into st_mara.

perform conversion using st_mara-matnr changing st_mara-matnr.

bapi_head-material = st_mara-matnr.

bapi_head-ind_sector = st_mara-mbrsh.

bapi_head-matl_type = st_mara-mtart.

bapi_head-basic_view ='X'.

bapi_clientdata-base_uom = st_mara-meins.

bapi_clientdatax-base_uom = 'x'.

refresh it_makt.

it_makt-langu = 'E'.

it_makt-matl_desc = st_mara-maktx.

append it_makt.

clear it_ret.

refresh it_ret.

perform update_bapi using bapi_head

bapi_clientdata

bapi_clientdatax .

read table it_ret with key type = 'S'.

if sy-subrc eq 0.

commit work.

else.

call function 'BAPI_TRANSACTION_ROLLBACK'

  • IMPORTING

  • RETURN =

.

endif.

endloop.

endform. " BAPI

&----


*& Form CONVERSION

&----


  • text

----


  • -->INPUT text

  • -->OUTPUT text

----


form conversion using input changing output.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = input

importing

output = output.

endform. "conversion

&----


*& Form update_bapi

&----


  • text

----


  • -->BAPI_HEAD text

  • -->BAPI_CLIENTDATA text

  • -->BAPI_CLIENTDATAX text

----


form update_bapi using bapi_head bapi_clientdata bapi_clientdatax .

call function 'BAPI_MATERIAL_SAVEDATA' in background task as separate unit

exporting

headdata = bapi_head

clientdata = bapi_clientdata

clientdatax = bapi_clientdatax

  • FLAG_ONLINE = ' '

  • FLAG_CAD_CALL = ' '

  • NO_DEQUEUE = ' '

  • NO_ROLLBACK_WORK = ' '

  • importing

return = it_ret

tables

materialdescription = it_makt

.

append it_ret.

endform. "update_bapi

regards

siva

6 REPLIES 6
Read only

former_member195698
Active Contributor
0 Likes
1,095

It seems to be because of the use of FM GUI_UPLOAD. You cannot upload a file from presentation server in background..

Try keeping your file on the application server, pick the file from app. server in your program using Open dataset and then try running the program in background.

Read only

Former Member
0 Likes
1,095

Hi,

Do you want to just run the program in background? If so then just create a variant and create a background job - I'm not sure you want to be calling the BAPI as a seperate background task?

Gareth.

Read only

0 Likes
1,095

hi,

thanks for ur quick response,

initially i uploaded the data using the above program using bapi

with out using background task. its showing error in function module.

i need to run this program in back ground .

if necessry i can go for background task also.

regards

siva

Read only

0 Likes
1,095

Hi,

I'm a bit confused now - does the BAPI call work if you run it entirely in foreground or does it fail there too?

You need to ensure your BAPI works correctly with the data you are passing to it - preferably in foreground so you can debug it and see what is happening. If it throws errors there then add them to this thread.

If it works in foreground then you probably need to schedule the job in background but as others have pointed out, you can't use the GUI_UPLOAD function to do this.

Gareth.

Read only

Former Member
0 Likes
1,095

HI,

Your problem is not with the BAPI function module, with the GUI_UPLOAD, because it is not working in back ground, only working in foreground. Do one thing try to get the data from application server instead of desktop when program is running in back ground.

Rgds,

Bujji

Read only

Former Member
0 Likes
1,095

Hi,

Abhishek's answer is true,in ur code u ar using GUI_UPload this fm is are dependent on the gui

You can not use these in the background. You must download to the application server, using the dataset statements.

OPEN DATASET

TRANSFER

CLOSE DATASET

Regards

Kiran Sure