Tip

Loading an internal table using dynamic data names

Sometimes we have different variables with homogenius content, and it would be preferable if those variables were in an internal table. To do this we can use field-symbols. The code below was written in 4.6b and works with 4.0. Previous versions might require some edits.

Report ZTest.

Parameters: dat01(5),
            dat02(5),
            dat03(5),
            dat04(5),
            dat05(5),
            dat06(5),
            mat01 like mara-matnr,
            mat02 like mara-matnr,
            mat03 like mara-matnr,
            mat04 like mara-matnr,
            mat05 like mara-matnr,
            mat06 like mara-matnr.            

types: begin of t_itab,
         dat(5),
         mat     like mara-matnr,
       end of t_itab.

data: itab type standard table of t_itab with header line.

Start-of-selection.
  Perform fr_load_itab.
  loop at itab.
    write:/ itab-dat, itab-mat.
  endloop.

******************************************************************
Form fr_load_itab.
Data: c_dat(3)   VALUE 'DAT', "Constant field name
      c_mat(3)   VALUE 'MAT', "Constant field name
      w_i(2)     Type N,      "Index name
      w_field(5).             "Target field name

* Field Symbols
  Field-Symbols: <FS1> TYPE ANY,
                 <FS2> TYPE ANY.

  clear: w_i, itab.
  While w_i < 4.
    w_i = w_i + 1.

    clear w_field.
    concatenate c_dat w_i INTO W_FIELD.
    condense W_FIELD.                    "Create first field name
    ASSIGN (W_FIELD) TO <FS1>.

    Requires Free Membership to View

"Assign field value itab-dat = <FS1>. clear w_field. concatenate c_mat w_i INTO W_FIELD. condense W_FIELD. "Create second field name ASSIGN (W_FIELD) TO <FS2>. "Assign field value itab-mat = <FS2>. APPEND itab. clear itab. EndWhile. Endform.

This was first published in August 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.