Showing posts with label ALV. Show all posts
Showing posts with label ALV. Show all posts

Monday, April 25, 2022

SMART FORMS IN SAP ABAP

 SMART FORMS IN SAP ABAP. 

It is enhanced version to SAP scripts. Transaction code is smartforms.


First we discuss about the differences scripts and smart forms.


Scripts are client dependent but smart forms are client independent.

Scripts are not self executable i.e. print program is compulsory, but smart forms are self executable. On executing the smart form system generates function module.

We can not write the logic in scripts but we can write the logic in smart forms.

Main window is compulsory in scripts but it is optional in smart forms.

Background logo is not possible in scripts but it is possible in smart forms.

There are character and paragraph formats in scripts but there are no character and  paragraph formats in smart forms

Labels are present in scripts but no labels in smart forms.


When ever you enter into smartforms under global settings you get three things.

Form attributes

Form interface

Global definitions

FORM ATTRIBUTES:-  It gives the history and technical attributes of smart form


FORM INTERFACE: - The variables that are needed to be populated at run time should be declared here.


GLOBAL DEFINITIONS:-  The variables that are needed in the smart form should be declared here. 

  


Now we discuss about the steps in creation of smart forms.


T-code smartforms

Press create button

To create logo window right click o page create( Graphic

Give the logo name

The variables that are needed to be populated at run time should be declared under form interface

The variables that are needed to be populated at run time should be declared under Global definitions.

To write the select query or logic select the window right click create( flow logic ( program lines

It is mandatory to give input parameters and output parameters

To write loop select the code Right click create( flow logic -( loop

To write the output select  loop Right click Create ( Text

Check for errors

Activate and Execute

Function module will be generated. Execute it

Give printer name LP01 (Default Printer)

Press print preview to see output

Friday, April 22, 2022

Pre-requisites for using Control break statements


Pre-requisites for using Control break statements in sap. 

Pre-requisites for using Control break statements Control break statements should be used in side the loop but on change of can be used outside the loop. Before using the control break statement the internal table should be sorted by the field on which control break statement is going to be used.

 

AT FIRST:- This is triggered at the first record of the internal table. This is triggered only once. It is usually used to write the heading to columns while displaying the records of internal table.


AT LAST:- This is also triggered only once at the last record of the internal table. This is used to find out grand totals of numeric values.


AT NEW <FIELD>:- This is triggered at the starting of every new record based on a particular field. It is used to calculate sub totals.


AT END OF <FIELD>:- This is triggered at the end of every new record based on a particular field. It is also used to find out sub totals.

Sunday, September 13, 2020

Differences between Normal Reports and ALV Reports in SAP ABAP.

What are the differences between Normal Reports and ALV Reports?



  • Classical reports
  • ALV Reports

1. Simple reports using the WRITE statements within the loops.

1. The system generated Functions start with REUSE* are used to display the data.

=================================================================

2. Performance is not as good as ALV Reports since the LOOP statement must be used to display the data.

2. Performance is good since the data is displayed using the function modules outside of the loops.

=================================================================

3. Not possible to edit the Fields in the Output.

3. It can be possible to edit the Fields in the Output.

=============================================================

4. It is difficult to display the LOGOS in the output.

4. It is so EASY to display the LOGOS in the output.

==========================================================

5. It is COMPLEX to Align the Columns.

5. Column Alignment is done by the system.

Thursday, July 23, 2020

Send Mail Excel attachment program in SAP ABAP

Send Mail Excel attachment program in SAP ABAP.




DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE,

      lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE,

      lt_attachment      TYPE STANDARD TABLE OF solisti1  WITH HEADER LINE,

      lt_mailsubject     TYPE sodocchgi1,

      lt_packing_list    TYPE STANDARD TABLE OF sopcklsti1 WITH HEADER LINE,

      gv_cnt             TYPE i.


Add Recipients


lt_mailrecipients-rec_type  = 'U'.

lt_mailrecipients-com_type  = 'INT'.

lt_mailrecipients-RECEIVER  = 'someone@erpdb.info'.

APPEND lt_mailrecipients .

CLEAR lt_mailrecipients .


Put in the Mail Contents


lt_mailtxt = 'Hi How are you'.      APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Here is a test mail'. APPEND lt_mailtxt. CLEAR lt_mailtxt.

lt_mailtxt = 'Thanks'.              APPEND lt_mailtxt. CLEAR lt_mailtxt.


Create the attachment


  DATA: BEGIN OF lt_po_data_cons OCCURS 0,

         ebeln LIKE ekpo-ebeln,

         ebelp LIKE ekpo-ebelp,

        END OF lt_po_data_cons.


  SELECT ebeln ebelp INTO TABLE lt_po_data_cons

  UP TO 10 ROWS

  FROM ekpo. 


  CLASS cl_abap_char_utilities DEFINITION LOAD.

  CONCATENATE 'PO' 'PO Line'

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=&GT;horizontal_tab.

  APPEND lt_attachment. CLEAR lt_attachment.


  LOOP AT lt_po_data_cons.

  CONCATENATE lt_po_data_cons-ebeln lt_po_data_cons-ebelp

              INTO lt_attachment SEPARATED BY

              cl_abap_char_utilities=&GT;horizontal_tab.


  CONCATENATE cl_abap_char_utilities=&GT;newline lt_attachment

              INTO lt_attachment.


  APPEND lt_attachment. CLEAR lt_attachment.

 ENDLOOP.

Pack the mail contents and attachment

 lt_packing_list-transf_bin  = SPACE.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 0.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_mailtxt ).

  lt_packing_list-doc_type    = 'RAW'.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_packing_list-transf_bin  = 'X'.

  lt_packing_list-head_start  = 1.

  lt_packing_list-head_num    = 1.

  lt_packing_list-body_start  = 1.

  lt_packing_list-body_num    = LINES( lt_attachment ).

  lt_packing_list-doc_type    = 'XLS'. " You can give RAW incase if you want just a txt file.

  lt_packing_list-obj_name    = 'data.xls'.

  lt_packing_list-obj_descr   = 'data.xls'.

  lt_packing_list-doc_size    = lt_packing_list-body_num * 255.

  APPEND lt_packing_list. CLEAR lt_packing_list.


  lt_mailsubject-obj_name     = 'MAILATTCH'.

  lt_mailsubject-obj_langu    = sy-langu.

  lt_mailsubject-obj_descr    = 'You have got mail'.

  lt_mailsubject-sensitivty   = 'F'.

  gv_cnt = LINES( lt_attachment ).

  lt_mailsubject-doc_size     = ( gv_cnt - 1 ) * 255 + STRLEN(

  lt_attachment ).

Finally, send the mail out.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data              = lt_mailsubject

    TABLES

      packing_list               = lt_packing_list

      contents_bin               = lt_attachment

      contents_txt               = 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.

    SUBMIT rsconn01 WITH MODE = 'INT' AND RETURN.

  ENDIF.

Thursday, February 13, 2020

Total and Subtotal Report Example in SAP ABAP.


Total and Subtotal Program Example in SAP ABAP.



REPORT  ZREPORTS_TOTAL.

TABLES: ekko.
TYPE-POOLS: slis.
DATA: wa_fcat   TYPE lvc_s_fcat,
      it_fcat   TYPE lvc_t_fcat,
      wa_layout TYPE lvc_s_layo,
      wa_top    TYPE slis_listheader,
      it_top    TYPE slis_t_listheader.

TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
aedat TYPE ekko-aedat,
END OF ty_ekko.
DATA: wa_ekko TYPE ty_ekko,
      it_ekko TYPE TABLE OF ty_ekko.

TYPES: BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
END OF ty_ekpo.
DATA: wa_ekpo TYPE ty_ekpo,
      it_ekpo TYPE TABLE OF ty_ekpo.

TYPES: BEGIN OF ty_out,
ebeln TYPE char15,
ebelp TYPE char5,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
color TYPE char4,
bold  TYPE lvc_t_styl,
END OF ty_out.
DATA: wa_out TYPE ty_out,
      it_out TYPE TABLE OF ty_out.

INITIALIZATION.
SELECT-OPTIONS s_aedat FOR ekko-aedat.

START-OF-SELECTION.
PERFORM get_ekko.
PERFORM get_ekpo.

END-OF-SELECTION.
PERFORM prepare_output.
PERFORM field_catalog.
PERFORM alv_grid_display.

TOP-OF-PAGE.
PERFORM top_of_page.
*&---------------------------------------------------------------------*
*&      Form  GET_EKKO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekko .

SELECT ebeln aedat FROM ekko
INTO TABLE it_ekko
WHERE aedat IN s_aedat.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekpo .

IF it_ekko IS NOT INITIAL.
SELECT ebeln ebelp matnr werks menge meins
FROM ekpo INTO TABLE it_ekpo
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln
AND matnr NE ' '.

IF sy-subrc = 0.
SORT it_ekpo BY ebeln ebelp.
ENDIF.
ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  PREPARE_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM prepare_output .

DATA: lw_bold TYPE lvc_s_styl,
      lt_bold TYPE lvc_t_styl.

IF it_ekpo IS NOT INITIAL.
LOOP AT it_ekpo INTO wa_ekpo.
wa_out-ebeln = wa_ekpo-ebeln.
wa_out-ebelp = wa_ekpo-ebelp.
wa_out-matnr = wa_ekpo-matnr.
SHIFT wa_out-matnr LEFT DELETING LEADING '0'.
wa_out-werks = wa_ekpo-werks.
wa_out-menge = wa_ekpo-menge.
wa_out-meins = wa_ekpo-meins.
APPEND wa_out TO it_out.
CLEAR: wa_out.

AT END OF ebeln.
SUM.
wa_out-ebeln = 'SUB TOTAL'.
wa_out-menge = wa_ekpo-menge.
wa_out-color = 'C200'.
lw_bold-style = '00000121'.
INSERT lw_bold INTO lt_bold INDEX 1.
wa_out-bold = lt_bold.
FREE lt_bold.

APPEND wa_out TO it_out.
CLEAR: wa_out, lw_bold, wa_ekpo.
ENDAT.

AT LAST.
SUM.
wa_out-ebeln = 'GRAND TOTAL'.
wa_out-menge = wa_ekpo-menge.
wa_out-color = 'C210'.
lw_bold-style = '00000121'.
INSERT lw_bold INTO lt_bold INDEX 1.
wa_out-bold = lt_bold.
FREE lt_bold.

APPEND wa_out TO it_out.
CLEAR: wa_out, lw_bold, wa_ekpo.
ENDAT.
ENDLOOP.
ENDIF.

FREE it_ekpo.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM field_catalog .

DATA: lv_col TYPE i VALUE 0.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'EBELN'.
wa_fcat-reptext   = 'Purchase Order'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'EBELP'.
wa_fcat-reptext   = 'Item'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-reptext   = 'Material'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-reptext   = 'Plant'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'MENGE'.
wa_fcat-reptext   = 'Quantity'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col            = 1 + lv_col.
wa_fcat-col_pos   = lv_col.
wa_fcat-fieldname = 'MEINS'.
wa_fcat-reptext   = 'Unit'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_layout-zebra      = 'X'.
wa_layout-cwidth_opt = 'X'.
wa_layout-info_fname = 'COLOR'.
wa_layout-stylefname = 'BOLD'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_grid_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
  i_callback_program     = sy-repid
  i_callback_top_of_page = 'TOP_OF_PAGE'
  is_layout_lvc          = wa_layout
  it_fieldcat_lvc        = it_fcat
TABLES
  t_outtab               = it_out
EXCEPTIONS
  program_error          = 1
  OTHERS                 = 2.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page .

REFRESH it_top.

wa_top-typ  = 'H'.
wa_top-info = 'Purchasing List'.
APPEND wa_top TO it_top.
CLEAR wa_top.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
  it_list_commentary = it_top.

ENDFORM.

Hierarchical ALV in SAP ABAP Example.


How to display a hierarchical sequential list ALV in SAP ABAP.
 TYPES: BEGIN OF ty_swa,
                  expand,
                  carrid TYPE s_carr_id,
                  carrname TYPE s_carrname,
             END OF ty_swa.
TYPES: BEGIN OF ty_swad,
                     carrid TYPE s_carr_id,
                     connid TYPE s_conn_id,
                     countryfr TYPE land1,
                     countryto TYPE land1,
              END OF ty_swad.
DATA: lt_swa TYPE TABLE OF ty_swa.
DATA: lt_swad TYPE TABLE OF ty_swad.
DATA: ls_layt TYPE slis_layout_alv.
DATA: lt_fcat TYPE slis_t_fieldcat_alv.
DATA: ls_fcat TYPE LINE OF slis_t_fieldcat_alv.
DATA: ls_key TYPE slis_keyinfo_alv.
START-OF-SELECTION.

SELECT carrid carrname
FROM scarr
INTO CORRESPONDING FIELDS OF TABLE lt_swa.

CHECK lt_swa[] IS NOT INITIAL.

SELECT carrid connidcountryfr countryto FROM spfli
INTO CORRESPONDING FIELDS OF TABLE lt_swad
FOR ALL ENTRIES IN lt_swa
 WHERE carrid = lt_swa-carrid.

”Layout 
ls_layt-expand_fieldname = ‘EXPAND’.
ls_layt-colwidth_optimize = ‘X’.
”Keyinfo 
ls_key-header01 = ‘CARRID’.
ls_key-item01 = ‘CARRID’.
“Build Fieldcat
ls_fcat-col_pos = ‘1’.
ls_fcat-fieldname = ‘CARRID’.
ls_fcat-tabname = ‘LT_SWA’.
ls_fcat-key = ‘X’.
ls_fcat-seltext_m = ‘Flight ID’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-col_pos = ‘2’.
ls_fcat-fieldname = ‘CARRNAME’.
ls_fcat-tabname = ‘LT_SWA’.
ls_fcat-seltext_m = ‘Flight Conn’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-col_pos = ‘3’.
ls_fcat-fieldname = ‘CONNID’.
ls_fcat-tabname = ‘LT_SWAD’.
ls_fcat-seltext_m = ‘Conn Number’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-col_pos = ‘4’.
ls_fcat-fieldname = ‘COUNTRYFR’.
ls_fcat-tabname = ‘LT_SWAD’.
ls_fcat-seltext_m = ‘From Country’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-col_pos = ‘5’.
ls_fcat-fieldname = ‘COUNTRYTO’.
ls_fcat-tabname = ‘LT_SWAD’.
ls_fcat-seltext_m = ‘To Country’.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
CALL FUNCTION ‘REUSE_ALV_HIERSEQ_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-repid
is_layout = ls_layt
it_fieldcat = lt_fcat
i_tabname_header = ‘LT_SWA’
i_tabname_item = ‘LT_SWAD’
is_keyinfo = ls_key
TABLES
t_outtab_header = lt_SWA
t_outtab_item = lt_SWAD
EXCEPTIONS
program_error = 1
OTHERS = 2.

Wednesday, February 12, 2020

Editable alv with checkbox check option in SAP ABAP code

Editable alv with checkbox

*&---------------------------------------------------------------------*
*&  Include           ZMAN_EDITABLE_ALV_DD
*&---------------------------------------------------------------------*

TYPE-POOLS slis.
TABLES zman_emp_table.
DATAit_fieldcat            TYPE slis_t_fieldcat_alv.
DATAwa_fieldcat            LIKE LINE OF it_fieldcat.
DATAt_list_top_of_page     TYPE slis_t_listheader.
DATAit_events              TYPE slis_t_event WITH HEADER LINE.
DATAg_save                 TYPE c VALUE 'A'.
DATAgt_sort                TYPE slis_t_sortinfo_alv.
DATAgx_save                TYPE c VALUE 'A'.
DATAgx_variant             TYPE disvariant.
DATAg_variant              TYPE disvariant.
DATAgs_layout              TYPE slis_layout_alv.
DATAt_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
DATAt_i_event              TYPE slis_alv_event.
TYPES BEGIN OF ty_zman_emp_table,
                zman_emp_no             
TYPE zman_emp_no,
                zman_emp_name           
TYPE zman_emp_name,
                zman_emp_address        
TYPE zman_emp_address,
                zman_emp_blood_grp      
TYPE zman_emp_blood_grp,
                zman_emp_gender         
TYPE zman_emp_gender,
                zman_emp_email          
TYPE zman_emp_email,
                zman_emp_marital_status 
TYPE zman_emp_marital_status,
                zman_emp_expirence      
TYPE zman_emp_expirence,
                flag                    
TYPE flag,
        
END OF ty_zman_emp_table.
DATA it_ZMAN_EMP_TABLE TYPE STANDARD TABLE OF TY_zman_emp_table WITH HEADER LINE,
       wa_zman_emp_table 
TYPE ty_zman_emp_table.
DATAit_update TYPE TABLE OF ty_zman_emp_table,
      it_change 
TYPE TABLE OF ty_zman_emp_table.
DATAit_delete TYPE TABLE OF ty_zman_emp_table,
      it_change1 
TYPE TABLE OF ty_zman_emp_table.
DATAdefaultoption   TYPE string,  "header declaration
        
title           TYPE string,  "header title
        textline         
TYPE string"text line
        lv_popup_ans    
TYPE string,  "pop up
        cancel_display  
TYPE string.   "pop up
DATAit_listheader TYPE slis_t_listheader.
========================================================================
*                                     Selection Screen
========================================================================

*&---------------------------------------------------------------------*
*&  Include           ZMAN_EDITABLE_ALV_SS
*&---------------------------------------------------------------------*
SELECT-OPTIONSS_EMPID FOR IT_ZMAN_EMP_TABLE-ZMAN_EMP_NO.

========================================================================
*                                     LOGIC
========================================================================
*&---------------------------------------------------------------------*
*&  Include           ZMAN_EDITABLE_ALV_LOGIC
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_DATA .
SELECT
        ZMAN_EMP_NO
        ZMAN_EMP_NAME
        ZMAN_EMP_ADDRESS
        ZMAN_EMP_BLOOD_GRP
        ZMAN_EMP_GENDER
        ZMAN_EMP_EMAIL
        ZMAN_EMP_MARITAL_STATUS
        ZMAN_EMP_EXPIRENCE
        
FROM zman_emp_table INTO CORRESPONDING FIELDS OF TABLE it_zman_emp_table
        
WHERE ZMAN_EMP_NO IN s_empid.
endform.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  ALV_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form ALV_FIELDCAT .

  
DATAcounter TYPE i.
  counter 
counter + 1.

  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-fieldname  ='FLAG'.
  wa_fieldcat
-seltext_m  ='CHECKBOX'.
  wa_fieldcat
-edit       ='X'.
  wa_fieldcat
-checkbox    'X'.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_NO '.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Employee ID.'.
  wa_fieldcat
-col_pos    0.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_NAME  '.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Employee NAME.'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'.   "its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_ADDRESS'.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Address'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'.   "its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_BLOOD_GRP  '.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Blood Group'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'"its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_GENDER  '.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Gender'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'.  "its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_EMAIL'.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Email'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'.   "its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_MARITAL_STATUS'.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Marital Status'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'"its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.

  wa_fieldcat
-fieldname  'ZMAN_EMP_EXPIRENCE'.
  wa_fieldcat
-tabname    'IT_zman_emp_table'.
  wa_fieldcat
-seltext_l  'Expirence'.
  wa_fieldcat
-col_pos    0.
  wa_fieldcat
-edit        'X'.    "its for edditing field.
  
APPEND wa_fieldcat TO it_fieldcat.
  
CLEAR wa_fieldcat.
endform.                    " ALV_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  GET_EVENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_EVENT .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

   
EXPORTING
   I_LIST_TYPE           
0

  
IMPORTING
    ET_EVENTS             
IT_EVENTS[]

  
EXCEPTIONS
   LIST_TYPE_WRONG       
1
   
OTHERS                2
          
.
     
IF sy-subrc <> 0.
* Implement suitable error handling here
      
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      
ENDIF.

  
READ TABLE it_events WITH KEY name slis_ev_top_of_page
                                
INTO it_events.
  
IF sy-subrc 0.
    
MOVE t_formname_top_of_page TO it_events-form.
    
APPEND it_events.
  
ENDIF.
endform.                    " GET_EVENT
*&---------------------------------------------------------------------*
*&      Form  SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_T_LIST_TOP_OF_PAGE  text
*----------------------------------------------------------------------*
form SUB_COMMENT_BUILD  using p_t_list_top_of_page TYPE slis_t_listheader.

  
DATAls_line TYPE slis_listheader.
  
DATAwrk_name     TYPE string.

  wrk_name 
'Squirrel Softech Pvt. Ltd.'.

  
CLEAR ls_line.

  ls_line
-typ  'H'.
  ls_line
-info wrk_name.
  
APPEND ls_line TO t_list_top_of_page.

  ls_line
-typ  'H'.
  ls_line
-info 'Employee Detail'.
  
APPEND ls_line TO  p_t_list_top_of_page.
endform.                    " SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form TOP_OF_PAGE .
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  
EXPORTING
    I_LOGO                   
=  'SAPLOGO'
    it_list_commentary       
t_list_top_of_page.
*   I_END_OF_LIST_GRID       =
*   I_ALV_FORM               =
.
endform.                    " TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form ALV_DISPLAY .

 gs_layout
-zebra                'X'.
  gs_layout
-detail_popup         'X'.
  gs_layout
-detail_initial_lines 'X'.
  gs_layout
-colwidth_optimize    'X'.

  
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    
EXPORTING
      it_fieldcat              
it_fieldcat
      it_events                
it_events[]
      i_callback_program       
sy-repid
      is_layout                
gs_layout
      it_sort                  
gt_sort[]
      i_save                   
g_save
      is_variant               
gx_variant
      i_callback_pf_status_set 
'ZSTANDARD1'
      i_callback_user_command  
'USER_COMMAND' " Interactive command
    
TABLES
      t_outtab                 
IT_zman_emp_table[].
ENDFORM.                    " ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM zstandard1 USING rt_extab TYPE slis_t_extab.
  
SET PF-STATUS 'ZSTANDARD1'.
ENDFORM.                    "text
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->SELFIELD   text
*----------------------------------------------------------------------*
FORM user_command USING r_comm TYPE sy-ucomm
                           selfield 
TYPE slis_selfield.

  
DATAgd_repid LIKE sy-repid,
      ref_grid 
TYPE REF TO cl_gui_alv_grid.

  
IF ref_grid IS INITIAL.
    
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      
IMPORTING
        e_grid 
ref_grid.
  
ENDIF.
  
IF NOT ref_grid IS INITIAL.
    
CALL METHOD ref_grid->check_changed_data.
  
ENDIF.
  
DATA flag TYPE i VALUE 0.

  
CASE r_comm.
    
WHEN 'SELECT_ALL'.
      
LOOP AT it_zman_emp_table INTO wa_zman_emp_table.
        
IF wa_zman_emp_table-flag IS INITIAL.
          wa_zman_emp_table
-flag 'X'.
          
MODIFY it_zman_emp_table FROM wa_zman_emp_table.
          
CLEAR wa_zman_emp_table.
        
ENDIF.
      
ENDLOOP.
      selfield
-refresh 'X'.

    
WHEN 'DSELECT_AL'.
      
LOOP AT it_zman_emp_table INTO wa_zman_emp_table.
        
IF wa_zman_emp_table-flag IS NOT INITIAL.
          wa_zman_emp_table
-flag ''.
          
MODIFY it_zman_emp_table FROM wa_zman_emp_table.
          
CLEAR wa_zman_emp_table.
        
ENDIF.
      
ENDLOOP.
      selfield
-refresh 'X'.

    
WHEN 'UPDATE'.
   
READ TABLE it_zman_emp_table into wa_zman_emp_table with key FLAG 'X'.
   
if sy-subrc 0.

      
CALL FUNCTION 'POPUP_TO_CONFIRM'
        
EXPORTING
          
titlebar             ='MESSAGE'
          text_question         
='ARE YOU SURE YOU WANT TO UPDATE THIS DATA'
          text_button_1         
='YES'
          text_button_2         
='NO'
          default_button       
'1'
        display_cancel_button  
'X'
          popup_type           
'ICON MESSAGE INFORMATION'

        
IMPORTING
          answer   
lv_popup_ans.
      
IF sy-subrc <> 0.
      
ENDIF.
      
IF lv_popup_ans '1'.
        
LOOP AT it_zman_emp_table INTO wa_zman_emp_table WHERE flag 'X'.
          
PERFORM zman_emp_table_updatedata.         " update data
           
IF sy-subrc EQ 0.
        
message 'DATA  UPDATED SUCCESSFULLY' TYPE 'I'.
          
ENDIF.
        
ENDLOOP.
     
ELSE.
       
LEAVE SCREEN.
      
ENDIF.
      
else.
    
MESSAGE 'please select atleast one line item' type 'E'.
    
endif.

    
WHEN 'DELETE'.
    
READ TABLE it_zman_emp_table into wa_zman_emp_table with key flag 'X'.
     
if sy-subrc 0.

     
CALL FUNCTION 'POPUP_TO_CONFIRM'
        
EXPORTING
          
titlebar             ='MESSAGE'
          text_question         
='ARE YOU SURE YOU WANT TO DELETE DATA'
          text_button_1         
='YES'
          text_button_2         
='NO'
          default_button       
'1'
        display_cancel_button  
'X'
          popup_type           
'ICON MESSAGE INFORMATION'

     
IMPORTING
          answer   
lv_popup_ans.
      
IF sy-subrc <> 0.
      
ENDIF.
      
IF lv_popup_ans '1'.
        
LOOP AT it_zman_emp_table INTO wa_zman_emp_table WHERE flag 'X'.

     
PERFORM zman_emp_table_DATADELETE.            " DATA DELETE

     
select ZMAN_EMP_NO
        ZMAN_EMP_NAME
        ZMAN_EMP_ADDRESS
        ZMAN_EMP_BLOOD_GRP
        ZMAN_EMP_GENDER
        ZMAN_EMP_EMAIL
        ZMAN_EMP_MARITAL_STATUS
        ZMAN_EMP_EXPIRENCE
                              
from zman_emp_table
      
INTO CORRESPONDING FIELDS OF TABLE it_zman_emp_table.
       
modify it_zman_emp_table FROM wa_zman_emp_table.
        selfield
-refresh 'X'.
       
IF sy-subrc EQ 0.
        
message 'DATA DELETED SUCCESSFULLY' TYPE 'I'.
          
ENDIF.
        
ENDLOOP.
     
ELSE.
       
LEAVE SCREEN.
      
ENDIF.
      
else.
    
MESSAGE 'please select atleast one line item' type 'E'.
    
endif.

        
ENDCASE.
      
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  ZMAN_EMP_TABLE_UPDATEDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form ZMAN_EMP_TABLE_UPDATEDATA .

    
datawa_tzman_emp_table type zman_emp_table.
  
REFRESH it_change.
  
IF it_zman_emp_table[] IS NOT INITIAL.
    
LOOP AT it_zman_emp_table INTO wa_zman_emp_table WHERE flag 'X'.
        
MOVE-CORRESPONDING wa_zman_emp_table TO wa_tzman_emp_table.
        
MODIFY zman_emp_table FROM wa_tzman_emp_table.
    
ENDLOOP.
  
ENDIF.
endform.


*&---------------------------------------------------------------------*
*&      Form  ZMAN_EMP_TABLE_DATADELETE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form ZMAN_EMP_TABLE_DATADELETE .

     
datawa_delete type ty_zman_emp_table,
         wa_tzman_emp_table 
type zman_emp_table.
   
refresh it_change1.
   
if it_zman_emp_table[] is not INITIAL.
    
loop at it_zman_emp_table into wa_zman_emp_table where flag 'X'.
       
MOVE-CORRESPONDING wa_zman_emp_table TO wa_tzman_emp_table.
      
delete from zman_emp_table where ZMAN_EMP_NO wa_zman_emp_table-ZMAN_EMP_NO.
    
endloop.
    
clear wa_delete.
    
endif.

endform.                    " ZMAN_EMP_TABLE_DATADELETE                    " ZMAN_EMP_TABLE_UPDATEDATA