You are on page 1of 14

Where does the ABAP program run?

Full Size

Back to top
How are RANGES different from SELECT-OPTIONS?

They are the same, except SELECT-OPTIONS will provide an interface


on the selection screen for the user to input data.

Back to top

How to convert a date to internal or external format?

Use the functions modules CONVERT_DATE_TO_EXTERNAL or CONVERT_DATE_TO_INTERNAL


to convert the date. When converting to external format, the date format from the user's user
profile will be used.
When converting to internal format, the result will be in YYYYMMDD format.

Back to top

How do I download data in my internal table in a CSV file?

Use the Function Module SAP_CONVERT_TO_CSV_FORMAT to convert the internal table into Comma
seperated format then download this
internal table using the Function Module GUI_DOWNLOAD.

See a sample program below:

TYPE­POOLS: truxs.

TYPES:

  BEGIN OF ty_Line,

    vbeln LIKE vbap­vbeln,

    posnr LIKE vbap­posnr,

  END OF ty_Line.

  ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.

DATA: itab   TYPE ty_Lines.

DATA: itab1  TYPE truxs_t_text_data.

SELECT

  vbeln

  posnr

  UP TO 10 ROWS

  FROM vbap

  INTO TABLE itab.

CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'

  EXPORTING

    i_field_seperator    = ';'
  TABLES

    i_tab_sap_data       = itab

  CHANGING

    i_tab_converted_data = itab1

  EXCEPTIONS

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

CALL FUNCTION 'GUI_DOWNLOAD'

  EXPORTING

    filename = 'C:\TEMP\test.txt'

  TABLES

    data_tab = itab1

  EXCEPTIONS

    OTHERS   = 1.

 

h3. 10 basic steps to create Enhancement Spot/ BADI

1. Go to se18.

2. Enter the name enhancement spot and click create.

3. On next screen click on create new BADI.
4. Once the BADI is created then expand the tree on the     
left side.
5. Then double click on interface and give the name of the interface.
6. On the next screen it will ask for interface methods and its level ,that is it 
static or instance ?
7. Go to se19, and then click on enhancemnet spot ,enter the name of enhacemnet 
spot created above and click on implement.
8. On next pop up give the name of enhancement implementation.
9. On next screen give the name of BADI implementation and its implementaion 
class and also BADI definition just created above and save.
10. Now back to se18 and there activate both enhancement spot and BADI 
implementaion.And see both BADI interface and implementation.

Back to top
How can I get the IP address of the system programmatically?

You can use cl_gui_frontend_services to get the system IP address.

DATA ip_addr TYPE c LENGTH 50.

CALL METHOD cl_gui_frontend_services=>get_ip_address

  RECEIVING

    ip_address           = ip_addr

  EXCEPTIONS

    cntl_error           = 1

    error_no_gui         = 2

    not_supported_by_gui = 3

    OTHERS               = 4.

DATA terminal LIKE USR41­TERMINAL.

CALL FUNCTION 'TERMINAL_ID_GET'

 EXPORTING

   USERNAME                   = sy­uname

 IMPORTING

   TERMINAL                   = terminal.

Back to top

How can I download my internal table into an Excel file?

Use the function module SAP_CONVERT_TO_XLS_FORMAT to download the internal table to an excel
file.

PARAMETERS: p_file LIKE rlgrap­filename DEFAULT 'c:\tmp\test.xls'.

DATA: t100_Lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.

SELECT * FROM t001 INTO TABLE t100_Lines.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

  EXPORTING

    i_filename     = p_file

  TABLES

    i_tab_sap_data = t100_Lines.

Or get much more control by creating an XML file

Back to top
How can I read an Excel file from presentation server?

You can use the Function module ALSM_EXCEL_TO_INTERNAL_TABLE to read the Excel file into the
internal table of type alsmex_tabline.
From this internal table you can fill the target internal table.

TYPES:

  BEGIN OF ty_upload,

    field1 TYPE c length 12,

    field2 TYPE c length 12,

    field3 TYPE c length 12,

  END OF ty_upload.

  DATA it_upload TYPE STANDARD TABLE OF ty_upload WITH DEFAULT KEY.

  DATA wa_upload TYPE ty_upload.

  DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.

  FIELD­SYMBOLS: <wa> type alsmex_tabline.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

      filename    = filename

      i_begin_col = 1

      i_begin_row = 1

      i_end_col   = 3

      i_end_row   = 65535

    TABLES

      intern      = itab.

  LOOP AT itab ASSIGNING <wa>.

    CASE <wa>­col.

      WHEN '0001'.

        wa_upload­field1 = <wa>­value.

      WHEN '0002'.

        wa_upload­field2 = <wa>­value.

      WHEN '0003'.

        wa_upload­field3 = <wa>­value.

    ENDCASE.

    APPEND wa_upload TO it_upload.

    CLEAR wa_upload.
  ENDLOOP.

Back to top

How can I convert numerals into the corresponding text?

Use the Function Module SPELL_AMOUNT to convert the integer into text.

DATA v_int TYPE i VALUE '1000'.

DATA words LIKE SPELL.

CALL FUNCTION 'SPELL_AMOUNT'

 EXPORTING

   AMOUNT          = v_int

   LANGUAGE        = SY­LANGU

 IMPORTING

   IN_WORDS        = words

          .

WRITE words­word.

Back to top

I am using a SELECT query on a database table. Since the number of records in the table
is very large,

the program dumps due to insufficient memory. How can I solve this?

In this case you could use the PACKAGE SIZE addition in the SELECT query to process in limited
amount of data,
thus avoiding the memory overloads.

Eg:

SELECT *

 FROM <table>

 INTO TABLE itab

 PACKAGE SIZE <n>.

IF sy­subrc EQ 0.

*" Process the n records
ENDIF.

ENDSELECT.

[Back to top]
How can I import and export my ABAP developments?

SAPlink is an opensource community project that makes it easy to share ABAP developments
between programmers.
It provides the ability to easily distribute and package custom objects.

Back to top

Where are the long texts of a document stored and how to access the same?*

The long texts of a document are stored in a encrypted format in the STXH and STXL tables, where
STXH stores the header information of the
long text like TDOBJECT, which indicates which text object the long text belongs to, TDID which
indicates the Text ID and TDNAME which is
the actual name of the long text.

As these texts are stored in a encrypted format, the text cannot be read using a SELECT statement.
You will have to use the function READ_TEXT. The easiest way of getting to know the parameter
values is to go to a document, open the long text in a full screen mode. For example, when you wan
to see the long text for a Purchase order, go to transaction ME23n. Assume, you want to see the
parameters for the Header Text. In the first Tab Strip Control, click on the Texts tab and select the
Header Text node on the left hand side, which will display the text on the right hand side. Now,
double click on the text editor on the right hand side. This will open the text in the full screen mode.
In the menu Go To --> Header, you should be able to see the values for all the three parameters we
discussed above. We will have to do the same thing for whichever text parameters we want to see.

CALL FUNCTION 'READ_TEXT'

  EXPORTING

*   CLIENT                        = SY­MANDT

    ID                            =

    LANGUAGE                      =

    NAME                          =

    OBJECT                        =

*   ARCHIVE_HANDLE                = 0

*   LOCAL_CAT                     = ' '

* IMPORTING

*   HEADER                        =

  TABLES

    LINES                         =

* EXCEPTIONS

*   ID                            = 1

*   LANGUAGE                      = 2

*   NAME                          = 3

*   NOT_FOUND                     = 4

*   OBJECT                        = 5
*   REFERENCE_CHECK               = 6

*   WRONG_ACCESS_TO_ARCHIVE       = 7

*   OTHERS                        = 8

          .

IF SY­SUBRC <> 0.

* MESSAGE ID SY­MSGID TYPE SY­MSGTY NUMBER SY­MSGNO

*         WITH SY­MSGV1 SY­MSGV2 SY­MSGV3 SY­MSGV4.

ENDIF.

Back to top

How do I create a long text for a document?*

Please refer to the important parameters that are discussed in the previous question of reading
texts. We will need the same parameters for saving the text as well. The function modules that you
can use for this will be SAVE_TEXT followed by COMMIT_TEXT. The parameters play a very
important roles as you might not see the saved text in the standard transaction if you give wrong
parameter values.

CALL FUNCTION 'SAVE_TEXT'

  EXPORTING

*   CLIENT                = SY­MANDT

    HEADER                =

*   INSERT                = ' '

*   SAVEMODE_DIRECT       = ' '

*   OWNER_SPECIFIED       = ' '

*   LOCAL_CAT             = ' '

* IMPORTING

*   FUNCTION              =

*   NEWHEADER             =

  TABLES

    LINES                 =

* EXCEPTIONS

*   ID                    = 1

*   LANGUAGE              = 2

*   NAME                  = 3

*   OBJECT                = 4

*   OTHERS                = 5

          .

IF SY­SUBRC <> 0.
* MESSAGE ID SY­MSGID TYPE SY­MSGTY NUMBER SY­MSGNO

*         WITH SY­MSGV1 SY­MSGV2 SY­MSGV3 SY­MSGV4.

ENDIF.

CALL FUNCTION 'COMMIT_TEXT'

* EXPORTING

*   OBJECT                = '*'

*   NAME                  = '*'

*   ID                    = '*'

*   LANGUAGE              = '*'

*   SAVEMODE_DIRECT       = ' '

*   KEEP                  = ' '

*   LOCAL_CAT             = ' '

* IMPORTING

*   COMMIT_COUNT          =

* TABLES

*   T_OBJECT              =

*   T_NAME                =

*   T_ID                  =

*   T_LANGUAGE            =

          .

Back to top

How do I display / add the Terms and Conditions to the business document?

I would suggest that you create separate SMART Form for the Terms and conditions and call that
right after the PO main smart form. It gives the flexibility in calling the same smart form for other
documents also, as generally these are the same Terms and Conditions for all the documents that a
company uses.

We can have the Terms and Conditions stored as long texts in SO10 (Standard Text, TDOBJECT -
TEXT and TDID - ST and TEXTNAME - Whatever name you want to give). This way if you want to
change the text, its easy to change and you can transport the changes using program RSTXTRAN.

We have a text element in the smart form, and the general attributes of the text change the type to
"Include Text". This will change the screen and you should be able enter the parameter values of
Object, ID and name.

This will automatically print the entire long text on the smart form, we just need to make sure that
this is a part of the main window of the smart form as the text might run into multiple pages.

Back to top
How to convert from one currency value to other?

We can Use the Following Function Module to convert from one Currency vale to other
In following function module we need to pass Foreign currency, Local Currency type_rate:Type of
rate M=Average rate G=Bank buying rate B=bank selling rate

We Get Exchange rate for that day, foreign factor, Local factor.
And Foreign currency can be calculated as below mentioned in IF ENDIF

DATA: l_er TYPE tcurr­ukurs, "

l_ff TYPE tcurr­ffact,

l_lf TYPE tcurr­tfact,

l_erate(12) TYPE c,

CALL FUNCTION 'READ_EXCHANGE_RATE'

EXPORTING

date = sy­datum

foreign_currency = wa_bseg­pswsl

local_currency = c_euro

type_of_rate = 'M'

IMPORTING

exchange_rate = l_er

foreign_factor = l_ff

local_factor = l_lf

EXCEPTIONS

no_rate_found = 1

no_factors_found = 2

no_spread_found = 3

derived_2_times = 4

overflow = 5

OTHERS = 6.

IF sy­subrc = 0.

l_erate = l_er / ( l_ff / l_lf ).

wa_itab­wrbtr = wa_itab­wrbtr * l_erate.

ENDIF.

Back to top

How do I send e-mail?


There are several methods to accomplish this:

Sending E-Mail from ABAP - Version 610 and Higher - BCS Interface
Sending E-Mail from ABAP - Version 46D and Lower - API Interface
BCS interface in BSPs
Develop a Web Service that sends an Email - in ABAP, Netweaver 04S

Back to top

How do I receive and process e-mail?

Receiving E-Mail and processing it with ABAP - Version 610 and Higher

Back to top

How do I generate PDFs?

BSP/HowTo: Generate PDF Output (from a BSP)

Back to top

ABAP:ABAP General

How to change the deadline of the workitem programmatically in SAP?

Following code is used to changes the deadline of any work item which is in WAITING state. The FMs
needs the input like the object type for which the workflow has executed, the workflow ID to which
the workitem belongs and the Task id of the standard task which is executed and in waiting state.

DATA: lit_deadline TYPE TABLE OF swwdeadlin,

      lt_workitem TYPE TABLE OF swr_wihdr,

      lt_rel_wi TYPE TABLE OF swwwihead,

      w_workitem TYPE swr_wihdr,

      w_rel_wi TYPE swwwihead,

      w_deadline TYPE swwdeadlin,

      l_objkey TYPE swo_typeid,

      l_retcode TYPE sy­subrc.

* Retrieve the work items executed for desired Object type
CALL FUNCTION 'SAP_WAPI_WORKITEMS_TO_OBJECT'
    EXPORTING
      objtype                  = l_objtype
      objkey                   = l_objkey
      top_level_items          = space
      selection_status_variant = '0001'
    IMPORTING
      return_code              = l_ret_code
    TABLES
      worklist                 = lt_workitem.
* Select the workitems executed for particular Workflow.
  SORT lt_workitem BY wi_rh_task wi_stat.
  READ TABLE lt_workitem
       INTO w_workitem
       WITH KEY wi_rh_task = 'WS91001143'
                wi_stat = 'STARTED'
                BINARY SEARCH.
* Select the dependent workitems of 'WS91001143'.
    CALL FUNCTION 'SWI_GET_DEPENDENT_WORKITEMS'
      EXPORTING
        wi_id         = w_workitem­wi_id
      TABLES
        dependent_wis = lt_rel_wi.
*   Select the workitems for which the deadline needs to be changed.
    SORT lt_rel_wi BY wi_rh_task wi_stat.
    READ TABLE lt_rel_wi
         INTO w_rel_wi
         WITH KEY wi_rh_task = 'TS91001414'
                  wi_stat = 'WAITING'
                  BINARY SEARCH.
*   Update the deadline of the waiting task.
      w_deadline­wi_dattype = 'DS'.
      w_deadline­wi_date = l_new_date.
      w_deadline­wi_time = '000001'.
      APPEND w_deadline TO lt_deadline.
      CALL FUNCTION 'SWW_WI_DEADLINES_CHANGE'
        EXPORTING
          wi_id               = w_rel_wi­wi_id
          do_commit           = 'X'
        TABLES
          deadline_attributes = lt_deadline
        EXCEPTIONS
          no_authorization    = 1
          invalid_type        = 2
          update_failed       = 3
          invalid_status      = 4
          OTHERS              = 5.
 if sy­subrc <> 0.

 endif.

Back to top

When selection screen-screen output will use?

Mostly selection screen will use for Repoting purpose.We can give range of inputs or particulat input
or single input by selection screen.

How to calculate last date of the month?

Mostly this problem arises since the months have variable end date and we need to know at
runtime, whether last date is 31 or 30 or in case of Feb 28 or29!!

Here's what can be done:

Data : lv_date type DATS,

          lv_lastday type DATS,

          wf_date type DATS,

          lv_month(2) type n.
wf_date = sy­datlo.&nbsp; "This is just for demo
*wf_date contains the date in the format 20071026

lv_month = wf_date+4(2) + 1.
concatenate wf_date+0(4) lv_month '01' into lv_date.
lv_lastday = lv_date ­ 1.

This method is better:


Use the function module FIMA_DATE_CREATE

data: lv_actual_date type sy-datum,


lv_end_of_month_date type sy-datum.

lv_actual_date = sy-datum.

CALL FUNCTION 'FIMA_DATE_CREATE'


EXPORTING
I_DATE = lv_actual_date
* I_FLG_END_OF_MONTH = ' '
* I_YEARS =0
* I_MONTHS =0
* I_DAYS =0
* I_CALENDAR_DAYS =0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = lv_end_of_month_date
.

With the other Exporting Parameters you can get the date of other years or months.
For example: I_YEARS = 2 => Input_Years = 2005 Output_Years = 2007
I_MONTHS = '-3' => Input_Month = 07 Output_Month = 04

Back to top

How to calculate last date of the month

10 basic steps to create Enhancement Spot/ BADI

1. Go to se18.
2. Enter the name enhancement spot and click create.
3. On next screen click on create new BADI.
4. Once the BADI is created then expand the tree on the left side.
5. Then double click on interface and give the name of the interface.
6. On the next screen it will ask for interface methods and its level ,that is it static or instance ?
7. Go to se19, and then click on enhancement spot ,enter the name of enhacement spot created
above and click on implement.
8. On next pop up give the name of enhancement implementation.
9. On next screen give the name of BADI implementation and its implementation class and also
BADI definition just created above and save.
10. Now back to se18 and there activate both enhancement spot and BADI implementaion.And see
both BADI interface and implementation.
Children Hide Children | View in hierarchy

You might also like