This website is not affiliated with, sponsored by, or approved by SAP AG.

0004 - PF Statuses

Moderators: thx4allthefish, Snowy, ilya, Rich

0004 - PF Statuses

Postby Rich » Thu Mar 26, 2009 11:49 am

PF Statuses.

A PF Status is the method by which SAP allows a programmer to create an Interactive Report. The PF Status is used when the programmer wants to provide more than the standard functionality provided by SAP. The catch is that when you create a PF Status you have to do everything including the programming the back button, the search button, the print button and so forth. These are all handled in the AT USER-COMMAND event.

How do they work?

Within the PF Status you assign an icon and a four character code to each button you want to include on the status.

You tell the program which status you wish to use by using the SET PF-STATUS Command.

When a user clicks one of these buttons, in report programming, the Status calls the AT USER-COMMAND event, passing the four character code of the button to your program in the system field SY-UCOMM. In Module Pool or Dialog Processing, the system calls the PAI event, passing the code for the button again in sy-ucomm. You can then process this like so:

Code: Select all
At User-Command.
*
   Data w_answer type c.
*
   Case sy-ucomm.
        When 'DSEL'.
             Perform Deselect_All.
        When 'F2'.
             Perform Show_Order.
        When 'FLTC'.
             Perform Filter_Report.
        When 'GO'.
             Perform Process_Orders using t_Orders changing w_answer.
*
*            Anything left to process ?
*
             If w_answer = '1'.                " Yes they processed them
                Read Table t_Orders index 1
                     transporting no fields.
                If sy-subrc = 0.
                   Perform Show_Report using t_orders.
                Else.
                   Message I000 with Text-035.
                   Leave.
                EndIf.
             EndIf.
        When 'HELP'.
             Perform Prg_Doc_Help.
        When 'SELA'.
             Perform Select_All.
        When 'SELB'.
             Perform Select_Block.
        When 'SHPR'.
             Perform Show_Prod_Orders using t_orders.
        When 'UPRI'.
             Perform Print_Report.
   EndCase.


Note that TOP-OF-PAGE processing is replaced by TOP-OF-PAGE DURING LINE-SELECTION.

For Module Pool programming, your code would look something like this:

Code: Select all
Process After Input.
  Loop At T_Sel_Heads.
      Chain.
        Field: Wa_Sel_Heads-Pcrn,
               Wa_Sel_Heads-Kunag,
               Wa_Sel_Heads-Kunwe,
               Wa_Sel_Heads-Vbeln,
               Wa_Sel_Heads-Coat,
               Wa_Sel_Heads-Colour,
               Wa_Sel_Heads-Vdatu,
               Wa_Sel_Heads-Area,
               Wa_Sel_Heads-Ameins.
        Module Tc_Sel_Heads_Modify On Chain-Request.
      Endchain.
  Endloop.
  Module Tc_Sel_Heads_User_Command.
*
  Loop At T_Cur_Items.
      Chain.
        Field: Wa_Sel_Items-Posnr,
               Wa_Sel_Items-Matnr,
               Wa_Sel_Items-Kwmeng,
               Wa_Sel_Items-Meins,
               Wa_Sel_Items-Werks,
               Wa_Sel_Items-Lifnr,
               Wa_Sel_Items-Netpr.
        Module Tc_Line_Items_Modify On Chain-Request.
      Endchain.
  Endloop.
  Module Tc_Move_Current_Lines.
  Module Tc_Line_Items_User_Command.
*
  Loop At T_Errors.
    Chain.
      Field: Wa_Error_Line-Pcrn,
             Wa_Error_Line-Posnr,
             Wa_Error_Line-Text.
    Endchain.
  Endloop.
  Module Tc_Errors_User_Command.
  Module Screen_Level_User_Command.   "<--- This module processes the button clicks


Code: Select all
Module Screen_Level_User_Command input.

  Case sy-Ucomm.
       When c_Back.
            Perform Check_Leave_Screen Using Text-062
                                    changing w_Answer.
            Case w_Answer.
                 When c_No.
                      Set Screen 0.
                      Leave Screen.
                 When c_Yes.

*                     Validate and save entryies c_Yes is returned
*                     if all saved ok

                      Perform Validate_And_Save Using t_Sel_Heads[]
                                                      t_Sel_Items[]
                                             Changing t_Errors[]
                                                      w_Answer.
                      If w_Answer = c_Yes.
                         Set Screen 0.
                         Leave Screen.
                      EndIf.
            EndCase.
       When c_Exit or c_RollBack.
            Perform Check_Leave_Screen Using Text-043
                                    Changing w_Answer.
            Case w_Answer.
                 When c_No.
                      Leave Program.
                 When c_Yes.
                      Perform Validate_And_Save Using t_Sel_Heads[]
                                                      t_Sel_Items[]
                                             Changing t_Errors[]
                                                      w_Answer.
                      If w_Answer = c_Yes.
                         Leave Program.
                      EndIf.
            EndCase.
       When c_Save.
            Perform Check_Save_Data Using Text-044
                                          Text-045
                                 Changing w_Answer.
            If w_Answer = '1'.
               Perform Validate_And_Save Using t_Sel_Heads[]
                                               t_Sel_Items[]
                                      Changing t_Errors[]
                                               w_Answer.
               If w_Answer = c_Yes.
                  Set Screen 0.
                  Leave Screen.
               EndIf.
            EndIf.
  EndCase.
endmodule.                 " Screen_Level_User_Command  INPUT



Sidestepping The Do-It-All Trap.

It is possible however to side step the problem above and that is by assigning the codes that SAP use in it's standard processing to the various buttons in the GUI Status to the buttons that you want to have normal functionality whilst assigning custom codes to the buttons that you want to process yourself. When a user then clicks a button on the GUI, SAP processes it's own statuses first, only triggering the AT USER-COMMAND event for the statuses that it does not recognise. This includes Find and Find Next functionality straight out of the box!

The standard button values are:

Image

The remaining buttons (New sessions, Help and Options) are not configurable.

Differences Between PF Statuses.

Are Statuses different from program to program -and if so what are the differences ?

How long is a piece of string ? The differences between each PF status in the system depends on the application program that it has been written for.

Setup

The easiest way to set up a PF-Status is to enter the line SET PF-STATUS 'MAIN' (or whatever name) in the correct part of your program, make sure the program compiles and then double click on the PF Status Name.

Code: Select all
Start-Of-Selection.                                       
*                                                         
    Set Pf-Status 'MAIN'.                                 
    Write :/ Text-002, w_kunnr input on.  Hide w_kunnr.   


The second easiest way is to copy a GUI Status from one that you made earlier! This is something that I do all the time. I tend to create a full GUI status for the first report I write and then I copy that, removing the application dependant buttons but keeping the SAP standard buttons. This is accomplished via transaction SE51.

So, click on the 'MAIN'. If you have not already created the status you are asked if you want to create it. Click Yes. Then the following screen appears:

Image

Enter a description for the status, make sure 'Online Status' is selected and click the green tick.

SAP will then create the gui status and display the Status Maintenance Screen.

Click on the 3 down pointing arrows to expand all the statuses so that you can work with them. This then gives you a screen like that shown in the screen shot below. Notice that the SAP Standard Tool bar is displayed.

Image

The first thing to do is to enter the standard SAP values into the Standard Tool bar fields. This at least gives the report standard functionality and the ability to get back to the Parameter screen (!)

Also click the 'Display Standards' button for the menu bar.

Creating Application Icons.
Application icons are icons that are specifically created for the report that is being displayed.

For example a particular report has a series of buttons that enable various actions to be carried out:Image

These icons enable the user to:

    Show the production orders for the display sales orders
    Show the actual sales order
    Select all of the items on the report
    Select a range of items on the report
    Deselect items on the report
    Filter items on the report
    Display program documentation

To create these icons, you use the screen shown above. There are three steps to creating these icons. They are:

    Assigning the Status Button Code.
    Entering the Function Text.
    Selecting the icon name.

Assigning the Status Button Code.
As mentioned above Status buttons are assigned a four character code that is used to communicate the users intent to the ABAP program. These codes are entered in the Enquiry Status Grid:

Image

Enter the first code in the first field. You can continue to enter the remainder of the codes by using the TAB key to move across the fields, or you can fully define the code (the following two steps) for each button as you enter the button code by pressing the <cr> key. If you enter all the codes and then press the return key you are asked to define all the buttons one after the other.

Entering the Function Text.

Press the <CR> key. The window shown below is displayed:

Image

There are two types of text to choose from. The first is a static text which is set in the GUI. The second is a dynamic text which ios set to the contents of a dictionary variable that you specify at run time.

This will only deal with static texts as I've never yet found the need to use dynamic texts.

Select 'Static Text'and click the tick. The next window displayed contains three fields. The Function text , Icon name and Info text.

The Function text is a short description that appears when the mouse hovers over the button, or when the item is displayed in an SAP menu.

The Info text is a short piece of help describing the function of the button.

Selecting The Icon Name.

SAP provides it's own icons which can be displayed using program RSTXICON which looks something like this:

Image

Function Key Usage.

The function keys are set during the construction of the GUI Status and are set using the above screen by entering the button codes in the relevant fields on the screen:

Image

But With A Print Option

If the user clicks the print button on the above report then the data displayed can be printed however, there is a technique that I like to use which makes displayed reports and printed reports slicker.

If a report is displayed on the screen, there is no point in displaying page breaks with multiple headers for each page. However, if the report is printed, the user requires the heading to be printed on the top of every page.

This can be achieved quite easily in the following manner.

    Set the initial report page line count to 0.
    This is carried out by the report statement at the top of your report program:

Code: Select all
Report Y_BackFlush
       Message-id 38
       Line-Size  190
       Line-Count 0
       No Standard Page Heading.


    Create a gui using the standard codes shown in the table above. Changing the printer code to something like 'UPRI'.

    Enter the appropriate code in the USER-COMMAND Event.Write a small subroutine which sets the line count and the print-immediately flag. Call the procedure that prints the report:

Code: Select all
Form Print_Report.
*
     New-Page No-title
              No-heading
              Line-Count 64
              Line-Size  190
              Print On Immediately True.
     If g_report_type <> c_Error_Report.
        Perform Show_Report using t_Orders.
     Else.
        Perform Error_Report.
     EndIf.
     New-Page print on immediately False.
EndForm.


Since somewhere in the 4.x releases, the ability of New-Page to display a printer selection dialog has been depreciated and should now look something like this:

Code: Select all
Form Print_Report using pu_Matnr        type Material_Number
                        pu_Order_List   type Order_List
                        pu_Filter_Field type Filter_Field
                        pu_Filter_Value type Filter_Value.
*
     Data: W_Pri_Params type Pri_Params,
           w_Valid      type C.
*
     Call Function 'GET_PRINT_PARAMETERS'
       Exporting
         Line_Count                   = 64
         Line_Size                    = 132
         Immediately                  = True
       Importing
         Out_Parameters               = w_Pri_Params
         Valid                        = w_Valid
       Exceptions
         Archive_Info_Not_Found       = 1
         Invalid_Print_Params         = 2
         Invalid_Archive_Params       = 3
         Others                       = 4.
      If w_Valid = True.
         New-Page Print on   Parameters w_Pri_Params
                             No Dialog.
         Perform Show_Report using pu_Matnr
                                   pu_Order_List[]
                                   pu_Filter_Field
                                   pu_Filter_Value.
         New-Page Print Off.
      EndIf.
EndForm.


Note the fact that the code now does not rely on New-Page to display the dialog but rather uses the function module 'GET_PRINT_PARAMETERS' to do so.

    The TOP-OF-PAGE event is not called during this process. This is because you are in a LINE-SELECTION situation so you need a TOP-OF-PAGE DURING LINE-SELECTION event which does the same thing as the TOP-OF-PAGE event. If there are other options available from the GUI status you need to include code to determine if the report is being printed or not (by looking at SY-UCOMM). I tend to put the top of page processing in a procedure and call that during both events:

Code: Select all
*Eject
Top-Of-Page.
   Perform Top_Of_Page.
Top-Of-Page during Line-Selection.
   Perform Top_Of_Page.
End-Of-Page.
   Perform TableLine.


    The code for the top-of-page events looks something like this:

Code: Select all
Form Top_Of_Page.
*
    Case g_report_type.
         When c_Error_Report.
              Perform RepHeader using '' Text-015.
              Psub s_vbeln text-016.
              Skip.
              Write :/ Text-034.
              Write :/10 Text-028, at 30 g_num_cnfmd,
                     /10 Text-029, at 30 g_num_recpt,
                     /10 Text-030, at 30 g_num_pickd.
              Skip 1.
         When c_Prod_Report.
              Perform RepHeader using '' Text-017.
              Perform Param_Subtitle using Text-016 g_vbeln.
              Perform PrintTitles.
         When Others.
              Perform RepHeader using '' sy-title.
              Psub s_vbeln text-016.
    EndCase.
EndForm.


    The end of page event is not fired when printing during line selection. Because of this you need to use code like this in the main report loop to compensate:

Code: Select all
*
*            End of page doesn't work when printing during line
*            selection
*
             If sy-linct <> 0.
                If sy-linno = 63.
                   Perform TableLine.
                   New-Page.
                EndIf.
             EndIf.


    Job Done.

Special Cases In Module Pool Programming

In Module Pool programming (ie dialog screens), there are times when you would want the normal screen validation checks not to occur. For example when the user is moving back a screen, or is exiting the program using the eXit or the roll back work buttons. In order to do this, you define your buttons in the GUI as Exit functions.

When creating the functions in transaction SE41, and you specify an okcode that does not exist in the system you will be presented with a window within which you can describe the various attributes of that button:

Image

As explained above, you enter the various static function texts, however, what interests us here is the field circled in red - The function type button. This defines what type of button the button is. Leaving the button blank specifies that the button is a standard menu bar button. However, if you enter 'E' in this field you define the button as an Exit Function.

So, now that we have done that, how does that benefit us ?

If we take the code defined in the Module Screen_Level_User_Command you can see that it contains functions that handle the user leaving the screen. In placing this functionality in the User_Command module all of the field validations will take place, which as the user is leaving the screen in the reverse direction, or even leaving the program entirely, we don't want to happen.

So, We move the exit functionality to a second module like so:

Code: Select all
Module Exit_Functions input.

  Case sy-Ucomm.
       When c_Back.
            Perform Check_Leave_Screen Using Text-062
                                    changing w_Answer.
            Case w_Answer.
                 When c_No.
                      Set Screen 0.
                      Leave Screen.
                 When c_Yes.

*                     Validate and save entryies c_Yes is returned
*                     if all saved ok

                      Perform Validate_And_Save Using t_Sel_Heads[]
                                                      t_Sel_Items[]
                                             Changing t_Errors[]
                                                      w_Answer.
                      If w_Answer = c_Yes.
                         Set Screen 0.
                         Leave Screen.
                      EndIf.
            EndCase.
       When c_Exit or c_RollBack.
            Perform Check_Leave_Screen Using Text-043
                                    Changing w_Answer.
            Case w_Answer.
                 When c_No.
                      Leave Program.
                 When c_Yes.
                      Perform Validate_And_Save Using t_Sel_Heads[]
                                                      t_Sel_Items[]
                                             Changing t_Errors[]
                                                      w_Answer.
                      If w_Answer = c_Yes.
                         Leave Program.
                      EndIf.
            EndCase.
  EndCase.
endmodule.                 " Exit_Functions  INPUT


And in the PBO of out program we add a new line:

Code: Select all
Module Exit_Functions at Exit-Command.


What now happens is that when the user presses a function key or button that is designated as an exit button, the normal screen checks are not processed, and instead this module is called. In this module you should be polite to the user and check to make sure that they do know what they are doing and do wish to leave the screen by the use of a popup (something like POPUP_TO_CONFIRM), and giving them the opportunity to cancel the exit if they so wish.

And Finally.

Statuses can be modified at run time by using the EXCLUDING clause of the SET PF-STATUS command to supply a list of buttons that should be inactivated. Other programs statuses can be used by using the OF PROGRAM clause.

A status can be displayed immediately by using the IMMEDIATELY clause.

Regards

Rich

Image
Abap KC
SFMDR
Rich
 
Posts: 6919
Joined: Thu Oct 31, 2002 4:47 pm
Location: Geneva

Return to ABAPers

Who is online

Users browsing this forum: No registered users and 1 guest




This website is not affiliated with, sponsored by, or approved by SAP AG.