Saving an internal table in Microsoft Excel format

You can use standard program RPR_ABAP_SOURCE_SCAN to search ABAP program code/screen logic for specific texts (strings.)

This program offers many more options than programs RSRSCAN1 or RKCTSEAR. The benefits of using this program are as follows:

  • Several texts can be entered for which the system searches. The search text should be entered without formatting characters(*,+). Only the texts are applied in the search, i.e. selection option conditions such as greater than, equal to, etc., are ignored
  • You can restrict the search to either the program code or the flow logic of the selected screens or both the program code and the flow logic of the screens.
  • You can set the option to ignore the comments for search.
  • Found location +/- x lines: Here we can specify how many program lines before and after the found location of the search string should be included in the output.
  • We can also specify the option to search in all the includes used in the specified programs.

Managing persistent objects with object services

There is a way to avoid building a fully object-oriented program while still working with non-object-oriented relational database. The object services layer now provides a persistence framework that closes the object-relational gap. You no longer need to write SQL code as objects are transparently loaded from the database when needed. You must make a persistent class.

Choose transaction SE24 and make a persistent class; this class must be protected.

clip image001 thumb21 SAP ABAP FAQS PART 2

In the class builder, a new button is added in the main toolbar – “Persistence” – press it :

in the next screen, you just have to map which fields you need in your persistent class

clip image002 thumb13 SAP ABAP FAQS PART 2

After having saved the previous screen, you will notice that the system makes a set/get method for each field that you selected.

clip image003 thumb14 SAP ABAP FAQS PART 2

Activate the whole class. Now that we have a persistent object to access the database table SFLIGHT, we must access it in a program. Here is a small example to read/write data into SFLIGHT using persistent objects.

REPORT zdany_sflight_persistent.

DATA : l_flight TYPE REF TO zcl_dany_sflight,

l_flight_agent TYPE REF TO zca_dany_sflight,

l_seatsfree TYPE i,

l_seatsocc TYPE i.

* Reference to the class agent, ALWAYS required for any operation

l_flight_agent = zca_dany_sflight=>agent.

TRY.

*We read a record from SFLIGHT using a unique key

l_flight = l_flight_agent->get_persistent(

i_carrid = ‘LH’

i_connid = ’0400′

i_fldate = ’20031030′ ).

*We read a specific field

l_seatsfree = l_flight->get_seatsmax( ) – l_flight->get_seatsocc( ).

IF l_seatsfree > 0.

l_seatsocc = l_flight->get_seatsocc( ) + 1.

* We write back a specific field into the DB

l_flight->set_seatsocc( l_seatsocc ).

ENDIF.

ENDTRY.

COMMIT WORK.

There are lots of other methods and techniques that you can use in persistent classes.

Contact Dany Charbonneau for more info.

Debugging ABAP programs from JAVA applications

You can do ABAP debugging from java applications here is how :

  1. Check whether your user has debugging authority. Auth. object S_DEVELOP has to contain ‘DEBUG’
    • Use su01; ROLES
    • Double click the different roles ->
    • new session will open
    • Choose Authorizations -> Show Authorization Data
  2. go to the ABAP coding
  3. go to the menu Utilities -> Settings / choose tab “ABAP editor ” / choose tab “Debugging” check the chek – box “Actv.” in the User field enter the user used in the Java logon (not the alias of the user!! e.g. for BRUNO enter “3B1968D7DD1″)
  4. Press enter or choose OK to get back to your source code
  5. If you set your next break-point a pop-up will occur to question you if you want to set an external break-point or a session break-point –> click external break-point (= former HTTP break-point) –>

if you run you Java application now and the coding with the break-point is called a new R/3 (CRM) window will open and you will see you code in debug mode (may take some seconds)

Defining a default variant

There are 2 different ways to define a default variant.

Method 1 – By assigning a variant directly on the transaction code. This is the simplest way but if the program was called from another program or directly from SE38, the default variant will be ignored.

Method 2 – By assigning a variant in the code, here is a small example of this:

* The code must be in the INITIALIZATION section

INITIALIZATION.

* We must check if a default variant was already entered by the user in a batch job or in the transaction code

* we do not want to overwrite it ! the current variant is store in the sy-slset field

IF sy-slset IS INITIAL.

CALL FUNCTION ‘RS_SUPPORT_SELECTIONS’

EXPORTING

report = sy-cprog “actual program name

variant = ‘SAPDEFAULT’ “default variant name

EXCEPTIONS

variant_not_existent = 0

variant_obsolete = 0

OTHERS = 0.

ENDIF.

* After the initialization we start the real code of our program in the section START-OF-SELECTION

START-OF-SELECTION.

Here is how to make a the variant “SAPDEFAULT” always using as a default date today minus 30 days:

Goto -> variant -> save as variant

Here is the standard variant save screen. Enter a name and a description and press “do”. Very few know how to handle the weird looking bottom part of this screen:

clip image004 thumb11 SAP ABAP FAQS PART 2

  1. Check the variables for which you want to maintain default values
  2. Choose selection variables button and see the next one

clip image005 thumb9 SAP ABAP FAQS PART 2

The first part is a legend of the column headers (T D B Z). Because we want to make a date, we double click on the traffic lights of the column “D” for Dynamic date calculation. when the traffic light turn green, you can press on the down arrow in the “T” column. This will bring a popup with all possibilities you can imagine for defaulting a date. From a usability point of view, this is not really excellent screens but nevertheless, this tool is very powerful.

Making Activable Breakpoints and Assertions

You can now make (de)activable breakpoints in your programs. You can release these breakpoints in production and a customer will have the opportunity to activate and debug your code more easily.

The following is an activable break-point : BREAK-POINT ID dany.

The checkpoint group is defined by double clicking on the checkpoint group in the editor OR directly via transaction SAAB.

Below is the SAAB screen. In the breakpoints part of the screen, you can set it to “inactive” or “break”. All breakpoint groups will be shipped inactive by default.

clip image006 thumb7 SAP ABAP FAQS PART 2

Assert :

An assertion is a condition which must be right during program execution. By using asserts in your program, you can find cause of error in shorter time. The reaction when violating an assertion depend on a customizing and could be :

  1. Start the debugger from this assert
  2. Do nothing, ignore the assert
  3. Log the assertion in a log
  4. Terminate the program with runtime error ASSERTION_FAILED

The assertions are defined in SAAB (exactly like the breakpoints, see screen above).Here is an example of a use for an assertion :

METHOD sort_by_name.

DATA: l_f1 TYPE i VALUE 2,

l_f2 TYPE c LENGTH 10 VALUE ‘test’,

l_t1 TYPE TABLE OF sflight.

the_sorting_algorithm.

ASSERT ID dany

SUBKEY ‘danysub1′

FIELDS l_f1 l_f2 l_t1

CONDITION itab->is_sorted_by_name( ) <> ‘ ‘.

ENDMETHOD.

This will ensure that the table is sorted. Below is the result of the log for this assert

clip image007 thumb3 SAP ABAP FAQS PART 2

Using Shared Objects

Shared objecta are SAP’s answer to an age-ancient request by programmers. Up until now, the only way to share variables between programs was to use EXPORT/IMPORT TO/FROM MEMORY. This method was very slow because the “sending” program had to copy variables from its memory to the shared memory, and the “receiving” program had to copy these variables from the shared memory into its own program memory. This generated two copies for basically nothing.

Here are the benefits of shared objects:

  1. Copy-free: very quick access
  2. Versioning management: you can handle many version of the variables at the same time
  3. Preloading: you can now request a specific variable no matter if the “sending” program already made them
  4. Automatic propagation from a database or to different application servers
  5. Could be client dependant
  6. Simple monitoring

Here is a very simple example but you can do very powerful shared object, see documentation for more information.

Step 1 :

You have to define a Root class using SE24, In this class you will defined all variables you want to share in the attributes tab, This class must be “Shared memory enabled” :

clip image008 thumb4 SAP ABAP FAQS PART 2

Step 2 : You have to define your shared memory object using the transaction SHMA. It is vital to place the class you made in step 1 in the field “root class”.

clip image009 thumb3 SAP ABAP FAQS PART 2

Step 3 : You have to write a program to write to the shared memory.

DATA : hdl TYPE REF TO zcl_sm_area,

root TYPE REF TO zcl_root_area.

* Make the default instance for write,

* when we attach for write, an exclusive lock is performed on the shared memory object

hdl = zcl_sm_area=>attach_for_write( ).

*when we make our root object to access variables, we must use the new keyword addition AREA HANDLE

MAKE OBJECT root AREA HANDLE hdl.

* Make the link between the root object and the shared memory object

hdl->set_root( root ).

* place data in the shared memory variable

root->big_var = ‘hello world!’.

* commit

hdl->detach_commit( ).

Step 4 : You have to make a program to read from the shared memory

DATA : hdl TYPE REF TO zcl_sm_area.

* Open default instance for read

hdl = zcl_sm_area=>attach_for_read( ).

*Access root object component to write the variable

WRITE / hdl->root->big_var.

*Release lock

hdl->detach( ).

Step 5: You can monitor the result in transaction SHMM

Defining dynamic orders in an ABAP sort

You can easily define dynamic fields in an ABAP sort using ( ) :

data : l_fieldname type dd03l-fieldname value ‘CARRID’.

SORT sflight by (l_fieldname) DESCENDING.

BUT you CANNOT define the order (ascending or descending) dynamically :

SORT sflight by (l_fieldname) (l_order). <<==– This is impossible in ABAP.

Now, with the new tree control­, when you want to give fully customizable tree, ou need to dynamically set the order in the sort command.

The first method is by using a MAKE SUBROUTINE POOL with your sort. Each time you will run the program, this subroutine will be recompiled. This is VERY slow and we should avoid using this command whenever it’s possible.

The second method is a simple trick that have no major impact on performance. You duplicate each fields you want to sort, 1 copy for ascending and 1 for descending. You go the fieldname only in 1 of those fields depending on what order you want.

Here is a small example on how to do that:

*&———————————————————————*

*& Report ZDANY_DYN_SORT

*&———————————————————————*

REPORT z_dany_dyn_sort.

* s_field* – field name for sorting ( F1,F2,F3,F4,F5 or space )

* s_ord* – ASC or DES ( ascending or descending)

PARAMETERS: s_field1(6) DEFAULT ‘FIELD1′, s_ord1(3) DEFAULT ‘ASC’,

s_field2(6) DEFAULT ‘FIELD2′, s_ord2(3) DEFAULT ‘DES’,

s_field3(6) DEFAULT ‘FIELD3′, s_ord3(3) DEFAULT ‘ASC’,

s_field4(6) DEFAULT ‘FIELD4′, s_ord4(3) DEFAULT ‘DES’,

s_field5(6) DEFAULT ‘FIELD5′, s_ord5(3) DEFAULT ‘ASC’.

TYPES: START OF ltt_fields,

field1(6),

field2(6),

field3(6),

field4(6),

field5(6),

END OF ltt_fields.

DATA: l_field_asc1(6),

l_field_asc2(6),

l_field_asc3(6),

l_field_asc4(6),

l_field_asc5(6),

l_field_des1(6),

l_field_des2(6),

l_field_des3(6),

l_field_des4(6),

l_field_des5(6),

lt_fields TYPE TABLE OF ltt_fields,

ls_fields TYPE ltt_fields,

l_flag_invalid_field,

l_flag_not_asc_des.

FIELD-SYMBOLS <fs> TYPE ANY.

INITIALIZATION.

* Just to fill an internal tables for testing

DO 3 TIMES.

ls_fields-field1 = sy-index.

DO 3 TIMES.

ls_fields-field2 = sy-index.

DO 3 TIMES.

ls_fields-field3 = sy-index.

DO 3 TIMES.

ls_fields-field4 = sy-index.

DO 3 TIMES.

ls_fields-field5 = sy-index.

APPEND ls_fields TO lt_fields.

ENDDO.

ENDDO.

ENDDO.

ENDDO.

ENDDO.

START-OF-SELECTION.

* The order must be “ASC” or “DES” or space, any other value is rejected

l_flag_not_asc_des = ‘X’.

CHECK ( s_ord1 = ‘ASC’ OR s_ord1 = ‘DES’ OR s_ord1 IS INITIAL ) AND

( s_ord2 = ‘ASC’ OR s_ord2 = ‘DES’ OR s_ord2 IS INITIAL ) AND

( s_ord3 = ‘ASC’ OR s_ord3 = ‘DES’ OR s_ord3 IS INITIAL ) AND

( s_ord4 = ‘ASC’ OR s_ord4 = ‘DES’ OR s_ord4 IS INITIAL ) AND

( s_ord5 = ‘ASC’ OR s_ord5 = ‘DES’ OR s_ord5 IS INITIAL ).

CLEAR l_flag_not_asc_des.

* the field name must be = “FIELD1, 2, 3, 4 or 5″, any other value is rejected

l_flag_invalid_field = ‘X’.

CHECK ‘FIELD1FIELD2FIELD3FIELD4FIELD5′ CS s_field1 AND

‘FIELD1FIELD2FIELD3FIELD4FIELD5′ CS s_field2 AND

‘FIELD1FIELD2FIELD3FIELD4FIELD5′ CS s_field3 AND

‘FIELD1FIELD2FIELD3FIELD4FIELD5′ CS s_field4 AND

‘FIELD1FIELD2FIELD3FIELD4FIELD5′ CS s_field5.

CLEAR l_flag_invalid_field.

* for a certain field, if the user question descending order, the name of this field is

* went in l_field_des1 AND it’s vital that l_field_asc1 remain empty.

IF s_field1 IS NOT INITIAL.

IF s_ord1 = ‘ASC’.

l_field_asc1 = s_field1.

ELSE.

l_field_des1 = s_field1.

ENDIF.

ENDIF.

IF s_field2 IS NOT INITIAL.

IF s_ord2 = ‘ASC’.

l_field_asc2 = s_field2.

ELSE.

l_field_des2 = s_field2.

ENDIF.

ENDIF.

IF s_field3 IS NOT INITIAL.

IF s_ord3 = ‘ASC’.

l_field_asc3 = s_field3.

ELSE.

l_field_des3 = s_field3.

ENDIF.

ENDIF.

IF s_field4 IS NOT INITIAL.

IF s_ord4 = ‘ASC’.

l_field_asc4 = s_field4.

ELSE.

l_field_des4 = s_field4.

ENDIF.

ENDIF.

IF s_field5 IS NOT INITIAL.

IF s_ord5 = ‘ASC’.

l_field_asc5 = s_field5.

ELSE.

l_field_des5 = s_field5.

ENDIF.

ENDIF.

* EACH field is used twice in the sort with different name for ascending and descending. 1 of the

* 2 fields will be empty and the sort will ignore it.

SORT lt_fields BY (l_field_asc1) ASCENDING (l_field_des1) DESCENDING

(l_field_asc2) ASCENDING (l_field_des2) DESCENDING

(l_field_asc3) ASCENDING (l_field_des3) DESCENDING

(l_field_asc4) ASCENDING (l_field_des4) DESCENDING

(l_field_asc5) ASCENDING (l_field_des5) DESCENDING.

* Show the results

EDITOR-CALL FOR lt_fields.

END-OF-SELECTION.

* if parameters was not entered correctly

IF l_flag_not_asc_des = ‘X’.

WRITE: / ‘Only ASC for ascending or DES for DESCENDING are allowed for fields S_ORDn’.

ELSEIF l_flag_invalid_field = ‘X’.

WRITE: / ‘S_FIELDn must be = FIELD1, FIELD2, FIELD3, FIELD4 or FIELD5.’.

ENDIF.

Inserting charts

It’s a known fact that customers are very sensitive to the appeal of charts. Making graphical charts (bar, pie char, lines graphs) in ABAP is simple. There are two main methods for making charts in ABAP

  • Using the class CL_GFW
  • Using the function module GFW_PRES_SHOW

There are also other classes and function modules derived from these ones. Use transaction GRAL to explore all possibilities provided by this class and this FM.

The following are two small examples of the huge potential of function module GFW_PRES_SHOW :

* Contain the constants for the graph type

TYPE-POOLS: GFW.

DATA: VALUES TYPE TABLE OF GPRVAL WITH HEADER LINE,

COLUMN_TEXTS TYPE TABLE OF GPRTXT WITH HEADER LINE.

REFRESH VALUES.

REFRESH COLUMN_TEXTS.

VALUES-ROWTXT = ‘Salary’.

VALUES-VAL1 = 50000.

VALUES-VAL2 = 51000.

APPEND VALUES.

VALUES-ROWTXT = ‘Life cost’.

VALUES-VAL1 = 49000.

VALUES-VAL2 = 51200.

APPEND VALUES.

COLUMN_TEXTS-COLTXT = ’2003′.

APPEND COLUMN_TEXTS.

COLUMN_TEXTS-COLTXT = ’2004′.

APPEND COLUMN_TEXTS.

* Call a chart into a standard container, this function could be used for many

* different graphic types depending on the presentation_type field :

* gfw_prestype_lines

* gfw_prestype_area

* gfw_prestype_horizontal_bars

* gfw_prestype_pie_chart

* gfw_prestype_vertical_bars

* gfw_prestype_time_axis

CALL FUNCTION ‘GFW_PRES_SHOW’

EXPORTING

CONTAINER = ‘CONTAINER’ “A screen with an empty container must be defined

PRESENTATION_TYPE = GFW_PRESTYPE_LINES

TABLES

VALUES = VALUES

COLUMN_TEXTS = COLUMN_TEXTS

EXCEPTIONS

ERROR_OCCURRED = 1

OTHERS = 2.

Resulting in this:

clip image010 thumb4 SAP ABAP FAQS PART 2

The following uses the EXACT same function with a different presentation type

REFRESH VALUES.

REFRESH COLUMN_TEXTS.

VALUES-ROWTXT = ”.

VALUES-VAL1 = 10.

VALUES-VAL2 = 35.

VALUES-VAL3 = 45.

VALUES-VAL4 = 8.sul

VALUES-VAL5 = 2.

APPEND VALUES.

COLUMN_TEXTS-COLTXT = ‘Fun’.

APPEND COLUMN_TEXTS.

COLUMN_TEXTS-COLTXT = ‘Cars’.

APPEND COLUMN_TEXTS.

COLUMN_TEXTS-COLTXT = ‘House’.

APPEND COLUMN_TEXTS.

COLUMN_TEXTS-COLTXT = ‘Services’.

APPEND COLUMN_TEXTS.

COLUMN_TEXTS-COLTXT = ‘Others’.

APPEND COLUMN_TEXTS.

CALL FUNCTION ‘GFW_PRES_SHOW’

EXPORTING

CONTAINER = ‘CONTAINER’

PRESENTATION_TYPE = GFW_PRESTYPE_PIE_CHART

X_AXIS_TITLE = ‘Expenses’

Y_AXIS_TITLE = ‘Expenses2′

TABLES

VALUES = VALUES

COLUMN_TEXTS = COLUMN_TEXTS

EXCEPTIONS

ERROR_OCCURRED = 1

OTHERS = 2

clip image011 thumb3 SAP ABAP FAQS PART 2

Knowing when to use SELECT SINGLE or SELECT … UP TO 1 ROWS

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. Other people prefer to use the ‘UP TO 1 ROWS’ variant of the SELECT statement.

So what’s the difference between using ‘SELECT SINGLE’ statement as against a ‘SELECT …. UP TO 1 ROWS’ statement ?

If you’re considering the statements

SELECT SINGLE field INTO w_field FROM table.

and

SELECT field INTO w_field FROM table UP TO 1 ROWS. ENDSELECT.

then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memory usage and they may be worlds apart.

Why is this ?? The answer is simple.

The ‘SELECT SINGLE’ statement selects the first row in the database that it finds that fulfils the ‘WHERE’ clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

The ‘SELECT …. UP TO 1 ROWS’ statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Get the difference ??

If not, here is a excellent example, credit for this example goes to Richard Harper, a friend of mine on sapfans.com :

Make a Ztable called ZDifference with 2 fields in it, MANDT of type MANDT and POSNR of type POSNR. Make sure both of these are keys. Also make a table maintenance dialog for it (SE11->Utilities->Table Maintenance Generator). Fill the table with ten rows 000001-000010.

Then run the program shown below:

Code:

******************************************************************

*

* Program: Z_Difference

*

* Purpose: A program that demonstrates the difference

* between SELECT SINGLE and SELECT UP TO n ROWS.

*

* This program requires the data table Z_DIFFERENCE

* to have been made according to the structure

* outlined in the text above and populated with

* at least 10 records.

*

* Creation Date: 21/04/2004

*

* Requested By:

*

* Reference Doc:

*

* Author: R Harper

*

* Modification History:

*

* Date Reason Transport Who

*

******************************************************************

Report Z_Difference

Message-id 38

Line-Size 80

Line-Count 0

No Standard Page Heading.

*

Start-Of-Selection.

Data: w_Single type Posnr,

t_Rows type standard table of Posnr

initial size 0

with header line.

*

Select single Posnr

from zDifference

into w_Single.

*

Select Posnr

into table t_Rows

from zDifference

up to 1 rows

order by Posnr descending.

*

Write :/ ‘Select single:’, w_Single.

Skip 1.

Write :/ ‘Up to 1 rows :’.

Loop at t_Rows.

Write t_Rows.

EndLoop.

You should see the output:

Select single: 000001

Up to 1 rows : 000010

The first ‘SELECT’ statement selected the first record in the database according to any selection criterion in the ‘WHERE’ clause. This is what a ‘SELECT SINGLE’ does. The second ‘SELECT’ has questioned the database to reverse the order of the records before returning the first row of the result.

In order to be able to do this the database has read the entire table, sort it and then return the first record. If there was no ORDER BY clause then the results would have been identical (ie both ’000001′) but the second select if given a huge enough table to look at would be far slower.

Note that this causes a problem in the Extended Program Check if the full key is not specified in a ‘SELECT SINGLE’. Replacing the ‘SELECT SINGLE’ by an “UP TO 1 ROWS” will give the same exact results without any warning but the program will run slower and consume more memory. This is a excellent example of a warning that we should ignore… considering you are sure of what you are doing !!

Working around the limitations of a range in SELECT…WHERE…IN

When you use a range table in a select (SELECT * FROM sflight WHERE carrid IN lt_carrid), you sometimes get a small dump with the error DBIF_RSQL_INVALID_RSQL.

A lot of people reckon that a maximum number of records was reached; rumour has it that it’s somewhere between 1000 and 2000 records. This is fake and groundless. In fact, the problem is that the “IN” keyword is not native SQL and the compiler converts it into native SQL. There is a limitation on the length of the generated SQL string.

Here is a small example of a program to make a small dump :

DATA : lt_range TYPE RANGE OF sflight-carrid WITH HEADER LINE,

lt_sflight TYPE TABLE OF sflight.

DO 5000 TIMES.

lt_range-sign = ‘I’.

lt_range-option = ‘EQ’.

lt_range-low = ‘AA’.

APPEND lt_range.

ENDDO.

SELECT * FROM sflight INTO TABLE lt_sflight WHERE carrid IN lt_range.

The compiler convert the SELECT in native SQL like that :

… WHERE carrid = lt_range[1]-low OR

lt_range[2]-low OR

lt_range[3]-low OR

….

lt_range[5000]-low.

The small dump occur when the generated SQL caracter string is over a certain threshold. This threshold is variable, could be between 2k and 32k (usually 4k or 8k) depending on the DB system. The threshold is stored in dbs/io_buf_size and could NOT be change by programmers because this is maintained on DB level (oracle, DB2, etc…) by IT.

There are two ways to avoid this problem :

  1. Make some small packages (500 records) and call the SELECT within a loop with APPENDING TABLE keyword
  2. Usually the best way to do it is using a SELECT… FOR ALL ENTRIES IN… instead.

Calling function modules dynamically

When you only know the function name to call at run-time, you have to call your function dynamically. Here is an example of how to call a function dynamically (note: comments were added to an existing example from the standard help)

REPORT ZDANY_DYN_FM_CALL.

*The constants and structures required to use the dynamic function call

*is stored in the type pool ABAP.

type-pools abap.

*This is the name of the function you want to call.

data NAME type STRING value `READ_SPFLI_INTO_TABLE`.

* Parameter table, where you store all parameters, importing, exporting

* and changing data PARA_TAB type ABAP_FUNC_PARMBIND_TAB. data PARA_LINE like line of PARA_TAB.

* Exception table to handle the exception that can occur during the

* execution of the function

data EXCP_TAB type ABAP_FUNC_EXCPBIND_TAB.

data EXCP_LINE like line of EXCP_TAB.

data CARRIER type SPFLI-CARRID.

data JTAB type SPFLI_TAB.

CARRIER = ‘XYZ’.

* Name of the first parameter

PARA_LINE-NAME = ‘ID’.

* type of the first parameter, could be :

* abap_func_exporting value 10,

* abap_func_importing value 20,

* abap_func_tables value 30,

* abap_func_changing value 40.

PARA_LINE-KIND = ABAP_FUNC_EXPORTING.

*We need the datatype of the parameter to pass

get reference of CARRIER into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Same thing for parameter 2

PARA_LINE-NAME = ‘ITAB’.

PARA_LINE-KIND = ABAP_FUNC_IMPORTING.

get reference of JTAB into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Now we make the possible exceptions

EXCP_LINE-NAME = ‘NOT_FOUND’.

EXCP_LINE-VALUE = 1.

insert EXCP_LINE into table EXCP_TAB.

EXCP_LINE-NAME = ‘OTHERS’.

EXCP_LINE-VALUE = 4.

insert EXCP_LINE into table EXCP_TAB.

*… and we dynamically call the function with the parameter-table and

* exception-table addition

call function NAME

parameter-table

PARA_TAB

exception-table

EXCP_TAB.

* We check the result code

case SY-SUBRC.

when 1.

message id SY-MSGID type SY-MSGTY number SY-MSGNO.

when 2.

message E888(SABAPDOCU) with ‘Error in function module’.

endcase.

Downloading ABAP code to your local PC

Making Z* test programs is a well loved method for conducting tests. But, when an environment is about to get shut down, keeping your test programs becomes tough. You have to launch se38/37/24/80, select your programs one by one, and choose system -> list -> save -> local file, or use function module WS_DOWNLOAD. This is a lengthy procedure that does not even enable you to save screens, tables, or structures.

An ABAP program available for free download at http://www.dalestech.com/ can help you save your test programs.

  1. Choose home -> R/3 entreprise -> direct download entreprise 1.2
  2. download the .ZIP file,
  3. Unzip
  4. Cut and paste in an ABAP program
  5. Compile and run

All your projects (including multiple classes, programs, function groups, screens and tables) can be saved in less than one minute.

If you want to backup your work in order to keep a certain stable version while you are programming, it might be preferable use a tool that is already embedded in the Workbench: in se38/37/24/80, choose utilities -> versions -> generate version

share save 171 16 SAP ABAP FAQS PART 2

Related posts:

  1. SAP ABAP Faqs Part 1
  2. SAP ABAP FAQS
  3. SAP ABAP Interview Questions part 2
  4. SAP ABAP Interview Questions part 4
  5. SAP ABAP Interview Questions part 5
  6. SAP ABAP Interview Questions part 1
  7. SAP ABAP Scripts Question and Answers Part 5
  8. SAP ABAP Technical Questions ( Data Dictonary )
  9. SAP ABAP Scripts Question and Answers Part 3
  10. SAP ABAP Scripts Question and Answers Part 6
PDF Download    Send article as PDF