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: 

How to download entire output as a one string

Former Member
0 Kudos

Hi Experts,

How to download the entire output as a one string which has the length of characters 15 thousand. After downloading the file , the file should show the entire output in one string instead of showing table lines. Please help me.

*DATA: BEGIN OF IT_DETAIL OCCURS 0,

DATA TYPE STRING,

END OF IT_DETAIL.

TYPES: BEGIN OF TY_STRING,

DATA TYPE STRING,

END OF TY_STRING.

DATA: TAB_DETAIL TYPE STANDARD TABLE OF TY_STRING,

WA_STRING TYPE TY_STRING.

some selection process...

loop at itab.

concatenation F1 F2 ..FN TO IT_DETAIL-DATA.

MOVE IT_DETAIL-DATA TO WA_STRING-DATA. wa_string_data contains 15k characters in debugging

APPEND WA_STRING TO TAB_DETAIL. Here appending 15k chars to TAB_DETAIL

endlo

  • but while downloading using Gui_Download i couldnt get 15k characters, only getting 8093 characters.

DATA: L_SIZE1 TYPE I.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\ITEM.TXT'

FILETYPE = 'ASC'

IMPORTING

FILELENGTH = L_SIZE1 in Debug mode L_size1 having only 8093 characters only, couldnt download 15K chars ..Why? Is there any restriction for string length for downloading

TABLES

DATA_TAB = TAB_DETAIL*

17 REPLIES 17

Former Member
0 Kudos

Hi Experts,

How to download the entire output as a one string which has the length of characters 15 thousand. After downloading the file , the file should show the entire output in one string instead of showing table lines. Please help me

Thanks

0 Kudos

Try the below code, this should work.


DATA: li_str TYPE STANDARD TABLE OF string,
      l_str TYPE string,
      l_len TYPE i.

l_str = 'fajsflkasdjfaslkfdjasl;kdfja;lskdfja;lksfhakjsfdh;alksjfd'.

DO 20 TIMES.
  CONCATENATE l_str l_str INTO l_str.
  l_len = STRLEN( l_str ).
  IF l_len GT 15000.
    EXIT.
  ENDIF.
ENDDO.
APPEND l_str TO li_str.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\TEMP\TEST.TXT'
  TABLES
    data_tab = li_str.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Regards,

Chen

Edited by: Chen K V on Jun 13, 2011 2:39 PM

0 Kudos

HI Chen KV,

I have tried your example...In that also i had the same problem. Actually l_str has total 29184 characters. But while downloading by using GUI_Download, it downloads only 8096 characters in the "TEST.TXT" file. Remaining characters is not downloading. Why? Any other way to get all 29,184 characters in the file?

SAP DB maximum row length is 8096 bytes in sap? Cant take more than 8096 characters at one row? Please confirm me.

Thanks in advance.

0 Kudos

Hi,

Please confirm me that NEVER the internal table row will be filled more than the SAP DB maximum length of 8096 bytes.

Thanks in advance

0 Kudos

Try the below code, i have just changed a few lines based on your original code snippet.


DATA: BEGIN OF IT_DETAIL OCCURS 0,
DATA TYPE STRING,
END OF IT_DETAIL.

TYPES: BEGIN OF TY_STRING,
DATA TYPE STRING,
END OF TY_STRING.

DATA: TAB_DETAIL TYPE STANDARD TABLE OF TY_STRING,
WA_STRING TYPE TY_STRING.

some selection process...

loop at itab.
concatenation F1 F2 ..FN TO IT_DETAIL-DATA.

concatenate WA_STRING-DATA IT_DETAIL-DATA TO WA_STRING-DATA.  "Use concatenate instead of loop.
debugging
endloop

APPEND WA_STRING TO TAB_DETAIL. "Get the append statement outside the loop

* but while downloading using Gui_Download i couldnt get 15k characters, only getting 8093 characters.
DATA: L_SIZE1 TYPE I.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\ITEM.TXT'
FILETYPE = 'ASC'
IMPORTING
FILELENGTH = L_SIZE1 in Debug mode L_size1 having only 8093 characters only, couldnt download 15K chars ..Why? Is there any restriction for string length for downloading
TABLES
DATA_TAB = TAB_DETAIL*

Note: there is a limit on the number of characters a string can take, so you need to be sure that the total content in your ITAB doesn't exceed this.

I didn't get your question,

Please confirm me that NEVER the internal table row will be filled more than the SAP DB maximum length of 8096 bytes.

Regards,

Chen

0 Kudos

Hi Chen KV,

Please try to debug the below coding from APPEND statement to Gui_Download..Then you can come to know my problem. In debug mode l_str contains 29,184 characters...while downloading using FM GUI_DOWNLOAD only 8096 bytes only transfered to the file. you can check l_size in debug mode.

I know there is no a limit for string. I meant internal table one row get fill 8096 length of characters only?

Please try this code and check whether you can able to download 29,184 characters in the file "TEST.TXT".

DATA: li_str TYPE STANDARD TABLE OF string,
      l_str TYPE string,
      l_len TYPE i,
      L_SIZE TYPE I.

l_str = 'fajsflkasdjfaslkfdjasl;kdfja;lskdfja;lksfhakjsfdh;alksjfd'.

DO 20 TIMES.
  CONCATENATE l_str l_str INTO l_str.
  l_len = STRLEN( l_str ).
  IF l_len GT 15000.
    EXIT.
  ENDIF.
ENDDO.

APPEND l_str TO li_str.      *(here l_str contains 29,184 characters)*
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\TEMP\TEST.TXT'
    FILETYPE = 'ASC'
  IMPORTING
      FILELENGTH  = L_SIZE       *(L_size shows 8096bytes while debugging)*  TABLES
    data_tab = li_str.
IF sy-subrc  NE 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Many thanks

Edited by: Matt on Jun 14, 2011 11:37 AM - Added tags

matt
Active Contributor
0 Kudos

OK - BIN doesn't work directly. I've tried your program, and it works fine for me. I added a write statement at the end, and it gives me 29'186 characters downloaded - I think the extra two are CR/LF.

What version of SAP are you running.

If you convert your string to xstring, then you can use the BIN parameter instead, which might overcome the limitation you're experiencing - wherever it is coming from.

matt

Edited by: Matt on Jun 14, 2011 11:44 AM

0 Kudos

Hi Matt,

As your suggestion, i have converted string to Xstring and changed parameter "BIN" type..But it's not downloading anything. I am using version 4.7. Actually i want to download the entire string in the internal table to gets downloaded as a one continuous string in the output file. Please help me.

*

DATA: li_str TYPE standard TABLE OF string,

l_str TYPE string,

l_len TYPE i,

L_SIZE TYPE I,

lx_str type xstring.

l_str = 'fajsflkasdjfaslkfdjasl;kdfja;lskdfja;lksfhakjsfdh;alksjfd'.

DO 20 TIMES.

CONCATENATE l_str l_str INTO l_str.

l_len = STRLEN( l_str ).

IF l_len GT 15000.

EXIT.

ENDIF.

ENDDO.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

TEXT = l_str

IMPORTING

BUFFER = lx_str.

APPEND lx_str TO li_str.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEMP\TEST.TXT'

FILETYPE = 'BIN'

IMPORTING

FILELENGTH = L_SIZE

TABLES

data_tab = li_str.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.*

matt
Active Contributor
0 Kudos

When you've converted your string to xstring, convert the xstring into a table with a line type of X.

E.g.

DATA: l_hex  TYPE X length 1024,
      lt_hex LIKE STANDARD TABLE OF l_hex.

Slice the xstring into 1024 lengths, and insert each length into lt_hex. Then try downloading lt_hex.

Unfortunately, I don't have a 4.7 system to test on.

matt

Edited by: Matt on Jun 14, 2011 1:19 PM

0 Kudos

Hi Experts,

The following code able to download the full string length 29,184 using FM GUI_DOWNLOAD in SAP ECC 6.0.

The same code downloading partial string length 8,096 using FM GUI_DOWNLOAD in SAP 4.7.

Is this problem of FM gui_download in SAP 4.7? Bcz my office using 4.7. So i couldnt able to download full content.

Please help me out how to download all string content using SAP 4.7..

*DATA: li_str TYPE STANDARD TABLE OF string,

l_str TYPE string,

l_len TYPE i,

L_SIZE TYPE I.

l_str = 'fajsflkasdjfaslkfdjasl;kdfja;lskdfja;lksfhakjsfdh;alksjfd'.

DO 20 TIMES.

CONCATENATE l_str l_str INTO l_str.

l_len = STRLEN( l_str ).

IF l_len GT 15000.

EXIT.

ENDIF.

ENDDO.

APPEND l_str TO li_str. (here l_str contains 29,184 characters)

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\TEMP\TEST.TXT'

FILETYPE = 'ASC'

IMPORTING

FILELENGTH = L_SIZE

TABLES

data_tab = li_str.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.*

Thanks in advance

matt
Active Contributor
0 Kudos

Did you try what I suggested - convert the string into a table of fixed length hexadecimal? If you use filetype 'BIN', you must also select bin_filesize = the length of your string.

I know this works, because I did it years ago on a 46C system.

matt

0 Kudos

Hi Matt,

I want the output file as a continuous one string . So i cant split the string & insert to table. Any suggestion? why GUi_download not downloading entire length of string in SAP 4.7..but it works in ECC 6.0.

0 Kudos

Hi Kelvin,

The reason for why it truncates characters to 8096 when FM is run ASCII mode can be found in the below place of GUI_DOWNLOAD - FORM PUT_CHAR_LINEBUFFER . Include LSFESF02.

Lines of code:

MOVE <f> TO prc_field_char. " Here <f> contains all the characters of your string, but PRC_FIELD_CHAR is defined as type c - 8096, hence itis cut off.

I have found a solution with which you can download upto 32000 characters in BINARY mode, and this has the restriction you cannot use an ITAB referring to a string or XSTRING as it throws an exception. Hence the restriction of 32000(you cannot have more this as the data element throws a restriction)

Try the below code, but before that create a Data element ztest_raw, with predefined type as RAW and length 32000.


TYPES: BEGIN OF t_data,
         data TYPE ztest_raw,
       END OF t_data.

DATA: li_xstr TYPE STANDARD TABLE OF t_data,
      lw_xstr TYPE t_data,
      l_xstr  TYPE xstring,
      l_str TYPE string,
      l_len TYPE i.

l_str = 'fajsflkasdjfaslkfdjasl;kdfja;lskdfja;lksfhakjsfdh;alksjfd'.

DO 30 TIMES.
  CONCATENATE l_str l_str INTO l_str.
  l_len = STRLEN( l_str ).
  IF l_len GT 15000.
    EXIT.
  ENDIF.
ENDDO.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text           = l_str
 IMPORTING
   buffer         = l_xstr.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

lw_xstr-data = l_xstr.
APPEND lw_xstr TO li_xstr.
l_len = XSTRLEN( lw_xstr-data ).

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    bin_filesize = l_len
    filename     = 'C:\TEMP\TEST.TXT'
    filetype     = 'BIN'
  TABLES
    data_tab     = li_xstr.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                = 'C:\TEMP\TEST.TXT'
  TABLES
    data_tab                = li_xstr
  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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


LOOP AT li_xstr INTO lw_xstr.
  l_len = XSTRLEN( l_xstr ).
ENDLOOP.

Now i have to check this out in ECC 6.0, will update the post later as its time to head home

Regards,

Chen

matt
Active Contributor
0 Kudos

Hi Matt,

>

> I want the output file as a continuous one string . So i cant split the string & insert to table...

Yes you can, because it doesn't make any difference how long the records are in the internal table in abap, the end result is one continuous string in your output file. Try and you'll see that it works.

If you think about it, you should be able to work out why, as well. Hint - does the concept of "record length" have any meaning in a binary file?

The steps are something like.

Data: ls_xtab TYPE x LENGTH 500, "Or anything length you like
      lt_xtab LIKE STANDARD TABLE of ls_xtab,.

"... Convert string to xstring
.
.
.

l_strlen = xstrlen( xstring ).
l_iterations = l_strlen / 500. " same number here as the length of ls_xtab.

DO l_iterations TIMES.
  ls_xtab = xstring(500). 
  insert ls_xtab into table lt_xtab.
  xstring = xstring+500.
ENDDO.
 
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    bin_filesize = l_strlen
    filename     = 'C:\TEMP\TEST.TXT'
    filetype     = 'BIN'
  TABLES
    data_tab     = lt_xtab.

Edited by: Matt on Jun 15, 2011 2:19 PM - added pseudocode

0 Kudos

Thanks a lot Chen..Its working.

0 Kudos

Hi Kelvin,

Good that it is working, but i guess you might be better off with Matt's solution, i haven't tried it, but i don't see any reason as to why it shouldn't work either. Moreover his solution would help you overcome the restriction of 32000 bytes.

Regards,

Chen

matt
Active Contributor
0 Kudos

Try file type 'BIN'.

matt