Funktionsbaustein DYNP VALUES UPDATE

Aus SAP-Wiki
Wechseln zu: Navigation, Suche

Mit dem Funktionsbaustein DYNP_VALUES_UPDATE kann man mehrere Werte auf einem Dynpro ändern, ohne dass der PBO durchlaufen werden muss.

Hier soll beim ersten Parameter PDF (bzw. P_PDF1) möglich sein mehrere Dateien auszuwählen, die dann in maximal 10 Parameterfelder zurückgeschrieben werden.

DYNP VALUES UPDATE1.jpg

Muster

CALL FUNCTION 'DYNP_VALUES_UPDATE'
  EXPORTING
    DYNAME                     =
    DYNUMB                     =
  TABLES
    DYNPFIELDS                 =
" EXCEPTIONS
"   INVALID_ABAPWORKAREA       = 1
"   INVALID_DYNPROFIELD        = 2
"   INVALID_DYNPRONAME         = 3
"   INVALID_DYNPRONUMMER       = 4
"   INVALID_REQUEST            = 5
"   NO_FIELDDESCRIPTION        = 6
"   UNDEFIND_ERROR             = 7
"   OTHERS                     = 8
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Coding

* Beim ersten PDF-Upload kann man gleich mehrere Dateien auswählen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_pdf1.
  CALL METHOD /vtis/cl_schn=>file_open_dialog_pdf_multi
    IMPORTING
      et_pdf_filename = gt_pdf_filename.

  IF gt_pdf_filename IS NOT INITIAL.
    PERFORM dynp_values_update
      USING gt_pdf_filename.
  ENDIF.
METHOD file_open_dialog_pdf_multi.

  DATA: lt_filetable TYPE filetable,
        ls_filetable LIKE LINE OF lt_filetable,
        ld_rc TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Datei auswählen'
      file_filter             = 'PDF-Dateien (*.PDF)|*.PDF'
      initial_directory       = 'H:\'
      multiselection          = true
    CHANGING
      file_table              = lt_filetable
      rc                      = ld_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      OTHERS                  = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  IF ld_rc > 0.
    LOOP AT lt_filetable INTO ls_filetable.
      append ls_filetable-filename to et_pdf_filename.
    ENDLOOP.
  ENDIF.

ENDMETHOD.
*&---------------------------------------------------------------------*
*&      Form  DYNP_VALUES_UPDATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM dynp_values_update
  USING pit_pdf_filename TYPE filetable.


  READ TABLE pit_pdf_filename INDEX 1  INTO p_pdf1.
  READ TABLE pit_pdf_filename INDEX 2  INTO p_pdf2.
  READ TABLE pit_pdf_filename INDEX 3  INTO p_pdf3.
  READ TABLE pit_pdf_filename INDEX 4  INTO p_pdf4.
  READ TABLE pit_pdf_filename INDEX 5  INTO p_pdf5.
  READ TABLE pit_pdf_filename INDEX 6  INTO p_pdf6.
  READ TABLE pit_pdf_filename INDEX 7  INTO p_pdf7.
  READ TABLE pit_pdf_filename INDEX 8  INTO p_pdf8.
  READ TABLE pit_pdf_filename INDEX 9  INTO p_pdf9.
  READ TABLE pit_pdf_filename INDEX 10 INTO p_pdf10.

  DATA: ls_fields  TYPE dynpread.
  DATA: lt_fields  TYPE TABLE OF dynpread.

  ls_fields-fieldname = 'P_PDF1'.
  ls_fields-fieldvalue = p_pdf1.
  APPEND ls_fields TO lt_fields.

  ls_fields-fieldname = 'P_PDF2'.
  ls_fields-fieldvalue = p_pdf2.
  APPEND ls_fields TO lt_fields.

  "...

  CALL FUNCTION 'DYNP_VALUES_UPDATE'
    EXPORTING
      dyname               = 'Z_MA_PROTOTYP'
      dynumb               = '1000'
    TABLES
      dynpfields           = lt_fields
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      undefind_error       = 7
      OTHERS               = 8.

  IF sy-subrc <> 0.
    break muellem1.
  ENDIF.

ENDFORM.                    " DYNP_VALUES_UPDATE

Literatur