Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Dynamically request values from user

$
0
0

Today I’d like to introduce a tool to request a random number of values from user. For example, you’d like to ask and then store a template of some structure to use this pattern further.

I used it to determine sample values for structure of an HR infotype to create a flexible data download program.

Initial screen of this report looks very ascetic:

1.jpg

                    The bottom button is used to request data from user. If you push it you’ll get:

2.jpg

Here you can see a list of P0009 structure fields with their names described at ABAP repository. So any changes of this structure will change this screen with requesting values.

Probably, you’d like to know how many instructions I was to code. Well, lets see it:

 

The first part is to describe my requesting tool:

DATA: lr_request_values TYPE REF TO zcl_bas_dyn_request_values.
  lr_request_values
= zcl_bas_dyn_request_values=>factory( ).

 

 

The second is to get my structure filled with values by user:

DATA: default_p0009 TYPE p0009,
     lr_descr     
TYPE REF TO cl_abap_structdescr,
     lr_elemdescr 
TYPE REF TO cl_abap_elemdescr.
   
lr_descr ?= cl_abap_structdescr=>describe_by_data( default_p0009 ).
    CHECK lr_descr IS BOUND.
 
LOOP AT lr_descr->components ASSIGNING <component>.

      ASSIGN COMPONENT <component>-name OF STRUCTURE default_p0009 TO <field>.
  
CHECK sy-subrc = 0.
   lr_elemdescr ?= cl_abap_elemdescr
=>describe_by_data( <field> ).
   ls_field
= lr_elemdescr->get_ddic_field( ).
  
IF ls_field-scrtext_m IS INITIAL.
    ls_field
-scrtext_m = ls_field-scrtext_s.
  
ENDIF.
   lv_defaultc
= <field>.
   lv_paratype
= 'P0009-' && <component>-name.
  
IF ls_field-scrtext_m IS INITIAL.
    ls_field
-scrtext_m = lv_paratype.
  
ENDIF.
   lr_request_values
->add_parameter(
    
EXPORTING
      iv_parakind 
= 'P'
      iv_paratype 
= lv_paratype
      iv_label    
= ls_field-scrtext_m
      iv_def_value
= lv_defaultc
    
CHANGING
      cv_parameter
= <field> ).
 
ENDLOOP.


And at last request user:

    lr_request_values->request_values( ).

When the last call ends my structure default_p0009 is filled with values user just filled. As you may count it’s just about 20 lines of code to ask user for values of any flat structure from ABAP repository.

And now my code to get this functionality:

 

TXT files attached for class ZCL_BAS_DYN_REQUEST_VALUES and for class ZCL_BAS_DYN_PARAM.


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>