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

Creating a log file

Former Member
0 Likes
3,333

Hi experts,

I have a requirement like to create a error log file.

In my ABAP program If a file does not conatin any data in application server or if the relavant file does not exist in the application server if any Fm gives sy-subrc <> 0 .i have to create a log file and display error messages.How can i create that type of log file in the ABAP program?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,467

Hello Ravi,

Check these Programs:

SBAL_DEMO_01 Application Log: Demo program: Simple call

SBAL_DEMO_01_S Application Log: Doc: Display program

SBAL_DEMO_02 Application Log: Demo program: Various ways of collecting message

SBAL_DEMO_02_S Application Log: Doc: Display program

SBAL_DEMO_03 Application Log: Demo program: Get/read data in main memory

SBAL_DEMO_03_S Application Log: Doc: Display program

SBAL_DEMO_04 Application Log: Demo program: Various log formats

If useful reward.

Vasanth

8 REPLIES 8
Read only

Former Member
0 Likes
1,468

Hello Ravi,

Check these Programs:

SBAL_DEMO_01 Application Log: Demo program: Simple call

SBAL_DEMO_01_S Application Log: Doc: Display program

SBAL_DEMO_02 Application Log: Demo program: Various ways of collecting message

SBAL_DEMO_02_S Application Log: Doc: Display program

SBAL_DEMO_03 Application Log: Demo program: Get/read data in main memory

SBAL_DEMO_03_S Application Log: Doc: Display program

SBAL_DEMO_04 Application Log: Demo program: Various log formats

If useful reward.

Vasanth

Read only

Former Member
0 Likes
1,467

Hi Ravi,

declare one internal table with one field of type string

then append all the errors to one internal table

you can download that internal table with errors using GUI_DOWNLOAD

Read only

Former Member
0 Likes
1,467

If you are talking about downloading a file,with the error messages,then do,

DATA : BEGIN OF IT_ERRORS OCCURS 0,

LINE TYPE STRING,

END OF IT_ERRORS.

OPEN DATASET.....

IF SY-SUBRC <> 0.

IT_ERR0R-LINE = 'file not found'.

append it_error.

ENDIF.

like that you have to append all the errors to IT_ERROR.

finally based on the user option,use GUI_DOWNLOAD to download this IT_ERROR table to presentation server or USE OPEN DATASET,TRANSFER,CLOSE to download it to application server

Regards

srikanth

Read only

0 Likes
1,467

Hi All,

Thnaks. I will try that.

Read only

0 Likes
1,467

Hi ,

This post is follow up of previous post regarding creating error log file.

As you told if i create an internal table with one filed,

How can i upload somany errors and how can i seperate them.

For example...i have to raise this many errors:

1.If error in opening file using open data set.

2.if error in reading file using read data set

3.if failed to upload data from file into SAP

So wheere ever i have to raise error i have to upload to that error table.

So all these errors how can identify?..Will they display line by line in itab?..

Read only

0 Likes
1,467

normally if we get an error we dont proceed with the processing.in this case your error NO 2 will not come if you get error 1. will you agree?

in general,

if you still have many records to be populated that internal table,and you want to distinguish them,

you can added up the FILE NAME along with that text like,(check the below in BOLD)

1.If error in opening file using open data set <b><FILENAME></b>

2.if error in reading file using read data set <b><FILENAME></b>

etc..

so you can use CONCATENATE

<b>

CONCATENATE 
'error in opening file using open data set'
  V_FILENAME
  INTO IT_ERROR-TEXT.
append it_error.

</b>

Regards

Srikanth

Message was edited by: Srikanth Kidambi

Read only

0 Likes
1,467

Hi,

Check this :

if you want to capture errors while creating the file. check below code for this :

data : begin of i_errmsg occurs 0,
        x_msg(100) type c,
       end of i_errmsg.

1.Creating a File

OPEN DATASET x_file FOR output 
                            MESSAGE l_msg
                       IN text MODE ENCODING DEFAULT.
  x_RCODE = sy-subrc. 
  IF x_RCODE <> 0.
    <b>i_errmsg-x_msg = l_msg.
    append i_errmsg.</b>  
  endif.

2.Reading the file

OPEN DATASET x_file FOR input

MESSAGE l_msg

IN text MODE ENCODING DEFAULT.

x_RCODE = sy-subrc.

IF x_RCODE <> 0.

<b>i_errmsg-x_msg = l_msg.

append i_errmsg.</b>

endif.[/code]

internal table i_errmsg will contain the error message details.

Regards

Appana

Read only

0 Likes
1,467

Hello Ravi,

The best soln is to have two fields in your internal table one for ERRID and ERRMSG.

In the code you can populate the ERRMSG with the error text while you can manipulate the ERRID field depending on the type of the error. Eg. Error while opening the file can be FILEOPEN type error. Something related to data can be DATA etc. It purely depends on your requirement.

Last you can sort the table if you wish to display the error list on type or do not sort if you wish to display the log as in sequence.