2014 Nov 18 1:05 PM
Hello Guys,
my goal is to read an PDF from the appication server and store it as an binary.
But i think i handle according a wrong procedure. Maybe some one can help me finding out.
first i read the PDF
using
OPEN DATASET gv_inp_file FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
DO.
READ DATASET gv_inp_file INTO gs_solix-line.
IF sy-subrc EQ 0.
APPEND gs_solix TO gt_solix.
CLEAR gs_solix.
ELSE.
APPEND gs_solix TO gt_solix.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET gv_inp_file.
the data is now in gt_solix
i concatenate tis into 1 xstring using a perform
PERFORM convert_tab_to_x USING gt_solix
CHANGING gv_len
gx_content.
this makes an long gx_content xstring
and seems to be ok
the FORM is
FORM convert_tab_to_x USING p_rawtab TYPE tabtype_solix
CHANGING p_len TYPE i
p_xstr TYPE xstring.
DATA: l_line TYPE solix,
l_count TYPE i,
l_len TYPE i,
l_rest TYPE i,
l_strlen TYPE i.
DESCRIBE TABLE p_rawtab LINES l_count.
LOOP AT p_rawtab INTO l_line.
IF sy-tabix = l_count.
l_rest = xstrlen( l_line-line ).
CONCATENATE p_xstr l_line-line(l_rest) INTO p_xstr IN BYTE MODE.
ELSE.
CONCATENATE p_xstr l_line-line INTO p_xstr IN BYTE MODE.
ADD 255 TO l_len.
ENDIF.
ENDLOOP.
* total length
ADD l_rest TO l_len.
MOVE l_len TO p_len.
as last part i convert this xstring to binary using
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gx_content
IMPORTING
output_length = gv_len
TABLES
binary_tab = gt_bin_data.
and the following standard coding handles this with at the end a wrong result.
is this the method i use ok
or is it better to declare an (big) xstring to read the dataset into and use this straight away
to convert to binary instrad of this method (parts of 255 long)
any suggestions are welcome.
hope you can tell me the how to do this right.
Regards, Frank
2014 Nov 18 1:40 PM
Hi Frank
i prefer
READ DATASET into WF_XSTRING (Straight away)
where do you want to store your binary data now? (table with RAWSTRING, SAP DMS, BDS, Contentserver, Archive...)
to convert it into an internal table i also use CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' (good choice!)
i see a lot of developers dealing with binary data using concatenate or split functions, but
in my opinion this is always a unnecessary source of erros, so i am always using the SCMS*STRING* functions
Hello Guys,
my goal is to read an PDF from the appication server and store it as an binary.
But i think i handle according a wrong procedure. Maybe some one can help me finding out.
first i read the PDF
using
OPEN DATASET gv_inp_file FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
DO.
READ DATASET gv_inp_file INTO gs_solix-line.
IF sy-subrc EQ 0.
APPEND gs_solix TO gt_solix.
CLEAR gs_solix.
ELSE.
APPEND gs_solix TO gt_solix.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET gv_inp_file.
the data is now in gt_solix
i concatenate tis into 1 xstring using a perform
PERFORM convert_tab_to_x USING gt_solix
CHANGING gv_len
gx_content.
this makes an long gx_content xstring
and seems to be ok
the FORM is
FORM convert_tab_to_x USING p_rawtab TYPE tabtype_solix
CHANGING p_len TYPE i
p_xstr TYPE xstring.
DATA: l_line TYPE solix,
l_count TYPE i,
l_len TYPE i,
l_rest TYPE i,
l_strlen TYPE i.
DESCRIBE TABLE p_rawtab LINES l_count.
LOOP AT p_rawtab INTO l_line.
IF sy-tabix = l_count.
l_rest = xstrlen( l_line-line ).
CONCATENATE p_xstr l_line-line(l_rest) INTO p_xstr IN BYTE MODE.
ELSE.
CONCATENATE p_xstr l_line-line INTO p_xstr IN BYTE MODE.
ADD 255 TO l_len.
ENDIF.
ENDLOOP.
* total length
ADD l_rest TO l_len.
MOVE l_len TO p_len.
as last part i convert this xstring to binary using
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gx_content
IMPORTING
output_length = gv_len
TABLES
binary_tab = gt_bin_data.
and the following standard coding handles this with at the end a wrong result.
is this the method i use ok
or is it better to declare an (big) xstring to read the dataset into and use this straight away
to convert to binary instrad of this method (parts of 255 long)
any suggestions are welcome.
hope you can tell me the how to do this right.
Regards, Frank
2014 Nov 18 1:40 PM
Hi Frank
i prefer
READ DATASET into WF_XSTRING (Straight away)
where do you want to store your binary data now? (table with RAWSTRING, SAP DMS, BDS, Contentserver, Archive...)
to convert it into an internal table i also use CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' (good choice!)
i see a lot of developers dealing with binary data using concatenate or split functions, but
in my opinion this is always a unnecessary source of erros, so i am always using the SCMS*STRING* functions
2014 Nov 18 1:49 PM
Hello Jörg,
thanks for your answer.
you mean with READ DATASET into WF_XSTRING (Straight away)
that i do not have to use that form convert_tab_to_x anymore.
The binary data has to be stored into archive.
and cause of your preferring SCMS functions i will see for moe of tjhem
Regards, Frank
2014 Nov 18 2:22 PM
yes, conversion form not required
use this:
data: gx_content xstring.
OPEN DATASET gv_inp_file FOR INPUT IN BINARY MODE.
if sy-subrc = '0'.
READ DATASET gv_inp_file INTO gx_content. "all in one go
CLOSE DATASET gv_inp_file.
endif.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gx_content
IMPORTING
output_length = gv_len
TABLES
binary_tab = gt_bin_data.
2014 Nov 18 3:00 PM
Hi,
Try:
FORM upload_file_2
USING
p_path TYPE pathextern
CHANGING
it_solix TYPE solix_tab .
DATA: big_string TYPE xstring .
DATA: mess TYPE string .
OPEN DATASET p_path FOR INPUT IN BINARY MODE MESSAGE mess .
READ DATASET p_path INTO big_string .
CLOSE DATASET p_path .
CALL METHOD cl_bcs_convert=>xstring_to_solix
EXPORTING
iv_xstring = big_string
RECEIVING
et_solix = it_solix.
ENDFORM . "upload_file_2
Regards.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |