Checklist for simpe dialog program
Create the program
Create a new program in the repository browser (Transaction SE80) . Name standard for dialog programs is SAPMZ
In the attributes window:
– Module pool = M
– Application = Z
Create the screen
Create a new screen.
Add a pushbutton to the screen
In the attributes screen for the pushbutton, enter a function code
in the FctCode field ( In this example: 0020 ).
When you create a screen, SAP automathic creates a field with the type OK. The function code of the psuhbutton will be placed here when you push the button. However you have to supply the name of the OK field ( In this example: OK_CODE ).
You must also create a global variable in the program, to store the value of the OK field ( See below ).
Create global variables
DATA:
* Global variable to store OK code
ok_code(4),
* Temporary store the value of the OK code
save_ok_code(4).
Create code for the screen
PROCESS BEFORE OUTPUT.
MODULE status_0001.
PROCESS AFTER INPUT.
MODULE user_command_0001.
MODULE status_0001 OUTPUT.
SET PF-STATUS ‘0001’.
SET TITLEBAR ‘001’.
* Example of how deactivate a field on the screen
* ZCOSTAFSTM-ZAFSTEMNR is the name of the screen field we want to
* deactivate.
LOOP AT SCREEN.
CHECK screen-name = ‘ZCOSTAFSTM-ZAFSTEMNR’.
screen-input = ‘0’.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
ENDMODULE.
MODULE user_command_0001 INPUT.
* Here you can catch when user pushes a pushbutton
* Save the OK code in save_ok_code and clear it
save_ok_code = ok_code.
CLEAR ok_code.
CASE save_ok_code.
WHEN ‘0010’.
* Afstemninger
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
PERFORM my_list.
WHEN ‘0020’.
CALL TRANSACTION ‘ZCO1’.
WHEN ‘RETU’.
LEAVE TO SCREEN ‘0000’.
ENDCASE.
ENDMODULE.
AT USER-COMMAND.
* Here you can catch when the user psuh a button on the menu bar or presses a function key
CASE sy-ucomm.
WHEN ‘OPRT’.
PERFORM something.
ENDCASE.
Other Useful Link :
change attributes of an item in a screen and in a table control at runtime
Hide a column in a table control at runtime
Create F4 help
Dialog Programming FAQ
Download Dialog programming Tutorial
Modify recording scenario
Open SQL syntax examples
Posted on: December 16, 2007
Working with single entries
select * from ska1
where saknr = ‘77004500’.
* Do something with data
move-corresponding ska1 to itab.
append itab.
endselect.
Reading all entries into an internal table
This is more efficient that example 1
select * from ska1 into table itab
where saknr like ‘77%’
order by saknr.
Reading single entries
You must specify the full primarykey in the where clause to get a correct result.
tables: zsd00004.
data l_custname like like zsd00004-zcustname.
SELECT SINGLE zcustname into l_custname FROM zsd00004
WHERE zcustno = ‘1551’.
Selecting single fields
This could improve effciency for database tables with many entries and many fields.
data: l_kunnr like kna1-kunnr,
l_kukla like kna1-kukla.
SELECT kunnr kukla
INTO (l_kunnr,l_kukla)
FROM kna1.
write: / l_kunnr, l_kukla.
ENDSELECT.
Append new record
Tables: zsd00003.
zsd00003-zprogram = g_screen0100-zprogram.
zsd00003-zstep = g_screen0100-zstep.
zsd00003-zenhed = g_screen0100-zenhed.
INSERT INTO zsd00003 VALUES zsd00003.
IF sy-subrc = 4.
SY-SUBRC = 0: Line inserted.
SY-SUBRC = 4: The line could not be inserted. A line with the same key
already existed.
Update with where clause
This statement updates the fields zlogdato and zlogtid for the records that
satisfies the where clause.
update zsd00003 set zlogdato = sy-datum
zlogtid = sy-uzeit
where zdriftscenter = g_screen0100-zdriftscenter.
For all entries
tables: mara, makt.
data: begin of i_material occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of i_material.
start-of-selection.
select matnr
appending corresponding fields of table i_material
from mara.
select matnr maktx
into corresponding fields of table i_material
from makt
for all entries in i_material
where matnr = i_material-matnr and
spras = sy-langu.
end-of-selection.
loop at i_material.
write: / i_material-matnr, i_material-maktx.
endloop.
JOINs in open SQL
INNER JOIN
One or more lines on the right-hand table is linked to a line in the
left-hand table. Lines from the left-handed table
is only selected if they meet the ON criteria.
FROM from vbak as a inner join vbap as b
ON b~vbeln = a~vbeln.
One or more lines from vbap is selected for each line in vbak.
Limits on the ON clause:
LEFT OUTER JOIN
The left outer join read lines from the left-handed table EVEN if there is
no corresponding line in the right hand table.
FROM vbak as a left outer join vbap as b
ON b~vbeln = a~vbeln.
If vbap does not contain any lines that meets the condition, a single line
where the values from vbap is filled with null values.
Example 1
SELECT a~zafstemnr b~zafstemnr b~zsaknr
INTO CORRESPONDING FIELDS OF TABLE i_tab
FROM zcostafstm as a INNER JOIN zcostplan as b
ON b~zafstemnr = a~zafstemnr.
Example 2
SELECT lips~vbeln lips~lfimg likp~wadat
INTO corresponding fields of table ltab_orders
FROM lips JOIN likp on ( lips~vbeln = likp~vbeln )
JOIN vbfa on ( lips~vbeln = vbfa~vbelv )
WHERE lips~matnr = matnr
and lips~vbeln in vbeln
and likp~vbeln in vbeln
and vbfa~vbelv in vbeln
and lips~werks in werks
and likp~wadat in datum
and vbfa~vbtyp_n = ‘Q’ “WMS transfer order
and vbfa~vbtyp_v = ‘J’. “Delivery
From ABAP hints & Tips: http://oasis.fortunecity.com/skegness/110/JOIN.html
Using IN in logical expressions and sql statements
It is possible to use a selection table if together with the IN operator.
Example:
* Selection table
DATA: BEGIN OF it_select_fkart OCCURS 0,
sign(1),
option(2),
low LIKE zsd00010-fkart,
high LIKE zsd00010-fkart,
END OF it_select_fkart.
* Build selection table
SELECT * FROM zsd00010
WHERE zaftaletype = ‘0/0’.
CLEAR it_select_fkart.
it_select_fkart-sign = ‘I’.
it_select_fkart-option = ‘EQ’.
it_select_fkart-low = zsd00010-fkart.
* it_select_fkart-high = . “Optional
APPEND it_select_fkart.
ENDSELECT.
* Select statement
SELECT vbeln
zuonr
kunag
fkart
fkdat
INTO CORRESPONDING FIELDS OF TABLE i_indlaes_vbrk
FROM vbrk
WHERE kunag IN s_kunag AND
fkart IN it_select_fkart.
endselect.
Using aggergate functions
SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = ‘D’ AND
ARBGB = ’00’.
Updating records in the database table from an internal table
table: personel.
data: itab like personel.
* Read records from the database table where name is space, into an internal table
select * from personal into table itab
where name = space.
* Update name in the internal table to Unknown
loop at itab.
itab-name = ‘Unknown’
endloop.
* Modify records in the database table. Only records with the same key values as then
* internal table is modified
MODIFY personel from table itab.
Updating a single entry
In this example the entry with the key value Customerno = 1 is changed.
table customer.
customer-customerno = 1.
customer-customnavme = ‘John’.
UPDATE customer.
if sy-subrc 0.
….. No entry with the customerno = 1, add error handling
endif.
Updating multiple entries
Examlpe updating the field zchecked to ‘X’
UPDATE zcostcheck set zchecked = ‘X’
WHERE zcostcheck-zaar = zaar and
zcostcheck-zmaaned = zmaaned and
zcostcheck-zbukrs = zbukrs and
zcostcheck-zsaknr = zsaknr2 and
zcostcheck-zgsber = zgsber.
Dynamic where clause
You can use an internal table to build a dynamic where clause:
data: where_tab(30) occurs 1 with header line,
where_clause(30) type c.
* Build the where clause. Will look like this when finished
* WHERE ZAFSTMD02 = ‘X’ AND rbusa = ‘5145’
* With a constant, result: ZAFSTMD01 = ‘X’
concatenate ‘ZAFSTMD’ zcostcheck-zmaaned ‘ = ”X”’ into where_clause.
* Append to internal table where_tab
append where_clause to where_tab.
* With a variable, result: AND rbusa = ‘5145’
concatenate ‘AND rbusa = ‘ ”” i_tab-zgsber ””
append where_clause to where_tab.
* Select
select * from zcostfreq
where (where_tab).
endselect.
Note that you can combine static and dynamic where clauses:
select * from zcostfreq
where bukrs = ‘2021’ AND
(where_tab).
endselect.
Using a dynamic table name
This report prints the number og entries in a table. The table name is specified by a parameter.
data:
l_count type i.
parameters:
p_tab type tabname.
start-of-selection.
select count(*) from (p_tab) into l_count.
write: / ‘Number of entries in table ‘, p_tab, l_count.
Dynamic retrieval and writing of data
In this example, data is retrieved from the table selected on the selection screen, and the contents of the table is written to the screen.
DATA:
* Create variable that can contain referecene to any data
dataref TYPE REF TO data.
FIELD-SYMBOLS:
TYPE ANY,
TYPE ANY.
PARAMETERS:
p_tab TYPE tabname.
START-OF-SELECTION.
* Create a workarea for the tabel selected on the selection screen
CREATE DATA dataref TYPE (p_tab).
* The variable dataref cannot be accessed directly, so a field symbol is
* used
ASSIGN dataref->* TO .
SELECT *
FROM (p_tab) UP TO 10 ROWS
INTO .
NEW-LINE.
DO.
* Write all the fields in the record
ASSIGN COMPONENT sy-index
OF STRUCTURE
TO .
IF sy-subrc 0.
EXIT.
ENDIF.
WRITE .
ENDDO.
ENDSELECT.
Dynamic SELECT
TYPES:
BEGIN OF st_bseg,
bukrs LIKE bseg-bukrs,
belnr LIKE bseg-belnr,
dmbtr LIKE bseg-dmbtr,
END OF st_bseg.
DATA:
sel_list TYPE STANDARD TABLE OF edpline,
li_bseg TYPE STANDARD TABLE OF st_bseg,
l_bseg TYPE st_bseg.
START-OF-SELECTION.
APPEND ‘bukrs belnr dmbtr’ TO sel_list.
SELECT (sel_list)
FROM bseg UP TO 100 ROWS
INTO TABLE li_bseg.
LOOP AT li_bseg INTO l_bseg.
WRITE : / l_bseg-bukrs, l_bseg-belnr, l_bseg-dmbtr.
ENDLOOP.
Dynamic programing can save a lot of ‘superfluous’ coding.
To assign a variable a type at runtime, use the ABAP statement ASSIGN with the option TYPE. For instance:
DATA: D_TYPE,
D_FIELD(35).
DATA: D_TEST TYPE P.
FIELD-SYMBOLS: .
D_FIELD = ‘D_TEST’.
D_TYPE = ‘P’.
ASSIGN (D_FIELD) TO TYPE D_TYPE.
Additionally you can use the option DECIMALS of the ASSIGN statement if your type is ‘P’. You can even change the type at runtime of previously assigned field symbol like
ASSIGN TO TYPE ‘C’.
One more thing for dynamic programing. With the following coding you can access every DDIC table with the key you want:
SELECT SINGLE * FROM (DF_TNAME) INTO S_TMP WHERE (IF_KEY).
It is very powerful, isn’t it !!!
[ Ingo-Willy Raddatz, posted to SAP listserver]
Example 1: Print page “n of x pages” on reports
The following code is just a function to loop total pages. To use from the beginning of your report, you will have to loop through your report once before display. ABAP does not provide
an easy “read-ahead” method of doing this, so this is the “cludgy” way of making it work if needed.
FORM GET_TOTAL_PAGENO.
WRITE SY-PAGNO TO NUM_PAGES_C LEFT-JUSTIFIED.
DO SY-PAGNO TIMES.
READ LINE 2 OF PAGE SY-INDEX.
REPLACE ‘*****’ WITH NUM_PAGES_C INTO SY-LISEL.
MODIFY LINE 2 OF PAGE SY-INDEX.
ENDDO.
ENDFORM. ” GET_TOTAL_PAGENO
[found on the Web at http://homepages.tcp.co.uk/~bob866/how_to.html%5D
What is a BTE
(1)BTE are comparabl to the old enhancements .
(2)BTEs are used mostly within FI .
(3)BTEs can be used both by SAP, third part vensdors and customers. Each use their own function modules where the logic is placed, so they don’t interfere with each other .
There are 2 types of BTE:
(1)Publish & Subscribe interfaces. Can not update data. Posiible to have multiple implementations .
(2)Process interfaces. Can update date. Only one active implementation .
How does it work
The BTE is a functionmodule (Implemented by the customer) that has a standard interface defined by SAP. The BTE is called by the SAP standard program by a call to function OPEN_FI_PERFORM_ or OUTBOUND_CALL_. This function chekcs if there are any active BTEs according to customizing.
How to find a BTE
Search the socurce code for for “OPEN_FI_PERFORM” og ” OUTBOUND_CALL_”
Use transaction FIBF menu Environment->Info System (P/S ). Use the Documenttion button to see the documentation for the BTE
Implementing a BTE
(1)Goto transction FIBF menu Environment->Info System (P/S )
(2)Select the BTE you want to implement.
(3)Press button Sample function module
(4)This brings you to SE37 – Copy the sample function module to a Z-function module (First create a new function group for the function module) . Note: The name of the Z-functionmodule is not important
(5)Edit the code in the new function module
(6)Go back to transaction FIBF – Menu Settings->Products -> Of a customer and create a new product whicj identifies the new product . Remember to mark the Active field.
(7)Go back to FIBF menu Settings->P/S function modules->of a customer – Create an entry that links the BTE and Product with the new function module
Example:
We want to implement BTE 00001030. Locate it in transaction FIBF .
- In: User Exit
- 2 Comments
Copied from From SapGenie.com
http://www.sapgenie.com/abap/code/abap26.htm
Selection Text: P_TCODE: Transaction Code to Search
Text Symbols: 001 – Enter the Transaction Code that you want to search through for a User Exit
REPORT z_find_userexit 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.
Reading and writing to a flatfile
Use transaction AL11 to view the files on the apllication server.
(1)Writing to a flatfile
(2)Reading a file
(3)Authority check
Writing to a flatfile
Note: If the path is not inlcuded in the file name, the file is
qwritten to the default directory on the apllication server (The system
uses the directory defined in the profile parameter DIR_HOME.)
DATA: dsn LIKE authb-filename VALUE ‘HFNK.DAT’.
OPEN DATASET dsn FOR OUTPUT IN TEXT MODE.
IF sy-subrc 0.
WRITE: ‘Error opening :’, dsn.
ENDIF.
LOOP AT it_doc INTO wa_doc.
TRANSFER wa_doc TO dsn.
IF sy-subrc 0.
WRITE /: ‘Error writing’.
ENDIF.
ENDLOOP.
CLOSE DATASET dsn.
Reading a file
DATA: g_delimiter(1) TYPE c VALUE ‘¤’,
dsn LIKE authb-filename VALUE ‘HFNK.DAT’.
OPEN DATASET g_dsn FOR INPUT IN TEXT MODE.
IF sy-subrc 0.
write ‘Error’.
EXIT.
ENDIF.
DO.
READ DATASET g_dsn INTO fline.
IF sy-subrc 0.
EXIT.
ELSE.
CLEAR wa_document.
* Split line into fields using the constant delimiter
SPLIT fline AT g_delimiter INTO
wa_document-bukrs
wa_document-gjahr
wa_document-belnr.
APPEND wa_document TO it_document.
ENDIF.
ENDDO.
CLOSE DATASET g_dsn.
Authority check
You can use the function module below to check for the necessary authorization. If the default value for the PROGRAM parameters is the current program .
CALL FUNCTION ‘AUTHORITY_CHECK_DATASET’
EXPORTING
* PROGRAM =
activity = ‘WRITE’
filename = dsn
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3
Validation of selection screens
Posted on: December 7, 2007
Validation of selection screen can be performed in the AT SELECTION SCREEN event.
Example:
************************************************************************
* AT SELECTION SCREEN *
************************************************************************
at selection-screen.
perform validate_selection_screen using g_returkode.
if g_returkode = c_returkode_error.
exit.
endif.
*&———————————————————————*
*& Form validate_selection_screen
*&———————————————————————*
* Validation of selection screen
*———————————————————————-*
* –>P_G_RETURKODE text
*———————————————————————-*
form validate_selection_screen using p_returkode.
if s_framd > 12 or s_framd 12 or s_tilmd < 1.
message e998.
p_returkode = c_returkode_error.
exit.
endif.
if s_framd > s_tilmd.
message e997.
p_returkode = c_returkode_error.
exit.
endif.
if s_fraaar < s_tilaar.
message e996.
p_returkode = c_returkode_error.
exit.
endif.
ENDFORM.
Example 1: Submitting a report using ranges for select-options
* Define range for ltak-tanum
RANGES: r_tanum FOR ltak-tanum.
* Read values from database tabel into the range
* These values are later used for select-options in the report
SELECT * FROM ltak
WHERE lgnum = w_lgnum AND “Warehouse number/complex
vbeln = w_screen1000-io_vbeln. “Transfer order number
MOVE ltak-tanum TO r_tanum-low.
MOVE ‘I’ TO r_tanum-sign.
MOVE ‘EQ’ TO r_tanum-option.
APPEND r_tanum.
ENDSELECT.
* Submit report with range
SUBMIT zmm00100 WITH p_tanum IN r_tanum.
Example 2: Submitting a report from ABAP with selection criterias
TYPES: tt_selection TYPE STANDARD TABLE OF rsparams.
DATA: l_iblnr TYPE st_iblnr,
* Define internal table and work area for select-options
l_selection TYPE rsparams,
li_selection TYPE tt_selection.
* Create selectIon table
LOOP AT gi_iblnr INTO l_iblnr.
CLEAR l_selection.
l_selection-selname = ‘IM_IBLNR’. “Option name
l_selection-kind = ‘S’. “S= select options P=Parameters
l_selection-sign = ‘I’. “Sign
l_selection-option = ‘EQ’. “Option
l_selection-low = l_iblnr-iblnr. “Value
APPEND l_selection TO li_selection.
ENDLOOP.
* Submit report
SUBMIT rm07idif WITH SELECTION-TABLE li_selection AND RETURN.

Recent Comments