ABAP Coding

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

ABAP – Using Web Dynpro Download Element

One of my recent adventures was find a way to pull documents out of SAP, and display them within my web application.  This turned out to be rather challenging, but I learned some neat tricks about ABAP Web Dynpro along the way.  The Web Dynpro Download Element is one of my new favorites, once I figured out how I could use it.

Let’s set the stage.  You have a document withing SAP that you want to display to your web user.  The Web Dynpro Download Element works perfectly for this…  provided you can feed it the proper data.  What I figured out is that in order to make this work, you need to get your document into an XSTRING format.  I think this is a RAW string or something like that, but it’s not important.  What is important is how do you get it into the XSTRING format.  One of the cool tricks I found online was using the following function module:

CONVERT_OTFSPOOLJOB_2_PDF

This function will convert a spool job into the XSTRING format you need to output it.  Now, getting things into the spool can be another headache, so tomorrow I’ll talk about how to get your standard SD documents into the spool again so you can read them out of the Web Dynpro Download Element.

Thanks for reading,

 

ABAP – Using a Dropdown to Populate Multiple Fields

Now, since I’ve been on a roll talking about the VALUE-REQUEST and some of the fun tricks I’ve been discovering.  Today, I’m going to give you some sample code to populate multiple values with a single dropdown.  Often, when I create a screen, I’m using some combination like sales order & line item, material & plant, etc…  so I wanted to know how I could use a single dropdown to populate multiple fields.  Here you go.  This is for VBELN & POSNR.  Now, keep in mind, I used the trick from yesterday to get the sales order number (if it’s populated) so that the pull down will work smarter.

SELECT vbeln posnr
FROM vbap
INTO TABLE lt_sh
UP TO 200 ROWS
WHERE VBELN = GV_VBELN.

” Set return fields

” Order
CLEAR ls_map.
ls_map-fldname = ‘F0001’.        ” Set that field 1
ls_map-dyfldname = ‘GV_VBELN’.
APPEND ls_map TO lt_map.
” Item
CLEAR ls_map.
ls_map-fldname = ‘F0002’.        ” Set that field 2
ls_map-dyfldname = ‘GV_POSNR’.
APPEND ls_map TO lt_map.

” Call Search Help Popup Function
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
retfield        = ‘POSNR’
dynpprog        = sy-repid
dynpnr          = sy-dynnr
dynprofield     = ‘VBAP-POSNR’
value_org       = ‘S’
TABLES
value_tab       = lt_sh
dynpfld_mapping = lt_map
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS          = 3.

That’s all there is to it.  You’ll still need to review my previous posts: dropdown list for characteristic values and dropdown list along with reading a dynpro value to pull it all together, but it should give you all the tricks you’ll ever need to use the VALUE-REQUEST.  I hope this makes sense on how you can use a dropdown to populate multiple fields.  Thanks for reading.

ABAP – Reading Dynpro Value

This latest trick I discovered when creating my pull down lists.  If you’re curious, check out my previous posts dropdown list for characteristic values and dropdown list.  It turns out reading dynpro value isn’t as easy as I thought.  I expected I could just read the variable into my module…  but I guess the variable doesn’t have a value yet at that point.  So I needed this function for reading a dynpro value.

  wa_dynpfields-fieldname = ‘GV_VBELN’.
append wa_dynpfields to dynpfields.
call function ‘DYNP_VALUES_READ’
exporting
dyname               = SY-REPID
dynumb               = sy-dynnr
tables
dynpfields           = dynpfields
exceptions
invalid_abapworkarea = 1
invalid_dynprofield  = 2
invalid_dynproname   = 3
invalid_dynpronummer = 4
invalid_request      = 5
no_fielddescription  = 6
invalid_parameter    = 7
undefind_error       = 8
double_conversion    = 9
stepl_not_found      = 10
others               = 11.

Again, this is a simple task, but if you don’t know how to get the information, it’s pretty tough to use it.  So there it is, a simple function to pull in a dynpro value from the screen in order to use it in the VALUE-REQUEST statement.  Thanks for reading.

 

ABAP – Dropdown List

Well, yesterday I mentioned that I’m building a screen, and I wanted to have a nice dropdown list for characteristic values.  So I was able to get a table of the characteristics and values, but now I need to do something to get it into a nice dropdown list.  Here’s how I did it.  This little function module takes the field, and you give it a table (value_tab) which holds the key and the description.  Then it pulls up a nice looking popup window.

So, the first step happens in your screen designer (TXN: SE51).  In the PAI section, you need to add a statement to the bottom:

PROCESS ON VALUE-REQUEST.
field WA_CSTICS-VAL MODULE drop_cstic_val.

In this statement, WA_CSTICS-VAL is the field I needed a dropdown list for.  Then I just needed a module to load the stuff.  That was drop_cstic_val.  In that module, I just used the function I talked about yesterday in my post on dropdown list for characteristic values. Then I called this function to generate the dropdown list popup.

CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
retfield        = ‘KEY’
window_title    = WA_CSTICS-ATNAM
dynpprog        = sy-repid
dynpnr          = ‘0100’
dynprofield     = ‘FIELD_W_DROPDOWN’
value_org       = ‘S’
TABLES
value_tab       = lt_val
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS          = 3.

And that’s all there is to creating the dropdown list popup.  Thanks for reading.  I have some more tricks related to this…  but you’ll have to wait till tomorrow =)

ABAP – Dropdown List for characteristic values

Here’s a fun little tidbit.  I was building a new screen, and I needed to add a pull down (you’ll see more of this in some future posts. )  I wanted to a build a dropdown list for characteristic values from a VC configuration.  Well, I needed to start simple, first I wanted an easy way to get all the characteristic values and their descriptions.  I found this line little function module that does just that.  It’s not exciting, but it sure is convenient.

lv_pppi_char = WA_CSTICS-ATNAM.
CALL FUNCTION ‘PROC_CHAR_HELPVALUES_GET’
EXPORTING
pppi_char                    = lv_pppi_char
TABLES
helpvalues                   = lt_helpvalues
values_for_field             = lt_values_for_field
EXCEPTIONS
characteristic_not_valid     = 1
values_can_not_be_determined = 2
no_authority                 = 3
OTHERS                       = 4.

And that’s the first step I needed to accomplish to build my dropdown list for characteristic values.  Tomorrow I’ll talk about how to do nice popup box for the dropdown list.

Thanks for reading.

 

Web Dynpro – reset_view

Here’s a cool little trick that I picked up in order to make my dynamic screens even more dynamic.  The reset_view statement turned out to be the piece of the puzzle I needed in order to to have a dynamic screen with multiple variations.  While this may be outside the norm, it’s still a great little trick, and let me show you why.

Here’s the scenario.  I’ve created a view with a set of dynamic elements.  Now the trick comes in that depending on the scenario, even that dynamic screen might change.  When I first set it up, I kept getting a short dump because the system was trying to recreate dynamic elements that already existed.  By adding the statement:

  view->reset_view( ).

at the beginning of the WDDOMODIFYVIEW (which is where I do all of my initialization for the view) that reset the stage, so that I could “rebuild” the view with any elements that I needed.

While this isn’t earth shattering, it just might be the trick you need to keep your ideas flowing.

Thanks for reading,

 

ABAP – SIMGH for IMG Cleanup

Well, recently, I was doing some prep work/clean up for my upcoming Field Service Engineer Web application.  I intend to reuse as much code as possible from my Rapier application.  In the course of my cleanup, I ran into an issue.  I had created some custom IMG nodes in configuration, and subsequently deleted them in order to clean up some of my export packages.  Well, short story, deleting the nodes didn’t delete all of the underlying pieces.  One of my tables was showing a where used for the IMG node that was already deleted, so I need to use SIMGH for IMG cleanup.

What I found is that since deleting the node didn’t delete the underlying pieces, the only alternative was to find those pieces individually, and delete them.  Transaction SIMGH did for me what S_IMG_EXTENSION couldn’t.  You see, I did all of my creation and deletion using S_IMG_EXTENSION, and for some reason, S_IMG_EXTENSION doesn’t properly clean up after itself.  So my word of warning is that if create your own custom IMG nodes using S_IMG_EXTENSION, be careful if you do any deletions, and be sure to use SIMGH to validate your work.

Thanks for reading,

 

 

ABAP – Screen Design with Too Many Elements

I recently ran into this while designing a configuration screen for our Proximity application.  This is something that I didn’t find anything about online, so either I looked in the wrong place, or maybe I’m the only one crazy enough to try this :).  Anyway, in the course of screen design I have a rather large subscreen, that contains a lot of radio buttons, a couple table controls and bunch of input fields.  You get the idea.  Well, as I was nearing the end of the screen, I start seeing some strange behavior, so that’s what I wanted to talk about today.  So if you’re designing a large screen and you see anything strange, keep this post in mind.  Now, keep in mind, this is my SAP ERP 6.0 SR3 system and I don’t have the latest basis release, so this might be something I could fix through basis, but who knows.

1.  RUNT_ILLEGAL_SWITCH short dump.  It’s interesting because the screen compiles just fine, but as soon as you go to execute the screen you see this dump.

2.  Radio button groups start asking strangely.  What I started seeing is that my radio button group that was set to include 2 or 4 buttons, suddenly is grouped around another set of radio buttons, 20 lines above this one (that’s how I can tell it wasn’t just my fat fingers) ha ha ha.

3.  Really long compile times.  If your subscreen starts taking around a minute or longer to compile, this might be another clue that your screen is getting too big.

4.  Your elements just start behaving strangely.  I ran into my table controls suddenly stopped scrolling.  It was populated, but I could only get to the first page.  This one drove me nuts for a couple hours last night.

If you see any of these suddenly start happening, go ahead and just remove a chunk of elements.  The trick that I use is that I “Cut” them out of the screen (leave them in memory) and then compile.  If things start working again, you have too many elements.  So then I paste the elements back in and narrow down how many elements are driving it over the edge.  You really have 2 options, 1 just strip out enough fields that everything will compile properly again or you will have to create another tab/screen/subscreen to handle a chunk of the elements so that you can simplify.

if anyone else has seen this, let me know, I’d be curious, and also if you found any other ways to correct the issue.  As always, I hope this helps.

 

ABAP – Call transaction and skip first screen tricks

Well, in my current development tasks, I’m really pushing to reuse code in more and more of my applications.  You know, that whole object oriented approach that should be standard for everything =)  Well, one of the tricks I discovered lately is that if you can do a  call transaction and skip first screen from within an application.

It’s great, SAP even provides a statement that allows you to do this.  However, what I found is that there are limitations, as well as some “unforeseen” behaviors that result from using this statement.  So here’s what you need to know.
If you are using a custom transaction, in the “first” screen, you need to make sure that the “Next Screen” on the attributes tab points to another screen number.  Sounds easy enough, but what I discovered is that using this next screen has some weird impacts on running the transaction normally.  For example, my custom transaction has all of the controls in the PAI/PBO code to tell it what to do next.  When I manually pointed to another screen, suddenly my PAI behavior changed.  When I hit enter it moved to the next screen.  My original coding required pressing execute.  While this isn’t the end of world, when I was green arrowed out of the results screen it now left my transaction, instead of returning to the first screen.  This behavior was certainly unacceptable for the flow I wanted.

OK…  how do you get past this.  I took a very easy approach, and let me know out there if there is a better way to handle it.  I created a new screen (a copy of my first screen, and this time I changed the “Next Screen”)  I didn’t change anything else.  Then I created a new transaction code that started from the new screen.  So now I have 2 different transactions.  1 for on-line users, 1 to be called from a program.  This worked perfect for me, but of course it is extra data, that to me seems unneeded.

Thanks for reading, and I hope this can help you…

 

ABAP – SELECT Statement with a variable table name

I just figured out a cool trick last night, and this may be old hat to a lot of you.  I was working on the latest piece of Proximity, and I wanted to be able to re-use my code, but each place would call it’s own custom transparent table.  The structures were the same, so it was an easy change.  Well, turns out it was a pretty easy trick.  You can create a Select statement with a variable table name.  Check it out the specific details below.

DATA: L_TABNAME TYPE DD02L-TABNAME.
L_TABNAME = ‘Z_TABLE’.

        select single * from (L_TABNAME) into z_wa
where field  = field.

That’s it.  Again, a trick I could’ve used a long time ago, but finally did the research last night to implement it.  Hope you find this handy.