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

Text file with Binary data - upload on Presentation server

Former Member
6,166

Hi All,

I have Text file which contains Binary data of an image.

Data is in the form of continuous string of 50000 characters. I am not sure how to take this TEXT file data into internal table using GUI_UPLOAD.

Please help.

Thanks and Regards,

Jitendra

17 REPLIES 17
Read only

michael_kozlowski
Active Contributor
0 Likes
4,526

This message was moderated.

Read only

0 Likes
4,526

Hi Michael,

Unfortunately above tread concludes nothing.

My data from file is getting converted to HEX form after using GUI_UPLAOD with BIN file type.

I want data in original form.

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
4,526

I'm sorry but your posts just don't make a lot of sense. Text and binary are two completely different formats. You can't have a "text" file with binary data in it. If you assign TXT extension, this does not change the file to "text".

The second post is even more confusing - what is "original form" and how exactly are you seeing that "file is getting converted to HEX form"? How did you expect to see binary content in SAP? Ones and zeroes?

You might want to clarify what you are doing.

Read only

0 Likes
4,526

Hi Jelena,

My file has extension TXT and it contains - 8CCA8D318D988DFF8E668ECE8F368F9E9006906E90D6913F91A89211927A92E3934D93B69420948A94F4955F95C9.... ( 50000 Continuous characters )

I want to get these 50000 characters string into an internal table using GUI_UPAOAD.

Read only

Former Member
0 Likes
4,526

Hi Jitendra,

Try this Fm after uploading the data,

SCMS_BINARY_TO_STRING.


Regards,

Ramesh

Read only

0 Likes
4,526

HI Ramesh,

As suggested, Below code I tried:

CALL FUNCTION 'SCMS_BINARY_TO_STRING'

      EXPORTING

        input_length  = v_fsize

      IMPORTING

        text_buffer   = lv_string

      TABLES

        binary_tab    = lt_content

      EXCEPTIONS

        failed        = 1

        OTHERS        = 2.

But my query is how to get 50000 characters string into internal table lt_content ?

Is there any FM for this?

Read only

Clemenss
Active Contributor
0 Likes
4,526

Hi Jitendra Nayak,

Just tell the community what you got and what you want to accomplish. Got a file of (obviously) binary data - what is the content and/or the origin and (planned) use?

METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD with type BIN will uploaf whatever you got into an internal table of whatever type you need. The content as shown above looks like hex characters, so a table of type x records may be suitable.

TYPES hexline type X lengght 100."Or any other length preferred

DATA lt_content TYPE TABLE OF hexline.

Using FUNCTION 'SCMS_BINARY_TO_STRING' you may convert it back to a string - whatever the use will be.

Thanks

Clemens

Read only

Former Member
0 Likes
4,526

HI Clemans,

I have a file with TXT format which contains data -

8CCA8D318D988DFF8E668ECE8F368F9E9006906E90D6913F91A89211927A92E3934D93B69420948A94F4955F95C9.... ( 50000 Continuous characters ).

Question 1 : As per 3rd Party, this is Binary data. I am confused now whether it's Binary data or Hex data.

Question 2 : I am using GUI_UPLAOD with ' BIN' type and providing this as Input file. Output table is Hex for GUI_UPLAOD.

  TYPES: BEGIN OF hex_record,

           myhex(255) TYPE x,

         END OF hex_record.

DATA : ls_out TYPE  hex_record,

              lt_out TYPE STANDARD TABLE OF hex_record.

I am not sure what format it converts the data after passing to GUI_UPLOAD.

Question 3 :I need to pass this data to FM 'SAPSCRIPT_CONVERT_BITMAP_BDS' using parameter bitmap_file or further processing.  IS it possible..

Please suggest.

Thank you..

Read only

matt
Active Contributor
0 Likes
4,526

When you open the file in a text editor, do you actually see

8CCA8D318D988DFF8E668ECE8F368F9E9006906...

or do you see garbage?


If the first, then your file is not binary. It is TEXT. You must read it as text, then convert the text to hexadecimal.



Read only

Former Member
0 Likes
4,526

Hi Matthew,

When I open the file in Text editor , I See 8CCA8D318D988DFF8E668ECE8F368F9E9006906..

So as as suggested it's 'Text' file. But how binary File should look like? Only 1s and 0s..

Also  when I tried to load file using  file type ASC in GUI_UPLAOD i see only 1 line with some 512/1024 characters ( = to  line type for internal table )

How to get 50000 characters long continuous string  into internal table...

Please suggest.

Read only

matt
Active Contributor
0 Likes
4,526

What is the difference between a text file and a binary file?

This is really quite basic stuff. If you want to know what a binary file looks like, try opening any .exe file in notepad.

Read only

Former Member
0 Likes
4,526

Hey Matthew,

I guess It's not necessary that Binary file should always consist of 1s and 0s. Correct me if I am wrong.

Also if we have some TXT file with above mentioned format, how will  you take 50000 characters long continuous string as it is using GUI_UPLAOD.

I couldn't find any approach on SCN at least..

Message was edited by: Jitendra Nayak

Read only

0 Likes
4,526

Hi Jitendra,

1: GUI_Upload works perfectly to upload this type pf files. I think you are looking at internal table in debugger that only shows initial 1024 or 512 bytes. I tested it myself with following code and it read the full file

**[[ ABAP Code

REPORT yy_read_file_hex.

PARAMETERS:

p_fnm1(1024) TYPE c OBLIGATORY DEFAULT 'D:\MY_FILES\IMG_HEXENCODE.TXT'.

TYPES:

BEGIN OF tt_fc,

    line TYPE string,

END OF tt_fc.

DATA:

lvfname TYPE string,

lv_len TYPE i,

lt_data TYPE STANDARD TABLE OF tt_fc,

ls_data TYPE tt_fc.

START-OF-SELECTION.

MOVE p_fnm1 TO lvfname.

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename                      = lvfname

*   FILETYPE                      = 'ASC'

*   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                    = lv_len

*   HEADER                        =

   TABLES

     data_tab                      = lt_data

* CHANGING

*   ISSCANPERFORMED               = ' '

  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.

   WRITE:/ 'File read error', sy-subrc.

   EXIT.

* Implement suitable error handling here

ENDIF.

WRITE:/ 'file Len:', lv_len.

*** End of program

**]] ABAP Code

In this case the variable lv_len returned the correct size of file verifying that all file is read.

2: From the look of it, the filetype you receive is in Hex encoding. I assume what happen here is that the third party has an image file (example jpg or bmp), this is in binary format. They convert this binary format to Hex format so it can be transferred as a text file. This is because binary can have special characters in it that are not readable in text format. but when binary is converted to Hex, it can be put to a text file and transmitted as text.

Hope this will help you!

RJv
Read only

matt
Active Contributor
0 Likes
4,526

Read the first three links that come up on the link I gave you before asking further questions about zeros and ones. You seem to have a fairly basic misunderstanding of the representation of data on computer systems and files.

When you got that straight in your mind I may continue with the rest of your questions.

Read only

Former Member
0 Likes
4,526

Hi Rashid,

I guess you are correct. binary data of file is converted to  Hex format so it can be transferred as a text file. I can see file length as  65538.

Now only query is to covert the 1 line data to multiple lines where each line has 128 characters in it.

Current Output:

Required Output:

Do we have any FM for it?

Please suggest.

Thanks and Regards,

Jitendra

Read only

Former Member
0 Likes
4,526

Hi All,

Can anybody please let me know how to covert the 1 line data to multiple lines where each line has 128 characters in it as shown above..

Thanks,

Jitendra

Read only

0 Likes
4,526

This reply is linked to my previous code posted above. Assuming that file is successfully read in internal table LT_DATA and also that LT_DATA has only one row. Following code will convert it into an internal table of 128 chars.


***[[ ABAP Code


TYPES: BEGIN OF tt_short,

        cline(128) TYPE c,

       END OF tt_short.

DATA: lt_short TYPE STANDARD TABLE OF tt_short,

       wa_short TYPE tt_short.

READ TABLE lt_data INTO ls_data INDEX 1.

IF sy-subrc = 0.

   CALL FUNCTION 'CONVERT_STRING_TO_TABLE'

     EXPORTING

       i_string               = ls_data-line

       i_tabline_length       = 128

     TABLES

       et_table               = lt_short

             .

ENDIF.

***]] ABAP Code

RJv