Monday, 18 January 2016

Gos_Attachment_upload Through program

*&---------------------------------------------------------------------*
*& Report  ZGOS_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zgos_test.


PARAMETERSp_key TYPE swo_typeid OBLIGATORY,
*p_type TYPE swo_objtyp OBLIGATORY,
p_file TYPE string,"c LENGTH 100 OBLIGATORY,
p_desc TYPE so_obj_des OBLIGATORY.

DATAls_fol_id   TYPE soodk,
      ls_obj_id   TYPE soodk,
      ls_obj_data TYPE sood1,
      ls_folmem_k TYPE sofmk,
      ls_note     TYPE borident,
      ls_object   TYPE borident,
      lv_ep_note  TYPE borident-objkey,
      lv_offset   TYPE i,
      lv_length   LIKE sy-tabix.


DATAit_objhead TYPE STANDARD TABLE OF soli,
      it_content LIKE STANDARD TABLE OF soli,
      wa_content LIKE soli.

ls_object-objkey p_key.
ls_object-objtype 'BUS1006'."p_type.

***TRY.
***    OPEN DATASET p_file FOR INPUT IN BINARY MODE.
***    WHILE sy-subrc = 0.
***      READ DATASET p_file INTO wa_content.
***      APPEND wa_content TO it_content.
***    ENDWHILE.
***    CLOSE DATASET p_file.
***  CATCH cx_sy_file_access_error.
***    MESSAGE 'Error reading file' TYPE 'E'.
***ENDTRY.




CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename   p_file
    filetype   'BIN'
  IMPORTING
    filelength lv_length
*   HEADER     =
  TABLES
    data_tab   it_content.





CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
  EXPORTING
    it_contents_bin it_content[]
  IMPORTING
    et_contents_bin it_content[].

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
  EXPORTING
    region    'B'
  IMPORTING
    folder_id ls_fol_id
  EXCEPTIONS
    OTHERS    1.

ls_obj_data-objsns 'O'.
ls_obj_data-objla sy-langu.
ls_obj_data-objdes p_desc.
lv_offset strlenp_file 3.
ls_obj_data-file_ext p_file+lv_offset(3).
ls_obj_data-objlen linesit_content 255.

CALL FUNCTION 'SO_OBJECT_INSERT'
  EXPORTING
    folder_id             ls_fol_id
    object_type           'EXT'
    object_hd_change      ls_obj_data
  IMPORTING
    object_id             ls_obj_id
  TABLES
    objhead               it_objhead
    objcont               it_content
  EXCEPTIONS
    active_user_not_exist 35
    folder_not_exist      6
    object_type_not_exist 17
    owner_not_exist       22
    parameter_error       23
    OTHERS                1000.

IF sy-subrc AND ls_object-objkey IS NOT INITIAL.
  ls_folmem_k-foltp ls_fol_id-objtp.
  ls_folmem_k-folyr ls_fol_id-objyr.
  ls_folmem_k-folno ls_fol_id-objno.
  ls_folmem_k-doctp ls_obj_id-objtp.
  ls_folmem_k-docyr ls_obj_id-objyr.
  ls_folmem_k-docno ls_obj_id-objno.
  lv_ep_note ls_folmem_k.
  ls_note-objtype 'MESSAGE'.
  ls_note-objkey lv_ep_note.
  CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
    EXPORTING
      obj_rolea    ls_object
      obj_roleb    ls_note
      relationtype 'ATTA'
    EXCEPTIONS
      OTHERS       1.
ELSE.
  MESSAGE 'Not OK' TYPE 'I'.
  RETURN.
ENDIF.

IF sy-subrc 0.
  MESSAGE 'OK' TYPE 'I'.
ELSE.
  MESSAGE 'Not OK' TYPE 'I'.
ENDIF.

Tuesday, 29 December 2015

First Letter Capital reming Small

    SELECT SINGLE mc_name1
                  mc_name2
          FROM but000 INTO l_but000
          WHERE partner = 'xxxxxxxx'.

      TRANSLATE l_but000-mc_name2+1(34to LOWER CASE.
      TRANSLATE l_but000-mc_name1+1(34to LOWER CASE.

    CONCATENATE l_but000-mc_name2 l_but000-mc_name1 INTO lv_bpname SEPARATED BY space.

Monday, 16 November 2015

Code sample to read and upload a file in application server

SELECTION-SCREEN BEGIN OF BLOCK block01
                WITH FRAME TITLE text-001.     "File Path
PARAMETERS: p_file LIKE  rlgrap-filename OBLIGATORY ,  "INPUT FILE PATH
            p_path LIKE rlgrap-filename OBLIGATORY .   "Output file path
 Providing F4 help for File path : 
AT SELECTION-SCREEN OUTPUT.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
**Providing F4 help for user to enter file name
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_file
    IMPORTING
      serverfile       = p_file
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE e009(zz) WITH p_file.
  ENDIF.
 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
**Providing F4 help for user to enter file name
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_path
    IMPORTING
      serverfile       = p_path
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc <> 0.
    MESSAGE e009(zz) WITH p_path.
  ENDIF.
 To read a file from Application server : 
DATA : lv_str(50) TYPE c.
 
*Read the data from application server
OPEN DATASET p_file FOR INPUT IN TEXT  MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
  MESSAGE e009(zz) WITH p_file.
 
ENDIF.
DO.
**Writing the data into internal table
  READ DATASET p_file INTO lv_str.
  IF sy-subrc = 0.
    SPLIT lv_str AT '#' INTO   gwa_file-f1
                               gwa_file-f2
                               gwa_file-f3
                               gwa_file-f4
                               gwa_file-f5
    append gwa_file to it_file.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET p_file.
 To Upload file back to application server : 
DATA : lv_filename TYPE rlgrap-filename,
      lv_file(60) TYPE c,
        lv_string(100) TYPE c ,
        c_con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
 
CONCATENATE p_path c_filename INTO lv_filename.
**Placing the file in Application server
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
**Displaying error message when file is unable to open
IF sy-subrc <> 0.
  MESSAGE e009(zz) WITH lv_filename.
 
ENDIF.
LOOP AT it_final INTO gwa_final.
 
  CONCATENATE gwa_file-f1
                               gwa_file-f2
                               gwa_file-f3
                               gwa_file-f4
                               gwa_file-f5
              INTO lv_string SEPARATED BY c_con_tab.
 
  TRANSFER lv_string   TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.