Application Development 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: 

Upload Image to sap and Save in ztable

Former Member
0 Kudos
2,009

Hi Experts,

I am trying to upload an image in a custom table zfrontend_upload.

The execution halts at a dump after I select the image to be uploaded.

This is my code-

*--------------------------------------------------------------------------------------

* Data Declarations.

*--------------------------------------------------------------------------------------

DATA: lt_file TYPE STANDARD TABLE OF FILE_TABLE,

       ls_file TYPE FILE_TABLE,

       lv_rc TYPE I,

       lv_filename TYPE string,"file_table-filename,

       lv_length TYPE I,

       lt_data TYPE RSANM_FILE_TABLE,

       lv_content TYPE XSTRING,

       wa_zfrontend_upload TYPE zfrontend_upload.

*--------------------------------------------------------------------------------------

* Select image from frontend system

*--------------------------------------------------------------------------------------

        cl_gui_frontend_services=>file_open_dialog(

          CHANGING

            file_table              lt_file     " Table Holding Selected image

            rc                      lv_rc  ).

        READ TABLE lt_file INTO ls_file INDEX 1.

        IF sy-subrc = 0.

          lv_filename = ls_file-filename.

        ENDIF.

*--------------------------------------------------------------------------------------

*      Upload selected image into SAP system.

*--------------------------------------------------------------------------------------

        cl_gui_frontend_services=>gui_upload(

          EXPORTING

            filename                = lv_filename  " Name of file

            filetype                  = 'BIN'

          IMPORTING

            filelength               lv_length      " File length

          CHANGING

            data_tab               = lt_data         " Transfer table for file contents

          EXCEPTIONS

            OTHERS              = 19 ).

*--------------------------------------------------------------------------------------

* Convert image into XSTRING format.

*--------------------------------------------------------------------------------------

   CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

     EXPORTING

       input_length = lv_length

     IMPORTING

       buffer           = lv_content                      " Image data

     TABLES

       binary_tab   = lt_data

     EXCEPTIONS

       failed           = 1

       OTHERS     = 2.

*--------------------------------------------------------------------------------------

* Save the photo in the ztable

*--------------------------------------------------------------------------------------

   wa_zfrontend_upload-SrNo = 1.

   wa_zfrontend_upload-photo lv_content.

   MODIFY zfrontend_upload FROM wa_zfrontend_upload .


Where do I go wrong?


Thank You in advance,

-Nimish Kate

1 ACCEPTED SOLUTION

SimoneMilesi
Active Contributor
0 Kudos
599

Sorry, but the dump screenshot is missing

How did you declared zfrontend_upload-photo?

7 REPLIES 7

SimoneMilesi
Active Contributor
0 Kudos
600

Sorry, but the dump screenshot is missing

How did you declared zfrontend_upload-photo?

0 Kudos
599

Hi Simone,

I got a dump before the debugger reached the part where zfrontend_upload comes into picture.

As for the declaration, the field photo has been declared of type HRTMC_XSTRING.

Here's the dump-

Thanks,

-NK

0 Kudos
599

So the dump is in GUI_UPLOAD since it happens in Func. Group SFES and the open dialog seems ok.

Which release are you running?
I cannot find in mine your "RSANM_FILE_TABLE" so i cannot give a try to your code.

0 Kudos
599

Hi simone,

My version of SAP is 7.4 SP level 0008.

Let me know if you need more details.

Thanks,

-NK

0 Kudos
599

Hi Simone Milesi,

The type of changing parameter data_tab is given to be Standard Table in the method GUI_UPLOAD. We cannot declare the table to be passed of the type Standard Table, So i used RSANM_FILE_TABLE to declare lt_tab in my code.

If you cannot find RSANM_FILE_TABLE in your SAP release, can you suggest me what type do I use to declare the table lt_tab?

Thanks,

-NK

0 Kudos
599

ok, using a similar table i replicated the dump and found solution in this thread

With this declaration i avoided the dump

DATA: lt_data TYPE STANDARD TABLE OF x255.

And the data is filled

0 Kudos
599

Hi Minish,

You can use /ORS/DATA_STREAM structure to get selected image RAW data.

Regards,

Praveer.