Tuesday 6 August 2013

Coding for the Editor?

Note the title. Not Coding IN the Editor, Coding FOR the Editor.
Alright, I'm sorry. You're used to high-grade, good quality tutorial stuff. This is more of a musing / comment.

I find myself doing same-same stuff all the time - tidying up code so it lines up nicely ( a pretty printer that works, anyone? ). 

It'd be super awesome if the editor had some kind of development framework so you could record macros, and then edit the code those macros created... Kind of like VBScript?

An obvious example would be you paste a list of fields from a data dictionary structure. A popup could come along and ask what the WorkArea field was, and prefix the fields; then all you'd need to do would be populate the fields... saving you literally minutes every time you do it!


Wednesday 22 May 2013

Mass Uploading of MIME Types to Transport

Brief : Package SMIME has lots of MIME interrogation objects in it.
By copying a BSP Application, you can attach all it's MIMEs to a transport.
You can't rename a BSP Application.

Our problem here is that we've developed a massive BSP with a bazillion MIMEs in it...

 We could quite easily hold down shift, select the first file in the folder, and then the last one, and rightclick. This only works for the folder though. 
So I was about to write a program that interrogates the MIME repository (Package SMIMES for the win there) and finds the MIME keys, and then uses those to attach to a transport. (Hadn't worked that bit out yet...)

THEN.... we were also asked to rename our BSP Application, because it'd been developed under some ZTEST_APP style name.
Now you can't rename a BSP application, so we cheekily copied it and deleted the original. Upon copying, we were obviously given a transport number, but also asked if the new BSP Application wanted the original's MIMEs. So I ticked that box, and the app then started chugging through, copying the 1400 MIMEs across, and .... attaching them to the new transport!
So flukily, saved myself the half a day it would have taken to write the program! 

Monday 20 May 2013

WD4A Popup Decision box

Just found totally excellent step-by-step for WD4A popup decision box. Not going to rehash it here, as it's soooo good to begin with, it doesn't need any further explanation!

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40bbbbf6-4fec-2e10-4fa1-b57866732ee0?QuickLink=index&overridelayout=true&52828097790413

Wednesday 15 May 2013

Paramaterising a Web Dynpro


So I wanted to Paramaterise my Web Dynpro. At the moment, we give out users a front screen that allows them to enter the Document #, and then view the Document.

What you’re looking at here is part of my WebDynpro application, the top view that you see when you first call the application…The requirement was that another Web Frontend Application (a really sexy BSP written by a company that does Websites) could call the WebDynpro by way of a paramaterised URL.

Chances are you see Paramaterised URLs all the time :Stuff like 

https://www.google.co.uk/search?q=dynamo 

Shows that you’re searching for dynamo on google. I started by adding I_QMNUM to the Paramaters list of the Application. 
You don’t really need to Type this, because it’ll just behave like a string regardless, and lots of browsers will do a bit of escape-charactering to it anyway.

I then put the following code into the HandleDefault Method of the main WINDOW (not view!) of the Application.



method HANDLEDEFAULT .

DATA it_parameter TYPE tihttpnvp,
         wa_parameter  
TYPE ihttpnvp.

  
DATA lo_nd_url_param TYPE REF TO if_wd_context_node.
*  DATA ls_url_param TYPE wd_this->element_url_param.

  
" Get all URL parameters
  
CALL METHOD wdevent->get_data
    
EXPORTING
      name  
if_wd_application=>all_url_parameters
    
IMPORTING
      
value it_parameter.

*  " Get parameter values
*  CLEAR wa_parameter.
  
READ TABLE it_parameter WITH KEY name 'I_QMNUM' INTO wa_parameter.
  
IF sy-subrc EQ 0.
     l_qmnum 
wa_parameter-value.
  
ENDIF.

Endmethod.

I then gave it a quick test.
I dropped an external breakpoint at the top of my code in the HANDLEDEFAULT method.
I went to my application in Internet Explorer, and opened my application as usual.
The Code was hit, but the it_paramater field wasn’t populated.

Now my usual url is
http://<servername>/sap/bc/webdynpro/sap/zhpewd_zecn_dash_chrome?sap-client=101&sap-language=EN

If I tag the I_QMNUM data on the end of it. (My QMNUM of choice is GB0002280), and plug in

http:// <servername /sap/bc/webdynpro/sap/zhpewd_zecn_dash_chrome?sap-client=101&sap-language=EN&I_QMNUM=GB0002280

to my browser bar…
when I hit the breakpoint, I’ve got it_parameter populated with the I_QMNUM!



Now all I’ve got to do is copy the code from the button press on the front screen which calls the document. But that’s the bit I already know how to do, so I’m not going to document that unless it throws up something interesting!








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! :) )