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: 

Convert Binary data into readable content

Former Member
0 Kudos

Hi,

Could anyone tell me how i can convert Binary data into a readable content?(.xlsx/.txt)

I tried all the Function modules to convert BINARY_TO_STRING, BINARY_TO_TEXT and also XSTRING to String. But all of them gives data in readable format.

Also, i need to perform this function in background and hence cannot use 'GUI_DOWNLOAD'

Please help me provide the solution.

Thanks,

Deepika

1 ACCEPTED SOLUTION

Former Member

Hi all,

An update. I was able to resolve that issue by writing the XSTRING directly to file in .xslx extension using OPEN DATASET. No more pop-up appear.

Thank you all for the help. really appreciate.

Thanks,

Deepika

34 REPLIES 34

former_member215542
Active Participant
0 Kudos

You could try methods of class  CL_BCS_CONVERT

0 Kudos

Hi Pulkit,

Thanks for your reply. This class doesnt have any method which converts XSTRING data to text. I need to be converted to Text format and create file in AS using background job.

Thanks,

Deepika

0 Kudos

HI Deepika,

It does have a method to convert xstring to string

Method XSTRING_TO_STRING

pass your xstring data as parameter  IV_XSTR and also pass the xstrlen( xstring variable) to IV_CP

For ex

data:      l_xstring     type xstring,

              l_gui_codepage TYPE cpcodepage.

              l_string      type string.

l_xstring = <xstring value>

sorry for the wrong sample code earlier.

CALL FUNCTION 'SCP_GET_CODEPAGE_NUMBER'

     EXPORTING

       database_also = 'X'

     IMPORTING

       gui_codepage  = l_gui_codepage.

l_string = call method CL_BCS_CONVERT=>XSTRING_TO_STRING (

               IV_XSTR = l_xstring

               IV_CP = l_gui_codepage ).   

0 Kudos

I tried that and its of same result as BINARY_TO_STRING. the output has special characters. am i missing anything?

Thanks,

Deepika

0 Kudos

The zip file does not seem to have a binary format, it seems a different format.

Whats the standard program/ FM name that returns this file? Is there a documentation supporting it?

0 Kudos

Please remove the .txt extension. I had to put this extension as other files are not allowed to attach.

archanapawar
Contributor
0 Kudos

Hi Deepika,

Did you try FM SCMS_BINARY_TO_STRING?

If you need to download the file in background, you will need to use open dataset method and write the files on application server. You can't use GUI_DOWNLOAD in background.

0 Kudos

Hi Archana,

Thanks for your reply.

I tried FM SCMS_BINARY_TO_STRING, this FM converts to String from Xstring where data is not in readable format.


Thanks,

Deepika

0 Kudos

Ok Try SCMS_BINARY_TO_TEXT.

0 Kudos

Hi Deepika,

How are you getting the binary data? Can you provide some text file which contains the Binary Information?

Regards.

Praveer


Former Member
0 Kudos

the data i am pulling is of Rate table in TM system. There is std FM which will read the table and get the output in XSTRING (Solix) format.

0 Kudos

then you should convert xstring to binary first and then convert binary to text.

SCMS_XSTRING_TO_BINARY and SCMS_BINARY_TO_TEXT

0 Kudos

I tried all the options. all of them writes data in to a file which has unreadable content. mostly i will see special characters. i can write data in text file or excel.

0 Kudos

Hi Deepika,

Could you provide a sample text file? so we can try and provide the solution.

Because we don't know what kind of file you have and what kind of data it's contains.

We only can provide you the FM or Class name which are available in SAP system.

May be you are not passing any of the parameters of any of the given FM.

Regards.

Praveer.

Former Member
0 Kudos

Hi Praveer,

Here is the sample file. Please remove the file extension (.txt) from file as other extensions are not allowed to be attached in this message

1. From the Table, the std SAP program gets the data in XSTRING,

2. Using OPEN DATASET in BINARY MODE, the contents are written to Binary file in AS

3. I am converting this file to Text or .xlsx file types.

Thanks,

Deepika

0 Kudos

Hi Deepika,

The file , what you have provide, it's contains the Excel Information and file format should be xlsx.

Then only you can view the Information.

What is the Extension of this file in AL11? is it xlsx?

if not then try to put an extension and create a copy of the same file, and then open the same file through AL11 and is it displaying the information?

Please check.

If it's displaying the Information in AL11 Screen, then you have to debug the AL11 while displaying the Information and try to get the FM name what SAP is using to displaying the Information.

Regards.

Praveer.

0 Kudos

Hi Praveer,

You are right. The contents are meant for .xslx file.

I am not sure how i can check in AL11 but the program uses logical->physical file path method and i forced to save the file in .xlsx. I am able to see the contents, but a pop-up appears when i open that

excel has unreadable content and do you want to repair? when i say 'Yes', then another pop-up appears that the file has been repaired. we want to override this pop-up as we would like to automate the file reading process.

Thanks,

Deepika

0 Kudos

Hi Deepika,

The same message I was facing, when I change the extension and try to open the file in local system.

Go to AL11 T-Code.

there you can see all folder information of the Application Server.

Select the Folder, where the particular file is storing.

Select the File, and from the Tool Buttons, you select the View Document (not Sure about the name).

After press the tool button, you will able to see the File Contents in SAP screen.

If you are able to see the file content over there, then you have to debug the AL11 t-code at the selection of View Tool Button and check the SAP standard code.

Please check.

Regards.

Praveer.

0 Kudos

Hi Praveer,

I could not find any Directory having my file in it.

do you know how to find one where the file path is saved in FILE tcode?

thanks,

Deepika

0 Kudos

Hi Deepika,

How have you downloaded the file?

Or

Check in you program, where you are using READ DATASET and passing file information, there you can find the file Path.

If you are using DATASET statement, means file is in AS only.

Regards.

Praveer.

0 Kudos

yes, i know the file path but i don't see that path in AL11. will there be any mapping?

Thanks,

Deepika

0 Kudos

first try downloading it in foreground using GUI_DOWNLOAD.

I guess your file is not getting downloaded using open dataset. Check sy-subrc after open dataset and debug.

0 Kudos

Hi Deepika,

May be some setting from the basis side not sure.

You can do one thing, Send the File Path and AL11 screen information to your basis team and ask them to check.

If it's basis setting, so they would know better.

Regards.

Praveer.


0 Kudos

Hi Archana,

open dataset works good. the sy-subrc is 0. just that the pop-up appears which says unreadable content.

and yes, GUI_DOWNlOAD does all the magic and works perfectly fine. but i need that same thing to happen in AS.

Thanks,

Deepika

0 Kudos

Let me check with them. Thanks Praveer.

But do you have any idea about CODEPAGE? will that handle the pop-up?

thanks,

Deepika

0 Kudos

Could you provide us details on how you are using the open dataset statement in your program?

0 Kudos

Hi Pulkit,

below is the code

CATCH SYSTEM-EXCEPTIONS file_access_errors = 4.

*      OPEN DATASET lv_serv_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.

*      IF sy-subrc NE 0.

*        CATCH SYSTEM-EXCEPTIONS file_access_errors = 4.

*          OPEN DATASET lv_serv_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

*          LOOP AT lt_text_tab INTO x_text_tab.

**          READ DATASET lv_serv_dest_path INTO lv_data.

*            TRANSFER x_text_tab-line TO lv_serv_path.

*          ENDLOOP.

*          CLOSE DATASET lv_serv_path.

*        ENDCATCH.

*      ELSEIF sy-subrc = 0.

*        CLOSE DATASET lv_serv_path.

**    the case when the file already present and a job is running on this file.do not submit the job

*        WRITE: 'Rate table already present in the server path'. "TYPE 'I'. "#EC NOTEXT

**          lv_file_present = abap_true.

**          EXIT.

*      ENDIF.

*    ENDCATCH.


i am trying to write it to text file. But for excel, i am using Binary Mode.


*    CATCH SYSTEM-EXCEPTIONS file_access_errors = 4.

*      OPEN DATASET lv_serv_path FOR INPUT IN BINARY MODE.

*      IF sy-subrc NE 0.

*        CATCH SYSTEM-EXCEPTIONS file_access_errors = 4.

*          OPEN DATASET lv_serv_path FOR OUTPUT IN BINARY MODE.

*          LOOP AT lt_binary_content INTO x_bin_tab.

*            TRANSFER x_bin_tab-line TO lv_serv_path.

*          ENDLOOP.

*          CLOSE DATASET lv_serv_path.

*        ENDCATCH.

*      ELSEIF sy-subrc = 0.

*        CLOSE DATASET lv_serv_path.

**    the case when the file already present and a job is running on this file.do not submit the job

*        WRITE: 'Rate table already present in the server path'. "TYPE 'I'. "#EC NOTEXT

**          lv_file_present = abap_true.

**          EXIT.

*      ENDIF.

*    ENDCATCH.


Thanks,

Deepika

0 Kudos

Hi Deepika,

You can check the below link.

http://wiki.scn.sap.com/wiki/display/ABAP/Character+encoding+conversion

Regards.

Praveer.


0 Kudos

If the data is binary, you cannot use text mode.

For excel, why dont you download the file in .csv format? You can use .csv files to open with excel

0 Kudos

Yes. I am try both ways.

For .csv file, can use open dataset in BINARY mode and write it to .csv? should i need to mention the delimiter anywhere?

thanks,

Deepika

0 Kudos

Hi Deepika,

CSV extension changes will not work in your case, since the file has been generated in XLSX format, so if you want to convert in CSV, you have to do manually from the Excel end.

Excel -> File->Save as (CSV).

Regards.

Praveer.

0 Kudos

The file generated by the standard program seems to be text (I assume based on your open dataset and read dataset statement).


In order to make your file readable by excel you have to download the file in text format as a .csv file (which is comma delimited) or use xml transformation and convert your internal table to excel format.

You can find a lot of material on scn on how to transform an internal table as excel file.

But reading text data converting it to binary and saving it as .xls wont create an excel file

Former Member

Hi all,

An update. I was able to resolve that issue by writing the XSTRING directly to file in .xslx extension using OPEN DATASET. No more pop-up appear.

Thank you all for the help. really appreciate.

Thanks,

Deepika

0 Kudos

HI,

Can you help to share more info with some example code to understand better.