Reading File On Application Server
-
for Reading the Data on Application Server, we need to follow the given steps :-
- OPEN DATASET ( file path ) FOR INPUT IN TEXT MODE ENCODING DEFAULT.
- TRANSFER ( DATA ) to ( File path )
- CLOSE DATASET
-
In the previous part, we have created a file on the application server.
-
Now, we will read that file on the application server.
Requirement :-
- How to read a file on the Application Server ?
Hints :-
- Open the file.
- Read the Data one by one
- Close the file
Solution :-
-
Step 1 :- Create a executable program in ABAP Editor.
-
Step 2 :- Declare the created file in the previous part.
-
Step 3 :- Open the File using FOR INPUT.
-
Step 4 :- Create a type structure for the VBAK table which we have used and then create a internal table and work area for it and also create a variable for string in which we will store file data.
-
Step 5 :- Use loop to read the file and stored it into string variable and then split it into the above work area and then append it into the internal table.
-
Step 6 :- After loop close the file.
-
Step 7 :- Display the interna; table in form of ALV.
Code :-
*&---------------------------------------------------------------------*
*& Report ZAR_READ_FILE_APPLICATION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zar_read_file_application.
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
END OF ty_vbak.
DATA : lt_vbak TYPE TABLE OF ty_vbak,
ls_vbak TYPE ty_vbak.
DATA : lv_string TYPE string.
DATA : lo_direct(20) TYPE c VALUE '/usr/sap/tmp/VBAK.txt'.
OPEN DATASET lo_direct FOR INPUT IN TEXT MODE ENCODING DEFAULT.
if sy-subrc eq 0.
DO.
READ DATASET lo_direct into lv_string.
if sy-subrc eq 0.
SPLIT lv_string at ' ' into ls_vbak-vbeln ls_vbak-erdat
ls_vbak-erzet ls_vbak-ernam ls_vbak-vbtyp.
Append ls_vbak to lt_vbak.
clear ls_vbak.
ELSE.
exit.
endif.
ENDDO.
CLOSE DATASET lo_direct.
endif.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = IF_SALV_C_BOOL_SAP=>FALSE
IMPORTING
r_salv_table = data(lo_alv)
CHANGING
t_table = lt_vbak
.
CATCH cx_salv_msg.
ENDTRY.
lo_alv->display( ).
Comments
Post a Comment