Skip to Content
author's profile photo Former Member
Former Member

Upload file in XSTRING format in SE38 report program

Hi All,

We have a very typical requirement of uploading attachments for Infotype using both Frontend(Web-Dynpro ABAP) and Backend(SE38 report program).

From frontend it is very simple as we directly get the data in XSTRING format. However, from backend I am facing some difficulty in getting data into XSTRING format.

1st I tried using GUI_UPLOAD in BIN mode and it gives me a dump which points to some SAP standard error in transferring data(frankly i donno what is going on there)...Ok.... dump is due to output table type as string. when i change it to char1024 there is no more error but the output data looks like some weird combination of Chinese characters, # and ~.

2nd I tried GUI upload in ASC mode and then convert the text into XSTRING but i donno if the file structure will remain stable by doing so.... (here GUI upload does not give me any dump or error)

3rd - search for similar blogs but failed finding anything which is quite relevant to the requirement.

Here is the code which I used for BIN mode:

DATA: gt_bin_data TYPE STANDARD TABLE OF char1024.
DATA: gd_file_length TYPE i.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = p_file
   FILETYPE                      = 'BIN'
*   HAS_FIELD_SEPARATOR           = ' '
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
 IMPORTING
   FILELENGTH                    = gd_file_length
*   HEADER                        =
  tables
    data_tab                      = gt_bin_data
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   NO_AUTHORITY                  = 6
*   UNKNOWN_ERROR                 = 7
*   BAD_DATA_FORMAT               = 8
*   HEADER_NOT_ALLOWED            = 9
*   SEPARATOR_NOT_ALLOWED         = 10
*   HEADER_TOO_LONG               = 11
*   UNKNOWN_DP_ERROR              = 12
*   ACCESS_DENIED                 = 13
*   DP_OUT_OF_MEMORY              = 14
*   DISK_FULL                     = 15
*   DP_TIMEOUT                    = 16
*   OTHERS                        = 17
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Any help would be appreciated.

Cheers,

Kunjal

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2012 at 12:21 PM

    "DATA: gt_bin_data TYPE STANDARD TABLE OF char1024."

    you have an error in your data declarations. The type should be type table of tbl1024.

    after the 'BIN' upload use the SCMS_BINARY_TO_XSTRING function module to convert binary table to xstring....very simple process and flawless for me.

    BTW, this has been discussed at length in these forums previously. May I suggest a search before posting in the future....will save you a lot of time, since it is unlikely that you will come across a problem that has not been discussed here previously.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hey man,

      You did not mentioned what type is ty_data_tab_bin and w_data_tab_bin

      and data_tab and w_data_tab and in above given code (Sumodh P Jun 21, 2010 11:25 AM).

      Copy same code to your sample program you will get plenty of syntax error.

  • author's profile photo Former Member
    Former Member
    Posted on Jun 21, 2010 at 08:33 AM

    i guess you are uploading some PDF file.. right?

    yes.. when it is uploaded with BIN format..it will come in those Chinese and ## type only.. (you try to download the same.. you will find your PDF back)..

    you cant read your PDF file data by uploading with GUI_DOWNLOAD.. you need to upload a XML.. then you can use ST to transform data to your required format.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 21, 2010 at 09:25 AM

    Hi,

    Below is the code for the filetype BIN

    DATA : conv1 TYPE REF TO cl_abap_conv_in_ce,

    view1 TYPE REF TO cl_abap_view_offlen.

    DATA lv_bin TYPE xstring.

    DATA: lv_tablenc TYPE i ,

    lv_tabnamec(10) TYPE c .

    FIELD-SYMBOLS : <gs_upload_table> TYPE STANDARD TABLE,

    <gs_upload_wa> TYPE ANY.

    DATA : gv_ref TYPE REF TO data,

    gv_tab TYPE REF TO data.

    CREATE DATA gv_ref TYPE ty_data_tab_bin.

    ASSIGN gv_ref->* TO <gs_upload_wa>.

    CREATE DATA gv_tab TYPE TABLE OF ty_data_tab_bin.

    ASSIGN gv_tab->* TO <gs_upload_table>.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = lv_filename_str

    FILETYPE = lv_filetype

    tables

    data_tab = <gs_upload_table>

    EXCEPTIONS

    FILE_OPEN_ERROR = 1

    FILE_READ_ERROR = 2

    NO_BATCH = 3

    GUI_REFUSE_FILETRANSFER = 4

    INVALID_TYPE = 5

    NO_AUTHORITY = 6

    UNKNOWN_ERROR = 7

    BAD_DATA_FORMAT = 8

    HEADER_NOT_ALLOWED = 9

    SEPARATOR_NOT_ALLOWED = 10

    HEADER_TOO_LONG = 11

    UNKNOWN_DP_ERROR = 12

    ACCESS_DENIED = 13

    DP_OUT_OF_MEMORY = 14

    DISK_FULL = 15

    DP_TIMEOUT = 16

    OTHERS = 17

    .

    • End UCC

    IF sy-subrc <> 0.

    RAISE upload_failed.

    ENDIF.

    • Start UCC

    REFRESH: t_data_tab_bin[], data_tab[].

    • CONVERSION binary to char.structure...

    LOOP AT <gs_upload_table> ASSIGNING <gs_upload_wa>.

    MOVE-CORRESPONDING <gs_upload_wa> TO w_data_tab_bin.

    MOVE w_data_tab_bin-raw TO lv_bin. " type string required for class

    conv1 = cl_abap_conv_in_ce=>create( input = lv_bin ).

    view1 = cl_abap_view_offlen=>create_legacy_view( w_data_tab ).

    CALL METHOD conv1->read( EXPORTING view = view1 IMPORTING data = w_data_tab ).

    APPEND w_data_tab TO data_tab.

    ENDLOOP.

    With Regards,

    Sumodh.P

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      CREATE DATA gv_ref TYPE ty_data_tab_bin.

      ASSIGN gv_ref->* TO <gs_upload_wa>.

      CREATE DATA gv_tab TYPE TABLE OF ty_data_tab_bin.

      ASSIGN gv_tab->* TO <gs_upload_table>.

      what should be the type of "ty_data_tab_bin" in the above code. I tried using table to type string but it dumps.

      Regards,

      Dileep

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.