Search For Potential Functional Issues With Code Inspector
Search For Potential Functional Issues With Code Inspector
Log on to the application server ZME on Sybase with system ID ZME. Create a copy
of report HA400_CODE_CHECK_T1 in your package ZHA400_## (suggested name:
ZHA400_##_CHECK_1, where ## is your group number). Activate and execute the
program, first on the primary database (Sybase ASE), then on the secondary
database (SAP HANA).
1. Create a copy of the report. Place it in your package ZHA400_## and assign it to
your workbench task.
a) Complete this step as you learned to do in previous classes.
Analyze the program with the Code Inspector (transaction SCI) to identify the source
of this functional issue. Use globally shipped check variant FUNCTIONAL_DB for
this check.
1. In Code Inspector (transaction SCI), create a local inspection for your program
ZHA400_##_CHECK_1 based on check variant FUNCTIONAL_DB (suggested
name for the inspection: HA400_##_FUNCTIONAL).
a) Enter transaction SCI.
b) In the Inspection frame, enter the name for the inspection and choose Create.
c) In the Object Selection frame, enter Single, Program, and the name of your
program.
d) In the Check Variant frame, enter the name of the check variant.
Hint:
You might have to choose the button to the left of the input field before you can
choose global check variants.
2. Execute the inspection and analyze the inspection result. Navigate to the ABAP
source
code. Read the check documentation for hints on how to correct the program.
a) On the toolbar, choose Execute.
b) To see the inspection result, choose Results on the toolbar.
c) Check the reported error(s). To navigate to the ABAP source, double-click a
message
code.
d) To display the check documentation, choose the “i”-icon next to the error
message.
Which check reports an error?
Check Search problematic statements for result of SELECT/OPEN CURSOR
without ORDER BY
What is the reason for this error?
Internal table lt_sbook is filled with a SELECT statement from database table
SBOOK. A subsequent LOOP over this internal table makes use of control
structures AT ... ENDAT.
This only works correctly if the content of lt_sbook is sorted by column CARRID.
What can you do to correct the coding?
Make sure the content of lt_sbook is sorted by column CARRID. There are
several ways to achieve this: 1. Add ORDER BY CARRID to the SELECT
statement. 2. Add statement SORT lt_sbook BY carrid. before the loop. 3.
Declare lt_sbook as Sorted Table.
1.Edit subroutine get_data of your program. Apply one of the possible corrections for
the Code Inspector error.
a) Alternative 1: Add addition ORDER BY CARRID at the end of the SELECT
statement .
b) Alternative 2: Add statement SORT lt_sbook BY carrid. before the loop.
c) Alternative 3: Replace the declaration of lt_sbook with statement DATA lt_sbook
TYPE SORTED TABLE OF sbook with NON-UNIQUE KEY carrid.
d)See the source code extract from the model solution.
2.Activate and test your program. Make sure both databases deliver exactly the
same data.
a)Complete this step as you learned to do in previous classes.
b)Verify that your code matches the following solution:
&---------------------------------------------------------------------*
*& Form get_data_template
*&---------------------------------------------------------------------*
* Declarations
****************
DATA ls_carrier LIKE LINE OF ct_carriers.
* Alternative 3: Sorted table
* DATA:
* lt_sbook TYPE SORTED TABLE OF sbook
* WITH NON-UNIQUE KEY carrid.
DATA:
lt_sbook TYPE TABLE OF sbook,
ls_sbook TYPE sbook,
ls_scarr TYPE scarr.
* Processing
*****************
*Alternative 1: ORDER BY
* SELECT * FROM sbook
* CONNECTION (pv_dbcon)
* INTO TABLE lt_sbook
SELECT * FROM sbook
CONNECTION (pv_dbcon)
INTO TABLE lt_sbook
ORDER BY carrid.
* Alternative 2: SORT ...
* SORT lt_sbook BY carcid.
LOOP AT lt_sbook INTO ls_sbook.
AT NEW carrid.
IF ls_carrier-carrid IS NOT INITIAL.
APPEND ls_carrier TO ct_carriers.
CLEAR ls_carrier.
ENDIF.
SELECT SINGLE * FROM scarr
CONNECTION (pv_dbcon)
INTO ls_scarr
WHERE carrid = ls_sbook-carrid.
MOVE-CORRESPONDING ls_scarr TO ls_carrier.
ENDAT.
CASE ls_sbook-class.
WHEN 'Y'.
ls_carrier-revenue_economy = ls_carrier-revenue_economy
+ ls_sbook-loccuram.
WHEN 'C'.
ls_carrier-revenue_business = ls_carrier-revenue_economy
+ ls_sbook-loccuram.
WHEN 'F'.
ls_carrier-revenue_first = ls_carrier-revenue_economy
+ ls_sbook-loccuram.
ENDCASE.
AT LAST.
APPEND ls_carrier TO ct_carriers.
CLEAR ls_carrier.
ENDAT.
ENDLOOP.
SORT ct_carriers BY carrid.
ENDFORM.