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: 

Reading file from application server and storing back in text format

Former Member
0 Kudos

Hi Gurus,

I have requirement to read a excel file from Application server and do some manipulations, then i have to store the file in tab delimmeted format in application server.

please guide me how to proceed on this?

do i need any authorizations to applications server directory access.

thanks a lot.

6 REPLIES 6

Former Member
0 Kudos

HI Kiran,

Refer sample code:

constants: c_split TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

c_path TYPE VALUE char100 '/local/data/interface/A28/DM/OUT'.

&----


*& Form f1001_browse_appl_file

&----


  • Pick up the file path for the file in the application server

&----


FORM f1001_browse_appl_file .

DATA: lcl_directory TYPE char128.

lcl_directory = p_direct.

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'

EXPORTING

directory = lcl_directory

filemask = c_mask

IMPORTING

serverfile = p_f2

EXCEPTIONS

canceled_by_user = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE s000 WITH text-039.

EXIT.

ENDIF.

ENDFORM. " f1001_browse_appl_file

&----


*& Form f1004_app_file

&----


  • upload the file from the application server

&----


FORM f1004_app_file .

REFRESH: i_input.

OPEN DATASET p_f2 IN TEXT MODE ENCODING DEFAULT FOR INPUT.

IF sy-subrc EQ 0.

DO.

READ DATASET p_f2 INTO wa_input_rec.

IF sy-subrc <> 0.

MESSAGE s000 WITH text-030.

EXIT.

ENDIF.

*-- Split The CSV record into Work Area

PERFORM f0025_record_split.

*-- Populate internal table.

APPEND wa_input TO i_input.

CLEAR wa_input.

ENDDO.

ENDIF.

ENDFORM. " f1004_app_file

&----


*& Form f0025_record_split

&----


  • Move the assembly layer file into the work area

&----


FORM f0025_record_split .

CLEAR wa_input.

SPLIT wa_input_rec AT c_split INTO

wa_input-legacykey

wa_input-profile_role

wa_input-read_date.

ENDFORM. " f0025_record_split

<b>DO your manipulation with the data records here.</b>

Popualte data into final internal table and write it back to application server at the desired path.

&----


*& Form f0020_write_application

&----


  • Write error log to application Server

----


FORM f0020_write_application .

IF p_f1 IS NOT INITIAL.

CONCATENATE p_direct p_obj sy-datum text-037 INTO p_f2.

ELSEIF p_f2 IS NOT INITIAL.

REPLACE text-036 IN p_f2 WITH text-037.

ENDIF.

OPEN DATASET p_f2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

EXIT.

ENDIF.

LOOP AT i_error INTO wa_error.

TRANSFER wa_error TO p_f2.

IF sy-subrc <> 0.

EXIT.

ENDIF.

CLEAR wa_error.

ENDLOOP.

CLOSE DATASET p_f2.

ENDFORM. " f0020_write_application

Reward points if this Helps.

Manish

Message was edited by: Manish Kumar

Message was edited by: Manish Kumar

Former Member
0 Kudos

Hi Kiran,

You can use transactions CG3Y and CG3Z. Its very simple.

regards

Chandra.

Note: Please reward if helpful.

Former Member
0 Kudos

DATA:

  • Variable to store filepath

v_app_file TYPE eseftappl.

CLEAR : v_app_file.

  • Get the filepath in a variable

v_app_file = p_flname. "/INTERFACE/ISU/IN/Fica/c_Filename.txt

  • open the file in application server

OPEN DATASET v_app_file

FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  • Check whether file already exists

IF sy-subrc NE 0.

MESSAGE i000 WITH text-002.

LEAVE LIST-PROCESSING.

ELSE.

REFRESH: it_filedata.

  • Get values in internal table from file on appication server

READ DATASET v_app_file INTO wa_filedata.

APPEND wa_filedata TO it_filedata.

CLEAR wa_filedata.

CLOSE DATASET v_app_file.

ENDIF.

Former Member
0 Kudos

even I have the same query...pls help..

/SAPDMC/LSM_F4_SERVER_FILE

function module didnt wrk!!

Former Member
0 Kudos

Hai Tom,

Use The Function Modules C13Z_APPL_TO_FRONT_END.

Then Do modifications.

Then use C13Z_FRONT_END_TO_APPL.

If Found helpfull Do reward .

Regards.

Eshwar.

0 Kudos

Hi,

To read the file from application server.

filename = '/usr/tmp/test.xls'.

filename1 = '/usr/tmp/test1.xls'.

OPEN DATASET filename FOR INPUT IN LEGACY TEXT MODE.

IF sy-subrc EQ 0.

DO.

READ DATASET filename INTO wa_tab.

IF sy-subrc <> 0.

EXIT.

ENDIF.

APPEND wa_tab TO i_tab.

CLEAR wa_tab.

ENDDO.

CLOSE DATASET filename.

ENDIF.

IF i_tab[] IS NOT INITIAL.

do the manupalation here.

OPEN DATASET filename1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

LOOP at i_tab INTO wa_tab.

TRANSFER wa_tab TO filename1.

CLEAR : wa_tab.

ENDLOOP.

CLOSE DATASET filename1.

ENDIF.

ENDIF.

Please reward if useful.

Regards,

Ramesh