How to maintain and monitor background jobs via SAP

SAP 2011. 1. 17. 11:53 Posted by KindKay

Creating a Background (Batch) Job in SAP

  1. To create a background job in SAP, enter the Define Background Job screen by using transaction code  SM36 or menu path System ® Services ® Background jobs ® Job definition.
  2. Enter a descriptive job name in the Job name field.  See document 15020 for naming conventions and reference.
  3. Enter the background job priority in the Job class field.  The different priority levels, from highest to lowest, are A, B, and C.  The job class determines how the background jobs are queued.  Jobs that are absolutely crucial should be classified as A, those that must run, but can be delayed without causing great disruption to operations should be classified as B, and jobs that the least imperitive to business functions (such as most reports, for example) should be classified as C.
  4. Enter the host (server) that will run the background job in the Target host field.  Click the down arrow on the right side of the field to get a listing of possible entries.  If this field is empty, the job will run on the host (server) that you are logged into.
  5. To schedule the background job, click on the Start time pushbutton.  This will bring up the Start Time pop-up window.
  6. There are several scheduling options:
  • Immediate   This option will be used on several occasions:   

      - When a job is run on request by a user.

      - When a job fails and must be restarted.

      - For some monthend jobs or jobs with dependencies on other platforms, they may need

      to be run when resources are available, or there predesessor jobs finish.

  • Date/Time   The date and time the job will release.  It may not start until resources are            available.  If a job is scheduled to be periodic, it will release at that time the next day,       week, month, etc based on the selected period.
  • After job      Jobs with dependencies will be scheduled to release upon completion of its       predecessor.  A status indicator may be checked.  If it is, the successor job will only release if the predecessor finishes completeley.
  • After event  Jobs may be set to release after pre-defined events are raised.  These events can           be coded into ABAP/4 programs.
  • At operation mode    These jobs will release when operation mode switching completes.  This would be useful  if many batch jobs need to be released around the same time.  They can be set to release when the operation mode switches a number of dialogue sessions to batch, ensuring adequate resources.

To schedule the background job according to one of the options, click the corresponding pushbutton at the top of the window.  After the selection, the appropriate entry fields will become active in the window.  The two most common options will probably be Immediate and Date/Time.

To schedule a background job to run immediately, click the Immediate pushbutton, and then the active Save button.  No additional entries are required.

To schedule a background job according to a specific date and time, click the Date/Time pushbutton.  Several fields will appear.  Enter the desired values in the Scheduled start fields.  Entries in these fields are required.  The background job will be released at this data and time but may wait in a queue.  To prevent a job waiting in the queue from running after a certain time, enter the desired values in the No start after fields.  The values in the Date fields should follow the default format for the login ID used.  (To determine this format, use transaction SU50 or menu path System ® User profile ® User defaults to see the user defaults.)  The values in the Time fields should be in military format.

When either the Immediate or Date/Time options are chosen, the Periodic job click box will appear at the bottom of the screen.  Click this box if you want to run this job at periodic intervals.  Options for periodic scheduling appear when the Period values pushbutton is clicked.  The background job will run at periodic intervals after the first background job runs.  In addition, a Restrictions pushbutton will appear.  In the Restrictions window, there are several options.  Click only on workdays to limit the days the job releases on.   You limit these days by specifying a calendar at the bottom of the window.  Separate calendars for Monday to Friday, Monday to Saturday, Everyday, and others will be created.  One of four buttons must also be set.  Always Execute will cause the job to releasee according to its period valued REGARDLESS OF ANY WORKDAY/CALENDAR RESTRICTIONS.  This is the default value, but it should almost always be changed.  Cancel Job will simply cancel the job on non-workdays.  Move to previous day will release the job on the workday previous to the date determined by the period value.  Move to next workday will release the job on the next available workday. To schedule a background according to the other options, use the F1 function key to obtain more information.

  1. After entering all the scheduling information, click the Save pushbutton.  This will bring back the Define Background Job screen.
  2. Click the Steps pushbutton to bring up the Step List and Create Step 1 windows.  These windows define the program(s) that will run in the background. 
  3. To run an ABAP/4 program, click the ABAP/4 pushbutton. 

10.  Enter the name of the ABAP/4 program in the Name field and, if necessary, enter the variant in the Variant field.  A variant specifies the set of parameters that an SAP program needs to execute.  To get a list of variants that have been created for a program click the Variant list pushbutton.  (Variants may defined in the ABAP/4 Program Development: Initial Screen using transaction code SE38 or menu path Tools ® CASE ® Development ® Program maintenance ® ABAP/4 development.) 

11.  When an ABAP/4 program uses write statements, these write statements are printed, rather than displayed on a screen , when the program runs in the background.  The print job will use the print specifications of the login ID used.  (To determine these specifications, use transaction SU50 or menu path System ® User profile ® User defaults to see the user defaults.)  To change the print specifications, such as the printer, click the Print specifications pushbutton.

12.  Note that external programs on the UNIX platform may be executed using the SAP scheduler.  This will probably not be too common, but to do so, click the External program pushbutton.  Enter the information in the Name and Parameter fields.  For more information, use the F1 function key.

13.  Once the background program has been defined, click the Save pushbutton.  This will save one “step,”  which will now appear on the Step List screen.

14.  A background job may execute more than one program.  To specify additional programs, click the Create pushbutton on the Step List screen and repeat numbers 9 through 13 above for the Create Step 2 screen and so on.  The Step List screen also allows the list of programs for a background job to be changed using the different pushbuttons at the top.

15.  After the programs for a background job have been completely specified, click the icon with the green arrow to return to the original Define Background Job screen.

16.  Click the Save (yellow folder) icon to save the background job definition and submit it.

Maintaining and Monitoring Scheduled Background Jobs

  1. To maintain or monitor SAP background jobs, enter the Select Background Jobs screen by using transaction code  SM37 or menu path System ® Services ® Background jobs ® Job overview.  The window is a selection screen.  A listing of background jobs will appear according to this window.
  2. The following fields are available to query all background jobs.
  • Job name - To find a particular job, enter the job name in this field.  To find all job names, enter *.
  • User name - To find jobs created by a particular user, enter the user ID in this field.  To find jobs by all users, enter *.
  • Start From/To Date/Time - To find jobs with start times in a particular interval, enter the beginning of the interval in the From Date and Time fields and the end of the interval in the To Date and Time fields.  The beginning or end of the interval may be left open.  The values in the Date fields should follow the default format for the login ID used.  (To determine this format, use transaction SU50 or menu path System ® User profile ® User defaults to see the user defaults.)  The values in the Time fields should be in military format.
  • Start at event - To find jobs that were triggered by an event, enter the event in this field.  Leave the field blank if it is not applicable.
  • Jobs Status - To find jobs with a particular status, select the click box associated with each status.  More than one status may be chosen.  Select all click boxes to get a listing of jobs, regardless of status.  The statuses include:
    • Scheduled - This status applies to background jobs that have been defined by users who do not have the authority to kick them off.  These jobs must be released by users who do have this authority or else they will not run at their start times.
    • Released - This status applies to background jobs that will run at their start times.
    • Ready - This status applies to background jobs that have been kicked off at their start times but have been queued to run.
    • Active - This status applies to background jobs that are currently running.
    • Finished - This status applies to background jobs that completed normally.
    • Cancelled - This status applies to background jobs that ended abnormally.
    • Jobs without start date - To find jobs without a start date, select this click box.
    • Jobs with previous job - To find jobs with previous jobs, select this click box.

The number of jobs selected will decrease as more criteria are chosen.  To find more information on possible entries for each field, select the field and select the F1 function key.

  1. Once the selection criteria have been specified, click the Execute pushbutton.  This will bring up the Job Overview: Alphabetic screen, which gives a listing of jobs that satisfy the criteria with the status of each job.
  2. By default, the jobs are listed alphabetically.  To sort the list by different criteria, select Sort from the Edit menu.
  3. Click the Refresh pushbutton to update the information listed on the overview screen.
  4. To maintain a specific background job or obtain information about it, select the job by clicking its job name in the list.  The following pushbuttons provide several options:
  • Job log - Click this pushbutton to display the results of a completed background job.
  • Display - Click this pushbutton to display general data about a job.
  • Release - Click this pushbutton to release a scheduled job.  A user may schedule a job, but if the user does not have the proper authorization, the job remains in scheduled status.  It will not run until, an authorized user has released it.  Jobs created by authorized users are automatically released.
  • Spool list - Click this pushbutton to display a background job’s spool requests (print/fax jobs).
  • Steps - Click this pushbutton to display a background job’s Steps List (the programs that it will or has run).

Other options are provided in the Job menu.  These include:

  • Schedule job - Select this to cancel, release, or repeat an existing job.
  • Copy - Select this to copy an existing job to a new one.
  • Delete - Select this to delete a job.
  • Change - Select this to change or modify the definition of a job that has not run yet.
  • Capture - Select this to capture a job that is currently running and run it in the current on-line session.
  • Cancel job - Select this to cancel a job that is currently running.

출처: http://wiki.sdn.sap.com/wiki/display/Basis/How+to+maintain+and+monitor+background+jobs+via+SAP

'SAP' 카테고리의 다른 글

SAP Event  (5) 2011.01.17
Scheduling background job by triggering an event  (0) 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

SAP Event

SAP 2011. 1. 17. 11:49 Posted by KindKay

Following are some details about the SAP Event:

An SAP event is a "flag" that is created in SAP (SM62). This event (or flag) can be triggered (from a Unix job to an incoming file), causing a job to execute in the background. This event (or flag) can be triggered within R/3 or can be done at the Unix level.

First, create an event in SM62. It's easy - just create it under "user event names" and "maintain". You'll find the create option from there.
Once created go to SM36 and create the job. Put in the job name you want to call it - fill in the ABAP/4 program you'll want executed, but under "START DATE" select option AFTER EVENT. Then plug in your SAP event name you created. Fill in the remaining information on this screen and save.
Once saved, an entry is put in table BTCEVTJOB. The entry is the name of the event you raised. This is the system's way of keeping track of which jobs are in the queue waiting for an event to occur.
Now, once the event is triggered this newly created job will execute. The event can be triggered via sap (SM64) or at the Unix level.
SM64 is pretty self-explanatory. To get the event triggered from Unix:
-Log into the <SID>adm user id at the Unix level and go to directory /usr/sap/<SYSID>/SYS/exe/run (there is an alias called 'cdexe' that will get you there)
-From there look for an executable called sapevt. Open another Unix window cause now you are going to need to cut and paste.

-At the other sap window switch user to the <SID>adm user and go to the /usr/sap/<SYSID>/SYS/profile directory ('cdpro' is the alias)

-Do an "ll | more" and look for the instance profile name (the sapevt executable will want this!) Example: <SID>DVEBMGS00<SYSNAME>

-Go back to the sapevt window and enter this command to get the event to raise:
sapevt <event_name> -t pf=<instance_profile_directory_and_name> nr=<SYS_number>
Example: sapevt roberts_test -t pf=/usr/sap/<SID>/SYS/profile/<SID>DVEBMGS00<SYSNAME> nr=00

-This will raise the event, and cause the job scheduled within SAP to execute.
Once the job has executed the SAP event that was in the table BTCEVTJOB will disappear.
Another table, TABTCO, will now have an entry in it with the SAP job that was executed. Once you've found that job name in this table you can double click on its entry and see that it was executed via an event.
--------------------------------------------
To set TRACE level WITHOUT bringing down the system:

Find the dispatcher process at the Unix level like this:
ps -ef | grep dw.sap | more
In the third column look for the "child" process ID number that repeats itself over and over
Then verify that number to the number in the second column, which should be the parent PID number.
Then issue the Unix command: kill -usr3 parent-pid-number (to turn on level 3 trace)
kill -usr2 parent-pid-number (to turn on level 2 trace)
kill -usr1 parent-pid-number (to turn on level 1 trace)

-------------------------------------------

To Transport Maintenance Dialogs, you need to enter the object(s) in the following manner in the command file:

R3TR TOBJ tablename .... (11th position) S

Function Group

Table Structure

And the entries for your table in TVDIR and TDDAT

--------------------------------------------

To see if a rollback is occurring at the Informix database level, do the following:

onstat -u | more

Look for the letter "R" in the 3rd column under the "flags". "R" means rollback - "P" means primary - "X" means critical


출처: http://wiki.sdn.sap.com/wiki/display/ABAP/SAP+Event

'SAP' 카테고리의 다른 글

How to maintain and monitor background jobs via SAP  (1) 2011.01.17
Scheduling background job by triggering an event  (0) 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

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

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

SCC1 - Copy by Transport Request

SAP 2010. 11. 24. 11:56 Posted by KindKay

'SAP' 카테고리의 다른 글

SAP Event  (5) 2011.01.17
Scheduling background job by triggering an event  (0) 2011.01.17
ALV Buffer Reset  (1) 2010.11.16
PP - Long-Term Planning  (2) 2010.09.22
Frequently Used Tables  (1) 2010.09.20

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.