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

sample code

Former Member
0 Likes
623

Need to create BDC with all file types just like tab delimited or continous file or "DAT" file or "CSV" file need to use case statement and need to use GUI_UPLOAD and upload into any transaction.

5 REPLIES 5
Read only

Former Member
0 Likes
581
Read only

Former Member
0 Likes
581

Hi,

Check the following link:

http://sap-img.com/bdc.htm

Regards,

Bhaskar

Read only

Former Member
0 Likes
581

data:

ref_editor TYPE REF TO cl_gui_textedit,

ref_box TYPE REF TO cl_gui_dialogbox_container.

PAI

CREATE OBJECT ref_box

EXPORTING

  • PARENT =

width = 300

height = 200

  • STYLE =

  • REPID =

  • DYNNR =

lifetime = cl_gui_dialogbox_container=>lifetime_default

top = 100

left = 100

  • CAPTION =

  • NO_AUTODEF_PROGID_DYNNR =

  • METRIC = 0

  • NAME =

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

event_already_registered = 6

error_regist_event = 7

OTHERS = 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.

DATA str(25) TYPE c VALUE 'First Dialog Box'.

CALL METHOD ref_box->set_caption

EXPORTING

caption = str

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

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

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

ENDIF.

SET HANDLER c_event_receiver=>on_close

FOR ref_box.

CREATE OBJECT ref_editor

EXPORTING

  • MAX_NUMBER_CHARS =

  • STYLE = 0

  • WORDWRAP_MODE = WORDWRAP_AT_WINDOWBORDER

  • WORDWRAP_POSITION = -1

  • WORDWRAP_TO_LINEBREAK_MODE = FALSE

  • FILEDROP_MODE = DROPFILE_EVENT_OFF

parent = ref_box

  • LIFETIME =

  • NAME =

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

GUI_TYPE_NOT_SUPPORTED = 5

others = 6

.

IF sy-subrc <> 0.

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

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

ENDIF.

Eg:2

this the program to create a txt file which is in notepad .

  • Retrieve data file from presentation server(Upload from PC)

DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.

DATA: begin of it_datatab occurs 0,

row(500) type c,

end of it_datatab.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = i_file

filetype = 'ASC'

TABLES

data_tab = it_datatab "ITBL_IN_RECORD[]

EXCEPTIONS

file_open_error = 1

OTHERS = 2.

Eg:3

Call the FM GUI_DOWNLOAD for creating a notepad file in the presentation server .

sample example is :

call function 'GUI_DOWNLOAD'

exporting

filename = 'C:\Documents and Settings\E10127Desktop\zmaterials.txt\Desktop\zmaterials.txt'

filetype = 'ASC'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = int_mat

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

others = 22

By doing this , the data present in internal table int_tab will be transferred to a notepad present in the location provided . and if the notepad file is not already present in the P. Server then it will be created in the provided location with the values transferred into it.

hi use this program to downlod a notepad what ever location you want with some data , if don't want data you can directly use that function module to create one note pad

&----


*& Report ZNNR_DOWNLOAD

*&

&----


*&

*&

&----


REPORT ZNNR_DOWNLOAD MESSAGE-ID ZNNR.

TABLES : MARA.

TYPES : BEGIN OF TY_MARA,

MATNR LIKE MARA-MATNR,

WERKS LIKE MARC-WERKS,

PSTAT LIKE MARC-PSTAT,

END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA.

SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.

SELECT MATNR

WERKS

PSTAT

FROM MARC

INTO TABLE IT_MARA

WHERE MATNR IN S_MATNR.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:\NARESH\eXcel5.TXT'

  • FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • 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 = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = IT_MARA

  • 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.

IF SY-SUBRC EQ 0.

MESSAGE I100.

ENDIF.

this is the function module to create a file at our own selected place

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:\NARESH\eXcel5.TXT'

  • FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • 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 = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = IT_MARA

  • 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.

Reward points if usefull

Read only

hymavathi_oruganti
Active Contributor
0 Likes
581

The following is an example code for uploading any file from presentation server

PARAMETERS: p_fname1 LIKE rlgrap-filename OBLIGATORY

DATA: l_fname1 TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname1.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_fname1

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

START-OF-SELECTION.

CLEAR: l_fname1.

l_fname1 = p_fname1.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_fname1

filetype = 'ASC'

dat_mode = 'X'

TABLES

data_tab = t_tab

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.

Read only

Former Member
0 Likes
581

HI,

create a drop down in your selection screen say p_select.

then do like this.

PARAMETERS: p_fname1 LIKE rlgrap-filename OBLIGATORY

DATA: l_fname1 TYPE string.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname1.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_fname1

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

START-OF-SELECTION.

case p_select.

when CSV.

<< populate type variable with app. value>>

when DAT.

endcase.

CLEAR: l_fname1.

l_fname1 = p_fname1.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_fname1

filetype = type

dat_mode = 'X'

TABLES

data_tab = t_tab

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.