REPORT zjss.
CONSTANTS : lc_per TYPE p DECIMALS 2 VALUE '1.1'.
TYPES: BEGIN OF lty_file,
doc type char10,
item TYPE char6,
cost type p DECIMALS 2,
SalesAmount TYPE p DECIMALS 2,
END OF lty_file.
TYPES: BEGIN OF lty_string,
f1(10) TYPE c,
f2(10) TYPE c,
f3(10) TYPE c,
f4(10) TYPE c,
END OF lty_string.
DATA: lt_File TYPE STANDARD TABLE OF lty_File,
ls_File TYPE lty_File,
lt_string TYPE STANDARD TABLE OF lty_string,
lt_output TYPE STANDARD TABLE OF string,
ls_output TYPE string,
ls_string TYPE lty_string.
DATA: lv_app_server_file TYPE string.
START-OF-SELECTION.
PERFORM upload_file.
PERFORM download_File.
*&---------------------------------------------------------------------*
* Form upload_file
*&---------------------------------------------------------------------*
* To upload file data into SAP
*&---------------------------------------------------------------------*
FORM upload_file.
PERFORM upload_app_server.
PERFORM data_convert.
ENDFORM. "upload_file
*&---------------------------------------------------------------------*
* Form upload_app_server
*&---------------------------------------------------------------------*
* To read file from application server
*&---------------------------------------------------------------------*
FORM upload_app_server.
lv_app_server_file = '/sapdownload/BPC/in_main/test.csv'.
OPEN DATASET lv_app_server_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET lv_app_server_file INTO ls_string.
IF sy-subrc = 0.
APPEND ls_string TO lt_string.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_app_server_file.
ENDFORM. "upload_app_server
*&---------------------------------------------------------------------*
* Form data_convert
*&---------------------------------------------------------------------*
* To convert file to specified format
*&---------------------------------------------------------------------*
FORM data_convert.
DATA: lv_file_separator TYPE c.
lv_file_separator = ','.
READ TABLE lt_string INTO ls_output INDEX 1.
APPEND ls_output to lt_output.
LOOP AT lt_string INTO ls_string FROM 2.
SPLIT LS_string at ',' INTO ls_string-f1 ls_string-f2 ls_string-f3 ls_string-f4.
ls_file-doc = ls_string-f1.
ls_file-item = ls_string-f2.
ls_file-cost = ls_string-f3.
ls_file-costprofit = ls_file-cost * lc_per.
ls_string-f4 = ls_file-costprofit.
CONDENSE ls_string-f4.
CONCATENATE ls_string-f1 ls_string-f2 ls_string-f3 ls_string-f4 INTO ls_output SEPARATED BY ',' .
APPEND ls_output to lt_output.
ENDLOOP.
ENDFORM. "data_convert
*&---------------------------------------------------------------------*
* Form download_file
*&---------------------------------------------------------------------*
* To assign field value into character format
*&---------------------------------------------------------------------*
FORM download_File.
OPEN DATASET lv_app_server_file FOR UPDATE IN TEXT MODE ENCODING DEFAULT.
LOOP AT lt_output INTO ls_output.
TRANSFER ls_output to lv_app_server_File.
ENDLOOP.
CLOSE DATASET lv_app_server_file.
ENDFORM. "data_assign
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 |