Hi please find the below code ,
START-OF-SELECTION.
perform select_data.
if gt_knkk is NOT initial.
perform save_file.
endif.
FORM select_data .
SELECT kunnr
kkber
klimk
knkli
skfor FROM knkk INTO TABLE gt_knkk
WHERE kkber IN s_area
AND knkli IN s_accnt.
ENDFORM. " SELECT_DATA
FORM save_file .
DATA : lv_data TYPE string,
lv_file LIKE gv_file,
lv_name TYPE string VALUE 'test.txt',
lv_email TYPE string,
lv_knkli TYPE char20,
lv_klimk TYPE char20,
lv_skfor TYPE char20.
DATA : lc_add TYPE char10 VALUE 'ADD',
lc_mod TYPE char10 VALUE 'MODIFY',
lc_del TYPE char10 VALUE 'DELETE'.
gv_file = 'QR1\SAP_HR\ST\AR\'.
CONCATENATE gv_file lv_name INTO gv_file.
IF rb_add = 'X'.
OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
TRANSFER 'VERSION : 10.1' TO gv_file.
CONCATENATE 'EMAIL RESPONSE' s_email-low INTO lv_email.
TRANSFER lv_email TO gv_file.
LOOP AT gt_knkk INTO gs_knkk.
lv_klimk = gs_knkk-klimk.
lv_knkli = gs_knkk-knkli.
lv_skfor = gs_knkk-skfor.
CONCATENATE lc_add
'SALARYFEED'
lv_klimk
lv_knkli
lv_skfor
INTO lv_data SEPARATED BY ';'.
TRANSFER lv_data TO gv_file.
CLEAR : gs_knkk,lv_klimk,lv_knkli,lv_skfor.
ENDLOOP.
CLOSE DATASET lv_file.
ENDIF.
ENDFORM. " SAVE_FILE