‎2008 Jul 01 3:54 PM
Good evening everybody!
I've got the following problem for solving:
Imagine the following situation:
on the selection-screen there are some input fields in one line and a button after them. By pressing that button (e.g. it's name is "Add line") the same fields should be duplicated so many times as many times that button pressed. By pressing another button (e.g. it's name is "Delete line") one last line should be deleted. The mechanism is similar to adding lines in a screen table. What is the solution of this problem?
So: by pressing an "Add line" button on a screen identical fields should be created on the same selection-screen and deleted by pressing "Delete line".
Thanks in advance!
‎2008 Jul 01 4:39 PM
Hello.
The solution for your requirement can be achieved, by following these actions:
1 - Create the buttons in your screen. For that, use command PF-STATUS. This way, you can create buttons in you standard selection-screen. Remember to assign a FUNCTION CODE to those buttons, like 'ADD' and 'REM'. Don't forget the button for F8 (execute). Must have ONLI function assigned to it.
2 - Create input variables, respecting a limit like:
SELECTION-SCREEN BEGIN OF block b1.
PARAMETERS: SEL_VAR_A_LINE1, SEL_VAR_B_LINE1,
SEL_VAR_A_LINE2, SEL_VAR_B_LINE2,
...
SEL_VAR_A_LINEn, SEL_VAR_B_LINEn. "you can use a limit of n = 10, for example.
SELECTION-SCREEN END OF block b1.
3 - In event AT SELECTION-SCREEN OUTPUT, use statement LIKE:
CASE sy-ucomm.
WHEN 'ADD'
LOOP AT SCREEN.
screen-active = '1'. "The field appears
MODIFY SCREEN.
ENDLOOP.
WHEN 'REM'.
LOOP AT SCREEN.
screen-active = '0'. "The field doesn't appear
MODIFY SCREEN.
ENDLOOP.
WHEN OTHERS.
ENDCASE.
The only thing that is missing here, is the code to choose which lines will appear and do not appear. My example makes all to appear, or none to appear.
Regards.
Valter Oliveira.
‎2008 Jul 01 4:39 PM
Hello.
The solution for your requirement can be achieved, by following these actions:
1 - Create the buttons in your screen. For that, use command PF-STATUS. This way, you can create buttons in you standard selection-screen. Remember to assign a FUNCTION CODE to those buttons, like 'ADD' and 'REM'. Don't forget the button for F8 (execute). Must have ONLI function assigned to it.
2 - Create input variables, respecting a limit like:
SELECTION-SCREEN BEGIN OF block b1.
PARAMETERS: SEL_VAR_A_LINE1, SEL_VAR_B_LINE1,
SEL_VAR_A_LINE2, SEL_VAR_B_LINE2,
...
SEL_VAR_A_LINEn, SEL_VAR_B_LINEn. "you can use a limit of n = 10, for example.
SELECTION-SCREEN END OF block b1.
3 - In event AT SELECTION-SCREEN OUTPUT, use statement LIKE:
CASE sy-ucomm.
WHEN 'ADD'
LOOP AT SCREEN.
screen-active = '1'. "The field appears
MODIFY SCREEN.
ENDLOOP.
WHEN 'REM'.
LOOP AT SCREEN.
screen-active = '0'. "The field doesn't appear
MODIFY SCREEN.
ENDLOOP.
WHEN OTHERS.
ENDCASE.
The only thing that is missing here, is the code to choose which lines will appear and do not appear. My example makes all to appear, or none to appear.
Regards.
Valter Oliveira.
‎2008 Jul 01 5:22 PM
Thanks Valter for your post!
But in my solution number of lines is not predefined. The user can add as many lines as he wants to... And if he needs N lines and my program allows only M lines (M < N) what shall I do?
A good example (different program logic from my task): I read items from delivery document and have to output them to the screen. The user selects the number of the document. I can determine the number of items of that doc only at runtime
and your example code allows to reflect only fixed number of items by activating or deactivating created beforehand parameters (input fields).
Thanks in advance!
‎2008 Jul 01 5:49 PM
Here's a way to do it.
DEFINE aline.
selection-screen: begin of line.
parameters: inp&1(5) type c modif id l&1.
selection-screen position 15.
parameters: inp10&1(5) type c modif id l&1.
selection-screen pushbutton 25(5) pb_&1 user-command add
modif id a&1.
selection-screen pushbutton 31(5) pb_10&1 user-command del
modif id d&1.
selection-screen end of line.
END-OF-DEFINITION.
TABLES: sscrfields.
DATA:
max_lines TYPE i VALUE 20,
fldname(60) TYPE c,
lines(2) TYPE n VALUE 1,
cnt(2) TYPE n VALUE 1.
FIELD-SYMBOLS:
<fld> TYPE ANY.
aline 01.
aline 02.
aline 03.
aline 04.
aline 05.
aline 06.
aline 07.
aline 08.
aline 09.
aline 10.
aline 11.
aline 12.
aline 13.
aline 14.
aline 15.
aline 16.
aline 17.
aline 18.
aline 19.
aline 20.
*---------------------------------------------------- Push Button
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'ADD'.
CHECK lines LT max_lines.
lines = lines + 1.
WHEN 'DEL'.
CHECK lines GT 1.
lines = lines - 1.
ENDCASE.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 CP 'A*'.
IF screen-group1+1(2) NE lines.
screen-active = 0.
ELSE.
IF lines LT max_lines.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
ENDIF.
ENDIF.
IF screen-group1 CP 'D*'.
IF screen-group1+1(2) NE lines.
screen-active = 0.
ELSE.
IF lines = 1.
screen-active = 0.
ELSE.
screen-active = 1.
ENDIF.
ENDIF.
ENDIF.
IF screen-group1 CP 'L*'.
IF screen-group1+1(2) GT lines.
screen-active = 0.
ELSE.
screen-active = 1.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
INITIALIZATION.
cnt = 1.
WHILE cnt LE max_lines.
CONCATENATE 'PB_' cnt INTO fldname.
ASSIGN (fldname) TO <fld>.
<fld> = 'Add'.
CONCATENATE 'PB_10' cnt INTO fldname.
ASSIGN (fldname) TO <fld>.
<fld> = 'Del'.
cnt = cnt + 1.
ENDWHILE.Edited by: Paul Chapman on Jul 1, 2008 1:06 PM
‎2008 Jul 01 6:10 PM
Thanks a lot! That's a great solution!
And is there a way to do the same without limit on number of lines?
I think of internal table
‎2008 Jul 01 6:18 PM
Unfortunetly no as you can't do say.. a loop to create lines.
But.. there has to be a limit to the screen as well due to number of fields, or lines etc.
In my example, you can just keep adding ALINE ## up to 99, if you go ever 99 lines then all the ALINE ## will need to be changed to ALINE ###. Just make sure you set the value for MAX_LINES to the last line you create.
‎2008 Jul 01 6:40 PM
Hi,
this will need the creation of a screen at runtime. Check documentation of:
READ report
DELETE report
INSERT report
GENERATE report
SUBMIT
(that is the way the good old SE16 works).
But I would rather try to avoid that. Inserting a PUSH BUTTON and calling a screen when presssed (with ALV or table control) would be an easy alternative - and much easier to maintain...
Kind regards,
HP
Edited by: Holger Pakirnus on Jul 1, 2008 7:41 PM