Tuesday 20 March 2012

Authority check



  *&---------------------------------------------------------------------*
*&      Form  authority_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM authority_check.
  DATA: ldt_tvko TYPE TABLE OF tvko,
        lds_tvko TYPE tvko.

* Check Authorization for Sales Org
*  SELECT vkorg INTO TABLE ldt_tvko                          "EJ3K943661
  SELECT mandt vkorg INTO TABLE ldt_tvko                     "EJ3K943661 Include MANDT in selection
    FROM tvko WHERE vkorg IN p_vkorg.

  IF sy-subrc NE 0.
    SET CURSOR FIELD 'S_VKORG-LOW'.
    MESSAGE e313(vf) WITH p_vkorg-low.
  ELSE.
    LOOP AT ldt_tvko INTO lds_tvko.
      AUTHORITY-CHECK OBJECT 'V_VBRK_VKO'
                          ID 'VKORG' FIELD lds_tvko-vkorg
                          ID 'ACTVT' FIELD '03'.

      IF sy-subrc NE 0.
        SET CURSOR FIELD 'S_VKORG-LOW'.
        MESSAGE e514(vf) WITH lds_tvko-vkorg.
      ENDIF.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " authority_check

TO build ALV events

  *&---------------------------------------------------------------------*
*&      Form  build_alv_events
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_alv_events TABLES prt_events.

  DATA: ldt_event TYPE slis_alv_event.

  CLEAR ldt_event.
  ldt_event-name = slis_ev_top_of_page.
  ldt_event-form = 'DISPLAY_ALV_HEADER'.
  APPEND ldt_event TO prt_events.

  ldt_event-name = slis_ev_end_of_list.
  ldt_event-form = 'DISPLAY_ALV_FOOTER'.
  APPEND ldt_event TO prt_events.

ENDFORM.                    " build_alv_events

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv_header.

  DATA: ldf_pos   TYPE sylinsz,
        ldf_pagno(10TYPE c.


  ldf_pos = sy-linsz - 20.
  WRITE sy-pagno TO ldf_pagno LEFT-JUSTIFIED.

  IF NOT gdt_listheader2[] IS INITIAL.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        it_list_commentary = gdt_listheader2.
  ENDIF.

  IF NOT ldf_pagno IS INITIAL.
    WRITEAT ldf_pos text-w01, ldf_pagno.
  ENDIF.

ENDFORM.                    " display_alv_header



  FORM display_alv_footer.

  DATA: ldf_linsz TYPE sylinsz,
        ldf_pos   TYPE i,
        ldf_len   TYPE i.

  ldf_linsz = sy-linsz.
  ldf_pos = ldf_linsz / 2.
  ldf_len = STRLEN( gdf_end_report ).
  ldf_len = ldf_len / 2.
  ldf_pos = ldf_pos - ldf_len.

  IF NOT gdt_listfooter2[] IS INITIAL.
    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
        it_list_commentary = gdt_listfooter2.
  ENDIF.

  IF NOT gdf_end_report IS INITIAL AND
    gdf_end_report <> space.
    SKIP.
    WRITEAT ldf_pos gdf_end_report.
  ENDIF.

ENDFORM.             

Interactive ALV




  *---------------------------------------------------------------------*
*       FORM ALV_USER_COMMAND_DISPLAY_SEL
*---------------------------------------------------------------------*
*  -->  P_UCOMM                                                       *
*  -->  PS_SELFIELD                                                   *
*---------------------------------------------------------------------*
FORM alv_user_command_display_sel USING
                              prf_ucomm LIKE sy-ucomm
                              prs_selfield TYPE slis_selfield.

  DATA: ldf_kunnr TYPE kunnr,
        ldf_vbeln TYPE vbeln.

  CASE prf_ucomm.
    WHEN '&IC1'.                                       "Double click
      READ TABLE gdt_rept INDEX prs_selfield-tabindex.   "Cursor position
      CHECK sy-subrc EQ 0.
      CASE prs_selfield-fieldname.
        WHEN 'KUNAG'.
          CLEAR ldf_kunnr.
          ldf_kunnr = gdt_rept-kunag.
          IF NOT ldf_kunnr IS INITIAL.
            SET PARAMETER ID 'KUN' FIELD ldf_kunnr.
            CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
          ENDIF.
        WHEN 'KUNWE'.
          CLEAR ldf_kunnr.
          ldf_kunnr = gdt_rept-kunwe.
          IF NOT ldf_kunnr IS INITIAL.
            SET PARAMETER ID 'KUN' FIELD ldf_kunnr.
            CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
    WHEN OTHERS.
  ENDCASE.

  CLEAR prf_ucomm.

ENDFORM.                    "alv_user_command_display_sel

To Display ALV Report (FIELD catalog bild, ALV header, ALV layout)

  * display report
  IF NOT p_disp IS INITIAL.
    PERFORM display_alv_report.

  *&---------------------------------------------------------------------
*&      Form  display_alv_report
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
*
FORM display_alv_report.

  DATA: ldt_listfooter TYPE slis_t_listheader.

  gdf_repid = sy-repid.

  PERFORM build_field_catalog.
  PERFORM build_alv_header.
  PERFORM build_alv_layout.

* set up header and footer data (to add page number and end of report)
  PERFORM setup_report_header_footer
                              TABLES gdt_listheader
                                     ldt_listfooter
                                     gdt_events
                              USING  gcf_end_rept.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = gdf_repid
      i_callback_user_command = gcf_alv_cmd
      is_layout               = gdt_layout
      it_fieldcat             = gdt_fieldcat
      it_events               = gdt_events
      is_print                = gds_print
      i_save                  = gcf_a
    TABLES
      t_outtab                = gdt_rept
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

  IF sy-subrc NE 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  build_field_catalog
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
FORM build_field_catalog.

  IF sy-batch = gcf_x.
    MESSAGE i000 WITH text-m11.
  ENDIF.

  PERFORM assign_fields USING:
   'VKORG'       'IT_REPT'   'C'  ' '  text-t01,
   'KTOKD'       'IT_REPT'   'C'  ' '  text-t02,
   'KUNAG'       'IT_REPT'   'C'  ' '  text-t03,
   'NAMAG'       'IT_REPT'   'C'  ' '  text-t04,
   'PARVW'       'IT_REPT'   'C'  ' '  text-t14, " Added by EJ3K946466 702061451 20.03.2012
   'KUNWE'       'IT_REPT'   'C'  ' '  text-t05,
   'NAMWE'       'IT_REPT'   'C'  ' '  text-t06,
   'NAME2'       'IT_REPT'   'C'  ' '  text-t07,
   'CITY'        'IT_REPT'   'C'  ' '  text-t08,
   'STATE'       'IT_REPT'   'C'  ' '  text-t09,
   'PSTCD'       'IT_REPT'   'C'  ' '  text-t10,
   'STADD'       'IT_REPT'   'C'  ' '  text-t11,
   'TELNO'       'IT_REPT'   'C'  ' '  text-t12,
   'FAXNO'       'IT_REPT'   'C'  ' '  text-t13.

ENDFORM.                    " build_field_catalog

  *&---------------------------------------------------------------------
*
*&      Form  build_alv_header
*&---------------------------------------------------------------------
*
*       text
*----------------------------------------------------------------------
*
FORM build_alv_header.

  CLEAR   gds_listheader.
  REFRESH gdt_listheader.

* Main heading
  CLEAR gdt_listheader.
  gds_listheader-typ = gcf_h.
  gds_listheader-info = sy-title.
  APPEND gds_listheader TO gdt_listheader.

* General ALV header info: date/time/username
* (this will appear on all ALV grids)
  CLEAR gds_listheader.
  gds_listheader-typ = gcf_s.
  gds_listheader-key = 'Date/Time/User:'.
  WRITE sy-datum TO gds_listheader-info.
  WRITE '/' TO gds_listheader-info+11(1).
  WRITE sy-uzeit TO gds_listheader-info+13.
  WRITE '/' TO gds_listheader-info+22(1).
  WRITE sy-uname TO gds_listheader-info+24.
  APPEND gds_listheader TO gdt_listheader.

ENDFORM.                    " build_alv_header

  *&---------------------------------------------------------------------
*&      Form  build_alv_layout
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
*
FORM build_alv_layout.

  gdt_layout-cell_merge        = gcf_x.
  gdt_layout-colwidth_optimize = gcf_x.
  gdt_layout-zebra = gcf_x.

ENDFORM.           


  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = gdf_repid
      i_callback_user_command = gcf_alv_cmd
      is_layout               = gdt_layout
      it_fieldcat             = gdt_fieldcat
      it_events               = gdt_events
      is_print                = gds_print
      i_save                  = gcf_a
    TABLES
      t_outtab                = gdt_rept
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

  IF sy-subrc NE 0.
*    message id sy-msgid type sy-msgty number sy-msgno
*            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

To send report as E-Mail

  PERFORM send_report_via_email.

  *&---------------------------------------------------------------------*
*&      Form  send_report_via_email
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM send_report_via_email.

  PERFORM build_column_header.

  IF p_emsubj IS INITIAL.
    p_emsubj = gcf_subjtxt.
  ENDIF.

  PERFORM build_subject_attach_name
                     USING
                       p_emsubj
                       gcf_emlfile_desc
                     CHANGING
                       gds_email_subject
                       gds_attach_descr.

  PERFORM send_email TABLES
                       p_addres
                       gdt_email_body
                       gdt_rept
                     USING
                       gds_email_subject
                       gds_attach_descr
                       gds_column_headers.

ENDFORM.                    " send_report_via_email


  *&---------------------------------------------------------------------*
*&      Form  build_subject_attach_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SUBJECT_TEXT  text
*      -->P_ATTACH_TEXT  text
*      <--P_EMAIL_SUBJECT  text
*      <--P_ATTACH_FILENAME  text
*----------------------------------------------------------------------*
FORM build_subject_attach_name USING    prf_subject_text
                                        prf_attach_text
                               CHANGING prf_email_subject
                                        prf_attach_descr.

  DATA: ldf_date(8)      TYPE c,
        ldf_time(8)      TYPE c.

  CLEAR: prf_email_subject,
         prf_attach_descr.

  WRITE sy-datum TO ldf_date DD/MM/YY.
  GET TIME.
  WRITE sy-uzeit TO ldf_time USING EDIT MASK '__:__:__'.

* build email subject
  CONCATENATE prf_subject_text ldf_date ldf_time
              INTO prf_email_subject SEPARATED BY space.

* build attachment file name
  CONCATENATE prf_attach_text gcf_undscore sy-datum sy-uzeit
              INTO prf_attach_descr.



ENDFORM.                    " build_subject_attach_name


  *&---------------------------------------------------------------------*
*&      Form  send_email
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FT_EMAIL_ADDRESS  text
*      -->FT_EMAIL_BODY  text
*      -->FT_REPT_DATA  text
*      -->FP_EMAIL_SUBJECT  text
*      -->FP_ATTACH_DESCR  text
*      -->FP_COLUMN_HEADERS  text
*----------------------------------------------------------------------*
FORM send_email TABLES prt_email_address  STRUCTURE p_addres
                       prt_email_body     STRUCTURE soli
                       prt_rept_data
                USING  prt_email_subject  LIKE sodocchgi1-obj_descr
                       prt_attach_descr   LIKE sopcklsti1-obj_descr
                       prt_column_headers LIKE solisti1.

  DATA: ldf_count       TYPE i,
        ldf_attach_cnt  TYPE i,
        ldf_body_cnt    TYPE i,
        ldf_data        TYPE gts_rept,
        ldf_tabix       TYPE sytabix,
        ldf_chardata    TYPE char200,
        ldf_mailsubject TYPE sodocchgi1.

  DATA: ldt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
        lds_packing_list TYPE sopcklsti1.
  DATA: ldt_recipients   TYPE STANDARD TABLE OF somlreci1,
        lts_recipients   TYPE somlreci1.
  DATA: ldt_rept_data    TYPE TABLE OF gts_rept,
        lds_rept_data    TYPE gts_rept.

  DATA: ldt_objbin  LIKE solisti1   OCCURS 10 WITH HEADER LINE.

* populate email addresses itab
  REFRESH ldt_recipients.
  LOOP AT prt_email_address.
    CLEAR lts_recipients.
    lts_recipients-receiver = prt_email_address-low.
    APPEND lts_recipients TO ldt_recipients.
    CLEAR prt_email_address.
  ENDLOOP.


* populate email attachment itab with tab delimited data
  REFRESH gdt_attachment.

* prepare attachment
  ldt_rept_data[] = prt_rept_data[].

  LOOP AT ldt_rept_data INTO lds_rept_data.
    CONCATENATE lds_rept_data-vkorg
                lds_rept_data-ktokd
                lds_rept_data-kunag
                lds_rept_data-namag
                lds_rept_data-kunwe
                lds_rept_data-namwe
                lds_rept_data-name2
                lds_rept_data-city
                lds_rept_data-state
                lds_rept_data-pstcd
                lds_rept_data-stadd
                lds_rept_data-telno
                lds_rept_data-faxno
        INTO ldt_objbin
        SEPARATED BY gcf_tab.
    CONCATENATE ldt_objbin gcf_newline INTO ldt_objbin.
    APPEND ldt_objbin.
  ENDLOOP.
  gdt_attachment[] = ldt_objbin[].


* insert column headers
  INSERT prt_column_headers INTO gdt_attachment INDEX 1.


  DELETE ldt_recipients WHERE receiver = space.
* check that the recipients table is not empty
  IF ldt_recipients[] IS INITIAL.
    RAISE no_address_given.
  ENDIF.

  DESCRIBE TABLE gdt_attachment LINES ldf_attach_cnt.

* populate email recipients table
  LOOP AT ldt_recipients INTO lts_recipients
    WHERE NOT receiver IS INITIAL.
    ldf_tabix = sy-tabix.
    lts_recipients-rec_type  = gcf_u.
    lts_recipients-com_type  = gcf_int.
    MODIFY ldt_recipients FROM lts_recipients INDEX ldf_tabix.
  ENDLOOP.

* populate email subject (document_data) structure
  ldf_mailsubject-obj_name     = gcf_mailsubject.
  ldf_mailsubject-obj_langu    = sy-langu.
  ldf_mailsubject-obj_descr    = prt_email_subject.
  ldf_mailsubject-sensitivty   = gcf_f.
  ldf_mailsubject-doc_size     = ( ldf_attach_cnt - 1 ) * 255 +
                                STRLEN( gdt_attachment ).

* email body
  lds_packing_list-transf_bin  = space.
  lds_packing_list-head_start  = 1.
  lds_packing_list-head_num    = 0.
  lds_packing_list-body_start  = 1.
  lds_packing_list-body_num    = ldf_body_cnt.
  lds_packing_list-doc_type    = gcf_raw.
  APPEND lds_packing_list TO ldt_packing_list.
  CLEAR  lds_packing_list.

* email attachment
  lds_packing_list-transf_bin  = gcf_x.
  lds_packing_list-head_start  = 1.
  lds_packing_list-head_num    = 1.
  lds_packing_list-body_start  = 1.
  lds_packing_list-body_num    = ldf_attach_cnt.
  lds_packing_list-doc_type    = gcf_xls.  "text file
  lds_packing_list-obj_name    = gcf_mailattach.
  lds_packing_list-obj_descr   = prt_attach_descr.
  lds_packing_list-doc_size    = lds_packing_list-body_num * 255.
  APPEND lds_packing_list TO ldt_packing_list.
  CLEAR  lds_packing_list.


* Call SAP Office function to send the email out
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = ldf_mailsubject
      put_in_outbox              = ' '
    TABLES
      packing_list               = ldt_packing_list
      contents_bin               = gdt_attachment
      receivers                  = ldt_recipients
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.

  CASE sy-subrc.
    WHEN 0.
      COMMIT WORK.
* Push mail out from SAP outbox
      SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
      MESSAGE s000(zev0301) WITH text-m03.
    WHEN 1.
      MESSAGE s000(zev0301) WITH text-m04.
    WHEN 2.
      MESSAGE s000(zev0301) WITH text-m05.
    WHEN 3.
      MESSAGE s000(zev0301) WITH text-m06.
    WHEN 4.
      MESSAGE s000(zev0301) WITH text-m07.
    WHEN OTHERS.
      MESSAGE s000(zev0301) WITH text-m08.
  ENDCASE.

ENDFORM.                    " send_email

To change the GUI status while executing the program

  PERFORM show_progress_indicator USING text-i02.
  PERFORM process_report_data.


*&---------------------------------------------------------------------*
*&      Form  show_progress_indicator
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM show_progress_indicator USING prf_text. "Processing report data...
                                             "Data selection in progress...
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = prf_text.

ENDFORM.                

When sending the mail

    DATA: ldf_mailsubject TYPE sodocchgi1.

  DATA: ldt_packing_list TYPE STANDARD TABLE OF sopcklsti1,
        lds_packing_list TYPE sopcklsti1.
  DATA: ldt_recipients   TYPE STANDARD TABLE OF somlreci1,
        lts_recipients   TYPE somlreci1.
 

* populate email subject (document_data) structure
  ldf_mailsubject-obj_name     = gcf_mailsubject.
  ldf_mailsubject-obj_langu    = sy-langu.
  ldf_mailsubject-obj_descr    = prt_email_subject.
  ldf_mailsubject-sensitivty   = gcf_f.
  ldf_mailsubject-doc_size     = ( ldf_attach_cnt - 1 ) * 255 +
                                STRLEN( gdt_attachment ).

* email body
  lds_packing_list-transf_bin  = space.
  lds_packing_list-head_start  = 1.
  lds_packing_list-head_num    = 0.
  lds_packing_list-body_start  = 1.
  lds_packing_list-body_num    = ldf_body_cnt.
  lds_packing_list-doc_type    = gcf_raw.
  APPEND lds_packing_list TO ldt_packing_list.
  CLEAR  lds_packing_list.

* email attachment
  lds_packing_list-transf_bin  = gcf_x.
  lds_packing_list-head_start  = 1.
  lds_packing_list-head_num    = 1.
  lds_packing_list-body_start  = 1.
  lds_packing_list-body_num    = ldf_attach_cnt.
  lds_packing_list-doc_type    = gcf_xls.  "text file
  lds_packing_list-obj_name    = gcf_mailattach.
  lds_packing_list-obj_descr   = prt_attach_descr.
  lds_packing_list-doc_size    = lds_packing_list-body_num * 255.
  APPEND lds_packing_list TO ldt_packing_list.
  CLEAR  lds_packing_list.


* Call SAP Office function to send the email out
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = ldf_mailsubject
      put_in_outbox              = ' '
    TABLES
      packing_list               = ldt_packing_list
      contents_bin               = gdt_attachment
      receivers                  = ldt_recipients
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.

  CASE sy-subrc.
    WHEN 0.
      COMMIT WORK.
* Push mail out from SAP outbox
      SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
      MESSAGE s000(zev0301) WITH text-m03.
"Email successfully sent

Thursday 15 March 2012

To connect to remote desktop

Start---> Accessories-->Remotedesktop connection
and give the IP address of the other system which you want to connect.

before that Start--->Settings-->Controlpannel-->
Administrative tools-->Computer managemant-->Local users and Groups-->inside groups you have to enter your mail id and add it.

than connect to other system.

Wednesday 14 March 2012

Standard Programs

1) Standard program to import standard script into Transport request : RSTXTRAN
2) Program to download spool to pdf : RSTXPDFT4
3) Program to download sap script and script texts : RSTXSCRP

BALVBT01
Example SAP program for displying multiple ALV reports on one page
BCALV_GRID_DEMO ALV Dialog grid demo (4.6)

BRF_COPY_IMPL_CLASSES
Copy standard implementing classes to your new application class. See BRF related transactions

SHOWCOLO
Displays all colours available

SHOWICON
Displays all icon available

RGUGBR00
Substitution/Validation and rules utility

RKCTSEAR
Search source code of various programs for up to two strings. Also see RPR_ABAP_SOURCE_SCAN or use search in source functionality via SE80

RPCIFU01
Display File

RPCIFU03
Download Unix File to PC

RPCIFU04
Upload PC File to Unix File

RPR_ABAP_SOURCE_SCAN
Search ABAP code for a string. Much more flexible than RSRSCAN1 or RKCTSEAR

RSBDCBTC
Submit a BDC job with an internal batch number and wait for the end of the batch input session

RSBDCDRU
Prints the contents of a Batch Input session. No options for error transactions only

RSBDCOS0
Execute OS Command (Logged in SYSLOG and Trace Files)

RSBDCSUB
Process batch input sessions automatically

RSBTCDEL
Delete batch jobs

RSCONN01
SAPconnect: Start Email Send Process

RSCSAUTH
Maintain/Restore Authorization Groups

RSINCL00
Extended ABAP Program Reference List

RSMODRES Restore enhancement projects after upgarde

RSORAREL
Check Oracle Version

RSPARAM
Display all instance parameters

RSPO0041
Delete Old Spool Requests

RSSNAPDL
Reorganization Program for Table SNAP of Short Dumps

RSTRANSP
Transport Report Variants

RSTXFCON
SAPscript: Conversion of Page Format for Forms

RSTXPDFT4
Convert spool request to PDF document

RSTXPDFT5
GUI download of a spool request

RSTXSCRP
SAPscript Export to Dataset / SAPscript Import from Dataset (Upload and download SAPScript layout sets)

RSTXTRAN
Transfer standard Texts(SAPscript texts) to a transport request

RSUSR003
Check the Passwords of Users SAP* and DDIC in All Clients

RSUSR006
List of Users with Incorrect Logons

RSVARFIT
Adjust Variants to Modified Selections

RSVTPROT
Evaluation of change logs

RSWBO052
Change Object Directory Entries

RSWBO060
Include Objects in a Transport Request

SAPMSUU0
Program for user maintenance(SU01), Maybe useful if you do not have access to the actual SU01 transaction code.

Thursday 8 March 2012

BAPI to change the date formate and FN module to separate the string

1) to change the date formate

data : date like sy-datum,
data1(10) type c.
call function 'CONVERT_DATE_TO_INTERNAL'
exporting
date_external = date1
importing
date_internal = date
exceptions
date_external_is_invalid = 1
others = 2.


http://anu-sapdiary.blogspot.com.au/2008/03/function-modules-for-date-conversion.html


2) to divide the string into 2.

   CALL FUNCTION 'HR_HK_STRING_INTO_2_LINES'
    EXPORTING
      source_str      = ldf_pay_terms
      len_of_1st_line = lcf_thirty
      len_of_2nd_line = lcf_thirty
    IMPORTING
      1st_line_str    = ldf_pay_terms1
      2nd_line_str    = ldf_pay_terms2
    EXCEPTIONS
      error           = 1
      OTHERS          = 2.

  CONDENSE: ldf_pay_terms1,
            ldf_pay_terms2.
  ldf_length = STRLEN( ldf_pay_terms1 ).
  ldf_length1 = STRLEN( ldf_pay_terms2 ).

Wednesday 7 March 2012

Print program for Order confirmation(Form entry and print parameters)

report  zet05r0003.

*&---------------------------------------------------------------------*
*& Declare Data Object                                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
include zet05r0003top.

include zet05r0003f01.

*---------------------------------------------------------------------*
*       FORM ENTRY
*---------------------------------------------------------------------*
form entry using prf_return_code type sy-subrc
                 prf_us_screen   type c.              "#EC CALLED

  data: ldf_return type sy-subrc.

  gdf_xscreen = prf_us_screen.
  perform processing_outp using prf_us_screen
                       changing ldf_return.
  if ldf_return ne 0.
    prf_return_code = 1.
  else.
    prf_return_code = 0.
  endif.

endform.                    "entry

**************************************************************************
 
*&---------------------------------------------------------------------*
*&  Include           ZEL03R0010F01
*&---------------------------------------------------------------------*
*& renew date   transport No  change by         contents               *
*& 18.11.2011   EJ3K941377    702068010     Change print params        *
*& 21.12.2011    EJ3K943103   Swapna Narra  Fix for Email Functionality*
*&---------------------------------------------------------------------*
*&      Form  processing
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      -->PRF_SCREEN  prf_screen(us_screen)
*&      <--PRF_RETURN  prf_return(return_code)
*&---------------------------------------------------------------------*

form processing_outp  using    prf_screen type c
                 changing prf_return type sy-subrc.
*Smartform Call
  perform output_list using    prf_screen
                      changing prf_return.

endform.                    " processing

*&---------------------------------------------------------------------*
*&      Form  output_list
*&---------------------------------------------------------------------*
*       To Display the Smartform for Display
*----------------------------------------------------------------------*
*      -->PRF_SCREEN  prf_screen(us_screen)
*      <--PRF_RETURN  prf_return(return_code)
*----------------------------------------------------------------------*
form output_list  using    prf_screen  type c
                 changing  prf_return  type sy-subrc.
*Local Variables
  data: lds_control_param              type ssfctrlop.
  data: lds_composer_param             type ssfcompop.
  data: lds_recipient                  type swotobjid.
  data: lds_sender                     type swotobjid.
  data: ldf_form                       type tdsfname.
  data: ldf_fm_name                    type rs38l_fnam.
  data: lds_addr_key                   type addr_key.
*Local Constants.
  constants: lcf_blank(1value ''.

* If no reference key is passed, it'll be handled as an exception and exit the processing.
  if nast-objky is initial.
    perform nast_prot_updt.
*Exit from the Subroutine
    exit.
  endif.

  if prf_return = 0.
*In Case No Error Exists move the Name of Smartform.
    move tnapr-sform to ldf_form.
    perform get_data changing lds_addr_key
                             prf_return  .
*Setting the Print Parameters.
    perform set_print_param using    lds_addr_key
                            changing lds_control_param
                                     lds_composer_param
                                     lds_recipient
                                     lds_sender
                                     prf_return.

*Function Module Call for the Smartform.
    call function 'SSF_FUNCTION_MODULE_NAME'
      exporting
        formname           = ldf_form
      importing
        fm_name            = ldf_fm_name
      exceptions
        no_form            = 1
        no_function_module = 2
        others             = 3.
    if sy-subrc <> 0.
*Error Handling
      prf_return = sy-subrc.
      if prf_screen = lcf_blank.
*Error Logging is Performed
        perform protocol_update.
      endif.
    endif.
  endif.

*In Case There are no Errors the Smartform Handling is done here.
  if prf_return = 0.
*   call smartform
    call function ldf_fm_name
      exporting
        control_parameters = lds_control_param
        mail_recipient     = lds_recipient
        mail_sender        = lds_sender
        output_options     = lds_composer_param
        user_settings      = lcf_blank
        i_nast             = nast
      exceptions
        formatting_error   = 1
        internal_error     = 2
        send_error         = 3
        user_canceled      = 4
        others             = 5.
    if sy-subrc <> 0.
*Error handling
      prf_return = sy-subrc.

      if prf_screen = lcf_blank.
*Error Logging is Performed
        perform protocol_update.
      endif.
*Get SmartForm protocol and store it in the NAST protocoll
      perform add_smfrm_prot.
    endif.
  endif.
endform.                    " output_list

*---------------------------------------------------------------------*
*       FORM PROTOCOL_UPDATE                                          *
*---------------------------------------------------------------------*
*       The messages are collected for the processing protocol.       *
*---------------------------------------------------------------------*

form protocol_update.

  check gdf_xscreen = space.

*Funtion Module Call for Error Logging
  perform nast_prot_updt.

endform.                    "PROTOCOL_UPDATE

*&---------------------------------------------------------------------*
*&      Form  ADD_SMFRM_PROT
*&---------------------------------------------------------------------*
form add_smfrm_prot.

  data: ldt_errortab             type tsferror.
  field-symbols: <fs_errortab>   type line of tsferror.
  constants: lcf_e(1)            value 'E'.

*Get smart form protocoll
  call function 'SSF_READ_ERRORS'
    importing
      errortab = ldt_errortab.

* add smartform protocoll to nast protocoll
  loop at ldt_errortab assigning <fs_errortab>.

*Updating the Error Log
    call function 'NAST_PROTOCOL_UPDATE'
      exporting
        msg_arbgb              = <fs_errortab>-msgid
        msg_nr                 = <fs_errortab>-msgno
        msg_ty                 = <fs_errortab>-msgty
        msg_v1                 = <fs_errortab>-msgv1
        msg_v2                 = <fs_errortab>-msgv2
        msg_v3                 = <fs_errortab>-msgv3
        msg_v4                 = <fs_errortab>-msgv4
      exceptions
        message_type_not_valid = 1
        no_sy_message          = 2
        others                 = 3.
    if sy-subrc <> 0.
      message id sy-msgid type lcf_e number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
  endloop.

endform.                               " ADD_SMFRM_PROT

*&---------------------------------------------------------------------*
*&      Form  SET_PRINT_PARAM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      -->  prs_addr_key
*&      <--  prs_control_param
*&      <--  prs_composer_param
*&      <-- prs_recipient
*&      <-- prs_sender
*&      <-- prf_return
*&---------------------------------------------------------------------*

form set_print_param using    prs_addr_key       type addr_key
                     changing prs_control_param  type ssfctrlop
                              prs_composer_param type ssfcompop
                              prs_recipient      type swotobjid
                              prs_sender         type swotobjid
                              prf_return         type sy-subrc.
*Local Declarations.
  data: lds_itcpo     type itcpo.
  data: ldf_repid     type sy-repid.
  data: ldf_device    type tddevice.
*Program Name
  ldf_repid = sy-repid.
*Local Constants.
  constants: lcf_x(1value 'X'.
*Smartform Conditions.
  call function 'WFMC_PREPARE_SMART_FORM'
    exporting
      pi_nast       = nast
      pi_addr_key   = prs_addr_key
      pi_repid      = ldf_repid
    importing
      pe_returncode = prf_return
      pe_itcpo      = lds_itcpo
      pe_device     = ldf_device
      pe_recipient  = prs_recipient
      pe_sender     = prs_sender.

  if prf_return = 0.
*Setting up the Display of Smartform.
    move-corresponding lds_itcpo to prs_composer_param.
    concatenate prs_composer_param-tdcovtitle
             space
             nast-objky
             into prs_composer_param-tdtitle.

*   prs_composer_param-tdnewid = lcf_x  .                  "<EJ3K941377
    prs_control_param-device      = ldf_device.
    prs_control_param-no_dialog   = lcf_x.
    prs_control_param-preview     = gdf_xscreen.
    prs_control_param-getotf      = lds_itcpo-tdgetotf.
    prs_control_param-langu       = nast-spras.
  endif.
endform.                               " SET_PRINT_PARAM

*&---------------------------------------------------------------------*
*&      Form  nast_prot_updt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form nast_prot_updt.
  constants: lcf_e(1value 'E'.
  call function 'NAST_PROTOCOL_UPDATE'
    exporting
      msg_arbgb              = syst-msgid
      msg_nr                 = syst-msgno
      msg_ty                 = syst-msgty
      msg_v1                 = syst-msgv1
      msg_v2                 = syst-msgv2
      msg_v3                 = syst-msgv3
      msg_v4                 = syst-msgv4
    exceptions
      message_type_not_valid = 1
      no_sy_message          = 2
      others                 = 3.
  if sy-subrc <> 0.
    message id sy-msgid type lcf_e number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.



endform.                    "nast_prot_updt
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LDS_ADDR_KEY  text
*----------------------------------------------------------------------*
form get_data  changing prf_addr_key type addr_key
                        prf_retcode  type sy-subrc.
  data: ldt_mess type standard table of vbfs,
        lds_mess like vbfs.
  databegin of ldt_vbdpa occurs 0.        "Internal table for items
          include structure vbdpa.
  dataend of ldt_vbdpa.
  data :lds_vbco3         type vbco3.

  lds_vbco3-mandt = sy-mandt.
  lds_vbco3-spras = nast-spras.
  lds_vbco3-vbeln = nast-objky.
  lds_vbco3-kunde = nast-parnr.
  lds_vbco3-parvw = nast-parvw.

  call function 'RV_DOCUMENT_PRINT_VIEW'
    exporting
      comwa                       = lds_vbco3
    importing
      kopf                        = vbdka
    tables
      pos                         = ldt_vbdpa
      mess                        = ldt_mess
    exceptions
      fehler_bei_datenbeschaffung = 1.
  if sy-subrc ne 0.
    perform protocol_update.
    prf_retcode = 1.
    exit.
  else.
    loop at ldt_mess into lds_mess.
      sy-msgid = lds_mess-msgid.
      sy-msgno = lds_mess-msgno.
      sy-msgty = lds_mess-msgty.
      sy-msgv1 = lds_mess-msgv1.
      sy-msgv2 = lds_mess-msgv2.
      sy-msgv3 = lds_mess-msgv3.
      sy-msgv4 = lds_mess-msgv4.
      perform protocol_update.
    endloop.
  endif.
* fill address key --> necessary for emails
  prf_addr_key-addrnumber = vbdka-adrnr.
  prf_addr_key-persnumber = vbdka-adrnp.
  prf_addr_key-addr_type  = vbdka-address_type.
endform.                    " GET_DATA