Skip to Content

operator REDUCE no proper outcome

Dear all.

I'm currently trying out the new operator REDUCE but I have following situation.

I am calling a REST API with the IF_HTTP_CLIENT and CL_REST_HTTP_CLIENT interfaces and wanted to dynamically build the URI query.

    "build query request
    IF iv_search IS SUPPLIED.
      APPEND |search={ iv_search }| TO lt_query.

    IF iv_views IS SUPPLIED.
      APPEND |views={ iv_views }| TO lt_query.

    IF iv_offset IS SUPPLIED.
      APPEND |offset={ iv_offset }| TO lt_query.

    IF iv_limit IS SUPPLIED.
      APPEND |limit={ iv_limit }| TO lt_query.

    LOOP AT lt_query ASSIGNING FIELD-SYMBOL(<ls_query>).
      lv_query = |{ lv_query }{ <ls_query> }&|.


Currently the code above is working properly and as I always try to learn new Syntax, I tried to replace the LOOP AT with the REDUCE operator.

I followed the F1 Documentation and used the Example and tried following code:

    lv_query = REDUCE #( INIT reduced_query = ''
                         FOR <query> IN lt_query
                         NEXT reduced_query = |{ reduced_query }{ <query> }&| ).

But now the Result looks as follows:

It looks like at some point the definition of one of the defined values is limited to 1 character but I couldn't figure out which one.

The variable lv_query is defined as STRING and the table lt_query as STRING_TABLE.

Do you see any mistake I made with the REDUCE statement?

Thanks for any feedback or help.



Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Feb 11, 2019 at 09:35 AM

    First of all, it's obvious (from debugger 1 character) that you didn't declare it correctly like this:

    DATA lv_query TYPE string.

    There's also an issue inside REDUCE, because REDUCED_QUERY is implicitly declared 1 character because of reduced_query = ''. Instead use the reversed quotes to declare it as STRING type:

    lv_query = REDUCE #( INIT reduced_query = `` " reversed quotes, or use INIT reduced_query TYPE string
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 11, 2019 at 12:49 PM

    Hi Sandra,

    thanks for you message.

    The variable is exactely defined as you mentioned.

    But the issue in REDUCE was correct. I changed the single quotes with backquotes and now lv_query is filled properly. I didn't know that you can declare a string literal with backquotes:

    Character Literals

    I was looking at this documentation and thought that all backquotes were single quotes at first sight.

    Table Reductions, String Processing

    Thanks for noticing.



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.