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

Error when using the method cl_gui_frontend_services=>file_open_dialog

aris_hidalgo
Contributor
0 Likes
1,083

Hello Experts,

I am currently practicing BDC and I think the first step is to locate where my text file is. Now based on my code below, after selecting my text file nothing happens.

Also, what will be my next after getting the file from a specific location? Thanks guys!

REPORT z_aris_practice_bdc_0

NO STANDARD PAGE HEADING

LINE-SIZE 255

LINE-COUNT 64

MESSAGE-ID zz.

*BDC Data

DATA: BEGIN OF bdc_tab OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdc_tab.

*Internal Table

DATA: BEGIN OF it_input OCCURS 0,

user TYPE usr02-bname,

title TYPE sza5_d0700-title_medi,

lname TYPE addr3_data-name_last,

fname TYPE addr3_data-name_first,

initials TYPE addr3_data-initials,

nickname TYPE addr3_data-nickname,

function TYPE addr3_data-function,

END OF it_input.

DATA: gt_lines TYPE sy-tabix,

gt_file TYPE filetable,

wa_file TYPE filetable,

gt_subrc TYPE i.

*CONSTANTS

CONSTANTS: c_mask(60) TYPE c VALUE ',..'.

*Selection Screen

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

PARAMETERS: p_input LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_input.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

initial_directory = 'C:\Temp\'

multiselection = 'X'

CHANGING

file_table = gt_file[]

rc = gt_subrc

  • USER_ACTION =

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

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

*START-OF-SELECTION

START-OF-SELECTION.

PERFORM put_in_itab.

PERFORM process_records.

&----


*& Form get_files

&----


  • text

----


FORM put_in_itab.

DATA: lv_file TYPE string.

lv_file = p_input.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

  • FILETYPE = 'ASC'

has_field_separator = 'X'

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

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.

ELSE.

DESCRIBE TABLE it_input LINES gt_lines.

ENDIF.

ENDFORM. "get_files

&----


*& Form process_records

&----


  • text

----


FORM process_records.

LOOP AT it_input.

ENDLOOP.

ENDFORM. "process_records

Hello Experts,

I am currently practicing BDC and I think the first step is to locate where my text file is. Now based on my code below, after selecting my text file nothing happens.

Also, what will be my next after getting the file from a specific location? Thanks guys!

REPORT z_aris_practice_bdc_0

NO STANDARD PAGE HEADING

LINE-SIZE 255

LINE-COUNT 64

MESSAGE-ID zz.

*BDC Data

DATA: BEGIN OF bdc_tab OCCURS 0.

INCLUDE STRUCTURE bdcdata.

DATA: END OF bdc_tab.

*Internal Table

DATA: BEGIN OF it_input OCCURS 0,

user TYPE usr02-bname,

title TYPE sza5_d0700-title_medi,

lname TYPE addr3_data-name_last,

fname TYPE addr3_data-name_first,

initials TYPE addr3_data-initials,

nickname TYPE addr3_data-nickname,

function TYPE addr3_data-function,

END OF it_input.

DATA: gt_lines TYPE sy-tabix,

gt_file TYPE filetable,

wa_file TYPE filetable,

gt_subrc TYPE i.

*CONSTANTS

CONSTANTS: c_mask(60) TYPE c VALUE ',..'.

*Selection Screen

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

PARAMETERS: p_input LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_input.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

initial_directory = 'C:\Temp\'

multiselection = 'X'

CHANGING

file_table = gt_file[]

rc = gt_subrc

  • USER_ACTION =

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

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

*START-OF-SELECTION

START-OF-SELECTION.

PERFORM put_in_itab.

PERFORM process_records.

&----


*& Form get_files

&----


  • text

----


FORM put_in_itab.

DATA: lv_file TYPE string.

lv_file = p_input.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

  • FILETYPE = 'ASC'

has_field_separator = 'X'

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

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.

ELSE.

DESCRIBE TABLE it_input LINES gt_lines.

ENDIF.

ENDFORM. "get_files

&----


*& Form process_records

&----


  • text

----


FORM process_records.

LOOP AT it_input.

ENDLOOP.

ENDFORM. "process_records

2 REPLIES 2
Read only

Former Member
0 Likes
687

Hi,

Please try this.


...

parameters: p_input type localfile.
  
at selection-screen on value-request for p_input.

  data: path_str type string.
 
  call method cl_gui_frontend_services=>directory_browse
      exporting
         window_title    = 'Select Directory'
      changing
         selected_folder = path_str
      exceptions
         cntl_error = 1.
 
  call method cl_gui_cfw=>flush
       exceptions
          cntl_system_error = 1
          cntl_error        = 2.
 
  p_input =  path_str.

...

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
687

Hii viraylab,

go throgh this link..This sample code solves ur problem....

/people/milind.upasani/blog/2007/03/07/step-by-step-approach-to-ceate-simple-bdc-session-program-using-reusable-template

U are new to BDC it seems...

first u read the sap help ... then u will come know what to do after wards....

http://help.sap.com/saphelp_47x200/helpdata/en/fa/097720543b11d1898e0000e8322d00/frameset.htm

Be familiar with the structure BDCDATA.

<b>Data transfers</b> In this page..

Next u need to know about the <b>transaction RECORDER the tcode is SHDB.</b>

Nothing is difficult in this ..

For example When u r creating a data element in SE11 u go through some screens in a flow, by clicking some pushbuttons and by generating some function codes manually, and entering values manually...

But here u wont do it manually, these values will be populated from file into an internal table...

Before calling a transaction into which u r going to populate the data is to be filled into a table with structure <b>BDCDATA.</b>

<b>U need to use CALL TRANSACTION 'SE11' using BDCDATA or

the session method..</b>

Reward points for helpful answers...

sai ramesh