Sunday, December 30, 2012

How to Add Traffic Sign in ALV report

REPORT  ZTRAFFICSIGN.

TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPESBEGIN OF ty_sbook.
        INCLUDE STRUCTURE sbook.
TYPESicon TYPE c,  " Add field to hold traffic light value
       END OF ty_sbook.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF ty_sbook.
DATA: wa_sbook     TYPE ty_sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: is_layout    TYPE slis_layout_alv.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.

*Assign different traffic lights to each row based on condition
  LOOP AT it_sbook INTO wa_sbook.
    IF wa_sbook-luggweight LE 0.
      wa_sbook-icon = 1.  " Red Traffic Light
    ELSEIF wa_sbook-luggweight LE 10.
      wa_sbook-icon = 2.  " Yellow Traffic Light
    ELSE.
      wa_sbook-icon = 3.  " Green Traffic Light
    ENDIF.
    MODIFY it_sbook FROM wa_sbook TRANSPORTING icon.
    CLEAR: wa_sbook.
  ENDLOOP.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'LUGGWEIGHT'.
  wa_fieldcat-seltext_m  = 'Weight'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'WUNIT'.
  wa_fieldcat-seltext_m  = 'Unit'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

*Fill layout info.
*Fill traffic lights field name in the ALV layout
  is_layout-lights_fieldname = 'ICON'.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      is_layout          = is_layout
      it_fieldcat        = it_fieldcat
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.



OUTPUT



Wednesday, December 26, 2012

Create Pushbuttons on the selection screen without using PF Status


Creating pushbuttons on the selection without using SET PF-STATUS

Step-by-step approach to create pushbuttons on the selection screen
Step 1:
Create a program “ZPUSH_BUTTON” in SE38 with meaning full name.

Choose Save or Enter Button.

Step 2:
Write the following code
REPORT  ZPUSH_BUTTON.

TABLES: SSCRFIELDS.

SELECTION-
SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_BSART TYPE BSART DEFAULT 'XXX'.

SELECTION-
SCREEN SKIP 3.
SELECTION-
SCREEN PUSHBUTTON /15(10TEXT-002 USER-COMMAND CL1.
SELECTION-
SCREEN PUSHBUTTON 45(10TEXT-003 USER-COMMAND CL2.
SELECTION-
SCREEN END OF BLOCK B1.

DATA: L_UCOM LIKE SY-UCOMM.

AT SELECTION-SCREEN OUTPUT.
IF L_UCOM = 'CL1'.
 
LOOP AT SCREEN.
 
IF SCREEN-NAME CS 'P_BSART'.
   
SCREEN-INPUT = 1.
   
MODIFY SCREEN.
 
ENDIF.
 
ENDLOOP.
ELSEIF L_UCOM = 'CL2'.
 
LOOP AT SCREEN.
 
IF SCREEN-NAME CS 'P_BSART'.
   
SCREEN-INPUT = 0.
   
MODIFY SCREEN.
 
ENDIF.
 
ENDLOOP.
ENDIF.

AT SELECTION-SCREEN.
CASE SSCRFIELDS.
WHEN 'CL1'.
 L_UCOM = 
'CL1'.
WHEN 'CL2'.
 L_UCOM = 
'CL2'.
ENDCASE.
Step 3:
Execute the program.
The Initial selection screen will be displayed as below.



How to debug Smart Forms


1. Go to your smart form, click on Environment->Function Module Name.

2. You will get a pop-up, in that function module name will be displayed copy that function module number
3. Go to transaction SE37 and paste the generated function module name
 
4. Click on display, select Attributes tab. In that tab double click on Program Name field
 
5. Following screen will appear, double click on last include
6. In this include first few lines will be system generated code, followed by our code 
7. If we want to check GV_NO variable and set breakpoint at that variable, give CTRL + F and give that variable name
8. Now execute your smartform, Breakpoint will be triggered & you can debug.
Summary
We can search for variable or internal table or objects in that include, set breakpoint & debug it.

Drop Down lists in the selection parameters

PROGRAM ztest.   TYPE-POOLS : vrm.   DATA : name TYPE vrm_id,        list TYPE vrm_values,        value LIKE LINE OF list. ...