‎2010 Jan 15 11:45 AM
Hello everyone,
right now i have an ABAP-function-module which i have to convert into Java-Code.
My problem is: i don't really understand ABAP so i have some questions.
The part which i don't understand is this:
READ TABLE t_ctab INDEX f_char.
IF sy-subrc EQ 0.
CONCATENATE f_werks t_ctab-char1 INTO f_werks.
ENDIF.What happens here?
Thanks in advance.
‎2010 Jan 15 11:52 AM
Hi Tanja ,
Consider for Example value in f_char is 4.
Then It will read the 4th row from the internal table t_ctab.
If this read is sucessful (that is what he has checked with it sy-subrc eq 0 condition),it will concatenate f_werks and t_ctab-char1 INTO f_werks.
That means for Eg if value in f_werks is 9999 and value in t_tab-char1 is 'hello' then after execution of Concatenate statement value in f_werks will be 9999hello.
Hope this is clear to you.
Get Back to me if you need more help.
Regards,
Nikhil
‎2010 Jan 15 11:52 AM
Hi Tanja ,
Consider for Example value in f_char is 4.
Then It will read the 4th row from the internal table t_ctab.
If this read is sucessful (that is what he has checked with it sy-subrc eq 0 condition),it will concatenate f_werks and t_ctab-char1 INTO f_werks.
That means for Eg if value in f_werks is 9999 and value in t_tab-char1 is 'hello' then after execution of Concatenate statement value in f_werks will be 9999hello.
Hope this is clear to you.
Get Back to me if you need more help.
Regards,
Nikhil
‎2010 Jan 15 12:06 PM
Thanks,
but what does
IF sy-subrc EQ 0.mean?
when is sy-subrc = 0?
‎2010 Jan 15 12:09 PM
SY-SUBRC is a system variable in ABAP which can be checked to confirm whether the ABAP command preceeding the check was successful or not.
As a norm (not a rule) - SY-SUBRC = 0 implies the previous ABAP command was successful.
In the instance of the code READ TABLE <itab> INDEX <index>. - the SY-SUBRC would be set as 0 if a record with index <index> exists in the table <itab> - if there is no record found for that index then the SY-SUBRC value is non zero - here 4.
‎2010 Jan 15 12:11 PM
Hi ,
In ABAP there are 171 system variables that are used by the ABAP to indicate the system response after a certain operation.
SY-SUBRC is Return Value After ABAP Statements . Value 0 in SY-SUBRC indicates that the system has performed previous operation Sucessfully. If it is non zero then it indivates that previous statement has not fetched any results .
Hope this is helpful for you to understand this,
Please get back to me in case you require more help.
Regards,
Nikhil
‎2010 Jan 15 12:16 PM
Thanks!
The next question is: what is the content of t_ctab?
I found this form:
CONSTANTS:
c_char(70) TYPE c VALUE
'$&(),-./0123456789:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]{}ÄÖÜß'.
FORM char_table_bilden TABLES t_ctab STRUCTURE t_ctab.
DATA:
g_offs TYPE i.
transfer chars to table
CLEAR g_offs.
DO.
t_ctab-char1 = c_char+g_offs(01).
IF t_ctab-char1 = space. EXIT. ENDIF.
APPEND t_ctab.
ADD 1 TO g_offs.
ENDDO.
SORT t_ctab BY char1.
DELETE ADJACENT DUPLICATES FROM t_ctab COMPARING char1.
ENDFORM. " char_table_bilden
I would guess, that t_ctab table looks something like this afterwards:
Index Char
0 $
1 &
2 (
3 )
4 ,
5 -
and so on....
am i right?
Edited by: Tanja Wiemann on Jan 15, 2010 1:17 PM
‎2010 Jan 15 12:20 PM
You're right!
Only the table doesnt have Index field. The internal table has only one column containing the character values.
‎2010 Jan 15 12:22 PM
Hi Tanja ,
To view the Exact content of the internal table , I would suggest you to place a break-point in the code and debug it . This will ensure that you will get the exact content of that internal table.
Hope this will help to you.
Please get back to me if you need more help in this
Regards,
Nikhil
Edited by: Nikhil Joshi on Jan 15, 2010 5:53 PM
‎2010 Jan 15 12:40 PM
Ok, thank you.
Hopefully the last question:
The next ABAP-Code snippet contains the main part which i have to translate.
It converts decimals into a char-sequence with a length of 4.
Example: 0010000 -> $),D
FORM umrechnung_dezimal_to_basis
TABLES t_ctab STRUCTURE t_ctab
USING i_werks
CHANGING o_werks.
*Read length of decimal
DATA:
f_stel TYPE i,
f_lines TYPE i.
DATA:
f_potenz TYPE i,
f_rest TYPE i.
DATA:
f_char TYPE i. "position of char
DATA:
f_werks TYPE ty_out-werks_i.
*determine base
DESCRIBE TABLE t_ctab LINES f_lines.
*delete leading zeros
WRITE i_werks TO f_werks NO-ZERO.
*delete leading whitespaces
CONDENSE f_werks.
*length of decimal
f_stel = strlen( f_werks ).
decimal to convert
f_rest = f_werks.
biggest potency
f_potenz = f_stel - 1.
CLEAR: f_werks.
conversion
DO f_stel TIMES.
f_char = trunc( f_rest / f_lines ** f_potenz ) + 1.
READ TABLE t_ctab INDEX f_char.
IF sy-subrc EQ 0.
CONCATENATE f_werks t_ctab-char1 INTO f_werks.
ENDIF.
f_rest = f_rest MOD ( f_lines ** f_potenz ).
f_potenz = f_potenz - 1.
ENDDO.
PERFORM format_i TABLES t_ctab
CHANGING f_werks
o_werks.
ENDFORM. " conversion
‎2010 Jan 15 12:42 PM
i translated it into:
public class ConvertDecimalToBase {
private static final String C_CHAR = "$&(),-./0123456789:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[
]{}ÄÖÜß";
public static String convert(String decimal){
double f_lines = C_CHAR.length();
// Position of char
int f_char;
// delete leading zeros
String f_werks = Integer.toString(Integer.parseInt(decimal));
// length of the decimal
int f_stel = f_werks.length();
// the decimal which has to be converted
int f_rest = Integer.parseInt(f_werks);
// biggest potency
double f_potenz = f_stel -1;
f_werks = "";
for(int i = 0; i < f_stel; i++){
f_char = (int) ((f_rest / Math.pow(f_lines, f_potenz))+1);
f_werks = f_werks + C_CHAR.charAt(f_char);
f_rest = (int) (f_rest % Math.pow(f_lines, f_potenz));
f_potenz = f_potenz -1;
}
return f_werks;
}
but i get &&,-E as the result.
the only difference betweent my java-code and the abap-code is, that i am using a String instead of the table t_ctab.
Does anyone see the error in my code?
‎2010 Jan 15 12:57 PM
solution: the index of t_ctab begins with 1 and not 0 like my String
furthermore only the last 4 chars of the result-char-sequence are used (taken from another part of the function module).
Thanks everyone for solving this riddle.
‎2010 Jan 15 12:15 PM
READ TABLE t_ctab INDEX f_char. " reading the table T_CTAB's f_charTH row.(or index)
IF sy-subrc EQ 0. " if read is successful i.e read fetches the required row, then the sytem field sy-subrc(sy(syst) is a
"structure and subrc field is automatically filled with 0 with a successful read and 4 if unsuccessful.
CONCATENATE f_werks t_ctab-char1 INTO f_werks. "concatenates the values of f_werks and t_ctab-char1(the fetched tow)
" again to f_werks
ENDIF. " if block closes.
‎2010 Jan 15 2:31 PM
Tanja - You have violated a number of forum rules.
Please do not ask basi questions
Only one question per thread
Use code tags to format your code
Mark your question as solved
Thread locked.
Rob