YFIR_AUTO_REFRESH

SAP/ABAP 개발 2011. 1. 17. 10:10 Posted by KindKay



  *&------------------------------------------------------------------*
*& Report  YFIR_AUTO_REFRESH
*&
*&------------------------------------------------------------------*
*&
*&
*&------------------------------------------------------------------*



REPORT  YFIR_AUTO_REFRESH.

DATA: G_INIT_ONCE,
      OK_CODE(20),
      G_REF_FROM_TIMER.

DATA: BEGIN OF ITAB OCCURS 0,
        CARRID TYPE SPFLI-CARRID,
        CONNID TYPE SPFLI-CONNID,
        COUNTRYFR TYPE SPFLI-COUNTRYFR,
        CITYFROM TYPE SPFLI-CITYFROM,
        AIRPFROM TYPE SPFLI-AIRPFROM,
        COUNTRYTO TYPE SPFLI-COUNTRYTO,
        CITYTO TYPE SPFLI-CITYTO,
        AIRPTO TYPE SPFLI-AIRPTO,
        FLTIME TYPE SPFLI-FLTIME,
        DEPTIME TYPE SPFLI-DEPTIME,
        ARRTIME TYPE SPFLI-ARRTIME,
        DISTANCE TYPE SPFLI-DISTANCE,
        DISTID TYPE SPFLI-DISTID,
        FLTYPE TYPE SPFLI-FLTYPE,
        PERIOD TYPE SPFLI-PERIOD,
      END OF ITAB.


IF G_INIT_ONCE <> 'X'.
  G_INIT_ONCE = 'X'.
  CALL FUNCTION 'Z_ENQUE_SLEEP'
     STARTING NEW TASK 'WAIT'
     PERFORMING WHEN_FINISHED ON END OF TASK.

ENDIF.

WRITE:/ 'wait for 10 sec....'.

AT USER-COMMAND.
  CASE OK_CODE.
    WHEN 'FCT_R'.
      SELECT FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE ITAB.
      WRITE:/ SY-UZEIT.
      LOOP AT ITAB.
        WRITE:/ ITAB-CARRID,ITAB-CONNID.
      ENDLOOP.
      SY-LSIND = 0.
      IF G_REF_FROM_TIMER = 'X'.

        CALL FUNCTION 'Z_ENQUE_SLEEP'
          STARTING NEW TASK 'INFO'
          PERFORMING WHEN_FINISHED ON END OF TASK.

        G_REF_FROM_TIMER = ''.
      ENDIF.
  ENDCASE.


*---------------------------------------------------------------------*
*       FORM WHEN_FINISHED                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  TASKNAME                                                      *
*---------------------------------------------------------------------*
FORM WHEN_FINISHED USING TASKNAME.
  RECEIVE RESULTS FROM FUNCTION 'Z_ENQUE_SLEEP'.

  G_REF_FROM_TIMER = 'X'.

* Trigger an event to run the at user-command
  SET USER-COMMAND 'FCT_R'.
  OK_CODE = 'FCT_R'.
  SY-UCOMM = 'FCT_R'.

ENDFORM.                    " WHEN_FINISHED
 



FUNCTION Z_ENQUE_SLEEP.
*"-------------------------------------------------------------------
*"*"Local Interface:
*"-------------------------------------------------------------------

  CALL FUNCTION 'ENQUE_SLEEP'
    EXPORTING
      SECONDS = 10.

ENDFUNCTION.


'SAP > ABAP 개발' 카테고리의 다른 글

[PP] AFRU table data - taking long time to access  (1) 2011.01.13
CDHDR - Change Document Header Table  (1) 2010.12.23
SM58 - Transactional RFC  (1) 2010.12.22
BAPI_GOODSMVT_CREATE-ABAP  (3) 2010.11.30
Search help exit  (1) 2010.11.17

Your query is simple but quite bad in terms of performance.

Change it to something like:

SELECT [...]
FROM afko 
INNER JOIN afvc ON afko~aufpl = afvc~aufpl
INNER JOIN afru ON afvc~rueck = afru~rueck
WHERE afko~aufnr = [...]


For more information you can check OSS note 187906 Performance: Customer developments in PP and PM.

출처: http://forums.sdn.sap.com/thread.jspa?threadID=1434770



  clear: lv_xmnga_c.
    select sum( a~xmnga )
      into lv_xmnga_c
      from afru as a inner join afvc as b
                             on a~rueck eq b~rueck
                            and b~aufpl eq gt_itab-aufpl
     where aufnr eq gt_itab-aufnr
       and stokz eq space.

    clear: lv_xmnga_d.
    select sum( a~xmnga )
      into lv_xmnga_d
      from afru as a inner join afvc as b
                             on a~rueck eq b~rueck
                            and b~aufpl eq gt_itab-aufpl
     where aufnr eq gt_itab-aufnr
       and stokz eq 'X'.

    gt_itab-xmnga = lv_xmnga_c - lv_xmnga_d.



'SAP > ABAP 개발' 카테고리의 다른 글

YFIR_AUTO_REFRESH  (1) 2011.01.17
CDHDR - Change Document Header Table  (1) 2010.12.23
SM58 - Transactional RFC  (1) 2010.12.22
BAPI_GOODSMVT_CREATE-ABAP  (3) 2010.11.30
Search help exit  (1) 2010.11.17

CDHDR - Change Document Header Table

SAP/ABAP 개발 2010. 12. 23. 23:53 Posted by KindKay

'SAP > ABAP 개발' 카테고리의 다른 글

YFIR_AUTO_REFRESH  (1) 2011.01.17
[PP] AFRU table data - taking long time to access  (1) 2011.01.13
SM58 - Transactional RFC  (1) 2010.12.22
BAPI_GOODSMVT_CREATE-ABAP  (3) 2010.11.30
Search help exit  (1) 2010.11.17

SM58 - Transactional RFC

SAP/ABAP 개발 2010. 12. 22. 00:01 Posted by KindKay

'SAP > ABAP 개발' 카테고리의 다른 글

[PP] AFRU table data - taking long time to access  (1) 2011.01.13
CDHDR - Change Document Header Table  (1) 2010.12.23
BAPI_GOODSMVT_CREATE-ABAP  (3) 2010.11.30
Search help exit  (1) 2010.11.17
WHERE - (cond_syntax)  (3) 2010.11.17

BAPI_GOODSMVT_CREATE-ABAP

SAP/ABAP 개발 2010. 11. 30. 13:09 Posted by KindKay

Description:

Example for BAPI_GOODSMVT_CREATE(To Post Goods Movement).

The following is an abap program making used of the BAPI function BAPI_GOODSMVT_CREATE to do Goods Receipts for Purchase Order after importing the data from an external system.

*BAPI TO Upload Inventory Data
*

*GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*                      02 - MB31 - Goods Receipts for Prod Order
*                      03 - MB1A - Goods Issue
*                      04 - MB1B - Transfer Posting
*                      05 - MB1C - Enter Other Goods Receipt
*                      06 - MB11
*

Domain: KZBEW - Movement Indicator
*      Goods movement w/o reference
*  B - Goods movement for purchase order
*  F - Goods movement for production order
*  L - Goods movement for delivery note
*  K - Goods movement for kanban requirement (WM - internal only)
*  O - Subsequent adjustment of "material-provided" consumption
*  W - Subsequent adjustment of proportion/product unit material
*
report zbapi_goodsmovement.

parameters: p-file like rlgrap-filename default
                                 'c:\sapdata\TEST.txt'.
parameters: e-file like rlgrap-filename default
                                 'c:\sapdata\gdsmvterror.txt'.

parameters: xpost like sy-datum default sy-datum.

data: begin of gmhead.
        include structure bapi2017_gm_head_01.
data: end of gmhead.

data: begin of gmcode.
        include structure bapi2017_gm_code.
data: end of gmcode.

data: begin of mthead.
        include structure bapi2017_gm_head_ret.
data: end of mthead.

data: begin of itab occurs 100.
        include structure bapi2017_gm_item_create.
data: end of itab.

data: begin of errmsg occurs 10.
        include structure bapiret2.
data: end of errmsg.

data: wmenge like iseg-menge,
      errflag.

data: begin of pcitab occurs 100,
        ext_doc(10),           "External Document Number
        mvt_type(3),           "Movement Type
        doc_date(8),           "Document Date
        post_date(8),          "Posting Date
        plant(4),              "Plant
        material(18),          "Material Number
        qty(13),               "Quantity
        recv_loc(4),           "Receiving Location
        issue_loc(4),          "Issuing Location
        pur_doc(10),           "Purchase Document No
        po_item(3),            "Purchase Document Item No
        del_no(10),            "Delivery Purchase Order Number
        del_item(3),           "Delivery Item
        prod_doc(10),          "Production Document No
        scrap_reason(10),      "Scrap Reason
        upd_sta(1),            "Update Status
      end of pcitab.

call function 'WS_UPLOAD'
  exporting
    filename                      = p-file
    filetype                      = 'DAT'

IMPORTING
*   FILELENGTH                    =
  tables
    data_tab                      = pcitab

EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
          .
if sy-subrc <> 0.
  message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  exit.
endif.

gmhead-pstng_date = sy-datum.
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '01'.   "01 - MB01 - Goods Receipts for Purchase Order

loop at pcitab.
  itab-move_type  = pcitab-mvt_type.
  itab-mvt_ind    = 'B'.
  itab-plant      = pcitab-plant.
  itab-material   = pcitab-material.
  itab-entry_qnt  = pcitab-qty.
  itab-move_stloc = pcitab-recv_loc.
  itab-stge_loc   = pcitab-issue_loc.
  itab-po_number  = pcitab-pur_doc.
  itab-po_item    = pcitab-po_item.
  concatenate pcitab-del_no pcitab-del_item into itab-item_text.
  itab-move_reas  = pcitab-scrap_reason.

  append itab.
endloop.

loop at itab.
  write:/ itab-material, itab-plant, itab-stge_loc,
          itab-move_type, itab-entry_qnt, itab-entry_uom,
          itab-entry_uom_iso, itab-po_number, itab-po_item,
                                              pcitab-ext_doc.
endloop.

call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header             = gmhead
    goodsmvt_code               = gmcode
*   TESTRUN                     = ' '

IMPORTING
    goodsmvt_headret            = mthead
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  tables
    goodsmvt_item               = itab
*   GOODSMVT_SERIALNUMBER       =
    return                      = errmsg
          .
clear errflag.
loop at errmsg.
  if errmsg-type eq 'E'.
    write:/'Error in function', errmsg-message.
    errflag = 'X'.
  else.
    write:/ errmsg-message.
  endif.
endloop.

if errflag is initial.
  commit work and wait.
  if sy-subrc ne 0.
    write:/ 'Error in updating'.
    exit.
  else.
    write:/ mthead-mat_doc, mthead-doc_year.
    perform upd_sta.
  endif.
endif.

---------------------------------------------------------------------
*       FORM UPD_STA                                                  *
---------------------------------------------------------------------
*       ........                                                      *
---------------------------------------------------------------------
form upd_sta.
  loop at pcitab.
    pcitab-upd_sta = 'X'.
    modify pcitab.
  endloop.

  call function 'WS_DOWNLOAD'
    exporting
      filename                      = p-file
      filetype                      = 'DAT'

IMPORTING
*   FILELENGTH                    =
    tables
      data_tab                      = pcitab

EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   OTHERS                        = 6
            .

endform.

*- *- *-- End of Program


출처: http://wiki.sdn.sap.com/wiki/display/Snippets/BAPI_GOODSMVT_CREATE-ABAP

'SAP > ABAP 개발' 카테고리의 다른 글

CDHDR - Change Document Header Table  (1) 2010.12.23
SM58 - Transactional RFC  (1) 2010.12.22
Search help exit  (1) 2010.11.17
WHERE - (cond_syntax)  (3) 2010.11.17
Function Module to handle Special Character (특수문자 관련)  (1) 2010.11.05

Search help exit

SAP/ABAP 개발 2010. 11. 17. 09:50 Posted by KindKay





  function zpp_wooden_f4_help_exit.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     REFERENCE(SHLP) TYPE  SHLP_DESCR
*"     REFERENCE(CALLCONTROL) TYPE  DDSHF4CTRL
*"----------------------------------------------------------------------

  data: lv_matnr  type matnr,
        lv_aufnr  type aufnr,
        lv_maktx  type maktx,
        lv_inch   like ztpp1140-inch01,
        lv_width  like ztpp1140-width01,
        lv_height like ztpp1140-height01,
        lv_char.

  clear: lv_matnr, lv_maktx, lv_aufnr.

  case sy-tcode.
    when 'CO01' or 'CO01' or 'CO01'.
      get parameter id 'MAT' field lv_matnr.
      get parameter id 'ANR' field lv_aufnr.

    when others.
      clear: lv_matnr, lv_maktx, lv_aufnr.
  endcase.

  if callcontrol-step = 'PRESEL1'.
    clear: g_check_first.
    return.
  endif.

  check lv_matnr is not initial or lv_aufnr is not initial.

  if lv_matnr is initial.
    select single matnr
      into lv_matnr
      from afpo
     where aufnr eq lv_aufnr.
  endif.

  select single maktx
    into lv_maktx
    from makt
   where matnr eq lv_matnr
     and spras eq sy-langu.

  if lv_maktx cs 'RTC'.
    clear: lv_char.
    call function 'ZPP_GETCHAR_SHIFT_LEFT'
      exporting
        i_matnr       = lv_matnr
        i_left        = 5
      importing
        e_char        = lv_char.

    if lv_char ne 'E'.
      clear: record_tab[].
      return.
    endif.
  else.
    clear: record_tab[].
    return.
  endif.

  call function 'F4UT_OPTIMIZE_COLWIDTH'
    tables
      shlp_tab = shlp_tab
      record_tab = record_tab
    changing
      shlp = shlp
      callcontrol = callcontrol.

  data: lt_ztpp1130   like table of ztpp1130 with header line,
        ls_record_tab like seahlpres.

  data: lt_ddshselops type table of ddshselopt.

  if callcontrol-step = 'SELECT'.
    perform get_characteristic using lv_matnr
                            changing lv_inch
                                     lv_width
                                     lv_height.

    clear: lt_ddshselops[].
    lt_ddshselops[] = shlp-selopt[].

    if lt_ddshselops[] is initial and g_check_first is initial.
      if lv_inch is not initial.
        perform append_model_selopt  tables lt_ddshselops
                                      using 'INCH01' lv_inch.

        perform append_model_selopt  tables lt_ddshselops
                                      using 'WIDTH01' lv_width.

        perform append_model_selopt  tables lt_ddshselops
                                      using 'HEIGHT01' lv_height.
      endif.

      shlp-selopt[] = lt_ddshselops[].
      g_check_first = 'X'.
    endif.

  endif.

endfunction.

WHERE - (cond_syntax)

SAP/ABAP 개발 2010. 11. 17. 08:15 Posted by KindKay

    data: cond_syntax type string.

  clear: cond_syntax

  case pa_werks.
    when 'P100'.
      lr_vstel-low = 'H110'.
      concatenate ' ( D~AUART LIKE ' '''' 'ZCD%' ''''
             into cond_syntax.
      concatenate cond_syntax 'OR D~AUART LIKE ' '''' 'ZEX%' ''''
             into cond_syntax.
      concatenate cond_syntax 'OR D~AUART LIKE ' '''' 'ZFB%' ''''
             into cond_syntax.
      concatenate cond_syntax 'OR D~AUART LIKE ' '''' 'ZFD%' ''''
             into cond_syntax.
      concatenate cond_syntax 'OR D~AUART LIKE ' '''' 'ZOR%' '''' ' )'
             into cond_syntax.
    when 'P200'.
      lr_vstel-low = 'H210'.
      concatenate ' D~AUART EQ ' '''' 'ZA1' ''''
             into cond_syntax.
  endcase.

  select a~edatu c~kunnr  a~vbeln a~posnr b~route
         b~matnr b~kwmeng b~zieme b~werks a~wmeng
    into corresponding fields of table gt_base
    from vbep as a inner join vbap as b
                           on a~vbeln eq b~vbeln
                          and a~posnr eq b~posnr
                   inner join vbpa as c
                           on a~vbeln eq c~vbeln
                          and c~parvw eq 'WE'     "Ship-to-party(SH)
                   inner join vbak as d
                           on a~vbeln eq d~vbeln
                   inner join mara as e
                           on b~matnr eq e~matnr
   where a~edatu in s_edatu
     and a~vbeln in s_vbeln
     and b~matnr in s_matnr
     and c~kunnr in s_kunnr
     and b~kwmeng ne ''
     and (cond_syntax).



Use these FM.

SCP_REPLACE_STRANGE_CHARS

SF_SPECIALCHAR_DELETE

'SAP > ABAP 개발' 카테고리의 다른 글

Search help exit  (1) 2010.11.17
WHERE - (cond_syntax)  (3) 2010.11.17
ALV Object Model - Simple 2D Table - The Basics  (1) 2010.11.04
ABAP Code Sample for ALV Grid  (1) 2010.11.03
ABAP ALV Grid Control  (1) 2010.11.02

'SAP > ABAP 개발' 카테고리의 다른 글

WHERE - (cond_syntax)  (3) 2010.11.17
Function Module to handle Special Character (특수문자 관련)  (1) 2010.11.05
ABAP Code Sample for ALV Grid  (1) 2010.11.03
ABAP ALV Grid Control  (1) 2010.11.02
NUMBER RANGE 사용법  (2) 2010.10.31

ABAP Code Sample for ALV Grid

SAP/ABAP 개발 2010. 11. 3. 17:04 Posted by KindKay