Moving field symbol value to variable
data f1(4) value ‘ABC’.
DATA: v_val TYPE char4 VALUE ‘XYZA’.
field-symbols <f>.
assign f1 to <f>.
write <f>.
<f> = ‘ABD’.
Learning SAP 1/1
Monday, July 6, 2015
ABAP Dynamic Tables
- Reading Dynamic Table
REPORT z_dynamic_read. DATA: gt_itab TYPE REF TO data, ge_key_field1 TYPE char30, ge_key_field2 TYPE char30, ge_key_field3 TYPE char30, go_descr_ref TYPE REF TO cl_abap_tabledescr. FIELD-SYMBOLS: <gt_itab> TYPE STANDARD TABLE, <gs_key_comp> TYPE abap_keydescr, <gs_result> TYPE ANY. PARAMETERS: pa_table TYPE tabname16 DEFAULT 'SPFLI', pa_cond1 TYPE string DEFAULT sy-mandt, pa_cond2 TYPE string DEFAULT 'LH', pa_cond3 TYPE string DEFAULT '0123'. START-OF-SELECTION. * Create and populate internal table CREATE DATA gt_itab TYPE STANDARD TABLE OF (pa_table). ASSIGN gt_itab->* TO <gt_itab>. SELECT * FROM (pa_table) INTO TABLE <gt_itab>. * Get the key components into the fields ge_key_field1, ... go_descr_ref ?= cl_abap_typedescr=>describe_by_data_ref( gt_itab ). LOOP AT go_descr_ref->key ASSIGNING <gs_key_comp>. CASE sy-tabix. WHEN 1. ge_key_field1 = <gs_key_comp>-name. WHEN 2. ge_key_field2 = <gs_key_comp>-name. WHEN 3. ge_key_field3 = <gs_key_comp>-name. ENDCASE. ENDLOOP. * Finally, perform the search READ TABLE <gt_itab> ASSIGNING <gs_result> WITH KEY (ge_key_field1) = pa_cond1 (ge_key_field2) = pa_cond2 (ge_key_field3) = pa_cond3. IF sy-subrc = 0. WRITE / 'Record found.'. ELSE. WRITE / 'No record found.'. ENDIF.
One note: When an internal table is created dynamically like in my program above,
the table key isnot the key defined in the DDIC structure — instead, the default key
for the standard table is used (i.e. all non-numeric fields).
Getting Run Time
Use the GET RUN TIME FIELD statement to measure the relative runtime of program segments in microseconds. The syntax is as follows:
GET RUN TIME FIELD <f>. <f> is a variable, which should be of type I.
And in order to calculate the relative runtime of a program segment follow
GET RUN TIME FIELD F1.
Code segment for which runtime needs to be calculated.
GET RUN TIEM FIELD F2.
Difference of F2 and F1(F2-F1) gives the runtime of the code segment. This stmt is especially useful for performance tuning.
GET RUN TIME FIELD <f>. <f> is a variable, which should be of type I.
And in order to calculate the relative runtime of a program segment follow
GET RUN TIME FIELD F1.
Code segment for which runtime needs to be calculated.
GET RUN TIEM FIELD F2.
Difference of F2 and F1(F2-F1) gives the runtime of the code segment. This stmt is especially useful for performance tuning.
Japanese Currency
Here is my input to this issue. In SAP, amounts (data type CURR) are
always stored with two decimals in the database. It does not matter how
many decimals are actually allowed for that currency. Currencies like
JPY, KRW, CLP, etc. do not have any decimals.
In those cases, SAP both on ECC and BW divides the amount for those currencies by the decimal factor maintained in TCURX table and multiplies by the same factor on the report.
For example, -30,000 will be stored as -30,000/100 (because the TCURX table has 0 decimal). For zero decimals, SAP divides by 100. If we are loading the flat file data from HFM, we should make sure that this division occurs. After the division, -30,000 will be stored as -300. In the BW report, -300 will be multiplied by 100 and shown as -30,000. This division and multiplication occurs for all the exception currencies maintained in TCURX.
If the above division is not happening, the report will multiply by 100 by default and that will be an overstated amount by a factor of 100.
For HFM, I am assuming it is a flat file load. There are specific settings for flat file as stated in OSS Note 1176399 for special currency loads to work correctly. May be we had correct settings and it was working correctly and those settings recently somehow got changed.
In those cases, SAP both on ECC and BW divides the amount for those currencies by the decimal factor maintained in TCURX table and multiplies by the same factor on the report.
For example, -30,000 will be stored as -30,000/100 (because the TCURX table has 0 decimal). For zero decimals, SAP divides by 100. If we are loading the flat file data from HFM, we should make sure that this division occurs. After the division, -30,000 will be stored as -300. In the BW report, -300 will be multiplied by 100 and shown as -30,000. This division and multiplication occurs for all the exception currencies maintained in TCURX.
If the above division is not happening, the report will multiply by 100 by default and that will be an overstated amount by a factor of 100.
For HFM, I am assuming it is a flat file load. There are specific settings for flat file as stated in OSS Note 1176399 for special currency loads to work correctly. May be we had correct settings and it was working correctly and those settings recently somehow got changed.
Using Hash Tables
DATA :int_target TYPE HASHED TABLE OF y_target
WITH UNIQUE KEY
COMPANYCODE
CCTXTLG
ACCOUNT
ATXTLG
ERPID
ICP
ICPTXTLG
TRANSCURR
DATASOU
LCURR,
wa_target TYPE y_target. * Moving values to Hash Table to use Collect.
LOOP AT it_target INTO ls_target CLEAR:wa_target.
MOVE-CORRESPONDING ls_target TO wa_target.
COLLECT wa_target INTO int_target.
CLEAR:ls_target,ls_source.
ENDLOOP.
Notes: When displaying data in the output of APD, for the (some)same fields the key figures need to be added and shown. So a Hash Table is used
WITH UNIQUE KEY
COMPANYCODE
CCTXTLG
ACCOUNT
ATXTLG
ERPID
ICP
ICPTXTLG
TRANSCURR
DATASOU
LCURR,
wa_target TYPE y_target. * Moving values to Hash Table to use Collect.
LOOP AT it_target INTO ls_target CLEAR:wa_target.
MOVE-CORRESPONDING ls_target TO wa_target.
COLLECT wa_target INTO int_target.
CLEAR:ls_target,ls_source.
ENDLOOP.
Notes: When displaying data in the output of APD, for the (some)same fields the key figures need to be added and shown. So a Hash Table is used
Removing the -ve sign to the starting
var_csign TYPE /BIC/OITDATASOU .
CLEAR:var_csign.
var_csign = var_tranamt.
SEARCH var_csign FOR ‘-‘.
IF sy-subrc EQ 0 AND sy-fdpos NE 0.
SPLIT var_csign AT ‘-‘ INTO var_csign var_sign.
CONDENSE var_csign.
CONCATENATE ‘-‘ var_csign INTO var_csign.
ELSE.
CONDENSE var_csign.
ENDIF.
CLEAR:var_csign.
var_csign = var_tranamt.
SEARCH var_csign FOR ‘-‘.
IF sy-subrc EQ 0 AND sy-fdpos NE 0.
SPLIT var_csign AT ‘-‘ INTO var_csign var_sign.
CONDENSE var_csign.
CONCATENATE ‘-‘ var_csign INTO var_csign.
ELSE.
CONDENSE var_csign.
ENDIF.
Notes: Change the datatype to CHAR
Removing unwanted characterstics
DATA: var_str(100) VALUE
‘QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_’ ,
var_custpo TYPE /BIC/OIZCCUSTPO,
var_temp TYPE /BIC/OIZCCUSTPO,
var_len(3) TYPE c.
CLEAR: var_custpo,
var_len,
var_temp.
var_custpo = source_fields-/bic/zccustpo.
var_len = strlen( var_custpo ).
DO var_len TIMES.
SUBTRACT 1 FROM var_len.
IF var_str CS var_custpo+var_len(1).
CONCATENATE var_custpo+var_len(1) var_temp INTO var_temp.
ENDIF.
ENDDO.
RESULT = var_temp.
CONSTANTS: c_allowed(100) TYPE C value
‘ #{}[]!”%&”()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcd’ &
‘efghi’ &
‘jklmnopqrstuvwxyz ‘.
DATA : var_EANUPC TYPE /BI0/OIEANUPC,
var_len TYPE i,
var_error TYPE sy-subrc,
var_offset TYPE sy-index.
CLEAR: var_EANUPC.
var_EANUPC = SOURCE_FIELDS-EANUPC.
TRANSLATE var_EANUPC TO UPPER CASE.
CLEAR: var_error.
CALL FUNCTION ‘RSKC_CHAVL_CHECK’
EXPORTING
I_CHAVL = var_EANUPC
IMPORTING
E_ERR_SUBRC = var_error.
IF var_error NE 0.
CLEAR: var_len.
var_len = strlen( var_EANUPC ).
DO var_len TIMES.
CLEAR:var_offset.
var_offset = sy-index – 1.
IF var_EANUPC+var_offset(1) CO c_allowed.
ELSE.
var_EANUPC+var_offset(1) = ”.
ENDIF.
ENDDO.
ENDIF.
* result value of the routine
RESULT = var_EANUPC.
‘QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_’ ,
var_custpo TYPE /BIC/OIZCCUSTPO,
var_temp TYPE /BIC/OIZCCUSTPO,
var_len(3) TYPE c.
CLEAR: var_custpo,
var_len,
var_temp.
var_custpo = source_fields-/bic/zccustpo.
var_len = strlen( var_custpo ).
DO var_len TIMES.
SUBTRACT 1 FROM var_len.
IF var_str CS var_custpo+var_len(1).
CONCATENATE var_custpo+var_len(1) var_temp INTO var_temp.
ENDIF.
ENDDO.
RESULT = var_temp.
CONSTANTS: c_allowed(100) TYPE C value
‘ #{}[]!”%&”()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcd’ &
‘efghi’ &
‘jklmnopqrstuvwxyz ‘.
DATA : var_EANUPC TYPE /BI0/OIEANUPC,
var_len TYPE i,
var_error TYPE sy-subrc,
var_offset TYPE sy-index.
CLEAR: var_EANUPC.
var_EANUPC = SOURCE_FIELDS-EANUPC.
TRANSLATE var_EANUPC TO UPPER CASE.
CLEAR: var_error.
CALL FUNCTION ‘RSKC_CHAVL_CHECK’
EXPORTING
I_CHAVL = var_EANUPC
IMPORTING
E_ERR_SUBRC = var_error.
IF var_error NE 0.
CLEAR: var_len.
var_len = strlen( var_EANUPC ).
DO var_len TIMES.
CLEAR:var_offset.
var_offset = sy-index – 1.
IF var_EANUPC+var_offset(1) CO c_allowed.
ELSE.
var_EANUPC+var_offset(1) = ”.
ENDIF.
ENDDO.
ENDIF.
* result value of the routine
RESULT = var_EANUPC.
Subscribe to:
Posts (Atom)