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.