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-datasets

Former Member
0 Likes
905

iam just working on datasets. i want to upload the data from the disk to the application server . so i want to know how to specify the file name in open dataset.

plz anyone send me the sample code for upload and downlod using datasets.

6 REPLIES 6
Read only

Former Member
0 Likes
748

form disk to appl server use

Function modules 'GUI_UPLOAD' or 'WS_UPLOAD'.

GUi_upload is reccomended.

BR, JAcek

Read only

0 Likes
748

From Disc to application layer right?

in that case u will have to use GUI_UPLOAD to upload the file from ur pres layer into an internal table. and then create and download the data into application layer using OPEN dataset <f>; TRANSFER dataset and CLOSE dataset commands.

ABAP documentation has the sytax for these commands. Use F1 to check them out.

-Aarthi.

Read only

Former Member
0 Likes
748

See the links for example.

http://sap.ittoolbox.com/code/archives.asp?i=10&d=3365&a=s

http://www.iconet-ltd.co.uk/sample_entry.php?id=28

Cheers,

Thomas.

Please mark points if helpful.

Read only

rahulkavuri
Active Contributor
0 Likes
748

sample code

FORM CALL_TRANSACTION.


  V_FILE = P_FILE.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                = V_FILE
      FILETYPE                = 'ASC'
      HAS_FIELD_SEPARATOR     = 'X'
    TABLES
      DATA_TAB                = IT_SALES
    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.


  LOOP AT IT_SALES.

    PERFORM POPULATE_BDC.

    CALL TRANSACTION 'VA01' USING IT_BDCDATA
                                  MODE MODE
                                  UPDATE UPDATE
                                  MESSAGES INTO IT_MSGS.

    IF NOT IT_MSGS[] IS INITIAL.

      LOOP AT IT_MSGS.

        CALL FUNCTION 'FORMAT_MESSAGE'
          EXPORTING
            ID        = IT_MSGS-MSGID
            LANG      = 'EN'
            NO        = IT_MSGS-MSGNR
            V1        = IT_MSGS-MSGV1
            V2        = IT_MSGS-MSGV2
            V3        = IT_MSGS-MSGV3
            V4        = IT_MSGS-MSGV4
          IMPORTING
            MSG       = V_MSG
          EXCEPTIONS
            NOT_FOUND = 1
            OTHERS    = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        WRITE:/ V_MSG.
      ENDLOOP.

    ENDIF.

  ENDLOOP.

ENDFORM.                    "CALL_TRANSACTION

Read only

Former Member
0 Likes
748

hii Devender ,

check this

Retrieve Data file from Application server(Upload )
DATA: i_file like rlgrap-filename value <b>'/usr/sap/tmp/file.txt'.</b>

    OPEN DATASET i_file FOR INPUT IN TEXT MODE.
    IF sy-subrc NE 0.
      MESSAGE e999(za) WITH 'Error opening file' i_file.
    ENDIF.
    DO.
*     Reads each line of file individually
      READ DATASET i_file INTO wa_datatab.
*     Perform processing here
*     .....   
    ENDDO.

Download internal table to Application server file

DATA: e_file like rlgrap-filename value <b>'/usr/sap/tmp/file.txt'.</b>  /* c:/file.txt */    

  open dataset e_file for output in text mode.
  lOOP AT it_datatab......
    transfer it_datatab to e_file.
  ENDLOOP.
 
  close dataset e_file.

however GUI_UPLOAD is recommended ..

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

DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'. /* c:/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.

Reward points if helpful..

Revert back for more help

Regards

Naresh

Read only

Former Member
0 Likes
748

Hi Devender,

Plz find the attached Code for uploading file (local pc) to Application Server.

PARAMETERS p_phyfil LIKE rfpdo-rfbifile.

DATA: BEGIN OF t_output_data OCCURS 0,

text_1(1000) TYPE c,

END OF t_output_data.

**UPLOAD THE DATA TO T_OUTPUT USING GUI_DOWNLOAD

----


  • Show Unix file path *

----


FORM show_unix_file.

DATA: l_unix_dir LIKE btch0000-text80,

l_unix_full_dir LIKE btch0000-text80.

l_unix_dir = '/tmp/'.

CALL FUNCTION 'PFL_CHECK_DIRECTORY'

EXPORTING

directory = l_unix_full_dir

filname = '.'

EXCEPTIONS

pfl_dir_not_exist = 1

pfl_permission_denied = 2

pfl_cant_build_dataset_name = 3

pfl_file_not_exist = 4

OTHERS = 5.

IF sy-subrc = 0.

l_unix_dir = l_unix_full_dir.

ENDIF.

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'

EXPORTING

directory = l_unix_dir

filemask = ''

IMPORTING

serverfile = p_phyfil

EXCEPTIONS

canceled_by_user = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE s899(v1) WITH 'F4 Functionality not working'.

ENDIF.

ENDFORM. " SHOW_UNIX_FILE

FORM write_to_unix_file.

g_long_file = p_phyfil.

OPEN DATASET g_long_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE a899(v1) WITH 'File' g_long_file 'could not be opened'.

ELSE.

MESSAGE s899(v1) WITH 'File opened:' g_long_file.

ENDIF.

LOOP AT t_output_data.

TRANSFER t_output_data TO g_long_file.

IF sy-subrc NE 0.

MESSAGE s899(v1) WITH 'Transfer failed: File' g_long_file.

STOP.

ENDIF.

ENDLOOP.

CLOSE DATASET g_long_file.

IF sy-subrc NE 0.

MESSAGE a899(v1) WITH 'File' g_long_file 'could not be closed'.

ELSE.

MESSAGE s899(v1) WITH 'File closed:' g_long_file.

ENDIF.

ENDFORM. " WRITE_TO_UNIX_FILE