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

data type STRING

Former Member
0 Likes
27,298

Hi all,

i have creted a ztable and in that for one field the length is to be more than 300 chars.

so i am using the data type directly as STRING. i tried to check the table but i am getting warning as 'data type string not allowed in DB tables'.

plz help what to do.

regards,

siri.

1 ACCEPTED SOLUTION
Read only

kostas_tsioubris
Contributor
0 Likes
10,973

Hi,

you can use the data element DSTRING for your table.

Kostas

11 REPLIES 11
Read only

Former Member
0 Likes
10,973

Hi

Use the datat Type

LCHR

LRAW

for more number of CHAR fields like 500 and 1000

see the EDID4-SDATA field as an example

We can declare in a program as STRING

but in tables it gives error.

so better use the above data types

Reward points for useful Answers

Regards

Anji

Read only

kostas_tsioubris
Contributor
0 Likes
10,974

Hi,

you can use the data element DSTRING for your table.

Kostas

Read only

0 Likes
10,973

Thanks Anji and Kostas,

ACTUALLY THE MAIN PROBLEM THE LENGTH THAT THE FIELD IS GOING TO TAKE IS LESS THAN 256 AND SOME TIMES MORE THAN 256.

which is better DSTRING or lraw.

regards,

siri.

Message was edited by:

sireesha yalamanchili

Read only

0 Likes
10,973

If your field is not going to be bigger than 1000 characters it won't be a problem whatever field you choose. If your field is bigger than 1000 character you have to use dstring.I have worked with type dstring and it is very useful to store big info( i had used it for storing text history ) but it will be a little problem if you want to display it in an alv or something. You choose.

Kostas

Read only

0 Likes
10,973

Kostas,

But when i use DSTRING as field type i am getting message data element DSTRING not available?

regards,

siri.

Read only

0 Likes
10,973

Siri,

I work on 4.7 and i can use dstring as data element without problems.Which version do you work on?

Kostas

Read only

0 Likes
10,973

4.6

regards,

siri.

Read only

0 Likes
10,973

I don't know if it is going to work in 4.6 but give it a try. Create a z data element and in the domain enter string. If this won't work in 4.6 maybe you should consider the solutions mentioned from the other people.

Kostas

Read only

Former Member
0 Likes
10,973

Hi,

SAP wont allow declare field of string in the DB table and you can use char length of 300 CHAR300 instead of the same

Regards

Shiva

Read only

Former Member
0 Likes
10,973

Hi,

Here is the sample code to store the xml file into ABAP DB table.

First create a table called YTEST_BIN with following fileds.

Filed Nmae Data Elemen type

MANDT MANDT CLNT

DESCRIPTION HTTPBODY RAWSTRING

Now create a program to read the XML file from your desktop and load it into the table.

Below given is the code for loading the table.

REPORT y_store_xml.

DATA: wf_filetab TYPE filetable .

DATA: wf_filerc TYPE i ,

wf_filename TYPE string ,

wf_path TYPE string ,

wf_full_path TYPE string ,

wf_file_length TYPE i .

DATA: wf_extension TYPE string ,

wf_fname TYPE string .

DATA: BEGIN OF int_tab1 OCCURS 0,

int_txt(1000) TYPE x ,

END OF int_tab1.

DATA: upd_tab TYPE STANDARD TABLE OF ytest_bin .

DATA: wa_upd_tab LIKE LINE OF upd_tab .

DATA: temp_xstring TYPE xstring .

PARAMETERS: p_file LIKE file_table-filename LOWER CASE VISIBLE LENGTH 80 .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .

PERFORM browse_file CHANGING p_file .

AT SELECTION-SCREEN ON p_file .

IF p_file IS INITIAL .

MESSAGE e398(00) WITH

'Enter Filename and path' .

ENDIF.

START-OF-SELECTION .

CLEAR wf_filename .

MOVE: p_file TO wf_filename .

PERFORM load_file USING wf_filename .

PERFORM save_file_contents .

&----


*& Form browse_file

&----


  • text

----


  • <--P_P_FILE text

----


FORM browse_file CHANGING p_p_file.

CLEAR wf_filename .

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = 'Select the File'

  • DEFAULT_EXTENSION = cl_gui_frontend_services=>FILETYPE_TEXT

  • DEFAULT_FILENAME =

  • FILE_FILTER = cl_gui_frontend_services=>FILETYPE_EXCEL

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

CHANGING

file_table = wf_filetab

rc = wf_filerc

  • USER_ACTION =

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

OTHERS = 5

.

IF sy-subrc <> 0.

MESSAGE e398(00) WITH 'Error Opening File' .

ELSE .

READ TABLE wf_filetab INDEX 1 INTO p_file .

ENDIF.

ENDFORM. " browse_file

&----


*& Form load_file

&----


  • text

----


  • -->P_WF_FILENAME text

----


FORM load_file USING p_wf_filename.

CLEAR int_tab1 .

REFRESH int_tab1 .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_wf_filename

filetype = 'BIN'

IMPORTING

filelength = wf_file_length

  • HEADER =

TABLES

data_tab = int_tab1

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.

MESSAGE e398(00) WITH 'File may be open - Error loading' .

ENDIF.

ENDFORM. " load_file

&----


*& Form save_file_contents

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM save_file_contents .

CLEAR :wa_upd_tab , temp_xstring .

LOOP AT int_tab1 .

CONCATENATE temp_xstring int_tab1-int_txt INTO temp_xstring IN BYTE MODE.

ENDLOOP .

IF NOT temp_xstring IS INITIAL .

              • optional

TRY.

CALL METHOD cl_abap_gzip=>compress_binary

EXPORTING

raw_in = temp_xstring

IMPORTING

gzip_out = wa_upd_tab-description.

CATCH cx_parameter_invalid_range .

CATCH cx_sy_buffer_overflow .

CATCH cx_sy_compression_error .

ENDTRY.

APPEND wa_upd_tab TO upd_tab .

ENDIF .

IF NOT upd_tab IS INITIAL .

MODIFY ytest_bin FROM TABLE upd_tab .

IF sy-subrc EQ 0 .

MESSAGE i398(00) WITH wf_filename ` Saved!`.

ENDIF .

ENDIF.

ENDFORM. " save_file_contents

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
10,973

Hi,

the dictionary type STRING can only be used in DATAELEMENT, STRUCTURE and DOMAIN. ABAP doesn't support to allowing STRING data type directly to the table fields.

Character string with variable length This data type can only be used in types (data elements, structures, table types) and domains. In the Dictionary a length can be specified for this type (at least 256 characters). It may be used in database tables, however, only with restrictions. For a description of them refer to the documentation of the ABAP statement 'STRING'

regards,

Ashokreddy.