[ABAP] Dynamisches Selektionsbild-Popup erzeugen

CLASS lcl_dynamic_popup DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS
      show
        RETURNING VALUE(rv_ok) TYPE abap_bool.
ENDCLASS.

CLASS lcl_dynamic_popup IMPLEMENTATION.
  METHOD show.

    rv_ok = abap_true.

* Werte für Selektionbild definieren
    DATA: p_carrid TYPE s_carr_id.
    DATA: so_werks TYPE gds_selrange_werks_tab.
    DATA: p_werks_no TYPE werks.
    DATA: p_check  TYPE xfeld.
    DATA: rb_1 TYPE xfeld.
    DATA: rb_2 TYPE xfeld.
    DATA: lb_language TYPE spras.

    lb_language = sy-langu.

* Selektionsbildelemente für das Popup
* die Eingabewerte werden mit den Variablen über die Felder "ref" verknüpft
    DATA(it_attr) = VALUE sci_atttab(
* Group1 für die folgenden Felder
                                      (
                                        kind = 'G'
                                        text = 'Gruppe1'
                                        ref  = REF #( sy-index )
                                      )
* Parameter
                                      (
                                          kind       = 'S'
                                          text       = 'Carrid'
                                          obligatory = abap_true
                                          ref        = REF #( p_carrid )
                                      )
* SELECT-OPTIONS
                                      (
                                          kind       = 'S'
                                          text       = 'Werk'
                                          ref        = REF #( so_werks )
                                      )
* SELECT-OPTIONS NO INTERVALS
                                      (
                                          kind       = 'T'
                                          text       = 'Werk2'
                                          ref        = REF #( p_werks_no )
                                      )
* Group2 für die folgenden Felder
                                      (
                                        kind = 'G'
                                        text = 'Gruppe2'
                                        ref  = REF #( sy-index )
                                      )
* Checkbox
                                      (
                                          kind       = 'C'
                                          text       = 'Check'
                                          ref        = REF #( p_check )
                                      )
* Radiobuttons mit Group
                                      (
                                          kind         = 'R'
                                          text         = 'Radiobutton1'
                                          button_group = 'GR1'
                                          ref          = REF #( rb_1 )
                                      )
                                      (
                                          kind         = 'R'
                                          text         = 'Radiobutton2'
                                          button_group = 'GR1'
                                          ref          = REF #( rb_2 )
                                      )
* Listbox
                                      (
                                          kind = 'L'
                                          text = 'Sprache'
                                          ref  = REF #( lb_language )
                                      )
                                    ).

* Selektionsbild erzeugen und Popup anzeigen
    IF abap_true = cl_ci_query_attributes=>generic( p_name       = CONV #( sy-repid )
                                                    p_title      = 'Dynamisches Popup'
                                                    p_display    = abap_false " abap_true: Anzeige im READONLY-Modus
                                                    p_attributes = it_attr ).
      rv_ok = abap_false.
    ENDIF.

* Werte ausgeben
    WRITE: / 'CARRID:', p_carrid.
    WRITE: / 'WERKS:', COND string( WHEN lines( so_werks ) > 0 THEN so_werks[ 1 ]-low ELSE '' ).
    WRITE: / 'WERKS2:', p_werks_no.
    WRITE: / 'Check:', p_check.
    WRITE: / 'RB1:', rb_1.
    WRITE: / 'RB2:', rb_2.
    WRITE: / 'LANGUAGE:', lb_language.

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  IF abap_true = lcl_dynamic_popup=>show( ).
    WRITE: / 'Ok.'.
  ELSE.
    WRITE: / 'Abbruch.'.
  ENDIF.

Generische Listenklasse mit Indexer und Enumerator

using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// generic list class with indexer and enumerator
/// freeware 2011 by admin of codezentrale.6x.to
/// </summary>
/// <typeparam name="T">datatype you want to manage</typeparam>
public class GenericList<T> : IEnumerable, IDisposable
{
    /// <summary>
    /// internal class, with interface for IEnumerable and IEnumerator
    /// </summary>
    private class GenericListEnumerator : IEnumerator
    {
        private int pos = -1;
        private GenericList<T> _t;

        public GenericListEnumerator(GenericList<T> t)
        {
            this._t = t;
        }

        public bool MoveNext()
        {
            if (pos < _t.Count - 1)
            {
                pos++;
                return true;
            }
            else
            {
                return false;
            }
        }

        public void Reset()
        {
            pos = -1;
        }

        public object Current
        {
            get
            {
                try
                {
                    return _t[pos];
                }
                catch (IndexOutOfRangeException)
                {
                    throw new InvalidOperationException();
                }
            }
        }
    }

    private List<T> _ObjectList = new List<T>();
    private bool _bDisposed = false;

    /// <summary>
    /// object counter
    /// </summary>
    public int Count
    {
        get { return _ObjectList.Count; }
    }
    /// <summary>
    /// indexer for direct index based access (e.g. mylist[1])
    /// </summary>
    /// <param name="pos"></param>
    /// <returns></returns>
    public T this[int pos]
    {
        get { return _ObjectList[pos]; }
        set { _ObjectList[pos] = value; }
    }

    public GenericList()
    {
    }

    // destructor, makro for 'protected override void Finalize()'
    ~GenericList()
    {
        this.Dispose(false);
    }

    // public Dispose-method for cleanup
    public void Dispose()
    {
        this.Dispose(true);
    }

    // internal Dispose-method
    private void Dispose(bool bDisposing)
    {
        if (!_bDisposed)
        {
            if (bDisposing)
            {
                // e.g. free managed resources here
            }
        }

        _bDisposed = true;
    }

    /// <summary>
    /// interface function for IEnumerable and IEnumerator
    /// </summary>
    /// <returns></returns>
    public IEnumerator GetEnumerator()
    {
        return new GenericListEnumerator(this);
    }
    /// <summary>
    /// add object to list
    /// </summary>
    /// <param name="obj">your object</param>
    public void Add(T obj)
    {
        _ObjectList.Add(obj);
    }
    /// <summary>
    /// clear list
    /// </summary>
    public void Clear()
    {
        _ObjectList.Clear();
    }
    /// <summary>
    /// swap objects inside list
    /// </summary>
    /// <param name="index1">index number one</param>
    /// <param name="index2">index number one</param>
    public void Swap(int index1, int index2)
    {
        if ((index1 >= 0) && (index2 >= 0) && (index1 < _ObjectList.Count) && (index2 < _ObjectList.Count))
        {
            T temp = _ObjectList[index1];
            _ObjectList[index1] = _ObjectList[index2];
            _ObjectList[index2] = temp;
        }
    }
    /// <summary>
    /// remove object from list
    /// </summary>
    /// <param name="obj"></param>
    public void Remove(T obj)
    {
        _ObjectList.Remove(obj);
    }
}