0 votes
1 view
in SAP by (2.1k points)

I have the following piece of code.

REPORT ZZY.

CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.

  PUBLIC SECTION.

    CLASS-METHODS:

      convert_to_xstring

        IMPORTING

          i_param1 TYPE i

          i_param2 TYPE i

        RETURNING

          VALUE(rv_result) TYPE xstring,

      main.

ENDCLASS.

CLASS lcl_main IMPLEMENTATION.

  METHOD convert_to_xstring.

  ENDMETHOD.

  METHOD main.

    DATA: lt_binary_tab TYPE STANDARD TABLE OF x.

    DATA(lv_result) = convert_to_xstring( i_param1 = 1 i_param2 = 2 ).

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

      EXPORTING

        buffer = lcl_main=>convert_to_xstring(

                   EXPORTING

                     i_param1 = 1

                     i_param2 = 2

                 )

        TABLES

        binary_tab = lt_binary_tab.

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  lcl_main=>main( )

A functional method call that is not a part of a function module call can be written like that.

DATA(lv_result) = convert_to_xstring( i_param1 = 1 i_param2 = 2 )

However when I want to use it exactly as written above

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

  EXPORTING

    buffer                = lcl_main=>convert_to_xstring( i_param1 = 1 i_param2 = 2 )

  TABLES

    binary_tab            = lt_binary_tab

I get the following syntax error.

Field "CONVERT_TO_XSTRING(" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. "DATA" statement.

It looks like the compiler needs some guidance, in this case, to distinguish between an attribute and a method. Why would it be ambiguous for the compiler to let such a case without writing EXPORTING?

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

  EXPORTING

    buffer                = lcl_main=>convert_to_xstring( EXPORTING i_param1 = 1 i_param2 = 2 )

  TABLES

    binary_tab            = lt_binary_tab

sap abap

1 Answer

0 votes
by (9.1k points)

The design of ABAP is not properly designed because you can’t use functional method calls in combination with all commands. For e.g. - the WRITE command doesn't work in combination with functional method calls. 

by (130 points)
since in code class is mentioned private you cannot access the object within the method
 you need to change the class from private to public

Related questions

0 votes
1 answer
asked Jul 9, 2019 in SAP by Prachi0901 (2.1k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 2, 2019 in SAP by Han Zhyang (25k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...