Friday, December 23, 2011

Function module to insert infotype


HR_INFOTYPE_OPERATION can be used for all the operation on infotypes.  Recently with the decoupled infotypes being introduced there were some instances where the program would give a dump when HR_INSERT_INFOTYPE_OPERATION is used.  (The dump would be something like  CL_HRPA_INFOTYPE_FACTORY======CP ....).

 There are two ways to avoid this dump -
  1)  If its a report then use the following statement in the report -

              LOAD-OF-PROGRAM.
              PERFORM do_nothing(sapfp50p).

 2) Use HR_ECM_INSERT_INFOTYPE.

     Sample code --

     Data: lref_msg TYPE REF TO cl_hrpa_message_list,
              lv_ok TYPE boole_d,
              lt_msg TYPE hrpad_message_tab.

      .....
      .....
     ASSIGN ls_pxxxx TO <record>..

     IF <record> is assigned.

           CREATE OBJECT lref_msg.
           CALL FUNCTION 'HR_ECM_INSERT_INFOTYPE'
           EXPORTING
                  pnnnn           = <record>
                  "no_auth_check   = 'X'
                  message_handler = lref_msg
           IMPORTING
                  is_ok           = lv_ok.

           CALL FUNCTION 'HR_ECM_FLUSH_INFOTYPE'
           EXPORTING
                  nocommit        = ''
                  message_handler = lref_msg
           IMPORTING
                  is_ok           = lv_ok.

          TRY.
              CALL METHOD lref_msg->get_message_list
                     IMPORTING
                            messages = lt_msg.
                     CATCH cx_hrpa_violated_assertion .
           ENDTRY.
    ENDIF.

SELECT-OPTIONS to show only single selection


Sample form to suppress tabs in select-option.............

FORM initialization .
  PERFORM selopt_no_interv.
ENDFORM.                    " initialization

*&---------------------------------------------------------------------*
*&      Form  selopt_no_interv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM selopt_no_interv.

  DATA: restriction TYPE sscr_restrict,
        w_opt_list TYPE sscr_opt_list,
        w_ass_tab TYPE sscr_ass.

  w_opt_list-name = 'OBJECTKEY1'.
  w_opt_list-options-eq = 'X'.
  APPEND w_opt_list TO restriction-opt_list_tab.
  w_ass_tab-kind = 'S'.
  w_ass_tab-name = 'CUSOBJ'.
  w_ass_tab-sg_main = 'I'.
  w_ass_tab-sg_addy = ' '.
  w_ass_tab-op_main = 'OBJECTKEY1'.
*  w_ass_tab-op_addy = 'OBJECTKEY1'.
  APPEND w_ass_tab TO restriction-ass_tab.

  w_opt_list-name = 'OBJECTKEY2'.
  w_opt_list-options-eq = 'X'.
  APPEND w_opt_list TO restriction-opt_list_tab.
  w_ass_tab-kind = 'S'.
  w_ass_tab-name = 'EMAILS'.
  w_ass_tab-sg_main = 'I'.
  w_ass_tab-sg_addy = ' '.
  w_ass_tab-op_main = 'OBJECTKEY2'.
*  w_ass_tab-op_addy = 'OBJECTKEY2'.
  APPEND w_ass_tab TO restriction-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
      EXPORTING
*         PROGRAM                =
           restriction            = restriction
*         DB                     = ' '
EXCEPTIONS
      too_late               = 0
      repeated               = 0
      selopt_without_options = 0
      selopt_without_signs   = 0
      invalid_sign           = 0
      empty_option_list      = 0
      invalid_kind           = 0
      repeated_kind_a        = 0
      OTHERS                 = 0.
ENDFORM.                               " SELOPT_NO_INTERV

Send Email from ABAP

Sample form to send email from ABAP using BCS method

FORM sub_send_mail.
DATA: l_message TYPE soli_tab,
l_send_result TYPE c,
l_cnt TYPE i,
l_doc_len TYPE so_obj_len,
l_subject(50) TYPE c,
l_email_body TYPE soli,
lo_sender TYPE REF TO cl_sapuser_bcs,
lo_receiver TYPE REF TO if_recipient_bcs,
lo_email TYPE REF TO cl_bcs,
lo_email_body TYPE REF TO cl_document_bcs,
lx_exception TYPE REF TO cx_bcs,


l_email_id TYPE ad_smtpadr.

* Fill the Subject Text


l_subject = 'Subject Line'.
REFRESH: l_message.
CLEAR: l_email_body.
l_email_body = '<html>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '<body>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '<p style="FONT-FAMILY: arial; FONT-SIZE: 12px">'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.


CONCATENATE 'Vamsi wants to send an email'
'using BCS'
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '<br/>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '<br/>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
CONCATENATE 'Second Line'
'</p>'
INTO l_email_body SEPARATED BY space.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '</body>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.
l_email_body = '</html>'.
APPEND l_email_body TO l_message.

CLEAR: l_email_body.

TRY.
lo_email = cl_bcs=>create_persistent( ).

* Get the length of the line
CLEAR l_cnt.
DESCRIBE TABLE l_message LINES l_cnt.
READ TABLE l_message INTO l_email_body INDEX l_cnt.
l_doc_len = ( l_cnt - 1 ) * 255 + STRLEN( l_email_body ).

lo_email_body = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = l_message
i_length = l_doc_len
i_subject = l_subject
i_language = sy-langu ).

lo_email->set_document( lo_email_body ).
* Sender - System User
lo_sender = cl_sapuser_bcs=>create( sy-uname ). "Use WF-BATCH for workflow batch
lo_email->set_sender( i_sender = lo_sender ).



lo_email->set_status_attributes( i_requested_status = 'E' ). "needed to avoid read receipts.

* Receiver Employee Email ID
l_email_id = 'receiver@abc.com'.
lo_receiver =
cl_cam_address_bcs=>create_internet_address( l_email_id ).
lo_email->add_recipient( i_recipient = lo_receiver
i_express = abap_true ).

lo_email->set_send_immediately( abap_true ).



lo_email->send( EXPORTING
i_with_error_screen = gc_checked
RECEIVING
result = l_send_result ).

IF l_send_result = abap_true.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ENDIF.
CATCH cx_bcs INTO lx_exception.

ENDTRY.

ENDFORM. " SEND_EMAIL

Wednesday, February 2, 2011

HR INFOTYPES

Payroll

0008 - Basic Pay

0009 - Bank Details

0014 - Recurring Payments and deductions

0015 - Additional Payments

0207 - Resident Tax Area

0208 - Work Tax Area

0209 - Unemployment Insurance

0210 - W4

0211 - COBRA Beneficiaries

0212 - COBRA Health Plans


Benefits

0021 - Family

0022 - Education

0378 - Benefits Adjustment Reasons


167 - Medical Plans

168 - Insurance Plans

169 - Savings plans

170 - Flexible Spending Accounts

171 - General Benefits information


Time Infotypes

2001 - Absences

2002 - Attendances

2006 - Absence Quota

2007 - Attendance Quota

2010 - Employee Remuneration




Tuesday, February 1, 2011

Utility Programs

Program to search strings in ABAP - RPR_ABAP_SOURCE_SCAN

Transactions

SE78 - Upload Graphics (Logo) into Smartforms or Scripts
SCC1 - Client Copy
QISRSCENARIO - ISR PCR Scenario
SWI1 - Workflow Scenario
SWO1 - Business Workflow (ZBUS7051 for HR Workflow)
ALRTCATDEF_SEL - Alert Category Defnition
ALRTDISP - Alerts display
IQS23 - Notification to Workflow
SICF - Activation of Web Components
PU01 - Delete Current payroll results
PPOME - Org Structure
PE02 - Personnel Calculation Rule
PE03 - Feature
RHCDOC_DISPLAY - OM CHANGES
SOST - Emails

SO10 - Text Module - Better maintenance for Translation/ SAP Script Text Elements can be maintained here.

Monday, January 31, 2011

Drill Down Report

Few Pointers -
HIDE - The values to be passed into the next level should be put in this statement.
SY-LSIND - The level of the list that is being displayed
You can drill down to 20 levels.

Sample Report -
tables: kna1, vbak, vbap.
select-options: s_kunnr for kna1-kunnr.
data: begin of itab occurs 0,kunnr like kna1-kunnr,name like kna1-name1,end of itab.
data: begin of jtab occurs 0,vbeln like vbak-vbeln,netwr like vbak-netwr,end of jtab.
data: begin of ktab occurs 0,posnr like vbap-posnr,matnr like vbap-matnr,end of ktab.
data: v_fnam(10), v_fval(10).
start-of-selection.
select kunnr name1 from kna1 into table itab where kunnr in s_kunnr.
loop at itab.write:/ itab-kunnr hotspot, itab-name.hide itab-kunnr.endloop.
at line-selection.
case sy-lsind.
when 1.select vbeln netwr from vbak into table jtab where kunnr = itab-kunnr.
loop at jtab.write:/ jtab-vbeln hotspot, jtab-netwr.hide jtab-vbeln.endloop.
when 2.
select posnr matnr from vbap into table ktab where vbeln = jtab-vbeln.
loop at ktab.write:/ ktab-posnr, ktab-matnr hotspot.endloop.
when 3.get cursor field v_fnam value v_fval.set parameter id 'MAT' field v_fval.call transaction 'MM02'.
endcase.
top-of-page.write:/ 'Custom Deatils Report'.
top-of-page during line-selection.
case sy-lsind.
when 1.write:/ 'Sales Details Report'.
when 2.write:/ 'Item Details Report'.
endcase.

Events in Reports

Classical Reports generates the Basic List and Interactive reports generates the Up to 20 Secondary Lists.
Sequence of events -
INTIALIZATION
AT SELECTION-SCREEN OUTPUT
AT SELECTION-SCREEN ON
AT SELECTION-SCREEN
START-OF-SELECTION
END-OF-SELECTION
TOP-OF-PAGE
END-OF-PAGE
AT USER-COMMAND
AT PF()
AT LINE-SELECTION
Initialization: is the event to get assign the value as a default(nothing but the initialization of the variable). It is the first event to trigger but if your program contains parameters or Select Options it trigger but not show the output on the list.
AT SELECTION-SCREEN OUTPUT -PBO for selection screen, just before displaying the screen
AT SELECTION-SCREEN ON - PAI on field
AT SELECTION-SCREEN - PAI of the selection screen
Top-of-page: is the event to design the header of the list. It is the only the event trigger after the initialization. Fist the control goes to Start-of-selection and then system(driver program ) searches for the Top-of-page envent if it has declared, immediatly control goes to that event and print the data whatever you given under that event.
Start-of-Selection: is the event to picking up the data from the database and for generating the Basic list data. It triggers after the top-of-page event. By defualt system declares this event, if you forget to declare in your report.

End-of-Selection: is the event that let to know the system program has just completed the execution of the Start-of-Selection event. it triggers after the Start-of-selection event.

End-of-page: is the event to display the Total Calculations or Page No.s and Footer Headings.

At PF: is the event to generate the GUIs(Graphical User Interface) like tool bars, application bar, title bar, Menu bar etc.,

At User-Command: used for generates the Push Buttons , Command Buttons etc., These events will trigger when the user perform some actions like pressing the command button .

At Line-Selection: is the event to geneartes the Secondary Lists, it will trigger when the user double click or press F2 key on the list contents. for generating the Secondary list sap provided predifined statements: SY-LIST,SY-LILLY,etc.,for entire record ,if you double click anywhere on the record it generates same secondary list. if you want to generate the secondary list based on the field you can go for GET CURSOR FIELD fieldname VALUE fieldvalue.

Top-of-page During Line-Selection: is the event to generate the Headers during on the Secondary List. You can generate different page headers for secondary lists

Saturday, January 29, 2011

FAQS

Following infotypes cannot be enhanced - 0000, 0302, Time infotypes (2xxx), Applicant Actions (4000)

Time Constraints

Time Constraint 1 - No gaps and No Overlap Ex - infotype 0001
Time Constraint 2 - Gaps are allowed but no overlap Ex: 0021 ( Spouse and Divorced )
Time Constraint 3 - Gaps and overlaps allowed - Ex - 0014 - Recurring payment
Time Constraint A - One record in the system begin date 1/1/1800 - 12/31/9999, cannot be deleted - Ex - infoype 0003
Time Constraint B - One record in the system with begin date 1/1/1800 - 12/31/9999, can be deleted - Ex - 0031
Time Constriant T - Varies according to subtype - Ex - 0009
Time Constrain Z - For Time management infotypes. Based on time constraint class table and collision table

Time Constriants in OM - 0, 1, 2.
0 - One record in the system
1 - without gaps
2 - with gaps
3 - as often as required