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.

Saturday, July 30, 2011

Download Smartform Output in PDF Format

SAP Smart Forms are used to create and maintain forms for mass printing in SAP Systems. As an output
medium SAP Smart Forms support a printer, a fax, e-mail. Many a times there is requirement to download
output of SAP Smart Forms in a PDF file.
Adobe® Portable Document Format (PDF) is a universal file format that contains all fonts, formats, and graphics. PDF files are widely used in the Internet, not least because the content of a PDF file cannot be changed, in contrast to Word.
Smart Forms does not support direct output in PDF format. Instead, the OTF output has to be converted to PDF. Fonts and code pages used have to be correct in the OTF output and are dependent on the language in which the form is printed. Depending on the language, a different device type that supports the corresponding fonts has to be used for printing.
A device type for printing PDF or for creating a PDF file is therefore not adequate for a Smart Form that is used as a template for printing forms in a number of languages. The device type has to be set dynamically before the Smart Forms function module is called.

Converting the smartform to PDF is process of 3 simple steps.
  • Calling the Smart form, then it returns the OTF data in Return.
  • Converting the OTF data into required format using the Function Module CONVERT_OTF_2_PDF.
  • Download the File

1. Call function module SSF_FUNCTION_MODULE_NAME. It returns the name of the generated function module. Call the generated function module.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  EXPORTING
    FORMNAME                 = 'SMARTFORM-NAME'
  IMPORTING
   
FM_NAME                  = FMNAME .

2. To get a device type suitable for the current language, call the function module SSF_GET_DEVICE_TYPE.

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
  EXPORTING
    I_LANGUAGE                   = 'E'
  IMPORTING
   E_DEVTYPE                    = v_e_devtype  .




3. Call Smartform

CALL
 FUNCTION FMNAME
 EXPORTING
   CONTROL_PARAMETERS         = st_control_parameters
   OUTPUT_OPTIONS             = st_output_options
  IMPORTING
   DOCUMENT_OUTPUT_INFO       = st_document_output_info
   JOB_OUTPUT_INFO            = st_job_output_info
   JOB_OUTPUT_OPTIONS         = st_job_output_options
  TABLES
    ITAB                       = ITAB
    ITAB1                      = ITAB1     .


4. Call the function module 'CONVERT_OTF_2_PDF' to convert the smart form to PDF format. The function module returns the size of downloaded file.

CALL FUNCTION 'CONVERT_OTF_2_PDF'
  IMPORTING
   BIN_FILESIZE                 = v_bin_filesize
  TABLES
    OTF                          = st_job_output_info-otfdata
    DOCTAB_ARCHIVE               = it_docs
    LINES                        = it_lines    .


5. You can then store the PDF output using the function module GUI_DOWNLOAD, for example, as a local file on your PC.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
   BIN_FILESIZE                    = v_bin_filesize
   FILENAME                       = 'SMART'
   FILETYPE                        = 'BIN'
  TABLES
    DATA_TAB                        = it_lines
          .





Tuesday, July 26, 2011

SAP Client Copy By Using SCC8 and SCC7

Client Copy can be done either using the remote client copy method or export/import method.

To do Remote client copy you need to use tcode  scc9
For Client export & Import  we use scc8 and scc7
For Export / Import:
   
Client Export:
1.  Run SCC8
2.  Select Profile for desired copy type (Usually All [SAP_ALL] or user master only [SAP_USER].  You will need direction from the requester as to the correct selection here.  Use Profile -> Display Profile to display profile details.)
3.  Select target System (or group)
4.  De- Select "Test Run" (If selected)
5.  Run Export
-  Up to 3 requests are created, depending on the data selected and available:
   1. "SIDKO00353" for transporting client-independent data, if you have selected this 
   2. "SIDKT00353" for transporting client-specific data 
   3. "SIDKX00353" for transporting client-specific texts, provided texts are available in this client            
6.Monitor TP logs for errors and export files for growth                            
   
Client Import:
1. Create client (scc4)
2. Login to client (sap* - pass)
3. Manually add "O" transport then "X" then "T" to TMS buffer
4. Highlight #1 and use "Request -> Import" to launch import tool
5. Monitor "I" file in OS "/usr/sap/trans/tmp" dir for progress info
6. After Import is complete perform "post processing steps" from client tool (SCC7)
   
For Local or Remote Copy:
   
Client Import:
1. Create client (scc4)
2. Login to new client (sap* - pass)
3. Run SCCL (Local copy ) or SCC9 (remote copy) and complete the form as required
    -  Select Profile for desired copy type (Usually All [SAP_ALL] or user master only [SAP_USER].  You will need direction from the requester as to the correct selection here.  Use Profile -> Display Profile to display profile details.)
    -  Select RFC Destination to copy from for Remote copy, or Source client to copy from for Local copies
    -  Execute in background
4.       Monitor SCC3 for copy status
5.       After Import is complete perform "post processing steps" from menu in client tool (SCC7)
  
Post Client Create Checks:
-  Adjust client settings as Dev / Config / or Closed as directed by requester.
-  Update Logon Screen for new / updated client info

Friday, July 22, 2011

Difference between ABAP and HR ABAP

The followings points distinguishes HR ABAP from ABAP :

1)  Use of Infotypes
2)  The use of Logical Database
3)  Use of Macros and Provide statement
4)  Storage and Access of data
5)  Authorization checks
 
There is not much difference between abap and hr abap. The way the data is retrieved from the database is different.
In general ABAP data is stored in Tables, but coming to HR ABAP employee data is sorted through Infotypes. The way we retrieve the data from infotypes is different in hr abap.
In general ABAP we use Logical data base very rare, as in HR ABAP most of the programs use Logical Database to select data from Infotypes by using Get event.
In ABAP we use read statement to read particular record, still in HR ABAP we do use read statement apart from that we have Macros and provide statement.
Macro is pre defined code (like function module) which reads data from internal table (internal infotype) based on dates.
Provide statement is like Select statement but selects data from internal table
Storage and access of data in hr abap is completely different in hr abap compared to ABAP. We use transaction code PA20 and PA30 to maintain data in infotypes.
PA20 is display mode and PA30 is change mode. We can create, change, display, copy, and delete in infotypes with PA30 transaction.
For Infotypes authorizations can be maintained infotype and subtype (field) level as HR data is more sensitive and secrete.

Friday, July 8, 2011

'Reference Field Unknown in the Form' Smartform Error

For currency and quantity fields in smartform, their Reference fields needs to be specified in the Global Definitions ==> Currency/Quantity Fields Tab..

Here, give the internal table and field which is a currency/quantity and next to it give the standard table and field name.

Friday, July 1, 2011

Difference between User-Exit & Customer-Exit

1. USER EXITS are FORMS (subroutines) and are called 
by SAP standard programs using PERFORM. 

CUSTOMER EXITS are FUNCTIONS so they are called using CALL
FUNCTION (or more exactly CALL CUSTOMER FUNCTION).

2. Inside the form (user exit) you can read and change almost
any global data from host program. 
Inside a function (customer exit) you can only access your
import/export/changing/tables parameters.

3. User exits are more flexible because you have more
information to use in your code but on the other hand , it
is very easy to manipulate erroneously global data and lead
the standard program to a dump or even to make database
inconsistent.
Customer exits are more restrictive but you are sure any
change you can make to any parameters will never lead to
inconsistency

4. User-exit does not have any classification. 
In customer-exit we have function-module exit , screen exit
, menu exit.

5. While changing User-exit, Access Key is required (There 
are other enhancement options available now which does not 
necessarily require the object to be registered for access 
key), whereas in Customer-exit no access key is needed.