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

BAPI_DOCUMENT_CHANGE2 and BAPI_DOCUMENT_CREATE2 in background

Former Member
0 Likes
3,179

Hi,

Can anyone please tell me whether the BAPIS 'BAPI_DOCUMENT_CHANGE2 ' and 'BAPI_DOCUMENT_CREATE2 can be executed in background?.

In foreground mode I can able to create and change the document successfully.

but in background mode I am getting an error from the BAPI saying that document can not be checked in.

Can anyone help me?

Regards,

Deepu

8 REPLIES 8
Read only

Former Member
0 Likes
1,826

Hi,

If you are trying to check in a document from a local drive, such as your C: drive then it will not work in the background. It will only work for network drives that are accessible from the application servers.

Regards

Darren

Read only

0 Likes
1,826

Hi Darren,

Thanks for the reply.

I Also tried to upload the document from an application server drive, but the same error existing.

Can you please tell me Background execution is possible or not?

I will once again check with the Application server.

Regards,

Deepu

Read only

former_member353207
Participant
0 Likes
1,826

Hi,

maybe the problem are not the BAPI but the selection of the file. You can't use the GUI Frontend Services for selection in Batch-Mode..

Please use FUNCTION 'EPS_GET_DIRECTORY_LISTING' .

program-code example for background:

FORM pd_batch .

DATA: lv_def(5) TYPE c,

lv_hp1 TYPE string,

lv_hp2 TYPE string,

lv_hp3 TYPE string,

lv_sep3(1),

lv_vg(20) TYPE c,

lt_epsfili TYPE STANDARD TABLE OF epsfili,

ls_epsfili TYPE epsfili.

DATA: lv_start TYPE string.

DATA: lv_dir TYPE epsf-epsdirnam.

DATA: lv_filter TYPE string.

DATA: gt_filetable TYPE filetable.

DATA: wa_filetable LIKE LINE OF gt_filetable.

DATA: return TYPE i.

DATA: lv_objnr TYPE cobrb-objnr.

DATA: lt_jstat LIKE STANDARD TABLE OF jstat WITH HEADER LINE.

DATA: lv_epsfilnam TYPE epsf-epsfilnam.

REFRESH: lt_files,lt_drat,lt_drad.

SELECT * FROM zqm_pd_custom INTO wa_pd_custom WHERE manuell = ''.

APPEND wa_pd_custom TO gt_pd_custom.

ENDSELECT.

    • Dokumentendaten zuweisen

break de00009.

LOOP AT gt_pd_custom INTO wa_pd_custom.

  • Liste mit allen Einlesedaten aus dem Verzeichnis

REFRESH: gt_filetable, lt_files.

CLEAR: wa_filetable.

CLEAR: ls_doc,ls_return,ls_return2, lf_docnumber,

lf_docpart,lv_01,lv_02,lv_03,lv_path,lv_file,

lv_file2,lv_fauf, lv_rest,lv_help,lv_help2,lv_sep,wa_aufk.

ls_doc-documenttype = '044'.

ls_doc-documentversion = '00'.

ls_doc-documentpart = '000'.

ls_doc-statusextern = 'FR'.

lv_sep3 = '-'.

lv_start = wa_pd_custom-path.

CONCATENATE '.' wa_pd_custom-ufext INTO lv_filter.

  • GUI-Frontend-Services läuft nicht im Batch

IF sy-batch = 'X'.

lv_dir = lv_start.

CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'

EXPORTING

dir_name = lv_dir

file_mask = '.'

TABLES

dir_list = lt_epsfili

EXCEPTIONS

invalid_eps_subdir = 1

sapgparam_failed = 2

build_directory_failed = 3

no_authorization = 4

read_directory_failed = 5

too_many_read_errors = 6

empty_directory_list = 7

OTHERS = 8.

LOOP AT lt_epsfili INTO ls_epsfili.

wa_filetable-filename = ls_epsfili-name.

APPEND wa_filetable TO gt_filetable.

ENDLOOP.

ELSE.

CALL METHOD cl_gui_frontend_services=>directory_list_files

EXPORTING

directory = lv_start

filter = lv_filter

files_only = 'X'

CHANGING

file_table = gt_filetable

count = return

EXCEPTIONS

cntl_error = 1

directory_list_files_failed = 2

wrong_parameter = 3

error_no_gui = 4

not_supported_by_gui = 5

OTHERS = 6.

ENDIF.

IF sy-subrc = 0 AND gt_filetable IS NOT INITIAL..

LOOP AT gt_filetable INTO wa_filetable.

REFRESH lt_files.

lv_path = wa_pd_custom-path.

lv_file = wa_filetable-filename.

SPLIT lv_file AT lv_sep3 INTO: lv_hp1 lv_hp2.

lv_fauf = lv_hp1.

CONCATENATE '00000' lv_fauf INTO lv_fauf.

REPLACE ALL OCCURRENCES OF '.csv' IN lv_hp2 WITH ''.

CONCATENATE 'O0000000000' lv_hp2 INTO lv_vg.

  • Testen, ob FAUF vorhanden

SELECT SINGLE * FROM aufk INTO wa_aufk

WHERE aufnr = lv_fauf.

IF sy-subrc <> 0.

*Datei einfach stehen lassen

ELSE.

  • Nur Status "TABG" behandeln

CONCATENATE 'OR' lv_fauf INTO lv_objnr.

CALL FUNCTION 'STATUS_READ'

EXPORTING

objnr = lv_objnr

only_active = 'X'

TABLES

status = lt_jstat

EXCEPTIONS

object_not_found = 1.

READ TABLE lt_jstat WITH KEY stat = 'I0045'. " TABG

IF sy-subrc = 0.

CONCATENATE lv_path '' lv_file INTO lt_files-docfile.

*zum löschen vormerken

CONCATENATE lv_path '' lv_file INTO lv_file2.

lt_files-wsapplication = wa_pd_custom-wsapp.

lt_files-statusintern = 'FR'.

lt_files-storagecategory = 'Z0001'.

APPEND lt_files.

    • Kurztexte

CLEAR lt_drat.

REFRESH lt_drat.

lt_drat-language = 'DE'.

lt_drat-description = wa_pd_custom-ktext.

APPEND lt_drat.

    • Objektverknüpfung zum Fertigungsauftrag

CLEAR lt_drad.

REFRESH lt_drad.

lt_drad-objecttype = 'PORDER'.

CONCATENATE lv_fauf lv_vg INTO lt_drad-objectkey.

APPEND lt_drad.

**************************************************************

    • Dokument anlegen

**************************************************************

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

EXPORTING: documentdata = ls_doc

IMPORTING: documenttype = lf_doctype

documentnumber = lf_docnumber

documentpart = lf_docpart

documentversion = lf_docversion

return = ls_return

TABLES: documentdescriptions = lt_drat

objectlinks = lt_drad

documentfiles = lt_files.

SHIFT lf_docnumber LEFT DELETING LEADING space.

  • FAUF-Nr.

lv_01 = lt_drad-objectkey.

  • Dokumentenart

lv_02 = ls_doc-documenttype.

  • DIS Nummer

lv_03 = lf_docnumber.

    • Fehler aufgetreten ??

IF ls_return-type CA 'EA'.

ROLLBACK WORK.

MESSAGE ID '26' TYPE 'I' NUMBER '000'

WITH ls_return-message.

ELSE.

COMMIT WORK.

  • Wenn einchecken ok, Datei löschen

IF ls_return IS INITIAL.

IF sy-batch = 'X'.

lv_epsfilnam = lv_file.

CALL FUNCTION 'EPS_DELETE_FILE'

EXPORTING

file_name = lv_epsfilnam

dir_name = lv_dir

EXCEPTIONS

invalid_eps_subdir = 1

sapgparam_failed = 2

build_directory_failed = 3

no_authorization = 4

build_path_failed = 5

delete_failed = 6

OTHERS = 7.

IF sy-subrc <> 0.

ENDIF.

ELSE.

CALL FUNCTION 'WS_FILE_DELETE'

EXPORTING

file = lv_file2

IMPORTING

return = sy-subrc.

IF sy-subrc <> 0.

ENDIF.

ENDIF.

ENDIF.

*Satz in ZPROZDATEN einfügen

wa_prozdaten-aufnr = lv_01.

wa_prozdaten-arbpl = wa_pd_custom-arbpl.

wa_prozdaten-werks = wa_pd_custom-werks.

wa_prozdaten-dokar = ls_doc-documenttype.

wa_prozdaten-doknr = lv_03.

wa_prozdaten-dokvr = ls_doc-documentversion.

CONCATENATE lv_path '' lv_file INTO wa_prozdaten-filep.

wa_prozdaten-datum = sy-datum.

wa_prozdaten-name = sy-uname.

wa_prozdaten-uzeit = sy-uzeit.

INSERT INTO zqm_prozdaten VALUES wa_prozdaten.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDLOOP.

regard Joerg

Read only

0 Likes
1,826

Hi Joerg,

Thanks for the reply.

This part is already done and if the Program is running in batch mode I am using the FM 'EPS_GET_DIRECTORY_LISTING' . This ia already done.

Can you please tell me Background execution is possible or not for the BAPIs?

Regards,

Deepu

Read only

0 Likes
1,826

Hi Deepu,

certainly it's possible. The posted program is running in background. What's the precise error message you get ?

Joerg

Read only

0 Likes
1,826

Hi Joerg,

I am getting an error only when I tried to upload and check-in the document with the BAPI. Other changes I am able to do in background. In background I am getting an error that "Document XXX can not be checked from path XXXXX".

Can please comment on this?

Regards,

Deepu

Read only

Former Member
0 Likes
1,826

I am getting the similar problem. Has everyone even get this resolved? Our problem is when the BAPI is being executed through a remote logon RFC user, it will fail with a similar error of "Document XXX can not be checked from path XXXXX" but when the RFC debug mode is on, and step through the code, no error will occur.

This error only happens in ECC 6.0 box, the same file is used for 4.7 systems and files were checked in okay.

Any advice is appreciated.

Best Regards,

Minami

Edited by: Minami Akana on Mar 7, 2009 7:39 AM

Read only

0 Likes
1,826

Hi,

I have the same problem now. My program works fine on line. but it always failed when executed in background. do you have the solution?