Skip to Content

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:

/wp-content/uploads/2013/06/1_228516.jpg

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

/wp-content/uploads/2013/06/2_228517.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 sysubrc = 0.
   lr_elemdescr ?= cl_abap_elemdescr
=>describe_by_data( <field> ).
   ls_field
= lr_elemdescr->get_ddic_field( ).
  
IF ls_fieldscrtext_m IS INITIAL.
    ls_field
scrtext_m = ls_fieldscrtext_s.
  
ENDIF.
   lv_defaultc
= <field>.
   lv_paratype
= ‘P0009-‘ && <component>name.
  
IF ls_fieldscrtext_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_fieldscrtext_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.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Jelena Perfiljeva

    Thanks for sharing! I’ve noticed P0009 is hardcoded, so how would one make this fully dynamic? Or is it not feasible? Also – any limitations on the structure definition? I guess at least it should be “flat”, but is there anything else to consider?

    (0) 
    1. Guryanov Alexandr Post author

      Yes, P0009 is hardcode here but you can replace it with any ather flat structure that described in ABAP repository. Furthermore you can use a structure that doesn’t exist in the repository but then you’re to carry out fields types as soon as they should reffer to a data element or to a base ABAP type.

      (0) 
  2. Nahuel ElĂ­as Romanello

    Hi, I think this post is really useful… I’m very grateful.

    But one thing that call me my attention… is… when you define the attached class, you define the code of the methods inside the definition, I think the right thing is to put the code of the methods inside the implementation clause, and in the definition clause only define them only with their parameters.

    What do you think?

    Thanks in advance!

    (0) 
    1. Guryanov Alexandr Post author

      Hi Nahuel,

      Soory for such long time for answer. Those classes are dictionary classes. They exist without any reports. So my texts are just copy-paste of code public-protexted-private sections and then code of each methods. Of course you can’t copy-paste all of these codes into your report. Sorry if that’s not very comfortable.

      Best regards,

      Alexander

      (0) 

Leave a Reply