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

How handale Error in Exception

ram_sahoo
Participant
0 Likes
1,941

Hi Experts,

I have report program to change the referance field value in Transaction code - FB02 using function module FI_DOCUMENT_CHANGE but thing is there we will run this report in background job,So at that time if any error message will through that function module then how to i will maintain that error in error log.Anyone can help me on requirement.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,305

Hi Ram,

You can define an internal table for storing the errors and exception. You can fill that internal table by checking the sy-subrc after the function is executed. The sy-subrc field will return the value referring to exception.

For eg.

NO_REFERENCE = 1

NO_DOCUMENT   = 2

  MANY_DOCUMENTS  = 3

WRONG_INPUT  = 4

OVERWRITE_CREDITCARD  = 5

OTHERS   = 6.


depending on the value stored in sy-subrc write a logic in CASE.. ENDCASE block and fill the internal table accordingly.


Hope this will help you.



Hi Ram,

You can define an internal table for storing the errors and exception. You can fill that internal table by checking the sy-subrc after the function is executed. The sy-subrc field will return the value referring to exception.

For eg.

NO_REFERENCE = 1

NO_DOCUMENT   = 2

  MANY_DOCUMENTS  = 3

WRONG_INPUT  = 4

OVERWRITE_CREDITCARD  = 5

OTHERS   = 6.


depending on the value stored in sy-subrc write a logic in CASE.. ENDCASE block and fill the internal table accordingly.


Hope this will help you.



6 REPLIES 6
Read only

Former Member
0 Likes
1,305

Hi,

You can generate one simple ALV report with list of exceptions occcured if any. So when ever an exception occurs, the list of exceptions can be seen in your ALV report which is generated if your program runs in background.

Ex :

CALL FUNCTION 'FI_DOCUMENT_CHANGE'

* EXPORTING

*   I_AWTYP                    =

*   I_AWREF                    =

*   I_AWORG                    = ' '

*   I_AWSYS                    = ' '

*   I_KUNNR                    = ' '

*   I_LIFNR                    = ' '

*   I_OBZEI                    = ' '

*   I_BUZEI                    =

*   I_BSEGC                    =

*   X_LOCK                     = 'X'

*   I_BUKRS                    =

*   I_BELNR                    =

*   I_GJAHR                    =

  TABLES

    t_accchg                   =

* EXCEPTIONS

*   NO_REFERENCE               = 1

*   NO_DOCUMENT                = 2

*   MANY_DOCUMENTS             = 3

*   WRONG_INPUT                = 4

*   OVERWRITE_CREDITCARD       = 5

*   OTHERS                     = 6

          .

IF sy-subrc <> 0.

"catch the exception here and update your execption itab(which needs to be created) and finally show the exceptions itab in your ALV report.

ENDIF.

Hope this helps you.

Thanks

KH

Read only

Former Member
0 Likes
1,305

Hi,

You can generate one simple ALV report with list of exceptions occcured if any. So when ever an exception occurs, the list of exceptions can be seen in your ALV report which is generated if your program runs in background.

Ex :

CALL FUNCTION 'FI_DOCUMENT_CHANGE'

* EXPORTING

*   I_AWTYP                    =

*   I_AWREF                    =

*   I_AWORG                    = ' '

*   I_AWSYS                    = ' '

*   I_KUNNR                    = ' '

*   I_LIFNR                    = ' '

*   I_OBZEI                    = ' '

*   I_BUZEI                    =

*   I_BSEGC                    =

*   X_LOCK                     = 'X'

*   I_BUKRS                    =

*   I_BELNR                    =

*   I_GJAHR                    =

  TABLES

    t_accchg                   =

* EXCEPTIONS

*   NO_REFERENCE               = 1

*   NO_DOCUMENT                = 2

*   MANY_DOCUMENTS             = 3

*   WRONG_INPUT                = 4

*   OVERWRITE_CREDITCARD       = 5

*   OTHERS                     = 6

          .

IF sy-subrc <> 0.

"catch the exception here and update your execption itab(which needs to be created) and finally show the exceptions itab in your ALV report.

ENDIF.

Hope this helps you.

Thanks

KH

Read only

Former Member
0 Likes
1,306

Hi Ram,

You can define an internal table for storing the errors and exception. You can fill that internal table by checking the sy-subrc after the function is executed. The sy-subrc field will return the value referring to exception.

For eg.

NO_REFERENCE = 1

NO_DOCUMENT   = 2

  MANY_DOCUMENTS  = 3

WRONG_INPUT  = 4

OVERWRITE_CREDITCARD  = 5

OTHERS   = 6.


depending on the value stored in sy-subrc write a logic in CASE.. ENDCASE block and fill the internal table accordingly.


Hope this will help you.



Read only

0 Likes
1,305

Hi Sneha,

Can you briefly explain me about of this my requirement and if possibilities with any sample logic.Canm you provide me.

Thanks,

Read only

0 Likes
1,305

Hi Ram,

Define 1 internal table with below structure:

types:

          begin of ty_error,

               errorid type n,

               errortext(50) type c, "you can also add some of the key fields of records which you are                                                  " changing

          end of ty_error.

Data: it_error type table of ty_error,

          wa_error type table of ty_error.

now after the FM gets executes write following piece of code:

CALL FUNCTION 'FI_DOCUMENT_CHANGE'

EXPORTING

i_awtyp =

i_awref =

i_aworg =

i_kunnr =

TABLES

it_accchg = it_accchg

EXCEPTIONS

NO_REFERENCE = 1

NO_DOCUMENT   =

MANY_DOCUMENTS  = 3

WRONG_INPUT  = 4

OVERWRITE_CREDITCARD  = 5

OTHERS   = 6.

if sy-subrc <> 0.

data: lv_subrc type sy-subrc.

lv_subrc = sy-subrc.

Case lv_subrc:

     when 1.

               wa_error-errorid = lv_subrc.

                wa_error-errortext = 'Description of the error'.

     when 2.

     .

     .

     .

Endcase.

Append this work area to it_error table.

Now you are having all the error records in it_error table.

Now just write a logic for display the ALV report on table it_error.

As you are running this report in background you can see the alv report in spool. Using TCODE Sp01.

Read only

Former Member
0 Likes
1,305

Hello,

You can handle the exception and display the message as:

CALL FUNCTION 'FI_DOCUMENT_CHANGE'

EXPORTING

i_awtyp =

i_awref =

i_aworg =

i_kunnr =

TABLES

it_accchg = it_accchg

EXCEPTIONS

no_reference = 1

no_documents = 1

many_documents = 1

wrong_input = 4

overwrite_creditcard = 5

OTHERS = 6.

if sy-subrc <> 0.

MESSAGE ID sy-msgid type sy-msgty NUMBER sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif,

When exception occurs message will be displayed.

Reward if useful.