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

code reading second line

Former Member
0 Likes
1,005

hi,

how to read the second line of file placed in application server in to the internal table

5 REPLIES 5
Read only

Former Member
0 Likes
663

hi,

Read the entire file into an in internal table and use statement..


READ TABLE ITAB INDEX 2. 

Regards,

Santosh

Read only

Former Member
0 Likes
663

*    To get the data from application server file
    OPEN DATASET p_filename IN TEXT MODE FOR INPUT ENCODING DEFAULT.
    IF sy-subrc <> 0.
      MESSAGE e001 WITH p_filename.
    ENDIF.
    CLEAR: wa_local.

    DO.
      READ DATASET p_filename INTO wa_local.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.

      APPEND wa_local TO p_local_table.
      CLEAR: wa_local.
    ENDDO.
    CLOSE DATASET p_filename.

To read the second recode:



    DO.
     
      IF sy-tabix EQ 2.
         READ DATASET p_filename INTO wa_local.
         IF sy-subrc  0.
             EXIT.
         ENDIF.
 
         APPEND wa_local TO p_local_table.
        CLEAR: wa_local.
     ENDIF.
    ENDDO.

Read only

Former Member
0 Likes
663

Hi,

Try using index.

Thanks,

Sriram Ponna.

Read only

asik_shameem
Active Contributor
0 Likes
663

Hi,

Try like this.

DO. 

  READ DATASET file INTO line. 
  IF sy-index = 2. 
    lv_line = line.
    EXIT. 
  ENDIF. 
  
ENDDO.

Read only

Former Member
0 Likes
663

Hi,

Please use the following code.

*Open the File in READ mode

open dataset <filename> for input in text mode encoding default.

  • Read the File.

read dataset <filename> to it_data.

if sy-subrc eq 0.

append it_data.

clear it_data.

endif.

  • Close the File

close dataset <filename>.