개념: ABAP에서 금액 필드(CURR:Currency field)는 통화키 필드(CUKY:Currency key)가 연결되어 있어야 합니다. 각 통화에 따라 금액 필드의 소수점을 해석하는 방법이 다릅니다. 예를 들어 금액 필드의 1.00 이라는 값을 USD 통화로는 1$로 해석하고 KRW 통화로는 100원으로 해석합니다. 금액 필드의 값을 통화 없이 값 그대로 사용하게 되면 100원을 1원으로 보게 됩니다. 금액에는 반드시 통화가 있어야 합니다. USD 통화일때는 무시해도 되는 함정이 있어서 USD만 테스트하는 실수를 주의해야 합니다.
흔한 오류: USD는 잘 되는데 KRW 통화일때 1/100 으로 표시 또는 처리 되어서 곱하기 100 을 하도록 로직 작성한다. 인터페이스 받아서 SAP에 저장하는데 KRW 통화일때 100배로 처리 되어서 나누기 100을 하도록 로직 작성한다.
무엇이 문제인가: KRW인지 체크하여 곱하기 100, 나누기 100을 하면 안됩니다. 표준적인 방법으로 통화를 적용하여 계산하세요.
왜 이렇게 하나요: 각 통화별로 금액의 최소 단위가 다르기 때문입니다. USD는 소수점 아래 2 자리까지 표시를 합니다. 0.01$(=1센트) 가 최소단위 입니다. KRW는 소수점이 없습니다. 1원이 최소단위 입니다. 소수점을 입력하면 안됩니다. 이런 차이를 수용하기 위한 방법입니다.
관련 테이블: 통화 마스터 테이블 TCURC 별 내용 없음 통화별 소수점 자리수 테이블 TCURX 기본값 2인 경우 생략되어 있음.
외부 -> 내부(SAP): BAPI_CURRENCY_CONV_TO_INTERNAL CURRENCY_AMOUNT_DISPLAY_TO_SAP
내부 외부 변환이 없어도 자동으로 적용되는 경우: 스트럭쳐에서 통화필드가 연결되어 있는 금액 필드를 SAP 화면에 표시하면 자동 적용.
변환이 필요한 경우: 고정된 통화라서 통화필드가 연결되지 않은 금액필드를 화면에 표시하는 경우. 금액을 인터페이스로 다른 시스템에 주거나 받는 경우. BDC로 작성한 프로그램에서 금액 입력시 외부 값으로 바꿔야함. 금액 필드를 숫자 필드로 타입 변환할때 외부 값으로 바꿔야함. 숫자 필드로 입력 받아서 DB에는 금액필드로 저장하는 경우 내부 값으로 바꿔야함.
CONVERT DATE lv_date_from TIME lv_time_from INTO TIME STAMP lv_ts TIME ZONE lv_tz_from. CONVERT TIME STAMP lv_ts TIME ZONE lv_tz_to INTO DATE lv_date_to TIME lv_time_to.
*&---------------------------------------------------------------------*
*& Report ZZIP
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zzip.
DATA: lt_file_table TYPE filetable,
ls_file_table TYPE file_table,
lv_rc TYPE i,
lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_filelength TYPE i,
lt_temptable TYPE w3mimetabtype,
lv_xstring TYPE xstring,
lo_zip TYPEREFTO cl_abap_zip.
cl_gui_frontend_services=>file_open_dialog(
EXPORTING* window_title = " Title Of File Open Dialog
* default_extension = " Default Extension
* default_filename = " Default File Name
* file_filter = " File Extension Filter String
* with_encoding = " File Encoding
* initial_directory = " Initial Directory
multiselection = abap_true" Multiple selections poss.
CHANGING
file_table = lt_file_table " Table Holding Selected Files
rc = lv_rc " Return Code, Number of Files or -1 If Error Occurred
* user_action = " User Action (See Class Constants ACTION_OK, ACTION_CANCEL)
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1" "Open File" dialog failed
cntl_error = 2" Control error
error_no_gui = 3" No GUI available
not_supported_by_gui = 4" GUI does not support this
OTHERS = 5
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CHECK: lt_file_table ISNOTINITIAL.
CREATEOBJECT lo_zip.
lo_zip->support_unicode_names = abap_true.
LOOPAT lt_file_table INTO ls_file_table.
CLEAR: lv_filename, lv_filelength, lt_temptable, lv_xstring.
lv_filename = ls_file_table-filename.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename " Name of file
filetype = 'BIN'" File Type (ASCII, Binary)
* has_field_separator = space " Columns Separated by Tabs in Case of ASCII Upload
* header_length = 0 " Length of Header for Binary Data
* read_by_line = 'X' " File Written Line-By-Line to the Internal Table
* dat_mode = space " Numeric and date fields are in DAT format in WS_DOWNLOAD
* codepage = " Character Representation for Output
* ignore_cerr = abap_true " Ignore character set conversion errors?
* replacement = '#' " Replacement Character for Non-Convertible Characters
* virus_scan_profile = " Virus Scan Profile
IMPORTING
filelength = lv_filelength " File Length
* header = " File Header in Case of Binary Upload
CHANGING
data_tab = lt_temptable " Transfer table for file contents
* isscanperformed = space " File already scanned
EXCEPTIONS
file_open_error = 1" File does not exist and cannot be opened
file_read_error = 2" Error when reading file
no_batch = 3" Cannot execute front-end function in background
gui_refuse_filetransfer = 4" Incorrect front end or error on front end
invalid_type = 5" Incorrect parameter FILETYPE
no_authority = 6" No upload authorization
unknown_error = 7" Unknown error
bad_data_format = 8" Cannot Interpret Data in File
header_not_allowed = 9" Invalid header
separator_not_allowed = 10" Invalid separator
header_too_long = 11" Header information currently restricted to 1023 bytes
unknown_dp_error = 12" Error when calling data provider
access_denied = 13" Access to file denied.
dp_out_of_memory = 14" Not enough memory in data provider
disk_full = 15" Storage medium is full.
dp_timeout = 16" Data provider timeout
not_supported_by_gui = 17" GUI does not support this
error_no_gui = 18" GUI not available
OTHERS = 19
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALLFUNCTION'SCMS_BINARY_TO_XSTRING'EXPORTING
input_length = lv_filelength
* first_line = 0
* last_line = 0
IMPORTINGbuffer = lv_xstring
TABLES
binary_tab = lt_temptable
EXCEPTIONS
failed = 1OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALLFUNCTION'SO_SPLIT_FILE_AND_PATH'EXPORTING
full_name = ls_file_table-filename
IMPORTING
stripped_name = lv_filename
EXCEPTIONS
x_error = 1OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
lo_zip->add(
EXPORTING
name = lv_filename
content = lv_xstring
* compress_level = 6 " Level of Compression
).
ENDLOOP.
lv_xstring = lo_zip->save( ).
CALLFUNCTION'SCMS_XSTRING_TO_BINARY'EXPORTINGbuffer = lv_xstring
IMPORTING
output_length = lv_filelength
TABLES
binary_tab = lt_temptable.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING* window_title = " Window Title
default_extension = 'ZIP'" Default Extension
default_file_name = 'a.zip'" Default File Name
* with_encoding =
file_filter = 'ZIP(*.ZIP)|*.ZIP'" File Type Filter Table
* initial_directory = " Initial Directory
* prompt_on_overwrite = 'X'
CHANGING
filename = lv_filename " File Name to Save
path = lv_path " Path to File
fullpath = lv_fullpath " Path + File Name
* user_action = " User Action (C Class Const ACTION_OK, ACTION_OVERWRITE etc)
* file_encoding =
EXCEPTIONS
cntl_error = 1" Control error
error_no_gui = 2" No GUI available
not_supported_by_gui = 3" GUI does not support this
invalid_default_file_name = 4" Invalid default file name
OTHERS = 5
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_filelength " File length for binary files
filename = lv_fullpath " Name of file
filetype = 'BIN'" File type (ASCII, binary ...)
* append = space " Character Field of Length 1
* write_field_separator = space " Separate Columns by Tabs in Case of ASCII Download
* header = '00' " Byte Chain Written to Beginning of File in Binary Mode
* trunc_trailing_blanks = space " Do not Write Blank at the End of Char Fields
* write_lf = 'X' " Insert CR/LF at End of Line in Case of Char Download
* col_select = space " Copy Only Selected Columns of the Table
* col_select_mask = space " Vector Containing an 'X' for the Column To Be Copied
* dat_mode = space " Numeric and date fields are in DAT format in WS_DOWNLOAD
* confirm_overwrite = space " Overwrite File Only After Confirmation
* no_auth_check = space " Switch off Check for Access Rights
* codepage = " Character Representation for Output
* ignore_cerr = abap_true " Ignore character set conversion errors?
* replacement = '#' " Replacement Character for Non-Convertible Characters
* write_bom = space " If set, writes a Unicode byte order mark
* trunc_trailing_blanks_eol = 'X' " Remove Trailing Blanks in Last Column
* wk1_n_format = space
* wk1_n_size = space
* wk1_t_format = space
* wk1_t_size = space
* show_transfer_status = 'X' " Enables suppression of transfer status message
* fieldnames = " Table Field Names
* write_lf_after_last_line = 'X' " Writes a CR/LF after final data record
* virus_scan_profile = '/SCET/GUI_DOWNLOAD' " Virus Scan Profile
* IMPORTING
* filelength = " Number of bytes transferred
CHANGING
data_tab = lt_temptable " Transfer table
EXCEPTIONS
file_write_error = 1" Cannot write to file
no_batch = 2" Cannot execute front-end function in background
gui_refuse_filetransfer = 3" Incorrect Front End
invalid_type = 4" Invalid value for parameter FILETYPE
no_authority = 5" No Download Authorization
unknown_error = 6" Unknown error
header_not_allowed = 7" Invalid header
separator_not_allowed = 8" Invalid separator
filesize_not_allowed = 9" Invalid file size
header_too_long = 10" Header information currently restricted to 1023 bytes
dp_error_create = 11" Cannot create DataProvider
dp_error_send = 12" Error Sending Data with DataProvider
dp_error_write = 13" Error Writing Data with DataProvider
unknown_dp_error = 14" Error when calling data provider
access_denied = 15" Access to file denied.
dp_out_of_memory = 16" Not enough memory in data provider
disk_full = 17" Storage medium is full.
dp_timeout = 18" Data provider timeout
file_not_found = 19" Could not find file
dataprovider_exception = 20" General Exception Error in DataProvider
control_flush_error = 21" Error in Control Framework
not_supported_by_gui = 22" GUI does not support this
error_no_gui = 23" GUI not available
OTHERS = 24
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA:
LT_ROOT_KEY TYPE /BOBF/T_FRW_KEY,
LT_ROOT TYPE /SCMTMS/T_TOR_ROOT_K,
LT_ALL_ITEMS TYPE /SCMTMS/T_TOR_ITEM_TR_K,
LT_STOP TYPE /SCMTMS/T_TOR_STOP_K,
LT_STOP_SUCC_ALL TYPE /SCMTMS/T_TOR_STOP_SUCC_K,
LT_DOC_REFERENCE TYPE /SCMTMS/T_TOR_DOCREF_K,
LT_EXEC TYPE /SCMTMS/T_TOR_EXEC_K,
LT_PARTY TYPE /SCMTMS/T_TOR_PARTY_K,
FIELD-SYMBOLS:
<LS_ROOT> TYPE /SCMTMS/S_TOR_ROOT_K,
<LS_ITEM> TYPE /SCMTMS/S_TOR_ITEM_TR_K,
<LS_STOP> TYPE /SCMTMS/S_TOR_STOP_K,
<LS_STOP_SUCC> TYPE /SCMTMS/S_TOR_STOP_SUCC_K,
<LS_DOC_REFERENCE> TYPE /SCMTMS/S_TOR_DOCREF_K,
<LS_EXEC> TYPE /SCMTMS/S_TOR_EXEC_K,
<LS_PARTY> TYPE /SCMTMS/S_TOR_PARTY_K,
" Invalidate cache
/bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( )->cleanup( ).
" Get TOR data
/scmtms/cl_tor_helper_common=>get_tor_data(
EXPORTING
it_root_key = lt_root_key
IMPORTING
et_root = lt_root
et_all_items = lt_all_items
et_stop = lt_stop
et_stop_succ_all = lt_stop_succ_all
et_doc_reference = lt_doc_reference
et_exec = lt_exec
et_party = lt_party
).
/SCMTMS/T_TOR_ITEM_TR_K에 Secondary Key 가 여러개 있습니다. Internal Table 의 Secondary Key 는 마치 DB Index 와 비슷한 역할을 하여 검색 속도를 빠르게 해줍니다. 차이점은 Secondary Key 가 여러개 있어도 Insert 속도에 영향을 주지 않습니다. Secondary Key 의 Indexing 생성 시기는 최초 사용시 입니다. 사용하지 않는 Secondary Key 는 Indexing 하지 않습니다.