‎2008 Jun 30 9:37 PM
Hello everyone,
I am pushing to use a BAPI on a project I am working on where we are going to create and change sales orders from an external application that will call the BAPI. The only issue is that if there are errors, we want SAP to store them so we can process the errors directly in SAP in a similar fashion to BDC's. Some people here want to use a BDC for the order process whereas I want to use the BAPI. I've used BAPI's before as a means for realtime data processing but never had a request to have error handling as part of it. Can this be done? And if so, how?
Thanks,
Chris
‎2008 Jun 30 9:43 PM
Hello Chris Castillo ,
Your requirement is not possible using BAPI. According to the SAP Standard functionality BAPI will save a transaction (commit) or it will give the error information back.
Hope this answers your question.
Thanks,
Greetson
‎2008 Jun 30 9:46 PM
Hello,
You can handle errors in bapi too, as there is a table called Bapiret2 where all the errors will be stored. You classify them in to different errors like E, A, W etc.
And process that internal table later to roll back the updates etc.
If bapiret2 gives u sucess messge as S then call bapi_commit
Try out......good luck
‎2008 Jun 30 10:07 PM
Hi Chris,
The way you had asked may not be possible...
If any clarifications needed check these links..
http://help.sap.com/saphelp_46c/helpdata/en/a5/3ec9f74ac011d1894e0000e829fbbd/content.htm
Hope you get the desired information.
Regards
Narin Nandivada.
‎2008 Jul 01 1:57 AM
Hi Chris,
Pls chk this code as example for BAPI and message handling.
Pls modify this code as per the standards. Like not using tables with header line etc.
REPORT ZH_BAPI_CC_01 .
TYPES : BEGIN OF tw_output,
kostl TYPE kostl,
datab TYPE datab,
datbi TYPE datbi,
ktext TYPE ktext,
verak TYPE verak,
kosar TYPE kosar,
khinr TYPE khinr,
bukrs TYPE bukrs,
gsber TYPE gsber,
prctr TYPE prctr,
END OF tw_output,
tt_output TYPE STANDARD TABLE OF tw_output.
DATA : lw_output TYPE tw_output,
lt_output TYPE tt_output,
ccil TYPE bapi0012_ccinputlist OCCURS 0 WITH HEADER LINE,
lt_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE, wa_kokrs TYPE bapi0012_gen-co_area,
kokrs TYPE kokrs,
lf_path TYPE string.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: conarea TYPE kokrs,
filepath TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filepath.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = filepath.
START-OF-SELECTION.
wa_kokrs = conarea.
lf_path = filepath.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lf_path
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = lt_output
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF NOT lt_output IS INITIAL.
LOOP AT lt_output INTO lw_output.
MOVE : lw_output-kostl TO ccil-costcenter,
lw_output-datab TO ccil-valid_from,
lw_output-datbi TO ccil-valid_to,
lw_output-ktext TO ccil-name,
lw_output-verak TO ccil-person_in_charge,
lw_output-kosar TO ccil-costcenter_type,
lw_output-khinr TO ccil-costctr_hier_grp,
lw_output-bukrs TO ccil-comp_code,
lw_output-gsber TO ccil-bus_area,
lw_output-prctr TO ccil-profit_ctr.
append ccil.
clear lw_output.
CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'
EXPORTING
controllingarea = wa_kokrs
TABLES
costcenterlist = ccil
return = lt_return
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
IF NOT lt_return[] IS INITIAL.
CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'
EXPORTING
id = sy-msgid
number = sy-msgno
language = sy-langu
textformat = 'ASC'
message_v1 = sy-msgv1
message_v2 = sy-msgv2
message_v3 = sy-msgv3
message_v4 = sy-msgv4
IMPORTING
message = LT_RETURN-MESSAGE
return = lt_return
.
WRITE: / LT_RETURN-MESSAGE.
ELSE.
MESSAGE i002(zrept).
ENDIF.
ENDLOOP.
ENDIF.
Reward if helpful.
Regards
Chandralekha.
‎2008 Jul 01 2:12 AM
Hi Chris,
We are having a similar scenario,
My suggestion is, once you have all the required sales order data to be passed to the BAPI, store this data as records in a custom table ( as flat records, with key fields, like the date, PO # , customer, file name , etc ) and this can be a back up. If the BAPI fails to create SO, you can have these orders stored into the database as a backup for reprocessing using either BDC or BAPI.
‎2008 Jul 01 4:29 AM
bapis hav a return table which hold all kinds of messages, u can filter out error messages and handle them in sap.