ABAP log

April 27, 2007

Copying ABAP program texts between two SAP systems / programs / languages.

Filed under: ABAP, SAP — abaplog @ 9:24 am

From time to time I need to transfer text elements between different SAP systems or ABAP programs without the hassle of the transport system. This happens if we have to do changes in “parallel” systems, or if I have a copy of a program but texts were not copied initially. Yet another case is quick copying of texts from one language to another without clicking a hundred times in the translation screen.

In this case I use two simple ABAP programs. One saves the text in specified language into a file on your PC. And the second one reads the texts back and writes them into the text pool of the second program.

************************
*     Download
************************
report zdowntex.

parameters:
  p_report like sy-repid,
  p_file like rlgrap-filename,
  p_lang like sy-langu.

data: it_text like textpool occurs 100 with header line.

start-of-selection.

  read textpool p_report into it_text language p_lang.

  if sy-subrc = 0.
    call function 'WS_DOWNLOAD'
        exporting
             filename            = p_file
             filetype            = 'DAT'
         tables
              data_tab            = it_text
         exceptions
              file_open_error     = 1
              file_write_error    = 2
              invalid_filesize    = 3
              invalid_table_width = 4
              invalid_type        = 5
              no_batch            = 6
              unknown_error       = 7
              others              = 8.
    write: / 'ws_download : ', sy-subrc.
  else.
    write: / 'read textpool : ', sy-subrc.
  endif.

************************
*     Upload
************************
report zuplotex.

parameters:
  p_report like sy-repid,
  p_file like rlgrap-filename,
  p_lang like sy-langu.

data: it_text like textpool occurs 100 with header line.

start-of-selection.

  call function 'WS_UPLOAD'
       exporting
            filename            = p_file
            filetype            = 'DAT'
       tables
            data_tab            = it_text
       exceptions
            conversion_error    = 1
            file_open_error     = 2
            file_read_error     = 3
            invalid_table_width = 4
            invalid_type        = 5
            no_batch            = 6
            unknown_error       = 7
            others              = 8.

  if sy-subrc = 0.
    insert textpool p_report from it_text language p_lang.
    write: / 'insert textpool : ', sy-subrc.
  else.
    write: / 'ws_upload : ', sy-subrc.
  endif.
Advertisements

April 25, 2007

Working with production order operation long texts from ABAP.

Filed under: ABAP, SAP — abaplog @ 6:03 am

The common task of changing the long text of a production order’s operation can bring some surprises that were discussed several times at Sapfans ABAP forum. Composing right text ID and key to feed the READ_TEXT and SAVE_TEXT functions is the first step. If you are unsure on that, some tips are provided in Sapfans ABAP FAQ, or you can use the debugger as an alternative. All that is relatively straightforward.

The first problem that is usually encountered is that after updating the long text with the function SAVE_TEXT, the new text is not visible in standard SAP transactions like CO03. The new text can be read with the function READ_TEXT though. The trick is that SAP uses the “long text exists” indicator, the field TXTSP in the table AFVC. To make the text “visible” to standard transactions, we have to set the TXTSP value to the current language (or the text’s language). Unfortunately, this has to be done with the direct UPDATE on the AFVC – there are no known workarounds.

Another problem can be seen when the same order is processed by users that use different languages. While SAP allows to store the long text for the same operation in several languages, actually, only one text object will be active at the same time in regard to standard transactions – the object in the last saved language. That means, when SAP writes the text back, the TXTSP will be overwritten with the current language (say, language A). If the next user is working in another language (language B), SAP will present the text in the “first” language (A) in the CO03 (even if the text in language B exists!). But after saving, the text will be written in the new language and TXTSP will be set accordingly.

So, when working with long texts directly, you have to read with READ_TEXT using the language stored in TXTSP, NOT with the current language. When saving, you save in the current language and set the TXTSP to the current language. This way you are consistent with what SAP does and this will prevent you from surprises in a multilingual environment.

April 20, 2007

Finding customer enhancement projects from ABAP user exit include name in SAP.

Filed under: ABAP, SAP — abaplog @ 1:52 pm

If I create a new implementation for a user exit, finding the CMOD project name months later is not a problem (if unsure, I just check the content of my transports). But when I modify the existing user exit, and know only the ABAP include or function name, SAP does not provide any standard function to find the customer enhancement, for example, in case I want to disable it temporarily. And as it often happens, we have to look at the database tables.

SAP user exits (enhancement names that we see in SMOD transaction) are all stored in the table MODSAP. The field NAME contains the enhancement name and the field MEMBER contains the name of the function module that will be called if the customer enhancement exists and is active. The customer enhancement projects are stored in the table MODACT. There, the NAME field is the name of the project and MEMBER is the name of SAP enhancement (that from the MODSAP).

So, if you are in some include, you can use where-used-list to get to the function module name. Then you find the SAP enhancement name from the MODSAP by supplying the function module. And finally, you find the customer enhancement projects by querying the MODACT with the SAP enhancement in the field MEMBER.

April 18, 2007

Running your ABAP on a particular SAP application server.

Filed under: ABAP, SAP — abaplog @ 3:25 pm

Sometimes we need to perform a task on a particular application server. Most common examples of that are collecting statistics or running SQL Trace, where the data is collected only for one application server and saved locally. I had to extract the statistics data once and do that from all servers. As I could not find any function modules that would help me, I have decided to let the standard report run on each server and grab the output data. There are two ways of doing that. One is to schedule background jobs on each server. You may have noticed that in the job parameters screen of SM36 you can select an application server, where the job will be running. But in my case I would then have to implement job status checking functionality and then read the spool. Another way, which is simpler, is to create an RFC-capable function module that is going to do the job for one server, and then call it for all servers in a loop. This assumes that for each application server, you have an RFC destination, which was so in my case.

The list of available servers can be requested with the function TH_SERVER_LIST, and in my case, to get a name of the RFC destinations, I followed a simple naming convention used on our systems. It can be something like HOSTNAME_SYSID_SYSNUMBER, but surely, it can be different for you.

Blog at WordPress.com.