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

sy-subrc 4 while read dataset from application server file.

Former Member
0 Likes
6,273

Hi team

my requirement is that upload the CSV file into the application server (AL11) and through program read this file .while reading this file it gives sy-subrc eq 4 . please suggest what can i do for reading the file.

What i am doing right now in the code as follows.

OPEN DATASET p_file FOR INPUT IN BINARY MODE.

DO .

READ DATASET p_file INTO st_string.

IF sy-subrc EQ 0 .

SPLIT st_string AT ',' INTO

gs_agent_file_input-zcntrl_grp

gs_agent_file_input-zlease_typ_sg

gs_agent_file_input-zne_user IN CHARACTER MODE.

APPEND gs_agent_file_input TO gt_agent_file_input.

CLEAR gs_agent_file_input.

ENDIF.

But currently i am getting sy-subrc 4. Please suggest me how can i read this file.

Thanks in Advance.

Puneet.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,753

Hi guys

i am working on something similar where firstly i need to read data from internal table then encode it and after that need to download that to presentation server.

st_string type string is not supported with read dataset.. u better use st_string(5000), where 5000 is the expected number of characters...

I hope this will help u out.

See this example code

DATA: BEGIN OF ITAB OCCURS 0,

LINE(5000),

END OF ITAB1.

DATA: file_path(50) TYPE C.

file_path = ' '. "FILE PATH GOES HERE

OPEN DATASET file_path FOR INPUT IN BINARY MODE.

DO.

READ DATASET file_path INTO ITAB.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND ITAB.

ENDDO.

CLOSE DATASET file_path.

Hi team

my requirement is that upload the CSV file into the application server (AL11) and through program read this file .while reading this file it gives sy-subrc eq 4 . please suggest what can i do for reading the file.

What i am doing right now in the code as follows.

OPEN DATASET p_file FOR INPUT IN BINARY MODE.

DO .

READ DATASET p_file INTO st_string.

IF sy-subrc EQ 0 .

SPLIT st_string AT ',' INTO

gs_agent_file_input-zcntrl_grp

gs_agent_file_input-zlease_typ_sg

gs_agent_file_input-zne_user IN CHARACTER MODE.

APPEND gs_agent_file_input TO gt_agent_file_input.

CLEAR gs_agent_file_input.

ENDIF.

But currently i am getting sy-subrc 4. Please suggest me how can i read this file.

Thanks in Advance.

Puneet.

15 REPLIES 15
Read only

Former Member
0 Likes
3,753

hi,

Declare st_string type character (CHAR)

Regards,

Dheeraj

Read only

Former Member
0 Likes
3,753

Hi,

firstly check in the application server if that file has any data in it...

Regards,

Siddarth

Read only

Former Member
0 Likes
3,753

Hi,

That file is having data in the application server.

Have you checked that?

Regards,

Jyothi CH.

Read only

0 Likes
3,753

Hi

yes, i have checked the file, file contains comma seperated file like

110000,1000,01,01

110001,1000,01,01

110002,1000,01,01

i have taken st_sting type string.

please suggest me what can i do.

thanks

puneet.

Read only

kanishakgupta1
Contributor
0 Likes
3,753

declare st_string as a string.

Read only

Former Member
0 Likes
3,753

Hi Team,

till now problem is not resolved . please do the needful information for resolving this problem.

Thanks in Advance.

Puneet.

Read only

0 Likes
3,753

check the location if the file exist or not

Read only

0 Likes
3,753

Hi Puneet,

Check the below piece of lines

*Read the file from the Application Server

DATA : w_filename(1024) TYPE c,
    OPEN DATASET w_filename FOR INPUT IN TEXT MODE
                            ENCODING DEFAULT.
    IF sy-subrc NE 0.
* Error while opening the file for output.
      MESSAGE e999(zfi_ap_gl) WITH text-005.
    ELSE.

      DO.
* reading the data into the internal table.
        READ DATASET w_filename INTO wa_file.
        IF sy-subrc EQ 0.

          PERFORM fill_data.

        ELSE.
          EXIT.
        ENDIF.
        CLEAR : wa_file.
      ENDDO.

      CLOSE DATASET w_filename.

    ENDIF.
  ENDIF.
ENDFORM.                    " READ_DATA

This is an example.

Hope that will be helpful for you.

Thanks,

Babu Kilari

Read only

0 Likes
3,753

Puneeth,

When I pressed F1 on Read Dataset, I got the following information for Sy-Subrc

System Fields 

sy-subrc Meaning 
0 Data was read without reaching end of file. 
4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.

So, the problem is not with the declaration. Problem is only with the reading of the file.

1.Make sure that the file is not corrupted.

2.Make sure that the file content is available

3.As open dataset is working fine,I dont think there is no need to check the path. But, anyways make sure that it is given correct.

Try to debug the code and check all the above values and see what is actually hapening.

Thanks,

Babu Kilari

Read only

Former Member
0 Likes
3,753

Its Strange..... Check whether correct Path is passed in p_file Variable. Chk the subrc value after Open Dataset....Careful with '/' and '\' coz if the appl server is on Linux then use the first one or else use the second one. Also do have a check whether the length of p_file is long enough to hold the Path...

Edited by: shafivullah mohammad on Apr 28, 2009 2:21 PM

Read only

0 Likes
3,753

Thanks.

I had same problem.Your solution is very helpful.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
3,753

Hi,

Trythis.

  • Local variable Declaration

DATA l_msg(60) TYPE c.

OPEN DATASET p_file FOR INPUT IN BINARY MODE

MESSAGE l_msg.

Then check the l_msg in debugging, it will give the nature of problem.

Read only

Former Member
0 Likes
3,753

Even i am facing the same situation if u get any solution can u tell me also

Read only

0 Likes
3,753

Vedhavathi,

Again, I would like to ask same questions. Have you debugged the code? Do you have the data in the file? Are you able to see the contents of the file in AL11?

Thanks,

Babu Kilari

Read only

Former Member
0 Likes
3,754

Hi guys

i am working on something similar where firstly i need to read data from internal table then encode it and after that need to download that to presentation server.

st_string type string is not supported with read dataset.. u better use st_string(5000), where 5000 is the expected number of characters...

I hope this will help u out.

See this example code

DATA: BEGIN OF ITAB OCCURS 0,

LINE(5000),

END OF ITAB1.

DATA: file_path(50) TYPE C.

file_path = ' '. "FILE PATH GOES HERE

OPEN DATASET file_path FOR INPUT IN BINARY MODE.

DO.

READ DATASET file_path INTO ITAB.

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

APPEND ITAB.

ENDDO.

CLOSE DATASET file_path.