ABAP Coding

Home / SAP / Archive by category "ABAP Coding" (Page 5)

ABAP – exporttoascii to Move Code from a Unicode ERP 6.0 to 4.6C

Wow…  what an adventure.  I feared I might run into some issues doing this, but being small means we need the sales and we need the references.  So it means we do some things to go the extra mile.  We have a really strong potential with a new client, but they run 4.6C.  I had forgotten just how long ago that 4.6C came out.  I did the math, and realized that its been over 10 years since the last time I worked on a 4.6C system.  Well, today was my first challenge.  I already knew that I couldn’t create a standard package to send for our free trial period, so I had to use standard transports.  Well, we sent the transports, they tried and right off the bat, we get an error that you can’t import from a unicode system into a 4.6C non-unicode system.  DOH!!!

So, I hit the interweb and looked in OSS to find some clues.  The first thing I found was OSS note 330267 that talks about just this issue.  Cool…  Well, it turns out there is an additional parameter you can add to the transport system that outputs the transport in a format readable by 4.6C.  Score!!!  but there’s a catch, you have to be on a late enough kernel.  Guess What?  My kernel version wasn’t recent enough.

So I pulled out my trusty post about upgrading your kernel…  spent way too much time downloading files from OSS, and finally got it upgraded. So then i went to STMS, clicked the system overview button, double clicked on my system, went to the transport tool tab, and added a new parameter:

exporttoascii = yes

Such a little command, with so much power.  Once I exported this transport, I was able to move onto my next set of errors…  but I’ll save that for tomorrow.

Thanks for reading.

Web Dynpro – Sorting Columns of Table

Now, in my recent experiments, I came to find just how much better the performance is when you can define the table in advance, and then manipulate it, rather than create the entire thing dynamically (check out some of my previous posts if you want to see how to do that).  So I decided create the full table in the layout tab, and then remove the columns I didn’t need.  Everything worked great, until I wanted to control the sorting columns of Table dynamically.

The first thing I found is that when you define a table using the wizard (not dynamic), it make the columns grouped columns.  I still don’t really grasp the difference, but it does force you to use a different set of methods and also has different behavior.  But thanks to Google, I found this nice little tidbit.  It showed me that you can delete the Grouped Column, and replace it with a standard column.  And with a standard column, you can define the sort order.  Here’s some sample code to get you rolling.

DATA: lo_table    TYPE REF TO cl_wd_table,
grcol         TYPE REF TO cl_wd_abstr_table_column,
tcol           TYPE REF TO cl_wd_table_column,
lc_element TYPE string VALUE ‘CTR_ITEMS’.

IF first_time EQ abap_true.
* get table reference
lo_table ?= view->get_element( id = lc_element ).
CALL METHOD lo_table->remove_grouped_column
EXPORTING
id                  = ‘COL_NAME’
index             = 1
RECEIVING
the_grouped_column = grcol.
tcol ?= grcol.

CALL METHOD lo_table->add_column
EXPORTING
index              = lv_sequence
the_column     = tcol.
ENDIF.

ABAP – Using BDC to create a Delivery – VL01

Wow…  I have to tell you, I pretty much feel like the dumbest guy on earth right now.  I’ve been fumbling for a few hours trying to do something as simple as automatically generate an inbound delivery for a repair order.  To set the stage, I’m trying to generate data in my test system is an automated fashion.  In short, I realize I need a lot more data to help me test the performance on my dashboards.  Well, if you want to at least make it look good, you should be generating some data every day, pretend like it’s a real company.  So I’ve got notification being generated every day, repair sales orders, and I thought the inbound delivery would be a nice easy piece…  Well, shame on me…

After spending way too much time on this, I wanted to give you benefit of my bonehead day.

1.  Be careful if you try to do BDC with an Enjoy transaction.  Sometimes it works, sometimes weird things happen, especially in the background.  I found this with VL01N.

2.  Most popup message DO NOT need to be addressed in the BDC.  This was the point that killed me.  I set it up to work perfectly on-line.  My example was to create an inbound delivery with serial number.  Well, if you have a status of ECUS on the serial number/equipment, you get that annoying popup to tell you that.  I confess, I haven’t played with BDC in a while, so I totally forgot that even though it happens on-line and in error mode, it doesn’t happen when you move to N mode.  “Doom on Me”, as one of my  favorite authors always said.  I eventually came to the revelation to find everything worked great.  DOH!

3.  Use transaction SHDB to get your recording information.  But remember #2 above.

Anyway, just wanted to float that tidbit out there in case you might be thinking of trying anything similar.

Thanks for reading,

ABAP Web Dynpro – Tree_by_Key and Tree_by_Nst

Hello again.  In my ever changing world, today I happen to be back to Web Dynpro and my Service Management Web application.  My life is truly fun and varied.  ha ha ha.  Anyway, my latest quest is to use a table tree.  Short story, a table tree looks like an ALV grid, but it has the branch/leaf concept like a tree.  I needed this particular structure because I want to sure additional columns when a node is a expanded, rather than just the node.  So I started doing some digging.  I was able to find a demo program in SAP to get me started.  I had 2 different web applications inside of the same program.  My immediate question was what is the different of between TREE_BY_KEY and TREE_BY_NST.

Strangely, this isn’t an obvious answer.  I started by looking at the code and there isn’t a lot of obvious differences.  So I went back to my trusty friend, Google.  While I may fear the amount of information they collect on me and pass to the government, they are still the best source of information when I’m looking for SAP stuff (I’ve tried Bing and Yahoo, but the results aren’t as good).  Anyway, I found a great blog that gave the answer I was looking for.  But like so many of my quests, it only got me half way there.  I learned that TREE_BY_KEY is for a known structure.  If you know the levels and everything before runtime, you should use TREE_BY_KEY.  Of course, in my world, I needed to use TREE_BY_NST because it is for dynamically building the folders and nodes when you don’t know the structure until during runtime.  So this blog is great because if walks you through the TREE_BY_KEY.  My next hunt is to learn about TREE_BY_NST.  I’m hoping that it will be similar, and I’ll be looking at the DEMO_TABLE_WITH_TREE application in SAP to give me a start.  Expect more information as I learn yet another new piece of ABAP Web Dynpro.

Thanks for reading,

ABAP – Using RPR_ABAP_SOURCE_SCAN as a code where used

Once again, thanks to my good friend Jeremy.  He has once again given me a cool tool to use.  The report:
RPR_ABAP_SOURCE_SCAN
It works as a Where Used within code to find any particular statement.  It’s provided by SAP, but like so many thing, it isn’t advertised.  Jer deals with a highly customized environment, so this tool is invaluable.

Here’s the basics of it, you get to define define what program(s) you want to search through (along with lots of other selection options).  Then enter in the String you are looking for.

In my recent optimization, I needed to hunt through my code and find all the places I was using ENDSELECT.  It would’ve been much easier had I used this program to find everywhere, instead of my hunt and paste methodology going through lots of different programs and ABAP methods.  So, my gift to those of you that didn’t know about this, here you go.  Courtesy of SAP =)
Thanks for reading,

ABAP – Optimizing your Code using SE30

One of my favorite tools when I’m developing is transaction SE30, ABAP Runtime Analysis.  I’ve been using this a lot more lately in an attempt to optimize my code in my Service Management Dashboard.  Whenever you deal with a dashboard, you are always hitting a lot of different tables, as well as implementing a lot of different code.  Using SE30 is a great way to quickly see the biggest pain points in your code.  Let me walk you through the basics of using it.

I’ve highlighted the 4 biggest fields you need to enter to execute it.

1.  Description
2. Transaction/Program/Function Module – I’m a fan of transaction whenever it’s available, but pick what you have.
3.  Execute Button – press when you populated everything else.
4.  Variant if you have one.

Press execute button, and you’ll see your program/transaction.  Execute all the steps you want to analyze.  Be careful with this step.  You maybe want to pinpoint certain parts of the transaction, and if you click too many options your results could be scewed.

When you’re done, you’ll this on the bottom.  Press Evaluate, and now you can start the real work.

This next screen will show you where all the work is, is it in ABAP, the Database, or the system.
PRess F5 to start the hit list.

Now, here’s all the information.  The column I tend to pay the most attention to Net %.  I will typically sort on this column to see where the worst performing code is.  Now you do need to be aware, that a lot of times your problems can be “obscured” if you code is too modular.  You may simply see that most of the time is in one function call or one method call.  So you may need to “throw” those numbers out and pay attention to next items on the list.  But i’m sure you’ll figure that out quick enough
Thanks for reading.

ABAP – Select Statement Optimization

Today, special thanks go out to my buddy Jeremy.  He set me straight on some things, and helped me streamline my code in my service management dashboard.

I’m quickly learning that my system works great, except when it comes to volume testing.  (I’m working on this in a separate initiative).  But back to my original thought.  The select statement.  I found out recently that using the SELECT with an ENDSELECT Statement to close it off, and then add some logic in the middle is terrible when it comes to database performance.  Take this example:

 

Select vbeln posnr from VBAP into (lv_vbeln, lv_posnr)
for all entries in table LT_TABLE
where pstyv = ‘TAC’.
<add some logic here>
endselect.

While this code works, and will produce the correct results, as the table VBAP grows, so will the runtime.  Now, the better approach (thanks Jer), is to build and internal table first, then loop through it…  like this.

define a type and a table for lt_result with the fields you want (vbeln & posnr)

Select vbeln posnr from VBAP lt_result
for all entries in table LT_TABLE
where pstyv = ‘TAC’.
loop at lt_result into wa_result.
<add some logic here>
endloop.

Now, this will improve performance, but the real trick to employ if you need to improve performance is to provide an index on the table you are seeing poor performance.  In essence, the index on a table is a lot like changing the key fields set for the table, and allows for faster searching.  This obvious involves a basis person and some additional storage space.  So, if you need to improve performance use the following guidelines.
1. try to set the key fields in the where statement.
2. avoid the select/endselect combination.
3. if using inner join, make sure you need to do it, and try to limit the number of inner joins to 2 or 3 tables max.
if you follow these guidelines, you code should work in nearly any enviroment.
Again, thanks Jer.  And for everyone else, Thanks for reading.

Variant Configuration – VC_I_GET_CONFIGURATION Issues

Well, it’s funny, just yesterday we were talking about interface design and the printouts, and here we are already finding an issue 🙂  Well, I came up with a great idea of having multiple Sales Printouts, and using the function: VC_I_GET_CONFIGURATION to just call it by Sales Printout and by the name of the UI Char group.  Well, unfortunately, I found that char group is not one of the parameters you can send into VC_I_GET_CONFIGURATION.  This was highly disappointing to me.  I did a little debug work, and found that it’s even more confusing than that.  If you create multiple Interface Designs with the same printout checked (for example, Sales Printout is selected on 2 different char groups) then it will only display the characteristics common in both groups.  Confusing???  well it was to me too.  So, let me explain a little better…

Char group 1 (sales printout has been checked)
Cstic 1
Cstic 2Cstic 3

Char group 2 (sales printout has been checked)
Cstic 2
Cstic 4
Cstic 6

If you execute: VC_I_GET_CONFIGURATION for sales, then it will only return Cstic 2.

I really don’t understand this behavior, but it’s what the function does.

Now… there is one potential, so bear with me…

Option 2 is a bit more involved, and depending on the requirements may not even be an option.  Here is the basic concept.  We would create a “super” UI for “engineering” that would be used for production orders and the like.  Then each characteristic (within the model specific class) could have an organizational area set.  We could create an organization for each plant (or each breakdown needed).  We could then assign all the applicable org areas to each characteristic, and the function module above is able to take into account the org areas in what it prints.  Since this is confusing, here’s an example…

Org areas available:

1-Plant 1
2-Plant 2
3-Plant 3
4-Plant 4
5-Plant 5
Etc…

Plant 1 only wants to see: Char 1, char 2, char 3.
Plant 3 wants to see char 1, char 3, char 5, char 7
Plant 5 wants to see char 1, char 4, char 7, char 10.

The Class would have the following:

Char                       Org Area
CHAR 1                 1, 4 , 5
CHAR 2                 1
CHAR 3                 1, 4
CHAR 4                 5
CHAR 5                 4
CHAR 6
CHAR 7                 4, 5
CHAR 8
CHAR 9
CHAR 10               5

So our UI (interface design) for engineering would contain:

CHAR 1
CHAR 2
CHAR 3
CHAR 4
CHAR 5
CHAR 7
CHAR 10

Now, when plant 1 prints the production order, we would call the function above with Org Area = 1, Engineering = X

The function will then pull the “super” UI, and then strip out anything that doesn’t have Org Area = 1.

Now keep in mind, VC_I_GET_CONFIGURATION can read the org areas, but I haven’t fully proved out this idea.  If anyone has a better idea to do something like this, I’d love to hear it.

So, there’s your forray into the mind of a crazy VC modeler.  Thanks for reading.

 

Development – Be Careful when Switching Gears

Today I wanted to talk about a general thing I’ve experienced, and I’m slowly learning from.  Switching gears.  By that I mean jumping from one project to another.  If you’ve checked out the products we’ve designed, you’ll notice that there are some very different items in the list.  Some are SM, some are PP, some VC and some even MM and WM.  So what?  So…  it means they are are all radically different from each other (and perhaps I’ve wandered too far away for some of them, in search of more sales).  Inevitably, it’ll happen though.  Even if you only have 2 different projects you’re working on, you might be asked to jump over to the other project…  so, how can you make that as painless and efficient as possible?  try this approaches..

My favorite, if you can, finish up what you’re working on.  Right now, I’ve been working on a big Web Dynpro addition, but there is interest in one of our MM utilities.  These 2 things have nothing in common.  So I chose to finish up the piece of the Web Dynpro that I’d been working on for the past 2 weeks.  Why?  because when you shift gears, you forget what you were doing, you have to spend an hour or so remember where you left off, and what you still wanted to do.  If you have the option, get yourself to a good stopping point before you move on.  It’ll save you a lot of time (and headaches).

Multi-task when you can.  I know this is a little counter-intuitive, but if you can spend even an hour a day on the first project, you’ll keep all your ideas fresh (even things as simple as where to put the breakpoint).  This will keep you from forgetting where you left off.  Option 1 is still better, but this will help without diverting too much attention away from your new priority.

Take good notes.  (often you’ll do this one no matter what).  Be sure to not everything you haven’t done yet, maybe little techniques you used that you might forget (I use this blog for that), or even just bullet points of what you were working on, and where to start when you can return to this.  It sounds obvious, but I’ve forgotten to do this more than one.

I know, none of this is rocket science, but keep this ideas in mind.  We all get pulled away from what we  “want” to work on, in order to do what we “have” to work on.  So make it as easy as you can to jump right back where you left off.  Thanks for reading.

 

Variant Configuration – using CS_BOM_EXPL_KND_V1 for VC BOM Explosion

Here’s a fun little tidbit.  A recent client was looking for ways to get the BOM from a sales order line item before if hits the planned order/production order phase.  Particularly when you deal with large or expensive manufacturing, you planning/procurement groups might need a heads up on what components will be needed long before it hits MRP.  In that case, you can use the ABAP Function:  CS_BOM_EXPL_KND_V1  This function with a few inputs will provide you the complete BOM for the sales order configuration.  Here’s what you need to enter to make CS_BOM_EXPL_KND_V1 work:

VBELN & VBPOS…  easy one here.  the sales order & line item you want to explode.
WERKS – the plant it should be exploded in
MTNRV – this is your configurable material (KMAT)
EMENG – the quantity of the line item
DAVTUV – the explosion date you want to use (important if you use ECM on the BOM)
CUOBJ – this is the configuration to use ( you can find this in VBAP)
CAPID – this is your BOM type.  PP01 or SD01 are the most popular
MMory – set this to 0 (not sure if this is required)
MEHRS – set this to X (again, not sure what this is for)

If you set these values, BAM, you get your VC BOM before MRP does.  Hope you find this useful.