Search This Blog

Friday, August 12, 2011

Sample Code to Lock / Unlock Program Editor


Program to Lock / Unlock program editor. The SAP Standard Table TRDIR has a field called EDTX which is basically the EDITOR lock field. Edit Lock facility is given in the PROGRAM ATTRIBUTES. The EDITOR LOCK is a check box given in the PROGRAM ATTRIBUTES. If this field is SET then the program gets locked and if this is Unchecked the program is unlocked.


If the EDITOR lock is ON then only the user who created the program can edit it.
REPORT  ZXXXX.
TABLES : TRDIR.

PARAMETERS : PROG_NAM LIKE TRDIR-NAME,
             EDTX 
LIKE TRDIR-EDTX.

SELECT SINGLE * FROM TRDIR WHERE NAME = PROG_NAM.

  
IF SY-SUBRC = 0.
    
IF TRDIR-EDTX = EDTX AND EDTX = ' '.
      
MESSAGE 'Already Unlocked' TYPE 'I'.
    
ELSEIF TRDIR-EDTX = EDTX AND EDTX = 'X'.
      
MESSAGE 'Already Locked' TYPE 'I'.
    
ELSE.
    TRDIR-EDTX = EDTX.
    
MODIFY TRDIR.
        
IF EDTX = ' '.
          
MESSAGE 'Program Successfully Unlocked' TYPE 'I'.
        
ELSE.
          
MESSAGE 'Program Successfully Locked' TYPE 'I'.
        
ENDIF.

    
ENDIF.
  
ELSE.
    
MESSAGE 'Program Not Found' TYPE 'I'.
  
ENDIF.



Upload Excel File Data using BDC

Sample Program to Upload MS Excel File data into SAP R/3 Using BDC
report ZXXXX
       
no standard page heading line-size 255.

include bdcrecx1.
TABLES : ZEMP.
DATA : ITAB TYPE STANDARD TABLE OF ZEMP WITH HEADER LINE,
G_XLDATA 
LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: p_file LIKE ibipparms-path.
start-
of-selection.

*Function Module to fetch file from the presentation server
  
CALL FUNCTION 'F4_FILENAME'
    
EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 
'P_FILE'
    
IMPORTING
      file_name     = p_file.

*Function Module to upload excel file data to internal table
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  
EXPORTING
    FILENAME                      = p_file
    I_BEGIN_COL                   = 
1
    I_BEGIN_ROW                   = 
1
    I_END_COL                     = 
100
    I_END_ROW                     = 
100
  
TABLES
    INTERN                        = G_XLDATA
          .
LOOP AT G_XLDATA.
  
CASE G_XLDATA-COL.
    
WHEN 1.
      ITAB-EMPID = G_XLDATA-
VALUE.
    
WHEN 2.
      ITAB-EMPNAME = G_XLDATA-
VALUE.
    
WHEN 3.
      ITAB-STREET = G_XLDATA-
VALUE.
    
WHEN 4.
      ITAB-CITY = G_XLDATA-
VALUE.
      
APPEND ITAB.
      
CLEAR ITAB.
  
ENDCASE.
 
ENDLOOP.


perform open_group.

LOOP AT ITAB.

perform bdc_dynpro      using 'ZRSCREEN1' '0100'.
perform bdc_field       using 'BDC_OKCODE'
                              
'=INSERT'.
perform bdc_field       using 'BDC_CURSOR'
                              
'ZEMP-CITY'.
perform bdc_field       using 'ZEMP-EMPID'
                              ITAB-EMPID.
perform bdc_field       using 'ZEMP-EMPNAME'
                              ITAB-EMPNAME.
perform bdc_field       using 'ZEMP-STREET'
                              ITAB-STREET.
perform bdc_field       using 'ZEMP-CITY'
                              ITAB-CITY.
perform bdc_dynpro      using 'ZRSCREEN1' '0100'.
perform bdc_field       using 'BDC_OKCODE'
                              
'/ELOGOUT'.
perform bdc_field       using 'BDC_CURSOR'
                              
'ZEMP-EMPID'.
perform bdc_field       using 'ZEMP-EMPID'
                              
'11'.
perform bdc_field       using 'ZEMP-EMPNAME'
                              
'JAMES SAWYER'.
perform bdc_field       using 'ZEMP-STREET'
                              
'B-100'.
perform bdc_field       using 'ZEMP-CITY'
                              
'SECTOR-100'.
perform bdc_transaction using 'ZRSCREEN1'.

ENDLOOP.
perform close_group.