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

Error when passing data from app server...

aris_hidalgo
Contributor
0 Likes
806

Hello Experts,

I am encountering an error when trying to pass data from application server

to my internal table. Below is the error:

"You cannot convert the character set"

Hope you can help me guys.Thank you and take care!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
775

Try using addition : IGNORING CONVERSION ERRORS and check if you still encounter the same error.

Regards

Eswar

7 REPLIES 7
Read only

Former Member
0 Likes
776

Try using addition : IGNORING CONVERSION ERRORS and check if you still encounter the same error.

Regards

Eswar

Read only

0 Likes
775

Hi Eswar,

How do I that?Thanks again!

Read only

0 Likes
775

Viray,

Addtion is for OPEN DATASET statement.

>OPEN DATASET <dsn> FOR ...

> IGNORING CONVERSION ERRORS.

Check below extract from help:


Addition 4 
... IGNORING CONVERSION ERRORS 


Effect 
This addition ensures that no exception is triggered when an error occurs during character set conversion and a file is accessed in read or write mode. If you do not use this addition, the exception CX_SY_CONVERSION_CODEPAGE is triggered when a conversion error occurs. (For details see READ DATASET and TRANSFER.) 

Regards

Eswar

Read only

0 Likes
775

Hi Again Eswar,

Thank you, it solved my problem. By the way, since the file that I am reading from

the app server is tab delimited, is there a way to split in respective fields of my itab?

Since I do not want to loop at my itab again to split because it might cause performance

issue. Below is my current code:


OPEN DATASET lv_filename
             FOR INPUT IN TEXT MODE
        ENCODING DEFAULT
        IGNORING CONVERSION ERRORS.

    IF sy-subrc = 0.
      WHILE sy-subrc = 0.
        READ DATASET lv_filename INTO wa_ftp_recs.
        TRY.
          CATCH cx_sy_codepage_converter_init.
        ENDTRY.
        TRY.
          CATCH cx_sy_conversion_codepage.
        ENDTRY.
        APPEND wa_ftp_recs TO lt_ftp_recs.
        CLEAR wa_ftp_recs.
      ENDWHILE.
    ENDIF.

    CLOSE DATASET lv_filename.

Thank you and take care!

Read only

0 Likes
775

You can use SPLIT command to get data into respective fields of structure.

Check below example:


DATA: str TYPE string.  " String

CONSTANTS: c_tab TYPE char01 VALUE
              cl_abap_char_utilities=>horizontal_tab.   " Tab Delimeter

OPEN DATASET <dsn> ....
IF sy-subrc eq 0.
   READ DATASET <dsn> INTO str.  " Read to String
   IF sy-subrc NE 0.
      EXIT.
   ELSE.
      SPLIT str AT c_tab INTO <wa>-fld1 <wa>-fld2 ... " Split at Delimeter into fields of work area
      APPEND <wa> TO <itab>. " Append Work Area to Structure
   ENDIF.
ELSE.
 ...." Error Message
ENDIF.

Regards

Eswar

Read only

Former Member
0 Likes
775

Hi

This is the Syntax for Uploading the File from Application Server .

  • Retrieve Data file from Application server(Upload from Unix)

DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

OPEN DATASET i_file FOR INPUT IN TEXT MODE.

IF sy-subrc NE 0.

MESSAGE e999(za) WITH 'Error opening file' i_file.

ENDIF.

DO.

  • Reads each line of file individually

READ DATASET i_file INTO wa_datatab.

  • Perform processing here

  • .....

ENDDO.

Reward points if it is usefull .....

Girish

Read only

Former Member
0 Likes
775

Hi ,

ABAP code for uploading a TAB delimited file into an internal table. See code below for structures. The code is base on uploading a simple txt file.

REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

DATA: ld_file LIKE rlgrap-filename.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 like pa0002-VORNA,

name2 like pa0002-name2,

age type i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Text version of data table

TYPES: begin of t_uploadtxt,

name1(10) type c,

name2(15) type c,

age(5) type c,

end of t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) type c.

constants: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

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

*START-OF-SELECTION

START-OF-SELECTION.

ld_file = p_infile.

OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

ELSE.

DO.

CLEAR: wa_string, wa_uploadtxt.

READ DATASET ld_file INTO wa_string.

IF sy-subrc NE 0.

EXIT.

ELSE.

SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

wa_uploadtxt-name2

wa_uploadtxt-age.

MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.

APPEND wa_upload TO it_record.

ENDIF.

ENDDO.

CLOSE DATASET ld_file.

ENDIF.

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

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

Reward points if it is usefull ..

Girish