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

Create Attachment for XD02

Former Member
0 Likes
632

Hi,

I need to create an interface like XD02 in my web denpro application. I am creating a RFC for this and need to upload a file through this also. My program is as below-

&----


*& Report ZRG_TEST_ATTACH

*&

&----


*&

*&

&----


REPORT ZRG_TEST_ATTACH.

PARAMETERS: p_key TYPE swo_typeid OBLIGATORY,

p_type TYPE swo_objtyp OBLIGATORY,

p_file type string obligatory,

*p_file TYPE c LENGTH 100 OBLIGATORY,

p_desc TYPE so_obj_des OBLIGATORY.

DATA: ls_fol_id TYPE soodk,

ls_obj_id TYPE soodk,

ls_obj_data TYPE sood1,

ls_folmem_k TYPE sofmk,

ls_note TYPE borident,

ls_object TYPE borident,

lv_ep_note TYPE borident-objkey,

lv_offset TYPE i.

DATA: it_objhead TYPE STANDARD TABLE OF soli,

it_content LIKE STANDARD TABLE OF soli,

wa_content LIKE soli.

ls_object-objkey = p_key.

ls_object-objtype = p_type.

try.

  • open gui file into an internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = p_file

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = it_content

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.

CATCH cx_sy_file_access_error.

MESSAGE 'Error reading file' TYPE 'E'.

endtry.

*TRY.

*OPEN DATASET p_file FOR INPUT IN BINARY MODE.

*WHILE sy-subrc = 0.

*READ DATASET p_file INTO wa_content.

*APPEND wa_content TO it_content.

*ENDWHILE.

*CLOSE DATASET p_file.

*CATCH cx_sy_file_access_error.

*MESSAGE 'Error reading file' TYPE 'E'.

*ENDTRY.

*CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'

  • EXPORTING

  • it_contents_bin = it_content[]

  • IMPORTING

  • et_contents_bin = it_content[].

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

region = 'B'

IMPORTING

folder_id = ls_fol_id

EXCEPTIONS

OTHERS = 1.

ls_obj_data-objsns = 'O'.

ls_obj_data-objla = sy-langu.

ls_obj_data-objdes = p_desc.

ls_obj_data-ownnam = sy-uname.

lv_offset = STRLEN( p_file ) - 3.

ls_obj_data-file_ext = p_file+lv_offset(3).

ls_obj_data-objlen = LINES( it_content ) * 255.

CALL FUNCTION 'SO_OBJECT_INSERT'

EXPORTING

folder_id = ls_fol_id

object_type = 'EXT'

object_hd_change = ls_obj_data

IMPORTING

object_id = ls_obj_id

TABLES

objhead = it_objhead

objcont = it_content

EXCEPTIONS

active_user_not_exist = 35

folder_not_exist = 6

object_type_not_exist = 17

owner_not_exist = 22

parameter_error = 23

OTHERS = 1000.

IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.

ls_folmem_k-foltp = ls_fol_id-objtp.

ls_folmem_k-folyr = ls_fol_id-objyr.

ls_folmem_k-folno = ls_fol_id-objno.

ls_folmem_k-doctp = ls_obj_id-objtp.

ls_folmem_k-docyr = ls_obj_id-objyr.

ls_folmem_k-docno = ls_obj_id-objno.

lv_ep_note = ls_folmem_k.

ls_note-objtype = 'MESSAGE'.

ls_note-objkey = lv_ep_note.

CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'

EXPORTING

obj_rolea = ls_object

obj_roleb = ls_note

relationtype = 'ATTA'

EXCEPTIONS

OTHERS = 1.

ELSE.

MESSAGE 'Not OK' TYPE 'I'.

RETURN.

ENDIF.

IF sy-subrc = 0.

MESSAGE 'OK' TYPE 'I'.

ELSE.

MESSAGE 'Not OK' TYPE 'I'.

ENDIF.

File is being uploaded but I not able to download it, I mean when I open XD02, it shows the file but when I try to download this file it changes the format and also some it comes as a blank file.

2 REPLIES 2
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
454

Take a look at the example and explanation here:

http://friendlyabaper.blogspot.com/2008/07/oh-my-gos.html

Read only

Former Member
0 Likes
454

If you are using webdynpor as you mentioned. Then you have Fileupload UI element. to upload the file