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

bdc uploading data

Former Member
0 Likes
1,066

while i am working with bdc when i am uploading flat file into sap.every time i am going to give the path of that file.i just cal function module gui_upload and give the path,how can i give the path dynamically.what is the use F4_filename

1 ACCEPTED SOLUTION
Read only

saranwin
Contributor
0 Likes
982

Hi,

If you want select the file name dynamically use the function module GUI_UPLOAD and F4_filename. F4_filename help you to get the file name from the desktop. But in the case of UPLOAD Function module

In the Example Code :

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS: P_FILE TYPE LOCALFILE.

SELECTION-SCREEN: END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

field_name = p_file

CHANGING

file_name = p_file.

DATA : lv_file TYPE string.

IF P_FILE IS NOT INITIAL.

lv_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

DAT_MODE = ' '

tables

data_tab = LT_ITAB

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.

ENDIF.

Regards,

Saran

8 REPLIES 8
Read only

Former Member
0 Likes
982

Hi,

Use F4_FILENAME FM in event for Value request of parameter Filename.

This will popup window when user presses F4 on the Filename parameter on the selection screen, wherein you can choose the file.

Regards

Vijai

Read only

Former Member
0 Likes
982

Hi

F4_file name is used to file selection.After then u exeute ur file wil upload....

Regards:

Prabu

Read only

Former Member
0 Likes
982

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS:p_efile LIKE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

  • FIELD_NAME = 'P_File'

IMPORTING

file_name = p_file.

this FM is used to get the file path of local system through dialog box.

Now the P_file will contain the file path

Use the following FM to upload the file

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

filename = p_file

filetype = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = it_text[]

EXCEPTIONS

conversion_error = 1

file_open_error = 2

file_read_error = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

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 it_text[] IS INITIAL.

  • File is empty ! No data to Upload

MESSAGE i130.

LEAVE LIST-PROCESSING.

ENDIF.

Hope this helps.

Bikas

Read only

Former Member
0 Likes
982

Hi,

you try this.

parameters:p_file type <filename structure>

AT selection screen on value request for p_file.

call fm f4_filename.

Read only

Former Member
0 Likes
982

SELECTION-SCREEN BEGIN OF BLOCK b1.

PARAMETERS : P_FILE LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = 'ZTESTVA02'

  • DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE

Regards

Anbu B

Read only

saranwin
Contributor
0 Likes
983

Hi,

If you want select the file name dynamically use the function module GUI_UPLOAD and F4_filename. F4_filename help you to get the file name from the desktop. But in the case of UPLOAD Function module

In the Example Code :

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS: P_FILE TYPE LOCALFILE.

SELECTION-SCREEN: END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

field_name = p_file

CHANGING

file_name = p_file.

DATA : lv_file TYPE string.

IF P_FILE IS NOT INITIAL.

lv_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

DAT_MODE = ' '

tables

data_tab = LT_ITAB

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.

ENDIF.

Regards,

Saran

Read only

0 Likes
982

Hi,

REPORT ZDN_DYNAMIC_PATH_001.

parameters: p_file type RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_file'

IMPORTING

FILE_NAME = p_file

.

Thanks,

Nelson

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
982

Hi Sekhar ,

Have look at this code..

PARAMETERS : p_upload TYPE rlgrap-filename.
DATA : w_upload TYPE string. "---------->path for uploading
*&---------------------------------------------------------------------*
*& AT SELECTIONSCREEN
*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR  p_upload .
"-------> dynamically assingin Path for Uploading input file
  PERFORM f_f4_upload.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
Start-of-selection.
PERFORM f_upload.
*&---------------------------------------------------------------------*
*&      Form   F_F4_UPLOAD
*&---------------------------------------------------------------------*
FORM f_f4_upload.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_upload.
ENDFORM.                    " F_F4_UPLOAD

*&---------------------------------------------------------------------*
*&      Form  F_UPLOAD
*&---------------------------------------------------------------------*
FORM f_upload .
  w_upload = p_upload.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = w_upload  "---------->path
      filetype                = 'ASC'
      has_field_separator     = 'x'
    TABLES
      data_tab                = it_itab
    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.


ENDFORM.                    " F_UPLOAD

Regards,