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

Thursday, February 6, 2020

How to call an OData service of a CDS view and also pass parameters and also including a date field?


Questions about SAP CDS Views.

How to call an OData service of a CDS view and also pass parameters and also including a date field?

ABAP CDS ODATA View with parameters bp_idp_date ,p_language:

























@AbapCatalog.sqlViewName: 'ZSD_CDSView'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'My Consumption CDS View'
@OData.publish: true
define view ZSD_CDS_View
    with parameters bp_id: bu_partner,
        @Environment.systemField: #SYSTEM_DATE
        p_date: dats,
        @Environment.systemField: #SYSTEM_LANGUAGE
        p_langu: spras
as select from ZI_CDS_View_Composite {   
     
    key partner1,
    partner2,
    date_to,
    reltyp,
    date_from,
    spras,
    bez50,
    bez50_2
     
} where partner1 = :bp_id
    and date_to >= :p_date
    and date_from <= :p_date
    and spras = :p_langu



ANOTATION: -@OData. Publish: true


You can call ODATA service this link
Link ODADA Service: /sap/opu/odata/sap/ZCDS_VIEW_SRV/ZC_CDS_View(bp_id='0123456789',p_date=datetime'2019-04-01T12:00',p_langu='E')/Set


Sunday, February 2, 2020

KE51 transaction how to make field (Address) required in SAP ABAP.


KE51 transaction how to make field (Address) required in SAP ABAP.
SAP does not provide any configuration and user exit to make fields in Address tab required in transaction KE51.After that debug ABAP Code, I found the way that you need to create enhancement point in include program LRKPMF05 in subroutine md_user_command_handle.

This example we want to make field Street, City, Country and Region is required when user click SAVE. Please check out this ABAP Code below.
FORM md_user_command_handle CHANGING p_fcode.
1) Form MD_USER_COMMAND_HANDLE, Start                                                                                                               
ENHANCEMENT 1  ZIMP_CO_REQUIRED_ADDR_KE51.    "active version
IF md_fcode = 'MD_SAVE'.

IF PRCT_V-STRAS EQ ''.
  MESSAGE 'You must input Street' TYPE 'E'.
ENDIF.


IF PRCT_V-ORT01 EQ ''.
 MESSAGE 'You must input Kota' TYPE 'E'.
ENDIF.

IF PRCT_V-LAND1 EQ ''.
 MESSAGE 'You must input Country' TYPE 'E'.
ENDIF.

IF PRCT_V-REGIO EQ ''.
 MESSAGE 'You must input Region' TYPE 'E'.
ENDIF.

ENDIF.
ENDENHANCEMENT.