Search This Blog

Tuesday, December 13, 2011

Simple steps to get Smartform output into PDF Format

Do the following:

  1. Print the smartform to the spool. 
  2. Note the spool number.
  3. Go to T-Code SE38 and execute the standard program  RSTXPDFT4 and download the PDF file by entering the spool number in the selection screen.

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.

Wednesday, June 22, 2011

Comparing Source Code of 2 different ABAP Programs

SAP provide a way to compare the source code of two different
objects, similar to what is available in Version Management. It is called the split screen editor. One can use transaction SE39 to compare 2 different ABAP programs. Can
also compare programs across systems as well using this transaction.

Wednesday, June 15, 2011

SAP ABAP Consultant At Tata Technologies

Location:

Experience:

Job Description:

Company Profile:

Monday, June 13, 2011

Coloring Individual Rows in ALV Grid

Sample ABAP Code for Coloring An Entire Row in ALV Grid.
Coloring a row is a bit complicated. To enable row coloring, you should add an additional field to your list data table ( internal table ). It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “t_ekko”.

Adding the field that will contain row color data:
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
  line_color(4) type c,     "Used to store row color attributes
 END OF t_ekko.

You should fill the color code to this field.
But how will ALV Grid know that you have loaded the color data
for the row to this field. So, you make it know this by passing
the name of the field containing color codes to the field 
“INFO_FIELDNAME” of the layout structure.

Example -
gd_layout-info_fieldname =      'LINE_COLOR'.




Sample Program :
Important lines to remember are highlighted.

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
  line_color(4) type c,     "Used to store row color attributes
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.
endform.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
* Set layout field for row attributes(i.e. color) 
  gd_layout-info_fieldname =      'LINE_COLOR'.
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
endform.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
*            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
*            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
*            IT_EVENTS                = GT_XEVENTS
            i_save                  = 'X'
*            is_variant              = z_template

       tables
            t_outtab                = it_ekko
       exceptions
            program_error           = 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.
endform.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.

*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
*           i.e. wa_ekko-line_color = 'C410'
  ld_color = ld_color + 1.

* Only 7 colours so need to reset color value
  if ld_color = 8.
    ld_color = 1.
  endif.
  concatenate 'C' ld_color '10' into wa_ekko-line_color.
 
*Instead of doing the above steps one can directly write the following statement:
*  wa_ekko-line_color = 'C410'. " This will give all the rows the same color.
  modify it_ekko from wa_ekko.
endloop.
endform.                    " DATA_RETRIEVAL
 
Output :
 

Sunday, June 12, 2011

Why is ALE used?

ALE (Application Link Enabling) provides for the integration of distributed applications.

Applications are distributed because of the following reasons :

  • System Performance:  The transaction load is too heavy for a single
    SAP system.
  • High Availability Requirements:  The Company cannot afford downtime due to backups, maintenance, upgrades, etc.
  • SAP Release Coordination:  Different units of the organization may require different releases of the SAP software.
  • Very Large Database:  Companies with very large databases may need to distribute the data across multiple SAP systems.
  • Business Structure:  Business units may require independence and autonomy for day-to-day operations, and yet still need to share some data and functionality with other units in the enterprise.
  • Interfacing with non-SAP systems:  The Company may wish to maintain certain applications on non-SAP systems, while at the same time integrate these applications and their data with the SAP system.
  • Keep development system data in sync with production data: An organization may wish to keep the data on a development system the same as on a production system.
  • Maintain configuration and master data across clients: Organizations using multiple clients may wish to maintain certain data on a client-independent basis.

ALE allows you to:
  • Distribute your applications across several SAP systems, such that centralized functions, as well as decentralized functions can operate in the same company arena.
  • Maintain and distribute master data elements from a central system, thus maintaining unique number ranges across several systems.
  • Maintain and distribute control data objects from a central system, thus synchronizing important configuration data. This is important when trying to decentralise functions, yet keep them integrated.
  • Couple R/2 and R/3 systems, in some instances
  • Couple SAP and external systems, via IDocs (Intermediate Documents) and an external translation mechanism.

Wednesday, June 8, 2011

LOOP AT SCREEN Statement | Modify Selection Screen at Run Time

Sample Code for modifying selection screen at user command :


PARAMETERS : CBOX AS CHECKBOX USER-COMMAND ACT DEFAULT ' ',
                            EBELN LIKE EKKO-EBELN MODIF ID R1.

 PARAMETERS: BLACK(10) MODIF ID A,
                            BLACK2(5) MODIF ID A,
                            WHITE1(2) MODIF ID B.

PARAMETERS: C RADIOBUTTON GROUP RAD1 USER-COMMAND ACT DEFAULT 'X',
                           D RADIOBUTTON GROUP RAD1.


AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.

IF CBOX = 'X'.
IF SCREEN-GROUP1 = 'R1'.
SCREEN-INPUT = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

LOOP AT SCREEN.
IF C = 'X'.
IF SCREEN-GROUP1 = 'B'.
SCREEN-INPUT = 0 .
ENDIF.
ELSEIF D = 'X'.
IF SCREEN-GROUP1 = 'A'.
SCREEN-INPUT = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.