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

uploading data into a fixed length file

Former Member
0 Likes
777

hello experts,

I got a task to upload data into a fixed length positional file from internal table.So please help me.

regards,

sriram.

2 REPLIES 2
Read only

Former Member
0 Likes
536

Hi there. What you basically need to do is set up the path and name for the export file, move your records to an output table, and then transfer the data to the file that you have specified. We usually set up our export programs so that the user can choose to download the file locally or onto the application server. So first we define the following fields on the selection screen:

PARAMETERS: p_file(128) LOWER CASE OBLIGATORY. "File

*path name from system standard

PARAMETERS: p_path LIKE rlgrap-filename MODIF ID fpn. "Path Name

PARAMETERS: p_local AS CHECKBOX. "Local File Flag

*******************************************

Then we use this to set the path to the application server:

INITIALIZATION.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

logical_filename = 'Z_AO_HR_UP_LOAD'

parameter_1 = space

IMPORTING

emergency_flag = lw_emergency_flag

file_name = p_path

EXCEPTIONS

file_not_found = 1

OTHERS = 2.

AT SELECTION-SCREEN OUTPUT.

  • make path name display only

LOOP AT SCREEN.

CHECK screen-group1 = 'FPN'.

screen-input = 0. "Output (Display) only

MODIFY SCREEN.

ENDLOOP.

*******************************************

After your START-OF-SELECTION statement, you need to open the file for output:

IF p_local NE ztc_on.

  • Get Path/file Name using logical filename.

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

logical_filename = 'Z_AO_HR_UP_LOAD'

parameter_1 = p_file

IMPORTING

emergency_flag = lw_emergency_flag

file_name = p_path

EXCEPTIONS

file_not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

w_message = 'No Output file - Missing Logical File Z_AO_HR_UP_LOAD'.

WRITE: / w_message.

IF sy-batch = 'X'. "Is this in a job?

NEW-PAGE.

PERFORM end_of_selection.

MESSAGE e000(38) WITH w_message. "This causes the job to cancel

ELSE.

MESSAGE i000(38) WITH w_message.

ENDIF.

w_stop = 'X'.

STOP.

ENDIF.

*Check if output file is already present.

OPEN DATASET p_path FOR INPUT IN TEXT MODE.

IF sy-subrc EQ 0.

CLOSE DATASET p_path.

WRITE: 'Output Data file already present ', p_path.

*Use the following for logging error message

CONCATENATE 'Ouput Data file already present ' p_path INTO

w_message.

IF sy-batch = ztc_on. "Is this in a job?

NEW-PAGE.

PERFORM end_of_selection.

MESSAGE e000(38) WITH w_message. "This causes the job to cancel

ELSE.

MESSAGE i000(38) WITH w_message.

ENDIF.

w_stop = 'X'.

STOP.

ENDIF.

OPEN DATASET p_path FOR OUTPUT IN TEXT MODE.

IF sy-subrc <> 0.

WRITE: 'Unable to open output dataset - ', p_path.

*Use the following for logging error message

CONCATENATE 'Unable to open output dataset - ' p_path INTO

w_message.

IF sy-batch = ztc_on. "Is this in a job?

NEW-PAGE.

PERFORM end_of_selection.

MESSAGE e000(38) WITH w_message. "This causes the job to cancel

ELSE.

MESSAGE i000(38) WITH w_message.

ENDIF.

w_stop = 'X'.

STOP.

ENDIF.

ENDIF.

*******************************************

Next you perform all of the steps to put your data in the internal table. After the end of selection we then transfer the data from the original internal table (which has many separate fields defined) to a second internal table, t_outfile, in which each record has a single field that is the total length of the original itab record:

*Internal table for Output data

DATA : BEGIN OF t_outfile OCCURS 0,

text(1000).

DATA : END OF t_outfile.

Then you can download your file, checking whether it goes to a local drive or the application server:

IF p_local EQ ztc_on.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = p_file

TABLES

data_tab = t_outfile

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

gui_refuse_filetransfer = 8

OTHERS = 9.

ELSE.

LOOP AT t_outfile.

TRANSFER t_outfile TO p_path.

ENDLOOP.

ENDIF.

****************************

Now close your dataset if it is on the application server:

IF p_local NE ztc_on.

CLOSE DATASET p_path.

ENDIF.

I hope this helps!

- April King

Read only

Former Member
0 Likes
536

I got the answer from the experts solutions to my question and solutions in other threads.

thanks