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

Urgent - Append data to internal table from Application server

Former Member
0 Likes
662

Hi All,

I encountered the problem while read the input file from Application server...then append it to internal table. I manage to read the input file from presentation and append the data to internal table.

Below are my coding which cause me not able the append data from Application server. Please kindly help me to solving/correct my coding. Thanks in advance .

PARAMETERS : p_inpfl LIKE rlgrap-filename. "Material Input File

SELECTION-SCREEN BEGIN OF LINE.

  • Application Server

SELECTION-SCREEN COMMENT 1(19) text-002 FOR FIELD rb_ux.

SELECTION-SCREEN POSITION 33.

PARAMETERS: rb_ux RADIOBUTTON GROUP g1.

  • Presentation Server

SELECTION-SCREEN COMMENT 40(21) text-003 FOR FIELD rb_pc.

SELECTION-SCREEN POSITION 65.

PARAMETERS: rb_pc RADIOBUTTON GROUP g1 DEFAULT 'X'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN END OF BLOCK b01.

FORM f_Input_file.

CLEAR: v_f_exists.

CHECK NOT p_inpfl IS INITIAL. "input file exist

IF NOT rb_pc IS INITIAL. " Pc check

PERFORM f_read_tab_delimited_file TABLES i_input

USING c_09

p_inpfl

rb_ux

CHANGING v_ifile_str_with_tab

v_f_exists

v_ifile_record_count

v_message.

IF v_f_exists EQ '1' .

  • UPLOAD FILE could not be read

MESSAGE e546 .

ENDIF .

IF v_ifile_record_count EQ 0 .

  • Zero records in upload file

MESSAGE e547 .

ENDIF.

ELSE.

OPEN DATASET p_inpfl FOR INPUT IN TEXT MODE.

DO.

READ DATASET p_inpfl INTO i_input.

IF sy-subrc EQ 0.

APPEND i_input.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET p_inpfl.

ENDIF.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
525

Hi Little,

I have developed a program where I was reading from application server.

Please go through the code and make changes as per your reqiurement.

  • Open the file in application server

OPEN DATASET l_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  • If file openning is successful

IF sy-subrc = 0.

MOVE cl_abap_char_utilities=>cr_lf+0(1) TO l_car_ret.

MOVE cl_abap_char_utilities=>cr_lf+1(1) TO l_lin_feed .

DO.

TRY.

  • Read the file line by line

READ DATASET l_filename INTO wa_record-line.

  • If file read is successful

IF sy-subrc EQ 0.

SEARCH wa_record-line FOR l_car_ret.

IF sy-subrc = 0. "(3)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(3)

SEARCH wa_record-line FOR l_lin_feed.

IF sy-subrc = 0. "(4)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(4)

wa_record-filename = wa_filelist-name. " Filename

APPEND wa_record TO itab_record.

CLEAR wa_record.

ELSE.

EXIT.

ENDIF.

CATCH cx_root. "#EC CATCH_ALL

IF sy-batch = c_true. "(3)

*-- Message: File could not be opened

MESSAGE e159 WITH wa_filelist-name.

ELSE. "(3)

*-- Message: File could not be opened

MESSAGE i145 WITH wa_filelist-name.

LEAVE LIST-PROCESSING.

ENDIF.

ENDTRY.

ENDDO.

  • Close the file in the application server

  • CLOSE DATASET p_apfile.

CLOSE DATASET l_filename.

Reward is useful,

Regards,

Tanmay

Hi Little,

I have developed a program where I was reading from application server.

Please go through the code and make changes as per your reqiurement.

  • Open the file in application server

OPEN DATASET l_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  • If file openning is successful

IF sy-subrc = 0.

MOVE cl_abap_char_utilities=>cr_lf+0(1) TO l_car_ret.

MOVE cl_abap_char_utilities=>cr_lf+1(1) TO l_lin_feed .

DO.

TRY.

  • Read the file line by line

READ DATASET l_filename INTO wa_record-line.

  • If file read is successful

IF sy-subrc EQ 0.

SEARCH wa_record-line FOR l_car_ret.

IF sy-subrc = 0. "(3)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(3)

SEARCH wa_record-line FOR l_lin_feed.

IF sy-subrc = 0. "(4)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(4)

wa_record-filename = wa_filelist-name. " Filename

APPEND wa_record TO itab_record.

CLEAR wa_record.

ELSE.

EXIT.

ENDIF.

CATCH cx_root. "#EC CATCH_ALL

IF sy-batch = c_true. "(3)

*-- Message: File could not be opened

MESSAGE e159 WITH wa_filelist-name.

ELSE. "(3)

*-- Message: File could not be opened

MESSAGE i145 WITH wa_filelist-name.

LEAVE LIST-PROCESSING.

ENDIF.

ENDTRY.

ENDDO.

  • Close the file in the application server

  • CLOSE DATASET p_apfile.

CLOSE DATASET l_filename.

Reward is useful,

Regards,

Tanmay

2 REPLIES 2
Read only

Former Member
0 Likes
526

Hi Little,

I have developed a program where I was reading from application server.

Please go through the code and make changes as per your reqiurement.

  • Open the file in application server

OPEN DATASET l_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

  • If file openning is successful

IF sy-subrc = 0.

MOVE cl_abap_char_utilities=>cr_lf+0(1) TO l_car_ret.

MOVE cl_abap_char_utilities=>cr_lf+1(1) TO l_lin_feed .

DO.

TRY.

  • Read the file line by line

READ DATASET l_filename INTO wa_record-line.

  • If file read is successful

IF sy-subrc EQ 0.

SEARCH wa_record-line FOR l_car_ret.

IF sy-subrc = 0. "(3)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(3)

SEARCH wa_record-line FOR l_lin_feed.

IF sy-subrc = 0. "(4)

CLEAR l_pos.

MOVE sy-fdpos TO l_pos.

REPLACE wa_record-line+l_pos(1) IN wa_record-line WITH space.

ENDIF. "(4)

wa_record-filename = wa_filelist-name. " Filename

APPEND wa_record TO itab_record.

CLEAR wa_record.

ELSE.

EXIT.

ENDIF.

CATCH cx_root. "#EC CATCH_ALL

IF sy-batch = c_true. "(3)

*-- Message: File could not be opened

MESSAGE e159 WITH wa_filelist-name.

ELSE. "(3)

*-- Message: File could not be opened

MESSAGE i145 WITH wa_filelist-name.

LEAVE LIST-PROCESSING.

ENDIF.

ENDTRY.

ENDDO.

  • Close the file in the application server

  • CLOSE DATASET p_apfile.

CLOSE DATASET l_filename.

Reward is useful,

Regards,

Tanmay

Read only

Former Member
0 Likes
525

Hi,

Refere the following code for the poulating internal from the application server.

PARAMETERS : pr_sfile TYPE filename-fileintern,

Here give the logical file name from the application serevr.

data : w_param_1 LIKE filename-fileintern,

x_file(500),

w_move_file LIKE epsf-epsfilnam,

w_from_dir LIKE epsf-epsdirnam,

w_path LIKE rlgrap-filename,

input_line(1000),

w_path LIKE rlgrap-filename,

w_file LIKE rlgrap-filename,

w_dir LIKE rlgrap-filename,

w_dir1 LIKE epsf-epsdirnam,

w_file1 LIKE epsf-epsfilnam,

**************Start of the code***************

MOVE '*' TO w_param_1.

PERFORM get_file_name USING pr_sfile w_param_1.

LOOP AT it_file WHERE name CP w_file1.

CLEAR : x_file, w_path,

w_move_file, w_from_dir.

REFRESH : it_input,

it_input_err.

  • IF w_flag IS INITIAL.

CONCATENATE w_dir it_file-name INTO x_file.

CONDENSE x_file.

    • TO Move file from sever for backup storing the file name and path

w_path = x_file.

CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = x_file

IMPORTING

stripped_name = w_move_file

file_path = w_from_dir

EXCEPTIONS

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

********here it_input will be the structure of the file present on the application server

PERFORM read_file TABLES it_input

USING x_file.

CLEAR it_input_err.

REFRESH it_input.

ENDLOOP.

*******************end of the code****************

&----


*& Form read_file

&----


  • text

----


  • -->P_X_FILE text

----


FORM read_file TABLES it_tab

USING x_file.

OPEN DATASET x_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

WRITE : / text-006.

ELSE.

DO.

READ DATASET x_file INTO input_line.

IF sy-subrc = 0.

CLEAR: it_input, count.

DO.

ADD 1 TO count.

ASSIGN COMPONENT count OF STRUCTURE it_tab TO <fs>.

IF sy-subrc = 0.

SPLIT input_line AT separator INTO <fs> input_line.

ELSE.

EXIT.

ENDIF.

ENDDO.

APPEND it_tab.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET x_file.

&----


*& Form get_file_name

&----


  • text

----


  • -->P_P_SFILE text

  • -->P_W_PARAM_1 text

----


FORM get_file_name USING p_sfile

w_param_1.

  • CHANGING x_file.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

client = sy-mandt

logical_filename = p_sfile

parameter_1 = w_param_1

IMPORTING

file_name = x_file

EXCEPTIONS

file_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.

w_path = x_file.

CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = w_path

IMPORTING

stripped_name = w_file

file_path = w_dir

EXCEPTIONS

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

w_dir1 = w_dir.

w_file1 = w_file.

CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'

EXPORTING

dir_name = w_dir1

file_mask = w_file1

TABLES

dir_list = it_file

EXCEPTIONS

invalid_eps_subdir = 1

sapgparam_failed = 2

build_directory_failed = 3

no_authorization = 4

read_directory_failed = 5

too_many_read_errors = 6

empty_directory_list = 7

OTHERS = 8.

IF sy-subrc <> 0.

WRITE : / text-006.

ENDIF.

Hope this will help you.