ABAP Coding

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

Netweaver Gateway – Creating a Service from RFC

Well, picking up where we left off on Netweaver Gateway.  Last time we created the project, now it’s time to actually create the service.  In my example, I have already created an RFC to feed the information I need to the service.  So, here’s how to do it.  Return to transaction SEGW.

segw03

next…

segw04

Here, you need to give it an entity name.  This is what you’ll be using going forward.  Select the type as Remote function call, and then list the name of the function.

segw05

Now we get to the magic.  The RFC has now pulled in all the inputs and outputs from the function.  Now, you check the fields you want to make part of your “entity”.  The entity will contain the fields that you plan to extract or feed into your service.

segw06

After you select the fields you want, you must define at least one key.

segw07

Now, you have the entity.  With this piece, you’re ready to start doing something with the data.

In a future post, I’ll talk about the next steps for the service.

Thanks for reading,

ABAP – Web Dynpro – Dynamic Cell Variants

Well, in my continued adventure, I found a new component in web dynpro call a cell variant.  The basic idea behind this is that you can change what kind of cell is within a table.  For example, sometimes you may want a field editable, based on the contents, and other times it should just be a text view.  Well, I had something similar in my latest web dynpro experiment.  I needed to do  dynamic cell variants.  By this, I wanted to add the cell variant to an ALV table, so I couldn’t just manually add it to the column.  Well, thanks a cool document I found, I was able to pull this off…  mostly.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0e7461d-5e6c-2b10-dda9-9e99df4d136d?overridelayout=true

Now, I use the term mostly, because of course, I tried branch out on my own.  It’s probably easiest to explain with a little code and my example.  First, I had a column in my ALV table that either listed a single serial number, or should provide a link to another window to show all the serial numbers associated with the document.  This is perfect for the cell variant.  I set it up so that

Here’s where I started, and syntactically, it would fine:

data: l_cv_ser TYPE REF TO cl_salv_wd_cv_standard,
lr_link_ser TYPE REF TO cl_salv_wd_uie_link_to_action,
l_col TYPE REF TO cl_salv_wd_column.

create OBJECT lr_link_ser.
lr_link_ser->set_text_fieldname( EXPORTING value = ‘SERNR’ ).
* create cell variant
create OBJECT l_cv_ser.
  l_cv_ser->set_key( VALUE = ‘MULTIPLE’ ).
* add link to action editor
l_cv_ser->set_editor( lr_link_ser ).
* Get column
l_col = lv_value->if_salv_wd_column_settings~get_column( ‘SERNR’ ).
* add cell variant to column
l_col->add_cell_variant( r_cell_variant = l_cv_ser ).
* assign attribute
  l_col->set_sel_cell_variant_fieldname( ‘SERNR’ ).

Now, if you pay close attention to the bold lines, these were my problem.  See, the data in the column might be MULTIPLE, or it be 1, 2, 3, 800034234, or any serial number.  So in my initial testing, it was all multiple, so it worked great.  suddenly I was getting a short dump when it hit a cell with a value other than MULTIPLE.  It finally hit me…  with a cell variant, you either need to define an editor for each value in the column?  or you need to make a new column with only 1 value or blank.  i ended up going down the second path.

data: l_cv_ser TYPE REF TO cl_salv_wd_cv_standard,
lr_link_ser TYPE REF TO cl_salv_wd_uie_link_to_action,
l_col TYPE REF TO cl_salv_wd_column.

create OBJECT lr_link_ser.
lr_link_ser->set_text_fieldname( EXPORTING value = ‘SERNR’ ).
* create cell variant
create OBJECT l_cv_ser.
l_cv_ser->set_key( VALUE = ‘X’ ).
* add link to action editor
l_cv_ser->set_editor( lr_link_ser ).
* Get column
l_col = lv_value->if_salv_wd_column_settings~get_column( ‘SERNR’ ).
* add cell variant to column
l_col->add_cell_variant( r_cell_variant = l_cv_ser ).
* assign attribute
l_col->set_sel_cell_variant_fieldname( ‘CV_SER’ ).
lv_value->if_salv_wd_column_settings~delete_column( id = ‘CV_SER’ ).

I hope this sheds some light on the cell variant.  it really is a pretty slick tool.
Thanks for reading,

Netweaver Gateway – Creating the Project

Well, since I recently spoke about using the gateway client, I figured I should talk about creating the service to use the gateway client.  The first step in this process is creating the project.  Like so many things, you must start small in order to build…  so let’s the netweaver gateway project and get this party started.

First, go to transaction SEGW

segw01

Press Create.

segw02

Now, put in the project name, description and package.  For me, I do everything within my own namespace, so notice how both the project and the package must start with the namespace.  Press the green check and you have your project.

segw021

In future posts, I’ll walk you through the next steps.

Thanks for reading,

Netweaver Gateway – Using the Gateway Client

Well, I just found a great document out there in SCN for how to use the Gateway Client.  I was kind of struggling with this, but after finding this trick, it makes it a lot easier.

http://scn.sap.com/docs/DOC-47626

There really isn’t a lot to say about this.  The author did a great job of making it simple.  I’ll be doing more posts in the near future about NW gateway, since I’ve recently learned how to make an RFC and create a service for it in the Gateway.  Don’t want to forget what I learned, and maybe you will find it valuable as well.

Thanks for reading,

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,