Just fill in the blanks
It feels like the school books, one just needs to fill in the blanks :-)
Labels: abap
On SAP SCM/APO, life and tech
Labels: abap
One of the hot topics for me last year was doing SAP development for mobile platforms. There is a huge quantity and quality of enterprise information inside SAP servers and the new wave of mobile devices opens so many new ways of interacting with that data and business processes. I did not write much on that topic in the blog but on onsap you can find many questions and answers related to the technologies I was using.
There are many platforms and toolkits for mobile development (and that is a good topic for another blog post that I hope to write one day). My choice of platform is jQuery Mobile for the frontend development and business server pages (BSP) for the backend development. With this stack it is possible to develop solutions using the platforms companies already have (ECC and other solutions based on Netweaver) and using an open toolkit that is evolving quickly and at the same time is stable and tested in a large number of devices.
As a result of some of that work we, at Cognitiva, are releasing an open-source package with some utilities to help development of jQuery Mobile on SAP. It includes sample applications like the one show in action in the video below, and it also includes a search help widget that is described in detail in this SDN blog post.
If you have interest in mobile apps give this technology a try. The source code is available in this repository and it is possible to run a demo application with the free Netweaver developer edition.
Labels: abap, javascript, jquery, mobile
>>> import random
>>> for i in range(20):
... print random.choice(['A','B','C','D']),
...
C A D C C D A D C B B B B C B C A C D B
class lcl_random definition.
public section.
class-methods choice importing it_table type standard table
exporting es_row type any.
endclass.
class lcl_random implementation.
method choice.
data: l_size type i,
l_index type i.
describe table it_table lines l_size.
call function 'QF05_RANDOM_INTEGER'
exporting
ran_int_max = l_size
ran_int_min = 1
importing
ran_int = l_index
exceptions
invalid_input = 1
others = 2.
if sy-subrc = 0.
read table it_table into es_row index l_index.
endif.
endmethod.
endclass.
form test.
data: lt_test type table of char1,
l_test type char1.
l_test = 'A'.
append l_test to lt_test.
l_test = 'B'.
append l_test to lt_test.
l_test = 'C'.
append l_test to lt_test.
l_test = 'D'.
append l_test to lt_test.
do 20 times.
lcl_random=>choice( exporting it_table = lt_test importing es_row = l_test ).
write: l_test.
enddo.
endform.
Labels: abap
A very simple trick that I only learned recently. A couple of times I faced the situation that I had a function that I could call to solve my problem. I would like to do it in SE37, but the function would need a COMMIT to be called after execution. I thought it was not possible to do in SE37 but it actually is. There is an option to test sequences:

So I just need to put my function and to perform the commit I can use the standard function BAPI_TRANSACTION_COMMIT.

Labels: abap



report z_top_used_functions.
tables cross.
data:
gt_objs type table of ztopusedfunctions.
selection-screen begin of block 0 with frame title text-002.
select-options:
s_name for cross-name.
selection-screen end of block 0.
selection-screen begin of block 1 with frame title text-001.
parameters:
p_type like cross-type default 'F',
p_max type tbmaxsel default 200.
selection-screen end of block 1.
start-of-selection.
clear gt_objs.
refresh gt_objs.
select name count(*) as counter
from cross
up to p_max rows
into table gt_objs
where type = p_type
and name in s_name
group by name
order by counter descending.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_structure_name = 'ZTOPUSEDFUNCTIONS'
tables
t_outtab = gt_objs.


CALL METHOD /sapapo/cl_atpfield_buf=>get_atpfield
EXPORTING
iv_ordid = lv_ordid
iv_delps = lv_delps
IMPORTING
et_atpfield = lt_atpfield.
DATA:
l_name(150) TYPE c,
l_tabtype(150) TYPE c,
ldr_reqref TYPE REF TO data.
FIELD-SYMBOLS:
<reqref_t> TYPE ANY TABLE.
l_name = '\PROGRAM=/SAPAPO/SAPLATPT\CLASS=LCL_REQUIREMENT_ATP'.
l_tabtype = '\PROGRAM=/SAPAPO/SAPLATPT\TYPE=TBL_REQREF'.
CREATE DATA ldr_reqref TYPE (l_tabtype).
ASSIGN ldr_reqref->* TO <reqref_t> CASTING TYPE (l_tabtype).
CALL METHOD (l_name)=>get_instances
RECEIVING rt_reqref = <reqref_t>.

FUNCTION z_macro_maxmode .
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" VALUE_TAB STRUCTURE /SAPAPO/VALUE_TAB
*" CHANGING
*" REFERENCE(F_CALC_ERROR) TYPE C
*" REFERENCE(F_ARGUMENT) TYPE /SAPAPO/MXSOP-V
*"----------------------------------------------------------------------
TYPES:
BEGIN OF t_histogram,
value TYPE i,
counter TYPE i,
END OF t_histogram.
DATA:
lv_value TYPE i,
ls_hist TYPE t_histogram,
lt_hist TYPE TABLE OF t_histogram WITH KEY value.
LOOP AT value_tab.
IF value_tab-string IS INITIAL.
CLEAR ls_hist.
* just truncated integers to make it simpler
lv_value = trunc( value_tab-value ).
READ TABLE lt_hist WITH TABLE KEY value = lv_value INTO ls_hist.
IF sy-subrc = 0.
* already in the table, increase the counter
ls_hist-counter = ls_hist-counter + 1.
MODIFY TABLE lt_hist FROM ls_hist TRANSPORTING counter.
ELSE.
* insert value for the first time in the table
ls_hist-value = lv_value.
ls_hist-counter = 1.
INSERT ls_hist INTO TABLE lt_hist.
ENDIF.
ENDIF.
ENDLOOP.
* return the integer with largest counter (if more than one return the
* largest integer)
SORT lt_hist BY counter DESCENDING value DESCENDING.
READ TABLE lt_hist INDEX 1 INTO ls_hist.
f_argument = ls_hist-value.
ENDFUNCTION.








http://myserver.com/mypage?x=1&y=10
len("x=1&y=10") = 8
ABSOLUTE_URI http://myserver.com/mypage
REQUEST_ENTITY_BODY_LENGTH 8
REQUEST_ENTITY_BODY x=1&y=10
Labels: abap