Application Development and Automation 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: 
Read only

How to input text from pushbutton into input field

tkasperski1
Participant
0 Likes
2,481

For example, I have 3 pushbuttons and one input field.

Pushbuttons, 1,2,+

And now I want to click 1 then + then 2.

After that I want to have on my input text: "1+2".

How Can I do that?

1 ACCEPTED SOLUTION
Read only

MateuszAdamus
Active Contributor
2,428

Hello tkasperski

Something like this?

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BTN_1'.
      gv_expression = |{ gv_expression }1|.
    WHEN 'BTN_2'.
      gv_expression = |{ gv_expression }2|.
    WHEN 'BTN_+'.
      gv_expression = |{ gv_expression }+|.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression.
  ENDCASE.

You could also make it like this.

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression.
    WHEN OTHERS.
      gv_expression = |{ gv_expression }{ sy-ucomm+4(1) }|.
  ENDCASE.

Kind regards,

Mateusz

10 REPLIES 10
Read only

MateuszAdamus
Active Contributor
2,429

Hello tkasperski

Something like this?

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BTN_1'.
      gv_expression = |{ gv_expression }1|.
    WHEN 'BTN_2'.
      gv_expression = |{ gv_expression }2|.
    WHEN 'BTN_+'.
      gv_expression = |{ gv_expression }+|.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression.
  ENDCASE.

You could also make it like this.

AT USER-COMMAND.
  CASE sy-ucomm.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression.
    WHEN OTHERS.
      gv_expression = |{ gv_expression }{ sy-ucomm+4(1) }|.
  ENDCASE.

Kind regards,

Mateusz

Read only

0 Likes
2,428

Hi, thanks for your answer. I don't understand how to use it. I mean to use the user selection screen. Add 3 buttons and input on the user selection screen for example

DATA: input TYPE i.

SELECTION-SCREEN:
BEGIN OF SCREEN 500 AS WINDOW TITLE title,
PUSHBUTTON 2(10) text-001 USER-COMMAND cli1,
PUSHBUTTON 12(30) text-002 USER-COMMAND cli2, PUSHBUTTON 12(30) text-003 USER-COMMAND cli3
VISIBLE LENGTH 10,
END OF SCREEN 500.


For example
text-001 = 1
text-002 = 2
text-003 = +

I click cli1(button) then cli3(button) then cli2(button) and as a result I have 1 + 2 on my input.

Read only

2,428

You need to use AT SELECTION-SCREEN event in this case.

DATA:
  gv_expression TYPE string.


" create push buttons
SELECTION-SCREEN PUSHBUTTON /2(40) text-001 USER-COMMAND btn_1,
SELECTION-SCREEN PUSHBUTTON /2(40) text-002 USER-COMMAND btn_2.
SELECTION-SCREEN PUSHBUTTON /2(40) text-003 USER-COMMAND btn_+.
SELECTION-SCREEN PUSHBUTTON /2(40) text-004 USER-COMMAND btn_clr.

" handle a button being pushed
AT SELECTION-SCREEN.
  CASE sscrfields.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression. " clear the expression
    WHEN OTHERS.
      gv_expression = |{ gv_expression } { sscrfields+4(1) }|. " add next character to the expression
  ENDCASE.

  WRITE gv_expression.

Not tested in the system, though. Might have some typos.


Kind regards,
Mateusz
Read only

0 Likes
2,428

Ok, now I understand but how to put values from text-001 etc. into input field?

Read only

2,428

If you want to do it that way.

  CASE sscrfields.
    WHEN 'BTN_CLR'.
      CLEAR gv_expression. " clear the expression
    WHEN 'BTN_+'.
      gv_expression = |{ gv_expression } { text-003 }|. 
    WHEN 'BTN_1'.
      gv_expression = |{ gv_expression } { text-001 }|. 
    WHEN 'BTN_2'.
      gv_expression = |{ gv_expression } { text-002 }|. 
  ENDCASE.
Kind regards,
Mateusz
Read only

0 Likes
2,428

Ok, thanks a lot now I understand how it works and how to do but the last thing I want to know Is how "in real time" put those values into input field because now I am clicking buttons and when I click execute button I see result.

Read only

2,428

Add the input field to the screen.

PARAMETER: p_input TYPE char20.

After the expression is updated, update the field.

p_input = gv_expression.

You could also concatenate the expression to the input field directly.

Kind regards,

Mateusz
Read only

2,428

Hello Tomasz Kasperski

Make sure to upvote and accept Mateusz Adamus answer as a token of appreciation. He's not only answer, he is providing a crash ABAP course here too ;))

BR, Dominik Tylczynski

Read only

2,428

Hello, 3a9e4ce873a94034b33dc62b0ce600eeI upvoted, accepted, and liked every comment. Thank you Mateusz Adamus for outstanding help and patience 🙂

Read only

2,428

No worries. Cheers.

Kind regards,
Mateusz