Skip to end of metadata
Go to start of metadata

Purpose : Mass upload of Employee photo for Infotype 0002

Reason : For mass upload the BDC (batch data communication) & LSMW (Legacy System Migration Workbench )doesn't work as transaction OAOH pop up to choose path of photo file hence customized program

Procedure :

Step 1: Just stores photo file as JPG ,file name same as employee Personal number . (sometimes  The Employee Photos name should be store as Employee Number as 8 digits( if needed with leading Zero)

Step 2 : Go SE38 Execute program name ( you can create t.code  in se93 for example :zhr_photo) 

Step 3: select Path 

Step 4 : Execute 

Code : 

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Report  ZHR_MASS_UPLOAD_PHOTO1
*&
*&---------------------------------------------------------------------*
*& Mass Upload 
*&
*&---------------------------------------------------------------------*
REPORT zhr_mass_upload_photo1 MESSAGE-ID oa.
 
DATA: lt_file_table TYPE TABLE OF sdokpath,
      wa_file_table LIKE LINE OF lt_file_table,
lt_dir_table  TYPE TABLE OF sdokpath,
lt_data       TYPE STANDARD TABLE OF string WITH HEADER LINE,
lt_output     TYPE TABLE OF sdokpath,
lt_invalid_f  TYPE TABLE OF sdokpath,
lv_error(1).
 
 
*--------------------------------------------------------------------------*
*                    S  T  R  U  C  T  U  R  E  S                          *
*--------------------------------------------------------------------------*
DATA: ls_file_table TYPE sdokpath,
      ls_output     TYPE sdokpath.
*--------------------------------------------------------------------------*
*           V A R I A B L E S    D E C L A R A T I O N                     *
*--------------------------------------------------------------------------*
DATA: lv_dir          TYPE cffile-filename, lv_flag(3)      TYPE n,
	  lv_app_path(80) TYPE c,               lv_file_count   TYPE i,
	  lv_cnt(3)       TYPE n,               lv_text(200)    TYPE c, 
      lv_filename     TYPE string.
 
*--------------------------------------------------------------------------*
*                         C O N S T A N T S                               *
*--------------------------------------------------------------------------*


CONSTANTS: lc_data1(6)  VALUE '/data/',
           lc_data2(17) VALUE '/TSB/CCP/in/data/'.
** Photo is visible via PA10, PA20, PA30, PA40.
* Program notifies that the Photo was updated succesfully.
TABLES: toav0, toaom, twfdb, toapa.
DATA: key LIKE ojint-key.
DATA: object LIKE ojint-name.
DATA: object_id LIKE toav0-object_id.
DATA: archiv_id LIKE toav0-archiv_id.
DATA: arc_doc_id LIKE toav0-arc_doc_id.
DATA: ablagedatum LIKE sapb-sapabldate.
DATA: ar_date LIKE toav0-ar_date.
DATA: del_date LIKE toav0-del_date.
DATA: sap_object LIKE toaom-sap_object.
DATA: ar_object LIKE toaom-ar_object.
DATA: expiry_tim LIKE toaom-expiry_tim.
DATA: method LIKE ojint-method.
DATA: return LIKE ojint-return.
DATA: parameter LIKE ojint-parameter.
DATA: BEGIN OF i_toav0 OCCURS 1.
        INCLUDE STRUCTURE toav0.
DATA: END OF i_toav0.
DATA: BEGIN OF i_toaom OCCURS 1.
	       INCLUDE STRUCTURE toaom.
DATA: END OF i_toaom.
DATA: BEGIN OF fields OCCURS 1.
        INCLUDE STRUCTURE ojfields.
DATA: END OF fields.
DATA: create(2) VALUE '01'.
DATA: w_pernr_zero LIKE sapb-sapobjid,
      w_pernr_pass LIKE sapb-sapobjid,
      p_pernr LIKE pa0001-pernr.
DATA: lw_ar_object LIKE toaom-ar_object,
      lw_object_id LIKE sapb-sapobjid,
      lw_sap_object LIKE toaom-sap_object,
      lw_doc_type LIKE toadd-doc_type,
      lw_path LIKE sapb-sappfad."toav0-arc_doc_id
DATA: archiv_doc_id LIKE toav0-arc_doc_id.
DATA : doc_type LIKE toadt-doc_class.
*internal table to store Emp PSL No & path of photo file
DATA: BEGIN OF it_data OCCURS 0,
        pernr LIKE rp50g-pernr,                             "1230
              rlgrap-filename(128), "c:\hr\1230.jpg
      END OF it_data.
DATA : wa_data LIKE LINE OF it_data.
DATA : lv_text_path(50).
* file to be uploaded
DATA: i_fname TYPE rlgrap-filename.
* Define Constants as per transaction OAOH
CONSTANTS:  c_sap_object TYPE toaom-sap_object VALUE 'PREL',
            c_ar_object TYPE toaom-ar_object VALUE 'HRICOLFOTO',
            c_doc_type TYPE toaom-doc_type VALUE 'JPG'.
* select file to be uploaded
PARAMETERS: path TYPE cffile-filename.
INITIALIZATION.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR path.
  PERFORM value_request_pc_file_download USING path.
START-OF-SELECTION.
  CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
    EXPORTING
      directory  = path
      filter     = '*.JPG'
    IMPORTING
      file_count = lv_file_count
    TABLES
      file_table = lt_file_table
      dir_table  = lt_dir_table
    EXCEPTIONS
      cntl_error = 1
      OTHERS     = 2.
  CLEAR wa_file_table.
  LOOP AT lt_file_table INTO wa_file_table.
    CLEAR wa_data.
    lv_text_path = wa_file_table-pathname.
    wa_data-rlgrap-filename = wa_file_table-pathname.
    REPLACE ALL OCCURRENCES OF '.JPG' IN lv_text_path WITH ''.
    wa_data-pernr = lv_text_path.
* For each employee - unpack emp No & info type 0002
    UNPACK wa_data-pernr TO wa_data-pernr.
    CONCATENATE wa_data-pernr '0002' INTO key.
* Remove leading zeros of pernr
    SHIFT wa_data-pernr LEFT DELETING LEADING '0'.
    CONDENSE wa_data-pernr.
    w_pernr_zero = wa_data-pernr.
    CLEAR w_pernr_pass.
    w_pernr_pass = w_pernr_zero.
* Object to be archived
    SELECT SINGLE * FROM toaom WHERE ar_object = c_ar_object
    AND sap_object = c_sap_object.
    IF sy-subrc <> 0.
      MESSAGE w251 WITH ar_object object. 	"No document type & exists with object type &
    ELSE.
* Authority check with Archive id
      archiv_id = toaom-archiv_id.
      PERFORM authority_check_create(oaall)
      USING archiv_id object space ar_object space
      CHANGING sy-subrc.
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          CLEAR toav0.
        ELSE.
* Transfer key for archiving
          toav0-object_id = key.
          IF key EQ space.
            MESSAGE w252.	 "Specify valid SAP object key
            CLEAR toav0.
          ELSE.
            PERFORM create_archive_object_new.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
    CLEAR wa_file_table.
  ENDLOOP.
  IF lv_error = 1.
    MESSAGE i044.	"Stored document created successfully
    MESSAGE 'Photo uploaded successfully' TYPE 'I'.
  ENDIF.
*&---------------------------------------------------------------------*
*& Form value_request_pc_file_download
*&---------------------------------------------------------------------*
FORM value_request_pc_file_download USING field.
  CALL FUNCTION '/SAPDMC/LSM_F4_FRONTEND_FILE'
    CHANGING
      pathfile         = path
    EXCEPTIONS
      canceled_by_user = 1
      system_error     = 2
      OTHERS           = 3.
  CLEAR lv_dir.
* Below functionality used to delete the file name form the selected path.
  DO.
    SEARCH path FOR '\'.
    IF sy-subrc EQ 0.
      lv_flag = strlen( path ).
      sy-fdpos = sy-fdpos + 1.
      CONCATENATE  lv_dir path+0(sy-fdpos)  INTO lv_dir.
      path+0(sy-fdpos) = ''.
      CONDENSE path.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
  CLEAR path.
  path = lv_dir.
  CONCATENATE 'Directory selected: --> ' path INTO ls_output SEPARATED BY space.
  APPEND ls_output TO lt_output.
  CLEAR ls_output.
ENDFORM. " value_request_pc_file_download
*&---------------------------------------------------------------------*
*& Form create_archive_object_new
*&---------------------------------------------------------------------*
FORM create_archive_object_new .
* First create archive link for the object
* Assign Values
  lw_ar_object = c_ar_object.
  lw_object_id = w_pernr_pass.
  lw_sap_object = c_sap_object.
  lw_doc_type = c_doc_type.
  lw_path = wa_data-rlgrap-filename.
  CALL FUNCTION 'ARCHIV_CREATE_FILE'
    EXPORTING
      ar_object               = lw_ar_object
      object_id               = lw_object_id
      sap_object              = lw_sap_object
      doc_type                = lw_doc_type
      path                    = lw_path
    EXCEPTIONS
      error_conectiontable    = 1
      error_parameter         = 2
      error_archiv            = 3
      error_upload            = 4
      error_kernel            = 5
      no_entry_possible       = 6
      error_comunicationtable = 7
      OTHERS                  = 8.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    CLEAR toav0.
  ELSE.
* Create file for archived object
    CALL FUNCTION 'ARCHIVOBJECT_CREATE_FILE'
      EXPORTING
        archiv_id                = archiv_id
        document_type            = lw_doc_type
        path                     = lw_path
      IMPORTING
        archiv_doc_id            = i_toav0-arc_doc_id
      EXCEPTIONS
        error_archiv             = 1
        error_communicationtable = 2
        error_upload             = 3
        error_kernel             = 4
        OTHERS                   = 5.
    MOVE i_toav0 TO toav0.
    toav0-sap_object = lw_sap_object.
    toav0-object_id = key.
    MOVE archiv_id TO toav0-archiv_id.
    MOVE i_toav0-arc_doc_id TO toav0-arc_doc_id.
    toav0-ar_object = lw_ar_object.
    MOVE lw_doc_type TO toav0-reserve.
    MOVE lw_doc_type TO doc_type.
    COMMIT WORK.
* secondly insert this archive link
    CALL FUNCTION 'ARCHIV_CONNECTION_INSERT'
      EXPORTING
        archiv_id             = toav0-archiv_id
        arc_doc_id            = toav0-arc_doc_id
        ar_date               = ar_date
        ar_object             = toav0-ar_object
        object_id             = toav0-object_id
        sap_object            = toav0-sap_object
        doc_type              = doc_type
      EXCEPTIONS
        error_connectiontable = 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
      RAISING error_connectiontable.
    ELSE.
      lv_error = 1.
    ENDIF.
  ENDIF.
ENDFORM. " create_archive_object_new  

 Related Wiki  : SAP Mass Upload Program for Photo to Content Server