• Home
  • About me
  • FALV
  • ALV Grid in the nutshell
    • Basic Information
    • Field catalog
  • Articles
    • Tricks
    • FALV (Fast ALV Grid)
    • ALV Grid in the nutshell
    • Tips
    • How to...
    • For beginners
    • Thoughts
  • By Topic
    • ALV
    • ALV OO
    • SALV
    • GOS
    • Selection screen
    • Purchase Requisitions
    • Purchase Orders
    • Attachments
    • Others
    • Characteristics
    • Sample Programs
    • ZIP
    • OLE
    • Mails
    • Routings
    • EWB
    • Excel
  • Keywords
  • RSS
  • Download
  • Home
  • Articles
  • Tricks

Range to search in lower case fields

Details
Łukasz Pęgiel
Tricks
13 March 2014
Hits: 12021
Tags: LOWER CASE , UPPER CASE , SEARCH , LOOP , SELECT
It may happen that you'll need to do select or loop on a base of the field which is kept in lower case, but you don't know exactly what's the value o field. In such case you may want to build a range of the possible values to be able to fulfill the task. Here is how to do it quite fast by doing FM:
 

function z_ab_prep_val_for_case_search.
*"--------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_TEXT) TYPE  CSEQUENCE
*"     VALUE(I_SIGN) TYPE  CHAR1
*"     VALUE(I_OPTION) TYPE  CHAR2
*"  EXPORTING
*"     REFERENCE(ER_RANGE) TYPE  STANDARD TABLE
*"--------------------------------------------------------------------
  field-symbols: <low> type any.
  field-symbols: <sign> type any.
  field-symbols: <opt> type any.
  field-symbols: <line> type any.
  field-symbols: <linenew> type any.
  field-symbols: <lownew> type any.
  field-symbols: <tab> type standard table.
  data: f_times type i.
  data: f_text type string.
  data: f_textnew type string.
  data: f_insidel type i.
  data: f_insidel2 type i.
  data: ft_data type ref to data.

  "create temp table and assign it to FS
  create data ft_data like er_range.
  assign ft_data->* to <tab>.

  f_text = i_text.

  "get lenght
  f_times = strlen( f_text ).
  "translate to upper case so we have always same start
  translate f_text to upper case.

  "append initial line to range and put first value into table
  append initial line to er_range assigning <line>.
  check sy-subrc eq 0.
  assign component 'LOW' of structure <line> to <low>.
  check sy-subrc eq 0.
  <low> = i_text. "all in uppercase
  assign component 'SIGN' of structure <line> to <sign>.
  check sy-subrc eq 0.
  <sign> = i_sign.
  assign component 'OPTION' of structure <line> to <opt>.
  check sy-subrc eq 0.
  <opt> = i_option.
  translate <low> to upper case.

  "create entries for each other combination of cases
  do f_times times.
    f_insidel2 = sy-index - 1.
    loop at er_range assigning <line>.
      assign component 'LOW' of structure <line> to <low>.
      check sy-subrc eq 0.
      if f_text+f_insidel2(1) ca '*+' and ( i_option eq 'CP' or i_option eq 'NP' ).

      else.
        append initial line to <tab> assigning <linenew>.
        check sy-subrc eq 0.
        assign component 'LOW' of structure <linenew> to <lownew>.
        check sy-subrc eq 0.
        assign component 'SIGN' of structure <linenew> to <sign>.
        check sy-subrc eq 0.
        <sign> = i_sign.
        assign component 'OPTION' of structure <linenew> to <opt>.
        check sy-subrc eq 0.
        <opt> = i_option.
        <lownew> = <low>.
        f_textnew = <lownew>+f_insidel2(1).
        translate f_textnew to lower case.
        <lownew>+f_insidel2(1) = f_textnew.
      endif.
    endloop.
    append lines of <tab> to er_range.
    refresh <tab>[].
  enddo.

endfunction.

Add a comment
Read more ...

Extend allowed runtime of a program

Details
Łukasz Pęgiel
Tricks
25 June 2013
Hits: 17409
Tags: TH_REDISPATCH , COMMIT WORK , EXTEND PROGRAM RUNTIME , SAPGUI_PROGRESS_INDICATOR
When you create a report or transaction that handles a lot of data with multiple selects and functions that are doing some manipulation of the data, or you have to call in this report a function module thousand times and you want to be sure that no matter how long it takes it should be done but your system administrators have put some restrictions for time limit then you have to use one of this methods:
  1. Call commit work whenever you want to reset the counter of running time for your transaction (especially if you haven't done any update into database tables)
  2. If commit work doesn't work or you don't want to use it at the moment then you could use FM TH_REDISPATCH with the check_runtime parameter equal to 0.
  3. You could also you FM SAPGUI_PROGRESS_INDICATOR for the same purpose but keep in mind that showing indicator too often can slower your program.
Both of the methods will make that the counter for application runtime will be reset, but be careful this can make you application run really long. Also if you got one select statement which takes more than maximum runtime for your system then it will not help so you have to prepare your coding to be able to use any of this method, like spliting the selects statements to parts or to select single in the loop.
 

Although it's nice to know this possibility my advice is to not to use it very often as the less time you have for program run the more optimized code you can provide, so it's really something that you use if you do not have other choice and you agreed that with your system admins.

Examples: (run the program and look into SM50 to see the runtime)
Add a comment
Read more ...

Copy routing (create on a base of existing one)

Details
Łukasz Pęgiel
Tricks
26 May 2013
Hits: 17991
Tags: CP_CC_S_LOAD_COMPLEX_BY_TSK , CP_CC_S_COPY_BY_TSK , CP_CC_S_SAVE
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 ).
Add a comment
Read more ...

Create XLSX/MHTML file from internal table in background

Details
Łukasz Pęgiel
Tricks
12 May 2013
Hits: 208246
Tags: CL_SALV_COLUMNS_TABLE , CL_SALV_AGGREGATIONS , CL_SALV_TABLE , CL_SALV_CONTROLLER_METADATA=>GET_LVC_FIELDCATALOG , CL_SALV_EX_UTIL , CL_SALV_BS_TT_UTIL , SCMS_XSTRING_TO_BINARY
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!
 
Importing:

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 ...

Subtotal lines of ALV GRID OO as content separator

Details
Łukasz Pęgiel
Tricks
28 April 2013
Hits: 52430
Tags: NO_TOTEXP , NO_TOTLINE , NO_ROWMARK , SUBTOTAL_TEXT , CL_GUI_ALV_GRID
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_TOTEXP, NO_TOTLINE, NO_ROWMARK.
Add a comment
Read more ...

Refresh ALV GRID and keep position and current cell

Details
Łukasz Pęgiel
Tricks
22 April 2013
Hits: 131209
Tags: CL_GUI_ALV_GRID , GET_SCROLL_INFO_VIA_ID , GET_CURRENT_CELL , GET_SELECTED_ROWS , GET_SELECTED_CELLS_ID , REFRESH_TABLE_DISPLAY , SET_SELECTED_CELLS_ID , SET_SELECTED_ROWS , SET_SCROLL_INFO_VIA_ID , SET_CURRENT_CELL_VIA_ID

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.

data: is_stable type lvc_s_stbl.
is_stable-row = 'X'.
is_stable-col = 'X'.
"or 
is_stable = 'XX'.

grid->refresh_table_display(
  exporting
    is_stable      =   is_stable   " With Stable Rows/Columns
*    i_soft_refresh =   i_soft_refresh  " Without Sort, Filter, etc.
  exceptions
    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.
endif.

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:

I_SOFT TYPE CHAR01  DEFAULT 'X' 
I_SET_CURRENT TYPE CHAR01  DEFAULT SPACE 
I_SET_SELECTED TYPE CHAR01  DEFAULT SPACE

Changing parameters:

GRID TYPE REF TO CL_GUI_ALV_GRID 

Add a comment
Read more ...

Save message with attachment in Outlook's Drafts

Details
Łukasz Pęgiel
Tricks
16 April 2013
Hits: 36901
Tags: OLE2_OBJECT , MS OUTLOOK , OUTLOOK.APPLICATION

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 ...

Zipping in IZArc with ABAP directly on PC

Details
Łukasz Pęgiel
Tricks
15 April 2013
Hits: 14308
Tags: CL_GUI_FRONTEND_SERVICES=>EXECUTE , CL_GUI_FRONTEND_SERVICES=>ENVIRONMENT_GET_VARIABLE , CL_GUI_FRONTEND_SERVICES=>FILE_EXIST , CL_ABAP_ZIP

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 ...

More Articles ...

  1. Link Attachments of Purchase Requisition to Purchase Order
  2. Free global data of a program at once
Page 4 of 5
  • Start
  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • Next
  • End


Łukasz Pęgiel
ALV GRID REUSE ALV VARIANT ECLIPSE SALV CONTROLLER METADATA GTGET LVC FIELDCATALOG SAP TechEd ALV Grid in the nutshell not allowed CURRENCY CALL TRANSFORMATION DYNAMIC GUI STATUS COC1 FEATURE CHECK GUI HTML EDITOR MMIM REP CUST Battleships game two players ABAP Favorites Eclipse plugin TOOL ACCESS RELEASABLE ZDEMO FALV08 - Mass replace function GUI GRID ALV GRID IN THE NUTSHELL RM07DOCS Field catalog - tooltip ESRUO Basic Information Field catalog Field catalog - key sel INTTYPE LOOP AT SCREEN F4IF GET SHLP DESCR FALV VRM SET VALUES COMPONENTS REFRESH ACR ABAP TYPEDESCR READ USER OBJECTS Selection-Screen Function Key in Form POPUP QM ATTACHMENTS PROGRESS INDICATOR FCAT FRONTEND SERVICES EXECUTE CREATE COM MB51 ENHANCEMENT IXML PARSER BAPI OBJCL GETDETAIL ADT Create XLSX MHTML file from internal table in background ISTREAM MB51 OSTREAM GOS MANAGER FALV10 - Color Settings How to copy BOM using CEWB Function Modules TSK UNLOCK CUSTOM CONTAINER LOWERCASE SAVE SETTINGS CHANGE cookies ABAP in Eclipse JSON2ABAPtype SELECTED ROWS
  • Laserowe usuwanie blizn Tychy
  • Laserowe usuwanie zmarszczek Tychy
  • Salon Kosmetyczny Tychy
  • Trycholog Tychy
  • Wypadanie włosów Tychy
Tweets by abapblog

Eclipse Plugins for ABAP

ABAP Favorites

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client

ABAP ADT Extensions

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client

ABAP Quick Fixes

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client

 

Latest Articles

  • ABAP in Eclipse - Install, Configure, Use, and Enhance Your ADT
  • ALV Grid in the nutshell: Field catalog - col_id - ALV control: Column ID
  • ALV Grid in the nutshell: Field catalog - dfieldname – Fieldname for column group
  • ALV Grid in the nutshell: Field catalog - Hotspot - ALV control: SingleClick-sensitive
  • ALV Grid in the nutshell: Field catalog - sp_group - Group key
  • ALV Grid in the nutshell: Field catalog - domname - Domain name
  • ALV Grid in the nutshell: Field catalog - reprep - ALV control: Value is selection criterion for rep./rep.intf.
  • ALV Grid in the nutshell: Field catalog - reptext – Heading
  • ALV Grid in the nutshell: Field catalog - lowercase - Lowercase letters allowed/not allowed
  • ALV Grid in the nutshell: Field catalog - intlen - Internal Length in Bytes
  • Downloading Exchange Rates from NBP (National Bank of Poland)
  • Downloading Exchange Rates from Central Bank of Turkey
  • ABAP Extensions - Automatic Logon
  • ALV Grid in the nutshell: Field catalog - inttype - ABAP data type (C,D,N,...)
  • ALV Grid in the nutshell: Field catalog - datatype

Most Read

  • Create XLSX/MHTML file from internal table in background
  • Refresh ALV GRID and keep position and current cell
  • Create XLSX file from internal table in background v2
  • FALV (Fast ALV Grid)
  • ATC Pseudo Comments list
  • Call standard F4 search help with customized parameters
  • Dynamic GUI STATUS & TITLE with ABAP code
  • Create fieldcatalog from internal table
  • Link Attachments of Purchase Requisition to Purchase Order
  • GOS - How to add business documents at creation of object
  • Endless loop in BADI ME_PROCESS_PO_CUST
  • Create a nice looking chart with CL_GUI_CHART_ENGINE - Part 3 - Chart Data and render
  • How to access private or protected data and methods of CL_GUI_ALV_GRID
  • Subtotal lines of ALV GRID OO as content separator
  • Popup with multi-select ALV
feed-image Feed Entries

Latest Comments

ABAP code and articles provided on http://abapblog.com, if it is not statet otherwise, were created by Łukasz Pęgiel. You can use the code in your SAP instance for commercial and non-commercial use without any warranty from side of the author. You cannot sell the code as a full program or a part of it.
Replicating of the articles and code is prohibited unless the agreement of the author is given to you. 

Bootstrap is a front-end framework of Twitter, Inc. Code licensed under MIT License. Font Awesome font licensed under SIL OFL 1.1.