Technology Blog Posts by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
mwn
Participant
0 Kudos
394

In traditional SAPGUI based ABAP reports, we use PARAMETERS to collect input from the user, and WRITE statements to provide some output.

With web based front ends, this is no longer possible, which led me to a possible solution.

We have two new tables, which hold parameter name/value pairs for each user, and outputs. The parameters are filled by presenting a simple HTML form to the user, where they can update any values. They can also provide the name of a global class, and a method name. These are what the developer builds from a global class, and static methods. The names of the methods are not important, but let's assume there is an INIT, which sets some parameters, and a MAIN which processes the inputs.

The INIT method might look like this:

zmn_getsetparams=>hideparams(  ).

  zmn_getsetparams=>setparam( description = 'Integer1' parname = 'INT1' parvalue = '66' sequence = '01' overwrite = abap_false ).
  zmn_getsetparams=>setparam( description = 'Integer2' parname = 'INT2' parvalue = '33' sequence = '03' overwrite = abap_false ).
  zmn_getsetparams=>setparam( description = 'Math operator' parname = 'OPERATOR' parvalue = '+' sequence = '02' overwrite = abap_false ).
  zmn_getsetparams=>clearoutput(  ).
  zmn_getsetparams=>write( |Initialized parameters| ).

The hideparams() method sets a flag for all existing parameters, so that the user doesn't se them on the HTML form.

The clearouput() method clears the output, and sets a simple status message.

zparams.png

An example of the MAIN method might look like this:

 DATA(pa_int1) = CONV i(  zmn_getsetparams=>getparam( 'INT1' ) ).
    DATA(pa_int2) = CONV i(  zmn_getsetparams=>getparam( 'INT2' ) ).

    DATA result TYPE string.

    CASE zmn_getsetparams=>getparam( 'OPERATOR' ).

      WHEN '+'.
        result = |{  pa_int1 }+{ pa_int2 } = { pa_int1 + pa_int2 }|.
      WHEN '-'.
        result = |{  pa_int1 }-{ pa_int2 } = { pa_int1 - pa_int2 }|.
      WHEN '*'.
        result = |{  pa_int1 }*{ pa_int2 } = { pa_int1 * pa_int2 }|.
      WHEN '/'.
        IF pa_int2 IS INITIAL.
          result = 'No division by zero allowed'.
        ELSE.
          result = |{  pa_int1 }/{ pa_int2 } = { conv f( pa_int1 / pa_int2 ) DECIMALS  = 2 }|.
        ENDIF.
      WHEN OTHERS.
        result = |Bad operator: {  zmn_getsetparams=>getparam( 'OPERATOR' ) }|.
    ENDCASE.
zmn_getsetparams=>clearoutput(  ).
zmn_getsetparams=>write( |=================Demo 2===========| ).
zmn_getsetparams=>write( result ).

This returns the values as entered by the user, and prepares a simple result of the calculation.

zparams_result.png

 

The code can be found under https://github.com/michaelnicholls/ZPARAMS.git, with some setup instructions for both on-premise and BTP ABAP environments.

Labels in this area