17 Ocak 2012 Salı

SAP/ABAP: Download excel template from selection screen








TYPE-POOLS: slis,
            icon,
            truxs.

TABLES sscrfields.

INCLUDE ole2incl.
DATA: h_excel TYPE ole2_object,        " Excel object
      h_mapl  TYPE ole2_object,        " list of workbooks
      h_map   TYPE ole2_object,        " workbook
      h_zl    TYPE ole2_object,        " cell
      h_f     TYPE ole2_object.        " font

SELECTION-SCREEN: PUSHBUTTON /2(40) xlsdesen USER-COMMAND but1.
AT SELECTION-SCREEN.
  CASE sscrfields.
    WHEN 'BUT1'.
      "PERFORM  sapgui_progress  USING  'Excel template downloading...'.
      PERFORM xls_template.
  ENDCASE.

FORM xls_template .


  DATA  h TYPE i VALUE 1.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
*     PERCENTAGE = 0
      text   = text-007
    EXCEPTIONS
      OTHERS = 1.
* start Excel
  CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
  PERFORM err_hdl.
  SET PROPERTY OF h_excel  'Visible' = 1.
  PERFORM err_hdl.
* tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
*     PERCENTAGE = 0
      text   = text-008
    EXCEPTIONS
      OTHERS = 1.
* get list of workbooks, initially empty
  CALL METHOD OF h_excel 'Workbooks' = h_mapl.
  PERFORM err_hdl.
* add a new workbook
  CALL METHOD OF h_mapl 'Add' = h_map.
  PERFORM err_hdl.
* tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
*     PERCENTAGE = 0
      text   = text-009
    EXCEPTIONS
      OTHERS = 1.
* output column headings to active Excel sheet
  PERFORM fill_cell USING 1 1 1   'Account Number of Vendor or Creditor'.
  PERFORM fill_cell USING 1 2 1   'Material Number'.
  PERFORM fill_cell USING 1 3 1   'Purchasing Organization'.
  PERFORM fill_cell USING 1 4 1   'Plant'.
  PERFORM fill_cell USING 1 5 1   'Purchasing info record category'.
  PERFORM fill_cell USING 1 6 1   'Base Unit of Measure'.
  PERFORM fill_cell USING 1 7 1   'Numerator for Conversion to Base Units of Measure'.
  PERFORM fill_cell USING 1 8 1   'Denominator for conversion to base units of measure'.
  PERFORM fill_cell USING 1 9 1   'Material Number Used by Vendor'.
  PERFORM fill_cell USING 1 10 1  'Salesperson Responsible in the Event of Queries'.
  PERFORM fill_cell USING 1 11 1  'First telephone number'.
  PERFORM fill_cell USING 1 12 1  'Country Key'.
  PERFORM fill_cell USING 1 13 1  'Region (State, Province, County)'.
  PERFORM fill_cell USING 1 14 1  'Purchasing Group'.
  PERFORM fill_cell USING 1 15 1  'Currency Key'.
  PERFORM fill_cell USING 1 16 1  'Minimum Purchase Order Quantity'.
  PERFORM fill_cell USING 1 17 1  'Standard Purchase Order Quantity'.
  PERFORM fill_cell USING 1 18 1  'Planned Delivery Time in Days'.
  PERFORM fill_cell USING 1 19 1  'Net price'.
  PERFORM fill_cell USING 1 20 1  'Price Unit'.
  PERFORM fill_cell USING 1 21 1  'Order Price Unit (Purchasing)'.
  PERFORM fill_cell USING 1 22 1  'Date of last forecast'.
  PERFORM fill_cell USING 1 23 1  'Numerator for Conversion of Order Price Unit into Order Unit'.
  PERFORM fill_cell USING 1 24 1  'Denominator for Conv. of Order Price Unit into Order Unit'.
  PERFORM fill_cell USING 1 25 1  'Indicator: GR-Based Invoice Verification'.
  PERFORM fill_cell USING 1 26 1  'Order Acknowledgment Requirement'.
  PERFORM fill_cell USING 1 27 1  'Tax on sales/purchases code'.
  PERFORM fill_cell USING 1 28 1  'Confirmation Control Key'.
  PERFORM fill_cell USING 1 29 1  'Price Determination (Pricing) Date Control'.
  PERFORM fill_cell USING 1 30 1  'Maximum Lot Size'.
  PERFORM fill_cell USING 1 31 1  'Period Indicator for Shelf Life Expiration Date'.
  PERFORM fill_cell USING 1 32 1  'Material Number Used by Vendor'.
  PERFORM fill_cell USING 1 33 1  'Second Tier Process InfRec  '.

  FREE OBJECT h_excel.
  PERFORM err_hdl.
  MESSAGE 'Excel template downloaded...' TYPE 'W'.

ENDFORM.
FORM fill_cell USING i j bold val.
  CALL METHOD OF h_excel 'Cells' = h_zl EXPORTING #1 = i #2 = j.
  PERFORM err_hdl.
  SET PROPERTY OF h_zl 'Value' = val .
  PERFORM err_hdl.
  GET PROPERTY OF h_zl 'Font' = h_f.
  PERFORM err_hdl.
  SET PROPERTY OF h_f 'Bold' = bold .
  PERFORM err_hdl.
ENDFORM.                    "FILL_CELL

FORM err_hdl.
  IF sy-subrc <> 0.
    WRITE: / 'A problem occured'(010), sy-subrc.
    STOP.
  ENDIF.
ENDFORM.                    " ERR_HDL

11 Ocak 2012 Çarşamba

3 Ocak 2012 Salı

SAP/ABAP: SO_NAME_CONVERT FM

Vay annassını, fonksiyona gel…
DATA:  USER_DATA LIKE SOUD3.

MOVE SY-UNAME TO USER_DATA-SAPNAM.

CALL FUNCTION 'SO_NAME_CONVERT'
EXPORTING
NAME_IN               = USER_DATA
IMPORTING
NAME_OUT              = USER_DATA
EXCEPTIONS
OFFICE_NAME_NOT_EXIST = 1
PARAMETER_ERROR       = 2
SAP_NAME_NOT_EXIST    = 3
USER_NOT_EXIST        = 4.
IF SY-SUBRC NE 0.

ENDIF.

WRITE: USER_DATA-SAPNAM,
USER_DATA-USRNAM,
USER_DATA-OCSNAM,
USER_DATA-USRTP,
USER_DATA-USRYR,
USER_DATA-USRNO,
USER_DATA-ADRNAME.

2 Ocak 2012 Pazartesi

SAP/ABAP: Field Symbol performans

*&---------------------------------------------------------------------*
*& Report  ZFS_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZFS_TEST.

*Field Symbol ile Work Area performans testi

DATA: LT_MAKT TYPE TABLE OF MAKT,
      LS_MAKT TYPE MAKT.

DATA: LV_FLAG TYPE FLAG,

      LV_BEGIN_TIME TYPE TIMESTAMPL,
      LV_ENDIN_TIME TYPE TIMESTAMPL,

      LV_WA_FARKI TYPE P DECIMALS 5,
      LV_FS_FARKI TYPE P DECIMALS 5,
      LV_FARK     TYPE P DECIMALS 5.

FIELD-SYMBOLS: <FS_MAKT> LIKE LINE OF LT_MAKT.

SELECT *
  FROM MAKT
  INTO TABLE LT_MAKT
  UP TO 100 ROWS.

*Work Area
GET TIME STAMP FIELD LV_BEGIN_TIME.

LOOP AT LT_MAKT INTO LS_MAKT.
  IF LV_FLAG EQ 'X'.
    LS_MAKT-MAKTX = 'Değiştirdim'.
    MODIFY LT_MAKT FROM LS_MAKT.
  ENDIF.
  CLEAR: LS_MAKT.
  IF LV_FLAG IS INITIAL.
    LV_FLAG = 'X'.
  ENDIF.
ENDLOOP.

GET TIME STAMP FIELD LV_ENDIN_TIME.
*--------------------------------------------------------------------*
LV_WA_FARKI = LV_ENDIN_TIME - LV_BEGIN_TIME.
*--------------------------------------------------------------------*

CLEAR: LV_FLAG,
       LV_BEGIN_TIME,
       LV_ENDIN_TIME.

*Field-Symbol
GET TIME STAMP FIELD LV_BEGIN_TIME.

LOOP AT LT_MAKT ASSIGNING <FS_MAKT>.
  IF LV_FLAG EQ 'X'.
    <FS_MAKT>-MAKTX = 'Değiştirdim'.
  ENDIF.
  IF LV_FLAG IS INITIAL.
    LV_FLAG = 'X'.
  ENDIF.
ENDLOOP.

GET TIME STAMP FIELD LV_ENDIN_TIME.
*--------------------------------------------------------------------*
LV_FS_FARKI = LV_ENDIN_TIME - LV_BEGIN_TIME.
*--------------------------------------------------------------------*

*Work Area ile Field Symbol farkı;
LV_FARK = LV_WA_FARKI - LV_FS_FARKI.

WRITE: /(10) 'WA Performansı', LV_WA_FARKI.
WRITE: /(10) 'FS Performansı', LV_FS_FARKI.
WRITE: /(10) 'Kârımız', LV_FARK.

"

İnsdroid

Sabahtan beri çatada çutada çatada çutada… Bitmedi yine de… Neyse, yolumuz uzun, toparlıyorum çantamı, adaptörü falan tıkıştırıyorum bir şe...