Tuesday 23 April 2013

WD4A - No direct access to context from Assistance Class!?

So in trying to tidy up my code, by segregating out the stuff in the Views Methods and putting it into the assistance class methods, I think to myself, "this is gonna be great! all that code that the wizard produces when accessing the context node, I can just hive that off into it's own method, my code will look loads neater!". 

I mean, for goodness sake, that wizard produces like 8 lines of code, just to read 1 variable. Seems a bit heavy handed. If only I could hide it.

So I tried something like this in my Assistance Class, expecting it to be able to see the Application's component controller:

data: lo_nd_qmel type ref to if_wd_context_node.

lo_nd_qmel = wd_context->get_child_node( name = wd_this->wdctx_qmel )

but it gives me an error saying that it didn't know what wd_context was.
So you've got to drag stuff out of the context, and put it into the Assistance Class variables.

Which may well end up with the comedy situation of having 8 lines to extract and set the data, then calling the assistance class (say... 4 lines to call it, and it contains 10 lines) . 

And then maybe another few for updating the variables back into the screen!

Friday 19 April 2013

WebDynpro for ABAP - Cardinality Violated!

I get the following error:

The following error text was processed in the system MIE : Number of Elements of the Collection of Node COMPONENTCONTROLLER.1.PRELM_PARTS Violates the Cardinality. 

When running my WebDynpro Application - it's output on a web browser screen that looks like this:


Basically what I've done is tried to code a table onto a Node that I've set Cardinality of 0-1.
I need a 0-n cardinality.
So I go back into my populating Method - it's got the following code, which ties the table to the node : 


  wd_node = wd_context->get_child_node( name = 'PRELM_PARTS' ).
  wd_node->bind_table( new_items = t_prelm_parts ).

But if I look at the Context node, I can see that it has a 1-1 cardinality




By re-defining this as 0..n I can bind a table to it.
In this case, the Context Node was mapped from the Component Controller Context Node, so I had to redefine that, and then update the mapping.

Files in a folder...

Not being a proper basis geek, I often get confused with file string formatting to describe locations and so on. Forward/back slashes directories, folders etc. 
On our project, a third party is FTPing into our SAP system, then telling us via a PI service where that folder is.
I can read the files using good olde "Open dataset" statement, but I need to know what they are first.

Here's the directory I wanted to read: (Transaction AL11)



Here's my code:


REPORT  YPD_GET_FILES_LIST.
data: dir_list type TABLE OF EPSFILI,
      file type epsfili,
      dir_name type EPSF-EPSDIRNAM.

dir_name = '/usr/sap/MIE/EB'.
CONCATENATE dir_name '/LCAPreRelease/EngData/GB/A/3000-3999' into dir_name.


CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
  EXPORTING
    DIR_NAME                     = DIR_NAME
  TABLES
    DIR_LIST                     = DIR_LIST
 EXCEPTIONS
   INVALID_EPS_SUBDIR           = 1
   SAPGPARAM_FAILED             = 2
   BUILD_DIRECTORY_FAILED       = 3
   NO_AUTHORIZATION             = 4
   READ_DIRECTORY_FAILED        = 5
   TOO_MANY_READ_ERRORS         = 6
   EMPTY_DIRECTORY_LIST         = 7
   OTHERS                       = 8.

LOOP AT DIR_list into file.
  write:/ file-name.
endloop.


So the thing to notice is that the function module expects EXACTLY what you see in transaction AL11

(*EDIT - I switched out EPS_GET for EPS2_GET as it allows 200char filenames, rather than the pansy 60 that EPS_GET allows! :) )