Skip to Content
0
Nov 05, 2012 at 02:17 PM

Attachment viewer, RFC/BAPI issue in HWC application

59 Views

Hi Friends,

I am implementing Attachment viewer in my HWC app.

For that we created an RFC with the given below code:

Issue: According to sybase we are converting the attachment (pdf/Image) into it's equivalent base64 format.

Once it is converted the length of the content (Attachment) is more than 10,000.

To map the content to a field in the MBO (Ex:string(100000)) when the content is passing in a string the maximum size of it is 256.

How to pass this big value in a string to the device as a single variable?

During MBO creation for the attachment if the output from the RFC is a single field for the content only we can map the field equivalent to that in the MBO right.

So how to create the output field for the RFC to pass this big value (Base64) to the device?


FUNCTION ZBAPI_FILE_ATTACHMENT_NEW.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" VALUE(I_PO_NUMBER) TYPE BAPIMMPARA-PO_NUMBER OPTIONAL

*" EXPORTING

*" VALUE(PO_NUMBER) TYPE BAPIMMPARA-PO_NUMBER

*" VALUE(BINARY) TYPE STRING

*" VALUE(FILENAME) TYPE STRING

*" VALUE(MIMETYPE) TYPE STRING

*" VALUE(FILESIZE) TYPE I

*" VALUE(LS_OUTPUT) TYPE STRING

*" TABLES

*" LT_HEXADECIMAL STRUCTURE SOLIX

*"----------------------------------------------------------------------

TYPES:BEGIN OF ty_srgbtbrel,

instida TYPE sibfboriid,

instidb TYPE sibfboriid,

END OF ty_srgbtbrel.

DATA:lt_attach TYPE TABLE OF ty_srgbtbrel,

ls_attach TYPE ty_srgbtbrel,

ls_folder_id TYPE soodk,

ls_obj_id TYPE soodk,

lt_obj_cont TYPE TABLE OF soli,

lt_obj_head TYPE TABLE OF soli,

ls_obj_cont TYPE soli,

ls_obj_head TYPE soli,

ls_hd_disp TYPE sood2.

DATA:lv_ebeln TYPE ebeln,

lv_data1 TYPE char20,

lv_data2 TYPE char255,

lv_mime TYPE skwf_mime,

lv_file TYPE SKWF_FILNM.

lv_ebeln = i_po_number. " To get PO number in required format

*" Multiple attachments are possible for a Purchase order

SELECT instid_a

instid_b FROM srgbtbrel INTO TABLE lt_attach

WHERE instid_a = lv_ebeln. " Get instance ID from SRGBTBREL table

IF sy-subrc = 0.

READ TABLE lt_attach INTO ls_attach INDEX 1.

IF sy-subrc = 0.

PO_NUMBER = ls_attach-instida.

ls_folder_id-objtp = ls_attach-instidb+0(3).

ls_folder_id-objyr = ls_attach-instidb+3(2).

ls_folder_id-objno = ls_attach-instidb+5(12).

ls_obj_id-objtp = ls_attach-instidb+17(3).

ls_obj_id-objyr = ls_attach-instidb+20(2).

ls_obj_id-objno = ls_attach-instidb+22(12).

CALL FUNCTION 'SO_OBJECT_READ'

EXPORTING

folder_id = ls_folder_id

object_id = ls_obj_id

IMPORTING

object_hd_display = ls_hd_disp

TABLES

objcont = lt_obj_cont

objhead = lt_obj_head

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

folder_not_exist = 4

folder_no_authorization = 5

object_not_exist = 6

object_no_authorization = 7

operation_no_authorization = 8

owner_not_exist = 9

parameter_error = 10

substitute_not_active = 11

substitute_not_defined = 12

system_failure = 13

x_error = 14

OTHERS = 15.

IF sy-subrc <> 0.

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

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

ENDIF.

READ TABLE lt_obj_cont INTO ls_obj_cont INDEX 1.

IF sy-subrc = 0.

SPLIT ls_obj_cont AT '=' INTO lv_data1 lv_data2.

binary = lv_data2. " Move binay data to export parameter

CLEAR:lv_data1,lv_data2.

ENDIF.

READ TABLE lt_obj_head INTO ls_obj_head INDEX 1.

IF sy-subrc = 0.

SPLIT ls_obj_head AT '=' INTO lv_data1 lv_data2.

filename = lv_data2. " Move filename to export parameter

lv_file = lv_data2.

CALL FUNCTION 'SKWF_MIMETYPE_OF_FILE_GET'

EXPORTING

filename = lv_file

IMPORTING

mimetype = lv_mime.

IF sy-subrc = 0.

mimetype = lv_mime.

ENDIF.

CLEAR:lv_data1,lv_data2.

ENDIF.

filesize = ls_hd_disp-objlen.

* ENDIF.

* ENDIF.

"new code

**** lv_docid = ls_attach-instidb.

**** CALL FUNCTION 'SO_DOCUMENT_READ_API1'

**** EXPORTING

**** document_id = lv_docid

***** FILTER = 'X '

**** IMPORTING

**** document_data = document_data

**** TABLES

**** object_header = object_header

**** object_content = object_content

**** object_para = object_para

**** object_parb = object_parb

**** attachment_list = attachment_list

**** receiver_list = receiver_list

**** contents_hex = contents_hex

**** EXCEPTIONS

**** document_id_not_exist = 1

**** operation_no_authorization = 2

**** x_error = 3

**** OTHERS = 4

**** .

**** IF sy-subrc <> 0.

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

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

**** ENDIF.

**** filename = document_data-OBJ_DESCR.

**** filesize = document_data-doc_size.

**** mimetype = document_data-obj_type.

***** lt_hexadecimal[] = contents_hex[].

DATA: p_asfile TYPE string VALUE '.\'.

* lt_raw TYPE TABLE OF char255.

CONCATENATE p_asfile ls_attach-instida INTO p_asfile.

DATA: w_raw TYPE char255,

lt_raw TYPE TABLE OF char255,

ls_data TYPE string,

* ls_output TYPE string,

lt_rawbinary TYPE xstring,

input_length TYPE i,

v_lines type i.

*CONCATENATE p_asfile 'temp' INTO p_asfile.

OPEN DATASET p_asfile FOR INPUT IN BINARY MODE.

DO.

READ DATASET p_asfile INTO w_raw.

IF sy-subrc <> 0.

EXIT.

ENDIF.

APPEND w_raw TO lt_raw.

ENDDO.

CLOSE DATASET p_asfile.

DESCRIBE TABLE lt_raw LINES v_lines.

input_length = v_lines * 255.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

EXPORTING

input_length = input_length

IMPORTING

buffer = lt_rawbinary

TABLES

binary_tab = lt_raw.

CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'

EXPORTING

input = lt_rawbinary

IMPORTING

output = ls_data.

ls_output = ls_data.

ENDIF.

ENDIF.

ENDFUNCTION.

Please help.

Thanks

Midhun