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

Error Handling in RFC

Former Member
0 Likes
1,454

Hi Gurus,

I want to do error handling in my RFC, for that what is the procedure.

Declaring an internal table of type BAPIRET1,and how to capture the error messages.

Thanks in Advance,

Praveen

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
1,408

What is it your RFC should do:

For example you want to create a Business Partner via the RFC.

Well, then in your RFC you will call a BAPI for example. This BAPI will return error message also in the same structure. Pass it to your structure / internal table and ready.

Another example: In the first step you check if Business Partner is already available (which means you can't create it again). So you do a select on the database table with all BP. If BP is already created you can create your own message and give it back to the RFC.

But do not forget to use the standard exceptions when calling the RFC in other system:

system_failure and communication_failure and catch these in message like this:

CALL FUNCTION ' RFC' destination 'DEST'

importing

xxxx

exporting

tables

exceptions

system_failure = 1 message lv_message

communication_failure = 2 message lv_message.

lv_message type string.

Hi Gurus,

I want to do error handling in my RFC, for that what is the procedure.

Declaring an internal table of type BAPIRET1,and how to capture the error messages.

Thanks in Advance,

Praveen

8 REPLIES 8
Read only

Former Member
0 Likes
1,408

well be sure you do just status messages.

perform MSG_PUT tables T_E_OBMS using SY-MSGNO.

FORM msg_put TABLES t_obms TYPE yic_obms_t
             USING p_rc TYPE n.

  CLEAR t_obms.
  t_obms-rc = p_rc.

  MOVE-CORRESPONDING sy TO t_obms.

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO t_obms-msgtx.

  APPEND t_obms.

ENDFORM.

Read only

Sm1tje
Active Contributor
0 Likes
1,409

What is it your RFC should do:

For example you want to create a Business Partner via the RFC.

Well, then in your RFC you will call a BAPI for example. This BAPI will return error message also in the same structure. Pass it to your structure / internal table and ready.

Another example: In the first step you check if Business Partner is already available (which means you can't create it again). So you do a select on the database table with all BP. If BP is already created you can create your own message and give it back to the RFC.

But do not forget to use the standard exceptions when calling the RFC in other system:

system_failure and communication_failure and catch these in message like this:

CALL FUNCTION ' RFC' destination 'DEST'

importing

xxxx

exporting

tables

exceptions

system_failure = 1 message lv_message

communication_failure = 2 message lv_message.

lv_message type string.

Read only

Former Member
0 Likes
1,408

Hi Thanks forr your responses,

my RFC is below where do I place the code for the error handling or a falg to return.

FUNCTION Z_HR_IT0094_CREATE1.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(GROUP) LIKE APQI-GROUPID OPTIONAL

*" VALUE(USER) LIKE APQI-USERID OPTIONAL

*" VALUE(KEEP) LIKE APQI-QERASE OPTIONAL

*" VALUE(HOLDDATE) LIKE APQI-STARTDATE OPTIONAL

*" VALUE(PERNR) LIKE P0094-PERNR

*" VALUE(BEGDA) LIKE P0094-BEGDA

*" VALUE(ENDDA) LIKE P0094-ENDDA

*" VALUE(CHOIC) LIKE RP50G-CHOIC

*" VALUE(RESIS) LIKE P0094-RESIS

*" VALUE(FPNCD) LIKE P0094-FPNCD

*" VALUE(AUTH1) LIKE P0094-AUTH1

*" VALUE(DOCN1) LIKE P0094-DOCN1

*" VALUE(DATE1) LIKE P0094-DATE1

*" VALUE(EXPID) LIKE P0094-EXPID

*" VALUE(FWOCD) LIKE P0094-FWOCD

*" VALUE(AUTH2) LIKE P0094-AUTH2

*" VALUE(DOCN2) LIKE P0094-DOCN2

*" VALUE(DATE2) LIKE P0094-DATE2

*" VALUE(EXPDT) LIKE P0094-EXPDT

*" EXPORTING

*" VALUE(SUBRC) LIKE SYST-SUBRC

*" TABLES

*" MESSTAB STRUCTURE BDCMSGCOLL OPTIONAL

*"----


DATA: LS_DATA LIKE P0094 OCCURS 0 WITH HEADER LINE.

DATA: LS_RETURN LIKE BAPIRETURN1 .

MOVE PERNR TO LS_DATA-PERNR.

MOVE BEGDA TO LS_DATA-BEGDA.

MOVE ENDDA TO LS_DATA-ENDDA.

MOVE RESIS TO LS_DATA-RESIS.

MOVE FPNCD TO LS_DATA-FPNCD.

MOVE AUTH1 TO LS_DATA-AUTH1.

MOVE DOCN1 TO LS_DATA-DOCN1.

MOVE DATE1 TO LS_DATA-DATE1.

MOVE EXPID TO LS_DATA-EXPID.

MOVE FWOCD TO LS_DATA-FWOCD.

MOVE AUTH2 TO LS_DATA-AUTH2.

MOVE DOCN2 TO LS_DATA-DOCN2.

MOVE DATE2 TO LS_DATA-DATE2.

MOVE EXPDT TO LS_DATA-EXPDT.

CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'

EXPORTING

NUMBER = LS_DATA-PERNR

IMPORTING

RETURN = LS_RETURN

LOCKING_USER = USER.

DATA: DIALOG_MODE TYPE C.

IF SYST-BATCH IS INITIAL.

DIALOG_MODE = '1'.

ELSE.

DIALOG_MODE = '0'.

ENDIF.

CALL FUNCTION 'HR_INFOTYPE_OPERATION'

EXPORTING

INFTY = '0094'

NUMBER = LS_DATA-PERNR

VALIDITYEND = LS_DATA-ENDDA

VALIDITYBEGIN = LS_DATA-BEGDA

RECORD = LS_DATA

OPERATION = 'INS'

DIALOG_MODE = DIALOG_MODE

NOCOMMIT = SPACE

IMPORTING

RETURN = LS_RETURN.

COMMIT WORK.

CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'

EXPORTING

NUMBER = LS_DATA-PERNR

IMPORTING

RETURN = LS_RETURN.

ENDFUNCTION.

Read only

Sm1tje
Active Contributor
0 Likes
1,408

In this RFC you should declare the return structure in stead of using the BDCMSGCOLL. But make sure that you transfer all messages coming back from this table in your return table.

Also, append the data from your other function modules ENQUEUE and DEQUEUE to your return table.

Before doing the COMMIT work you should check if an error has occured during the operation. So check LS_RETURN-TYPE <> 'E' or 'A'.

Do not use DIALOG MODE in RFC when calling from another system, this will give DUMP.

Read only

Former Member
0 Likes
1,408

Thanks so much,

can you please give me any code samples... please

Read only

Sm1tje
Active Contributor
0 Likes
1,408

The code looks not bad at all, but you do need to make some adjustments:

FUNCTION Z_HR_IT0094_CREATE1.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(GROUP) LIKE APQI-GROUPID OPTIONAL

*" VALUE(USER) LIKE APQI-USERID OPTIONAL

*" VALUE(KEEP) LIKE APQI-QERASE OPTIONAL

*" VALUE(HOLDDATE) LIKE APQI-STARTDATE OPTIONAL

*" VALUE(PERNR) LIKE P0094-PERNR

*" VALUE(BEGDA) LIKE P0094-BEGDA

*" VALUE(ENDDA) LIKE P0094-ENDDA

*" VALUE(CHOIC) LIKE RP50G-CHOIC

*" VALUE(RESIS) LIKE P0094-RESIS

*" VALUE(FPNCD) LIKE P0094-FPNCD

*" VALUE(AUTH1) LIKE P0094-AUTH1

*" VALUE(DOCN1) LIKE P0094-DOCN1

*" VALUE(DATE1) LIKE P0094-DATE1

*" VALUE(EXPID) LIKE P0094-EXPID

*" VALUE(FWOCD) LIKE P0094-FWOCD

*" VALUE(AUTH2) LIKE P0094-AUTH2

*" VALUE(DOCN2) LIKE P0094-DOCN2

*" VALUE(DATE2) LIKE P0094-DATE2

*" VALUE(EXPDT) LIKE P0094-EXPDT

*" EXPORTING

*" VALUE(SUBRC) LIKE SYST-SUBRC

*" TABLES

*" RETURN STRUCTURE BAPIRET2

*"----


DATA: LS_DATA LIKE P0094 OCCURS 0 WITH HEADER LINE.

DATA: LS_RETURN LIKE BAPIRETURN1 .

DATA: LS_RETURN2 TYPE BAPIRET2.

MOVE PERNR TO LS_DATA-PERNR.

MOVE BEGDA TO LS_DATA-BEGDA.

MOVE ENDDA TO LS_DATA-ENDDA.

MOVE RESIS TO LS_DATA-RESIS.

MOVE FPNCD TO LS_DATA-FPNCD.

MOVE AUTH1 TO LS_DATA-AUTH1.

MOVE DOCN1 TO LS_DATA-DOCN1.

MOVE DATE1 TO LS_DATA-DATE1.

MOVE EXPID TO LS_DATA-EXPID.

MOVE FWOCD TO LS_DATA-FWOCD.

MOVE AUTH2 TO LS_DATA-AUTH2.

MOVE DOCN2 TO LS_DATA-DOCN2.

MOVE DATE2 TO LS_DATA-DATE2.

MOVE EXPDT TO LS_DATA-EXPDT.

CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'

EXPORTING

NUMBER = LS_DATA-PERNR

IMPORTING

RETURN = LS_RETURN

LOCKING_USER = USER.

if ls_return-type = 'E'.

move-corresponding ls_return to ls_return2.

append ls_return2 to return.

exit.

endif.

DIALOG MODE => background mode (NO dialog)

CALL FUNCTION 'HR_INFOTYPE_OPERATION'

EXPORTING

INFTY = '0094'

NUMBER = LS_DATA-PERNR

VALIDITYEND = LS_DATA-ENDDA

VALIDITYBEGIN = LS_DATA-BEGDA

RECORD = LS_DATA

OPERATION = 'INS'

DIALOG_MODE = DIALOG_MODE

NOCOMMIT = SPACE

IMPORTING

RETURN = LS_RETURN.

if ls_return-type = 'E'.

move-corresponding ls_return to ls_return2.

append ls_return2 to return.

rollback work. " Just in case.

exit.

else.

move-corresponding ls_return to ls_return2.

append ls_return2 to return.

endif.

COMMIT WORK.

CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'

EXPORTING

NUMBER = LS_DATA-PERNR

IMPORTING

RETURN = LS_RETURN.

Needs some fine tuning perhaps, but all in all this should do the trick.

Look at predefined exceptions when calling RFC from external system:

http://help.sap.com/saphelp_nw70/helpdata/EN/22/0425e0488911d189490000e829fbbd/frameset.htm

Copy and paste this part:

EXCEPTIONS

SYSTEM_FAILURE = 1 MESSAGE msg

COMMUNICATION_FAILURE = 2 MESSAGE msg

directly after your function module.

msg type string.

Read only

Former Member
0 Likes
1,408

Hi Micky,

Thanks for your reply.

When I pase the code for the exceptions the system is giving error message

"The formal parameter "MESSAGE" appear twice".

and the rest of the code seems to be working fine.

Thanks..