1

I want to grey out a field "REQUIREMENT QUANTITY" in an enhancement of COR1 and COR2. I have made a Z-table so that the IDs maintained in that Z-Table should not be able to make any changes and the field should be greyed out for those particular IDs. Please guide.

Thank you.

I wrote the following code. Please check if this works for the above condition:

IF sy-tcode EQ 'COR1' or sy-tcode EQ 'COR2'.
  SELECT SINGLE *
  FROM zita_pp_cor1
  INTO @DATA(wa_zita)
  WHERE z_user = @sy-uname.
ENDIF.

IF wa_zita IS NOT INITIAL.
 AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-name = 'BDMNG'.
      screen-input = 0.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
ENDIF.
AlexSchell
  • 953
  • 1
  • 1
  • 18
Uzair Qazi
  • 11
  • 1
  • You have posted ABAP code which doesn't compile. Either you have a question about fixing the syntax error and you should then be describing this error, or your issue is not about the syntax error and you should review your question to post valid code. Thank you. – Sandra Rossi May 30 '23 at 21:02
  • I guess my ABAP code is incorrect. Can someone please guide me through the code? The question I asked is correct – Uzair Qazi May 31 '23 at 04:24

2 Answers2

0

Theoretically, clearing INPUT will make the input field grey, so that shouldn't be a problem. Check in Debug mode to see if you can get to that point and pass 0.

I think the problem will be that you are using the AT SELECTION-SCREEN OUTPUT section in the wrong place. Since SELECT is not part of this section either, it will contain empty values.

This is how I would modify your code:

AT SELECTION-SCREEN OUTPUT. 
  IF sy-tcode EQ 'COR1' or sy-tcode EQ 'COR2'. 
    SELECT SINGLE * FROM zita_pp_cor1 INTO @DATA(wa_zita) WHERE z_user = @sy-uname. 
  ENDIF.

  IF wa_zita IS NOT INITIAL. 
    LOOP AT SCREEN. 
      IF screen-name = 'BDMNG'. 
        screen-input = 0. 
        MODIFY SCREEN. 
      ENDIF. 
    ENDLOOP. 
  ENDIF.

Make sure the screen name is correct. I use the group to define the exact fields on the select screen.

PARAMETERS: p_matnr TYPE matnr MODIF ID fil.
...
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
  IF screen-group1 = 'FIL'.
    CLEAR screen-input.
    MODIFY SCREEN.
  ENDIF.
ENDLOOP.
Kisbandi
  • 71
  • 5
0

Let's have a look at a general structure of the program events to understand where it is necessary to place the custom code.

There are a number of events in the lifecycle, which can be introduced in the program through the following keywords in order to place the custom code inside them. Note that event block are internal to the program, they are triggered by the runtime environment at the defined points of execution and cannot be called programmatically.

Program constructor events

LOAD-OF-PROGRAM

Servers as a program constructor. Called by environment when the program is loaded into internal session memory, triggered only once per program execution. Used to initialize the global data.

Reporting events

INITIALIZATION

The first event triggered when the program is executed, executed immediately after the LOAD-OF-PROGRAM. If the program has a selection screen defined, INITIALIZATION event is called after the selection screen code has been processed first time by runtine environment but before the selection screen is dispayed to the user. Can be used to initialize input fields, change the default values of them or initialize all of the values in the program. The event is triggered only once per program execution, any subsequent call to the selection screen would not trigger this even again. For initializing or modifying the selection screen fields often the selection sreen events are preferred.

Note: Selection screen events (see below) are executed between INITIALIZATION and START-OF-SELECTION

START-OF-SELECTION

Called after the INITIALIZATION event. If the program has a selection screen defined, this is the first event triggered after all selection screen events. It is a standard event: if no other events are declared, there is no need to code this event manually, all processing statements are automatically assigned to an implicit START-OF-SELECTION block. Any statements between the global declaration area and the first processing block of the program are automatically inserted at the beginning of the event. All the program logic goes into this event block.

Selection screen events

they are called when a selection screen is processed

AT SELECTION-SCREEN OUTPUT

is a PBO - process before output - event, triggered before the screen is displayed to the user
can use this event block in the program to react to the event and execute code to dynamically change field properties (i.e. enable / disable fields) or to assign default values

AT SELECTION-SCREEN

is a PAI - process after input - event, triggered after user takes some action on the displayed screen (i.e. clicking a button)
this is a default PAI event triggered after all the selection screen events are executed, can be used to validate user inputs
there are several other specific PAI events available, which allow more fine-grained control: AT SELECTION-SCREEN ON <field> | END OF <sel> | BLOCK | RADIO BUTTON GROUP

Having this overview it should be clear, that conditions, looping at and modifying the screen should go inside the AT SELECTION-SCREEN OUTPUT event - process before output, modification of the selection screen should be done before it will be displayed to a user.

In case as you wrote it (used AT SELECTION-SCREEN OUTPUT inside the condition) places this whole part of code to the default START-OF-SELECTION event block and does not lead to the desired result.

AlexSchell
  • 953
  • 1
  • 1
  • 18