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

Scheduling background job by triggering an event

SAP 2011. 1. 17. 10:02 Posted by KindKay

Step1: Create event from transaction SM62.


 
Give event name and description and press save button
 

 
 
Step2: Create a program that triggers this event by calling the FM 'BP_EVENT_RAISE'.

*&---------------------------------------------------------------------*
*& Report  Z_TRIGGER_EVENT                                             *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  Z_TRIGGER_EVENT                         .


CALL FUNCTION 'BP_EVENT_RAISE'
  EXPORTING
    eventid                      = 'Z_TRIGGER_JOB'
 EXCEPTIONS
   BAD_EVENTID                  = 1
   EVENTID_DOES_NOT_EXIST       = 2
   EVENTID_MISSING              = 3
   RAISE_FAILED                 = 4
   OTHERS                       = 5
          .
IF sy-subrc <> 0.
 Write: 'Event failed to trigger'.
else.
 Write: 'Event triggered'.
ENDIF.


Step3: Configure the background job from transaction SM36.

In the initial screen give job name and job class and press "Start condition" button.
 
In the popup screen press "After event" button and give the event name and then press save button.

Now go back to the initial screen and press "Step" button

Provide program and variant name and after providing all the values press save button.

In the initial screen press save button.

 
Step4: Now execute the program to trigger the event and as well check the background job.
 
Run transaction SM37
 
Check the status of job created by the program.
 
Now check the spool to see the generated list



출처: http://wiki.sdn.sap.com/wiki/display/ABAP/Scheduling+background+job+by+triggering+an+event

'SAP' 카테고리의 다른 글

How to maintain and monitor background jobs via SAP  (1) 2011.01.17
SAP Event  (5) 2011.01.17
SCC1 - Copy by Transport Request  (1) 2010.11.24
ALV Buffer Reset  (1) 2010.11.16
PP - Long-Term Planning  (2) 2010.09.22

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