Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert ABAP to Java

Former Member
0 Likes
2,880

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,975

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

12 REPLIES 12
Read only

Former Member
0 Likes
1,976

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

Read only

0 Likes
1,975

Thanks,

but what does

 IF sy-subrc EQ 0.

mean?

when is sy-subrc = 0?

Read only

0 Likes
1,975

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.

Read only

0 Likes
1,975

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

Read only

0 Likes
1,975

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

Read only

0 Likes
1,975

You're right!

Only the table doesnt have Index field. The internal table has only one column containing the character values.

Read only

0 Likes
1,975

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

Read only

0 Likes
1,975

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

Read only

0 Likes
1,975

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?

Read only

0 Likes
1,975

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.

Read only

Former Member
0 Likes
1,975
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.
Read only

Former Member
0 Likes
1,975

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