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

to open pdf from binary text itab

Former Member
0 Likes
4,487

Hi friends,

I have a PDF in app server which i am reading into a binary text form into an internal table.

Below code:


data: begin of itab occurs 0,
field(256),
end of itab.
data: dsn(100) value '/usr/sap/xfr/FIS/testpdf',

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 how do i launch this PDF by using this binary text in ITAB.

I know i can download on to presentation server using GUI_Download, and then opening the same using CL_GUI_FRONTEND_SERVICES=>EXECUTE

but i don't want to do that.

Is there any way to launch / render this PDF on UI.

Any inputs on this is highly appreciated.

Regards,

Simha

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,884

using HTML Viewer you can get that..pass the PDF and generate the URL and use the same for display .show URL will take care of that.

data:    v_html_alignment type i,
           v_numbytes type i,
           v_mode type char1,
           v_url(255) type c,
           v_pdf     like sopcklsti1-doc_type value 'PDF',
           v_application(11) type c value 'application',
           lt_pdf  type table of tline.


*-Container for html viewer
  data: cl_html_container type ref to cl_gui_custom_container,
*-HTML viewer
        cl_htmlviewer     type ref to cl_gui_html_viewer.

**-Create container for HTML viewer
*  create object cl_html_container
*    exporting
*      container_name = 'HTML_CONTAINER'.
*
**-Create HTML Viewer
*  create object cl_htmlviewer
*    exporting parent = cl_html_container.
*
**-Alignment
**  v_html_alignment = cl_htmlviewer->align_at_left  +
**                     cl_htmlviewer->align_at_right +
**                     cl_htmlviewer->align_at_top   +
**                     cl_htmlviewer->align_at_bottom.
**
**  call method cl_htmlviewer->set_alignment
**    EXPORTING
**      alignment = v_html_alignment
**    EXCEPTIONS
**      others    = 1.
*
*
**-Load PDF Data
*  call method cl_htmlviewer->load_data
*    EXPORTING
*      type                 = v_application
*      subtype              = v_pdf
*      size                 = v_numbytes
*    IMPORTING
*      assigned_url         = v_url
*    CHANGING
*      data_table           = lt_pdf
*    EXCEPTIONS
*      dp_invalid_parameter = 1
*      dp_error_general     = 2
*      cntl_error           = 3
*      others               = 4.
*
*
*  call method cl_htmlviewer->show_url   "data
*    EXPORTING
*      url                    = v_url
*      in_place               = ' '
*    EXCEPTIONS
*      cntl_error             = 1
*      cnht_error_not_allowed = 2
*      cnht_error_parameter   = 3
*      dp_error_general       = 4
*      others                 = 5.

You can use the above code.

13 REPLIES 13
Read only

Former Member
0 Likes
2,885

using HTML Viewer you can get that..pass the PDF and generate the URL and use the same for display .show URL will take care of that.

data:    v_html_alignment type i,
           v_numbytes type i,
           v_mode type char1,
           v_url(255) type c,
           v_pdf     like sopcklsti1-doc_type value 'PDF',
           v_application(11) type c value 'application',
           lt_pdf  type table of tline.


*-Container for html viewer
  data: cl_html_container type ref to cl_gui_custom_container,
*-HTML viewer
        cl_htmlviewer     type ref to cl_gui_html_viewer.

**-Create container for HTML viewer
*  create object cl_html_container
*    exporting
*      container_name = 'HTML_CONTAINER'.
*
**-Create HTML Viewer
*  create object cl_htmlviewer
*    exporting parent = cl_html_container.
*
**-Alignment
**  v_html_alignment = cl_htmlviewer->align_at_left  +
**                     cl_htmlviewer->align_at_right +
**                     cl_htmlviewer->align_at_top   +
**                     cl_htmlviewer->align_at_bottom.
**
**  call method cl_htmlviewer->set_alignment
**    EXPORTING
**      alignment = v_html_alignment
**    EXCEPTIONS
**      others    = 1.
*
*
**-Load PDF Data
*  call method cl_htmlviewer->load_data
*    EXPORTING
*      type                 = v_application
*      subtype              = v_pdf
*      size                 = v_numbytes
*    IMPORTING
*      assigned_url         = v_url
*    CHANGING
*      data_table           = lt_pdf
*    EXCEPTIONS
*      dp_invalid_parameter = 1
*      dp_error_general     = 2
*      cntl_error           = 3
*      others               = 4.
*
*
*  call method cl_htmlviewer->show_url   "data
*    EXPORTING
*      url                    = v_url
*      in_place               = ' '
*    EXCEPTIONS
*      cntl_error             = 1
*      cnht_error_not_allowed = 2
*      cnht_error_parameter   = 3
*      dp_error_general       = 4
*      others                 = 5.

You can use the above code.

Read only

0 Likes
2,884

Hi Vijay,

Thanks for your inputs.

I used the code but just populated lt_pdf like below.


LOOP AT ITAB.
  LS_PDF-TDLINE = ITAB-FIELD.
  APPEND LS_PDF TO LT_PDF.
ENDLOOP.

but its not working i am getting HTML000001.pdf in V_URL in load_data method but show_url is not working.

What is wrong with my code?

Regards,

Simha

Edited by: Simha on Jul 31, 2008 11:11 AM

Read only

0 Likes
2,884

Can some one help me out?

Edited by: Simha on Aug 8, 2008 10:29 AM.

Edited by: Simha on Aug 18, 2008 12:19 PM

Read only

0 Likes
2,884

Hi simha,

As you say that you do not want to download the file

on presentation server (front end) and open it --

But that would really happen if at all there is some

FM which would directly open the file.

Eg. When we open a file on browser thru a link,

the file actually gets downloaded on local machine

in some temporary folder under some temporary name,

and ONLY then it gets opened.

I don't see any other direct way in which a pdf file can

get opened, without getting downloaded & saved, behind the scenes.

regards,

amit m.

Read only

0 Likes
2,884

Hi Amit,

I understand that anything that you open on your PC takes system memory but there should be a way to open the attachments using cl_htmlviewer or something.

What i want is, in a report on click of button i need to invoke the attaachment(either PDF/JPEG).

as i have this data as binary text in a cluster table, which i will retrieve on click of button into ITAB and invoke.

I am struck here in invoking this as i am not sure how to do using HTML control or any other better ways.

Regards,

Simha

Edited by: Simha on Aug 18, 2008 12:56 PM

Read only

0 Likes
2,884

Hi again,

1. Is there any specific reason that - behind the scenes -

you do not want to download the file on front end and then open it?

As per my personal opinion, there is no harm in doing it.

If we use a HTML viewer or anything, it will also do the

same behind the scenes.

regards,

amit m.

Read only

0 Likes
2,884

when i download and open it, user knows that it is being downloaded and i don't want to do it as i feel its not the best way of giving the solution.

can't we invoke with out downloading?

Read only

0 Likes
2,884

Hi,

1. If your concern is about the user knowing that the file

is downloaded,

then i would say that don't worry about that.

When we use GUI_DOWNLOAD then there is

no progress bar or any download icon on front-end,

that one can know what is really happening.

It would be almost instantaneous, unless the file is very big.

2. To get a taste of it, just copy paste.

a) this will download a .txt file with two lines

b) it will automatically open it in notepad.



report abc.


*---------------------------------------
data : begin of itab occurs 0,
       line(100) type c,
       end of itab.


*---------------------------------------
itab-line = 'This is line 1'.
append itab.
itab-line = 'This is line 2'.
append itab.



*---------------------------------------
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                    =
    FILENAME                        = 'd:\zz.txt'
*   FILETYPE                        = 'ASC'
  TABLES
    DATA_TAB                        = itab
.

*---------------------------------------
CALL FUNCTION 'GUI_RUN'
  EXPORTING
    COMMAND          = 'd:\zz.txt'
*   PARAMETER        =
*   CD               =
* IMPORTING
*   RETURNCODE       =
          .



regards,

amit m.

Read only

0 Likes
2,884

Hi Amit,

Thanks for your patience inputs.

I will be downloading a file of size 3-5MB

So thats going to be huge and gives a message so many bytes transferred..

I don't want that to happen thats my intention.

Regards,

Simha

Read only

0 Likes
2,884

Hi again,

If your concern is just about the message of xx bytes transferred,

then there is a small one line work around for it.

This will not show the standard message, instead

it will show our message which can be either blank,

or a simple message that 'Opening File'.

Just put this statement, immediately after gui_download.



*---------------- MESSAGE-----
message 'Opening File' type 'S'.
*------------------------------

Now run the program again, and u will see the difference.

regards,

amit m.

Read only

Former Member
0 Likes
2,884

I did the same for a file which is at desktop.

use function module GUI_UPLOAD in BIN format and put it into internal table.

then do whatever you want with the internal table and then take the output with GUI_DOWNLOAD FUNCTION MODULE.

Please find the code below.

REPORT ZCRMTEST NO STANDARD PAGE HEADING.

************************************************************************

*Program Name : ZCRMTEST

**----


    • TABLES

**----


*

*

TABLES: zcrmtest."/sapapo/dp_fcst2,

*----


  • DATA DECLARATION

*----


DATA: file_name TYPE string.

DATA: BEGIN OF file_data OCCURS 0, "Table for file records

  • pareaid(40) TYPE c,

  • seltext(120) TYPE c,

prpfl(70) TYPE c,

END OF file_data.

DATA: BEGIN OF t_plan OCCURS 0,

selectionid(22) TYPE c,

sel_description(120) TYPE c,

prpfl(22) TYPE c,

END OF t_plan.

DATA: no_of_records_in_plan TYPE sy-tfill,

no_of_records_in_dp_fcst2 TYPE sy-tfill,

final_table_records TYPE sy-tfill,

no_of_records_in_file TYPE sy-tfill.

*----


  • FIELD-SYMBOLS

*----


FIELD-SYMBOLS <fs_t_plan> LIKE t_plan.

*----


  • SELECTION SCREEN

*----


*

*SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

*

*PARAMETERS : p_area TYPE /sapapo/dp_fcst2-pareaid OBLIGATORY.

*

*SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.

PARAMETERS: filename LIKE rlgrap-filename "Output file path

DEFAULT '' OBLIGATORY.

SELECTION-SCREEN END OF BLOCK blk2.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

field_name = filename

CHANGING

file_name = filename.

TOP-OF-PAGE.

sy-title = ' Overview Of Data Upload In Table /sapapo/dp_fcst2 '.

WRITE: 'PROGRAM EXECUTED BY' .

WRITE: ' '.

WRITE: 'DATE'.

WRITE: ' '.

WRITE: 'TIME' .

SKIP 1.

WRITE: sy-uname .

WRITE: ' '.

WRITE: sy-datum .

WRITE: ' '.

WRITE: sy-uzeit .

WRITE:/.

*----


  • CALL FUNCTION FOR TAB DELIMITED FILE UPLOAD TO SAP SYSTEM

*----


START-OF-SELECTION.

file_name = filename.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file_name

filetype = 'BIN' "'ASC'

  • has_field_separator = 'X'

  • HEADER_LENGTH = '1'

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = file_data

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.

DESCRIBE TABLE file_data .

no_of_records_in_file = sy-tfill.

data: itab type standard table of zcrmtest with header line,

count type sy-tabix..

loop at file_data.

count = sy-tabix.

itab-mandt = sy-mandt.

itab-count1 = count.

itab-ZTEST = file_data-prpfl.

append itab.

insert into zcrmtest values itab.

commit work.

clear itab.

endloop.

clear itab.

refresh itab[].

DATA: BEGIN OF file_data_DOWNLOAD OCCURS 0, "Table for file records

  • pareaid(40) TYPE c,

  • seltext(120) TYPE c,

prpfl(70) TYPE c,

END OF file_data_DOWNLOAD.

SELECT * FROM ZCRMTEST INTO CORRESPONDING FIELDS OF TABLE itab.

LOOP AT ITAB.

file_data_DOWNLOAD-PRPFL = itab-ZTEST.

APPEND file_data_DOWNLOAD.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:\test.pdf'

FILETYPE = 'BIN'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

  • SHOW_TRANSFER_STATUS = ABAP_TRUE

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = file_data_DOWNLOAD "itab "file_data

  • FIELDNAMES =

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

this report will take any file from ur desktop and put into internal table.

from this internal table i am populating in one DB table for reference purpose and then again dumping it to somewhere in the local system.

regards,

Mukesh

Read only

0 Likes
2,884

Hi,

There was a similar requirement for our customer couple of years back and similar was our approach, but with time customer faced lot of performance issues and as the DB space grows table space allocation became tedious for DBA's , back up took lot more time , which resulted in more down time of system . There after slowly we migrated to Documemt management system of SAP which is a proven and standard methodolgy. Why not suggest your customer explaining the pitfalls and go for a DMS way for a longer term approach.

Regards

Suresh Bala

Read only

0 Likes
2,884

Hi Suresh,

You are correct. we invite all sorts of problems as you mention. We have suggested the client and they might consider after some time but mean while have to live with this.

Appreciate your inputs. Thanks.

Regards,

Simha