Application Development 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: 

How to send data from Internal table to File in App. Server

Former Member
0 Kudos

Hi all,

What is the procedure to send data from internal tables to flat files in the Unix Application Server..

regards,

Vishnu

7 REPLIES 7

Former Member
0 Kudos

Hi,

Using dataset you can transfer the internal table values to application server file.

OPEN DATASET <dataset name>

TRANSFER

CLOSE DATASET <dataset name>.

Rgds,

Bujji

former_member156446
Active Contributor
0 Kudos

hi Vishnu

check the sample code:


parameters: pa_ufile(200) LOWER CASE.

OPEN DATASET p_ufile FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
EXIT.
ENDIF.
LOOP AT p_output INTO wa_file.
TRANSFER wa_file TO p_ufile.
CLEAR wa_file.
ENDLOOP.
CLOSE DATASET p_ufile.

Points..

Former Member
0 Kudos

Hi,

To send the data from internal table to file in application server.

Any file before sending the data want to open it.

for opening the file

Open dataset <Filename> for input In binary mode or text mode

after opening the file transfer the data from the internal table to the file.

Transfer <Itab> to <File>

Last close the file.

Close dataset <filename>.

Regards,

Suganya.

Former Member
0 Kudos

How to create a file if it is not created in the server before? Should it be done manually or is there any statement in ABAP?

0 Kudos

the file will automatically get created in the directory you mentioned the path ex: "/sap/usr/temp/test.txt" is the path you give at open dataset a file will be creates in that directory of unix automatically.

Mark all helpful answers

Former Member
0 Kudos

Hi

se this program where EXCEL to INTERNAL table and then to APPLICATION SERVER

&----


*& Report ZSD_EXCEL_INT_APP

*&

&----


*&

*&

&----


REPORT ZSD_EXCEL_INT_APP.

parameter: file_nm type localfile.

types : begin of it_tab1,

f1(20),

f2(40),

f3(20),

end of it_tab1.

data : it_tab type table of ALSMEX_TABLINE with header line,

file type rlgrap-filename.

data : it_tab2 type it_tab1 occurs 1,

wa_tab2 type it_tab1,

w_message(100) TYPE c.

at selection-screen on value-request for file_nm.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

  • PROGRAM_NAME = SYST-REPID

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

STATIC = 'X'

  • MASK = ' '

CHANGING

file_name = file_nm

EXCEPTIONS

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

start-of-selection.

refresh it_tab2[].clear wa_tab2.

file = file_nm.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '10'

i_end_row = '35'

tables

intern = it_tab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

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

loop at it_tab.

case it_tab-col.

when '002'.

wa_tab2-f1 = it_tab-value.

when '004'.

wa_tab2-f2 = it_tab-value.

when '008'.

wa_tab2-f3 = it_tab-value.

endcase.

at end of row.

append wa_tab2 to it_tab2.

clear wa_tab2.

endat.

endloop.

data : p_file TYPE rlgrap-filename value 'TEST3.txt'.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

*--- Display error messages if any.

IF sy-subrc NE 0.

MESSAGE e001(zsd_mes).

EXIT.

ELSE.

*---Data is downloaded to the application server file path

LOOP AT it_tab2 INTO wa_tab2.

TRANSFER wa_tab2 TO p_file.

ENDLOOP.

ENDIF.

*--Close the Application server file (Mandatory).

CLOSE DATASET p_file.

loop at it_tab2 into wa_tab2.

write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.

endloop.

shekhar01
Explorer
0 Kudos

Check out this report

 

REPORT ZK_FILE_TO_APPL_SERVER.

TABLES KNA1.
*----------------------------------------------------------------------*
*     Data Decalaration
*----------------------------------------------------------------------*
DATAGT_KNA1 TYPE TABLE OF KNA1,
      GS_KNA1 TYPE KNA1.
DATAGV_FILE   TYPE RLGRAP-FILENAME.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS S_KUNNR FOR KNA1-KUNNR OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.


*----------------------------------------------------------------------*
*     START-OF-SELECTION
*----------------------------------------------------------------------*
PERFORM GET_DATA.

IF NOT GT_KNA1[] IS INITIAL.
  PERFORM SAVE_FILE.
ELSE.
  MESSAGE 'No data found' TYPE 'I'.
ENDIF.
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*

FORM GET_DATA.
*Get data
  SELECT FROM KNA1
         INTO TABLE GT_KNA1 WHERE KUNNR IN S_KUNNR.
ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  save_file
*&---------------------------------------------------------------------*

FORM SAVE_FILE.
  DATALV_DATA TYPE STRING.

*Move complete path to filename
*  gv_file = '/tmp/cust.txt'.
  "Note if we are not passing any specific directory, by default it will
  " get stored in DIR_HOME in AL11 transaction

  CONCATENATE '/tmp/' SY-UNAME SY-DATUM SY-UZEIT '.txt' INTO GV_FILE.


* Open the file in output mode
  OPEN DATASET GV_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC NE 0.
    MESSAGE 'Unable to create file' TYPE 'I'.
    EXIT.
  ENDIF.

  LOOP AT GT_KNA1 INTO GS_KNA1.
    CONCATENATE GS_KNA1-KUNNR
                GS_KNA1-ANRED
                GS_KNA1-NAME1
                GS_KNA1-LAND1
                GS_KNA1-REGIO
                GS_KNA1-CITYC
     INTO LV_DATA
     SEPARATED BY ','.
*TRANSFER moves the above fields from workarea to file  with comma
*delimited format
    TRANSFER LV_DATA TO GV_FILE.
    CLEARGS_KNA1.
  ENDLOOP.
* close the file
  CLOSE DATASET GV_FILE.

  CONCATENATE 'File' GV_FILE 'created' INTO DATA(GV_MSGSEPARATED BY SPACE.

  MESSAGE GV_MSG TYPE 'I'.

ENDFORM.                    " save_file