Append fields to IW38 (and maybe some other tcodes)

I had the requirement to add a couple of fields to the list of IW38, and I had to seek a way to do it, because I was not familiar with that transaction.

I’ve found a couple of guides, what ended me in the right path after few wrong approaches (maybe because the guides were not clear enough or because my English is pretty bad, who knows, and who cares).

So, I decided to write this small approach. Do not expect code snipets, screenshots or anything like that because this is intended as a simple hint for the approach: any ABAPer must be able to work from here.

New fields on the block

Pretty easy: go to the structure RIHAUFK_LIST and create an append with your new fields.

Populate those fields

Not so easy if you are not familiar with those bl**dy enhancement spots, but there are thousand guides about them, and if I could do it, you can for sure, so I will not explain it here.

Go to the line

ENDFORM SELECTION_L,

Just over it, you will find an ENHANCEMENT POINT. Use it to populate your new fields in the table OBJECT_TAB (nice naming, duh).

Read the order BoM in a PI-Sheet

To manage BoM within a PI-Sheet, you should work with the class CL_IM_COCR_CMX_BI_GEN_MAT, but for some reason, I’ve not been able to do it properly, nor I could found a viable BAdI enhancement.

So I had to create a new enhancement for CMX_XS_SRV_GEN to do it.

Just there, I had to create a reference to that class and populate the system’s memory with the order BoM (it’s an old piece of code, just forgive my mistakes there):

* A lot of declarations missed
DATA: cl_super    TYPE REF TO cl_im_cocr_cmx_bi_gen_mat.
* Get context
lo_context = query->get_context( ).
CHECK NOT lo_context IS INITIAL.
ls_context = me->xs_get_context( lo_context ).
CHECK NOT ls_context-aufnr IS INITIAL.
* Let's go!
CREATE OBJECT cl_super.

* tried to inherit the class, but it's a final one and cannot be
* inherited, I had to try the hard way
TRY.
    CALL METHOD cl_super->if_cmx_xs_service_generation~get_data
      EXPORTING
        flt_val = flt_val
        query = query.
  CATCH cx_root INTO oref.
    err_text = oref->get_text( ).
ENDTRY.
* Check the number of created steps
mycount = query->get_count( ).
CHECK mycount > 0.
From there, you will work with the different symbols in a "DO mycount TIMES" loop:
TRY.
    mysymbol = query->get_symbols( myindex ).
    myname-namespace = 'SAP'.
    myname-symbol = 'MATERIAL'.
    CALL METHOD mysymbol->get_value
      EXPORTING
        symbol = myname
      RECEIVING
        value  = myvalue.
  CATCH cx_root INTO oref.
    err_text = oref->get_text( ).
    CONTINUE.
ENDTRY.
 With these pieces of code you should be able to "mount" a nice grid with the BoM details, adding any number of colums per row.

Enjoy!

ABAP UNIT by example

I’m reading Ken Beck’s “Test-Driven Development by example” (a review when I’ll finish it) and I tried to find if there’s a way to adapt it to ABAP.

Yes, it does. Mainly because SAP launched ABAP Unit, a test environment appliable to both programs and classes.

In programs is easy to implement: you must just define a local class FOR TESTING and go on.

In classes… it’s the same, but a bit trickier: take a look at this link from SAP

Let’s try it.
Continue reading

CL_ABAP_BROWSER

Great class to show your HTML strings via dialog box or within a custom container.

Just a trick: if you will use both options within the same program, it will fail if you don’t reset your browser AND the custom container.

It means that you must create a global (sigh) variable for the custom container:

DATA: browser TYPE REF TO cl_gui_custom_container.

And before the call to the dialog version you must free it:

  TRY .
       cl_abap_browser=>close_browser).
       IF browser IS BOUND.
         CALL METHOD browser->free
           EXCEPTIONS
             OTHERS 0"nasty
       ENDIF.
     CATCH cx_root.
       "Nothing
   ENDTRY.

The nasty thing here is the cleansing of SY-SUBRC even when errors occured. You can find a way to make it cleaner, I bet.

But it’s up to you to do it.

Variants’ function modules

Just a few, because I want not to forget it…

– RS_ALL_VARIANTS_4_1_REPORT: providing the name of the report (sy-repid), and just by putting ‘*’ in the TEXT parameter, you will get a table with all the variants of the program.

– RS_VARIANT_CATALOG: (online only?) by providing a program’s name, the system will show a pop-up window with the variants’ list of the program. The user can select one of them, who will be returned in the exporting parameters.

– RS_VARIANT_CONTENTS: just tell this beauty the program and its variant’s name, and it will give you a VALUTAB table parameter with its variable contents.

Rant: Learn how to use Module-pools!

Why some self-called ‘developers’ create module-pools if they don’t understand the whole concept of them? Where’s the sense of create a module-pool for each action of the same concept? Why must I find a module-pool for create data, another one for display it, and a third one to delete them? Where did those self-called ‘developers’ learn about the module-pool thing?

 

Maybe I’m the one who’s wrong, but I ever supposed a module-pool is a bunch of code pieces and screens, that, under the same concept, allow the easy maintenance of a business concept’s actions. I mean, if I must maintain the object Ob, I will create a SINGLE module-pool, with enough code pieces (modules) and screens to be able to maintain all the Ob’s properties. I will save time and space if I can use a single screen and block and/or hide its useless items when they are not needed…

Then I’ll decide if I want a single transaction or more of them, calling the proper screen, who will block by itself its parts what will not be used by the calling transaction. It will save time and space, and, better than this, will make my life easier when the users will ask me to modify the screen. Think about it: I will to modify ONE screen, when all those self-called ‘developers’ will must to modify three or more.

 

Why people cannot (or want not) learn the advantages of a tool before to use it?

The Pomodoro Technique(TM)

I’m a confused mind. It’s something natural being a chimp, but it doesn’t help too much to my productivity. When I’m feeling “unfocused” or too tired to continue with my current task, I find easy ways to rest my mind. Sadly, personal situations affect my worktime (as they do to everyone but robots and jedi knights), and when I’m tired my rest times tend to space themselves shorter (more rests, less work… it hurts… to my work). Continue reading

I’m stuck with the old tricks (posted in SAPFans)

I’m almost six years old here. And I’m starting to feel I can do my work with the same knowledge I had when I started to develop in ABAP. It’s not about compatibility, it’s about evolution. If I didn’t need to learn new tricks to continue doing my work, it means ABAP is optimized? I don’t think so.

What does it mean, then?
It means two things (or more): I will be able to continue being an ABAPer without any kind of effort (wow!) and I will be able to continue using unoptimized techniques (ouch!). The quality of my work relies absolutely over my will. And I don’t have will (not time) enough to seek new ways to do old things. From time to time a question here raises an answer that shows me a new way, that I try to append to my developing “tools”, but no more.

I’m still working with programs which use of unoptimized (and weird) coding makes my worktime a hell. The code works, of course (more or less), but each change I must do takes too much time because the use of things like “OCCURS 0 WITH HEADER LINE” or “TABLES:”. And I don’t have enough time (nor my boss wants me to invest time on it) to fix/upgrade/optimize those old sentences.

I’m still finding (from time to time) old-school coders (doh! how many people will call me “old-school coder” now?) who still use sentences like the ones I said you. Why? Because they don’t need to evolve. It’s their fault or SAP’s? Am I the only one who feels sad because that? Or maybe all you had enough will/time/luck to be able to evolve your programs (and your skills) to use optimized calls?

Doh, I’m still trying to find time to test my old objects skills with ABAP :cry:

More Doh’es… I just had some kind of dejà vu (matrix error?) when thinking about to post this post in the TI blog, and though “I though it before”. And I was right. I wrote about this kind of things there: Evolution needed?
I think I failed miserably trying to evolve myself. But it’s not just my fault only. I think someone in Walldorf shall start to remove some sentences/adds from ABAP, before we’ll be too used to use them.

Or not?