ALV Tutorial 02 - PF-STATUS, GUI Title and Exception Lights - Spider's Web

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

11/20/2019 ALV tutorial 02 – PF-STATUS, GUI title and exception lights | Spider's web

Spider's web
…share your own experience

ALV tutorial 02 – PF-STATUS, GUI title and exception


lights
Posted on 2013-04-26

In this step we’ll customize our ALV with custom PF-STATUS (buttons, menu, …), GUI title and we’ll also add a column
with exception lights (Red/Yellow/Green)

1. We need to modify our table gt_data with SFLIGHT data to hold one more information – exception light.

TYPES: BEGIN OF ty_data.


INCLUDE STRUCTURE sflight.
TYPES: exc_light(1) TYPE c, " new field to hold the exception light
END OF ty_data.

DATA: gt_data TYPE TABLE OF ty_data.

2. Then we have to fill this info field with data – most probably during data retrieval so in our case in FORM
get_data:

FORM read_data.
DATA:
l_color TYPE c.

FIELD-SYMBOLS:
<fs_data> TYPE ty_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data


FROM sflight
UP TO c_max_rows ROWS.

LOOP AT gt_data ASSIGNING <fs_data>.


IF <fs_data>-seatsocc = <fs_data>-seatsmax OR
<fs_data>-seatsocc_b = <fs_data>-seatsmax_b OR
<fs_data>-seatsocc_f = <fs_data>-seatsmax_f.
<fs_data>-exc_light = 2. " Yellow - some class is full
ELSEIF <fs_data>-seatsocc = <fs_data>-seatsmax AND
<fs_data>-seatsocc_b = <fs_data>-seatsmax_b AND
<fs_data>-seatsocc_f = <fs_data>-seatsmax_f.
<fs_data>-exc_light = 1. " Red - the flight is full
oprsteny.com/?p=496 1/5
11/20/2019 ALV tutorial 02 – PF-STATUS, GUI title and exception lights | Spider's web
ELSE.
<fs_data>-exc_light = 3. " Green - seats available
ENDIF.
ENDLOOP.
ENDFORM.

3. We have to tell our ALV which field holds the exception light information so we have to add this information to
layout (new variable ls_layout) of ALV used during it’s display:

FORM display_grid.
DATA: ls_layout TYPE lvc_s_layo.

ls_layout-excp_fname = 'EXC_LIGHT'.

CREATE OBJECT g_grid


EXPORTING
i_parent = cl_gui_container=>default_screen.

CALL METHOD g_grid->set_table_for_first_display


EXPORTING
i_structure_name = 'SFLIGHT'
is_layout = ls_layout
CHANGING
it_outtab = gt_data
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.

4. We are now done with the exception light and we can step into adding the PF-STATUS (modify the toolbar,
define response on user actions, …)
First of all we will separate the PF-STATUS and titlebar modification from our code so we’ll add new module into
screen 0100 PBO section (we’ll put it’s definition into main program).
At the same time we add new module for handling user actions to the PAI section (we’ll create it’s definition in the
main program)

PROCESS BEFORE OUTPUT.


MODULE status_0100.
MODULE display_grid.
*
PROCESS AFTER INPUT.
MODULE user_command_0100.

5. We’ll take it step-by step so the first will be MODULE status_0100

MODULE status_0100 OUTPUT.


SET PF-STATUS 'MAIN'.
SET TITLEBAR 'ALV_EXAMPLES'.
ENDMODULE.

oprsteny.com/?p=496 2/5
11/20/2019 ALV tutorial 02 – PF-STATUS, GUI title and exception lights | Spider's web

In the above code you can see we set the TITLEBAR to ALV_EXAMPLES – double click on ALV_EXAMPLES, create
new GUI title object and set your desired title text. We alse set name of the PF-STATUS 'MAIN'. We’ll create this
status in object tree by right-click on the program name -> Create -> GUI status and name it MAIN. In our
program we won’t handle any special user commands so we’ll implement only the BACK, EXIT and CANCEL
actions.

6. The next is new MODULE display_grid where we moved our data handling and calling the ALV display
(separation into modules depends only on your choice)

MODULE display_grid OUTPUT.


PERFORM read_data.
PERFORM display_grid.
ENDMODULE.

7. The last part is handling user input in MODULE user_command_0100

MODULE user_command_0100 INPUT.


* to react on oi_custom_events:
call method cl_gui_cfw=>dispatch.
CASE sy-ucomm.
WHEN 'BACK' OR
'EXIT' OR
'CANCEL'.
LEAVE PROGRAM.
WHEN OTHERS.
* do nothing
ENDCASE.
ENDMODULE.

oprsteny.com/?p=496 3/5
11/20/2019 ALV tutorial 02 – PF-STATUS, GUI title and exception lights | Spider's web

8. Output of our program will be like on the following picture

SHAR E I T W I T H YOUR FRIENDS:

 Print  Email Share 0 Share Tweet  More

RELAT E D

ALV tutorial 05 - Handling events ALV tutorial 07 - coloring rows ALV tutorial 03 - ICON column
2013-04-28 2013-04-28 2013-04-28
In "ABAP" In "ABAP" In "ABAP"

Article displayed: 10641x


This entry was posted in ABAP, ALV tutorial, Development and tagged ABAP.PF-STATUS, GUI title, lights, SAP by
Spider. Bookmark the permalink [https://oprsteny.com/?p=496] .

3 THOUGHTS ON “ALV TUTORIAL 02 – PF-STATUS, GUI TITLE AND EXCEPTION LIGHTS”

Youssef.B
on 2015-04-22 at 3:15 pm said:

Hello,

Thank you very much for your tutorial. Their is mistake on the condition of step 2, you have to reverse the
condition test of yellow and red light otherwise we will never go to red condition test.

 Loading...

oprsteny.com/?p=496 4/5
11/20/2019 ALV tutorial 02 – PF-STATUS, GUI title and exception lights | Spider's web

FuryNocturn
on 2017-10-02 at 8:24 am said:

Programa Z04_RESERVAS_ALV linea 36


Field “C_MAX_ROWS” is unknown. It is neither in one of the specified
tables nor defined by a “DATA” statement . . . . . . . . . .

 Loading...

FuryNocturn
on 2017-10-02 at 8:34 am said:

Programa Z04_RESERVAS_ALV linea 60


Field “G_GRID” is unknown. It is neither in one of the specified tables
nor defined by a “DATA” statement . . . . . . . . . .

 Loading...

Become a Data Scientist


Get certi ed by a globally recognized institute! Program starts soon,
book your seat now

oprsteny.com/?p=496 5/5

You might also like