Friday, June 25, 2010

Posting on Error message : Prebooking exists for personnel number

Perhaps you have faced this error when do the changes in PA records or OM integrations:

Scenario : While performing Employee cost center conversions by assiging to Postion/Org Units, I have faced the issue while doing the integrations from OM to PA

Reason:
This error is coming from the activation of switch PLOGI EVENB and PLOGI EVEGC. here is the functionality Setting the 'PLOGI EVENB' switch to 'X' enables you to move a person,position or organizational unit within an organizational structure, when these changes lead to a change in company code for the person(s) concerned.

The personnel numbers of the persons concerned are locked in PA. The only personnel action you can now carry out these personnel numbers is Organisational change. You must carryout this action before you can make further chagnes to the infotypes for the persons concerned .

Technically the lock what we are getting was caused by entry in the table T77INT.

Soluctions:
- Run the program RPLEVENT to create the actoin what it demands.
- To solve this problem, you should create a blank event reason for
personnel event '02'.
You can do in IMG -> Personnel Management -> Personnel Administration -
>Setting Up Procedures -> Actions -> Create Reasons for Personnel Actions

- Setting of PLOGI EVENB:
"Setting the 'PLOGI EVENB' switch to 'X' enables you to move a person, when position or organizational unit within an organizational structure, these changes lead to a change in company code for the person(s) concerned.
The personnel numbers of the person(s) concerned are locked in Personnel Administration. The only personnel action you can now carry out for these personnel numbers is "Organizational Change". You must carry out this action before you can make further changes to the infotypes for the person(s) concerned. Technically, the lock is caused by an entry in table T77INT.
Note that this switch only works when the 'PLOGI ORGA' switch is switched to 'X'."

Saturday, June 19, 2010

Debugging a RF calls, Remotely - Article from Saptechnical

Scenario:  
When I initially started working on Integration tools like Business Connector/.Net connectors/XI, I always wondered how to debug the process in the backend SAP R/3 system when I make a RFC call. Because when we call any SAP RFC function module from any integration tool, it will be processed on any available application server in the backend, where a user breakpoint can not be triggered to debug the ABAP code in the backend system. The situation becomes worst to the developers/testers when they want to test the scenarios like HTTP-XI-RFC, HTTP-XI-PROXY, and FTP-XI-RFC so on. But we have a simple solution to debug the ABAP code when we are working on Remote function calls.  
 
PRE-REQUISITE:  


  • The backend SAP system should be ECC 6.0 with latest patch updates.

  • It is assumed that user has developed a simple scenario HTTP-XI-PROXY/HTTP-XI-RFC or any similar scenario where XI makes a RFC or Proxy call to SAP R/3 system. 

  • When developing the scenario, in the integration directory configuration, while creating the Receiver communication channel with RFC adapter or Proxy Adapter user has to use own SAP R/3 user id / password as authentication parameters with which user wants to login to the SAP system to debug the code. i.e the same user id has to use to login the sap system to set the break-point in the ABAP Code.

 
SOLUTION:
Log in to the sap system where RFC function module or Proxy class implemented.  
Open the Function module/ Proxy class and set a break-point. It is not mandatory that break-point has to set only at the initial line of the code; user can set any where in the entire code, which will be executed on RFC call.  
Execute the transaction code “SRDEBUG” (Note: this tcode is available only in latest ECC 6.0 system)  
Click on the button Activate Debugging. A pop-up screen will be opened. Fill the User-ID with which break-point has been set. (The same user-id should be used as authentication data in the XI while creating RFC communication channel).  Select the radio buttons “all Appl. Servers” and “External breakpoints already set”. Click on OK.

Saturday, June 12, 2010

How to D-bug a background job

It is very simple,

1. select active job in sm37.
2. type "jdbg" command in command field. .
3. Double click the job , it will go in debug mode.

OR
1. Go to sm50 .
2. place the cursor on active job.
3. goto program mode--> program--> Debugging.

Demo Program for - Logical Database

REPORT ZChandeep_HR_prog_1
LINE-SIZE 200 .
****************************
*Database Table
****************************
TABLES: PERNR,           " Pernr structure for Logical database
       PA0001,           " Actions
       PA0002.           " Personnel Info
****************************
*Infotypes
****************************
INFOTYPES: 0001,         " Actions
           0002.         " personnel info
****************************
*Variable Declaration
****************************
DATA: FORM_NAM LIKE P0001-ENAME,
      V_AGE(5) TYPE C,       "variable for calculating age in days
      V_CTR1 TYPE I VALUE 0, "counter
      V_CTR2 TYPE I VALUE 0, "counter
      VAR(5) TYPE C ,        " variable to store btrtl
      VAR1(5) TYPE C  .      " variable to store werks
*****************************
*Internal Table Decalartion
*****************************
DATA: BEGIN OF I_TAB1 OCCURS 0,
       WERKS LIKE PA0001-WERKS,  "personnel area
       BTRTL LIKE PA0001-BTRTL,  "personnel sub area
       PERNR LIKE PA0001-PERNR,  "employee number
       ENAME LIKE PA0001-ENAME,  "employee name
       BEGDA LIKE PA0002-BEGDA,  "employee join date
       PERSG LIKE PA0001-PERSG,  "employee group
       PERSK LIKE PA0001-PERSK,  "employee sub-group
       PLANS LIKE PA0001-PLANS,  "position
       GBDAT LIKE P0002-GBDAT,   "date of birth
     END OF I_TAB1.
******************************
*START-OF-SELECTION
******************************
START-OF-SELECTION .
GET PERNR .                     
  RP-PROVIDE-FROM-LAST P0001 SPACE PN-BEGDA PN-ENDDA .   " Macro for IFT-0001
  RP-PROVIDE-FROM-LAST P0002 SPACE PN-BEGDA PN-ENDDA .   " Macro for IFT-0002
**--> Populate internal table
  MOVE P0001-WERKS TO I_TAB1-WERKS .
  MOVE P0001-BTRTL TO I_TAB1-BTRTL .
  MOVE P0001-PERNR TO I_TAB1-PERNR .
  MOVE P0001-ENAME TO I_TAB1-ENAME .
  MOVE P0002-BEGDA TO I_TAB1-BEGDA .
  MOVE P0001-PERSG TO I_TAB1-PERSG .
  MOVE P0001-PERSK TO I_TAB1-PERSK .
  MOVE P0001-PLANS TO I_TAB1-PLANS .
  MOVE P0002-GBDAT TO I_TAB1-GBDAT .
**--> Append data to internal table
  APPEND I_TAB1 .
  CLEAR I_TAB1 .                                       " Clear header I_TAB1
******************************
*END-OF-SELECTION
******************************
END-OF-SELECTION.
*****sorting the internal table on Personnel Area & Personnel Sub-Area
  SORT I_TAB1 BY WERKS BTRTL.
******************************
*TOP_OF_PAGE
******************************
  PERFORM TOP_OF_PAGE.
******************************
*Output Display
******************************
  LOOP AT I_TAB1.
*for calculating the age in days
    V_AGE = SY-DATUM - I_TAB1-GBDAT.
*control break on Personal Sub Area
    AT NEW BTRTL .
      IF SY-TABIX NE 1.
        FORMAT COLOR COL_NORMAL ON.
        WRITE:/5 'Total Number of Employees for personnel Sub-Area:',
        VAR  , 'is ',
        V_CTR1.
        CLEAR V_CTR1.
        FORMAT COLOR OFF.
      ENDIF.
    ENDAT .
**Control Break on personnel Area
    AT NEW WERKS.
      IF SY-TABIX NE 1.
        FORMAT COLOR COL_TOTAL ON.
        WRITE:/5 'Total Number of Employees for Personal Area: ',
         VAR1 ,'is    ', V_CTR2. "color col_total.
        CLEAR V_CTR2.
        SKIP 1.
        FORMAT COLOR OFF.
      ENDIF.
    ENDAT .
    WRITE:/5 I_TAB1-PERNR,   "personnel number
          16 I_TAB1-ENAME,   "emp name
          47 I_TAB1-BEGDA,   "join date
          60  V_AGE,         "age in days
          74  I_TAB1-WERKS,  "P area
          84  I_TAB1-BTRTL,  "P sub Area
          94  I_TAB1-PERSG,  "emp group
          104  I_TAB1-PERSK, "emp sub group
          114  I_TAB1-PLANS. "position
    V_CTR1 = V_CTR1 + 1.
    V_CTR2 = V_CTR2 + 1.
    VAR = I_TAB1-BTRTL .
    VAR1 = I_TAB1-WERKS .
  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       Header Output
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
  FORMAT COLOR COL_HEADING ON.
  WRITE:/5 'Employee',
        16 'Employee',
        47 'Join Date',
        62 'Age',
        74 'Personal',
        84 'Personal',
        94 'Employee',
        104 'Employee',
        114 'Position ',
      /5 'Number',
      16 'Name',
      60 '(In Days)',
      74 'Area',
      84 'Sub-Area',
      94 'Group',
      104 'Sub-Group'.
  FORMAT COLOR OFF.
  SKIP 1.
ENDFORM.                    " top_of_page
Following is the output:

How execute unathorised transactions?




Just user the below transaction in SE37 and pass the T-code what ever you want to execute.

TRANSACTION_CALL_VIA_RFC
To execute some unauthorized transactions.


Function Modules for creating programs (Useful when you are generating programs)
RS_PROGRAM_CHECK_NAME - To check program names if you are generating them.
RS_CORR_INSERT - To insert the correction request in the repository.
REPS_OBJECT_ACTIVATE - To activate repository objects, for example - to activate a newly generated program.
RS_DELETE_PROGRAM - To delete the program.
RS_ACCESS_PERMISSION - To lock or unlock a program.

Function modules for Amount and Currency

CURRENCY_AMOUNT_SAP_TO_IDOC Convert currency to IDOC format
CLOI_PUT_SIGN_IN_FRONT Move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all character fields), not right justifed as numbers normally are.
CONVERT_TO_FOREIGN_CURRENCY Convert local currency to foreign currency.
CONVERT_TO_LOCAL_CURRENCY Convert from foreign currency to local currency
CONVERT_AMOUNT_TO_CURRENCY Convert an amount from a currency to another (exchange rate taken from database tables)
CONVERT_CURRENCY_BY_RATE Convert an amount from a currency to another, according to the passed exchange rate
BAPI_CURRENCY_CONV_TO_EXTERNAL Conversion of Currency Amounts into External Data Format
BAPI_CURRENCY_CONV_TO_INTERNAL Conversion of Currency Amounts into Internal Data Format
CALCULATE_TAX_FROM_NET_AMOUNT  
SPELL_AMOUNT to get Amount in words
HR_IN_CHG_INR_WRDS Changes INR amount to words.

How to send emails from SAP by using the Function Modules

Sending External email through SAP
What is the FM for sending the external email through SAP by attaching layout set  to it?
These are the FM for sending external email :-
SO_DOCUMENT_SEND_API1 
SAPoffice: Send new document with attachments via RFC 
SO_NEW_DOCUMENT_ATT_SEND_API1
(In 4.6C only, You can go to SE37 and click the documentation on how to use it. A sample program is provided there.)
SAPoffice: Send new document with attachments via RFC 
Note : If you are using FM SO_NEW_DOCUMENT_ATT_SEND_API1 then Export Parameter DOCUMENT_DATA-OBJ_DESCR contains the Subject. 
SO_NEW_DOCUMENT_SEND_API1 
SAPoffice: Send new document 


Sample Program :

REPORT ZREPORT_TO_EMAIL NO STANDARD PAGE HEADING .
DATA : BEGIN OF ITAB OCCURS 0,
PERNR LIKE PA0001-PERNR,
ENAME LIKE PA0001-BUKRS,
END OF ITAB.
DATA: body_message  LIKE soli OCCURS 5 WITH HEADER LINE,
receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,
packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,
listobject LIKE abaplist OCCURS 10,
compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,
w_object_hd_change LIKE sood1,
compressed_size LIKE sy-index.

START-OF-SELECTION.
SELECT PERNR BUKRS
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM PA0001
WHERE PERNR < 5.
LOOP AT ITAB.
WRITE :/02 SY-VLINE , ITAB-PERNR, 10 SY-VLINE , ITAB-bukrs, 50
SY-VLINE.
ENDLOOP.
 
* Receivers
receiver_list-recextnam = 'Giridhar_External@gmail.com'. "-->
* EMAIL ADDRESS
RECEIVER_list-RECESC = 'E'. "<-
RECEIVER_list-SNDART = 'INT'."<-
RECEIVER_list-SNDPRI = '1'."<-
APPEND receiver_list.
* General data
w_object_hd_change-objla = sy-langu.
w_object_hd_change-objnam = 'Object name'.
w_object_hd_change-objsns = 'P'.
* Mail subject
w_object_hd_change-objdes = 'Message subject'.
* Mail body
APPEND 'Message content' TO message_content.
* Attachment
CALL FUNCTION 'SAVE_LIST'
EXPORTING
list_index = '0'
TABLES
listobject = listobject.
CALL FUNCTION 'TABLE_COMPRESS'
IMPORTING
compressed_size = compressed_size
TABLES
in = listobject
out = compressed_attachment.
DESCRIBE TABLE compressed_attachment.
CLEAR packing_list.
packing_list-transf_bin = 'X'.
packing_list-head_start = 0.
packing_list-head_num = 0.
packing_list-body_start = 1.
packing_list-body_num = sy-tfill.
packing_list-objtp = 'ALI'.
packing_list-objnam = 'Object name'.
packing_list-objdes = 'Attachment description'.
packing_list-objlen = compressed_size.
APPEND packing_list.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = w_object_hd_change
object_type = 'RAW'
owner = sy-uname
TABLES
objcont = message_content
receivers = receiver_list
packing_list = packing_list
att_cont = compressed_attachment.

Good article about common problem in ALV while running a program in background

Purpose: This document details about the common problem faced by many consultants: “Fatal Error - GUI cannot be reached” in ALV Grid Control.
 SAP® has provided us with some demo programs on ALV. We would use one of them in our scenario. BCALV_GRID_DEMO is the demo program provided by SAP® for ALV Grid Control. When you execute the program in foreground, you get the similar following output:
  Untitled Attachment
When you schedule the same program in background, your job is cancelled due to an error. Screenshot of the same is shown below:
Untitled Attachment 
Reason:
ALV Grid control is based on the custom controls on the screen. When the program is scheduled in background, it tries to create GUI related front-end objects and hence the error “Fatal Error - GUI cannot be reached”. This type of problem is common with all the programs that use the ALV grid control to display the output. 
Untitled Attachment Untitled AttachmentSolution:
Whenever we execute this type of programs in background, we should be passing a blank docking container instead of the custom container as parent to our grid control. 
The docking container doesn’t need any of the custom controls on the screen; instead it attaches an area to any or all of the four edges of the screen (top, left, right or bottom). The behavior of the areas in the container is determined by the sequence in which they are initialized. Docking Containers are attached to the screen from the inside out. This means that when you create a second container, it is attached to the edge of the screen, and the container that was already there is pushed outwards. 
Let us modify the standard program (by taking a copy of it) to enable it to execute it in background.
Following modifications have to be made:
·        Define a docking container in the program
    data: or_doc  type ref to cl_gui_docking_container .
·        At the time of creating a custom container, check if the program is being executed in background or foreground. If the program is scheduled in background, then create a docking container instead of custom container.
    if cl_gui_alv_grid=>offline( ) is initial.     create object or_custom_container            exporting container_name = c_container.   create object or_grid          exporting i_parent = or_custom_container. else . create object or_grid          exporting i_parent = or_doc .
      endif . 
Now test executing the program in background. The report would be generated

Useful Funciton modules for Amount and Currency

CURRENCY_AMOUNT_SAP_TO_IDOC Convert currency to IDOC format
CLOI_PUT_SIGN_IN_FRONT Move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all character fields), not right justifed as numbers normally are.
CONVERT_TO_FOREIGN_CURRENCY Convert local currency to foreign currency.
CONVERT_TO_LOCAL_CURRENCY Convert from foreign currency to local currency
CONVERT_AMOUNT_TO_CURRENCY Convert an amount from a currency to another (exchange rate taken from database tables)
CONVERT_CURRENCY_BY_RATE Convert an amount from a currency to another, according to the passed exchange rate
BAPI_CURRENCY_CONV_TO_EXTERNAL Conversion of Currency Amounts into External Data Format
BAPI_CURRENCY_CONV_TO_INTERNAL Conversion of Currency Amounts into Internal Data Format
CALCULATE_TAX_FROM_NET_AMOUNT
SPELL_AMOUNT to get Amount in words
HR_IN_CHG_INR_WRDS Changes INR amount to words.

Popup for dates, Holidays and Factory Calendar

F4_DATE Displays a popup dialog to choose date
POPUP_TO_SELECT_MONTH Display a pop-up to select a month 

HOLIDAY_GET Gives holidays for a country.It has two flags Freeday(for weekends)and Holiday(for public holidays).
FACTORYDATE_CONVERT_TO_DATE returns the calendar date for the factory date and the factory calendar passed
DATE_CONVERT_TO_FACTORYDATE returns the factory date for the date and factory calendar passed
 
    

Function Modules related to Date and Time Calculations

CALCULATE_DATE Calculates the future date based on the input .
DATE_TO_DAY Returns the Day for the entered date. 
DATE_COMPUTE_DAY Returns weekday for a date
DATE_GET_WEEK Returns week for a date
RP_CALC_DATE_IN_INTERVAL Add days / months to a date
DAY_ATTRIBUTES_GET Returns attributes for a range of dates specified
MONTHS_BETWEEN_TWO_DATES To get the number of months between the two dates.
END_OF_MONTH_DETERMINE_2 Determines the End of a Month.
HR_HK_DIFF_BT_2_DATES Find the difference between two dates in years, months and days.
FIMA_DAYS_AND_MONTHS_AND_YEARS Find the difference between two dates in years, months and days.
MONTH_NAMES_GET Get the names of the month
WEEK_GET_FIRST_DAY Get the first day of the week
HRGPBS_HESA_DATE_FORMAT Format the date in dd/mm/yyyy format
SD_CALC_DURATION_FROM_DATETIME Find the difference between two date/time and report the difference in hours
L_MC_TIME_DIFFERENCE Find the time difference between two date/time
HR_99S_INTERVAL_BETWEEN_DATES Difference between two dates in days, weeks, months
LAST_DAY_OF_MONTHS Returns the last day of the month
DATE_CHECK_PLAUSIBILITY Check for the invalid date.
DATE_2D_TO_4D_CONVERSION Year entry: 2-character to  4-character.
DAY_IN_WEEK Input date and will give the name of the day 1-monday,2-Tuesday....
SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates