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: 

Table to store binary data

Former Member
0 Kudos

Hi friends,

I could read a file from app server into an internal table.


DATA: BEGIN OF ITAB OCCURS 0,
               FIELD(255),
           END OF ITAB.

OPEN DATASET DSN FOR INPUT IN BINARY MODE.

DO.
  READ DATASET DSN INTO ITAB-FIELD.
  IF SY-SUBRC = 0.
    APPEND ITAB.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.

Now i need to store this into a database table.

Length of the binary text could be more than 350000 as i am reading a PDF file.

How should be my DB table design ideally be?

What data type i use to store such data?

My SAP Version is 4.7EE Xstring datatype not available

Fields of table:

DOCNAME (PK)

DOCTYPE

DOCCONTENT - in this field i want to store the data. how can i do that?

Any help on this is highly appreciated.

Regards,

Simha

Edited by: Simha on Aug 1, 2008 10:00 AM

1 ACCEPTED SOLUTION

ian_maxwell2
Active Participant
0 Kudos

You can store the data easily in a data cluster table. Create a new table copying the structure of it from the standard table INDX. Tables of this structure can be used to hold blobs of data.

You don't use regualr OpenSQL statements to read and write from a data cluster table, instead you use the "Import From Database" and "Export To Database" commands. Here is a link to the documentation for doing this:

[http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3bf8358411d1829f0000e829fbfe/content.htm]

The import and export commands will take care of splitting your data up accross multiple DB records and mergeing them back together. It makes it really easy.

Since the implimentation of the import and export commands are actaully doing SQL statements against the DB for you, you can combine the updating of the data cluster table in the same DB transaction as updates to other tables. A scenario where I have used this in the past is that I store the blob of data in a data cluster table and I just put a reference to it into a field of the main table where my other buisness data is located. For the key that you use as the reference you can decide on what you want to use, either a concatenation of the key fields from the main table or an aribitrary value such as a GUID that you generate.

~Ian

Edited by: Ian Maxwell on Aug 3, 2008 4:35 AM

10 REPLIES 10

Former Member
0 Kudos

Hi Simha,

You can use RAW or the LRAW datatype for the field in the database table , RAW has a capacity of storing 2000 bytes and LRAW can store upto 2Gigabytes , this might suffice ur requirement and then for retreiving data u can use the logic that we use for retrieving from any cluster table. Let me know if u want any further help

Regards,

Santosh.

0 Kudos

Hi Santosh

thanks for you help.

I am unsuccessful in creating a field with RAW / LRAW field. Can you help me out.

Do i have to use any conversions before insert and after retrieve.

Could you throw some light on this?

Regards,

Simha

Former Member
0 Kudos

Hi Simha,

As your reading into the internal table with field size 255, just make it as char with that add two more fields as Docname & Docline and create the database table with structure

Docname - Key

Docline# - Key

line content (255)

While pulling data from app ser, change the input mode to 'text mode'.

In docname field populate the filename and docline field populate the line item (use some counter for line number). After getting all the values into the internal table, now insert this internal table to the database table.

Thanks,

Muthu

0 Kudos

Hi Muthu,

thanks for inputs.

Yes i knew i can do like that but was somehow not willing to store like that as it might affect the performace as i will store v huge data and have to retrieve many a times as its going to be display from report.

is there any better way of storing the data that is read from Such documents??

Regards,

Simha

Former Member
0 Kudos

I think you are trying to do some crapy things by storing in a table after reading through dataset so never do it as you might end up crashing the database

0 Kudos

Hi mate Mark Faber,

Yes i am trying to do crapy things and let me test how my DBA recovers the database (if it crashes)...

well everything on a lighter side..

how does one learn unless they try to do things like this..? And i guess i am among the right SDNers who will tell me what is right and what is not.

Let me know if you know any better ways of handling documents like PDF/JPEG/jpg that has to be displayed and stored in SAP.

Regards,

Simha

ian_maxwell2
Active Participant
0 Kudos

You can store the data easily in a data cluster table. Create a new table copying the structure of it from the standard table INDX. Tables of this structure can be used to hold blobs of data.

You don't use regualr OpenSQL statements to read and write from a data cluster table, instead you use the "Import From Database" and "Export To Database" commands. Here is a link to the documentation for doing this:

[http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3bf8358411d1829f0000e829fbfe/content.htm]

The import and export commands will take care of splitting your data up accross multiple DB records and mergeing them back together. It makes it really easy.

Since the implimentation of the import and export commands are actaully doing SQL statements against the DB for you, you can combine the updating of the data cluster table in the same DB transaction as updates to other tables. A scenario where I have used this in the past is that I store the blob of data in a data cluster table and I just put a reference to it into a field of the main table where my other buisness data is located. For the key that you use as the reference you can decide on what you want to use, either a concatenation of the key fields from the main table or an aribitrary value such as a GUID that you generate.

~Ian

Edited by: Ian Maxwell on Aug 3, 2008 4:35 AM

0 Kudos

Hi Ian,

Thanks a Ton for your help.

I tried creating a custom cluster table like INDX as you said and its working fentastic.

I have a similar requirement like your's where i need to store a BLOB object.

But last point of clarification (out of curiosity), how did u mange the Key fields of your custom cluster table?

I know RELID and SRTFD both make a key and i can use SRTFD for my reference.

How do i insert into the rest of the fields other than the Data?(like user name updated time/date)

Thanks once again for your valuable help.

Regards,

Simha

Edited by: Simha on Aug 4, 2008 8:11 AM

0 Kudos

I'm glad that the solution worked.

>But last point of clarification (out of curiosity), how did u mange the Key fields of your custom cluster table?

>I know RELID and SRTFD both make a key and i can use SRTFD for my reference.

For the keys, it's actaully pretty much up to what you want to do, there isn't a lot of restrictions on it. Usually the way I have seen it done is RELID be using to segment the table for multiple uses (i.e. all records for a similiar purpose would have the same value). The value of SRTFD is for your specific key that you want to use.

RELID will be populated by the area ID in your export statetment for example INDX(XX) will use "XX" for the area. SRTFD will be populated by the value given for ID in your export statement.

>How do i insert into the rest of the fields other than the Data?(like user name updated time/date)

To populate the other fileds in the table you need to add on the "From WA" extension to the export command, for example (from the online help):


wa_indx-aedat = sy-datum.
wa_indx-usera = sy-uname.
wa_indx-pgmid = sy-repid.

EXPORT itab TO DATABASE indx(hk) ID 'Table' FROM wa_indx.

You can actually add on other fileds in the copy of the INDX table as well and populate them in the same way, as long as the table starts with the key the same as the INDX table and ends with the cluster data.

Hope this helps...

~Ian

Edited by: Ian Maxwell on Aug 4, 2008 11:17 AM

0 Kudos

Hi Ian,

Thanks a lot for your help.

Yes i understood how we can update the other fields.

Kudos to Cluster tables for making my life easy

Regards,

Simha

Edited by: Simha on Aug 5, 2008 4:32 AM