<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to convert any file from directory into binary string xstring in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195466#M1375278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have requirement to convert the files from an application directory in binary string and pass to custom function module to load in another SAP server folder.  I have written the custom fm to load but have difficulty in converting the files from application directory.  These files can be in variety of format such as .doc, .xls, .pdf, .ppt or visio or any valid acceptable by SAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really need experts' help to acheive this.  Are there any SAP functions or class/methods that I can use :&lt;/P&gt;&lt;P&gt;1. to check user authorization to read and write a file from directory&lt;/P&gt;&lt;P&gt;2. to get list of files from directory and select right one using document number&lt;/P&gt;&lt;P&gt;3. to read each file and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;4. or read all files in one step and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone has sample code to do all steps or any step or any helpful information to convert into binary string please let me know.  Any help on this will be greatly appreciated.  I have searched the forum but unable to find answer for all steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Stacy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 10 Oct 2009 18:46:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-10-10T18:46:51Z</dc:date>
    <item>
      <title>How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195466#M1375278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have requirement to convert the files from an application directory in binary string and pass to custom function module to load in another SAP server folder.  I have written the custom fm to load but have difficulty in converting the files from application directory.  These files can be in variety of format such as .doc, .xls, .pdf, .ppt or visio or any valid acceptable by SAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really need experts' help to acheive this.  Are there any SAP functions or class/methods that I can use :&lt;/P&gt;&lt;P&gt;1. to check user authorization to read and write a file from directory&lt;/P&gt;&lt;P&gt;2. to get list of files from directory and select right one using document number&lt;/P&gt;&lt;P&gt;3. to read each file and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;4. or read all files in one step and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone has sample code to do all steps or any step or any helpful information to convert into binary string please let me know.  Any help on this will be greatly appreciated.  I have searched the forum but unable to find answer for all steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Stacy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Oct 2009 18:46:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195466#M1375278</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-10T18:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195467#M1375279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Stacy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check if the below information helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. to check user authorization to read and write a file from directory&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To check the authorization you can use the authority-check statement on the object s_dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
authority-check object 'S_DATASET'
id 'PROGRAM' field sy-repid
id 'ACTVT' field '33'
id 'FILENAME' field dir_path.        " Path of the application server filename
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. to get list of files from directory and select right one using document number&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For this you can use the FM &lt;STRONG&gt;EPS_GET_DIRECTORY_LISTING.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. to read each file and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: data TYPE string.

 OPEN DATASET zfile FOR INPUT IN BINARY MODE. 
if sy-subrc = 0.  
   READ DATASET zfile INTO data.  
  IF sy-subrc = 0. 
" use the FM SCMS_TEXT_TO_BINARY to convert the file to binary
 endif.
CLOSE DATASET file. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Oct 2009 20:07:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195467#M1375279</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-10T20:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195468#M1375280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Vikranth,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the information.  I have tried to use it but I have issues with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. to read each file and convert into binary string or xstring&lt;/P&gt;&lt;P&gt;When I execute OPEN DATASET zfile FOR INPUT IN BINARY MODE. the sy-subrc is 8. I am passing ZFILE -filename from the dir_list table received FM  EPS_GET_DIRECTORY_LISTING.  When I tried OPEN DATASET zfile FOR OUTPUT IN BINARY MODE. The sy-subrc is 0 but it fails in READ DATASET.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need your help to resolve these issues.  Should I use output mode or input mode?  And how I read the dataset successfully.  The files I want to read are word document, excel sheet, pdf doc, visio, etc.  Will OPEN DATASET zfile FOR INPUT IN BINARY MODE convert these files in binary?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anothe question I have is for the FM SCMS_TEXT_TO_BINARY'.  What mimetype should be passed to the FM for word document, excel sheet, pdf doc, visio, etc.  I think it varies based on the doc type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me to to convert all types of files in string or xstring.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;StacyLee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Oct 2009 03:45:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195468#M1375280</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-11T03:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195469#M1375281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Stacy,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the open dataset statement is working and just read dataset is not working, the problem could be with the declaration of the variable into which you are trying to read. As per SAP help for read statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
System Fields 
 
sy-subrc Meaning 
0 Data was read without reaching end of file. 
4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try declaring a variable of fixed length and check if the read dataset is working. For Eg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: BEGIN OF ITAB OCCURS 0,
TABLINE(5000),
END OF ITAB.

OPEN DATASET file_path FOR INPUT IN BINARY MODE.
DO.
READ DATASET file_path INTO ITAB.
IF SY-SUBRC EQ 0.
APPEND ITAB.
ENDIF.
ENDDO.

CLOSE DATASET file_path.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As per your questions, for reading a file in application server, you will have to use only OPEN DATASET PATH FOR INPUT. The FOR OUTPUT will only be used when creating a file in application server. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using OPEN DATASET in BINARY MODE will not convert the file into BINARY format directly. Its just used to read the file byte by byte. You could also try reading the fiel in TEXT MODE . The conversion to BINARY format should be done explicitly after reading the file. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Oct 2009 07:16:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195469#M1375281</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-11T07:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195470#M1375282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a few remarks:&lt;/P&gt;&lt;P&gt;- The most correct way to copy the files would be to use an OS command&lt;/P&gt;&lt;P&gt;- Do you need to copy or to move?&lt;/P&gt;&lt;P&gt;- You don't need to "convert", you just need to copy files ("binary safe copy" as one says)&lt;/P&gt;&lt;P&gt;- a "binary string" is a "xstring"&lt;/P&gt;&lt;P&gt;- You may read directly in binary using XSTRING type:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA binary TYPE xstring.
 OPEN DATASET fullpath FOR INPUT IN BINARY MODE. 
if sy-subrc = 0.  
   READ DATASET zfile INTO binary.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why do you want to use string type?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Oct 2009 12:22:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195470#M1375282</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-10-11T12:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195471#M1375283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Stacy,&lt;/P&gt;&lt;P&gt; You will have to use the class CL_BCS_CONVERT to get the Binary Format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read your files on the App server into a internal table. Now pass this internal table to the below method of the class.&lt;/P&gt;&lt;P&gt;You can pass different codepages to the method basing on your source document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code Snippet:&lt;/P&gt;&lt;P&gt;  TRY.&lt;/P&gt;&lt;P&gt;      cl_bcs_convert=&amp;gt;txt_to_xstring(&lt;/P&gt;&lt;P&gt;        EXPORTING&lt;/P&gt;&lt;P&gt;          iv_string   = gv_string&lt;/P&gt;&lt;P&gt;          iv_codepage = '4103'  "suitable for MS Excel, leave empty&lt;/P&gt;&lt;P&gt;          iv_add_bom  = 'X'     "for other doc types&lt;/P&gt;&lt;P&gt;          iv_size   = size&lt;/P&gt;&lt;P&gt;        IMPORTING&lt;/P&gt;&lt;P&gt;          EV_XSTRING  = binary_content ).&lt;/P&gt;&lt;P&gt;    CATCH cx_bcs.&lt;/P&gt;&lt;P&gt;      MESSAGE xyyy(zz).&lt;/P&gt;&lt;P&gt;  ENDTRY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if this help!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Oct 2009 13:57:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195471#M1375283</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-11T13:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195472#M1375284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for providing me with useful information.  I have tried XSTRING but I still have not successfully loaded the word doc or excel spreadsheet or pdf document.  I am using binary string first and then convert into xstring because for each doc it has to loop through and append each line to internal table.  The issue I am having now how successfully I take all lines in xstring as continueous line rather than table.  The upload function has no facility to receive internal table It can accept only xstring so I want to concatenate to make it  one xstring.  Wll this work?  Other concern I have about the size. What are limitations here.  If I have a large pdf document then how I handle to upload successfully.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me with a code example for defining string/table and converting into xstring/table.  I have used the type string &amp;amp; type xstring or xstringval but unable to upload entire document.  I have seen use of bapiconten but do not know how to use for string to xstring as binary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help on this will be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;StacyLee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Oct 2009 00:56:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195472#M1375284</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-15T00:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert any file from directory into binary string xstring</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195473#M1375285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please provide the portions of your code where you define data types, read and convert data. Our answer depends on what function modules and methods you use, and what data types you use. You may also find answer in the forum for each function module or method you use, this topic has been discussed so many times!&lt;/P&gt;&lt;P&gt;THX&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Oct 2009 08:58:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-convert-any-file-from-directory-into-binary-string-xstring/m-p/6195473#M1375285</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-10-15T08:58:34Z</dc:date>
    </item>
  </channel>
</rss>

