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: 

AL11 file download issue using Open Dataset in ABAP program

0 Kudos

Need urgent help.

I have a selection screen having two radio buttons - For Valid records download to AL11 and Invalid records download on AL11.

But data is not getting downloaded correctly on AL11 when i schedule the program using - EXECUTE in BACKGROUND option on selection screen.

Program code is below -

On Start of selection event -

on below condition, i am fetching data.

IF sy-batch = 'X' .
PERFORM get_data.

endif.

Then in next subroutine, Download data in same Start of selection event, i am writing the data to AL11.

*Correct records radio button
IF r1 EQ 'X' .
IF sy-batch = 'X'.

MOVE p_file2 TO file_name2.

CALL FUNCTION 'TRINT_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = file_name2
IMPORTING
stripped_name = lv_stripname2
file_path = lv_file_2
EXCEPTIONS
x_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

*File download on application server
* CONCATENATE lv_name 'Valid_recs_File' INTO lv_temp_path.
* CONCATENATE lv_path1 lv_temp_path sy-datum '_' sy-uzeit '.' lv_ext INTO fname.

CONCATENATE 'Valid_recs_file_' lv_stripname2 INTO lv_temp_path.
CONCATENATE lv_file_2 lv_temp_path INTO fname.

OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
IF t_final1[] IS NOT INITIAL.
LOOP AT t_final1 INTO wa_final1. "Valid documents
CLEAR lv_output.
CONCATENATE wa_final1-doknr
wa_final1-dokar
wa_final1-doktl
wa_final1-dokvr
INTO lv_output
SEPARATED BY '|'.

TRANSFER lv_output TO fname.
ENDLOOP.
ENDIF.
ENDIF.
CLOSE DATASET fname.
IF sy-subrc EQ 0.
WRITE 'Valid link attachment records file downloaded successfully on AL11' .
ENDIF.

Please let me know if i am missing anything as the valid file doesnt have any data in AL11. but the internal table - T_FINAL1 is having records to be written in Valid file download on AL11.

Please let me know if more information is required on this.

Thanks

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

First of all, change your program to handle the exceptions, and tell us what statement is faulty.

You may also directly start "the job" in debug mode in SM37 by selecting the job, entering JDBG in the command field and Enter (search the Web for more information).

abo
Active Contributor

Also, please format the code to make it easier to read. As far as I can see, this line is redundant:

IF t_final1[] IS NOT INITIAL.

(the LOOP won't be run if the array is empty, no need for protection)

Sandra_Rossi
Active Contributor

No reply, so I guess the question was not so urgent, or the OP has solved the issue since then.