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: 

How to handle exceptions while calling a function module without interrupt the program execution

Former Member
0 Kudos
116

Hi Experts,

I have developed program to import excel into sap. And i am creating Opportunities by passing that excel data.

My excel has 300 rows, when i am executing the program if get an error the program has to continue the execution by skipping that that record and that record has to place in the error table. After the program execution it has to display successful records as well error records which are not saved in the database.

For this i am able to display successful records but not error ones.

I am calling below function module.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'

  EXPORTING

    IT_OPPORT_H                   = IT_OPPORT_H

    IT_PARTNER                    = IT_PARTNER

  IMPORTING

    ET_EXCEPTION                  = ET_EXCEPTION

  CHANGING

    CT_ORDERADM_H                 = it_orderadm_h

*   CT_ORDERADM_I                 = it_orderadm_i

    CT_INPUT_FIELDS               = it_input_fields

    ct_partner_attributes         = it_partner_attributes

  EXCEPTIONS

    ERROR_OCCURRED                = 1

    DOCUMENT_LOCKED               = 2

    NO_CHANGE_ALLOWED             = 3

    NO_AUTHORITY                  = 4

    OTHERS                        = 5

           .

In this if sy-subrc <> 0.

the error message has move error table and program will continue with next record.

Can anyone please tell me how to do this.

Thanks in advance.

Regards,

Suman

3 REPLIES 3

murtuza_chhatariya
Active Participant
0 Kudos
46

Hi,

If you are calling above FM in loop for every record of excel file. Try doing as below.

LOOP AT lt_excel_records TO wa_record.

     CALL FM

     IF sy-subrc = 0.

          APPEND wa_record TO lt_success_records.

     ELSE.

          APPEND wa_record TO lt_error_records.

     ENDIF.

ENDLOOP.

Let me know if you are searching someth

Thanks,

Murtuza

0 Kudos
46

Hi Murtuza,

Thanks for Reply.

but i am calling two more function modules along with that.

Loop it_exc_rec into wa_exc_rec.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'.

if sy-subrc <> 0.

append wa_rec to wa_error_rec.

else.

here it has again go to loop and pick 2nd rec.

endif.

because once it is sy-subrc = 0.

then it should to continue the process with calling another FM


call function 'CRM_ORDER_SAVE'.

How can do this. Can you please help me.


0 Kudos
46

Write Continue command if you want to skip the record.

Regards,

Murthy