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

Getting .CSV file from sap server, using Logical File and module FILE_GET_NAME to retrieve

former_member201275
Active Contributor
0 Likes
1,157

Hi

I have googled but cannot find an example of how to get a .csv file from the SAP server (AL11) into an internal table in my program. I want to use Logical File transaction FILE to specify where the file path. Then I assume I would use function FILE_GET_NAME to get the file before using open_dataset etc.

The problem is I cannot get the Logical File to work. 😞

1 ACCEPTED SOLUTION
Read only

Nawanandana
Active Contributor
0 Likes
816

Hi,

To read the file path used bellow link.

https://answers.sap.com/questions/10308209/fm-to-read-a-file-path-based-on-al11-profile.html

To read the CSV file, use bellow

OPEN DATASET filename FOR INPUT IN TEXT MODE
                ENCODING DEFAULT MESSAGE msg.   
IF SY-SUBRC EQ 0.
DO.
   READ DATASET filename INTO l_string.
   IF sy-subrc NE 0.
     EXIT.
   ELSE.
     SPLIT l_string AT ',' INTO WA-FIELD1  WA-FIELD2 ..... WA-FIELDn.
     APPEND wa to datatab.
   ENDIF.
ENDDO.
  CLOSE DATASET filename.
ENDIF.

Hi

I have googled but cannot find an example of how to get a .csv file from the SAP server (AL11) into an internal table in my program. I want to use Logical File transaction FILE to specify where the file path. Then I assume I would use function FILE_GET_NAME to get the file before using open_dataset etc.

The problem is I cannot get the Logical File to work. 😞

1 REPLY 1
Read only

Nawanandana
Active Contributor
0 Likes
817

Hi,

To read the file path used bellow link.

https://answers.sap.com/questions/10308209/fm-to-read-a-file-path-based-on-al11-profile.html

To read the CSV file, use bellow

OPEN DATASET filename FOR INPUT IN TEXT MODE
                ENCODING DEFAULT MESSAGE msg.   
IF SY-SUBRC EQ 0.
DO.
   READ DATASET filename INTO l_string.
   IF sy-subrc NE 0.
     EXIT.
   ELSE.
     SPLIT l_string AT ',' INTO WA-FIELD1  WA-FIELD2 ..... WA-FIELDn.
     APPEND wa to datatab.
   ENDIF.
ENDDO.
  CLOSE DATASET filename.
ENDIF.