0% found this document useful (0 votes)
105 views8 pages

ABAP Programming - Day 3

This document provides an overview of various ABAP programming concepts including: 1. Program variants - Creating, saving, and reusing program variants. 2. Testing and debugging - Using extended syntax checks, breakpoints, watchpoints, and the debugger to test and debug programs. 3. Function modules - Creating normal, remote-enabled, and update function modules. 4. File handling - Uploading and downloading files from the presentation server and application server using GUI_UPLOAD, GUI_DOWNLOAD, and application files.

Uploaded by

Smack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
105 views8 pages

ABAP Programming - Day 3

This document provides an overview of various ABAP programming concepts including: 1. Program variants - Creating, saving, and reusing program variants. 2. Testing and debugging - Using extended syntax checks, breakpoints, watchpoints, and the debugger to test and debug programs. 3. Function modules - Creating normal, remote-enabled, and update function modules. 4. File handling - Uploading and downloading files from the presentation server and application server using GUI_UPLOAD, GUI_DOWNLOAD, and application files.

Uploaded by

Smack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

1

ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Day 3

Sanity Check, Testing & Debugging


Program Variants, Create, Save & Use

Extended Syntax Check and SCI

Break Points (Session/External), Watch Points & Debugging -> Program Flow; Logic better

Static and Dynamic (Session and External)

Function Module
Create one simple FM with MATNR as IMPORTING Parameter & WERKS field of MARC as
EXPORTING/Table Parameter

Test Data Save, Test & Debug

Concepts of Normal, RFC & Update Function Module

File Handling
Local File/Presentation - Upload/Download

Application File - Upload/Download

Difference, Advantage, Disadvantage

Program Variants, Create, Save & Use & Delete

Variant is a concept of saving a set of input fields with values with a particular name, so that we can use
the same set of inputs next time.

Create a demo variant and see to how to reuse it.


To get the variant name from VARID table by passing the report name; By using VARIT table how to
get name and text by passing report name.
Also, to see which set of values are saved in the variant make use of the FM: -
RS_VARIANT_VALUES_TECH_DATA and pass Report name and Variant Name to Importing
Parameters.

Finally delete the Variant and observe.

Extended Syntax Check and SCI

The extended program check can be called for activated programs either from ABAP Workbench or by
using transaction SLIN. It performs static checks that are too complex for the normal syntax check.

General Rule: - Use the extended program check

Page | 1 Course Content


2
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Use the extended program check and take the results seriously.

"Extended Program Check


SET EXTENDED CHECK OFF.
data: lv_val type i,
lv_val1 type c,
lv_final_output type char10.
field-symbols: <fs> type any.
lv_val = 5.
lv_val1 = lv_val.
concatenate 'The value is' lv_val1 into lv_final_output separated by space.
assign lv_val to <fs>.
write: lv_val.
if sy-subrc eq 0.
*IF <fs> IS ASSIGNED.
<fs> = 10.
endif.
write:/ lv_val.

For the Code Inspector we will use the t-code SCI. It helps developers to adhere to programming standards
and guidelines by creating messages on less-than-optimal coding. The Code Inspector can be used in
various scenarios with different types of checks, thus providing insights into the code quality from various
angles. We can create a Custom Variant as well

Single object checks from the Development Workbench

Checks on transport objects from the Transport Organizer

Write the below Demo Program and do an inspection via SCI and use the Custom Variant
created and check the Results via Logs

*declare all global variables.


DATA: spfli_table TYPE STANDARD TABLE OF spfli,
alv_obj TYPE REF TO cl_salv_table,
alv_exc_obj TYPE REF TO cx_salv_msg,
row_count TYPE int4.
*get the data from spfli table
SELECT * FROM spfli INTO TABLE spfli_table WHERE carrid = 'LH'.
row_count = sy-dbcnt.
IF sy-subrc = 0.
*dislpay the resultset in alv table
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = alv_obj
CHANGING t_table = spfli_table ).
alv_obj->display( ).
CATCH cx_salv_msg INTO alv_exc_obj.
MESSAGE alv_exc_obj TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
ENDIF.
WRITE: / 'row_count:', row_count.

Page | 2 Course Content


3
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Break Points (Session/External), Watch Points & Debugging

Important part in troubleshooting of an ABAP application. Helps in understanding the program flow and
logic better. Having good debugging skill is an Art and added Advantage.

Two kinds of BPs: - Static (By using BREAK-POINT) and Dynamic (External or Session) and also in the
debugger we can place BPs which are known as Debugger BPs.

Check F5, F6, F7, F8(Icon Strip) and how to create a watchpoint. Check the current cursor line in
debugger as in the yellow line. Also check the Desktop Strip and Tools available on the right side and
Variable Fast Display along with system variables(syst).

Will show some more BP concepts to participants by playing around with Internal Table and Variables
and how to change the entries.

Function Module
Create one simple FM with MATNR as IMPORTING Parameter & WERKS of MARC as EXPORTING/Table
Parameter. FM name ZFM_FETCH_PLANT_DETAIL. Use the FM created in report Z_ABAP_TRAINING.
(Save Test Data, Test & Debug)

1. Normal Function Module


2. Remote-Enabled Module -> A Remote-Enabled Module aka RFC is similar to a Normal
Function Module plus it can be accessed outside SAP. For example, consider there is an
application developed using c#.net and it requires to call specific Function Module in
SAP. One of the ways is to expose the Remote-Enabled Function. An RFC can be used
as a normal function module as well.

3. Update Module-> An Update Function Module has a special purpose. Consider a situation
where a vendor is to be created followed by a vendor extension. The prerequisite to
extend a vendor, the same vendor should be available in the database. Viz. a vendor
150100 is to be created in company 1000 and the same vendor needs to be extended to
companies 1001 and 1002. The vendor extension code is written in an update function
module and will be called as CALL FUNCTION ‘ZMM_EXTEND_VENDOR’ IN UPDATE
TASK exporting the relevant parameters. This function call will be kept in a queue rather
than executing it. Then the vendor is created and checked whether the creation is
successful. If the vendor creation is successful, a COMMIT WORK is called which executes
all Update Function Modules in the queue. If the transaction is failure, either a ROLLBACK
is called or the program is exited as is.

So, if a predefined set of instructions need to be executed after a successful execution of a module,
the predefined set is made an Update Module and called when needed. When the work is committed
on a successful execution, the Update Module in the queue is called.

Create an Update FM (Ref of ZFM_UPDATE_DATA) and use in report (Z_ABAP_TRAINING) to


pass data and Update DB data ZTAB_ADDRESS and also show the participants that the Parameter
of Update FM can be passed by Reference and hence we have to select the checkbox Pass b y Value
as shown below.

Page | 3 Course Content


4
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

DATA: ls_data TYPE ztab_address.

START-OF-SELECTION.
ls_data-emp_id = '1001'.
ls_data-address = 'ABC Street'.
ls_data-city = 'Bangalore'.
ls_data-state = 'Karnataka'.

CALL FUNCTION 'ZFM_UPDATE_DATA' IN UPDATE TASK


EXPORTING
im_data = ls_data
EXCEPTIONS
update_db_failed = 1
OTHERS = 2.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

COMMIT WORK.

Logic Inside Update FM: -

MODIFY ztab_address FROM im_data.


IF sy-subrc NE 0.
MESSAGE 'Error inserting data' TYPE 'E' RAISING update_db_failed.
ENDIF.

ENDFUNCTION.

Also, since the updates registered via update FM are executed in Special Work Processes UPD
hence exceptions are not considered for Update FMs.

For debugging an update FM, we have to change the settings via going to Debugger and Click on
Change debugger profile/settings button and then the update FM will be triggered on reaching
COMMIT WORK.

File Handling
Local File/Presentation - Upload/Download

Application File - Upload/Download

Page | 4 Course Content


5
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Show the Custom Prog: - Z_ABAP_TRAINING_UPLD_DWNLD to upload files from Pres. Server to App
Server and similarly download from App. Server to Presentation Server. There is also a provision to delete
files from both Presentation and App. Server. Execute the program and show them with the help of
debugging as in what’s the flow and how File Handling can be done.

The directory created via AL11 IS => ZTEST_DIR & /usr/sap/S20/D11/data

Explain the concepts to participants w.r.t GUI_UPLOAD and GUI_DOWNLOAD AND THE CONCEPT OF
DATASET to read and write files.(IN BINARY OR TEXT MODE FOR INPUT/OUTPUT)

Difference, Advantage, Disadvantage: - Jobs can be scheduled in background mode not only at the current
time, but it can also be scheduled for future time. If you schedule a background job which does
GUI_DOWNLOAD/UPLOAD, your program would dump or cancel out. The reason being, want to take
chance. GUI_DOWNLOAD/UPLOAD needs your laptop/computer to be switched on for it to save the data
in the presentation server path. Say you scheduled a job which has GUI_DOWNLOAD/UPLOD and switched
off your laptop and went to bed. When the job actually triggers, where will it save the file since your
laptop is switched off?

Therefore, SAP came with Application File Concept (although not just for background job).
Now, let us do the same exercise. You have OPEN DATASET (for AL11) syntax in your program. You
schedule a job. Switch off your laptop and go to sleep. In the middle of the night, the job triggers and it
saves the file in Application Server (AL11). It is not dependent on your local laptop or desktop. It is at the
Server level and Servers normally never sleep (except at planned outage or downtime).

Concept of OPEN DATASET, CLOSE DATASET…. (OUTPUT & INPUT MODE) … TRANSFER….. / READ
DATASET…/ DELETE DATASET… and so on.

Page | 5 Course Content


6
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Quizzes & Assignments

While creating an Include Program what is the Type to be chosen under Program Attributes?
• Executable
• Include
• Module Pool
• Function Group

What is the t-code for accessing a Include?


• SE38
• SE80
• SE37
• SE11

T-code for Extended Program Check and Code Inspector?

Suppose you set a Session BP in an ABAP program and you log off from the session and log in as a
different user; will the session BP be still applicable?
• Yes
• No

Can you set Dynamic BPs in an inactive source Code??


• Yes
• No

What are the 3 different types of FM?

For passing the Parameters in an Update or RFC FM can we pass them by Reference?
• Yes
• No

For calling a FN. Module in Update Task which statement needs to be executed?

What is the t-code used for Configuring a directory in SAP App. Server?
• AL11
• SM51
• WE05
• BD87

Exercise: -

• Explore AL11 and DATASET concepts and create a program for the same by making use of the
concepts learnt? (Same as in lines of the concept taught today). The below screens to be
designed and the functionality to be achieved as shown in class.

Page | 6 Course Content


7
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

Page | 7 Course Content


8
ABAP PROGRAMMING FOR BEGINNERS & FUNCTIONAL CONSULTANTS

• Explore SCI and create your own variant by making use of DEFAULT variant and then use this
variant to inspect an ABAP object.

• Explore the Debugger Screen and find out how many Desktop strips are there and also play
around by changing the values of an Internal Table during debugging.

• Explore V1, V2 and V3 update FM in detail. Also try to show some real time use cases of V1 and
V2 update FMs and also which work-process will be used for V1 and V2? (Hint: - UPD and UP2)

• Can’t we call an Update FM without making use of CALL FM…” IN UPATE TASK” statement. If yes
please try the same with the help of an example and do end to end testing.

Page | 8 Course Content

You might also like