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

printing the document attachments

Former Member
0 Likes
1,313

hi all,

i have a requirement to print the attachments of a document in background or forground. i have done a good search on sdn and also other help forums but couldnt find a right solution. i know that we can achive this using gos services, i can read and view them but unable to do a print function. can anyone please help me

thanks,

anupama.

hi all,

i have a requirement to print the attachments of a document in background or forground. i have done a good search on sdn and also other help forums but couldnt find a right solution. i know that we can achive this using gos services, i can read and view them but unable to do a print function. can anyone please help me

thanks,

anupama.

1 REPLY 1
Read only

Former Member
0 Likes
507

here is the solution

CONSTANTS : lc_objtype TYPE saeanwdid VALUE 'BUS2081',


              

lc_directory TYPE string VALUE 'C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe',

              

lc_directory1 TYPE string VALUE 'rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt'

DATA : ls_items TYPE rfposxext,

  • lv_length TYPE num12,

  • lv_binleg TYPE num12,

lt_uri_tab TYPE TABLE OF toauri,

ls_uri_tab TYPE toauri,

lt_arch_tab TYPE TABLE OF docs,

ls_arch_tab TYPE docs,

lt_bin_tab TYPE TABLE OF tbl1024,

ls_bin_tab TYPE tbl1024,

lv_buffer TYPE xstring,

lv_saeobjid TYPE saeobjid,

  • lt_mess_att TYPE STANDARD TABLE OF solisti1,

  • ls_mess_att TYPE solisti1,

lv_filename TYPE string,

lv_batch TYPE string,

lv_parameter TYPE string,

lv_rcode TYPE i,

lt_binary TYPE solix_tab,

ls_binary TYPE LINE OF solix_tab,

lt_filename TYPE STANDARD TABLE OF string,

ls_filename TYPE string,

lv_doctype TYPE saedoktyp,

lv_directory TYPE string,

lv_prdefault TYPE rspoprname,

lt_batch_tab TYPE TABLE OF string.

*line items which are selected or only processed

LOOP AT it_items INTO ls_items WHERE xselp = 'X'.

*check if reference key is not initial

IF NOT ls_items-u_awkey IS INITIAL.

MOVE ls_items-u_awkey TO lv_saeobjid.

*get the url link based on the BUS2081 and the reference key(document number followed the year)

REFRESH : lt_uri_tab, lt_arch_tab, lt_bin_tab.

CALL FUNCTION 'ARCHIVOBJECT_GET_URI'

EXPORTING

objecttype = lc_objtype

object_id = lv_saeobjid

TABLES

uri_table = lt_uri_tab

EXCEPTIONS

error_archiv = 1

error_communicationtable = 2

error_kernel = 3

error_http = 4

error_dp = 5.

IF NOT lt_uri_tab[] IS INITIAL.

CLEAR ls_uri_tab.

READ TABLE lt_uri_tab INTO ls_uri_tab INDEX 1.

IF sy-subrc EQ 0.

CLEAR lv_doctype.

IF ls_uri_tab-mimetype CS 'pdf'.

MOVE : 'PDF' TO lv_doctype .

ELSEIF ls_uri_tab-mimetype CS 'tiff'.

MOVE : 'TIF' TO lv_doctype .

ENDIF.

*get the archive id and the type of document

CALL FUNCTION 'ARCHIVOBJECT_GET_TABLE'

EXPORTING

archiv_id = ls_uri_tab-archiv_id

document_type = lv_doctype

archiv_doc_id = ls_uri_tab-arc_doc_id

signature = 'X'

compid = 'data'

  • IMPORTING

  • length = lv_length

  • binlength = lv_binleg

TABLES

archivobject = lt_arch_tab

binarchivobject = lt_bin_tab

EXCEPTIONS

error_archiv = 1

error_communicationtable = 2

error_kernel = 3.

IF sy-subrc EQ 0.

CLEAR : ls_bin_tab, lv_buffer.

REFRESH : lt_binary.

LOOP AT lt_bin_tab INTO ls_bin_tab.

CONCATENATE lv_buffer ls_bin_tab-line INTO lv_buffer IN BYTE MODE.

ENDLOOP.

*convert to binary

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = lv_buffer

TABLES

binary_tab = lt_binary.

CONCATENATE 'C:\Mass Print\' ls_items-u_awkey '.' lv_doctype INTO lv_filename.

*download to the local drive

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = lv_filename

filetype = 'BIN'

TABLES

data_tab = lt_binary

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.

IF sy-subrc EQ 0.

CLEAR : lv_directory, lv_parameter.

IF lv_doctype EQ 'PDF'.

MOVE : lc_directory TO lv_directory.

CONCATENATE '/n /t' lv_filename INTO lv_parameter SEPARATED BY space.

ELSE.

CLEAR : lv_prdefault, lv_batch.

REFRESH :lt_batch_tab.

*get default printer

CALL FUNCTION 'RSPO_FRONTEND_PRINTERS_FOR_DEV'

EXPORTING

device = 'LOCL'

IMPORTING

prdefault = lv_prdefault

EXCEPTIONS

no_list = 1

list_truncated = 2

name_not_found = 3.

CONCATENATE lc_directory1 lv_filename lv_prdefault INTO lv_parameter SEPARATED BY space.

CONCATENATE 'C:\Mass Print\' ls_items-u_awkey '.bat' INTO lv_batch.

APPEND lv_parameter TO lt_batch_tab.

CLEAR lv_parameter.

APPEND lv_batch TO lt_filename.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = lv_batch

filetype = 'ASC'

TABLES

data_tab = lt_batch_tab

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.

MOVE lv_batch TO lv_directory.

ENDIF.

*print the pdf file from command line

cl_gui_frontend_services=>execute(

EXPORTING

application = lv_directory

parameter = lv_parameter

synchronous = 'X'

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

bad_parameter = 3

file_not_found = 4

path_not_found = 5

file_extension_unknown = 6

error_execute_failed = 7

synchronous_failed = 8

not_supported_by_gui = 9 ).

IF sy-subrc <> 0.

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

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

ENDIF.

MOVE : lv_filename TO ls_filename .

APPEND ls_filename TO lt_filename.

CLEAR ls_filename.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

IF NOT lt_filename[] IS INITIAL.

  • WAIT UP TO 30 SECONDS.

LOOP AT lt_filename INTO ls_filename.

*delete the file from local drive

cl_gui_frontend_services=>file_delete(

EXPORTING

filename = ls_filename

CHANGING

rc = lv_rcode

EXCEPTIONS

file_delete_failed = 1

cntl_error = 2

error_no_gui = 3

file_not_found = 4

access_denied = 5

unknown_error = 6

not_supported_by_gui = 7

wrong_parameter = 8 ).

IF sy-subrc <> 0.

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

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

ENDIF.

ENDLOOP.

ENDIF.

solved ...

thanks,

anupama