ABAP Coding

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

ABAP – Creating an RFC

Now, in one of my many latest endeavors, I need to create RFC’s to port my code out to an Iphone/Ipad application.  Happily, we have a great contact that is helping me with this stuff.  Now, I knew this was coming, so at least I put the majority of my code into objects/methods.  This makes moving the code pretty simple.  however, I still needed to add a new wrapper to an existing object.

So I go to SE37, create myself a function.  Under attributes there is one major piece to turn on:

blog02

Set this flag, and you’re good to go.  Now, I have run into a small little obstacle that I have yet to overcome.  I’m using the Netweaver gateway to port my code to the application.  Initially, I had set a bunch of tables (so it would like a select option).  For some reason, we were unable to get the information to be sent to through the gateway like this.  When we moved it to be a straight exporting parameter, everything worked fine.

So, if you happen to be someone that knows NW Gateway, is there a trick to send in information as an input table?  and still have the information sent through the gateway?  I’m sure it’s something dumb that I missed, so any feedback you might have, please post a comment.

Thanks for reading,

ABAP – SELECT vs. SELECT INTO CORRESPONDING FIELDS OF TABLE

Well, it turns out my new system is teaching me all sorts of things lately.  Today, I learned the value of how to code the select statement.  In my old ERP 6.0 SR3 system, I built a small program to make notifications in my system.  I use it to generate master data to test my dashboard.  Well, the statement worked just fine so I didn’t think anything of it.

Select equnr from VIQMEL into lv_equnrfor all entries in lt_equip
where equnr = lt_equip-equnr and

kzloesch = ” and
owner = ‘4’.
… do something here.
Endselect.

The statement seemed harmless enough…  until I went to load this into my new EHP4 system.  It has the upgraded kernel, latest support packs, blah blah blah.  It suddenly when a minute, to hours to execute this same piece of code.  I still don’t know exactly what changed…  but sure as hell, my code changed 🙂

I moved to:

select equnr from viqmel into corresponding fields of table lt_qmelwhere equnr = lt_equip-equnr and
kzloesch = ” and
owner = ‘4’.
loop at lt_equip into wa_equip.
read table lt_qmel into wa_qmel with key equnr = wa_equip-equnr.
if sy-subrc = 0.
… do something…
endif.
endloop.

this dropped it make into the less than a minute to read the new code.  wow.  I don’t know what caused the issue, maybe it was 7.01 vs. 7.00, but the same table read in a slightly different way made a huge difference in this program.
Thanks for reading,

ABAP Web Dynpro – Setting ALV Column Header

Not that long ago, I discovered the whole world of ALV tables within ABAP Web Dynpro. As is so common for me, I’m still figuring out all the ins and outs of the code. I have done several tables in my first application, and they all went pretty straightforward. Suddenly, I went a little off the norm, and the column text that I was using stopped working. So because of that, I wanted to make sure I shared this little tidbit about setting the ALV Column Headers. I did a post on this stuff, but I missed a key element. If you’re looking for explanation, take a look at this post.

        ls_col_hdr = ls_cols-r_column->get_header( ).         ls_col_hdr->set_ddic_binding_field( if_salv_wd_c_column_settings=>ddic_bind_none ).         ls_col_hdr->set_text( ‘R’ ).

Now, the important thing to notice is the 2nd line I have listed above. In certain instances, no matter what you try, you can’t undo this binding. So, when in doubt, explicitly break the link. it’ll save you a lot of headaches 🙂

Thanks for reading,

ABAP – Changing a Namespace

Well, once you finally get to the phase of creating a namespace and making yourself a program, inevitably, things change.  In my case, I joined forces with a partner, created a new company and started moving forward.  So, in order to keep things keep everything consistent, I had to generate some new namespaces.  The problem is that you can’t simply rename things for a new namespace, you have to copy each component to the new namespace, then delete the existing stuff.  Of course, the fun comes in the sequencing.

In order to start everything, I recommend using transaction SE80.  Since a namespace is generally associated with a package, the easiest way to pull everything for a particular package.  This will give you everything associated with the namespace.  Initially, you I suggest just copying everything.  For this piece, it doesn’t matter the sequence.

Once everything is copied, now is where the fun part begins.  Go back to the original namespace pull up all of the objects.  Typically I go through and start with the highest level objects.  This will include any programs, web dynpro objects or BSP objects.  For each object, do a where used to make sure it isn’t included anything else, if the where used list is empty, then I’ll delete the item.  Next I move to functions and function group.  Then I’ll move onto the data dictionary objects.  Starting again with the highest level tables and table types.  Then move down the chain to structures and finally data types.

It’s not a simple task, and can be rather tedious… but at the end of the day, you can move from one namespace to another with very little risk, and just a little bit of time.

Thanks for reading,

Web Dynpro – Editable ALV Table

Well, I’m still learning things about the Web Dynpro version of the ALV Table.  In this post, I’m going to about how to make an editable ALV Table within ABAP Web Dynpro.  So far, I’ve talked about how to make the table, and now it’s time for a little more advanced stuff.

Here’s some simple code to handle this aspect:

  data: l_ref_cmp_usage type ref to if_wd_component_usage.

" Instantiate the ALV usage
  l_ref_cmp_usage =   wd_This->wd_CpUse_My_Alv( ).

  if l_ref_cmp_usage->has_active_component( ) is initial.
    l_ref_cmp_usage->create_component( ).
  endif.

" Get reference to the model
  DATA: l_ref_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
  l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_My_Alv( ).

  data: lr_config type ref to Cl_Salv_Wd_Config_Table.

  lr_config = l_ref_INTERFACECONTROLLER->Get_Model( ).

|" Set read only mode to false (and display edit toolbar)
  lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

  data: lr_table_settings type ref to if_salv_wd_table_settings.
  lr_table_settings ?= lr_config.
  lr_table_settings->set_read_only( abap_false ).

Now, this is only the first half of the equation.  By default, every column is a text view within the table.  In order to have anything to edit, you'll need to change certain columns to be a different editor.  If you want to set something to say a checkbox, this is how you'd go about doing it.
  data: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
        lt_columns         TYPE        salv_wd_t_column_ref,
        ls_columns         TYPE        salv_wd_s_column_ref,
        lr_checkbox        TYPE REF TO cl_salv_wd_uie_checkbox.

"  Embed the UI elements within the ALV
  lr_column_settings ?= lr_config.
  lt_columns = lr_column_settings->get_columns( ).
" Embed a checkbox within the column APPROVE
  LOOP AT lt_columns into ls_columns.
    CASE ls_columns-id.
      WHEN 'APPROVE'.
        CREATE OBJECT lr_checkbox1
          EXPORTING
            checked_fieldname = ls_columns-id.
        ls_columns-r_column->set_cell_editor( lr_checkbox ).
        FREE lr_checkbox.
    ENDCASE.
  ENDLOOP.

While there are a lot of ways to handle this, this is the most straightforward.  
As always, thanks for reading,

ABAP – Using ABAP Help On

Since I’m working on training someone completely new to SAP and ABAP, I’m realizing there are a lot of tricks that I know that I take for granted.  One of the things I realized was the ABAP Help On feature.  It’s actually very good and often even includes sample code to show you how it looks.

blog01-01

This is the magic button.  If you have some text highlighted, it will pull it directly into the next screen.

blog01-02

Now, there are a lot of options, but the most commonly used by me is the first option.  enter in your keyword, take the defaulted index search and hit enter.

blog01-03

Now you get your result list.  Find the best match and double click it.

blog01-04

it will come back with a good explanation, syntax diagrams, options you can attach, and sometimes sample code.

in addition, it drops you into the correct place in the help menu, so if you didn’t pick exactly what you needed, you might see it in one of the nearby menu options.

Anyway, basic to my expert readers out there, but if you don’t know much about ABAP, it could come in handy.

Thanks for reading,

ABAP – BDC ABAP Code

Well, we’ve created a program, and done the BDC recording.  Now, all that’s left is the BDC ABAP Code to make it all useful.  So, let’s jump right into it.

First off, you’ll need 2 FORMS and some standard data declarations:

DATA:   BEGIN OF bdcdata OCCURS 100.

INCLUDE STRUCTURE bdcdata.

DATA END OF bdcdata.

DATA: mess TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.

*———————————————————————*

*       FORM BDC_DYN                                                  *

*———————————————————————*

*       start a new screen in the BDC table                           *

*———————————————————————*

*  –>  PROGRAM                                                       *

*  –>  DYNPRO                                                        *

*———————————————————————*

FORM bdc_dyn USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = ‘X’.

APPEND bdcdata.

ENDFORM.                    “bdc_dyn

*———————————————————————*

*       FORM BDC_FLD                                                  *

*———————————————————————*

*       add a field to the BDC table                                  *

*———————————————————————*

*  –>  FNAM                                                          *

*  –>  FVAL                                                          *

*———————————————————————*

FORM bdc_fld USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.                    “bdc_fld

 

Now, the actual transactional stuff that will change with every transaction…

FORM load_cnf.

REFRESH: BDCDATA, MESS.

 

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3000’.

PERFORM bdc_fld USING CORUF-AUFNR ‘ ‘4000100’.

PERFORM bdc_fld USING CORUF-VORNR ‘ ‘0010’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=ENTR’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3200’.

PERFORM bdc_fld USING AFRUD-ISMNW_2 ‘ ‘2’.

PERFORM bdc_fld USING AFRUD-LEARR ‘ ‘SRV’.

PERFORM bdc_fld USING AFRUD-AUERU ‘ ‘’.

PERFORM bdc_fld USING AFRUD-LEKNW ‘ ‘’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=MB03’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCOWB’ ‘0130’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=WEIT’.    ” ENTER

* runs transaction defined above, mode ‘A’ goes step by step, use this

* to prototype code, mode ‘N’ runs automatically, use this in

* production, mode ‘E’ generates errors only, use this for debug

COMMIT WORK AND WAIT.

CALL TRANSACTION ‘IW41’ USING bdcdata

MODE ‘A’         ” mode ‘A’,’N’,’E’

UPDATE ‘S’

MESSAGES INTO mess.

endform.                    “load_cnf

Now, the biggest piece to remember is the MODE.  In the code above, it’s set to A, which means that it will go through step by step. When you execute, it will look something like this.
blog01-12

Beyond that, it’s all about translating the recording into the steps.  You’ll notice that every screen must start with the bdc_dyn.  The bdc_fld will be all the steps within that screen.  At the end of each screen, you will add a BDC_OKCODE.  This will be like hitting enter, or pressing a button.  After ever BDC_OKCODE, you will do a bdc_dyn (even if you don’t leave the screen).

Beyond that, it’s all about entering in the data to populate the screen.  Now something to keep in mind, it won’t always be sufficient to use the same data type as the screen field.  For example, I did transaction IW41, and you have to enter in a number of time units (hours/mins/etc).  I used the same data type, but when I executed the transaction, it told me that the values didn’t fit in the field…  WTF?”.  So i changed it to a text field to enter in the number, and magically it worked.  Keep in mind, you may need to do tricks like that from time to time.

Hope you found this useful and thanks for reading,

ABAP – BDC Recording

Well, since I’ve been talking about BDC, seems logical that I should actually show you how to get a BDC Recording.  It’s easier than you might expect, but reading the results can take some effort.

blog01-01

Use this menu path to start the BDC recorder.

blog01-02

Start a new recording.

blog01-03

Enter in your transaction, and a description.  Then press Start Recording.  Just to give you an idea, let’s walk through a simple recording.

blog02-01

Now, the biggest thing to keep in mind is to know the steps of your transaction, eliminate extra steps (don’t randomly hit enter) and make sure to populate every field you want to be able to populate in your program.

blog02-02

Fill in the values you want, and then press the Goods Movement Button.

blog02-03

Finally, press Save.

Now, you will get your results:

Now, the recording will give you this result:

 

                                               0000                T                      IW41

SAPLCORU                                                       3000                X

                                                0000                                       BDC_CURSOR                                                                                                                                                   CORUF-VORNR

                                                0000                                       BDC_OKCODE                                                                                                                                                  =ENTR

                                                0000                                       CORUF-AUFNR                                                                                                                                                 4000100

                                                0000                                       CORUF-VORNR                                                                                                                                                 10

SAPLCORU                                                       3200                X

                                                0000                                       BDC_CURSOR                                                                                                                                                   AFRUD-LEKNW

                                                0000                                       BDC_OKCODE                                                                                                                                                  /00

                                                0000                                       AFRUD-ARBPL                                                                                                                                                  SERVICE

                                                0000                                       AFRUD-WERKS                                                                                                                                                1100

                                                0000                                       AFRUD-ISMNW_2                                                                                                                                                   28

                                                0000                                       AFRUD-ISMNU                                                                                                                                                H

                                                0000                                       AFRUD-LEARR                                                                                                                                                  srv

                                                0000                                       AFRUD-BUDAT                                                                                                                                                12/06/2013

                                                0000                                       AFRUD-AUERU

                                                0000                                       AFRUD-LEKNW

                                                0000                                       AFRUD-OFMNU                                                                                                                                               H

                                                0000                                       AFRUD-ISDD                                                                                                                            01/11/2013

                                                0000                                       AFRUD-ISDZ                                                                                                                            07:00:00

                                                0000                                       AFRUD-IDAUE                                                                                                                                                 H

                                                0000                                       AFRUD-IEDD                                                                                                                            12/06/2013

                                                0000                                       AFRUD-IEDZ                                                                                                                            23:31:37

                                                0000                                       AFRUD-PEDZ                                                                                                                          24:00:00

SAPLCORU                                                       3200                X

                                                0000                                       BDC_CURSOR                                                                                                                                                   AFRUD-ARBPL

                                                0000                                       BDC_OKCODE                                                                                                                                                  =MB03

                                                0000                                       AFRUD-ARBPL                                                                                                                                                  SERVICE

                                                0000                                       AFRUD-WERKS                                                                                                                                                1100

                                                0000                                       AFRUD-ISMNW_2                                                                                                                                                   28

                                                0000                                       AFRUD-ISMNU                                                                                                                                                H

                                                0000                                       AFRUD-LEARR                                                                                                                                                  SRV

                                                0000                                       AFRUD-BUDAT                                                                                                                                                12/06/2013

                                                0000                                       AFRUD-OFMNU                                                                                                                                               H

                                                0000                                       AFRUD-ISDD                                                                                                                            01/11/2013

                                                0000                                       AFRUD-ISDZ                                                                                                                            07:00:00

                                                0000                                       AFRUD-IDAUE                                                                                                                                                 H

                                                0000                                       AFRUD-IEDD                                                                                                                            12/06/2013

                                                0000                                       AFRUD-IEDZ                                                                                                                            23:31:37

                                                0000                                       AFRUD-PEDZ                                                                                                                           24:00:00

SAPLCOWB                                                      0130                X

                                                0000                                       BDC_OKCODE                                                                                                                                                  =WEIT

                                                0000                                       BDC_SUBSCR                                                                                                                          SAPLCOWB                                0806HEADER

                                                0000                                       BDC_SUBSCR                                                                                                                          SAPLCOWB                                0510TABLE

                                                0000                                       BDC_CURSOR                                                                                                                                                   COWB_COMP-ERFMG(01)

Now, this will translate into the following ABAP code.   In a future post, I’ll give you the simple bdc_dyn and bdc_fld form code.

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3000’.

PERFORM bdc_fld USING CORUF-AUFNR ‘ WA_CNF-AUFNR.

PERFORM bdc_fld USING CORUF-VORNR ‘ WA_CNF-VORNR.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=ENTR’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3200’.

PERFORM bdc_fld USING AFRUD-ISMNW_2 ‘ WA_CNF-TIME.

PERFORM bdc_fld USING AFRUD-LEARR ‘ WA_CNF-LEARR.

PERFORM bdc_fld USING AFRUD-AUERU ‘ WA_CNF-AUERU.

PERFORM bdc_fld USING AFRUD-LEKNW ‘ WA_CNF-LEKNW.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=MB03’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCOWB’ ‘0130’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=WEIT’.    ” ENTER

* runs transaction defined above, mode ‘A’ goes step by step, use this

* to prototype code, mode ‘N’ runs automatically, use this in

* production, mode ‘E’ generates errors only, use this for debug

COMMIT WORK AND WAIT.

CALL TRANSACTION ‘IW41’ USING bdcdata

MODE ‘N’         ” mode ‘A’,’N’,’E’

UPDATE ‘S’

MESSAGES INTO mess.

That’s it for today.  The recording is pretty easy.  Using it, well, I’ll get to that soon 🙂

Thanks for reading,

 

ABAP – Copying a program

Continuing on my training of an intern, one of the things I need is a series of BDC programs to automatically generate data within my test systems.  While, there are a lot of ways to make transactional data, I need something that I can “fire and forget”.  So that means I need programs with either a BAPI or BDC.  In my opinion, for this, I want simple and I want quick, so I’ve gone down the BDC path.  So…  I’m using it as a training opportunity for my intern.  Today, I’m going to focus on simply copying an existing program.  I know it sounds simple, but hey, not everyone is an ABAP expert.  That’s what I”m going to be sharing with y’all today 🙂

blog01-01

Now, since I’ve already developed a few of these (I’m working my way through the in-house repair process), the easiest way is to copy from an existing one.

blog01-02

This program will be to generate service order confirmations.

blog01-03

Now, the next question is if you want to copy all the attached pieces of the program.  In general, I say yes, but obviously, this depends on your goal.

blog01-04

Now, the transport portion.  This may depend on your system and your plans.  For me, I want to make sure I can transport this forward, but perhaps you’re just playing.  In that event, skip the package, and just select Local Object

blog01-05

But, if you choose a transportable object, you’ll need to create a transport.

blog01-06

Give it a description, press Save.

blog01-07

Now your transport is listed, press the green check to accept it.

blog01-08

Finally, we just need to make some minor updates, like the program title.  Select Attributes and Press Change.

blog01-09

Change the title and press Save.

blog01-10

Normally, I’ll change the boilerplate as well.

blog01-11

Once I add the information to boiler plate, you can activate it, and even execute it if you choose (granted, it’ll execute the program you copied, but at least you can be sure syntax is good to go).

There you go…  how to properly copy an ABAP program.

Thanks for Reading,

 

ABAP – Finding Field and Type

Well, it occurred to me.  I have a new intern, and he knows nothing about SAP or ABAP.  So I’m having to go back to the beginning to try to get him in the swing of things.  So, I thought I’d start throwing some of the things I’m teaching him out here.  Who knows?  maybe it’s useful to some of you out there too 🙂  Today I’m going back to the very basics.  Finding field and type from a screen.

For this example, I’m using transaction IW41

blog03-01

Highlight the field you want information on.

blog03-02

Press the technical details button.

blog03-03

This magical screen gives you quite a bit of information.  Typically, Field Name and Data Type are the most valuable.  Occasionally, you can even get the Table name.  In a future post, I’ll talk about digging further when this screen only gives you a structure (which happens quite often).

Thanks for reading,