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 Data from a SQL table to a Logical file on R/3 appl. Server

Former Member
0 Kudos
82

Hi All,

We would like to create Master Data using LSMW (direct Input) with source files from R/3 Application Server.

I have created files in the'/ tmp/' directory however I do not know how to read data from the SQL table and insert it into the logical file on the R/3 application server.

I am new to ABAP , please let me know the steps to be done to acheive this .

Regards

- Ajay

1 ACCEPTED SOLUTION

Former Member
0 Kudos
56

Use READ DATASET and TRANSFER concept to read data from SQL table and write it to a file on Apll Server.

3 REPLIES 3

Former Member
0 Kudos
57

Use READ DATASET and TRANSFER concept to read data from SQL table and write it to a file on Apll Server.

Former Member
0 Kudos
56

That helps for sure, what i am looking more for is a step by step guide to do this or if ther is a template program whihc I can use.

Thanks

0 Kudos
56

Hi,

You can find lot of information about Datasets in SCN just SEARCH once.

You can check the code snippet for understanding

DATA:
BEGIN OF fs,
  carrid TYPE s_carr_id,
  connid TYPE s_conn_id,
END OF fs.
DATA:
  itab    LIKE
          TABLE OF fs,
  w_file  TYPE char255 VALUE 'FILE',
  w_file2 TYPE char255 VALUE 'FILE2'.

SELECT carrid connid FROM spfli INTO TABLE itab.

OPEN DATASET w_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. "Opening a file in Application
                                                        " Server to write data
LOOP AT itab INTO fs.
  TRANSFER fs TO w_file. "" Writing the data into the Application server file
ENDLOOP.
CLOSE DATASET w_file.

OPEN DATASET w_file FOR INPUT IN TEXT MODE ENCODING DEFAULT. "Opening a file in Application 
                                                      " server to read data
FREE itab.
DO.
  READ DATASET w_file INTO fs.
  IF sy-subrc EQ 0.
    APPEND fs TO itab.
    OPEN DATASET w_file2 FOR APPENDING IN TEXT MODE ENCODING DEFAULT. "Appending more data to the file in the
                                                       " application server
    TRANSFER fs TO w_file2.
    CLOSE DATASET w_file2.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.

Regards

Sarves