*---------------------------------------------------------------------*
*       FORM F4_POSITIONIEREN                                         *
*---------------------------------------------------------------------*
*       called externally from POPUP_GET_VALUES_USER_HELP             *
*---------------------------------------------------------------------*
FORM f4_positionieren USING value(tabname) TYPE tabname
                            value(fieldname) TYPE fieldname
                            value(display)
                      CHANGING returncode
                               value TYPE any.
  STATICS: field_tab TYPE TABLE OF dfies INITIAL SIZE 20.

  DATA: tabval(132) TYPE c,
        v_tab LIKE TABLE OF tabval INITIAL SIZE 500,
        w_dfies TYPE dfies,
        return_tab TYPE TABLE OF ddshretval INITIAL SIZE 1,
        BEGIN OF out_conv_function,
         prefix(16) TYPE c VALUE 'CONVERSION_EXIT_',
         exit LIKE vimnamtab-convexit,
         suffix(7) TYPE c VALUE '_OUTPUT',
        END OF out_conv_function,
        f4_length TYPE i.    "total length of to be displayed fields
  FIELD-SYMBOLS: <hf1>, <dfies> TYPE dfies, <retval> TYPE ddshretval.

  READ TABLE field_tab INDEX 1 ASSIGNING <dfies>.
  IF sy-subrc <> 0 OR <dfies>-tabname <> x_header-maintview.
    REFRESH field_tab.

* xb  06.02 csn ext.237151 2002, BCEK061005 ---------begin----------
* check the total display length of F4-List
    f4_length = 0.
    IF x_header-tablen > 1000.
      LOOP AT x_namtab.
        IF x_header-clidep NE space.       "ignore client field
          CHECK sy-tabix NE 1.
        ENDIF.
        IF x_namtab-keyflag NE space OR    "all key fields or
           x_namtab-datatype EQ 'CHAR' AND "all possibly text fields
           x_namtab-flength  GE 10     AND
           x_namtab-lowercase  NE space.

          f4_length = f4_length + x_namtab-outputlen.
        ENDIF.
      ENDLOOP.
    ENDIF.

    IF f4_length < 1000.          "check the fields length
* xb  06.02 csn ext.237151 2002, BCEK061005 ----------end-----------
    LOOP AT x_namtab.
      IF x_header-clidep NE space.       "ignore client field
        CHECK sy-tabix NE 1.
      ENDIF.
      CHECK x_namtab-readonly <> vim_hidden.                  "Subviews
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        CHECK x_namtab-keyflag NE space AND   "all entity keyfields
              x_namtab-texttabfld EQ space OR                 "or
            x_namtab-keyflag EQ space AND   "all texttab function fields
              x_namtab-texttabfld NE space.
      ELSE.
        CHECK x_namtab-keyflag NE space OR    "all key fields or
              x_namtab-datatype EQ 'CHAR' AND "all possibly text fields
              x_namtab-flength  GE 10     AND
              x_namtab-lowercase  NE space.
        ENDIF.
        IF x_namtab-texttabfld NE space.
          w_dfies-tabname = x_header-texttab.
        ELSE.
          w_dfies-tabname = x_header-maintview.              "Subviews
        ENDIF.
        w_dfies-fieldname = x_namtab-viewfield.
        APPEND w_dfies TO field_tab.
      ENDLOOP.
    ELSE.
* xb  06.02 csn ext.237151 2002, BCEK061005 ---------begin----------
      MESSAGE I810(SV) WITH x_header-viewname.
*   Die gesamte Länge der View & ist mehr als 1000 Charakter. Nur Key
*   Field wird gezeigt.
      LOOP AT x_namtab.
        IF x_header-clidep NE space.       "ignore client field
          CHECK sy-tabix NE 1.
        ENDIF.
       CHECK x_namtab-readonly <> vim_hidden.                  "Subviews
        IF x_header-bastab NE space AND x_header-texttbexst NE space.
          CHECK x_namtab-keyflag NE space AND   "all entity keyfields
                x_namtab-texttabfld EQ space OR                 "or
            x_namtab-keyflag EQ space AND   "all texttab function fields
                x_namtab-texttabfld NE space.
        ELSE.
          CHECK x_namtab-keyflag NE space.    "all key fields
      ENDIF.
      IF x_namtab-texttabfld NE space.
        w_dfies-tabname = x_header-texttab.
      ELSE.
        w_dfies-tabname = x_header-maintview.                  "Subviews
      ENDIF.
      w_dfies-fieldname = x_namtab-viewfield.
      append w_dfies to field_tab.
    ENDLOOP.
* xb  06.02 csn ext.237151 2002, BCEK061005 ----------end-----------
    ENDIF.
  ENDIF.


  LOOP AT extract.
    LOOP AT field_tab ASSIGNING <dfies>.
      READ TABLE x_namtab WITH KEY viewfield = <dfies>-fieldname.
      IF x_header-bastab NE space AND x_header-texttbexst NE space.
        IF x_namtab-keyflag EQ space AND x_namtab-texttabfld NE space.
* Type S: text field
          ASSIGN COMPONENT x_namtab-viewfield
           OF STRUCTURE <vim_ext_txt_struc> TO <hf1>.
        ELSEIF x_namtab-keyflag NE space
         AND x_namtab-texttabfld EQ space.
* Type S: key field
          ASSIGN COMPONENT x_namtab-viewfield
           OF STRUCTURE <vim_extract_struc> TO <hf1>.
        ENDIF.
      ELSE.
* viewfield
        ASSIGN COMPONENT x_namtab-viewfield
         OF STRUCTURE <vim_extract_struc> TO <hf1>.
      ENDIF.
      CHECK <hf1> IS ASSIGNED.
*        IF X_HEADER-BASTAB NE SPACE AND X_HEADER-TEXTTBEXST NE SPACE.
*          CHECK X_NAMTAB-KEYFLAG NE SPACE AND   "all entity keyfields
*                X_NAMTAB-TEXTTABFLD EQ SPACE OR             "or
*                X_NAMTAB-KEYFLAG EQ SPACE AND   "all texttab function
*                X_NAMTAB-TEXTTABFLD NE SPACE.
*        ENDIF.
*        ASSIGN EXTRACT+X_NAMTAB-POSITION(X_NAMTAB-FLENGTH) TO <HF1>
*               TYPE 'C'.
      WRITE <hf1> TO tabval(x_namtab-outputlen).
      APPEND tabval TO v_tab.
      CLEAR tabval.
    ENDLOOP.
  ENDLOOP.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*     DDIC_STRUCTURE         = ' '
      retfield               = fieldname
*     PVALKEY                = ' '
*     DYNPPROG               = ' '
*     DYNPNR                 = ' '
*     DYNPROFIELD            = ' '
*     STEPL                  = 0
*     WINDOW_TITLE           =
*     VALUE                  = ' '
*     VALUE_ORG              = 'C'
*     MULTIPLE_CHOICE        = ' '
      display                = display
*     CALLBACK_PROGRAM       = ' '
*     CALLBACK_FORM          = ' '
*     MARK_TAB               =
    TABLES
      value_tab              = v_tab
      field_tab              = field_tab
      return_tab             = return_tab
*     DYNPFLD_MAPPING        =
    EXCEPTIONS
      parameter_error        = 1
      no_values_found        = 2
      OTHERS                 = 3.
  IF sy-subrc = 0.
    READ TABLE return_tab INDEX 1 ASSIGNING <retval>.
    IF sy-subrc = 0.
      value = <retval>-fieldval.
    ENDIF.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                               "f4_positionieren
