 |
 |
| SAP Tips: |
|
 |
 |

ABAP/JAVA DEVELOPER TIPS
Function Modules
Sangramjit Routray 10.12.2001
Rating: -4.27- (out of 5) Hall of fame tip of the month winner




Function Modules to Read/Update Screen Fields without PAI/PBO events
Code
***********************************************************************
Function Modules to Read Screen Fields
************************************************************************
Sometimes it is required to read the screen field values before they get
transferred into programme variables.
To achive the same the following steps may be carried out.
Step 1:
Create an internal table to hold the fields names that you want to read.
This internal table is a standard table of dynpread type.
For ex. :
T_DF LIKE STANDARD TABLE OF DYNPREAD
INITIAL SIZE 0 WITH HEADER LINE.
Also, declare two local variables to pass the programme name and
screen number to the function module
For ex. :
Variable to hold the program name
l_repid LIKE d020s-prog
Variable to hold the screen number
l_scrnr LIKE d020s-dnum
Step 2:
Populate the internal table with the field names that is to be read.
For ex. :
T_DF-FIELDNAME = 'KNA1-KUNNR'
APPEND T_DF
Take extra care when populating the field name of table control.
In that we will have to find out the line number where the cursor
is placed. To archive this the following piece of code may be used.
For ex. :
Declare the following variables.
l_cline(2) TYPE c "Holds the current line no
l_fld LIKE dynpread-fieldname "Holds the field name
l_lno TYPE i "Holds the current line no
Fetch the line number the cursor is
GET CURSOR LINE l_cline .
The following peice of code may be used to concatenate extra zero(0)
if the line number is less than 2 digits.
l_lno = strlen( l_cline ).
IF l_lno <= 1.
CONCATENATE '0' l_cline INTO l_cline.
ENDIF.
Then concatenate the line number along with a pair of parathesises
CONCATENATE 'T_ENLINES-MATNR(' l_cline ')' INTO l_fld.
CONDENSE l_fld NO-GAPS.
Then populate the internal table with field names
t_df-fieldname = l_fld.
APPEND t_df.
Step 3:
Assign the SY-REPID to the local variable. This step is required
otherwise it will give a warning message.
For ex. :
l_repid = sy-repid
l_scrnr = 9010
Step 4:
Call the function module, DYNP_VALUES_READ, to read the screen fields.
Export the programme name and screen number to the function module. Supply the internal table as parameter. This internal table will be
populated by the function module with the field values.
By trapping the value of sy-subrc, we can find out whether any error
occured or not.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = l_repid
dynumb = l_scrnr
* TRANSLATE_TO_UPPER = ' '
* REQUEST = ' '
* PERFORM_CONVERSION_EXITS = ' '
* PERFORM_INPUT_CONVERSION = ' '
* DETERMINE_LOOP_INDEX = ' '
TABLES
dynpfields = T_DF
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11
.
Step 5:
After successful execution of function module , we may read the
internal with the key field name, and find out the value by reading
the FIELDVALUE.
For ex.:
READ TABLE T_DF WITH KEY FIELDNAME = 'KNA1-KUNNR'.
T_DF-FIELDVALUE, will hold the value of the field 'KNA1-KUNNR'.
*************************************************************************
Function Modules to Read / Update Screen Fields
*************************************************************************
Sometimes it is required to update the screen field values before they
get populated by the programme variables. To achive the same the
following steps may be carried out.
Step 1:
Create an internal table to hold the fields names as well as field values
that you want to update. This internal table is a standard table of
dynpread type.
For ex. :
t_dynpread LIKE STANDARD TABLE OF dynpread
INITIAL SIZE 0 WITH HEADER LINE.
Also, declare two local variables to pass the programme name and screen
number to the function module
For ex. :
Variable to hold the program name
l_repid LIKE d020s-prog
Variable to hold the screen number
l_scrnr LIKE d020s-dnum
Step 2:
Assign the SY-REPID to the local variable. This step is required
otherwise it will give a warning message.
For ex. :
l_repid = sy-repid
l_scrnr = 9010
Step 3:
Populate the internal table with field name and field values.
For example if we want to populate screen field sales office after
fetching the data from database, then the following peice of code
may be used.
1. Fetch the sales office from database
SELECT SINGLE vkbur FROM knvv INTO vbak-vkbur
WHERE kunnr = kna1-kunnr AND
vkorg = vbak-vkorg AND
vtweg = c_vtweg AND
spart = c_spart.
(Note:- Here I have taken distribution channel and division as contants)
Then populate the internal table with field name and field value.
t_dynpread-fieldname = 'VBAK-VKBUR'. "Specify the screen field name
t_dynpread-stepl = 0.
t_dynpread-fieldvalue = vbak-vkbur. "Specify the program variable that
holds the value to be updated
APPEND t_dynpread.
Call the function module, DYNP_VALUES_UPDATE, to update the screen fields.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = l_repid
dynumb = l_scrnr
TABLES
dynpfields = t_dynpread
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
undefind_error = 7
OTHERS = 8
.
SY-SUBRC value may be checked to find the successful execution of the
function module.
 |

|
|
 |
|
 |
 |
 |
 |
| TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of . |
|
| | |
All Rights Reserved, , TechTarget |
SearchSAP.com is a search service provided by TechTarget and is completely independent of and not affiliated with SAP AG.
|
|
|
|
|