Tuesday, July 31, 2007

Tabstrip in selection screen

To define a tabstrip area with tab pages in selection screen, use the following statements in your selection screen definition:


SELECTION-SCREEN: BEGIN OF TABBED BLOCK FOR LINES,
TAB () USER-COMMAND
[DEFAULT [PROGRAM ] SCREEN ],
TAB () USER-COMMAND
[DEFAULT [PROGRAM ] SCREEN ],
...
END OF BLOCK .


This defines a tabstrip control with size . The tab pages , ... are assigned to the tab area. defines the width of the tab title. You must assign a function code area to each tab title.

For each tab title, the system automatically creates a character field in the ABAP program with the same name. In ititialization, you can assign a text to the field. This then appears as the title of the corresponding tab page on the selection screen.

You must assign a subscreen to each tab title. This will be displayed in the tab area when the user chooses that title. You can assign one of the following as a subscreen:



1. A subscreen screen defined using the Screen Painter.
The dialog modules containing its flow logic must be defined in the current ABAP program.

2. A selection screen subscreen, defined in an ABAP program.
User actions will trigger the AT SELECTION-SCREEN event at least twice – firstly for the "included" selection screen (we can use it for validation), then for the selection screen on which it appears.

This is simple program with three tab title.
Tab1 demonstrating input validation.
Don't forget to create subscreen 0300 for Tab3.

REPORT ZAALGAL0007.
*http://abap-gallery.blogspot.com

TABLES: sscrfields.

* SUBSCREEN 1 For Tabstrip BUTTON1

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p1(10) TYPE c,
p2(10) TYPE c,
p3(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2 For Tabstrip BUTTON2

SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME.
PARAMETERS: q1(10) TYPE c OBLIGATORY,
q2(10) TYPE c.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.

* Go to tcode SE51 Create screen no 0300
* with screen type = subscreen

* STANDARD SELECTION SCREEN

PARAMETERS: h1(10) TYPE c.

SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 10 LINES,
TAB (20) button1 USER-COMMAND push1
DEFAULT SCREEN 100,
TAB (20) button2 USER-COMMAND push2
DEFAULT SCREEN 200,
TAB (20) button3 USER-COMMAND push3
DEFAULT SCREEN 300,
END OF BLOCK mytab.

INITIALIZATION.
button1 = 'This is sel-screen 100'.
button2 = 'This is sel-screen 200'.
button3 = 'This is screen 300'.
mytab-prog = sy-repid.
mytab-dynnr = 100.
mytab-activetab = 'BUTTON1'.

AT SELECTION-SCREEN.
CASE sy-dynnr.
WHEN 1000.
WHEN 100.
IF p1 IS INITIAL.
sscrfields-ucomm = 'PUSH1'.
MESSAGE I888(sabapdocu) WITH 'Make an entry in P1'.
ENDIF.
WHEN 200.
MESSAGE s888(sabapdocu) WITH 'Validation on' sy-dynnr.
ENDCASE.


START-OF-SELECTION.
WRITE: / 'P1:', p1,'Q1:', q1,
/ 'P2:', p2,'Q2:', q2,
/ 'P3:', p3.

Read More......

Thursday, July 26, 2007

Change layout format in ALV

Layout format in ALV defined in structure IS_LAYOUT as importing structure of ALV REUSE_ALV_LIST_DISPLAY.


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
......
is_layout = wa_layout
......
EXCEPTIONS
program_error = 1
OTHERS = 2.


Commonly used field:

- IS_LAYOUT-ZEBRA: X=striped (zebra) pattern
- IS_LAYOUT-BOX_FIELDNAME: insert column checkbox for each row to select row.
How to inset checkbox:
1. insert new field with type C in internal table ALV data to record selection indicator (X:selected).
Example:

DATA: BEGIN OF t_alv OCCURS 1,
field1,
field2,
...
BOX,
END Of T_alv.

2. set IS_LAYOUT-BOX_FIELDNAME = fieldname in internal table ALV data.
Example:

IS_LAYOUT-BOX_FIELDNAME = 'BOX'.

3. At run time, t_alv-box will filled with 'X' for selected data.

CheckBox can be initiated in these ways:
1: selected, can not be changed
0: not selected, can not be changed
X: selected, can be changed
SPACE (blank):not selected, can be changed
-: disable check box

- IS_LAYOUT-COL_FIELDNAME
Cells can be colored individually using a color code which is contained in a column of the internal output table for the record containing the cell.
Assign the name of the field to this parameter.
The internal output table field must be of type SLIS_T_SPECIALCOL_ALV.
Principle: the color code field is entered for the record containing the cells to be colored. The field contains an internal table with the above structure, containing the field names of the cells to be colored and the color code. The cell coordinates are determined by the record position containing the color code and the column information in the color table.
The record structure of the internal color table of type SLIS_T_SPECIALCOL_ALV is as follows:
Color table-FIELDNAME = field name of the cell to be colored
Color table-COLOR-COL = color number (1 - 9)
Color table-COLOR-INT = bold (0 = off, 1 = on)
Color table-COLOR-INV = inverse (0 = off, 1 = on)
Color table-NOKEYCOL = ignore key coloring ('X' = yes, ' ' = no)
If the parameter color table-FIELDNAME is not filled, the coloring applies to all fields, so the entire record is colored.

Read More......

Field catalog in ALV

Field catalog containing descriptions of the list output fields. You can use fields of the catalog to determine the number format and column properties of the list to be displayed.

The field catalog contains more than 60 fields, some of which are only used internally. The field catalog is defined in the Data Dictionary through table type LVC_T_FCAT.

We can get field description by calling function module REUSE_ALV_FIELDCATALOG_MERGE. You can see the sample in my post about Simple ALV Report.

In general case, we only use few field to describe output field.
To make it easier I use this form:



FORM f_alv_fieldcatg USING
fu_types "internal table name
fu_fname "Field name of internal table field
fu_reftb "reference table name
fu_refld "reference table field
fu_noout "X= No out
fu_outln "out
fu_fltxt "output length
fu_dosum "X=Do sum (total)
fu_hotsp "X=hotspot on
fu_just. "Justification:L,R,C

CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-no_out = fu_noout.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
t_fieldcat-just = fu_just.
APPEND t_fieldcat.
CLEAR t_fieldcat.
ENDFORM. " f_alv_fieldcatg

We can use it in two way:
1. refer to data dictionary:

PERFORM f_alv_fieldcatg USING 'T_REPORT' :
'EQUNR' 'EQUI' 'EQUNR' '' '' '' '' 'X' '',
'SPART' 'VBAK' 'SPART' '' '' '' '' '' ''.

2. or define yourself

PERFORM f_alv_fieldcatg USING 'T_REPORT' :
'FIELD1' '' '' '' '20' 'Text Field1' '' '' ''.


and for field with type number, I use this:

*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_number
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_number USING fu_types
fu_fname
fu_noout
fu_outln
fu_no_sign
fu_no_zero
fu_fltxt
fu_dosum
fu_exponent
fu_decimals_out.

CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-no_zero = fu_no_zero.
t_fieldcat-no_sign = fu_no_sign.
t_fieldcat-exponent = fu_exponent.
t_fieldcat-decimals_out = fu_decimals_out.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-datatype = 'FLTP'.
APPEND t_fieldcat.
CLEAR t_fieldcat.


ENDFORM. " f_alv_fieldcatg_number


For field currency, there are two options, fixed currency or variable currency.

*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_curr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_curr USING fu_types
fu_fname
fu_reftb
fu_refld
fu_noout
fu_outln
fu_fltxt
fu_dosum
fu_hotsp
fu_cfield.

CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
t_fieldcat-cfieldname = fu_cfield.
t_fieldcat-ctabname = fu_types.
t_fieldcat-no_zero = 'X'.
APPEND t_fieldcat.
CLEAR t_fieldcat.

ENDFORM. " F_FIELDCATG_CURR

*&---------------------------------------------------------------------*
*& Form f_alv_fieldcatg_curr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv_fieldcatg_curr_fixed USING fu_types
fu_fname
fu_reftb
fu_refld
fu_noout
fu_outln
fu_fltxt
fu_dosum
fu_hotsp
fu_curr.

CLEAR: t_fieldcat.
t_fieldcat-tabname = fu_types.
t_fieldcat-fieldname = fu_fname.
t_fieldcat-ref_tabname = fu_reftb.
t_fieldcat-ref_fieldname = fu_refld.
t_fieldcat-no_out = fu_noout.
t_fieldcat-outputlen = fu_outln.
t_fieldcat-seltext_l = fu_fltxt.
t_fieldcat-seltext_m = fu_fltxt.
t_fieldcat-seltext_s = fu_fltxt.
t_fieldcat-reptext_ddic = fu_fltxt.
t_fieldcat-do_sum = fu_dosum.
t_fieldcat-hotspot = fu_hotsp.
* t_fieldcat-cfieldname = fu_cfield.
* t_fieldcat-ctabname = fu_types.
t_fieldcat-datatype = 'CURR'.
t_fieldcat-currency = fu_curr.
t_fieldcat-no_zero = 'X'.
APPEND t_fieldcat.
CLEAR t_fieldcat.

ENDFORM. " F_FIELDCATG_CURR

Read More......

Wednesday, July 25, 2007

Hide parameter / select option in selection screen

We can Hide parameter / select option in selection screen dynamically by manipulating screen object.

SCREEN is like an internal table with a header line. However, you do not have to declare it in your program. Go to debugging mode and then view structure of screen.

You can modify SCREEN in your ABAP program during the PBO event of a screen. Its contents override the static attributes of the screen fields for a single screen call. The only statements that you can use with SCREEN are:


LOOP AT SCREEN.
...
MODIFY SCREEN.
...
ENDLOOP.

We can hide parameter by set screen-active to 0.
Here is example of how to hide parameter in selection screen. Write it, and change click on radiobutton to hide parameter.


REPORT ZAALGAL0006.

DATA: d_ucomm LIKE sy-ucomm.

PARAMETERS: p_grpa1(10) MODIF ID A,
p_grpa2(5) MODIF ID A,
p_grpb1(2) MODIF ID B.

PARAMETERS: p_actA RADIOBUTTON GROUP rad1 USER-COMMAND ACT DEFAULT 'X',
p_actB RADIOBUTTON GROUP rad1.

AT SELECTION-SCREEN.
d_ucomm = sy-ucomm.

AT SELECTION-SCREEN OUTPUT.
LOOP AT screen.
IF p_actA = 'X'.
IF screen-group1 = 'B'.
screen-active = 0.
ENDIF.
ELSEIF p_actB = 'X'.
IF screen-group1 = 'A'.
screen-active = 0.
ENDIF.
ENDIF.
MODIFY screen.
ENDLOOP.

START-OF-SELECTION.


Read More......

Tuesday, July 24, 2007

Add toolbar button on selection screen


We can add new toolbar (maximal 5) in ABAP report to make program more interactive to user on selection screen.

Do following step.

1. Declare work area sscrfields.

TABLES: sscrfields.

2. Define text displayed in button in initialization event.

INITIALIZATION.
MOVE 'This is button 1' TO sscrfields-functxt_0n." n = 1 up to 5

3. Activate toolbar in selection screen.

SELECTION-SCREEN FUNCTION KEY n.

4. Check user command in AT selection screen

AT SELECTION-SCREEN.
IF sy-ucomm = 'FC0n'." n = 1 up to 5
....
ENDIF.

This is complete sample:

REPORT ZAALGAL0005 .

TABLES: sscrfields.

DATA: d_butt1(4).

PARAMETERS: p_grpa1(10) MODIF ID A,
p_grpa2(10) MODIF ID A,
p_grpb1(10) MODIF ID B.

SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.

INITIALIZATION.
MOVE 'This is button 1' TO sscrfields-functxt_01.
MOVE 'Toggle 1' TO sscrfields-functxt_02.
d_butt1 = 'NO'.

AT SELECTION-SCREEN.
IF sy-ucomm = 'FC01'.
d_butt1 = 'YES'.
sscrfields-ucomm = 'ONLI'.
ELSEIF sy-ucomm = 'FC02'.
IF sscrfields-functxt_02 = 'Toggle 1'.
sscrfields-functxt_02 = 'Toggle 2'.
ELSE.
sscrfields-functxt_02 = 'Toggle 1'.
ENDIF.
ENDIF.

START-OF-SELECTION.
WRITE d_butt1.


Read More......

Monday, July 23, 2007

Debugging ABAP Program

To go to ABAP debugging mode, activate ABAP debuggin then press enter. In ABAP report, usually debuggin mode started from selection screen, just before we enter execute command (F8).

There are two way to alternative way to activate debugging mode:
1. Type "/h" in command field (little box in upper left corner, where we usually type transaction code in it)
2. Go To System -> Utilities -> Debug ABAP






In ABAP debugger we can view and change data. It also allow you to execute your program line by line.

Read More......

Performance Tuning - Operation on Internal Table

In development server you may not aware of performance tuning on operation on internal table, but it could become a problem when you are working on internal table containing more 10 thousand rows.

These are tips to improve your program performance.

READ Table WITH Criteria
By default, read command on internal table will read it sequentially. The binary search algorithm helps faster search of a value in an internal table. But you must sort it before use binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half.


SORT TABLE BY field1.

READ TABLE table1 WITH KEY field1 = criteria1 BINARY SEARCH.
Do try it for internal table containing more than 10 thousand rows, you will find it significantly improve performance tuning.

You can apply binary search method to improve performance on nested loop.
Nested loop:


LOOP AT inttab1.
LOOP AT inttab2 WHERE intab2-field1 = intab1-field1.
ENDLOOP.
ENDLOOP.



Replace above code with additional binary search.



SORT inttab2 BY field1.
LOOP AT inttab1.
READ TABLE inttab2 WITH KEY field1 = inttab1-field1 BINARY SEARCH.
CHECK sy-subrc = 0.
LOOP AT inttab2 FROM sy-tabix.
IF inttab2-field1 NE inttab1-field1.
EXIT.
ENDIF.
ENDLOOP.
ENDLOOP.


Read More......

Sunday, July 22, 2007

Help Value Request (F4)

This sample program demonstrate how to create "Help Value Request". It will appear when user pressing F4 (help) on an input field to request list of available value.

To do this we are using function module F4IF_INT_TABLE_VALUE_REQUEST. It provide help value request with following feature:
1. single / multiple choice.
2. update screen without PBO, so it can be used to update more than one field on one request.

Here is the code:


REPORT ZAALGAL0003 .

TABLES: usr02.

parameters: p_bname LIKE usr02-bname,
p_class LIKE usr02-class.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_bname.
PERFORM f_valuerequest_vbeln.
*&---------------------------------------------------------------------*
*& Form f_valuerequest_vbeln
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_valuerequest_vbeln.

DATA: BEGIN OF t_data OCCURS 1,
data(20),
END OF t_data.

DATA: lwa_dfies TYPE dfies.

data h_field_wa LIKe dfies.
data h_field_tab like dfies occurs 0 with header line.
data h_dselc like dselc occurs 0 with header line.

SELECT * FROM usr02.
t_data = usr02-bname. APPEND t_data.
t_data = usr02-class. APPEND t_data.
ENDSELECT.

PERFORM f_fieldinfo_get USING 'USR02'
'BNAME'
CHANGING h_field_wa.
APPEND h_field_wa TO h_field_tab.
PERFORM f_fieldinfo_get USING 'USR02'
'CLASS'
CHANGING h_field_wa.
APPEND h_field_wa TO h_field_tab.

h_dselc-fldname = 'BNAME'.
h_dselc-dyfldname = 'P_BNAME'.
APPEND h_dselc.
h_dselc-fldname = 'CLASS'.
h_dselc-dyfldname = 'P_CLASS'.
APPEND h_dselc.

DATA: ld_repid LIKE sy-repid.
ld_repid = sy-repid.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'P_BNAME'
dynpprog = ld_repid
dynpnr = '1000'
dynprofield = 'P_BNAME'
* multiple_choice = ''
* value_org = 'S'
TABLES
value_tab = t_data
field_tab = h_field_tab
* return_tab = return_tab
DYNPFLD_MAPPING = h_dselc
EXCEPTIONS
OTHERS = 0.

ENDFORM. " f_valuerequest_vbeln
*&---------------------------------------------------------------------*
*& Form f_fieldinfo_get
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0079 text
* -->P_0080 text
* <--P_H_FIELD_WA text
*----------------------------------------------------------------------*
FORM f_fieldinfo_get USING fu_tabname
fu_fieldname
CHANGING fwa_field_tab.


CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = fu_tabname
FIELDNAME = fu_fieldname
LFIELDNAME = fu_fieldname
IMPORTING
DFIES_WA = fwa_field_tab
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM. " f_fieldinfo_get

Read More......

Friday, July 20, 2007

New ABAP Trial Software Available !!!


If you are new to ABAP / SAP. You might find this link useful.

Download the latest version trial version of SAP NetWeaver 7.0 ABAP technology (SP12), including Web Dynpro for ABAP! .
Download ABAP Trial Version

Try to download it, and if it success, try to create your first ABAP program.


Enjoy installing ABAP trial :)

Read More......

Get Document / File stored in SAP

Previous post: Store Document / File to SAP

Get document / file stored in SAP Business Document.


REPORT ZAALTES1 line-size 300.

INCLUDE officeintegrationinclude. " used by DOI
* Get descr_list
TYPES: BEGIN OF SOI_DOCUMENT_TYPE_DESCR,
DOCUMENT_TYPE TYPE SOI_DOCUMENT_TYPE, " prog id
TYPE_FULL_NAME(70) TYPE C, " full name
TYPE_SHORT_NAME(20) TYPE C, " short name
APPLICATION_NAME(50) TYPE C, " application name
SUPPORTED_INTERFACES(256) TYPE C, " supported SAP interfaces
AVAILABLE(1) TYPE C, " X on return when available
END OF SOI_DOCUMENT_TYPE_DESCR.
DATA:
descr_list TYPE soi_document_type_descr_list,
wa_descr_list TYPE SOI_DOCUMENT_TYPE_DESCR,
retcode TYPE t_oi_ret_string.
DATA: application_cntl TYPE REF TO i_oi_ole_container_control.
* ----------

* -- connection table and the internal structure of the ITAB
DATA: BEGIN OF i_bds_conn OCCURS 10. " ITAB for the actual
INCLUDE STRUCTURE bdn_con. " document
DATA: objecttext LIKE toasp-objecttext,
objecttext2 LIKE toasd-objecttext,
objecttext3 LIKE toasr-objecttext,
ntext LIKE tojtt-ntext,
END OF i_bds_conn.
DATA: BEGIN OF bds_doctype_list OCCURS 10,
mandt TYPE mandt,
classname LIKE bapibds01-classname,
contrep LIKE i_bds_conn-contrep,
docuclass LIKE i_bds_conn-docuclass,
docuclass_text LIKE toasd-objecttext,
doc_type LIKE i_bds_conn-doc_type,
doc_type_text LIKE toasp-objecttext,
appl_type LIKE toadd-appl_type,
appl_type_text(50) TYPE c,
standard LIKE toadv-standard,
check_box LIKE toadv-standard,
END OF bds_doctype_list.

TYPES: ole2_application(70) TYPE c.

DATA:
logical_system LIKE bds_conn00-log_system,
display_struc LIKE i_bds_conn OCCURS 2 WITH HEADER LINE,
classname_select LIKE bdn_con-classname,
classtype_select LIKE bdn_con-classtype,
objkey_select LIKE bdn_con-objkey,
mask(20) TYPE c,
signature LIKE bapisignat OCCURS 1 WITH HEADER LINE,
build_all(1) TYPE c, " get all OLE apps
ole2_app TYPE ole2_application,
i_ole2_app_text LIKE bds_doctype_list-appl_type_text,
d_tabix LIKE sy-tabix,
vartemp
.
TYPES: BEGIN OF ole_apps_struc,
appl_type LIKE toadd-appl_type,
appl_type_text LIKE bds_doctype_list-appl_type_text,
mimetype LIKE bdn_con-mimetype,
docuclass LIKE bdn_con-docuclass,
END OF ole_apps_struc.
DATA: ole_apps TYPE ole_apps_struc OCCURS 5.

PARAMETERS: p_class LIKE bdn_con-classname OBLIGATORY,
p_objct LIKE bdn_con-objkey OBLIGATORY.


start-of-selection.
classname_select = p_class.
classtype_select = 'OT'.
objkey_select = p_objct.
PERFORM f_bds_call_navigator.

at line-selection.
PERFORM f_line_selection.


FORM f_bds_call_navigator.
* Function : BDS_CALL_NAVIGATOR
* -- data declaration -- *
DATA: i_connections LIKE bdn_con OCCURS 0 WITH HEADER LINE,
calling_signa LIKE bapisignat OCCURS 0 WITH HEADER LINE,
i_count LIKE sy-index,
i_gui_type LIKE bapibds01-type,
web_excluding LIKE bdn_fkt OCCURS 1 WITH HEADER LINE.

* -- get all connections for the objtype/objkey -- *
CALL FUNCTION 'BDS_ALL_CONNECTIONS_GET'
EXPORTING
logical_system = logical_system
classname = classname_select
classtype = classtype_select
objkey = objkey_select
client = sy-mandt
all = ' ' " <- get the newest version
IMPORTING
count = i_count
TABLES
signature = signature
all_connections = i_connections
* framework = framework
* -- Begin correction 388230 ------------------------------ *
* EXCEPTIONS
* no_objects_found = 1
* error_kpro = 2
* internal_error = 3
* OTHERS = 4.
* IF sy-subrc > 1.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
* RAISING internal_error.
* ENDIF.
EXCEPTIONS
no_objects_found = 1
error_kpro = 2
internal_error = 3
not_authorized = 4
OTHERS = 5.
*End Function : BDS_CALL_NAVIGATOR

*Function : BDS_DISPLAY_LIST_VIA_TREE
* -- get some text fields -- *
DATA:
i_toasp LIKE toasp OCCURS 1 WITH HEADER LINE,
i_toasd LIKE toasd OCCURS 1 WITH HEADER LINE,
i_toasr LIKE toasr OCCURS 1 WITH HEADER LINE,
class_text like tojtt-ntext
.
SELECT * FROM toasp INTO TABLE i_toasp WHERE language = sy-langu.
SELECT * FROM toasd INTO TABLE i_toasd WHERE language = sy-langu.
SELECT * FROM toasr INTO TABLE i_toasr WHERE language = sy-langu.
APPEND LINES OF i_connections TO i_bds_conn.
LOOP AT i_bds_conn.
IF i_bds_conn-doc_type <> space. " -> Corr. (402788) A.M.
READ TABLE i_toasp WITH KEY ar_object = i_bds_conn-doc_type.
IF sy-subrc = 0.
i_bds_conn-objecttext = i_toasp-objecttext.
ENDIF.
ENDIF. " -> Corr. (402788) A.M.
READ TABLE i_toasr WITH KEY archiv_id = i_bds_conn-contrep.
IF sy-subrc = 0.
i_bds_conn-objecttext3 = i_toasr-objecttext.
ENDIF.
IF i_bds_conn-docuclass <> space.
READ TABLE i_toasd WITH KEY doc_type = i_bds_conn-docuclass.
IF sy-subrc = 0.
i_bds_conn-objecttext2 = i_toasd-objecttext.
ENDIF.
ENDIF.

i_bds_conn-ntext = class_text.

MODIFY i_bds_conn.
ENDLOOP.

*End Function : BDS_DISPLAY_LIST_VIA_TREE
skip.
LOOP AT i_bds_conn.
d_tabix = sy-tabix.
HIDE d_tabix.
WRITE : / i_bds_conn-BDN_TAB_I,
i_bds_conn-descript,
(50) i_bds_conn-comp_id,
i_bds_conn-objecttext,
i_bds_conn-objecttext2,
i_bds_conn-objecttext3,
i_bds_conn-ntext.

ENDLOOP.
CLEAR d_tabix.

EXIT.

PERFORM f_get_registered_doc_types.
*Program: LBDS_TOOLSF01, Form: display_selected_document
MOVE-CORRESPONDING i_bds_conn TO display_struc.
* -- find ole2_app -- *
build_all = ' '.
PERFORM get_ole2_app2 TABLES descr_list
USING display_struc-docuclass
display_struc-mimetype
ole2_app i_ole2_app_text
build_all.


ENDFORM. "f_bds_call_navigator
*&---------------------------------------------------------------------*
*& Form display_selected_document_out
*&---------------------------------------------------------------------*
* display selected document NOT in-place.
*----------------------------------------------------------------------*
FORM display_selected_document_out
TABLES display_struc STRUCTURE i_bds_conn.

* -- data declaration -- *
DATA: display_signature LIKE bapisignat OCCURS 5 WITH HEADER LINE.
* -------------------------------------------------------------------- *

CLEAR: display_signature.
REFRESH: display_signature.

READ TABLE display_struc INDEX 1.

display_signature-doc_count = '1'.
display_signature-doc_id = display_struc-loio_id.
display_signature-doc_ver_no = display_struc-doc_ver_no.
display_signature-doc_var_id = display_struc-doc_var_id.
display_signature-doc_var_tg = display_struc-doc_var_tg.
APPEND display_signature.

CALL FUNCTION 'BDS_OBJECT_DISPLAY_INTERN'
EXPORTING
logical_system = display_struc-log_system
classname = display_struc-classname
classtype = display_struc-classtype
client = display_struc-client
object_key = display_struc-objkey
bds_docid = display_struc-bds_docid
bds_contrep = display_struc-contrep
bds_docuclass = display_struc-docuclass
TABLES
signature = display_signature
EXCEPTIONS
error_kpro = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.


ENDFORM. " display_selected_document_out

*&---------------------------------------------------------------------*
*& Form GET_OLE2_APP2
*&---------------------------------------------------------------------*
* Get the correct OLE-App.
*----------------------------------------------------------------------*
FORM get_ole2_app2 TABLES descr_list
USING i_docuclass LIKE bdn_con-docuclass
i_mimetype LIKE bdn_con-mimetype
ole2_app LIKE toadd-appl_type
ole2_app_text LIKE bds_doctype_list-appl_type_text
build_all LIKE bdn_con-stor_tab.
* -- Data declaration ------------------------------------------------ *
TYPES: BEGIN OF document_type_descr,
document_type(70) TYPE c,
type_full_name(70) TYPE c,
type_short_name(20) TYPE c,
application_name(50) TYPE c,
supported_interfaces(256) TYPE c,
available(1) TYPE c,
END OF document_type_descr.

DATA: i_ole2_app TYPE toadd OCCURS 1 WITH HEADER LINE,
descr_list_struc TYPE document_type_descr,
local_langu LIKE sy-langu,
ole_apps_line TYPE ole_apps_struc,
temp_mimetype LIKE bdn_con-mimetype.

* -- Initilize Data -------------------------------------------------- *
local_langu = sy-langu.
* -------------------------------------------------------------------- *

IF build_all = ' '. " -> get a special ole_type
SET LOCALE LANGUAGE local_langu.
TRANSLATE i_mimetype TO LOWER CASE.
SET LOCALE LANGUAGE space.

IF i_docuclass <> space.
SELECT * INTO TABLE i_ole2_app FROM toadd
WHERE doc_type = i_docuclass.
temp_mimetype = i_mimetype.
i_mimetype = space.
ELSEIF i_mimetype <> space.
SELECT * INTO TABLE i_ole2_app FROM toadd
WHERE mimetype = i_mimetype.
i_docuclass = space.
temp_mimetype = i_mimetype.
ENDIF.
CLEAR i_ole2_app.
LOOP AT i_ole2_app.
IF i_ole2_app-appl_type <> space.
IF ( i_ole2_app-appl_type = 'EAIWEB.WEBVIEWER2D' OR
i_ole2_app-appl_type = 'EAIWEB.WEBVIEWER3D' OR
i_ole2_app-appl_type = 'SAPHTML' ).
ole2_app = i_ole2_app-appl_type.
i_mimetype = temp_mimetype.
EXIT.
ENDIF.
LOOP AT descr_list INTO descr_list_struc.
SET LOCALE LANGUAGE local_langu.
TRANSLATE descr_list_struc-document_type TO UPPER CASE.
SET LOCALE LANGUAGE space.
IF i_ole2_app-appl_type = descr_list_struc-document_type.
ole2_app = i_ole2_app-appl_type.
ole2_app_text = descr_list_struc-application_name.
i_docuclass = i_ole2_app-doc_type.
i_mimetype = i_ole2_app-mimetype.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
ole2_app = space.
ole2_app_text = space.
i_mimetype = i_ole2_app-mimetype.
i_docuclass = i_ole2_app-doc_type.
EXIT.
ENDIF.
ENDLOOP.
ELSE. " -> get the complete list
CLEAR i_ole2_app.
SELECT * INTO TABLE i_ole2_app FROM toadd.
LOOP AT i_ole2_app.
IF ( i_ole2_app-appl_type <> space AND
i_ole2_app-appl_type <> 'ACROEXCH.DOCUMENT' ). "#EC NOTEXT
LOOP AT descr_list INTO descr_list_struc.
SET LOCALE LANGUAGE local_langu.
TRANSLATE descr_list_struc-document_type TO UPPER CASE.
SET LOCALE LANGUAGE space.
IF i_ole2_app-appl_type = descr_list_struc-document_type.
ole_apps_line-appl_type = i_ole2_app-appl_type.
ole_apps_line-appl_type_text =
descr_list_struc-application_name.
ole_apps_line-docuclass = i_ole2_app-doc_type.
ole_apps_line-mimetype = i_ole2_app-mimetype.
APPEND ole_apps_line TO ole_apps.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.

SORT ole_apps BY appl_type.
DELETE ADJACENT DUPLICATES FROM ole_apps COMPARING appl_type.

ENDIF.

ENDFORM. " GET_OLE2_APP2
*&---------------------------------------------------------------------*
*& Form f_get_registered_doc_types
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_get_registered_doc_types.
if application_cntl is initial.
* -- Create Container Control -- *
call method c_oi_ole_control_creator=>get_ole_container_control
importing
control = application_cntl
retcode = retcode.

if retcode <> c_oi_errors=>ret_ok.
call method c_oi_errors=>show_message
exporting
type = 'E'.
endif.

call method application_cntl->get_registered_doc_types
exporting
interface_type = ' '
importing
descr_list = descr_list
retcode = retcode.

if retcode <> c_oi_errors=>ret_ok.
call method c_oi_errors=>show_message
exporting
type = 'E'.
endif.

endif.
ENDFORM. " f_get_registered_doc_types
*&---------------------------------------------------------------------*
*& Form f_line_selection
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_line_selection.
READ TABLE i_bds_conn INDEX d_tabix.
CHECK sy-subrc = 0.
MOVE-CORRESPONDING i_bds_conn TO display_struc.

PERFORM display_selected_document_out TABLES display_struc.


CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
IF sy-subrc <> 0.
MESSAGE e324(sbds).
ELSE.
WRITE :/ 'success'.
ENDIF.

ENDFORM. " f_line_selection

Read More......

Thursday, July 19, 2007

Store Document / File to SAP

To store document / image in SAP, we can use Business Document Navigator.
To go to the Business Document Navigator, choose Office -> Business Documents -> Documents -> Find (transaction code : OAOR).

In the upper part of the screen, the relevant documents, sorted by document type (the document types in turn belong to specified application objects) are displayed in the tree. The lower left part of the screen contains tab pages with the functions Detailed display, Document information (version string), Keywords and Storing. On the right-hand side of the screen, you can display a selected document in-place.

A bundled document structured by Class Name, Class Type and object Key. We can add additional attributes for document, including key word, title, description.

To save and get file programmatically, here are the codes.

I split them into two program, store document and get document. Program to get and display document can be found in next post.
Program to store document:


REPORT ZAALGAL0002 NO STANDARD PAGE HEADING.
* Store document in BDN

* -- connection table and the internal structure of the ITAB
DATA: BEGIN OF i_bds_conn OCCURS 10. " ITAB for the actual
INCLUDE STRUCTURE bdn_con. " document
DATA: objecttext LIKE toasp-objecttext,
objecttext2 LIKE toasd-objecttext,
objecttext3 LIKE toasr-objecttext,
ntext LIKE tojtt-ntext,
END OF i_bds_conn.
DATA: BEGIN OF bds_doctype_list OCCURS 10,
mandt TYPE mandt,
classname LIKE bapibds01-classname,
contrep LIKE i_bds_conn-contrep,
docuclass LIKE i_bds_conn-docuclass,
docuclass_text LIKE toasd-objecttext,
doc_type LIKE i_bds_conn-doc_type,
doc_type_text LIKE toasp-objecttext,
appl_type LIKE toadd-appl_type,
appl_type_text(50) TYPE c,
standard LIKE toadv-standard,
check_box LIKE toadv-standard,
END OF bds_doctype_list.
DATA: file_extension LIKE toadd-doc_type, " file-extension
i_files LIKE bapifiles OCCURS 1 WITH HEADER LINE,
i_signature LIKE bapisignat OCCURS 1 WITH HEADER LINE,
logical_system LIKE bds_conn00-log_system.

PARAMETERS: p_class LIKE bdn_con-classname OBLIGATORY,
p_objct LIKE bdn_con-objkey OBLIGATORY,
p_descr LIKE bdn_con-descript OBLIGATORY.

start-of-selection.

PERFORM create_doc_via_file.

*&---------------------------------------------------------------------*
*& Form CREATE_DOC_VIA_FILE
*&---------------------------------------------------------------------*
* create a new document via file
*----------------------------------------------------------------------*
FORM create_doc_via_file.
* -- data declaration ------------------------------------------------ *
DATA: classname_select LIKE bdn_con-classname,
classtype_select LIKE bdn_con-classtype,
objkey_select LIKE bdn_con-objkey,
mask(20) TYPE c,
answer TYPE c,
mimetype LIKE toadd-mimetype,
i_toadd LIKE toadd,
filename_all LIKE sapb-sapfiles,
file_path LIKE sapb-sapfiles,
file_path_memory(250) TYPE c, " path für SAP memory
file_path_length TYPE i, " length of the file_path
file_name LIKE sapb-sapfiles.


classname_select = p_class.
classtype_select = 'OT'.
objkey_select = p_objct.


GET PARAMETER ID 'OAP' FIELD file_path.
IF sy-subrc <> 0. " no file_path found.
file_path = space.
ENDIF.

CONCATENATE ',*.' '*' ',*.' '*' '.' INTO mask.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = file_path
mask = mask
mode = 'O'
title = 'Select File to upload'
IMPORTING
filename = filename_all
EXCEPTIONS
inv_winsys = 01
no_batch = 02
selection_cancel = 03
selection_error = 04.

IF sy-subrc = 3.
MESSAGE s012(sbds). " cancel file selection
EXIT.
ELSEIF sy-subrc <> 0 AND sy-subrc <> 3.
MESSAGE e011(sbds). " error during file selection
ENDIF.

* -- split filename -- *
PERFORM split_path(oaall) USING filename_all file_path file_name.

* -- set new file_path to SAP memory -- *
file_path_length = strlen( file_path ).

IF file_path <> space AND file_path_length < 250.
file_path_memory = file_path.
SET PARAMETER ID 'OAP' FIELD file_path_memory.
ELSE.
file_path_memory = space.
SET PARAMETER ID 'OAP' FIELD file_path_memory.
ENDIF.

* -- check documentclass -- *
PERFORM get_file_extension USING file_name
file_extension.

* -- check file extension -- *
IF file_extension = space.
* -> if no docuclass is found from the document
* -> default docuclass from the doctype!
file_extension = bds_doctype_list-docuclass.
ENDIF.

* -- get the mimetype of the docuclass -- *
PERFORM mimetype_get(oaall) USING file_extension
CHANGING i_toadd.
MOVE i_toadd-mimetype TO mimetype.

* -- fill file and signature structure -- *
CLEAR: i_files, i_signature.
REFRESH : i_files, i_signature.

i_files-doc_count = 1.
i_files-directory = file_path.
i_files-filename = file_name.
i_files-mimetype = mimetype.
APPEND i_files.

i_signature-doc_count = 1.
i_signature-prop_name = 'BDS_DOCUMENTCLASS'.
i_signature-prop_value = file_extension.
APPEND i_signature.
i_signature-prop_name = 'BDS_CONTREP'.
IF bds_doctype_list-contrep = space.
i_signature-prop_value = ' '. "#EC NOTEXT
ELSE.
i_signature-prop_value = bds_doctype_list-contrep.
ENDIF.
APPEND i_signature.
i_signature-prop_name = 'BDS_DOCUMENTTYPE'.
i_signature-prop_value = bds_doctype_list-doc_type.
APPEND i_signature.
i_signature-prop_name = 'DESCRIPTION'.
i_signature-prop_value = p_descr.
APPEND i_signature.
i_signature-prop_name = 'LANGUAGE'.
i_signature-prop_value = sy-langu.
APPEND i_signature.

* -- create new document via KPro -- *
CALL FUNCTION 'BDS_BUSINESSDOCUMENT_CREATEF'
EXPORTING
logical_system = logical_system
classname = classname_select
classtype = classtype_select
client = sy-mandt
object_key = objkey_select
TABLES
files = i_files
signature = i_signature
EXCEPTIONS
internal_error = 1
OTHERS = 2.

WRITE:/ 'sy-subrc:',sy-subrc.



ENDFORM. " CREATE_DOC_VIA_FILE
*&---------------------------------------------------------------------*
*& Form GET_FILE_EXTENSION
*&---------------------------------------------------------------------*
* try to get the extension of the uploaded file
*----------------------------------------------------------------------*
FORM get_file_extension USING file_name file_extension.
* -- data declaration ------------------------------------------------ *
DATA: length TYPE i,
single_c TYPE c.
* -------------------------------------------------------------------- *
CLEAR: single_c.

length = strlen( file_name ).
IF length > 0.
WHILE length > 0.
single_c = file_name+length(1).
IF single_c CO '.'.
length = length + 1.
EXIT.
ELSE.
length = length - 1.
ENDIF.
ENDWHILE.
IF length > 0.
file_extension = file_name+length.
ELSE.
file_extension = space.
ENDIF.
ELSE.
file_extension = space.
ENDIF.

IF file_extension <> space.
SET LOCALE LANGUAGE sy-langu.
TRANSLATE file_extension TO UPPER CASE. "#EC TRANSLANG
SET LOCALE LANGUAGE space.
ENDIF.

ENDFORM. " GET_FILE_EXTENSION

Read More......

Wednesday, July 18, 2007

Customizing SAP

If you want to be a SAP consultant, customizing will be a knowledge you must have.

Customizing covered following function:
1. Define Organization Structure
Example:
Business Area (Finance Accounting)
Maintain Storage Location (Material Management)
2. Maintain Master Data
Example:
-Define Customer Group (Sales and Distribution)
3. Rules:
-Define required entry in each module
4. Output Layout
-Define output layout

How to customize SAP

Go to TCode SPRO then click "SAP Reference IMG".
You will see tree of customizing Menu.
For example we want to maintain Sales Group, double click this menu from tree, you will see table maintenance view to maintain master data.



To have a competencies in customizing you must understand SAP business process.


Read More......

Tuesday, July 17, 2007

Step by step learning ABAP

ABAP stands for Advanced Business Applicatian Programming. The ABAP programming language was originally used by SAP developers to develop the SAP R/3 platform. It was also intended to be used by SAP customers to enhance SAP applications customers can develop custom reports and interfaces with ABAP programming. The language is fairly easy to learn for programmers but it is not a tool for direct use by non-programmers. Good programming skills, including knowledge of relational database design and preferably also of object-oriented concepts, are required to create ABAP programs.


If you are new to ABAP, there are 2 point you should learn first, in following order:
1. Explore Data Dictionary
Data dictionary is a workplace for defining table, define data type, display table content.
Go to transaction code SE11 (SAP Menu->Tools->ABAP Workbench->Development->Data Dictionary).
Then enjoy exploring data dictionary.
2. Create ABAP Report
Go to transaction code SE38 (SAP Menu->Tools->ABAP Workbench->Development->ABAP Editor), and try to write your first program.

Here are other useful links for beginner:
ABAP Overview in Wikipedia
Blog Series in SAP Developer Network

Read More......

Dynamic Table Maintenance

It is a good sample of how to create dynamic table maintenance by utilized SAP function module "STC1_FULLSCREEN_TABLE_CONTROL".
I copy this code from ITToolbox

You can use it to replace funtion of SM31 with additional benefit.
1. Because it is written in as customer program we can add additional feature, for example change history.
2. There is no need to create screen maintenance for all table because screen will automatically generated.

But, remember, this is only a demonstration of how to use STC1_FULLSCREEN_TABLE_CONTROL. Use it carefully and only for customer table (Z*).


Because there is difficulty in write "<" and ">" in blogger, I replace "<" with "{" and ">" with "}" in this sample code. Copy this sample code, then replace all "{" with "<" then replace all "}" with ">".


REPORT ZAALGAL002 NO STANDARD PAGE HEADING.

TYPE-POOLS: rsds.

DATA: is_x030l TYPE x030l,
it_dfies TYPE TABLE OF dfies,
is_dfies TYPE dfies,
it_fdiff TYPE TABLE OF field_dif,
is_fdiff TYPE field_dif.

DATA: w_selid TYPE rsdynsel-selid,
it_tables TYPE TABLE OF rsdstabs,
is_tables TYPE rsdstabs,
it_fields TYPE TABLE OF rsdsfields,
it_expr TYPE rsds_texpr,
it_ranges TYPE rsds_trange,
it_where TYPE rsds_twhere,
is_where TYPE rsds_where,
w_active TYPE i.

DATA: it_content TYPE REF TO data,
it_modif TYPE REF TO data,
it_fcat TYPE lvc_t_fcat.

DATA: w_okcode TYPE sy-ucomm.


FIELD-SYMBOLS: {itab} TYPE STANDARD TABLE,
{ntab} TYPE STANDARD TABLE.


* Macros
DEFINE table_error.
message e398(00) with 'Table' p_table &1.
END-OF-DEFINITION.

DEFINE fixed_val.
is_fdiff-fieldname = is_dfies-fieldname.
is_fdiff-fixed_val = &1.
is_fdiff-no_input = 'X'.
append is_fdiff to it_fdiff.
END-OF-DEFINITION.


* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: p_table TYPE tabname OBLIGATORY "table
MEMORY ID dtb
MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: BEGIN OF LINE,
PUSHBUTTON 33(20) selopt USER-COMMAND sel,
COMMENT 55(15) selcnt,
END OF LINE.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_rows TYPE i. "rows
SELECTION-SCREEN: END OF BLOCK b01,
SKIP,
BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: p_displ TYPE c AS CHECKBOX. "display
SELECTION-SCREEN: END OF BLOCK b02.

* Initialization
INITIALIZATION.
MOVE '@4G@ Filter records' TO selopt.

* PBO
AT SELECTION-SCREEN OUTPUT.
IF w_active IS INITIAL.
CLEAR: selcnt.
ELSE.
WRITE w_active TO selcnt LEFT-JUSTIFIED.
ENDIF.

* PAI
AT SELECTION-SCREEN.
IF p_table NE is_x030l-tabname.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
tabname = p_table
IMPORTING
x030l_wa = is_x030l
TABLES
dfies_tab = it_dfies
EXCEPTIONS
OTHERS = 1.
IF is_x030l IS INITIAL.
table_error 'does not exist or is not active'.
ELSEIF is_x030l-tabtype NE 'T'.
table_error 'is not selectable'.
ELSEIF is_x030l-align NE 0.
table_error 'has alignment - cannot continue'.
ENDIF.

* Default values for system fields
REFRESH: it_fdiff.
is_fdiff-tabname = p_table.
LOOP AT it_dfies INTO is_dfies.
IF is_dfies-datatype = 'CLNT'.
fixed_val sy-mandt.
ELSEIF is_dfies-rollname = 'ERDAT'
OR is_dfies-rollname = 'ERSDA'
OR is_dfies-rollname = 'AEDAT'
OR is_dfies-rollname = 'LAEDA'.
fixed_val sy-datum.
ELSEIF is_dfies-rollname = 'ERTIM'
OR is_dfies-rollname = 'AETIM'.
fixed_val sy-uzeit.
ELSEIF is_dfies-rollname = 'ERNAM'
OR is_dfies-rollname = 'AENAM'.
fixed_val sy-uname.
ENDIF.
ENDLOOP.

* Prepare free selection on table
REFRESH it_tables.
is_tables-prim_tab = p_table.
APPEND is_tables TO it_tables.

CLEAR: w_selid.
ENDIF.

IF sy-ucomm = 'SEL'.
IF w_selid IS INITIAL.
* Init free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = it_expr
IMPORTING
selection_id = w_selid
expressions = it_expr
TABLES
tables_tab = it_tables
EXCEPTIONS
OTHERS = 1.
ENDIF.

* Display free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = w_selid
title = 'Selection'
status = 1
as_window = 'X'
IMPORTING
expressions = it_expr
field_ranges = it_ranges
number_of_active_fields = w_active
TABLES
fields_tab = it_fields
EXCEPTIONS
OTHERS = 1.
ENDIF.


* Start of processing
START-OF-SELECTION.

PERFORM f_create_table USING p_table.

PERFORM f_select_table.

PERFORM f_display_table.


*---------------------------------------------------------------------*
* FORM f_create_table *
*---------------------------------------------------------------------*
FORM f_create_table USING in_tabname.

FIELD-SYMBOLS: {fcat> TYPE lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = in_tabname
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
* Complete field catalog
LOOP AT it_fcat ASSIGNING {fcat>.
{fcat>-tabname = in_tabname.
ENDLOOP.
CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
ELSE.
WRITE: 'Error building field catalog'.
STOP.
ENDIF.

* Create dynamic table for data
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_content.
IF sy-subrc = 0.
ASSIGN it_content->* TO {itab}.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.

* Create dynamic table for modif
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_modif.
IF sy-subrc = 0.
ASSIGN it_modif->* TO {ntab}.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
* FORM f_select_table *
*---------------------------------------------------------------------*
FORM f_select_table.

IF w_active = 0.
SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE {itab}
UP TO p_rows ROWS.
ELSE.
* Selection with parameters
CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
EXPORTING
field_ranges = it_ranges
IMPORTING
where_clauses = it_where.
READ TABLE it_where INTO is_where WITH KEY tablename = p_table.

SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE {itab}
UP TO p_rows ROWS
WHERE (is_where-where_tab).
ENDIF.

IF sy-dbcnt = 0.
WRITE: 'No record selected'.
STOP.
ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
* FORM f_display_table *
*---------------------------------------------------------------------*
FORM f_display_table.
DATA: l_answer TYPE c,
l_eflag TYPE c.

CLEAR: w_okcode.
REFRESH: {ntab}.
* Display table contents
CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
EXPORTING
header = p_table
tabname = p_table
display_only = p_displ
endless = 'X'
no_button = space
IMPORTING
okcode = w_okcode
TABLES
nametab = it_dfies
table = {itab}
fielddif = it_fdiff
modif_table = {ntab}
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
IF p_displ IS INITIAL AND w_okcode = 'SAVE'.
* Confirm update
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = p_table
text_question = 'Do you want to update table ?'
default_button = '2'
display_cancel_button = ' '
IMPORTING
answer = l_answer
EXCEPTIONS
OTHERS = 1.
IF l_answer = '1'.
* Apply modifications
IF NOT {ntab}[] IS INITIAL.
PERFORM f_add_system USING space.
MODIFY (p_table) FROM TABLE {ntab}.
IF sy-subrc NE 0.
l_eflag = 'X'.
ENDIF.
ENDIF.
* Apply deletions
IF l_eflag IS INITIAL.
REFRESH: {ntab}.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
deleted_data = {ntab}
EXCEPTIONS
OTHERS = 1.
IF NOT {ntab}[] IS INITIAL.
DELETE (p_table) FROM TABLE {ntab}.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
* Apply creations
IF l_eflag IS INITIAL.
REFRESH: {ntab}.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
new_data = {ntab}
EXCEPTIONS
OTHERS = 1.
IF NOT {ntab}[] IS INITIAL.
PERFORM f_add_system USING 'X'.
INSERT (p_table) FROM TABLE {ntab}.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
IF l_eflag IS INITIAL.
COMMIT WORK.
MESSAGE s261(53).
ELSE.
MESSAGE s075(3i).
PERFORM f_select_table.
ENDIF.
ENDIF.
* Display table again
PERFORM f_display_table.
ENDIF.
ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
* FORM f_add_system *
*---------------------------------------------------------------------*
FORM f_add_system USING new TYPE c.

FIELD-SYMBOLS: {irec} TYPE ANY,
{upd} TYPE ANY.

LOOP AT it_fdiff INTO is_fdiff.
READ TABLE it_dfies INTO is_dfies
WITH KEY fieldname = is_fdiff-fieldname.
LOOP AT {ntab} ASSIGNING {irec}.
ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE {irec} TO {upd}.
IF is_dfies-datatype = 'CLNT'.
{upd} = sy-mandt.
ELSE.
CASE is_dfies-rollname.
WHEN 'AENAM'.
{upd} = sy-uname.
WHEN 'AEDAT' OR 'LAEDA'.
{upd} = sy-datum.
WHEN 'AETIM'.
{upd} = sy-uzeit.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDLOOP.
ENDLOOP.

ENDFORM.


Read More......

FTP



SAP provide sample code to connect to FTP.

It provided in SAP function module, FTP_CONNECT (connect to FTP), FTP_COMMAND (send command by FTP), FTP_DISCONNECT (disconnect),FTP_R3_TO_SERVER (put file to FTP),FTP_SERVER_TO_R3 (get file from FTP).

Instead of writing a new code, I will try to give you explanation on SAP sample code.

I will explore program RSFTP002.


Program RSFTP002 demonstrate how to send command to FTP.



You can send any FTP command by this program.
For RFC destination use SAPFTP or SAPFTPA. Those are standard RFC destination to connect to FTP. SAPFTP run on client, and SAPFTPA run on application server.

First step of this program is using FTP_CONNECT, don't forget to use scrambled password.
Then we send a command to FTP by using FTP_COMMAND.
To disconnect, use FTP_DISCONNECT.

To copy, or get a file from SAP to/from FTP, you can explore RSFTP002. It demonstrate how to use FTP_R3_TO_SERVER (put file to FTP) & FTP_SERVER_TO_R3 (get file from FTP).
Other way is send put command using FTP_COMMAND. To put a file, do this steps, change FTP directory using "cd dir", change local directory using "lcd localdir", then send put command "put file".

Read More......

Simple ALV

ALV is very an useful tools in reporting. Just pass the data to ALV, than it will display interactive report easy to sort, filter, calculate total, etc.

There are two ALV model, list report (function REUSE_ALV_LIST_DISPLAY) and grid report (function REUSE_ALV_GRID_DISPLAY). Please read the function module documentation for complete guidance.

There are two main part of simple ALV report.
1. Create field catalog.
Field catalog containing descriptions of the list output fields.
2. Pass data and field catalog to ALV function (function REUSE_ALV_LIST_DISPLAY or REUSE_ALV_GRID_DISPLAY).

You can also playing with ALV format, find it in "Change Format in ALV".

This is a simple sample of how to use ALV.


REPORT ZAALGAL0001.
*-----------------------------------------
*Data declaration
TABLES: mara,
makt.

* Data output
DATA: BEGIN OF t_report OCCURS 3,
matnr LIKE mara-matnr,
mtart LIKE mara-mtart,
maktx LIKE makt-maktx,
END OF t_report.

* Field desciption / field catalog
TYPE-POOLS: SLIS.
data t_fcat type SLIS_T_FIELDCAT_ALV.

*-
DATA: d_repid LIKE sy-repid.

*-----------------------------------------
*--Selection Screen
SELECT-OPTIONS: s_matnr FOR mara-matnr,
s_mtart FOR mara-mtart.

*-----------------------------------------
START-OF-SELECTION.
*-Read data
SELECT * FROM mara
WHERE matnr IN s_matnr AND
mtart IN s_mtart.
CLEAR makt.
SELECT SINGLE *
FROM makt
WHERE matnr = mara-matnr AND
spras = sy-langu.
MOVE: mara-matnr TO t_report-matnr,
mara-mtart TO t_report-mtart,
makt-maktx TO t_report-maktx.
APPEND t_report.
ENDSELECT.

IF sy-subrc NE 0.
WRITE 'No data found'.
EXIT.
ENDIF.

*-----------------------------------------
*-Create Field Catalog

* Store report name
d_repid = sy-repid.

* Create Fieldcatalogue from internal table
* Use capital letter for I_INTERNAL_TABNAME
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = d_repid
I_INTERNAL_TABNAME = 'T_REPORT'
I_INCLNAME = d_repid
CHANGING
CT_FIELDCAT = t_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.

IF SY-SUBRC <> 0.
write: / 'Error:',sy-subrc,
'when Create Field Catalog'.
EXIT.
ENDIF.

* Call ALV List Display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = d_repid
IT_FIELDCAT = t_fcat
TABLES
T_OUTTAB = t_report
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

IF SY-SUBRC <> 0.
write: / 'Error:',sy-subrc,
'when Call ALV List Display'.
EXIT.
ENDIF.

Read More......

Processing Internal Tables

Internal Table is a main part of ABAP programming. In ABAP, internal tables fulfill the function of arrays. It is a data that have a structure and could contain more than one row.

Please refer to Data declaration for creating an internal table.

These are how to process internal table.

1. Sort Internal Table

SORT inttab BY field1 field2 ... field-n.

2. Loop At internal Table
LOOP AT inttab.
ENDLOOP.

3. Modify
3.1. Modify in a LOOP.
LOOP AT inttab.
MOVE ... TO inttab-field1.
MODIFY inttab.
ENDLOOP.

3.2. MODIFY BY index
MODIFY inttab INDEX int_index.

3.3. MODIFY BY condition
MODIFY inttab WHERE field1 = ....

4. Insert / Append
APPEND inttab.

5. Delete
Delete have variant similar to modify, delete in a loop, delete by index, and delete by criteria.

Read More......

Data Declaration

Declare single value variable:
Variable can be declared by two ways, first by declaring based on data type, second by declared it refer to table field.


Data d_data1 TYPE type. " berdasarkan type data
Data d_data2 LIKE customer-customerno. " refer ke field tertentu

Data types:
C (character)
N (numeric)
D (date)
T (Time)
X (byte / hexadecimal)
I (integer)
P (packed number)
F (floating point number)

Internal Table
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays.
DATA: BEGIN OF t_report OCCURS 10,
field1 LIKE customer-customerno,
field2 TYPE I,
field3(20) TYPE C,
END OF t_report.

In above example, we define internal table contatin 3 fields, field-1 refer to field customer-customerno, field-2 type Integer, field-3 type character with field length 10 character. OCCURS 10 means that it reserve 10 line of memory at initialization, in run time memory will expand automatically when data exceed the limit.

Read More......

Monday, July 16, 2007

my first ABAP program

No, it's not a "hello world" program ;p

One of main job of an ABAPer is create ABAP report.
Report content 4 basic component.
1. Data declaration.
2. Selection screen.
3. Select Data.
4. Write Report.


I assume you already familiar with data dictionary. For an example, we have a table "SFLIGHT", with following fields:
1. CARRID (Airline carrier ID)
2. CONNID (Flight connection Id)
3. FLDATE (Flight date).
4.SEATSMAX (Maximum capacity).
We wan to create a report that can be filtered based on Airline carrier ID and Flight connection Id.
Go to transaction code SE38 (SAP Menu->Tools>ABAP Workbench->Development->ABAP Editor), enter program name with prefix Z, for example ZTEST0001, then choose "Create" button.


Then, enter title for program, and choose 1 "Executable Program" for program type. If screen input for development class appear, click "Local Object".

Then, go to following steps.
1. Data declaration



TABLES: sflight.

DATA: BEGIN OF t_report OCCURS 3,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
END OF t_report.

2. Selection screen



SELECT-OPTIONS s_carrid FOR sflight-carrid.
SELECT-OPTIONS s_connid FOR sflight-connid.

It will generate selection screen like picture below.


3. Select data



SELECT * FROM sflight
WHERE carrid IN s_carrid AND
connid IN s_connid.
t_report-carrid = sflight-carrid.
t_report-connid = sflight-connid.
t_report-fldate = sflight-fldate.
t_report-seatsmax = sflight-seatsmax.
APPEND t_report.
ENDSELECT.
IF sy-subrc NE 0. "sy-subrc = return code
WRITE 'Data not found'.
ENDIF.

4. Write data



LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.

The result :


Here is the complete program:


REPORT ZTEST0001 .
*Data Declaration
tables: sflight.

DATA: BEGIN OF t_report OCCURS 3,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
END OF t_report.

*Selection Screen
SELECT-OPTIONS s_carrid FOR sflight-carrid.
SELECT-OPTIONS s_connid FOR sflight-connid.

*Get Data
SELECT * FROM sflight
WHERE carrid IN s_carrid AND
connid IN s_connid.
t_report-carrid = sflight-carrid.
t_report-connid = sflight-connid.
t_report-fldate = sflight-fldate.
t_report-seatsmax = sflight-seatsmax.
APPEND t_report.
ENDSELECT.
IF sy-subrc NE 0.
WRITE 'Data not found'.
ENDIF.

*Write Data
LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.

Read More......

Sunday, July 15, 2007

Data Dictionary

Data dictionary provide:
1. Table definition
2. Type definition

Data dictionary can be accessed by transaction code SE11. (SAP Menu->Tools->ABAP Workbench->Development->Data Dictionary).

Table definition.
Display table definition.Go to Transaction Code SE11, enter table name (example: SFLIGHT), click Display.

You can assign the data type, length and short text in different ways:
1. You directly assign the field a data type, field length (and if necessary decimal places) and short text in the table definition.
2. You can assign the field a data element. The data type, field length (and decimal places) are determined from the domain of the data element. The short description of the data element is assigned to the field as a short text. In above case, all fields refer to data element (Field CARRID refer to date element S_CARR_ID). We will explain about data element in Type Definition below.To toggle beetween data element / direct type method click button "Data Element/Direct type".
To display table content, click Utilities -> Table Contents -> Display, then click Execute (F8).
Type DefinitionWe can define type as reusable object. It means that when we create new table, we can create field refer to data element. These type attributes can either be defined directly in the data element or copied from a domain. Data element is an object where we put short text for field, and domain is an object where we store information like data type (CHAR, NUMC) and its length. We can see relation beetween table field, data element and domain in figure below.

Benefit of using this hierarchy is when you change domain, for example change field length, it will change all field length for all table using this domain.
To open a data element, go to TCode SE11, select data type, and enter data element name (for example S_CARR_ID). You will see in this screen that data element S_CARR_ID refer to domain S_CARR_ID ( in this case, data element and domain have a same name), and also display field label tab, it contain short text that appear in short text of table field.
To open a domain, go to TCode SE11, select domain, and enter domain name (for example S_CARR_ID), you will see that this domain have CHAR (character) data type and field length 3.

Read More......