ABAP Coding

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

ABAP Web Dynpro – ALV Table Columns

Ok…  now I finally got to the really important stuff for me.  I have a configuration table that tells how columns are available, and how they sequenced by default.  So obviously, if I’m going to use the ALV simple table versus the “standard” Table Class, I need to control the ALV Table Columns, this includes sequence, visibility and column header text.

So, again, I’m doing all of this in the WDDOINIT method, since it’s a one time read.  Here’s how you can do it yourself.

  data lo_cmp_usage type ref to if_wd_component_usage.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
DATA lv_value TYPE ref to cl_salv_wd_config_table.

*** instantiate the component
lo_cmp_usage =   wd_this->wd_cpuse_alv_comp( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_alv_comp( ).
*** get the ALV table
lv_value = lo_interfacecontroller->get_model( ).

** first, get all of the columns from the table.
lt_cols = lv_value->if_salv_wd_column_settings~get_columns( ).
READ TABLE lt_cols INTO ls_cols with key ID = <TABLE FIELD NAME>.
*** For visibility, you the following values
*      WHen ‘VISIBLE’
lv_vis = ’02’.
*     when ‘INVISIBLE’.
lv_vis = ’01’.
ls_cols-r_column->set_visible( lv_vis ).

*** set the sequence of the columns
lv_seq = lv_sequence.
ls_cols-r_column->set_position( lv_seq ).

*** Set the header text and tooltip
ls_col_hdr = ls_cols-r_column->get_header( ).
lv_col_text = lv_text.
ls_col_hdr->set_text( lv_col_text ).
ls_col_hdr->set_tooltip( lv_col_text ).

Of course, you can loop through and find your values from anywhere.  The important thing to notice is that it’s pretty simple.  Especially in comparison to the process I was using that had to delete a column and re-add it in order to sequence it properly.  This is a lot less involved.  So far, I haven’t found anything that I do that would force me away from the ALV Table.  I guess I’ll see what happens, but I may start converting my SM Portal to the ALV Tables.  The processing time doesn’t seem bad, so if you happen to know why the “standard” vs SALV table is preferable, I’d love to hear from you.

As always, Thanks for reading,

ABAP Web Dynpro – ALV Table Settings

Well, the next phase of my journey was the ABAP Web Dynpro ALV Table Settings.  I wanted to control things like the number of rows to display, what buttons should be available etc…

So after a little more research, I found that is pretty easy to do too.

Again we go to the WDDOINIT and add the follow code (or something like it ).

  data lo_cmp_usage type ref to if_wd_component_usage.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
DATA lv_value TYPE ref to cl_salv_wd_config_table.

*** instantiate the component
lo_cmp_usage =   wd_this->wd_cpuse_alv_comp( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_alv_comp( ).
*** get the ALV table
lv_value = lo_interfacecontroller->get_model( ).

*** Set Table Buttons and attributes
lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_SCROLLABLE_COL_COUNT( value = 10 ).
lv_value->IF_SALV_WD_STD_FUNCTIONS~SET_EXPORT_ALLOWED( value = abap_false ).
lv_value->IF_SALV_WD_STD_FUNCTIONS~SET_PDF_ALLOWED( value = abap_false ).

this particular example turns off the print button (PDF Allowed), turns off the Export button (Export_Allowed), and sets the scrollable column count = 10.  Just because my particular table could be 100 columns wide.  So I want it to render nicely, and 10 is a pretty good number of columns.  In addition, I’m leaving the settings button available, so a user can make his own settings if he doesn’t like my default.  I really like this ALV stuff 🙂

Alright, back to it.  Thanks for reading,

ABAP Web Dynpro – ALV Table Button

Well, after my last post, I realized, this is cool.  Now it’s time to make it better.  So the first objective is to add an ALV table button for refresh.  It turns out, it’s pretty easy to accomplish this.  Here’s what you need to do.

So, go into your WDDOINIT and add the following code (or some variation).

*** initial ALV table
data lo_cmp_usage type ref to if_wd_component_usage.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
DATA lv_value TYPE ref to cl_salv_wd_config_table.
DATA: lr_btui_refresh TYPE REF TO cl_salv_wd_fe_button.
DATA: lr_bt_refresh TYPE REF TO cl_salv_wd_function.

*** instantiate the component
lo_cmp_usage =   wd_this->wd_cpuse_alv_comp( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_alv_comp( ).
*** get the ALV table
lv_value = lo_interfacecontroller->get_model( ).
*** create the button object
create OBJECT lr_btui_refresh.
*** set icon
lr_btui_refresh->set_image_source( ‘ICON_REFRESH’ ).
lr_bt_refresh = lv_value->if_salv_wd_function_settings~create_function( ID = ‘BT_REFRESH’ ).
lr_bt_refresh->set_editor( lr_btui_refresh ).

Now you can also add text to the button instead of just the image source.  If you drill into the cl_salv_wd_fe_button class to see the methods available.

I’ll have more tomorrow as I keep learning.  Thanks for reading,

Web Dynpro – The ALV Table

Well, with all the work that I did for my Customer SM Portal, I thought I knew what I was doing with the ABAP Web Dynpro, especially around tables and dynamically changing them.  I recently started working on a new application that is more scaled back.  One of the requirements is to have the same sort of functionality as an ALV Table in the ABAP.  So we want to have the filter, sorting, and flexibility to play with your layout and settings.  Well, I started to look at the current tables I’d been using, and realized I had to implement each of those functions myself.  Well, that looked like a rather big task to undertake, so I went to my buddy, the internet and looked up Web Dynpro ALV Table and quickly found that SAP was nice enough to provide a way to implement the ALV Table.  Of course, it meant another change to the way I was doing things… but hey, I learned something new.

First of all, thanks that Sankar.  If you like to see exactly how to do this in video format, check out this like.  Sankar does a great job in demonstrating exactly how to code this stuff.  My only problem is that sometimes it was hard to read the code and class names (which is why I’m going to cover this in text form). https://www.youtube.com/user/sankar1bhatta?feature=watch

So, let me walk you through the steps of how to create an ALV Table.  The first step is to add a new Web Dynpro Component. blog01-01

So, go to your top level, and add a Used Web Dynpro Component.  You can name the Component Use whatever you like, the component itself is SALV_WD_TABLE.  This is the magic that will allow you to use all of the ALV functions. I’m not going to cover this in depth, but the next step will be to add a context node + attributes that will be the structure for the table you want to create.  Be sure to create this in the componentcontroller, and not directly in a particular view. This next part was new to me.  I believe it’s called external component mapping.  So let me walk you through this next part.

blog01-02

First, drill down into the component usuages until you find the ALV component you defined above (mine is ALV_COMP).  Next, you need to drag your context (table you want to create in ALV) from the right side, over to the Data node on the left side above.  You have now linked that table structure to the ALV components. Finally, we need to add this to the layout so you can actually see the table.  So, go to your layout and add a ViewContainerUIElement.  Wherever you place this is where your table will come in. We have one final step, and then you’re ready to test.

blog01-03

So, go to your window, and find the VCUI element that you just created, and drill down and then right click to Embed View.

blog01-04

Select the Table interface, and you’re ready to go.  Just fire up your application.  In some future posts, I’ll discuss how you can customize this, but for many applications, this might be enough.

Thanks for reading,

Web Dynpro – wda_ls_main.js Error in IE

Well, here’s something new I just ran into.  Last night, my system crashed, which by itself was no big deal.  I just had to restart my virtual server.  But then I went to do some testing in Rapier and suddenly I couldn’t even get the login page to show up.  All I got was an error in IE (internet Explore) talking wda_ls_main.js  Well, this sounded cryptic and unhelpful.  So I went to SDN, and quickly found that it’s a browser issue, not anything with my code.  Which was good, since it worked last night and I hadn’t changed anything.

The solution was simple, go to the internet options, delete all the browsing history.  Apparently, from time to time, something strange gets cached and it won’t reload.  I wasn’t able to really get any more info than that (that I understood at least.  ha ha ha).

so if you run into this error on you AWDP page, try just clearing out the history.

Thanks for reading,

ABAP – 4.6C code differences

Like I mentioned yesterday, we have a potential sale, if we can make WMigo work in a 4.6C system.  Sounds easy, right?  Well, it’s all part of my latest adventure.  First I had to figure out a way to convert my 6.0 Unicode system transport to go to 4.6C.  Check my post from yesterday if you want to know more about that.  Now, back to my story.  After overcoming the obstacle of getting the 4.6C system to accept my transport then I started to find code issues.  It turns out that a system more than 10 years old doesn’t have all the tools that I”m used to.  Today I want to talk about some of the 4.6C code differences I’m experiencing.

1.  Line length has a max of 72.  sounds simple, but I had about 20 + errors just on this.  When you get the nice word wrap type features, you don’t notice when you get to 75 or 80 chars, but it just rolls onto the next line.  Simple fix, but still a fix.

2.  is not INITIAL doesn’t work in 4.6C.  Instead, you need to change it to NOT <variable> is INITIAL.  it’s subtle, but again, I had a lot of instances that needed to change.

3.  some methods have changed parameters.  on_data_changed for example did not have the parameter e_ucomm.

4.  some methods need to be called “differently”.  for example: cl_gui_cfw=>set_new_ok_code( new_code = ‘OK’ ), needs to be
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = ‘OK’.
subtle, but necessary if you want to run in 4.6C

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,