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: 

How to get updated fields in a classical report

Former Member
0 Kudos

Hi,

After displaying the report using Write, multiple fields are editable. I used INPUT ON for this. My problem is, how does the program recognize the new entered values in all the editable fields? I can not use AT LINE-SELECTION because only the current line that the cursor has focus on is being retrieved.

I've also researched about DYNPRO_FIELD_GET but i requires a DYNPRO. When I checked the report, it doesn't have a screen number?

Kindly Help.

2 REPLIES 2

Former Member
0 Kudos

Hi,

You can do that in AT USER-COMMAND

Check this program...


*" Field string declarations...........................................
*"--------------------------------------------------------------------*
* Field string declaration to hold computation values with operator   *
*"--------------------------------------------------------------------*
data:
  begin of fs_comp,
    operand1(10) type  c,                                   " Operand1
    operator(2)  type  c,              " Operator
    operand2(10) type  c,                                   " Operand2
    result(30)   type  c,              " Result
  end of fs_comp.

*"--------------------------------------------------------------------*
* Internal table to hold computation values including operator        *
*"--------------------------------------------------------------------*
data:
  t_comp  like
standard table
      of fs_comp.

*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables                                                      *
*"--------------------------------------------------------------------*
data:
  w_operand1(10) type  c,                                   " Operand1
  w_operator(2)  type  c,              " Operator
  w_operand2(10) type  c,                                   " Operand2
  w_result(30)   type  n,              " Result
  w_flag         type  i.              " Temporary Flag

*"--------------------------------------------------------------------*
*                 END-OF-SELECTION EVENT                              *
*"--------------------------------------------------------------------*
end-of-selection.
  sy-title = ' '.
  perform operations.

*"--------------------------------------------------------------------*
*                 AT-LINE-SELECTION EVENT                             *
*"--------------------------------------------------------------------*
at line-selection.
  if sy-lsind ne 1.
    message e000(yh1152).
  else.
    w_flag = 0.
    perform display_input.
  endif.                               " IF SY-LSIND NE 1

*"--------------------------------------------------------------------*
*                 AT PF<nn>                                           *
*"--------------------------------------------------------------------*
at pf05.
  set user-command 'CALC'.

*"--------------------------------------------------------------------*
*                 AT USER-COMMAND EVENT                               *
*"--------------------------------------------------------------------*
at user-command.
  if sy-lsind eq 1.
    message e008(yh1152).

  else.
    if w_flag eq 0.
      perform calculations.
    else.
      message e007(yh1152).
    endif.                             " IF W_FLAG EQ 0

  endif.                               " IF SY-LSIND EQ 1

*&--------------------------------------------------------------------*
*&      Form  operations
*&--------------------------------------------------------------------*
*This subroutine displays the operations to be performed on basic list
*---------------------------------------------------------------------*
*   No interface parameters
*---------------------------------------------------------------------*
form operations .
  write:
    /10 'Select a line'(008).
  skip 2.
  format hotspot on.
  write:
    /10 'ADDITION : +'(002),
    /10 'SUBTRACTION : -'(003),
    /10 'MULTIPLICATION : *'(004),
    /10 'DIVISION : /'(005),
    /10 'POWER  : ** '(006).
endform.                               " operations

*&---------------------------------------------------------------------*
*&      Form  calculations
*&---------------------------------------------------------------------*
* This subroutine performs the calculation part of detail list
*----------------------------------------------------------------------*
*   No interface parameters
*----------------------------------------------------------------------*
form calculations .
  data:
    lw_line  type    i value 4,        " No of Lines
    lw_str   type    string.           " Exception text

  data:
   lw_ref type ref to cx_root.         " Reference Variable

  refresh t_comp.

  do 3 times.
    clear:
      w_operand1,
      w_operator,
      w_operand2.

    read line lw_line field value
     w_operand1 into w_operand1
     w_operator into w_operator
     w_operand2 into w_operand2.

    fs_comp-operand1  =   w_operand1.
    fs_comp-operator  =   w_operator.
    fs_comp-operand2  =   w_operand2.


    try.

        case w_operator.

          when '+'.

            fs_comp-result  = fs_comp-operand1 + fs_comp-operand2.

          when '-'.
            fs_comp-result  = fs_comp-operand1 - fs_comp-operand2.

          when '*'.
            fs_comp-result  = fs_comp-operand1 * fs_comp-operand2.

          when '/'.
            fs_comp-result  = fs_comp-operand1 / fs_comp-operand2.

          when '**'.
            w_result  = fs_comp-operand1 ** fs_comp-operand2.
            fs_comp-result = w_result.
            clear w_result.
        endcase.                       " CASE W_OPERATOR

      catch cx_root into lw_ref.
        fs_comp-result = 'Cannot Compute'(007).
        lw_str = lw_ref->get_text( ).
        message lw_str type 'I'.

    endtry.

    append fs_comp to t_comp.
    clear fs_comp.
    add 2 to lw_line.

  enddo.                               " DO 3 TIMES
  add 1 to w_flag.
  perform result.

endform.                               " calculations

*&--------------------------------------------------------------------*
*&      Form  DISPLAY_INPUT
*&--------------------------------------------------------------------*
* This subroutine displays the input on basic list for operations
*---------------------------------------------------------------------*
*   No interface parameters
*---------------------------------------------------------------------*
form display_input .

  sy-lsind = 1.

  clear:
    w_operand1,
    w_operand2.

  case sy-lilli.
    when '4'.
      w_operator = '+'.

    when '5'.
      w_operator = '-'.

    when '6'.
      w_operator = '*'.

    when '7'.
      w_operator = '/'.

    when '8'.
      w_operator = '**'.

    when others.
      stop.
  endcase.                             " CASE SY-LILLI

  write:
    /10 'Enter values and press F5 to calculate'(009).
  skip 2.
  do 3 times.

    write:
      10 w_operand1  no-zero input on color 1,
      25 w_operator  intensified on color 2,
      30 w_operand2 no-zero   input on,
      45 ' = ' ,
      w_result  no-zero  input off.
    skip.

  enddo.                               " D0 3 TIMES.
endform.                               " DISPLAY_INPUT

*&--------------------------------------------------------------------*
*&      Form  RESULT
*&--------------------------------------------------------------------*
* This subroutine displays the caculated result for selected operator
*---------------------------------------------------------------------*
*   No interface parameters
*---------------------------------------------------------------------*
form result .

  sy-lsind = 1.

  write: /08 'The result of operation processed is'(001).
  skip 2.
  do 3 times.
    read table t_comp into fs_comp index sy-index.
    write:
      10 fs_comp-operand1 no-zero input off color 1,
         fs_comp-operator no-zero intensified on color 7.

    if fs_comp-operand2 eq '' or fs_comp-operand2 eq '0'.
      write: fs_comp-operand2 no-zero input off color 6.
    else.
      write: fs_comp-operand2 no-zero input off color 1.
    endif.                             " IF FS_COMP-OPERAND2 NE 0

    write:' = ' color 3.
    write:
      fs_comp-result no-zero intensified on input off color 5.

    skip.

  enddo.                               " DO 3 TIMES

endform.                               " RESULT

*---------------------------------------------------------------------*
*                        End Of Program                               *
*---------------------------------------------------------------------*

Execute the above program and run in debugging mode after selecting a line in the basic list.

Hope this would help you.

Regards

Narin Nandivada

Former Member
0 Kudos

Hi,

For Operation you can go for AT USER-COMMAND using PF-STATUS.In This Case you Can get all the Edibale value you want-

You Can check the following sample code Using INPUT ON Statement for your reference-

The purpose of this program to do mathematical operation :



DATA:
  w_input1 TYPE p,                     " Input Number 1.
  w_input2 TYPE p,                     " Input Number 2.
  w_result TYPE p DECIMALS 2,          " Result variable.
  w_optr(2) TYPE c.                    " Operator.
*"-------------------------------------------------------------------"*
*                     AT LINE-SELECTION.
*"-------------------------------------------------------------------"*
AT LINE-SELECTION.
**Calling Status Bar*****
  SET PF-STATUS 'OPERATION'.
  w_optr = sy-lisel.
  IF sy-lsind EQ 1.
****Calling Subroutine***
    PERFORM display.
  ENDIF.                               " IF sy-lsind EQ 1.
*"-------------------------------------------------------------------"*
*                      AT USER-COMMAND
*"-------------------------------------------------------------------"*
AT USER-COMMAND.
  IF sy-lsind EQ 2.
****Calling Subroutine***
    PERFORM operation.
  ENDIF.                               " IF sy-lsind EQ 2.
*"-------------------------------------------------------------------"*
*                      START-OF-SELECTION.
*"-------------------------------------------------------------------"*
START-OF-SELECTION.
  WRITE:
  / '+ Addition'(001),
  / '- Subtraction'(002),
  / '* Multiplication'(003),
  / '/ Division'(004),
  / '^ Powers'(005).
*&---------------------------------------------------------------------*
*&      Form  Display
*&---------------------------------------------------------------------*
*       Subroutine To Display Input Fields And Result.
*----------------------------------------------------------------------*
*  No Interface Parameter Passed.
*----------------------------------------------------------------------*
FORM display .
  CLEAR:
   w_input1,
   w_input2,
   w_result.
  DO 3 TIMES.
    WRITE:
      / w_input1 INPUT ON,
        w_optr INPUT OFF COLOR 4,
        w_input2 INPUT ON,
        '=',
        w_result INPUT OFF.
  ENDDO.                               " DO 3 TIMES.
ENDFORM.                               " Form Display.
*&---------------------------------------------------------------------*
*&      Form  operation
*&---------------------------------------------------------------------*
*       Subroutine For Mathematical Calculation.
*----------------------------------------------------------------------*
*  No Interface Parameter Has Passed.
*----------------------------------------------------------------------*
FORM operation .
  DATA:
    w_total TYPE i,                    " Resultant Variable.
    w_line TYPE i VALUE 1.             " Index Variable.
  DO 3 TIMES.
    READ LINE w_line FIELD VALUE
    w_input1 INTO w_input1
    w_input2 INTO w_input2
    w_optr INTO w_optr
    w_result INTO w_result.
    CASE w_optr.
      WHEN '+'.
        w_total = w_input1 +  w_input2.
      WHEN '-'.
        IF w_input2 LT w_input1.
          w_total = w_input1 -  w_input2.
        ELSE.
          MESSAGE i005(zyh1151).
          EXIT.
        ENDIF.                         " IF w_input2 LT w_input1.
      WHEN '*'.
        w_total = w_input1 *  w_input2.
      WHEN '/'.
        IF w_input2 EQ '0'.
          MESSAGE i006(zyh1151).
          EXIT.
        ELSE.
          w_total = w_input1 /  w_input2.
        ENDIF.                         " IF w_input2 EQ '0'.
      WHEN '**'.
        w_total = w_input1 **  w_input2.
    ENDCASE.                           " CASE w_optr.
    MODIFY LINE w_line
    FIELD VALUE w_result FROM w_total.
    ADD 1 TO w_line.
  ENDDO.                               " DO 3 TIMES.
  CLEAR:
   w_input1,
   w_input2,
   w_result.

Hope it will help you.

Regards,

Sujit