ABAP log

February 26, 2007

Checking existing SAP locks (enqueue-locks) from ABAP.

Filed under: ABAP, SAP — abaplog @ 8:45 pm

In the transaction SM12 you can see all current SAP locks, they can be selected using object or user name. If you want to get that list in your ABAP, the function ENQUEUE_READ will return you a list of object locks for specific objects (that can be specified with a pattern). The function can be useful if you want to process some object without locking it, for example, with a BAPI or BDC, and you want to check whether you may do this at the moment. If the object is currently locked by another user, you can read the lock and decide what to do: wait, or just report an error.

February 23, 2007

How to run the CIF queue LUWs that are stuck in READY state.

Filed under: ABAP, APO, CIF, SAP — abaplog @ 5:09 pm

When we started to play with SAP APO and its CIF interface with R/3, we had, as most of other companies should, all kind of data errors that brought data transfer to a halt. Normally you should clean up your data in R/3 and then run the transfer again after deleting the crashed data queue, but then we found that many queues continued to hang in WAIT state, even if the blocking entry was deleted. You can rerun those LUWs one by one manually, but it’s obviously no fun. After doing some research in OSS and asking advice on Sapfans, I have found that the program RSTRFCI3 does this for many queues at once.

February 19, 2007

Handling date and time on SAP systems running across multiple time zones.

Filed under: ABAP, SAP — abaplog @ 8:18 pm

The easiest way to prevent any time zone problems is to run everything with UTC (formerly GMT – Greenwich Mean Time). But while it’s a good idea for servers, end users will most likely complain about being confused (my family doesn’t – my home systems are on UTC to prevent the hassles with summer/winter time). And if you implement SAP using local time on the server, while your users are in different time zones, things can get slightly complicated. Just try searching in OSS with search term “sy-timlo”.

The main problem is that some fields in SAP are stored as server local time (and date), while others use user’s local time. In general, as SAP explains in many OSS notes, any date/time that is written by the system is server local time, and any date/time that can be manually entered by users is in respective user’s time zone. To help us even more, the time zone used is not stored in documents, but only in user profile, so to be really sure which time is meant, one has to find the user who did the data entry or update, and then find the time zone and do conversion if necessary. SAP gives a good example in OSS note 636992. There, a user sitting in Japan creates a notification about, for example, machine breakdown, entering local time. Several hours later, a colleague in Germany looks at the notification and thinks that the machine has been down only a few moments, while it’s actually several hours!

Things are enough confusing if you are analysing some problem by looking at the data. And if you are creating documents (material movements, accounting postings or production order confirmations) from ABAP programs with, for example, BAPI functions, you have to be especially careful because the system will run checks on date and time fields, with different logic. In general, the posting date (BUDAT or, as in BAPIs, POSTG_DATE) and several date/time fields like EXEC_START_DATE, EXEC_START_TIME, EXEC_FIN_DATE, EXEC_FIN_TIME, EX_CREATED_DATE/TIME in confirmations in the BAPI function BAPI_PRODORDCONF_CREATE_TT are your local date and time. While creating order confirmations, the system will check the date/time against the user local date and time and will prevent creating confirmations in the future. In contrast to PP, the BAPI to create a goods movement – BAPI_GOODSMVT_CREATE – assumes that posting date is a local date, but doesn’t complain if it’s in the future. The potential problems can be hard to find and detect: if you have small time differences, the posting date can differ only during one-two hours per date – only then you will get an error when posting an order confirmation. For all those fields mentioned above you should normally use the system fields SY-DATLO and SY-TIMLO if they have to be populated with current date and time. If the data is provided by an external system, then either the system has to care about the correct time, or your ABAP program has to do time zone conversion.

In certain situations you can assume that if a document is being created for some plant, then the current server time can be converted into local time of the plant, if you know the time zones of both. The server’s time zone, or more exactly, its difference with UTC, can be found in the system variable SY-TZONE. To find the time zone of a plant, you can use the logic that can be found in the function CO_R0_SET_LOCAL_DATE_AND_TIME.

February 15, 2007

Rounding material quantities taking unit into account.

Filed under: ABAP, SAP — abaplog @ 7:40 pm

Sometimes ABAP reports end up showing funny material quantities as “0.5 pieces”. You could truncate or round the values easily, but you have to be sure when you may do that. The function MD_SINGLE_ROUNDING will do the material- and UoM-specific rounding correctly.

February 12, 2007

Getting SAP object directory entry from a partial object.

Filed under: ABAP, SAP — abaplog @ 7:43 pm

If you change an ABAP program source code, it is recorded in a transport with an entry type LIMU REPS, but the program object has an object directory entry of type R3TR PROG in the TADIR table. To convert from partial object to the “real” name, you can use the function TR_CHECK_TYPE. This may be useful if you, for example, want to check what are the objects contained in several transports and whether they “overlap”, so that you should take care if you have several transports to import into another system.

February 7, 2007

Language-specific logic in ABAP.

Filed under: ABAP, SAP — abaplog @ 8:06 pm

Writing code to support users all over the world is never easy, and SAP has, of course, its own specifics. You should process language-dependent data with care. You can get into a trouble if you assume that the data like material description is always available in your current language.

Have a look at this example of selecting production orders for materials together with their descriptions:

select afko~aufnr  makt~maktx from afko inner join makt
    on makt~matnr = afko-plnbez
  into table t_orders
  where afko-plnbez = material and
         makt~spras = sy-langu.

What if some material has a description only in a language other than current? You’ll miss some orders! If that can be possible on your system, it’s better to select production orders for the material first and then do a loop, selecting descriptions and assigning something like “Unknown” to those that do not have one.

A problem of similar kind can arise if you are using text constants for texts that are actually language dependent. Let’s say that your ABAP program is checking whether a production order is completed, assuming a presence of order status ‘TECO’. If you give this text to the status check function and don’t supply the language, you will get the wrong status information if your program is running in German (where ‘TECO’ is ‘TABG’). To solve the problem you can supply the right language or read the status directly from table JEST, providing language-independent status name like ‘Ixxxxxxx’ (see the contents of table TJ02T for possible values).

Another kind of problems with language-dependent data arise when your are doing updates with CALL TRANSACTION supplying BDC data in an internal table. The quantity fields or date and time are stored in your program variables in an internal form. To make your BDC work, you have to convert them to “output” representation that is specific to the user, with which your BDC will be running. For example, the difference can be on the order of date and month (European format vs USA), or decimal separator (comma or period?). The most simple way to get proper format is to declare a character variable and use WRITE … TO operation that will take care of current user’s formats.

February 5, 2007

Reading machine capacity calendar in ABAP.

Filed under: ABAP, SAP — abaplog @ 7:39 pm

If you create a production order, SAP schedules start and end times using the machine and routing parameters. Even with a routing, you can ask SAP to make a simulated scheduling. If you want to do that yourself, you will have to use not only standard times of machine (capacity per time unit), but you will have to know when the machine is available (to throw the holidays out). Function CR_CAPACITY_AVAILABLE_TIMES will return a list of time periods when the machine is running.

February 1, 2007

SAP database tables documentation.

Filed under: ABAP, SAP — abaplog @ 7:11 pm

While SAP doesn’t provide real technical documentation, you can still do a lot to get the information about SAP data model and the sources of data for your programs. I have written a short guide once describing many tricks you can do if you have no idea where the data is coming from. It is published as one of the articles in the ABAP Knowledge Corner from Richard Harper. Apart from that, lots of information is stored right in the SAP system, as standard documentation for programs, functions and ABAP Dictionary objects. For the function modules’, the best way is to use the www.se37.com – a searchable library of documentation. If you want to (try to) get a document from SAP for a database table, here’s the trick: you run the report RSSDOCTB, select the output to be printed on screen and in the popup window (coming after F8 – Run) check all the checkboxes to get the documentation not only for the table but also for relationships and data elements. If you are lucky enough, meaning that normally all older tables (master data and core transaction data tables) are more or less documented, you get a report looking similar to the sample below, that can be stored in a local file. Long time ago I even wrote a program that reprocessed the resulting file into HTML to produce hyperlinked version for many tables.

        MARC                Material Master: C Segment
        Application class     MG
        Table class           TRANSP      SQL-Tabelle
        Last change by        SAP         Date         04/09/1996
        ______________________________________________________________________
        Technical settings
        data class:           APPL0       size category:4
        buffering type:
        ______________________________________________________________________
        Table structure

        Field name K Type Length Data el.  Domain     Text
        ______________________________________________________________________

        MANDT      X CLNT 3      MANDT     MANDT      Client
        MATNR      X CHAR 18     MATNR     MATNR      Material number
        WERKS      X CHAR 4      WERKS     WERKS      Plant
        PSTAT        CHAR 15     PSTAT     PSTAT      Maintenance status
        LVORM        CHAR 1      LVOWK     XFELD      Deletion flag for all material data of a
                                                      plant
        BWTTY        CHAR 1      BWTTY     BWTTY      Valuation category
        XCHAR        CHAR 1      XCHAR     XFELD      Batch management indicator (internal)
        MMSTA        CHAR 2      MMSTA     MMSTA      Material status from MM/PP view
        MMSTD        DATS 8      MMSTD     DATUM      Date as from which MM/PP status is
                                                      valid (deactivated)
        MAABC        CHAR 1      MAABC     MAABC      ABC indicator

...

        Relationships

        Field name Checks fromDependencyCardinality   Text
        ______________________________________________________________________

        MANDT      T000       KEY      CN             Client
        MATNR      MARA       KEY      CN
        WERKS      T001W      KEY      CN
        BWTTY      T149C      REF      CN
        MMSTA      T141       REF      CN
        EKGRP      T024       REF      CN
        AUSME      T006       REF      CN             Unit of measure
        DISPR      MDIP       REF      CN             MRP profile
        DISMM      T438A      REF      CN             MRP type
        DISPO      T024D      REF      CN             Disponent
        DISLS      T439A      REF      CN             Lot size

...

Data element   BESKZ          Domain BESKZ
        _______________________________________________________________________
        Procurement type

        Definition

              Indicator that defines how the material is procured. The following
              procurements types are possible:

              o  The material is produced in-house.

              o  The material is procured externally.

              o  The material can be both produced in-house and procured externally.

        Checks

              Lower limit Upper limitValue description
        __________________________________________________________________
              E                      In-house production
              F                      External procurement
              SPACE                  No procurement
              X                      Both procurement types

Blog at WordPress.com.