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

Problem convert string to table

Former Member
0 Likes
6,172

Hi guys.

I have a long string in BASE64, using the FM SSFC_BASE64_DECODE, I'm able to decode the base64 string to a normal string.

Now, the problem is that i need to convert that long string into a table and then save it as .pdf in the local pc.

I tried using the FM CONVERT_STRING_TO_TABLE but it gives me a dump. This is the code that i have. The w_result is the string in base64 that i get from a webservice.


data: w_result TYPE string, 
        fic_binario TYPE xstring.
DATA: string_binario TYPE string.

  DATA: BEGIN OF lines OCCURS 100,
  tdline(1024) TYPE x.
  DATA: END OF lines.

  CALL FUNCTION 'SSFC_BASE64_DECODE'
    EXPORTING
      b64data = w_result
    IMPORTING
      bindata = fic_binario.

  string_binario = fic_binario.

* Dump
  CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
    EXPORTING
      i_string         = string_binario
      i_tabline_length = 1024
    TABLES
      et_table         = lines.

* Also i tried this: DUMP as well

  DATA: lv_divisor TYPE i,
  lv_resto TYPE i,
  lv_longitud TYPE i,
  lv_indice TYPE i.

  DO.

    lv_longitud = STRLEN( string_binario ).

    lv_divisor = lv_longitud DIV 256.
    lv_resto = lv_longitud DIV 256.

    lv_indice = 256 * sy-index.

    lines-tdline = string_binario+lv_indice(256).

    APPEND lines.
    CLEAR lines.

    IF lv_divisor IS INITIAL.

      EXIT.

    ENDIF.

  ENDDO.

How can i convert that string that I get from the FM SSFC_BASE64_DECODE to a table??? so then i can download it to a local pc????

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,229

Hi Miguel,

Once you have the binary in the XSTRING, you could convert that into a table and download using GUI_DOWNLOAD.

Check with the below code, no need to put it in a string just to use the FM "CONVERTSTRINGTOTABLE.


  DATA: li_contents         TYPE TABLE OF sdokcntbin,
        lw_contents         TYPE sdokcntbin,
        l_file_length       TYPE i,
        l_flag              TYPE c,
        l_off               TYPE i,
        l_len               TYPE i.

  TRY.
      l_len = XSTRLEN( fic_binario ).
      l_file_length = l_len.

      WHILE l_flag IS INITIAL.

        IF l_len LE 1022.
          lw_contents-line = fic_binario+l_off(l_len).
          l_flag = 'X'.
        ELSE.
          lw_contents-line = fic_binario+l_off(1022).
          l_off = l_off + 1022.
          l_len = l_len - 1022.
        ENDIF.

        APPEND lw_contents TO li_contents.

      ENDWHILE.

* Download the ITAB li_contents[].
endtry.

Note: When you are downloading with GUI_DOWNLOAD, you might (not that you should) need to use a corresponding codepage.

Reasons for the short dump you are getting,

"MOVE src TO dst"

requires that the operands "dst" and "src" are convertible.

DATA: BEGIN OF lines OCCURS 100,

tdline(1024) TYPE x.

DATA: END OF lines.

You have defined the lines table as that of raw, while internally the convert to string FM expects a string/char type table, change the above data definition to C instead of X and the FM will work fine, but the data will not be valid to be opened as a PDF anymore i guess.

Errores tiempo ejec. STRING_OFFSET_LENGTH_TOO_LARGE

Excepción CX_SY_RANGE_OUT_OF_BOUNDS

I think the above dump is because of the below line, here you have hardcoded the offset value, which will work fine till the last subset of the string is reached, and if the last subset happens to be less than 255 characters, the offset becomes too large.

lines-tdline = string_binario+lv_indice(255).

Regards,

Chen

Edited by: Chen K V on Jun 1, 2011 1:48 PM

Edited by: Chen K V on Jun 1, 2011 1:53 PM

13 REPLIES 13
Read only

Former Member
0 Likes
4,229

What do the dumps say?

Rob

Read only

0 Likes
4,229

Hi Rob the dump says:

The statement

"MOVE src TO dst"

requires that the operands "dst" and "src" are convertible.

Since this statement is in a Unicode program, the special conversion

rules for Unicode programs apply.

In this case, these rules were violated.

Err.tmpo.ejec. UC_OBJECTS_NOT_CONVERTIBLE

Fecha y hora 31.05.2011 14:57:44

Texto breve

Data objects in Unicode programs cannot be converted.


   1 FUNCTION CONVERT_STRING_TO_TABLE.                      
   2 *"-----------------------------------------------------
   3 *"*"Local interface:                                   
   4 *"  IMPORTING                                          
   5 *"     REFERENCE(I_STRING) TYPE  STRING                
   6 *"     VALUE(I_TABLINE_LENGTH) TYPE  I                 
   7 *"  TABLES                                             
   8 *"      ET_TABLE TYPE  TABLE                           
   9 *"-----------------------------------------------------
  10                                                        
  11   data: l_length      type i,                          
  12         l_offset      type i,                          
  13         l_full_lines  type i,                          
  14         l_last_length type i.                          
  15                                                        
  16 * get string length                                    
  17   l_length = strlen( i_string ).                       
  18 * get number of full lines                             
  19   l_full_lines  = l_length div i_tabline_length.       
  20 * get length of last line                              
  21   l_last_length = l_length mod i_tabline_length.       
  22                                                        
  23 * append full lines to output table                    
  24   do l_full_lines times.                               
>>>>     et_table = i_string+l_offset(i_tabline_length).    
  26     append et_table.                                   
  27     l_offset = l_offset + i_tabline_length.            
  28   enddo.                                               
  29                                                        
  30 * append last line to output table                     
  31   et_table = i_string+l_offset(l_last_length).         
  32   append et_table.                                     
  33                                                        
  34 ENDFUNCTION.                                           

There is a 5,000 character posting limit to individual posts. Put the other dump in anoter response please.

After the SY-TABIX = 615

Regards

I dont know why it looks very bad format, no idea, I tried to write it again, but it looks the same-

Edited by: Rob Burbank on May 31, 2011 3:05 PM

Read only

0 Likes
4,229

How is the variable you are passing to TABLE defined?

Rob

Read only

0 Likes
4,229

Hi,

the variable string_binario contains the value after i decode the string in base64. Until there, it seems to be ok. That variable is a string that containes the info, that must be convert in a table and then download to a local pc in .pdf


  DATA: BEGIN OF lines OCCURS 100,
  tdline(1024) TYPE x.
  DATA: END OF lines.

  DATA: string_binario TYPE string.

  CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
    EXPORTING
      i_string         = string_binario
      i_tabline_length = 1024
    TABLES
      et_table         = lines.

other option is


  DATA: lv_divisor TYPE i,
  lv_resto TYPE i,
  lv_longitud TYPE i,
  lv_indice TYPE i.

  DO.

    lv_longitud = STRLEN( string_binario ).

    lv_divisor = lv_longitud DIV 256.
    lv_resto = lv_longitud DIV 256.

    lv_indice = 256 * sy-index.

    lines-tdline = string_binario+lv_indice(255).

    APPEND lines.
    CLEAR lines.

    IF lv_divisor IS INITIAL.

      EXIT.

    ENDIF.

  ENDDO.

but this option also gives me a dump.

Regards

Read only

0 Likes
4,229

the dumps that gives me the second option is:

Errores tiempo ejec. STRING_OFFSET_LENGTH_TOO_LARGE

Excepción CX_SY_RANGE_OUT_OF_BOUNDS

Fecha y hora 31.05.2011 15:00:17

Texto breve

Illegal access to a string (offset+length too large)

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_RANGE_OUT_OF_BOUNDS', was not

caught and

therefore caused a runtime error.

The reason for the exception is:

In the running program "ZTEST003", part of a string was about to be accessed

via offset and length.

However, the total of offset (157696) and length (255) exceeded the current

length of the string (157874).

This kind of access is illegal.

the dump is getting after the sy-tabix = 615

Regards

Read only

0 Likes
4,229

Change:

tdline(1024) TYPE x.

to

tdline TYPE string

Rob

Read only

0 Likes
4,229

Hi,

if i change that, and using the FM * CONVERT_STRING_TO_TABLE*

it gives me a dump:

Err.tmpo.ejec. OBJECTS_MOVE_NOT_SUPPORTED

Fecha y hora 31.05.2011 15:22:47

Texto breve

Conversion of type "g" to type "v" not supported.

You attempted to move one data object to another.

This is not possible here because the conversion of a data object

of type "g" to type "v" is not supported.

Posición desencadenante de error tiempo ejecución

Programa SAPLHR_GB_EF_OUTG

Include LHR_GB_EF_OUTGU02

Línea 25

Tp.módulo (FUNCTION)

Nombre módulo CONVERT_STRING_TO_TABLE

I'm going to check with the another option to see how it works....

I used the second option and it pass without dumps.

but i can't open the file


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:Fichero100.pdf'
TABLES
DATA_TAB = lines .

the acrobat says that the file is damage...

Thanks

Read only

0 Likes
4,229

mistake

the same, it doesnt work.

sorry, but i did what u said and it didnt work.

Regards

Read only

0 Likes
4,229

if i use the second option, the dumps says:

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_RANGE_OUT_OF_BOUNDS', was not

caught and

therefore caused a runtime error.

The reason for the exception is:

In the running program "ZTEST003", part of a string was about to be accessed

via offset and length.

However, the total of offset (157696) and length (256) exceeded the current

length of the string (157874).

This kind of access is illegal.

using the tdline type string. same as the another tdline(1024) type x.

Regards

Read only

0 Likes
4,229

the variable string_binario has sth like this : 255044462D312E330D0A25F6E4FCDF0D0A312030206F626A0D0A3C3C0D0A2F54797065202F436174616C6F670D0A2F50616765732032203020520D0A3E3E0D0A656E646F626A0D0A332030.............

but i can't get it full, even i debbug the program, i can't get the whole value of the variable.

Regards

Read only

Former Member
0 Likes
4,229

Hi,

Write like the below :

DATA: lv_divisor TYPE i,

lv_resto TYPE i,

lv_longitud TYPE i,

lv_temp_length type i,

lv_remaining type i,

lv_indice TYPE i.

lv_longitud = STRLEN( string_binario ).

DO.

clear : lv_temp_length.

lv_indice = 256 * sy-index.

lv_temp_length = lv_indice + 256.

if lv_temp_length < lv_longitud.

lines-tdline = string_binario+lv_indice(256).

else.

lv_remaining = lv_temp_length - lv_longitud.

lines-tdline = string_binario+lv_indice(lv_remaining).

APPEND lines.

CLEAR lines.

exit.

endif.

APPEND lines.

CLEAR lines.

ENDDO.

Regards,

Srini.

Read only

Former Member
0 Likes
4,230

Hi Miguel,

Once you have the binary in the XSTRING, you could convert that into a table and download using GUI_DOWNLOAD.

Check with the below code, no need to put it in a string just to use the FM "CONVERTSTRINGTOTABLE.


  DATA: li_contents         TYPE TABLE OF sdokcntbin,
        lw_contents         TYPE sdokcntbin,
        l_file_length       TYPE i,
        l_flag              TYPE c,
        l_off               TYPE i,
        l_len               TYPE i.

  TRY.
      l_len = XSTRLEN( fic_binario ).
      l_file_length = l_len.

      WHILE l_flag IS INITIAL.

        IF l_len LE 1022.
          lw_contents-line = fic_binario+l_off(l_len).
          l_flag = 'X'.
        ELSE.
          lw_contents-line = fic_binario+l_off(1022).
          l_off = l_off + 1022.
          l_len = l_len - 1022.
        ENDIF.

        APPEND lw_contents TO li_contents.

      ENDWHILE.

* Download the ITAB li_contents[].
endtry.

Note: When you are downloading with GUI_DOWNLOAD, you might (not that you should) need to use a corresponding codepage.

Reasons for the short dump you are getting,

"MOVE src TO dst"

requires that the operands "dst" and "src" are convertible.

DATA: BEGIN OF lines OCCURS 100,

tdline(1024) TYPE x.

DATA: END OF lines.

You have defined the lines table as that of raw, while internally the convert to string FM expects a string/char type table, change the above data definition to C instead of X and the FM will work fine, but the data will not be valid to be opened as a PDF anymore i guess.

Errores tiempo ejec. STRING_OFFSET_LENGTH_TOO_LARGE

Excepción CX_SY_RANGE_OUT_OF_BOUNDS

I think the above dump is because of the below line, here you have hardcoded the offset value, which will work fine till the last subset of the string is reached, and if the last subset happens to be less than 255 characters, the offset becomes too large.

lines-tdline = string_binario+lv_indice(255).

Regards,

Chen

Edited by: Chen K V on Jun 1, 2011 1:48 PM

Edited by: Chen K V on Jun 1, 2011 1:53 PM

Read only

0 Likes
4,229

Hi Chen.

I did what u said and it works, thanks very much.

Also, i use


    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename = 'C:\Fichero100.pdf'
        filetype = 'BIN'
      TABLES
        data_tab = li_contents.

without filetype = 'BIN' the .PDF file doesnt work.

I dont know why, the website doesnt show me the option to give points....any clue???

I'm going to have it, just the website doesnt show me that...when i figuret out, i will do it.

Thanks to all.

Regards