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.

Thursday, May 24, 2012

SAMPLE SMARTFORMS

report  zsmartformstest.
data: fm_name type
 rs38l_fnam ,
      p_form  
type tdsfname   value 'ZSMARTFORMS'
.
data : begin of t_vbpa occurs 0
,
          vbeln 
type
 vbpa-vbeln,
           kunnr 
type
 vbpa-kunnr ,
           adrnr 
type
 vbpa-adrnr,

       
end of
 t_vbpa.

data : begin of t_kna1 occurs 0
,
          name1 
type
 kna1-name1,
          name2 
type
 kna1-name2 ,
          adrnr 
type
 kna1-adrnr,

       
end of
 t_kna1.
data : begin of t_kna2 occurs 0
,
          vbeln 
type
 vbpa-vbeln,
          name1 
type
 kna1-name1,
          name2 
type
 kna1-name2 ,


       
end of
 t_kna2.
data: t_kna3 like t_kna2 occurs 0 with header line
.data: t_kna4 like t_kna2 occurs 0 with header line.
data: vb like
 vbpa-vbeln.data: n1 like kna1-name1.data: n2 like kna1-name2.
parameters : vbeln like
 vbpa-vbeln.



start-
of
-selection .

  
perform
 data_selection.
  
perform
 data_display.

form
 data_selection.
select

  vbeln
   name1
  name2
  
from kna1 as k inner join vbpa as v on k~adrnr = v~adrnr
  
into corresponding fields of table
 t_kna2
  
where
 vbeln = vbeln.
  
endform
.



form
 data_display.
call function 'SSF_FUNCTION_MODULE_NAME'

    
exporting
      formname           = p_form
    
importing
      fm_name            = fm_name
    
exceptions
      no_form            = 
1
      no_function_module = 
2
      
others             = 3.
  
if sy-subrc <> 0
.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  
endif.

  
call function
 fm_name
    
exporting

         vbeln   = vbeln

    
tables
      t_kna2        =  t_kna2
exceptions
  error_message ss.

 
endform.

EXAMPLE OF SMARTFORMS

report  zsmartformstest.
data: fm_name type
 rs38l_fnam ,
      p_form  
type tdsfname   value 'ZSMARTFORMS'
.
data : begin of t_vbpa occurs 0
,
          vbeln 
type
 vbpa-vbeln,
           kunnr 
type
 vbpa-kunnr ,
           adrnr 
type
 vbpa-adrnr,

       
end of
 t_vbpa.

data : begin of t_kna1 occurs 0
,
          name1 
type
 kna1-name1,
          name2 
type
 kna1-name2 ,
          adrnr 
type
 kna1-adrnr,

       
end of
 t_kna1.
data : begin of t_kna2 occurs 0
,
          vbeln 
type
 vbpa-vbeln,
          name1 
type
 kna1-name1,
          name2 
type
 kna1-name2 ,


       
end of
 t_kna2.
data: t_kna3 like t_kna2 occurs 0 with header line
.data: t_kna4 like t_kna2 occurs 0 with header line.
data: vb like
 vbpa-vbeln.data: n1 like kna1-name1.data: n2 like kna1-name2.
parameters : vbeln like
 vbpa-vbeln.



start-
of
-selection .

  
perform
 data_selection.
  
perform
 data_display.

form
 data_selection.
select

  vbeln
   name1
  name2
  
from kna1 as k inner join vbpa as v on k~adrnr = v~adrnr
  
into corresponding fields of table
 t_kna2
  
where
 vbeln = vbeln.
  
endform
.



form
 data_display.
call function 'SSF_FUNCTION_MODULE_NAME'

    
exporting
      formname           = p_form
    
importing
      fm_name            = fm_name
    
exceptions
      no_form            = 
1
      no_function_module = 
2
      
others             = 3.
  
if sy-subrc <> 0
.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  
endif.

  
call function
 fm_name
    
exporting

         vbeln   = vbeln

    
tables
      t_kna2        =  t_kna2
exceptions
  error_message ss.

 
endform.

Sunday, March 11, 2012

Conversion exit routine for inverted date (INPUT/OUTPUT)

report ZCERINVERTDATE
data d_date(10).

call function 'CONVERSION_EXIT_INVDT_OUTPUT'
exporting
input = '79879869'
importing
output = d_date.
write d_date.

data c_date(8).

call function 'CONVERSION_EXIT_INVDT_INPUT'
exporting
input = '07102005'
importing
output = c_date.
write c_date.

HOW TO SEND AUTOMAIL


report ZSENDAUTOMAIL.

*Sample Program
*
*
*REPORT zcustom_errmsg.
data: lt_mailsubject     type sodocchgi1.
data: lt_mailrecipients  type standard table of somlrec90 with header line.
data: lt_mailtxt         type standard table of soli      with header line.

* Recipients
lt_mailrecipients-rec_type  = 'U'.
lt_mailrecipients-receiver = 's777@gmail.com'.
append lt_mailrecipients .
clear lt_mailrecipients .

* Subject.
lt_mailsubject-obj_name = 'TEST'.
lt_mailsubject-obj_langu = sy-langu.
lt_mailsubject-obj_descr = 'Mail Subject'.

* Mail Contents
lt_mailtxt = 'This is a test mail'.
append lt_mailtxt. clear lt_mailtxt.

* Send Mail
call function 'SO_NEW_DOCUMENT_SEND_API1'
  exporting
    document_data              = lt_mailsubject
  tables
    object_content             = lt_mailtxt
    receivers                  = lt_mailrecipients
  exceptions
    too_many_receivers         = 1
    document_not_sent          = 2
    document_type_not_exist    = 3
    operation_no_authorization = 4
    parameter_error            = 5
    x_error                    = 6
    enqueue_error              = 7
    others                     = 8.
if sy-subrc eq 0.
  commit work.

*   Push mail out from SAP outbox
  submit rsconn01 with mode = 'INT' and return.
endif.

HOW TO CREATE RANDOM NUMBER

*&---------------------------------------------------------------------*
*& Report  ZRANDOMNUMBER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZRANDOMNUMBER.
DATA RANINT LIKE QF00-RAN_INT.

PARAMETERS: P_MAX LIKE QF00-RAN_INT DEFAULT 100,
P_MIN LIKE QF00-RAN_INT DEFAULT 1,
P_TIMES TYPE I DEFAULT 10.

WRITE:/ 'RANDOM NUMBER'.
ULINE.

DO P_TIMES TIMES.

CALL FUNCTION 'QF05_RANDOM_INTEGER'

EXPORTING RAN_INT_MAX = P_MAX
         RAN_INT_MIN = P_MIN

IMPORTING RAN_INT = RANINT

EXCEPTIONS INVALID_INPUT = 1

OTHERS = 2.

IF SY-SUBRC EQ 0.

WRITE:/ RANINT. ELSE.
WRITE:/ 'UNABLE TO GENERATE RANDOM NUMBER'.

ENDIF.

ENDDO.

Wednesday, January 25, 2012

HOW TO UPLOAD A EXCEL FILE USING ABAP


REPORT  ZEXCELFILEUPLOAD.
TYPE-POOLS: truxs.

type-pools : slis.
data:   it_fieldcat type slis_t_fieldcat_alv,
        lt_top_of_page type slis_t_listheader,
        ls_layout      type slis_layout_alv,
        gt_events      type slis_t_event.

data :  wa_fieldcat like line of it_fieldcat.

PARAMETERS: p_file TYPE  rlgrap-filename.

TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      col4(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.

DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.


***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw       " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
   EXCEPTIONS
      conversion_failed        = 1
      OTHERS                   = 2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
*  LOOP AT it_datatab INTO wa_datatab.
*    WRITE:/ wa_datatab-col1,
*            wa_datatab-col2,
*            wa_datatab-col3.
*  ENDLOOP.


  wa_fieldcat-fieldname = 'COL1'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'NAME'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '1'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL2'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'ADDRESS'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '2'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL3'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'PHONE'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '3'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  wa_fieldcat-fieldname = 'COL4'.
  wa_fieldcat-ref_tabname = 'IT_DATATAB'.
  wa_fieldcat-seltext_l = 'EMAIL'.
  wa_fieldcat-outputlen = 20.
  wa_fieldcat-col_pos     = '4'.
  append wa_fieldcat to it_fieldcat.
  clear wa_fieldcat.

  clear wa_fieldcat.

  call function 'REUSE_ALV_GRID_DISPLAY'

  exporting
    i_callback_program                = sy-cprog
    is_layout                         = ls_layout
    it_fieldcat                       = it_fieldcat[]

   it_events                         = gt_events[]
   tables
     t_outtab                          = it_datatab[]
 exceptions
  program_error                     = 1
  others                            = 2
           .
  if sy-subrc <> 0.

  endif.
  """"""""""""