REPORT ztest.
*---data declarations
DATA: file_content TYPE string.
*---selection screen
PARAMETERS:p_file TYPE char100 DEFAULT 'F:\usr\sap\put\venkat.txt',
p_input TYPE char20,
p_char TYPE char30,
p_pos TYPE i.
*---get f4 help for the file
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_file.
*---start of selection
START-OF-SELECTION.
PERFORM write_file.
PERFORM update_file.
PERFORM display_file.
*&---------------------------------------------------------------------*
*& Form write_file
*----------------------------------------------------------------------*
FORM write_file .
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
with smart linefeed.
TRANSFER p_input TO p_file.
CLOSE DATASET p_file .
ENDFORM. " write_file
*&---------------------------------------------------------------------*
*& Form update_file
*----------------------------------------------------------------------*
FORM update_file .
OPEN DATASET p_file FOR UPDATE IN TEXT MODE
ENCODING DEFAULT
with smart linefeed
AT POSITION p_pos.
TRANSFER p_char TO p_file.
CLOSE DATASET p_file.
ENDFORM. " update_file
*&---------------------------------------------------------------------*
*& Form display_file
*----------------------------------------------------------------------*
FORM display_file .
OPEN DATASET p_file FOR INPUT IN TEXT MODE
ENCODING DEFAULT
with smart linefeed.
WHILE sy-subrc = 0.
READ DATASET p_file INTO file_content.
WRITE / file_content.
ENDWHILE.
CLOSE DATASET p_file.
ENDFORM. " display_file
*&---------------------------------------------------------------------*
*& Form f4_file
*----------------------------------------------------------------------*
FORM f4_file .
*-- if the file location is application server
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = '/'
filemask = '*'
IMPORTING
serverfile = p_file
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " f4_file
the selection screen is like this:
and the output is like this:
No comments:
Post a Comment