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

Upload CSV file in background

Former Member
0 Likes
2,587

Hi,

How 2 upload CSV file in Background, if the Flat file is input .

regrds

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,700

as GUI_* and WS_* function modules do not work in background

When scheduling a job in the background the appropriate statement to read in your file is OPEN DATASET, and the file must be on the file system that the SAP server can see.

At anytime, a user can switch of the Personal Computers even though the job is still running in the background. Therefore GUI_* and WS_* function modules are not designed to work in that way, as they need to access your personal computer file.

To choose the correct download method to used, you can check the value of SY-BATCH in your code,

if it is 'X' use OPEN DATASET and if it is ' ' use WS_UPLOAD.

*-- Open dataset for reading

DATA:

dsn(20) VALUE '/usr/test.dat',

rec(80).

OPEN DATASET dsn FOR INPUT IN TEXT MODE.

IF sy-subrc = 0.

DO.

READ DATASET dsn INTO rec.

IF sy-subrc <> 0.

EXIT.

ELSE.

WRITE / rec.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET dsn.

*-- Open dataset for writing

DATA rec(80).

OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.

TRANSFER rec TO '/usr/test.dat'.

CLOSE DATASET dsn.

Hope this will solve your problem.

Regards.

Rajnesh

Edited by: Rajnesh Dharmat on Mar 3, 2009 1:53 PM

Hi,

How 2 upload CSV file in Background, if the Flat file is input .

regrds

5 REPLIES 5
Read only

Former Member
0 Likes
1,701

as GUI_* and WS_* function modules do not work in background

When scheduling a job in the background the appropriate statement to read in your file is OPEN DATASET, and the file must be on the file system that the SAP server can see.

At anytime, a user can switch of the Personal Computers even though the job is still running in the background. Therefore GUI_* and WS_* function modules are not designed to work in that way, as they need to access your personal computer file.

To choose the correct download method to used, you can check the value of SY-BATCH in your code,

if it is 'X' use OPEN DATASET and if it is ' ' use WS_UPLOAD.

*-- Open dataset for reading

DATA:

dsn(20) VALUE '/usr/test.dat',

rec(80).

OPEN DATASET dsn FOR INPUT IN TEXT MODE.

IF sy-subrc = 0.

DO.

READ DATASET dsn INTO rec.

IF sy-subrc <> 0.

EXIT.

ELSE.

WRITE / rec.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET dsn.

*-- Open dataset for writing

DATA rec(80).

OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.

TRANSFER rec TO '/usr/test.dat'.

CLOSE DATASET dsn.

Hope this will solve your problem.

Regards.

Rajnesh

Edited by: Rajnesh Dharmat on Mar 3, 2009 1:53 PM

Read only

Former Member
0 Likes
1,700

hi,

you have to call it from Applications server using OPEN DATASET and CLOSE DATASET.

GUI_UPLOAD in background wont work.

thanks

Read only

Former Member
0 Likes
1,700

Hi,

Try like this....



lv_filename = <input file path>

 open dataset lv_filename for input in text mode encoding default.
    if sy-subrc = 0.
      do.
        read dataset lv_filename into gs_input-wa_string.
        if sy-subrc eq 0.
          append gs_input to gt_input.
        else.
          exit.
        endif.
      enddo.
      close dataset lv_filename.
    endif.

Hope its helps

Read only

0 Likes
1,700

Hi All,

Thanks for the reply,

our system is as follows,

The user logins to the portal and enters the data to the screen and submits,

The UI people turns it to a csv file and sends it to my RFC

so can I follow above procedure.... and is it the only procedure....?

Regards

Read only

0 Likes
1,700

if your RFC places the file in Application server.. you can use open dataset statement and get data to internal table by using split at comma....

key words to search Open dataset CSV application server file