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

file create

Former Member
0 Likes
902

hello abap gurus,

in my scenario, i have to check if an entry in afield in an itab is less than 0,

i need to write the entire record into an error file.

i can check if the field value is less than zero,

but how to create and write in the error log file.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
874

If the condition failed then collect the error record in another internal table.

If you want to create the error file in thepresentation server then download that table in to presentation server by the following function module:

 CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = l_ofile1
        filetype                = 'ASC'
      TABLES
        data_tab                = p_local_table
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc <> 0.
      MESSAGE e000 WITH text-036.
    ENDIF.
  ENDIF.
ENDFORM.                    " download_audit_file

here l_ofile1 is presentation file path and p_local_table is the internal table where you collected the error data.

If you want to create the error file in application server then first:

1. Collecet the error records in a internal table.

2. Create a internal table containing only one column as string.]

3. concatenate each records for first internal table and append to the second table]

4. Open a dataset into the application server and write the error records into it.

DATA: l_string TYPE string.
  l_string = p_value_audit.

  CONCATENATE p_level l_string
               INTO wa_local-string SEPARATED BY c_tab.
  APPEND wa_local TO p_locl_tab.
  CLEAR: l_string, wa_local.
    


OPEN DATASET p_path_ofile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc = 0.
      CLEAR: wa_local.
      LOOP AT p_local_table INTO wa_local.
        TRANSFER wa_local TO p_path_ofile.
      ENDLOOP.
      CLOSE DATASET p_path_ofile.
    ELSE.
      MESSAGE e000 WITH text-035.
    ENDIF.


 OPEN DATASET p_path_ofile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc = 0.
      CLEAR: wa_local.
      LOOP AT p_local_table INTO wa_local.
        TRANSFER wa_local TO p_path_ofile.
      ENDLOOP.
      CLOSE DATASET p_path_ofile.
    ELSE.
      MESSAGE e000 WITH text-035.
    ENDIF.

8 REPLIES 8
Read only

Former Member
0 Likes
874

Hi Sarita,

itab and itab_error has same structure --declare both of them same

loop at itab where quantity le 0.

itab_error = itab.

append itab_error.

clear itab_error.

clear itab.

endloop.

Loop at itab_error.

write : /itab_error.

endloop.

aWARD POINTS IF HELPFUL

Thansk

VENKI

i

Read only

Former Member
0 Likes
874

HI saritha,

U can create a z table by refering t100 table and catch that error messages and append it to that z table.

If u are using call transaction then u should use BDCMSGCOLL Structure to catch the error logs.

Need ur reward points.

Thanks a

Ravi

Read only

Former Member
0 Likes
874

It is simple one,

declare one internal table which will have text field..

data : begin of i_error occurs 0,

text(255) type c,

end of i_error.

use describe command for ur internal table

if v_lines = 0.

pass ur values into internal table.

use gui_download FM to download the data into file.

endif.

I am not clear what is ur req ,if you need any more information,please let me know

Read only

0 Likes
874

Save your formatted error messages to internal table and use EXCEL_OLE_STANDARD_DAT to save the error to an excel file.

Read only

Former Member
0 Likes
875

If the condition failed then collect the error record in another internal table.

If you want to create the error file in thepresentation server then download that table in to presentation server by the following function module:

 CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = l_ofile1
        filetype                = 'ASC'
      TABLES
        data_tab                = p_local_table
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc <> 0.
      MESSAGE e000 WITH text-036.
    ENDIF.
  ENDIF.
ENDFORM.                    " download_audit_file

here l_ofile1 is presentation file path and p_local_table is the internal table where you collected the error data.

If you want to create the error file in application server then first:

1. Collecet the error records in a internal table.

2. Create a internal table containing only one column as string.]

3. concatenate each records for first internal table and append to the second table]

4. Open a dataset into the application server and write the error records into it.

DATA: l_string TYPE string.
  l_string = p_value_audit.

  CONCATENATE p_level l_string
               INTO wa_local-string SEPARATED BY c_tab.
  APPEND wa_local TO p_locl_tab.
  CLEAR: l_string, wa_local.
    


OPEN DATASET p_path_ofile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc = 0.
      CLEAR: wa_local.
      LOOP AT p_local_table INTO wa_local.
        TRANSFER wa_local TO p_path_ofile.
      ENDLOOP.
      CLOSE DATASET p_path_ofile.
    ELSE.
      MESSAGE e000 WITH text-035.
    ENDIF.


 OPEN DATASET p_path_ofile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc = 0.
      CLEAR: wa_local.
      LOOP AT p_local_table INTO wa_local.
        TRANSFER wa_local TO p_path_ofile.
      ENDLOOP.
      CLOSE DATASET p_path_ofile.
    ELSE.
      MESSAGE e000 WITH text-035.
    ENDIF.

Read only

Former Member
0 Likes
874

thank you very much for all of your responses.

but,

in my scenario,

i have to write scentences, that so and so field has so and so error.

in the second line , i should display, the error record.

i think seshu is near to solution for this, but,

i didnot understand many thing in your solution, what is describe and all,

can u be more clear plz.

thank you

Read only

0 Likes
874

see the example to update custom tables and if any error then it will display report.

************************************************************************

  • Program : ZFFII002 (Load 821 Freight Charge Information)

  • Type : Update

  • Author : Seshu Maramreddy

  • Date : 05/02/2005

  • Transport : DV3K919411

  • Transaction: None

  • Description: This program will upload the data into

  • ZFREIGHT table from Flat file

*

************************************************************************

REPORT ZFFII002 LINE-SIZE 90

LINE-COUNT 40

no standard page heading.

  • Tables

tables : zfreight. " Freight Charge data

*Constants

Constants : c_x(1) type c value 'X',

TAB TYPE X VALUE '09'. " Delimter

  • Variables

data : flag_error type c . " Flag variable

  • Internal tables

  • Internal table for zfreight

data : t_zfreight like zfreight occurs 0 with header line.

  • Internal table for Flat file

data : begin of t_text occurs 0,

text(1024) type c,

end of t_text.

  • Internal table for Format Internal table

data : begin of t_upload occurs 0,

BUDAT(8) type c, " Post Date

BELNR like zfreight-belnr," Account # / Cost Center

tknum like zfreight-tknum," Bill of Lading

caref like zfreight-caref," Carrier Ref

carid like zfreight-carid," Carrier ID

frchg(11) type c," like zfreight-frchg," Freight Charge

stdat(8) type c, " Date Settled

stcod like zfreight-stcod," Status Code

end of t_upload.

  • Internal table for Simulation Message

DATA: BEGIN OF t_msgs OCCURS 0,

text LIKE t100-text," Message text

END OF t_msgs.

**************************************************************

                                  • Selection-Screen *************************

**************************************************************

selection-screen : begin of block blk with frame title text-001.

PARAMETERS: P_file(128) type c LOWER CASE." File name

selection-screen : skip 1.

parameters : p_siml as checkbox default c_x." Simulation

selection-screen : end of block blk.

**************************************************************

                                  • Start-of-Selection ************************

**************************************************************

start-of-selection.

refresh t_msgs.

IF p_siml IS INITIAL.

  • 'SIMULATION ===> OFF'.

MESSAGE i099(zz) INTO t_msgs-text.

APPEND t_msgs.

ELSE.

  • 'SIMULATION ===> ON'.

MESSAGE i100(zz) INTO t_msgs-text.

APPEND t_msgs.

ENDIF.

  • Open the file at Application Server.

perform open_file.

  • Read the file into internal table.

perform read_file.

  • Close the file

PERFORM close_file .

  • Count the data from File

PERFORM data_get_file.

  • Read the data from internal table as proper format

perform read_data.

  • Coverted as date format in ZFREIGHT Table

perform format_table.

if p_siml is initial.

  • Inserting the records to ZFREIGHT Table

perform modify_table.

else.

perform nochange_table.

endif.

  • Displays Log message

PERFORM write_log.

TOP-OF-PAGE.

CALL FUNCTION 'Z_HEADER'

  • EXPORTING

  • FLEX_TEXT1 =

  • FLEX_TEXT2 =

  • FLEX_TEXT3 =

.

*END-OF-SELECTION.

&----


*& Form data_get_file

&----


  • Count the records from Flat file

----


FORM data_get_file.

DATA: l_count TYPE i.

describe table t_text lines l_count.

IF sy-subrc = 0 OR

( sy-subrc NE 0 AND l_count LE 0 ).

MESSAGE i124(zz) WITH l_count INTO t_msgs-text.

APPEND t_msgs.

else.

flag_error = 'Y'.

endif.

ENDFORM. " data_get_file

&----


*& Form open_file

&----


  • Open the file at application Server

----


FORM open_file.

Open dataset p_file for input in text mode .

if sy-subrc ne 0.

message i123(ZZ).

stop.

endif.

ENDFORM. " open_file

&----


*& Form read_file

&----


  • Read the file into internal table

----


FORM read_file.

DO.

CLEAR t_text.

READ DATASET P_FILE INTO t_TEXT.

IF SYST-SUBRC <> 0.

EXIT.

ENDIF.

APPEND T_TEXT.

ENDDO.

ENDFORM. " read_file

&----


*& Form close_file

&----


  • Close the file

----


FORM close_file.

CLOSE DATASET P_FILE.

ENDFORM. " close_file

&----


*& Form write_log

&----


  • Displays Log message

----


FORM write_log.

SKIP 3.

LOOP AT t_msgs.

WRITE: /15 t_msgs-text.

SKIP 2.

ENDLOOP.

ENDFORM. " write_log

&----


*& Form read_data

&----


  • Delimter

----


FORM read_data.

loop at t_text.

split t_text-text at tab into t_upload-budat

t_upload-belnr

t_upload-tknum

t_upload-caref

t_upload-carid

t_upload-frchg

t_upload-stdat

t_upload-stcod.

append t_upload.

clear t_upload.

endloop.

ENDFORM. " read_data

&----


*& Form format_table

&----


  • Assign the data to Zfreight table

----


FORM format_table.

loop at t_upload.

  • Assign sy-mandt to zfreight-mandt.

t_zfreight-mandt = sy-mandt.

  • Assign the data as per ZFREIGHT Table

t_zfreight-budat = t_upload-budat.

  • Account # / Cost Center

t_zfreight-belnr = t_upload-belnr.

  • Bill of Lading

t_zfreight-tknum = t_upload-tknum.

  • Carrier Ref

t_zfreight-caref = t_upload-caref.

  • Carrier ID

t_zfreight-carid = t_upload-carid.

  • Freight Charge

t_zfreight-frchg = t_upload-frchg.

  • Assign date as per ZFREIGHT table

t_zfreight-stdat = t_upload-stdat.

  • Status Code

t_zfreight-stcod = t_upload-stcod.

  • User name

t_zfreight-ERNAM = sy-uname.

  • Current Date

t_zfreight-ERDAT = sy-datum.

  • Current Time

t_zfreight-ERZET = sy-uzeit.

*Program name

t_zfreight-ERPGM = sy-repid.

append t_zfreight.

clear : t_zfreight.

endloop.

ENDFORM. " format_table

&----


*& Form modify_table

&----


  • Inserting the records to ZFREIGHT Table

----


FORM modify_table.

commit work.

modify zfreight from table t_zfreight.

if sy-subrc eq 0.

MESSAGE i125(zz) INTO t_msgs-text.

APPEND t_msgs.

endif.

ENDFORM. " modify_table

&----


*& Form nochange_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM nochange_table.

rollback WORK.

MESSAGE i109(zz) INTO t_msgs-text.

APPEND t_msgs.

ENDFORM. " nochange_table

Read only

Former Member
0 Likes
874

thanks abhishek.