Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Restful State Web Service

Former Member
0 Kudos
301

Hey All, (UPDATED WITH DISCOVERIES)

I have this odd problem with a simple restful state web service that I'm putting together. I want the user to be able to post in IE either a variant or a material number. For instance either...

http://devisrv.internal.upsher-smith.com:8000/sap/USL/weeksonhand?<variant>;

http://devisrv.internal.upsher-smith.com:8000/sap/USL/weeksonhand?<material#>;

would elicit an xml response. The problem I'm having is that the <variant> one won't work. When I debug it in SAP all looks fine, but when submitting from a browser it cannot find any of the variants. I guess the question is...how do I debug from a browser??? or, is there something obvious in my simple code below that is wrong??? What has me stumped is that the <material#> version works great. ??

I've now discovered that it is the ALPHA characters that is causing the problem. I send in a parameter that is '12345' and it is fine, but I put in a '123R5' and it fails. If I hardcode the alpha characters directly into the program it also has an issue, so it is not how the program is receiving the ~path_info or the ~query_string. I've not encountered an issue with processing alphas in background, then again I've sadly not done much OO programming so this may be the whole issue in the end. Still stuck, but still tryin'.

Any insight would be greatly appreciated.

Greg

METHOD if_http_extension~handle_request.

DATA: path_info TYPE string,

w_body TYPE string,

parameter TYPE string,

variant TYPE variant,

matnr TYPE matnr,

zweeksreturn TYPE TABLE OF zweeksreturn,

type(10) TYPE c,

xml_out TYPE string,

value TYPE string.

FIELD-SYMBOLS: <zweeksreturn> TYPE zweeksreturn.

path_info = server->request->get_header_field( name = '~query_string' ).

parameter = path_info.

SELECT SINGLE variant INTO variant FROM varid

WHERE report = 'ZRPP_WEEKS_ON_HAND'

AND variant = parameter.

IF sy-subrc = 0.

type = 'VARIANT'.

ENDIF.

SELECT SINGLE matnr INTO matnr FROM mara

WHERE matnr = parameter.

IF sy-subrc = 0.

type = 'MATERIAL'.

ENDIF.

CASE type.

WHEN 'VARIANT'.

CALL FUNCTION 'Z_WS_WEEKS_ON_HAND'

EXPORTING

i_variant = variant

TABLES

t_return = zweeksreturn.

CALL TRANSFORMATION id

SOURCE table = zweeksreturn

RESULT XML xml_out.

WHEN 'MATERIAL'.

CALL FUNCTION 'Z_WS_WEEKS_ON_HAND'

EXPORTING

i_material = matnr

i_period = 'Z1'

TABLES

t_return = zweeksreturn.

CALL TRANSFORMATION id

SOURCE table = zweeksreturn

RESULT XML xml_out.

WHEN OTHERS.

CONCATENATE '<html>'

'<head>'

'<title>Parameter is neither a variant nor a material</title>'

'</head>'

'<body>'

'<h1>Parameter&nbsp;'

parameter

'&nbsp;not found</h1>'

'</body>'

'</html>'

INTO xml_out.

ENDCASE.

CALL METHOD server->response->set_cdata( data = xml_out ).

ENDMETHOD.

Edited by: Greg Foss on Feb 11, 2009 9:55 PM

Edited by: Greg Foss on Feb 11, 2009 10:02 PM

4 REPLIES 4

mvoros
Active Contributor
0 Kudos
109

Hi,

it looks like you have some problems with encoding/decoding URL. So I have one tip for you: have a look at class CL_HTTP_UTILITY. This class has methods like escape_url/unescape_url or encode_/decode_. Try to convert your paramter using one of these methods. Maybe it will solve your problems.

Good luck

Former Member
0 Kudos
109

Thanks Martin for your input. I have more information related to my problem. It seems I've been chasing ghosts and the URL has nothing to do with it. Here is what I have so far. I've simplified the already simple code to JUST return the material number that was hardcoded in the program. If this program is run in SAP in debug, it works fine...if it is triggered by the browser...it fails. Now this only happens when the hardcoded material number has alpha characters in it. Notice that in the simplified code the handler doesn't care what was sent by the browser, it should return <MATNR>ZNON-ALCOHOL</MATNR>...simple right?

Here is the simplified code. The mystery...what is different about it when triggered by the browser as opposed to just running it in SAP. The latter works fine, the former doesn't. ?

METHOD if_http_extension~handle_request.

DATA: xml_out TYPE string,

var2 TYPE matnr,

lv_matnr TYPE matnr.

var2 = 'ZNON-ALCOHOL'.

SELECT SINGLE matnr INTO lv_matnr FROM mara

WHERE matnr = var2.

IF sy-subrc = 0.

CALL TRANSFORMATION id

SOURCE XML = lv_matnr

RESULT XML xml_out.

ENDIF.

CALL METHOD server->response->set_cdata( data = xml_out ).

ENDMETHOD. "if_http_extension~handle_

0 Kudos
109

Hi,

another wild guess. Don't you use long names for materials. The type matnr is only 18 characters long but you can still have longer names. SAP has internal numbering for material but it displays long name. You can check in SE11 conversion routine for domain MATNR. So instead of ZNON-ALCOHOL maybe you need to use number corresponding to this material name. Try to conver it using conversion routine. I do not have access to SAP system right now and I do not remember FM name.

Good luck

Former Member
0 Kudos
109

Ok...this is a wierd issue so I wanted to document it for anyone else having odd issues with web services.

It turns out that I could not get the debugger to activate externally or anything. My service had been setup with a 'Standard Logon' and no anonymous user. I believed (and I believe it should be this way) that a standard logon requires the user to login manually, therefore the authorization credentials for that user should be taken from SAP. However, somewhere the authorization credentials are NOT passed, and the behaviour of the code is affected. In my case above, the SELECT statement worked differently. (God don't ask me more details than that, I just know it didn't take alpha characters). Anyway, when adding a 'Anonymous Logon Data' entry into the web service the code behaved differently (correctly). Even though the anonymous user and the standard user were the SAME USER, they behaved differently. More than that, I do not know...suffice it to say...

If you are having an issue with your web service and you can't figure out what the hell is going on, make sure that you are using an anonymous logon (preferably with a service user). Why this would affect the behaviour of the code? I don't know, but it does.

Thanks,

Greg