Monday 21 November 2011

Program to Download the graphics from SAP(give the sap logo name and file path to download)

REPORT z_download_graphic_image.
DATA : g_bytecount             TYPE i,
       g_content               TYPE STANDARD TABLE OF
                                    bapiconten INITIAL SIZE 0,
       g_bitmap_file_bytecount TYPE i,
       g_file_name             TYPE string,
       BEGIN OF g_bitmap_file OCCURS 0,
        line(255TYPE x,
       END OF g_bitmap_file,
       l_bitmaps TYPE TABLE OF stxbitmaps WITH HEADER LINE,
       lit_scrfields TYPE TABLE OF dynpread WITH HEADER LINE.
PARAMETER: p_image LIKE  stxbitmaps-tdname
                   DEFAULT 'ENJOY'"name of the image
           p_file  LIKE  ibipparms-path
                   DEFAULT 'H:\My Documents\enjoy.bmp'.
" Download File path
*F4 help to get file path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.
*F4 help search for image files
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_image.
  CALL FUNCTION 'SAPSCRIPT_SEARCH_GRAPHIC_BDS'
    EXPORTING
      selection_screen   = 'X'
      select_entry       = 'X'
      selection_show     = 'X'
    IMPORTING
      e_name             = p_image
    TABLES
      t_selections       = l_bitmaps
    EXCEPTIONS
      nothing_found      = 1
      selection_canceled = 2
      internal_error     = 3
      OTHERS             = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
START-OF-SELECTION.
  MOVE p_file TO g_file_name.
*Get graphics to BDS
  CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
    EXPORTING
      i_object       = 'GRAPHICS'
      i_name         = p_image
      i_id           = 'BMAP'
      i_btype        = 'BCOL'
    IMPORTING
      e_bytecount    = g_bytecount
    TABLES
      content        = g_content
    EXCEPTIONS
      not_found      = 1
      bds_get_failed = 2
      bds_no_content = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    MESSAGE i208(00WITH 'Image does not exists.'(000).
  ENDIF.
  IF NOT g_content[] IS INITIAL.
*Convert to BITMAP
    CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
      EXPORTING
        old_format               = 'BDS'
        new_format               = 'BMP'
        bitmap_file_bytecount_in = g_bytecount
      IMPORTING
        bitmap_file_bytecount    = g_bitmap_file_bytecount
      TABLES
        bds_bitmap_file          = g_content
        bitmap_file              = g_bitmap_file
      EXCEPTIONS
        OTHERS                   = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
*Download to PC
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        bin_filesize            = g_bitmap_file_bytecount
        filename                = g_file_name
        filetype                = 'BIN'
      TABLES
        data_tab                = g_bitmap_file
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.

Wednesday 16 November 2011

To give the color properties to ALV output and download to local file

Please implement the following program, this will color the second cell of the second line in the ALV grid. It should show you what you need.


report zrich_0004
       no standard page heading.
 
type-pools slis.
 
data: fieldcat type slis_t_fieldcat_alv.
 
data: begin of imara occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      tcolor type slis_t_specialcol_alv,
      end of imara.
 
data: xcolor type slis_specialcol_alv.
 
start-of-selection.
 
  perform get_data.
  perform write_report.
 
 
************************************************************************
*  Get_Data
************************************************************************
form get_data.
 
imara-matnr = 'ABC'.
imara-maktx = 'This is description for ABC'.
append imara.
 
imara-matnr = 'DEF'.
imara-maktx = 'This is description for DEF'.
append imara.
 
  loop at imara.
 
    if sy-tabix = 2.
      clear xcolor.
      xcolor-fieldname = 'MAKTX'.
      xcolor-color-col = '3'.
      xcolor-color-int = '1'. "Intensified on/off
      xcolor-color-inv = '0'.
 
      append xcolor to imara-tcolor.
 
 
      modify imara.
    endif.
 
  endloop.
 
endform.
 
************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.
 
  data: layout type  slis_layout_alv.
 
  layout-coltab_fieldname = 'TCOLOR'.
 
 
  perform build_field_catalog.
 
* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            is_layout   = layout
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.
 
endform.
 
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
 
  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.
 
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.
 
endform.
 


If you continue having problems, please post the full code.