1 1 1 1 1 Rating 0% (0 Votes)
In article Delete Routing - piece of cake I've shown you how to use FM from CEWB transaction to delete routings. If you go through all FM that are inside function groups of CEWB then you'll see that there is a lot of possibilities there. For example creation of a new routing, you can do it step by step or create a routing on a base of existing one. Today I'll show how to copy existing routing to new one with usage of FM CP_CC_S_LOAD_COMPLEX_BY_TSK to load source routing to memory , CP_CC_S_COPY_BY_TSK to copy areas we want and CP_CC_S_SAVE to save new routing to database. In my example I will copy completely source routing to target but in any case you can also omit some of the areas and create them after save (like material allocation or components assignment ).
Read more ...

4.66666666667 1 1 1 1 1 Rating 93% (15 Votes)
I think that any of us had meet the situation when we needed to create an Excel output from internal table in background. There is a really nice project called ABAP2XLSX which gives you to possibility to do all you need but in some case you won't be allowed to install ABAP2XLSX at you SAP instance. Don't worry there is a way to do it, but in older SAP version we will be allowed only to save the file as MHTML excel (like in ALV->Export to Spreadsheet). In newest version we're able save the file directly to XLSX also. In a method shown bellow you can see that to create Excel file you need to only pass internal table, the rest of the parameters are option which gives you opurtinity to pass the settings you've made in your program to the output file. 

So what am I doing here.... firstly I check if the fieldcatalog was passed. If not then I create it on a base of internal table with usage of cl_salv_table  and cl_salv_controller_metadata=>get_lvc_fieldcatalog. After I finally have the fieldcatalog I create result table with sort and filter criteria if they were passed. To do that  I use class cl_salv_ex_util. At the end result table is transformed to xstring with method cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform. So you're receiving at the end of the method an xstring file so you can do what you want with it, for example send via mail to the user, or save it on local PC (like in the example found at the end). The most important is that you can use this method in a background so you can prepare some jobs for your programs and send results of them to the users!

it_fieldcat type lvc_t_fcat optional -> field catalog for list viewer control
it_sort type lvc_t_sort optional -> alv control: table of sort criteria
it_filt type lvc_t_filt optional -> alv control: table of filter conditions
is_layout type lvc_s_layo optional -> alv control: layout structure
i_xlsx type flag optional -> create xlsx file?

Add a comment
Read more ...

4.66666666667 1 1 1 1 1 Rating 93% (3 Votes)
ALV Grid gives us some possibilities for easier reading of the grid content like "zebra" or colored rows. But when this is not enough and you want to make sure that users will focus on part of the rows only, then you have additionally two options:
1st) Add empty line after each part you want to separate and color it differently; 
2nd) Use subototals of ALV Grid to do it instead of you (but without any values).

Adding empty lines will force you to delete all of them each time you'll do changes inside table displayed in grid and you'll have to do the calculation of position again, that's why today I will show you the second option. 
I will use event subtotal_text for cl_gui_alv_grid, three additional colums in internal table (for sorting and separating key) and  lvc_s_layo settings NO_TOTEXPNO_TOTLINENO_ROWMARK.
Read more ...

5 1 1 1 1 1 Rating 100% (3 Votes)

When you use CL_GUI_ALV_GRID in edit mode or you change your internal table used to display data on ALV grid it may happen that after refreshing the grid using refresh_table_display your cursor or scroll goes to the begining of the grid. Users feels little lost in such situation but there is an easy solution for that.

datais_stable type lvc_s_stbl.
is_stable-row 'X'.
is_stable-col 'X'.
is_stable 'XX'.

    is_stable      =   is_stable   " With Stable Rows/Columns
*    i_soft_refresh =   i_soft_refresh  " Without Sort, Filter, etc.
    finished       1
    others         2
if sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
*            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EDIT: Method of mine which can be found bellow doesn't have to be used to achieve your goal. To be honest I can't remember why I created separate version of it as only the cursor act a bit different than oryginal one. I must have had mind eclipse at the time :-) . Excuse me for that.

So to keep scroll position and current cell we will need to use  following methods of CL_GUI_ALV_GRID:

  • get_scroll_info_via_id - gets current scroll information

  • get_current_cell         - gets current cell, we will use that data to set the cursor at the end

  • get_selected_rows      - gets selected rows

  • get_selected_cells_id  - if we didn't select any rows, we check for the selected cell information

  • refresh_table_display  - then simple refresh of grid

  • set_selected_cells_id   - after refresh it's time to set back all information, so set selected cell

  • set_selected_rows       - or set seleted rows (depanding what we received at the begining)

  • set_scroll_info_via_id  - set scroll position back

  • set_current_cell_via_id - set cursor back.

There is no special coding here, just standard ALV grid methods used in proper order.

Method definition, Importing parameters:


Changing parameters:


Add a comment
Read more ...

1 1 1 1 1 Rating 0% (0 Votes)

In previous post I've shown how to zip file directly on PC without using CL_ABAP_ZIP, this time I will show you how easy is to use OLE2_OBJECT to create an MS Outlook message with attachment and save it in Outlook's Drafts folder. OLE2_OBJECT in fact can be used with any application that allows it, but today I will only show a hint how to work with MS Outlook.

I know that most of us use CL_BCS to create and send the message directly from SAP, but in a situation when you're working on local files then It may be better to do it with Outlook. This is of course just a short sample of the possibilities, all functions for OLE & MS you can find in MSDN documents.

Here is the code with f_path parameter which is used to pass path of local file to attach to message:

Add a comment
Read more ...

5 1 1 1 1 1 Rating 100% (1 Vote)

From time to time you have to work on files that are stored in user PC, like when you're working with SOI (SAP Office Integration) for example. All operations that are done are save directly to a file which is stored on PC so if you would like to zip it with cl_abap_zip class then you would need to copy file to ABAP memory, then zip it using cl_abap_zip and then save back file to PC. Sometimes this is not the best solution, especially when working on slow connections via VPN or similar. So with help there goes cl_gui_frontend_services=>execute. This method allows you to run every file on PC directly - also a program with proper parameters. In my example I will use IZArc (it's free and fast).

So what I'm doing here is:
- passing full path to the file which will be zipped
- call cl_gui_frontend_services=>environment_get_variable to check program files directories
- concatenate file path with parameter of IZArc "-ad"
- concatenate program files directories with 'IZArc\IZArc.exe'
- check if IZArc exists with  cl_gui_frontend_services=>file_exist
- if yes then I'm executing it with cl_gui_frontend_services=>execute.

Here is the full code for such function:

Add a comment
Read more ...

5 1 1 1 1 1 Rating 100% (3 Votes)

If during creation of purchase requisition you've attached some documents into requisition and you convert requisition to purchase order then the attachments aren't copy to PO. But you can do it either by daily job or by the implementation of user-exit if you know how to link GOS object to PO. I faced a request to copy attachments from PR to PO, but what I did was in fact just linking existing attachment to PO. In that way you do not double the same content on server. Bellow you can find the code of an function module which uses 'BINARY_RELATION_CREATE' and 'BINARY_RELATION_CREATE_COMMIT'.

  • Importing

I_EBELN TYPE EBELN -> Purchase Order number
I_COMMIT TYPE C     -> Do you want to do the commit?

  • Tables

T_EBAN STRUCTURE EBAN  -> Table with PR lines to check GOS relations

  • Exceptions


Add a comment
Read more ...

1 1 1 1 1 Rating 0% (0 Votes)

At the very begining when I started to develop in ABAP I was wondering why I cannot clear all global data at once after I do all my calculations? As this is something that it's very useful when you create a report which just show some figures and you don't need anymore all the internal tables or objects that you used to prepare output table. So to free memory then just before calling ALV I was always refreshing all tables and clearing work areas, but this was something that had to be done manually so I was a little bit angry that I cannot automize it... and then I started to look for the way how to automize it.

I knew that SE80 is displaying all globals but I couldn't find how it's done there. As you may know debuggin the code which was done by SAP is creepy usually and after spending some hours on that I gave up. But it returned someday I just simply saw FM 'RS_PROGRAM_INDEX' and that was enough to create fast a method to free all global data for me. 

So let's start with definition. We will need a range type which we will use to call the method with objects to be excluded from clearing (like ALV output table or ALV objects)

Add a comment
Read more ...
Page 4 of 4