Application Development 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: 

ABAP Coding for BW Transformation Routine (Eliminate Invalid Characters)

tnecnivo
Active Contributor
0 Kudos

Hi Abap-gurus,

I am using a simple piece of codes for ABAP-Routine in BW Transformation to eliminate invalid Characters.

The Source is XBLNR and the Target field is 0REF_DOC_NO (Reference Document Number).

My piece of codes as following:-


DATA : v_char(27) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

DATA: l_user_allowed_char TYPE rsallowedchar,

             input(200) TYPE c,

             l_all_allowed_char(140) TYPE c,

             l_result_str_len TYPE i,

             l_str_increment TYPE i.

     CONSTANTS c_sap_allowed_char(84) TYPE c VALUE

     ' !"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

     IF l_all_allowed_char IS INITIAL.

       SELECT SINGLE * FROM rsallowedchar

       INTO l_user_allowed_char

       WHERE allowkey = 'S'.

       CONCATENATE c_sap_allowed_char

       l_user_allowed_char-allowchar

       INTO l_all_allowed_char.

     ENDIF.

     IF source_fields-xblnr CA v_char.

       input = source_fields-xblnr.

       TRANSLATE input TO UPPER CASE.

       l_result_str_len = STRLEN( input ).

       l_str_increment = 0.

       WHILE l_str_increment LE l_result_str_len.

         IF NOT input+l_str_increment(1) CO l_all_allowed_char.

           input+l_str_increment(1) = ' '.

         ENDIF.

         ADD 1 TO l_str_increment.

       ENDWHILE.

       result = input.

     ENDIF.

However, I still receive error message saying:-

Value '#' (hex. '2300') of characteristic 0REF_DOC_NO contains invalid characters.

Any advice would be greatly Appreicated.

Thanks in advance,

Vince

Tag

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Vincent,

As I can see from your reply that in RSKC you have following values:

SPACE@.`|#!"%&'()*+,-–/\:;<=>?_^[]$Ö�0123456789ALL_CAPITAL_PLUS_HEX {}ÜÄ

And in your code you are concatenating these values in l_all_allowed_char.

So after this if you are trying to validate and eleminate # from the XBLNR values it is basically considering # as a valid character because it is present in 'rsallowedchar' table.

WHILE l_str_increment LE l_result_str_len. 

         IF NOT input+l_str_increment(1) CO l_all_allowed_char.

           input+l_str_increment(1) = ' '.

         ENDIF.

         ADD 1 TO l_str_increment.

       ENDWHILE.

And the control will not go to in the IF condtion at all.

I suggest try to comment the concatenate statement once and then try to run the DTP, it shuld work.

Then you make changes accordingly to consider Concatenate statement or not.

Please let us know how it goes.

Thanks

Amit

12 REPLIES 12

KodandaPani_KV
Active Contributor
0 Kudos

Hi,

please check the RSKC transaction maintain the special char

then check the BW side in RSKC  - ALL_CAPITAL_PLUS_HEX

check the table - RSALLOWEDCHAR - those special char to maintain or not.

Thanks,

Phani.

0 Kudos

Hi Kodanda,

Thanks for the prompt reply, I have checked RSKC on BW and also Table RSALLOWEDCHAR, it shows as below:-

SPACE@.`|#!"%&'()*+,-–/\:;<=>?_^[]$Ö�0123456789ALL_CAPITAL_PLUS_HEX {}ÜÄ

The piece of code that I used basically should only take the characters I mentioned in the code right?

Did I miss something in the ABAP codes?

Many thanks,

Vince

shaik_sajid
Active Contributor
0 Kudos

Hi,

In one of my Previous BW Project, we faced same issue and I used the code in the attached file.

Try it, it might be helpful to you.

Regards

Sajid Shaik

Former Member
0 Kudos

Hi Vincent,

As I can see from your reply that in RSKC you have following values:

SPACE@.`|#!"%&'()*+,-–/\:;<=>?_^[]$Ö�0123456789ALL_CAPITAL_PLUS_HEX {}ÜÄ

And in your code you are concatenating these values in l_all_allowed_char.

So after this if you are trying to validate and eleminate # from the XBLNR values it is basically considering # as a valid character because it is present in 'rsallowedchar' table.

WHILE l_str_increment LE l_result_str_len. 

         IF NOT input+l_str_increment(1) CO l_all_allowed_char.

           input+l_str_increment(1) = ' '.

         ENDIF.

         ADD 1 TO l_str_increment.

       ENDWHILE.

And the control will not go to in the IF condtion at all.

I suggest try to comment the concatenate statement once and then try to run the DTP, it shuld work.

Then you make changes accordingly to consider Concatenate statement or not.

Please let us know how it goes.

Thanks

Amit

0 Kudos

Hi Amit,

Thanks for the explanation, I have followed what you said and commented the Concatenate statement. However, it display error:-


E:Statement "L_USER_ALLOWED_CHAR-ALLOWCHAR" is not defined. Check your spelling. spelling.

What is did was this:-


     if l_all_allowed_char is initial.

       select single * from rsallowedchar

       into l_user_allowed_char

       where allowkey = 'S'.

"      concatenate c_sap_allowed_char

       l_user_allowed_char-allowchar

       into l_all_allowed_char.

     endif.

Did I do it wrongly?

Thanks,
Vince

0 Kudos

Hi Vincent,

When I said comment the concatenate statement I meant that complete statement.

You had to comment all three lines.

Now just comment all the IF condition, like below:

"    IF l_all_allowed_char IS INITIAL.

"      SELECT SINGLE * FROM rsallowedchar

"      INTO l_user_allowed_char

"      WHERE allowkey = 'S'.

"      CONCATENATE c_sap_allowed_char

"      l_user_allowed_char-allowchar

"      INTO l_all_allowed_char.

"    ENDIF.

I have tried your code in my local program and it works.
Following is your complete code with some tweaks:

-----------------------------------------------------------------------------------------

DATA : v_char TYPE c LENGTH 27.
DATA: l_user_allowed_char TYPE rsallowedchar,
             input(200) TYPE c,
             l_all_allowed_char(140) TYPE c,
             l_result_str_len TYPE i,
             l_str_increment TYPE i.
CONSTANTS c_sap_allowed_char(84) TYPE c VALUE
' !"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

*     IF l_all_allowed_char IS INITIAL.
*       SELECT SINGLE * FROM rsallowedchar
*       INTO l_user_allowed_char
*       WHERE allowkey = 'S'.
*       CONCATENATE c_sap_allowed_char
*       l_user_allowed_char-allowchar
*       INTO l_all_allowed_char.
*     ENDIF.

v_char = sy-abcde.
IF xblnr CN v_char.
  input = xblnr.
  TRANSLATE input TO UPPER CASE.
  l_result_str_len = strlen( input ).
  l_str_increment = 0.
  WHILE l_str_increment LE l_result_str_len.
    IF NOT input+l_str_increment(1) CO c_sap_allowed_char.
      input+l_str_increment(1) = ' '.
    ENDIF.
    ADD 1 TO l_str_increment.
  ENDWHILE.
  result = input.
ENDIF.

-----------------------------------------------------------------------------------------

Bolds are the values I changed.

Please let me know if this works for you.

Thanks

Amit

0 Kudos

It worked! Thanks a lot Amit

Appreciated the help.

0 Kudos

Good to know that it helped.

Happy working

Regards

Amit

matt
Active Contributor
0 Kudos

Not directly related to your query, but there are two enhancements to make.

First of all: DATA : v_char(27) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

should be a constant, and you should use a different TYPE C LENGTH 27. (This is because the v_char(27) isn't permitted in some contexts, so you'll should get used to it). But in fact, you don't need it. The system field sy-abcde contains what you need.


This next bit is just wrong:

IF l_all_allowed_char IS INITIAL.


l_allowed is ALWAYS initial at this point.


tnecnivo
Active Contributor
0 Kudos

Hi Matthew,

Thanks for the advice.

Sorry but my abap skills is really limited >.<

I understand you are saying I should use sy_abcde, but may I know how should I put it into this routine?

And I_allowed is always initial that that point, which means I shouldn't use that If-else statement in my code?

Kindly advise please.

Thanks in advance,

Vince

matt
Active Contributor
0 Kudos

Define l_allowed_char using STATIC rather than DATA. Or if it is used in an end-routine or other 7.0 type routine, define it as a class attribute.

For sy-abcde, I'd use:

DATA : v_char TYPE c LENGTH 27.

v_char = sy-abcde. " Since sy-abcde has length 26, the 27th position will have space


Now I notice that you have: IF source_fields-xblnr CA v_char. This means "If XBLNR contains any allowed characters..."

I think you want "If XBLNR contains any character that isn't allowed". For that you need CN. You can read the different operations here. ABAP Keyword Documentation

tnecnivo
Active Contributor
0 Kudos

Hi Matthew,

Thanks for the advice,

I have made changes according to what you have advised, my code as below:-


Did the changes I do correctly?


    DATA : v_char TYPE c LENGTH 27.

    v_char = Sy-abcde.

    DATA: l_user_allowed_char TYPE rsallowedchar,

            input(200) TYPE c,

            l_all_allowed_char(140) TYPE c,

            l_result_str_len TYPE i,

            l_str_increment TYPE i.

    CONSTANTS c_sap_allowed_char(84) TYPE c VALUE

    ' !"%&''()*+,-./:;<=>?_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

    IF l_all_allowed_char IS INITIAL.

      SELECT SINGLE * FROM rsallowedchar

      INTO l_user_allowed_char

      WHERE allowkey = 'S'.

      CONCATENATE c_sap_allowed_char

      l_user_allowed_char-allowchar

      INTO l_all_allowed_char.

    ENDIF.

    IF SOURCE_FIELDS-xblnr CN v_char.

      input = SOURCE_FIELDS-xblnr.

      TRANSLATE input TO UPPER CASE.

      l_result_str_len = STRLEN( input ).

      l_str_increment = 0.

      WHILE l_str_increment LE l_result_str_len.

        IF NOT input+l_str_increment(1) CO l_all_allowed_char.

          input+l_str_increment(1) = ' '.

        ENDIF.

        ADD 1 TO l_str_increment.

      ENDWHILE.

      RESULT = input.

    ENDIF.

By the way, Someone above (Amit) advised me on commenting off the CONCATENATE statement, do I still need to do that?

Many thanks for your time,
Vince