Download as pdf or txt
Download as pdf or txt
You are on page 1of 98

CD120 The Old Dog Tricks

That Will Help You Build


Applications FAST
MICHELLE CRAPO, PERRIGO COMPANY
MCRAPO@PERRIGO.COM
09-14-2011

Objective
Remind people of some of the older programming techniques that
will make your programming easier
Teach you just one thing Something new
Give you examples of things you can use NOW
Generate some open discussion
Personal objective get some feedback via the survey

Agenda

MVC quick comments about MVC


Change Documents
Text Object
Pattern
Table Maintenance
Debug
Helpful Transactions
Open Discussion You bring the questions
EVALUATIONS!!!!
The last pages are a program for you to take home. As time allows
Ill explain the requirements. Youve probably had similar ones.

ABAP Tips - MVC

Model Get
the Data

Controller
Links the
View and
the model

View
User
Interface

Change Documents

Why
When
How

Change Documents - Why?

SAP provided: Automatically creates data


Quick and Easy to do
Data in CDHDR / CDPOS

6
6

Change Documents - When


Every time I update a Z table where I need to track changes.
One example of a requirement
A new table was created to keep track of special instructions
needed on our production orders. This table is used when the
packaging card is printed. It was critical to know who made the
changes, and what they changed. The requirement was the
ability to track changes consistently.

Change Documents - How


SCDO
Create document object
Enter the name of the Z table
Several can be used. Logical groups. Are they all related to a
sales org?
Utilities generate update program
A list of includes will be generated. These includes can be used
with programs to track changes.
SCU3 will display the changes. Or you can create your own custom
program.

Change Documents - How


SCDO Create
Change Documents

Change Documents - How

Enter the name of


your table / tables

10

Change Documents - How


Utilities->Generate
Update program

11

Change Documents - How

Enter a function
group, click generate

12

Change Documents - How


List of includes to use
in custom program

13

Abap Tips - Change Documents

Custom Code
Include
FZMCTESTCHGCDC
Call form
cd_call_zmctestchg.
When there is a
change

CALL FUNCTION 'ZMCTESTCHG_WRITE_DOCUMENT'


EXPORTING
OBJECTID
=
TCODE
=
UTIME
=
UDATE
=
USERNAME
=
* PLANNED_CHANGE_NUMBER
=''
* OBJECT_CHANGE_INDICATOR
= 'U'
* PLANNED_OR_REAL_CHANGES
=''
* NO_CHANGE_POINTERS
=''
* UPD_ICDTXT_ZMCTESTCHG
=''
* UPD_ZMCTEST
=''
TABLES
ICDTXT_ZMCTESTCHG
=
XZMCTEST
=
YZMCTEST
=
.

14

Program to display change docs or you can use

SCU3
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING
* ARCHIVE_HANDLE
=0
* CHANGENUMBER
=''
* DATE_OF_CHANGE
= '00000000'
objectclass
= <Name of the class>
objectid
= objectid
TABLES
editpos
= editpos
EXCEPTIONS
no_position_found
=1
wrong_access_to_archive
=2
time_zone_conversion_error
=3
OTHERS
=4
.

15

Demo

16

Text Object
Why
When
How

17

Text Object - Why


SAP creates the editor screen
Use SAP Tables no need to create Z tables
The text object/id can be created by SAP provided screens

18

Text Object - When


Requirement
Create a screen where the user can enter long text like in VA02
Header text. We would like it to be attached to a custom
transaction ZXY. It should be pulled up via the key to the custom
table.
I have more text I want to add to the sales order it doesnt fit
into any of the categories listed. I want a new screen to add the
text.

19

Text Object - How

SE75
Create the text object

20

Text Object - How

Create the text ID

21

Text Object - How

SAP Supplied Function module to


read a text object / ID

CALL FUNCTION 'READ_TEXT_INLINE'


EXPORTING
id
= w_id
inline_count = '1'
language
= 'E'
name
= tdname2
object
= <Object you created>
IMPORTING
header
= header
TABLES
inlines
= inlines2
lines
= lines2
EXCEPTIONS
id
=1
language
=2
name
=3
not_found
=4
object
=5
reference_check = 6
OTHERS
= 7.
22

Text Object - How

SAP Supplied way of creating a


screen for the text to be entered.
You dont have to do anything to
create the screen. You can save
at this point or use the
SAVE_TEXT function module to
save here save = X.

CALL FUNCTION 'EDIT_TEXT_INLINE'


EXPORTING
display
=''
*
EDITOR_TITLE
=''
header
= header
inline_count
= w_lines
save
=''
textscreen
= 'X'
*
CONTROL
=''
*
SUPPRESS_END_SPACE = ' '
IMPORTING
function
= txtfunction
*
NEWHEADER
=
*
RESULT
=
TABLES
inlines
= inlines
lines
= lines
EXCEPTIONS
id
=1
language
=2
linesize
=3
name
=4
object
=5
OTHERS
= 6.

23

Text Element - Save

Save the text entered

CALL FUNCTION 'SAVE_TEXT'


EXPORTING
header
= header
insert
= w_insert
savemode_direct = 'X'
IMPORTING
function
= txtfunction
newheader
= header
TABLES
lines
= lines2
EXCEPTIONS
id
=1
language
=2
name
=3
object
= 5.

24

Demo

25

Pattern
Why
When
How

26

Pattern - Why
Easily insert repeated text

27

Pattern - When
Used to keep our comments at the top of the program the same.
Quick reference for a simple ALV

28

Pattern - How

Create
the Code

Create the
Pattern

Use it

Create the Code


- Write code in a different program and syntax check it
Create the Pattern
- Path in the editor: Utilities->More Utilities->Edit Pattern->Create Pattern
Use it!
-In the Editor Path: Edit->Pattern->Other Patterns

29

Patterns - How
Create a
program for
syntax
check

30

Patterns - How
Enter your code
for your pattern
and check it.
Switch your
parameters to
something
generic like
xx_table.
Copy to clipboard
31

Patterns - How

Create pattern

Utilities
More utilities
Edit Pattern
Create Pattern

32

ABAP Tips - Patterns


Paste code . Save the
pattern.
To use it:
Edit
Patterns
Other
Enter your pattern
name

33

Demo

34
34

Table Maintenance
Why
When
How

35

Table Maintenance - Why


Quickly creates an interactive interface for updating tables

36

Table Maintenance - When


The requirement:
Create a new table to hold master data about a SAP Teched.
Things like session number, Date, Time, Speaker
This really isnt a nice way to keep transactional data

37

Table Maintenance - How

So you create the


table / tables as there
is one that is a
header and one that
is a detail.
The header Master
data is a good
candidate for a table
maintenance
38

Table Maintenance - How

Table maintenance is
a nice quick way of
doing things
Set up foreign key
relationship.

39

Table Maintenance - How

SE80 Create
function group where
your table
maintenance for a
project will live. I
would recommend
creating a new one
based on the project

40

Table Maintenance - How

Create table
maintenance

41

Table Maintenance - How

SM30 test your


maintenance. But
what about your
description from the
master data? You do
have the drop down
for the data domain
with the values

42

Table Maintenance How

SE93
Pick a name
Parameter transaction
Enter the update
value and viewname

43

Table Maintenance How Whats possible

Create another table


maintenance for the
transactional table
Add entry

44

Table Maintenance How Whats Possible

Create a table
maintenance view

45

Table Maintenance How what is possible with the


maintenance view
Uses of a maintenance View
Combine tables
Limit the editable fields - There are times when fields shouldnt
be changed, but the table still needs to be edited.
There should be a place

46

Table Maintenance How Whats possible

Click relationships
Let it generate the
joins
Move to the view
fields
Click table fields and
select the ones you
want
Look at the second
column.

47

Table Maintenance How Whats possible

End up with a view


where when you enter
the key field the
description populates
You can use this
when you only want
one/several of the
fields editable nice
way to restrict fields
48

Demo

49

ALV
Why
When
How

50

Why?
Quickly creates a very nice user interface where they have control of
the layout. That means no programming changes when they want
to rearrange data.
A side benefit if you give them more information than they need, set
up a default layout then when they request the extra fields, they
are already there. Again no programming.

51

ALV - How

Old Dog Trick use


ALV to quickly format
your reports this
allows the user to
have control of
columns displayed /
sorts etc.

CALL FUNCTION 'REUSE_ALV_GRID_D


ISPLAY'
EXPORTING
IS_LAYOUT
IT_FIELDCAT
IT_EXCEPT_QINFO
TABLES
T_OUTTAB
EXCEPTIONS
PROGRAM_ERROR
OTHERS

= ls_layout
= lt_fcat
= gt_exc
= gt_outtab
=1
=2

52

ALV How Old to New

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
IS_LAYOUT
IT_FIELDCAT
IT_EXCEPT_QINFO
TABLES
T_OUTTAB
EXCEPTIONS
PROGRAM_ERROR
OTHERS

= ls_layout
= lt_fcat
= gt_exc
= gt_outtab
=1
=2

DATA: go_alv
TYPE REF TO cl_sal
go_functions TYPE REF TO cl_salv_functions_list.
cl_salv_table=>factory(
IMPORTING
r_salv_table = go_alv
CHANGING
t_table
= gt_ZMC_TECHEDGRD_table
).
go_functions = go_alv->get_functions( ).
go_functions->set_all( ).
go_alv->display( ).

53

ALV How - Old/New

call function 'LVC_VARIANT_F4'


exporting
is_variant = x_layout
i_save = x_save
importing
e_exit = g_exit
es_variant = spec_layout
exceptions
not_found = 1
others = 2.

DATA: ls_layout TYPE salv_s_layout_info,


ls_key TYPE salv_s_layout_key,
cv_layout TYPE disvariant-variant.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>f4_layouts(
s_key = ls_key
restrict = if_salv_c_layout=>restrict_none ).
p_layout = ls_layout-layout.

54

ALV How - Help on New OO ALV


SCN
See BCALV* programs on your system
Start to look at the way the classes are configured double click to
see everything available look at the parameters

55

Debugging
Why
When
How

56

Debugging Why?
A million reasons basically to troubleshot programs while
developing and when there is a problem.

57

Debugging - When
Business Case
All the time!!!! Development and troubleshooting. Or figuring out
what SAP has done.

58

Debugging - How
Download internal tables I use this when I want to look at the data
in an excel format change to a summary view, total a column
subtotal etc.
Test FM with parameters saved from running your program This
one has saved a lot of time when Debugging SAP Programs. If you
just want to run the FM, and dont want to try to copy the data from
your screen into a FM.
Display multiple internal tables Ive used this to compare tables.
Modify multiple lines of internal tables.
Can be started from outside applications by setting break-point in
code.
Started with jobs in the background.

59

Debugging - How
Download Internal table

60

Debugging - How
Step 1 Save parameter FM test data
Name test

Select test data created

Test
FM

61

ABAP Tips - Debugging


Tables tab

Tools Box

62

Debug - How
Tables Tab

Rows
open for
input

63

Debugging - how

External
Breakpoint

64

Debug - How
Set Breakpoint

Start
Debug
JDBG

65

Demo

66

Helpful Transactions to Remember

Parameter IDs
SE38 or SE80 *Demo*
ABAPDOCU
SEARCH_SAP_MENU Search SAP Menus
DWDM Sap Demo Programs
Create variants at run time RS_CREATE_VARIANT
SHDB Create BDC recording
Enqueue / Dequeue table SE11, Lock Objects

67

Helpful Transactions
Transaction Variant require fields / hide etc
Create in SPRO
SPRO -> SAP Netweaver -> General Settings -> field display
characteristics -> Configure application transaction fields
ZMD_CONSTANT Set up a custom configuration table
Search Help SE11 saves code
SM37 set the breakpoints then JDBG to run the background job
RSMODPRF to maintain old text element changes

68

New Technology - View / Controller

Web Dynpro
JAVA Dynpro
Visual Composer
Business Objects
BI reports
More

Controller Usually a part of the new technology. It pulls in the


data via the model

69

Questions? / Tips
you have?

70

Evaluations Please
Feedback
Please complete a session evaluation for this session!

71

And so the quick program


Requirement 1:
Create tables for inputting badge number (It could be scanned.)
and ratings of classes
Allow header and detail tables to be edited. Have a set of fields
for specific entries (Ratings from 1 10 ) (Dont worry about the
format of you detail / transactional data.)
Requirement 2
Follow standards using comments at the top of the page
Display the Ratings of a session allow for a selection by badge
number. (Require the field) Allow for sorting, rearranging, and
saving of layouts.
Have an open page for comments from people in lecture
72

Fast and Easy


Create tables needed
Create Maintenance View

73

Fast and Easy Example

Example of a Main
data table We can
even use a
maintenance view if
one person enters the
session and one
person adds the
speaker names

74

Fast and Easy Example

Create the Function


group
Create the table
Maintenance

75

Fast and Easy Example

Create Transaction

76

Fast and Easy Example

Run the transaction


Quickly creates a
screen to load some
master data

77

Fast and Easy Example

Do the same thing for your


ZMC_TECHEDGRD, and add data (I would
create an interactive program for this one
transactional data.)

78

Fast and Easy Example

Create an ALV to get


data on all the
sessions
Need to allow person
to enter comments
Start my program by
filling in the
comments using a
pattern
79

Fast and Easy Example

Quickly have a
common heading
Now Ill add the ALV
Pattern

80

Fast and Easy Example

Do some minor code


changes

81

Fast and Easy Example

Run the program for a


badge in the system
Quick this was done
very fast, with a
decent first result
Next to add the long
text

82

Fast and Easy Example

SE75 create your


text object / ID

83

Fast and Easy Example

Add the event to your


program Thats it!

84

Fast and Easy Add Layout option

85

Demo

86

Other Related Teched Sessions

CD102 How to use SAP Interactive Forms from Adobe


CD112 Introduction to Code Exchange
CD164 Web Dynpro for beginners
CD204 Enhancing SAP without Modification Best Practice

87

The following slides - Program


The following slides were set up so you could cut and paste the
program into your system and use it. (Take Home Slides)
Note replace zmc_techedgrd with a table in your system.

88

The Program Comments / Data Definition

***********************************************************************
* Program Purpose: Provide a description of what this program does
* Date Written:
* Author:
* Initial request number
* Transaction code (if applies)
* SAIC Contact name
* SAIC functional area
* Unit test script name (if applicable)
* Where used: important if standard SAP "where-used" function won't
*
"see" this program
* Area Menu (if applicable)
************************************************************************
*
Maintenance
*
* Task #
Date
CC# Prgmr Description
* D46nnnnnn mm-dd-yyyy
ZMC_TECHEDGRDx
************************************************************************
*&---------------------------------------------------------------------*
*& Z_ALV: pattern for creating an ALV report
*&
*&---------------------------------------------------------------------*
*& Replace ZMC_TECHEDGRD_TABLE with the table you are selecting from or displaying
*& It must be defined in the data dictionary but may be a structure
*& instead of a transparent table
*&
*&---------------------------------------------------------------------*
REPORT zmc_fillform2.
PARAMETERS p_badge TYPE zsess_attkey OBLIGATORY.
PARAMETER: p_layout TYPE ltdx-variant.
DATA: gt_zmc_techedgrd_table TYPE TABLE OF zmc_techedgrd,
gs_zmc_techedgrd_table LIKE LINE OF gt_zmc_techedgrd_table.

DATA: go_alv
TYPE REF TO cl_salv_table,
go_functions TYPE REF TO cl_salv_functions_list,
go_layout TYPE REF TO cl_salv_layout,
v_key
TYPE salv_s_layout_key.

89

The program Cont Double click Set up data for


display and change

CONCATENATE 'Comments on Session ' gs_zmc_techedgrd_table-session_num INTO


ls_header-tdtitle.
ls_header-tdobject = 'ZTECHSESS'.
ls_header-tdname = lv_name.
ls_header-tdid
= 'ZLTX'.
ls_header-tdspras = sy-langu.
ls_header-tdlinesize = '072'.
ls_header-tdtxtlines = '0001'.
ls_header-tdospras = sy-langu.
ls_header-tdfuser = sy-uname.
ls_header-tdfreles = sy-saprl.
ls_header-tdfdate = sy-datum.
ls_header-tdftime = sy-uzeit.
ls_header-mandt
= sy-mandt.

90

The Program execute up edit / save screen

CALL FUNCTION 'EDIT_TEXT_INLINE'


EXPORTING
* DISPLAY
=''
* EDITOR_TITLE
=''
header
= ls_header
inline_count
= 50
save
= 'X'
textscreen
= 'X'
* LINE_EDITOR
=''
* CONTROL
=''
* SUPPRESS_END_SPACE
=''
* PROGRAM
=''
* LOCAL_CAT
=''
IMPORTING
function
= txtfunction
* NEWHEADER
=
* RESULT
=
TABLES
inlines
= lt_inlines[]
lines
= lt_lines[]
EXCEPTIONS
id
=1
language
=2
linesize
=3
name
=4
object
=5
OTHERS
=6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMETHOD.
"on_double_click
ENDCLASS.

91

Program Class definition for double click

*=====================================================================*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
"lcl_handle_events DEFINITION

92

The program start of double click read the text

CLASS lcl_handle_events IMPLEMENTATION.


METHOD on_double_click.
DATA lv_name TYPE thead-tdname.
DATA: lt_lines TYPE STANDARD TABLE OF tline.
DATA: lt_inlines TYPE STANDARD TABLE OF tline.
DATA: ls_header TYPE thead.
DATA: txtfunction(1).
READ TABLE gt_zmc_techedgrd_table INTO gs_zmc_techedgrd_table INDEX row.
CONCATENATE p_badge gs_zmc_techedgrd_table-session_num INTO
lv_name.
CALL FUNCTION 'READ_TEXT_INLINE'
EXPORTING
id
= 'ZLTX'
inline_count = 50
language
= sy-langu
name
= lv_name
object
= 'ZTECHSESS'
TABLES
inlines
= lt_inlines[]
lines
= lt_lines[]
EXCEPTIONS
id
=1
language
=2
name
=3
not_found
=4
object
=5
reference_check = 6
OTHERS
= 7.

93

The Program main start-of-selection Data


declarations and retrieve the data to be displayed

START-OF-SELECTION.
v_key-report = sy-repid.
DATA: lr_events TYPE REF TO cl_salv_events_table.
DATA: gr_events TYPE REF TO lcl_handle_events.
DATA: lr_layout TYPE REF TO cl_salv_layout.
*----------------------------------------------------------------------*
* either select from db table or use internal table that is already
* built but structure must be defined in DB
*----------------------------------------------------------------------*
SELECT * FROM zmc_techedgrd
INTO TABLE gt_zmc_techedgrd_table
WHERE badge = p_badge.

IF sy-subrc <> 0.
MESSAGE 'No records found' TYPE 'I'.
RETURN.
ENDIF.

94

The Program - Start setting up ALV

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = go_alv
CHANGING
t_table
= gt_zmc_techedgrd_table
).
*IF ERROR...
CATCH cx_salv_msg.
*ELSE IF ERROR...
WRITE: /5 'ERROR OCCURRED'.
ENDTRY.
** Set up Double Click
lr_events = go_alv->get_event( ).
lr_layout = go_alv->get_layout( ).

95

The Program - Set up Events allow save of


layout

CREATE OBJECT gr_events.


SET HANDLER gr_events->on_double_click FOR lr_events.

go_layout = go_alv->get_layout( ).
* allow layout saves and sel.
* Set up the key for the layout
v_key-report = sy-repid.
* Step 2 set the key.
go_layout->set_key( v_key ).
* Set layout
go_layout->set_initial_layout( p_layout ).
* Allow save
DATA: v_res TYPE salv_de_layout_restriction.
v_res = if_salv_c_layout=>restrict_none.
go_layout->set_save_restriction( v_res ).
* Allow default layout
go_layout->set_default( 'X' ).
go_functions = go_alv->get_functions( ).
go_functions->set_all( ).

go_alv->display( ).
END-OF-SELECTION.

96

The Program the end dropdown (F4) for layout


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
DATA: ls_layout TYPE salv_s_layout_info,
ls_key TYPE salv_s_layout_key,
cv_layout TYPE disvariant-variant.
ls_key-report = sy-repid.
ls_layout = cl_salv_layout_service=>f4_layouts(
s_key = ls_key
restrict = if_salv_c_layout=>restrict_none ).

p_layout = ls_layout-layout.

97

Evaluations
Feedback
Please complete a session evaluation for this session!

98

You might also like