工作生活与爱好

工作中的记录; 生活中的记忆; 业余爱好的记载。

2007-01-17

 

SAP的Selection屏幕的事件处理顺序

一、处理顺序图


二、处理说明

1、程序首先执行INITIALIZATION 事件;
2、接着执行AT SELECTION SCREEN OUTPUT事件(也就是PBO) ,在这个事件里你可以通过修改系统默认screen内表修改屏幕的某些属性;
PARAMETERS: TEST1(10) MODIF ID SC1,
TEST2(10) MODIF ID SC2,
TEST3(10) MODIF ID SC1,
TEST4(10) MODIF ID SC2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'SC1'.
SCREEN-INTENSIFIED = '1'.
MODIFY SCREEN.
CONTINUE.
ENDIF.
IF SCREEN-GROUP1 = 'SC2'.
SCREEN-INTENSIFIED = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

3、系统将屏幕输出到用户端,用户就可进行交互操作了。也就是PAI处理,其分为
3.1字段AT SELECTION-SCREEN ON XXXX.
REPORT EVENT_DEMO.
NODES SPFLI.
AT SELECTION-SCREEN ON CITY_FR.
IF CARRID-LOW EQ 'AA' AND CITY_FR NE 'NEW YORK'.
MESSAGE E010(HB).
ENDIF.
3.2区域AT SELECTION-SCREEN ON BLOCK XXXX.
REPORT EVENT_DEMO.
SELECTION-SCREEN BEGIN OF BLOCK PART1 WITH FRAME.
PARAMETERS: NUMBER1 TYPE I,
NUMBER2 TYPE I,
NUMBER3 TYPE I.
SELECTION-SCREEN END OF BLOCK PART1.

SELECTION-SCREEN BEGIN OF BLOCK PART2 WITH FRAME.
PARAMETERS: NUMBER4 TYPE I,
NUMBER5 TYPE I,
NUMBER6 TYPE I.
SELECTION-SCREEN END OF BLOCK PART2.

AT SELECTION-SCREEN ON BLOCK PART1.
IF NUMBER3 LT NUMBER2 OR
NUMBER3 LT NUMBER1 OR
NUMBER2 LT NUMBER1.
MESSAGE E020(HB).
ENDIF.

AT SELECTION-SCREEN ON BLOCK PART2.
IF NUMBER6 LT NUMBER5 OR
NUMBER6 LT NUMBER4 OR
NUMBER5 LT NUMBER4.
MESSAGE E030(HB).
ENDIF.

3.3屏幕AT SELECTION-SCREEN
在此事件里可以进行对用户输入进行完整性进行检查。
在PAI处理中出现错误,系统返回屏幕,请求用户重新输入;

4、当所有的PAI执行后,则进入START-OF-SELECTION事件的执行。


 

调用CALL TRANSACTION的三种方法

1.使用屏幕传入
REFRESH BDCDATA.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'SAPLCSDI'. "Programm St點kliste
BDCDATA-DYNPRO = '0100'. "Dynpro
BDCDATA-DYNBEGIN = 'X'. "Sofort starten
APPEND BDCDATA.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' "HW 81070
EXPORTING
INPUT = H_MATNR
IMPORTING
OUTPUT = H_MATNR
EXCEPTIONS
OTHERS = 0.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RC29N-MATNR'. "Material
BDCDATA-FVAL = H_MATNR.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RC29N-WERKS'. "Werks
BDCDATA-FVAL = H_WERKS.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RC29N-STLAN'. "Verwendung
BDCDATA-FVAL = H_STLAN.
APPEND BDCDATA.
*
** IF NOT H_STLAL IS INITIAL.
** CLEAR BDCDATA.
** BDCDATA-FNAM = 'RC29N-STLAL'. "Stl.Alternative
** BDCDATA-FVAL = H_STLAL.
** APPEND BDCDATA.
** ENDIF.
*
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'SAPLCSDI'. "Programm St點kliste
BDCDATA-DYNPRO = '0150'. "Dynpro
BDCDATA-DYNBEGIN = 'X'. "Sofort starten
APPEND BDCDATA.
* Umwandeln in Anzeigemodus 黚er BDC_OKCODE
CLEAR BDCDATA.
BDCDATA-FNAM = 'BDC_OKCODE'.
BDCDATA-FVAL = '/BDA'.
APPEND BDCDATA.
* Verzweig in St點klistenanzeige 黚er Batchinput-Tabelle
CALL TRANSACTION 'CS03' USING BDCDATA MODE 'E'.
2.使用parameter
SET PARAMETER ID 'MAT' FIELD P_MATNR.
SET PARAMETER ID 'WRK' FIELD P_WERKS.
SET PARAMETER ID 'CSV' FIELD P_STLAN.
CALL TRANSACTION 'CS03' AND SKIP FIRST SCREEN.
3.使用memory
data:
wfbomcom type rc29n.
move-corresponding bom_key to wfbomcom. "#EC ENHOK "note0526541
wfbomcom-aennr = display_aennr.
wfbomcom-datuv = display_datuv.
wfbomcom-datub = display_datub.
export wfbomcom to memory id 'WFBOMCOM'.
* display bom
call transaction 'CS03' and skip first screen.

 

如何使用自定义的 number range objects

1、Create number range object using OYSN.

2、Then call the following function modules.
FORM get_next_id CHANGING p_discrep.
DATA: last_id LIKE zrecaudit-discrep,
quant LIKE inri-quantity, "dummy
code LIKE inri-returncode. "returncode
CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
EXPORTING
object = 'ZRECAUDIT'
EXCEPTIONS
foreign_lock = 1
object_not_found = 2
system_failure = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'ZRECAUDIT'
IMPORTING
number = last_id
quantity = quant
returncode = code
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
OTHERS = 8.
CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
EXPORTING
object = 'ZRECAUDIT'
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
ENDIF.
ENDFORM. " get_next_id

 

如何限制SELECT-OPTIONS的选择屏幕的OPTION

REPORT Z_CONECT_A.
* Include type pool
 SSCRTYPE-POOLS sscr.
TABLES : marc.
*定义选择屏幕
select-options : s_matnr for marc-matnr,
s_werks for marc-werks.
* Define the object to be passed to the RESTRICTION 
parameterDATA restrict TYPE sscr_restrict.
* Auxiliary objects for filling RESTRICT
DATA : optlist TYPE sscr_opt_list,         
  ass type sscr_ass.INITIALIZATION.
* 限制MATNR参数只能使用‘EQ’ 和‘BT’. 
 optlist-name = 'OBJECTKEY1'.  
optlist-options-eq = 'X'.  
optlist-options-bt = 'X'. 
 APPEND optlist TO restrict-opt_list_tab. 
 ass-kind = 'S'. 
 ass-name = 'S_MATNR'. 
 ass-sg_main = 'I'. 
 ass-sg_addy = space.  
ass-op_main = 'OBJECTKEY1'. 
 APPEND ass TO restrict-ass_tab.
* 限制 WERKS 参数只能使用CP, GE, LT, NE. 
 optlist-name = 'OBJECTKEY2'. 
 optlist-options-cp = 'X'. 
 optlist-options-ge = 'X'.  
optlist-options-lt = 'X'. 
 optlist-options-ne = 'X'. 
 APPEND optlist TO restrict-opt_list_tab.
  ass-kind = 'S'.  
ass-name = 'S_WERKS'. 
 ass-sg_main = 'I'. 
 ass-sg_addy = space. 
 ass-op_main = 'OBJECTKEY2'.  
APPEND ass TO restrict-ass_tab. 
 CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'  
    EXPORTING    restriction                  = restrict  
     EXCEPTIONS     TOO_LATE                     = 1    
     REPEATED                     = 2     
     SELOPT_WITHOUT_OPTIONS       = 3    
     SELOPT_WITHOUT_SIGNS         = 4    
     INVALID_SIGN                 = 5    
     EMPTY_OPTION_LIST            = 6    
     INVALID_KIND                 = 7    
      REPEATED_KIND_A              = 8   
      OTHERS                       = 9            . 
     IF sy-subrc <> 0. 
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO       
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
 ENDIF.

 

获取sap系统用户出口列表 sap user exit

*&---------------------------------------------------------------------*
*& Report ZFIND_USER_EXIT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZFIND_USER_EXIT NO STANDARD PAGE HEADING.

*&---------------------------------------------------------------------*

*& Enter the transaction code that you want to search through in order
*& to find which Standard SAP User Exits exists.
*&

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Tables
*&---------------------------------------------------------------------*

TABLES : tstc, "SAP Transaction Codes
tadir, "Directory of Repository Objects
modsapt, "SAP Enhancements - Short Texts
modact, "Modifications
trdir, "System table TRDIR
tfdir, "Function Module
enlfdir, "Additional Attributes for Function Modules
tstct. "Transaction Code Texts

*&---------------------------------------------------------------------*
*& Variables
*&---------------------------------------------------------------------*

DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
DATA : field1(30).
DATA : v_devclass LIKE tadir-devclass.
*&---------------------------------------------------------------------*
*& Selection Screen Parameters
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK a01.

*&---------------------------------------------------------------------*
*& Start of main program
*&---------------------------------------------------------------------*

START-OF-SELECTION.

* Validate Transaction Code

SELECT SINGLE * FROM tstc
WHERE tcode EQ p_tcode.

* Find Repository Objects for transaction code

IF sy-subrc EQ 0.

SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'PROG'
AND obj_name = tstc-pgmna.

MOVE : tadir-devclass TO v_devclass.

IF sy-subrc NE 0.

SELECT SINGLE * FROM trdir
WHERE name = tstc-pgmna.

IF trdir-subc EQ 'F'.

SELECT SINGLE * FROM tfdir
WHERE pname = tstc-pgmna.

SELECT SINGLE * FROM enlfdir
WHERE funcname = tfdir-funcname.

SELECT SINGLE * FROM tadir
WHERE pgmid = 'R3TR'
AND object = 'FUGR'
AND obj_name = enlfdir-area.

MOVE : tadir-devclass TO v_devclass.

ENDIF.

ENDIF.

* Find SAP Modifactions

SELECT * FROM tadir
INTO TABLE jtab
WHERE pgmid = 'R3TR'
AND object = 'SMOD'
AND devclass = v_devclass.


SELECT SINGLE * FROM tstct
WHERE sprsl EQ sy-langu
AND tcode EQ p_tcode.

FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.

WRITE:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
SKIP.

IF NOT jtab[] IS INITIAL.

WRITE:/(95) sy-uline.

FORMAT COLOR COL_HEADING INTENSIFIED ON.

WRITE:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
WRITE:/(95) sy-uline.

LOOP AT jtab.

SELECT SINGLE * FROM modsapt
WHERE sprsl = sy-langu AND
name = jtab-obj_name.

FORMAT COLOR COL_NORMAL INTENSIFIED OFF.

WRITE:/1 sy-vline,
2 jtab-obj_name HOTSPOT ON,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.

ENDLOOP.

WRITE:/(95) sy-uline.

DESCRIBE TABLE jtab.

SKIP.

FORMAT COLOR COL_TOTAL INTENSIFIED ON.

WRITE:/ 'No of Exits:' , sy-tfill.

ELSE.

FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.

WRITE:/(95) 'No User Exit exists'.

ENDIF.

ELSE.

FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'Transaction Code Does Not Exist'.

ENDIF.

* Take the user to SMOD for the Exit that was selected.

AT LINE-SELECTION.

GET CURSOR FIELD field1.

CHECK field1(4) EQ 'JTAB'.

SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).

CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.

 

获取SAP表字段说明

REPORT ZGETTABLEFIELD .
* Data declaration
TYPE-POOLS: SLIS.

* Global structure of list
TYPES: BEGIN OF UD_STRUCT,
POSITION LIKE DD03L-POSITION,
TABNAME LIKE DD03L-TABNAME,
FIELDNAME LIKE DD03L-FIELDNAME,
DATATYPE LIKE DD03L-DATATYPE,
DDLENG LIKE DD03L-LENG,
DECIMALS LIKE DD03L-DECIMALS,
DDTEXT LIKE DD03T-DDTEXT,
EDDTEXT LIKE DD03T-DDTEXT,
DDDTEXT LIKE DD03T-DDTEXT,
END OF UD_STRUCT.

TABLES: DD03L.

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GT_OUTTAB TYPE UD_STRUCT OCCURS 0 WITH HEADER LINE.
DATA: G_REPID LIKE SY-REPID.
data : begin of exclude occurs 5,
fcode like sy-ucomm,
end of exclude.
DATA p_ucomm LIKE sy-ucomm.

PARAMETER P_TNAME LIKE DD02l-TABNAME DEFAULT 'VBAK'.

*======================================================================*
* Initialization fieldcatalog
*======================================================================*
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].


*======================================================================*
* Ereignis : AT SELECTION-SCREEN OUTPUT (PBO-Zeitpunkt) *
*======================================================================*
at selection-screen output.
data exclude like rsexfcode occurs 0 with header line.
if sy-dynnr = 1000.
call function 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = 'ZGETTBFD'
TABLES
p_exclude = exclude
EXCEPTIONS
others = 1.
endif.
p_ucomm = SPACE.

*======================================================================*
* Ereignis : AT SELECTION-SCREEN (PAI-Zeitpunkt) *
* letztes PAI-Ereignis *
*======================================================================*
at selection-screen.
p_ucomm = sy-ucomm.
CASE p_ucomm.
WHEN 'STBL'.
SET PARAMETER ID 'DTB' FIELD P_TNAME.
* PERFORM AUTHORITY_CHECK USING 'SE11' .
CALL TRANSACTION 'SE11' AND SKIP FIRST SCREEN.
ENDCASE.

*======================================================================*
* Data selection
*======================================================================*
START-OF-SELECTION.
PERFORM SELECT_DATA TABLES GT_OUTTAB.
perform function_exclude tables exclude.

*======================================================================*
* Display list
*======================================================================*
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = GT_FIELDCAT[]
TABLES
T_OUTTAB = GT_OUTTAB.
*-----------------------------------------------------------------------
* Forms
*-----------------------------------------------------------------------

* Initialization fieldcatalog

FORM FIELDCAT_INIT
USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: POS TYPE I VALUE 1.

clear ls_fieldcat.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'POSITION'.
ls_fieldcat-ref_fieldname = 'POSITION'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'TABNAME'.
ls_fieldcat-ref_fieldname = 'TABNAME'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
* LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'FIELDNAME'.
ls_fieldcat-ref_fieldname = 'FIELDNAME'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DATATYPE'.
ls_fieldcat-ref_fieldname = 'DATATYPE'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DDLENG'.
ls_fieldcat-ref_fieldname = 'LENG'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DECIMALS'.
ls_fieldcat-ref_fieldname = 'DECIMALS'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DDTEXT'.
ls_fieldcat-ref_fieldname = 'DDTEXT'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
* LS_FIELDCAT-NO_OUT = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
ENDFORM. "fieldcat_init


* Data selection
FORM SELECT_DATA
TABLES RT_OUTTAB LIKE GT_OUTTAB[].
SELECT DD03L~POSITION DD03L~TABNAME
DD03L~FIELDNAME DD03L~DATATYPE
DD03L~LENG DD03L~DECIMALS
DD03T~DDTEXT
DD04T~DDTEXT DD01T~DDTEXT
INTO (RT_OUTTAB-POSITION, RT_OUTTAB-TABNAME,
RT_OUTTAB-FIELDNAME, RT_OUTTAB-DATATYPE,
RT_OUTTAB-DDLENG, RT_OUTTAB-DECIMALS,
RT_OUTTAB-DDTEXT,
RT_OUTTAB-EDDTEXT,RT_OUTTAB-DDDTEXT)
FROM DD03L LEFT JOIN DD03T
ON DD03L~TABNAME = DD03T~TABNAME
AND DD03L~FIELDNAME = DD03T~FIELDNAME
AND DD03T~DDLANGUAGE = SY-LANGU
LEFT JOIN DD04T
ON DD03L~ROLLNAME = DD04T~ROLLNAME
AND DD04T~DDLANGUAGE = SY-LANGU
LEFT JOIN DD01T
ON DD03L~DOMNAME = DD01T~DOMNAME
AND DD01T~DDLANGUAGE = SY-LANGU
WHERE DD03L~TABNAME = P_TNAME
ORDER BY DD03L~POSITION.
IF RT_OUTTAB-DDTEXT = SPACE.
IF RT_OUTTAB-EDDTEXT = SPACE.
RT_OUTTAB-DDTEXT = RT_OUTTAB-DDDTEXT.
ELSE.
RT_OUTTAB-DDTEXT = RT_OUTTAB-EDDTEXT.
ENDIF.
ENDIF.
APPEND RT_OUTTAB.
ENDSELECT.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form FUNCTION_EXCLUDE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXCLUDE text *
*----------------------------------------------------------------------*
form function_exclude tables p_exclude structure exclude.
* data : rcode like sy-subrc.
* clear p_exclude.
* refresh p_exclude.
* exclude-fcode = 'EERW'.
* append exclude.
* exclude-fcode = 'EXIT'.
* append exclude.
endform. " FUNCTION_EXCLUDE


 

用户出口 user exit

什么叫用户出口呢?打个比方说吧,SAP软件就象一根晾衣服的绳子,上面有数不清的衣架,多数衣架上 已经挂上了衣服,就些衣服就SAP的标准程序,还有些衣架是空着的,这些就是“用户出口”,你可以把自己做的衣服(比如程序代码)挂到这些衣架上去--如 果你觉得SAP给你准备的衣服不够穿或者不合身的话。

使用用户出口可以:
-不影响标准SAP源代码
-不影响软件升级

SAP有四种基本用户出口的类型:
1.菜单出口-Menu Exits
定义自己的菜单
2.屏幕出口-Screen Exits
定义自己的屏幕
3.功能模块出口-Function Module Exits
在SAP应用程序中添加功能
4.关键字出口-Keyword Exits
在ABAP/4字典中的关键字数据元素添加文档。结果是你在使用这些数据元素的字段处按F1后会出现你自定义的说明文档

使用的方法是:首先定义(T-Code:CMOD)一个项目Project(以管理你的增强,这里的项目和PS模块的项目可是两回事),把你要使用的系统增加Enhancement分配给这个项目,编辑系统增强中的用户出口对象。

SAP的用户出口和其它模块不太一样,其他模块基本采用上面说到的系统增强方法,SD的子模块则是罗列了一大堆已经定义好的子程序(Include)--说实话,我比较喜欢这种方式,你可以直接在SE38中修改这些子程序,然后激活就可以了。

要编辑用户出口,你必须有开发的权限,另外,除了关键字出口外,其他的出口都需要你有一定的ABAP/4编程能力。

 

BDC技术

首先简单解释一下BDC(Batch Data Conversion):

在SAP系统里,由于某种原因,可能需要重复输入数据,(数据不同,但是操作是相同的,典型的情形就是切换系统的时候,旧系统的数据需要导入SAP),大致过程不外乎是这样: 输入一个t-code,
进入一个某个屏幕,然后输入一个值(有时还要加上一些附加的checkbox选项等),点执行或者确定按钮,
进入另一个屏幕,在某些字段输入值(也可能是标注checkbox选中或者不选中)或者修改这些字段里的值。
然后按“Eneter”……
最后按“SAVE”……,
一条记录完成了,继续下一条,如此循环。

上面所述的情形,如果让一个“人”来做的话,可能是真是受不了的。但是对于计算机来说,就很简单了。

SAP通过一个特殊的程序(T-code:SHDB)把用户的一次业务操作的所有过程记录下来。

从用户输入transaction code(事务代码),点下“Start Recording”开始,对于用户的来说是一次普通的业务操作,但是SAP却在记录:
1.光标放到哪个字段,(在程序中不用改变)
2.填入了什么值,(变量,循环中的Internal Table 某个字段)
3.点击了什么按钮(在程序中不用改变)

本次操作的作为一个“代表”,是一个“模板”,告诉SAP系统以怎样的方式来执行程序,也就是用计算机的语言来描述如果手工操作的话应该是怎样的一个过程。


用BDC技术编程时,有以下几个步骤:
1.把外部的数据源(Txt,Excel等)用读进internal table或者用do enddo循环。
2.在循环里,把用SHDB记录的步骤重复执行N次,(N = Dialog屏幕数量)这时实际上并没行完成数据的入,系统只是在“填表”,填一个叫做“BDCData”的Internal Table。
填 完bdcdata以后,用call transaction ‘XXXX’ using bdc……这个命令来真正的commit动作或者call function 'BDC_Insert'在建立一个session。并把执行的结果返回给messtab这个Internal Table

现在假想一种情境,来做一个演示的BDC程序。
由于业务上的需要,某公司打算将某些物料的描述都在后面加上指定的文本Group X,所以需要修改已经存在的物料数据,用T-code:MM02,

外部数据是TXT文本,记录有N条,如下:

Material NO. Description
6000-00001 XXXXXXX(Group A)
2098-00001 fdfladsfladfl(Group B )
2059-00009 dfdsfreddfalfasfa(Group A)
2003-00003 iadfdafdf,adfasf(Group D)
……
……
下面是“录”操作的过程,在命令栏里输入T-code :SHDB,进入如下屏幕:

点New Recodring,出现如下屏幕:

其中Recording 的名字是任意给的。MM02是需要录的事务代码。

按下“Start Recording”,就会进入“Change Material”,这时,以下的操作对于用户来说是一次普通修改物料描述操作,尽管系统在记录所有的操作。


输入一个物料后,点击“Select View(s)”

假设我们只选“Basic Data 1”和“Basic Data 1”
然后点击绿色的小勾“Enter”

我们在该物料后面添加一个“Group A”,描述改为:


……

然后点“SAVE”,保存这次修改。

现在SAP回到了SHDB,

先点“SAVE”,保存Recording :Ztest,然后点”Back”,返回SHDB的第一屏。

选中“Ztest”,然后点击“Program”,由SAP自动生成一个程序。


在上面的对话框中输入程序的名字(注意SAP的命名规范,Y或者Z开头),确认输入

再输入一些程序的属性信息如下:

点击“Source Code”,指定“Develop Class”等后,就可以进入ABAP Editor,产生如下代码:

report ZBDCTEST
no standard page heading line-size 255.

include bdcrecx1.

parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: MATNR
MATNR_001(018),
* data element: XFELD
KZSEL_01_002(001),
* data element: XFELD
KZSEL_02_003(001),
* data element: MAKTX
MAKTX_004(040),
* data element: MEINS
MEINS_005(003),
* data element: MTPOS_MARA
MTPOS_MARA_006(004),
* data element: GEWEI
GEWEI_007(003),
end of record.

*** End generated data section ***

start-of-selection.

perform open_dataset using dataset.
perform open_group.

do.

read dataset dataset into record.
if sy-subrc <> 0. exit. endif.

perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'=AUSW'.
perform



 

调用SAP的单位转换函数进行单位转换

report Zrsbzme10 .
parameters: p_In(10) type c,
unit_in like t006-msehi default 'M',
unit_out like t006-msehi default 'MM',
round(1) type c default 'X'.
data: result type p decimals 3,
input type p decimals 3.
input = p_IN.
call function 'UNIT_CONVERSION_SIMPLE'
exporting
input = input
round_sign = round
unit_in = unit_in
unit_out = unit_out
importing
output = result
exceptions
conversion_not_found = 01
division_by_zero = 02
input_invalid = 03
output_invalid = 04
overflow = 05
units_missing = 06
unit_in_not_found = 07
unit_out_not_found = 08.
write: 'Result: ',result.

 

How to Get Name of Months in ABAP/4

1 使用数据表 ’T247’
DATA: it_month_name TYPE TABLE OF t247 WITH HEADER LINE.
SELECT * INTO TABLE it_month_name FROM T247
WHERE spras = sy-langu.

2 使用函数’MONTH_NAMES_GET’
DATA: it_month_name TYPE TABLE OF t247 WITH HEADER LINE.
CALL FUNCTION ’MONTH_NAMES_GET’
EXPORTING
LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
TABLES
MONTH_NAMES = it_month_name
EXCEPTIONS
MONTH_NAMES_NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


 

创建动态内表

REPORT zg_dynamic_ex LINE-SIZE 300.
TYPE-POOLS: abap.
FIELD-SYMBOLS: TYPE STANDARD TABLE,
,
.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
*&--------------------------------------------------------------------*
*& Form get_structure
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM get_structure.
DATA: idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA: ref_table_des TYPE REF TO cl_abap_structdescr.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name.
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
*&--------------------------------------------------------------------*
*& Form create_dynamic_itab
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM create_dynamic_itab.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO .
CREATE DATA dy_line LIKE LINE OF .
ASSIGN dy_line->* TO .
ENDFORM. "create_dynamic_itab
*&--------------------------------------------------------------------*
*& Form get_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM get_data.
SELECT * INTO TABLE FROM (p_table).
ENDFORM. "get_data
*&--------------------------------------------------------------------*
*& Form write_out
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM write_out.
LOOP AT INTO .
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE TO .
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ .
ELSE.
WRITE: .
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out

 

常用的Function Module

Indeed these powerful ABAP/4 functions are very interesting and can bring some advantages. Improve your home development easily. They belong to standard objects and should never be changed.

Note:

These functions have been used and have worked as well as they were supposed to do.


 

关于SAP的TABLEVIEW编程的几个重要变量值的变化列表

SAP的TC控件编程的几个重要变量值说明

BPO内

BPO外

PAI内

PAI外

sy-stepl 从1计,每次循环自动加1 0 从1计,每次循环自动加1 0
sy-loopc tableview可显示最大记录数(自动) 0 tableview可显示最大记录数(自动) 0
top_line 起始值为循环外的top_line值,每次循环自动加1,结束置回原值 最上一行对应记录号 新的top_line,值不变 最上一行对应记录号 (新)
cuurent_line 起始值为循环外的top_line值,每次循环自动加1 最下一行对应记录号 置为上一个BPO外的top_line值 最下一行对应记录号 (新)
lines 需要显示的记录总数,一般设为内表的记录数

 

常见的abap面试题目,请大家对照学习

1. What is the typical structure of an ABAP program?

2. What are field symbols and field groups.? Have you used "component idx of structure" clause with field groups?

3. What should be the approach for writing a BDC program?

4. What is a batch input session?

5. What is the alternative to batch input session?

6. A situation: An ABAP program creates a batch input session. We need to submit the program and the batch session in background. How to do it?

7. What is the difference between a pool table and a transparent table and how they are stored at the database level?

8. What are the problems in processing batch input sessions? How is batch input process different from processing on line?

9. What do you define in the domain and data element?

10. What are the different types of data dictionary objects?

11. How many types of tables exists and what are they in data dictionary?

12. What is the step by step process to create a table in data dictionary?

13. Can a transparent table exist in data dictionary but not in the data base physically?

14. What are the domains and data elements?

15. Can you create a table with fields not referring to data elements?

16. What is the advantage of structures? How do you use them in the ABAP programs?

17. What does an extract statement do in the ABAP program?
18. What is a collect statement? How is it different from append?
19. What is open sql vs native sql?
20. What does an EXEC SQL stmt do in ABAP? What is the disadvantage of using it?
21. What is the meaning of ABAP editor integrated with ABAP data dictionary?
22. What are the events in ABAP language?
23. What is an interactive report? What is the obvious diff of such report compared with classical type reports?
24. What is a drill down report?
25. How do you write a function module in SAP? describe.
26. What are the exceptions in function module?
27. What is a function group?
28. How are the date abd time field values stored in SAP?
29. What are the fields in a BDC_Tab Table.
30. Name a few data dictionary objects?
31. What happens when a table is activated in DD?
32. What is a check table and what is a value table?
33. What are match codes? describe?
34. What transactions do you use for data analysis?
35. What is table maintenance generator?
36. What are ranges? What are number ranges?
37. What are select options and what is the diff from parameters?
38. How do you validate the selection criteria of a report? And how do you display initial values in a selection screen?

39. What are selection texts?
40. What is CTS and what do you know about it?
41. When a program is created and need to be transported to prodn does selection texts always go with it? if not how do you make sure? Can you change the CTS entries? How do you do it?
42. What is the client concept in SAP? What is the meaning of client independent?
43. Are programs client dependent?
44. Name a few system global variables you can use in ABAP programs?
45. What are internal tables? How do you get the number of lines in an internal table? How to use a specific number occurs statement?

46. How do you take care of performance issues in your ABAP programs?
47. What are datasets?
48. How to find the return code of a stmt in ABAP programs?
49. What are interface/conversion programs in SAP?
50. Have you used SAP supplied programs to load master data?
51. What are the techniques involved in using SAP supplied programs? Do you prefer to write your own programs to load master data? Why?

52. What are logical databases? What are the advantages/disadvantages of logical databases?

53. What specific statements do you using when writing a drill down report?
54. What are different tools to report data in SAP? What all have you used?
55. What are the advantages and disadvantages of ABAP query tool?
56. What are the functional areas? User groups? and how does ABAP query work in relation to these?
57. Is a logical database a requirement/must to write an ABAP query?
58. What is the structure of a BDC sessions.
59. What are Change header/detail tables? Have you used them?
60. What do you do when the system crashes in the middle of a BDC batch session?
61. What do you do with errors in BDC batch sessions?
62. How do you set up background jobs in SAP? What are the steps? What are the event driven batch jobs?
63. Is it possible to run host command from SAP environment? How do you run?
64. What kind of financial periods exist in SAP? What is the relavent table for that?
65. Does SAP handle multiple currencies? Multiple languages?
66. What is a currency factoring technique?
67. How do you document ABAP programs? Do you use program documentation menu option?
68. What is SAPscript and layout set?
69. What are the ABAP commands that link to a layout set?
70. What is output determination?
71. What are IDOCs?
72. What are screen painter? menu painter? Gui status? ..etc.
73. What is screen flow logic? What are the sections in it? Explain PAI and PBO.
74. Overall how do you write transaction programs in SAP?
75. Does SAP has a GUI screen painter or not? If yes what operating systems is it available on? What is the other type of screen painter called?
76. What are step loops? How do you program pagedown pageup in step loops?
77. Is ABAP a GUI language?
78. Normally how many and what files get created when a transaction program is written? What is the XXXXXTOP program?
79. What are the include programs?
80. Can you call a subroutine of one program from another program?
81. What are user exits? What is involved in writing them? What precations are needed?
82. What are RFCs? How do you write RFCs on SAP side?
83. What are the general naming conventions of ABAP programs?
84. How do you find if a logical database exists for your program requrements?
85. How do you find the tables to report from when the user just tell you the transaction he uses? And all the underlying data is from SAP structures?
86. How do you find the menu path for a given transaction in SAP?
87. What are the different modules of SAP?
88. What is IMG in SAP?
89. How do you get help in ABAP?
90. What are different ABAP editors? What are the differences?
91. What are the different elements in layout sets?
92. Can you use if then else, perform ..etc statements in sap script?
93. What type of variables normally used in sap script to output data?
94. How do you number pages in sapscript layout outputs?
95. What takes most time in SAP script programming?
96. How do you use tab sets in layout sets?
97. How do you backup sapscript layout sets? Can you download and upload? How?
98. What are presentation and application servers in SAP?
99. In an ABAP program how do you access data that exists on a presentation server vs on an application server?
100. What are different data types in ABAP?
101. What is difference between BDC and Call Transaction?
102. Setting up a BDC program where you find information from?
103. What has to be done to the packed fields before submitting to a BDC session.

Archives

1990年1月15日   2007年1月14日   2007年1月15日   2007年1月16日   2007年1月17日   2007年1月18日   2007年1月19日   2007年1月20日   2007年1月22日   2007年1月23日   2007年1月24日   2007年1月25日   2007年1月26日   2007年1月27日   2007年1月29日   2007年1月30日   2007年1月31日   2007年2月1日   2007年2月2日   2007年2月3日   2007年3月13日   2007年5月15日   2007年5月16日   2007年6月2日  

This page is powered by Blogger. Isn't yours?