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

11 comments:

SAPna said...

Nice program.

I want to know can I choose either of the two values - For example if I have a Price field; and I want to populate Price field with either SalePrice or RetailPrice (which are coming from a ztable for a specific material).

Any suggestions are highly appreciated.

Thanks

alionzo said...

Hi Naved,
Thanks for you comment.
This function return which row choosen by user, not which column choosen. So you have to manipulate the data to make SalePrice & RetailPrice come to different row in VALUE_TAB.
Here is you output tab.
Output fields:
MaterialNo,SalePrice,RetailPrice.
VALUE_TAB data:
Row1:
MaterialNo1,SalePrice1,blank
Row2:
MaterialNo1,blank,RetailPrice1.
...
...
Row(2*n-1):
MaterialNo-n,SalePrice-n,blank.
Row(2*n):
MaterialNo-n,blank,RetailPrice-n.

Hope it help.

SAPna said...

Thanks for your comments.

I have few questions. What do you mean by VALUE_TAB (is it ztable).

All the Row1, Row2 ,... will be maintained in the ztable manually first? That is two rows for each product.

Also, I have only one output field Price which will capture either SalePrice or RetailPrice.

Any comments appreciated.
Thanks

alionzo said...

VALUE_TAB is an internal table as a table parameter passed to function F4IF_INT_TABLE_VALUE_REQUEST (look at my sample code, find VALUE_TAB).
Do you ask about "help value request"?
You have one output field. Is it output field in selection screen?
What process do capture the field price, is it "help value request"?

SAPna said...

Thanks for your reply.

1)Do you ask about "help value request"? YES

2)You have one output field. Is it output field in selection screen?
No. The OUTPUT field is in 'TABLE CONTROL' on SCREEN 100

What process do capture the field price, is it "help value request"?
Yes.

alionzo said...

You have one output field. When user put cursor in this field then press F4 it will pop up list of available value. First you must define format of this pop up list. 1. How many output field then define type of fields (structure in pop up list).
2. Define how data written in this pop up list.

For example, let me explain the definition of my sample code:
1. Structure :
field1=Username (USR02-BNAME)
field2=UserGroup (USR02-CLASS)
2. Definition of how data written in output list:
Select all data from table USR02, then display all row in output list.

Please describe your need in this format.

Thanks.

Anonymous said...

Can i use pass a structure in function module 'DDIF_FIELDINFO_GET' ?

alionzo said...

Yes, you can pass structure, view, table to get their field definition using DDIF_FIELDINFO_GET

Unknown said...

What is the use of the MULTIPLE_CHOICE parameter in this FM?
I have read the documentation but not able to understand it.

Unknown said...

hi,
i have problem with f4 help ,i am passing my own structure vaues tab (containing 2 fields itemcategory and description) ,for select-option low when iam pressing f4 it is showing description only that to first letter is not showing,one column values showing with # .can u please help me on this issue.

Thanks in advance.

Anonymous said...

the loan company that grants me loan of 5,000,000.00 USD When other loan investors has neglect my offer but mr benjamin lee granted me success loan.they are into directly in loan financing and project  in terms of investment. they provide financing solutions to companies and individuals seeking access to capital markets funds, they can helped you fund your project or expand your business.. Email Contact:::: Also  247officedept@gmail.com or Write on whatsapp Number  on    +1-(989-394-3740)