ABAP log

October 10, 2007

Navigating component screen of CO02 with BDC.

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

Creating and changing production orders in SAP R/3 is a common task in production planing. While you can easily create an order from your ABAP program and do some simple changes using BDC technique, things get ugly when you need to do some more complex tasks. Unfortunately, there are no BAPIs or official function modules to cover every possible operation. Creating orders and changing their operation parameters can be done using “Production Optimization Interface” functions, as I described once here on ABAPlog. Yes, we all know that a couple of years ago SAP promised us to cover complete functionality of SAP with its SOA stuff (ESA in SAP lingo) till the end of 2007, but it doesn’t look like they are going to hit that. Therefore, we poor ABAP developers have to stick with BDC as the last but proven solution.

The most common requirement, apart from changing the header and operation data, is changing the component list. This could be relatively easy with BDC, but only if you are always sure that you have just a few of components that fit on the same page of the table control in the component overview of CO02. Unlucky ones have to deal with the navigation. Some general ideas are given in the BDC article of the ABAP Knowledge Corner from Richard Harper. The main point is: look for navigation commands in menu. Even if you don’t see them, you still have a chance that they are not present in the GUI status but nevertheless supported (you have to study the source code of the SAP transaction to find that out). But CO02 have a wonderful command in its component overview screen: “Find”. Clicking it brings a popup window:

co02.gif

For BCD, it’s the screen 0110 of the program SAPLCO05. By filling some parameters and clicking Enter, you land on the corresponding line. This line will be the first one in the table control and thus easily handles by your batch input. Before using the navigation screen, it is normally a good idea to navigate to the top of the list using the corresponding command.

Let’s see how can we use the navigation. I assume first that each ABAP BDC program defines a form to populate BDC data table, something like this:

form dynpro using dynbegin name value.
  if dynbegin = 'X'.
    clear t_bdc_tab.
    move: name                    to t_bdc_tab-program,
          value                   to t_bdc_tab-dynpro,
          'X'                     to t_bdc_tab-dynbegin.
    append t_bdc_tab.
  else.
    clear t_bdc_tab.
    move: name                    to t_bdc_tab-fnam,
          value                   to t_bdc_tab-fval.
    append t_bdc_tab.
  endif.
endform.

The following form will change the sort string (normally the very last column) for item identified with position number and material:

form change_sort_string
  using p_pos p_newsortval p_matnr.
  perform dynpro using:
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_OKCODE' 'P--',  "Go to top pos first
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_OKCODE' 'AUFS',  "Find item
    'X' 'SAPLCO05' '0110',
    ' ' 'RCOSU-POSNR' p_pos,
    ' ' 'RCOSU-MATNR' p_matnr,
    ' ' 'BDC_OKCODE' 'MORE',  "Enter to navigate
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_CURSOR' 'RESBD-SORTF(01)',
    ' ' 'RESBD-SORTF(01)' p_newsortval,
    ' ' 'BDC_OKCODE' '/00',  "Enter to change pos number
    'X' 'SAPLCOMD' '0110',
    ' ' 'BDC_OKCODE' '/00'.  "confirm
endform.

And this one will delete the item, also identified with its position number and material:

form delete_pos_by_number using    p_posnr p_matnr.
  perform dynpro using:
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_OKCODE' 'P--',  "Go to top pos first
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_OKCODE' 'AUFS',  "Find item
    'X' 'SAPLCO05' '0110',
    ' ' 'RCOSU-POSNR' p_posnr,
    ' ' 'RCOSU-MATNR' p_matnr,
    ' ' 'BDC_OKCODE' 'MORE',  "Enter to navigate
    'X' 'SAPLCOMK' '0120',
    ' ' 'BDC_CURSOR' 'RESBD-POSNR(01)',
    ' ' 'RC27X-FLG_SEL(01)' 'X',  "select 1st item in the list
    ' ' 'BDC_OKCODE' 'DEL',  "delete selected item
    'X' 'SAPLCOMD' '0110',
    ' ' 'BDC_OKCODE' '/00'.  "confirm
endform.

October 4, 2007

Using ABAP Native SQL with SAP Namespaces.

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

Starting, I think, with SAP R/3 4.6, we can use namespaces to name our objects. (“We” includes, in this case, SAP itself too.) That means that instead of using the Y- or Z-prefix to distinguish between SAP’s objects (like tables or programs) and customer or third-party objects, we can register a namespace with SAP that will be used as object name prefix exclusively by our company, thus preventing name conflicts. SAP itself is using, for example, /SAPAPO/ namespace for all objects specific to APO. The feature was logical to expect from SAP to add it, but sometimes it is bringing problems.

Till now all I had were some warning messages when activating tables or ABAP programs (already forgot what was that exactly). But today, when I was writing DELETEs in Native SQL, I had to spend some time to figure out what kind of syntax does it want. The problem was that when the native SQL statement was sent to our IBM DB6 database, it was causing a short dump. I did not expect it to be happy though, and tried to enclose my table names that had slashes in them into single quotes. Doesn’t work. I used the SQL Trace (ST05) then to see which syntax does SAP use internally. They used double quotes. (Note that unless it is the native SQL, double quotes will be considered a comment opening.) But double quotes didn’t help me either – it was still crashing.

I did a quick search in OSS and found one rather unrelated note that among other things mentioned that in addition to double quotes, all table and column names should be in upper case. This was my last trouble to fix. My ABAP Pretty Printer setting is “all lowercase”, and though the pretty printer doesn’t touch the native SQL, I typed everything in lower case myself. If I only copied the syntax that was shown in the “Detail” screen of the SQL Trace, my problem would be solved right away! But well, it was a nice little trick for me to learn.

Blog at WordPress.com.