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

Continue the Processing even on Error or Warning Message, inside Loop.

Former Member
0 Kudos
6,679

Hi All,

I have already a running code, where the input is provided in terms of Work Area.

Here a number of FMs and Standard Routines have been invoked based on Work Area content.

Now, my requirement is to put the same peice of code inside loop.

But the problem is that the same peice of code should run for each entry ( as work area ) in loop,

but when then system encounters erroe for any entries the code terminates over there only, with the error message

of current loop pass and the whole process haults.

Now, I need to continue with the next loop entry, but it is not possible.

Commenting these Error Message Statement is not possible, since it a standard code.

I need to collect all the error messages in some internal table and then show the result for all the loop entries at the end of the loop.

I belive there is some FM for this purpose, but I am not sure.

Can some one help me here ?

Thanking You All.

1 ACCEPTED SOLUTION
Read only

Former Member
2,133

Ankit,

Search for *collect*messages* in SE37.

But I believe this will not help you much. If the error message is from a standard code, there is good chance that SAP will automatically stop processing. For example if a FM returns subrc > 0, there will be some code for exception handling which might result in throwing an error. When an error is encountered, SAP halts the process as opposed to a warning where the process continues.

If the result comes back to your custom program, then you should be able to continue processing. Can you share some sample code and tell us where the error happens.

Thanks,

Vikram.M

14 REPLIES 14
Read only

Former Member
2,134

Ankit,

Search for *collect*messages* in SE37.

But I believe this will not help you much. If the error message is from a standard code, there is good chance that SAP will automatically stop processing. For example if a FM returns subrc > 0, there will be some code for exception handling which might result in throwing an error. When an error is encountered, SAP halts the process as opposed to a warning where the process continues.

If the result comes back to your custom program, then you should be able to continue processing. Can you share some sample code and tell us where the error happens.

Thanks,

Vikram.M

Read only

0 Kudos
2,133

Hi Vikram,

Thanks for the reply.

I will certainly check and revert.

Thanking You All.

Read only

arindam_m
Active Contributor
0 Kudos
2,133

Hi,

Usually all messages in SAP has some parts

MSGID-Message Class ID

MSGNO-Message number in Class

MSGVAR1- Message text container 1 length 50 char

MSGVAR2- Message text container 2 length 50 char

MSGVAR3- Message text container 3 length 50 char

MSGVAR4- Message text container 4 length 50 char

You can create a internal table sa ITAB_ERR and simply put this values in this table via a work area instead of using the message statement. Then At end of program you can loop through ITAB_ERR and write the errors in list.

Cheers,

Arindam

Read only

Former Member
0 Kudos
2,133

Hi Arindam,

Thanks for the reply, but this way will not help me to get my code executed for all the loop entries.

It will stop processing once an error message is encountered, and thus other loop entries will not be processed.

Thanking You All.

Read only

arindam_m
Active Contributor
0 Kudos
2,133

Hi,

Your processing will stop only if the statement

MESSAGE ... with TYPE 'E' is executed. NO matter what FM you use with in the loop all set SY_SUBRC and return message text using SYSTEM parameters SY-MSGID, SY-MSGNO, SY_MSGV1, SY_MSGV2, SY_MSGV3, SY_MSGV4.

So replace the these MESSAGE statement with:

W_ITAB_ERR-MSGID = SY-MSGID.

W_ITAB_ERR-MSGNO = SY-MSGNO.

W_ITAB_ERR-MSGVAR1 = SY_MSGV1.

W_ITAB_ERR-MSGVAR2 = SY_MSGV2.

W_ITAB_ERR-MSGVAR3 = SY_MSGV3.

W_ITAB_ERR-MSGVAR4 = SY_MSGV4.

APPEND w_itab_err INTO ITAB_ERR.

Cheers,

Arindam

Read only

Former Member
0 Kudos
2,133

Hi Arindam,

Thanks once again for the reply, but since it is a standard code,

so I can not do any modification there.

Thanking You All.

Read only

Former Member
0 Kudos
2,133

Hi,

  Which standard code are you changing? The messaging needs to be done depends on that.

Thanks

Naren

Read only

Former Member
0 Kudos
2,133

Hi Narendran,

Thanks for the reply.

I am not changing the Standard Code, rather I have to do the changes in my Z* Code.

I am tweaking the existing code, to work inside loop, the existing code is working for Work Area.

Thanking You All.

Read only

Former Member
0 Kudos
2,133

It depends on which tcode / user exit you are changing.

Let's say in some of the HR transactions..in Portal...you can collect the messages...with type as error..and still continue with the remaining records..

Thanks

Naren

Read only

Former Member
0 Kudos
2,133

Hi Narendran,

It is from SD, and I am invoking RSNAST01 from my Z* Program.

I am also invoking couple of other Function Modules.

Thanking You All.

Read only

Former Member
0 Kudos
2,133

Hi,

It would be helpful if you post some of your codes here especially those that are in the loop process.

Thanks

-Jake

Read only

Former Member
0 Kudos
2,133

Hi All,

I am still searching for it, but could not get too helpful stuffs.

Well, have got Standard Reports SBAL_DEMO_01 and others which works but its not too helpful for me.

I just thought of the standard handals these stuffs,, ended with debugging DP95.

It works as expected in TCode DP95, here I got FMs like SD_MESSAGE_COLLECT, MESSAGES_STOP, MESSAGES_INITIALIZE, MESSAGES_GIVE and others but nothing worked for me.

DP95 also works inside Loop and captures well the Messages raised inside the User Exits.

Any one worked with these things, please post.

Thanking You All.

Read only

Former Member
0 Kudos
2,133

Hi Ankit,

Try below function modules.

CALL FUNCTION 'MESSAGES_INITIALIZE'.    "clear the buffer messages on starting

LOOP at <internal table>.    "to collect messages
CALL FUNCTION 'MESSAGE_STORE'            "add your message
  EXPORTING
    ARBGB = ''       "Message ID
    MSGTY = ''       "Type of message (I, S, W, E, A)
    TXTNR = ''       "Message Number

ENDLOOP.


CALL FUNCTION 'MESSAGES_SHOW'.    "Show messages at end

Regards,

Mordhwaj

Read only

Former Member
0 Kudos
2,133

Hi Ankit

We can collect the error messages by using below function modules..

Before processing the loop use the fm

data: wa_appl_log1  TYPE bal_s_log,
        wa_log_handle1 TYPE balloghndl,


if wa_log_handle1 is not initial.
*Delete previous messages
     call function 'BAL_LOG_REFRESH'
       EXPORTING
         i_log_handle  = wa_log_handle1
       EXCEPTIONS
         log_not_found = 1
         others        = 2.
   endif.

   clear wa_appl_log1.
* define some header data of this log
   wa_appl_log-aluser    = sy-uname.
   wa_appl_log-alprog    = sy-repid.

* create a log
   call function 'BAL_LOG_CREATE'
     EXPORTING
       i_s_log                = wa_appl_log1
     IMPORTING
       e_log_handle           = wa_log_handle1
     EXCEPTIONS
       og_header_inconsistent = 1
       others                 = 2.

   if sy-subrc <> 0.
     message id sy-msgid type sy-msgty number sy-msgno
           with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

Then Inside the loop collect the error messages in a variable and add the messages to log


data: msg type string,

         itype type string.

loop...

concatenate 'your error mess'  msg into msg

message e001(00) INTO ITYPE with msg.

perform add_message.

endloop..

form add_message.

data: lw_appl_msg1 type bal_s_msg .
* Define data of message for Application Log
   lw_appl_msg1-msgty     = sy-msgty.
   lw_appl_msg1-msgid     = sy-msgid.
   lw_appl_msg1-msgno     = sy-msgno.
   lw_appl_msg1-msgv1     = sy-msgv1.
   lw_appl_msg1-msgv2     = sy-msgv2.
   lw_appl_msg1-msgv3     = sy-msgv3.
   lw_appl_msg1-msgv4     = sy-msgv4.
   IF lw_appl_msg1-msgty = 'E'.
     lw_appl_msg1-probclass = '1'.
   ELSEIF lw_appl_msg1-msgty = 'W'.
     lw_appl_msg1-probclass = '2'.
   ELSE.
     lw_appl_msg1-probclass = '3'.
   ENDIF.
* Add this message to log file
   call function 'BAL_LOG_MSG_ADD'
     EXPORTING
       i_log_handle  = wa_log_handle1
       i_s_msg       = lw_appl_msg1
     EXCEPTIONS
       log_not_found = 0
       others        = 1.

   if sy-subrc <> 0.
     message id sy-msgid type sy-msgty number sy-msgid
             with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   endif.

endform.

Finally display the error log..


data: lwa_display_profile type bal_s_prof,
           lit_log_handle type bal_t_logh.

* get a prepared profile
   call function 'BAL_DSP_PROFILE_POPUP_GET'
     IMPORTING
       e_s_display_profile = lwa_display_profile
     EXCEPTIONS
       others              = 1.

   if sy-subrc <> 0.
     message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   endif.

* use grid for display if wanted
   lwa_display_profile-use_grid = 'X'.
   lwa_display_profile-title = text-007.                     "#EC *

* set report to allow saving of variants
   lwa_display_profile-disvariant-report = sy-repid.
   lwa_display_profile-disvariant-handle = 'LOG'.

   append wa_log_handle to lit_log_handle.

*Display Application Log
   call function 'BAL_DSP_LOG_DISPLAY'
     EXPORTING
       i_s_display_profile = lwa_display_profile
       i_t_log_handle      = lit_log_handle.

Hope it helps..

Regards,

Suganya