Friday, November 1, 2013

ABAP Week Operations

Some SAP objects must deal with week periods. Here I'll show a small class to deal with some of the needs that arise when making calculations with week periods. This class makes simplier to use only one object to provide the needed calculations with weeks. As usual, there is allways room for improvement.

1 - Create the Class:
















2 - Create the Methods:







3 - Define Methods Parameters












4 - Insert the code in the appropriate methods:

method ADD_NUMBER.

datal_first_day type dats.


  do im_numb times.
    l_first_day get_first_dayim_week ch_week ).
    l_first_day l_first_day + 7.
    ch_week     get_from_dayim_day l_first_day ).
  enddo.

endmethod.

method DIFFERENCE.

  if im_week2(4im_week1(4).
    re_no_weeks im_week1+4(2im_week2+4(2).
  elseif im_week1(4> im_week2(4).
    re_no_weeks im_week1(4im_week2(452 + im_week1+4(2)

                                                         im_week2+4(2).
  else.
    clearre_no_weeks.
  endif.

endmethod.

method GET_FIRST_DAY.

  call function 'WEEK_GET_FIRST_DAY'
    exporting
      week         im_week
    importing
      date         re_day
    exceptions
      week_invalid 1
      others       2.

endmethod.

method GET_FROM_DAY.

  call function 'DATE_GET_WEEK'
    exporting
      date         im_day
    importing
      week         re_week
    exceptions
      date_invalid 1
      others       2.

endmethod.

method GET_LAST_DAY.

  re_day get_first_dayim_week im_week 6.

endmethod.

method SUBTRACT_NUMBER.

datal_first_day type dats.


  do im_numb times.
    l_first_day get_first_dayim_week ch_week ).
    l_first_day l_first_day 7.
    ch_week     get_from_dayim_day l_first_day ).
  enddo.

endmethod.

Thursday, October 31, 2013

Convert ALV to Excel and send it by email

One of the most requested abilities for an report is the possibility to run it as a job and send the output to a given user. However, the spool output of most ALV reports is unusable as is. To solve this problem, I'll show a simple class that takes an internal table, a fieldcatalog and a user email to create a xml excel file from the field catalog with the contents of the internal table and forward it to the email supplied.
I should warn that the excel output isn't something fancy. It's just a simple table. The class can be greatly enhanced.

1 - Create a class:



2 - Create the class atributes:





3 - Create the class methods:

4 - Create the method parameters:










5 - Insert the appropriate code in each method:


Friday, October 25, 2013

Talking ABAP

Just for fun, you can make sap talk to the user or, for more serious work, you can give hearing aids to alert the users for some event or to help them be more aware of what is happening.


As a final thought, I should say that, this is a simple example. As most of the times, you have plenty of room to improve.
Don't forget that this is an instanciation of a windows object. It will only work with SAP Gui for windows.

Remark: depending on the security settings of your SAP GUI configuration, a popup can appear asking for authorization to instanciate a windows object.

Thursday, October 24, 2013

Batch Input with Objects

Some times, we get such a requirement that forces us to use batch input for creation/changing of some SAP object/document. Usually, the resulting code isn't that elegant. In this post, I'll show how to use a ABAP Class to process call transaction and allow to future improvements that afects every program that uses it, without the need to change those same programs.
Those improvements could be:
  • Create Batch input in DB for latter processing
  • Create Enhanced Logs
  • Start Workflows
  • Etc

1 - Create an ABAP Class in transaction SE24, select an apropriate package:

















2 - Create the following attributes:

3 - Create these methods:









4 - Pick the relevant code for the each method:


5 - Save and activate the class.

6 - To help generate the code, the following program can be used:



The input for this program is the SHDB record and the program variable name.

7 - Example:
  • SHDB Record:


8 - Program Input

9 - Generated Code:


Final remarks:
As you can see, the code is more understable and simplier to use.
The SHDB record name, must be unique, since it is selected by name.
With the generated code, you must add the coding for variable selection and remove unecessary inputs. The program only creates code for the relevant batch input lines.

Friday, December 31, 2010

Tuesday, April 6, 2010

SAP Texts Copy

RSTXTCPY - This program is very useful to copy texts between SAP clients.

Thursday, March 11, 2010

SAP Texts Transport

An simple way of transport SAP texts is to use the program RSTXTRAN.

First, you must create a transport order, check if the task is of development/correction type.

After that, take not of the task number (not the request), and introduce it in the program, together with the text name, type and language.