Monday, August 19, 2019

F4 Help Multiple fields Update in Table Control

In the following example we are learning how to populate multiple fields records by using F4 search help. We know that F4 search help logic is written in Process On Value Request event. Here we are using function module F4 Int Table Value Request and then we are passing rest of the required data records by Dynp Values Update.

We are creating a basic Table Control.

Top Include:
TABLESmsegmara.
TYPESBEGIN OF ts_mseg,
         mblnr TYPE mseg-mblnr,
         mjahr TYPE mseg-mjahr,
         matnr TYPE mseg-matnr,
         werks TYPE mseg-werks,
         lgort TYPE mseg-lgort,
         charg TYPE mseg-charg,
       END OF ts_mseg.
DATAwa_mseg TYPE ts_mseg,
      it_mseg TYPE TABLE OF ts_mseg.

DATAok_9001 TYPE sy-ucomm,
      batch   TYPE charg_d.
CONTROLS tabc_9001 TYPE TABLEVIEW USING SCREEN 9001.


Screen 9001:
PROCESS BEFORE OUTPUT.
  MODULE status_9001.

  LOOP AT it_mseg INTO wa_mseg WITH CONTROL tabc_9001.
    MODULE populate_table.
  ENDLOOP.

PROCESS AFTER INPUT.
  LOOP AT it_mseg.
    MODULE modify_table.
  ENDLOOP.

  MODULE user_command_9001.

PROCESS ON VALUE-REQUEST.
  FIELD batch MODULE f4_help_batch.



Process Before Output:
MODULE status_9001 OUTPUT.
  SET PF-STATUS 'PF_9001'.
  SET TITLEBAR 'T_9001'.
ENDMODULE.


MODULE populate_table OUTPUT.
  DESCRIBE TABLE it_mseg LINES sy-dbcnt.
  tabc_9001-current_line sy-loopc.
  tabc_9001-lines        sy-dbcnt.

  mseg-mblnr wa_mseg-mblnr.
  mseg-mjahr wa_mseg-mjahr.
  mseg-matnr wa_mseg-matnr.
  mseg-werks wa_mseg-werks.
  mseg-lgort wa_mseg-lgort.
  batch wa_mseg-charg.
ENDMODULE.


Process After Input:
MODULE user_command_9001 INPUT.
  CASE sy-ucomm.
    WHEN 'ENTER'.
      PERFORM enter_9001.
    WHEN 'DISP'.
      PERFORM display_9001.
    WHEN 'BACK'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.


MODULE modify_table INPUT.
  READ TABLE it_mseg ASSIGNING FIELD-SYMBOL(<lw_mseg>)
  INDEX tabc_9001-current_line.
  IF sy-subrc 0.

  ENDIF.
ENDMODULE.


Performs:
FORM enter_9001 .
  SORT it_mseg BY matnr.
ENDFORM.


FORM display_9001 .
  SELECT matnrmtart FROM mara
    INTO TABLE @DATA(lt_mara)
    WHERE mtart @mara-mtart.

  IF sy-subrc 0.
    SELECT mblnr mjahr matnr
      FROM mseg INTO TABLE it_mseg
      FOR ALL ENTRIES IN lt_mara
      WHERE matnr lt_mara-matnr.
  ENDIF.
ENDFORM.


The most important part is in the Process on Value Request:
MODULE f4_help_batch INPUT.
  DATAlv_line   TYPE i,
        lt_return TYPE TABLE OF ddshretval.

  "--It will catch the row no. of table control
  GET CURSOR LINE lv_line.

  "--Fetching the table data based on the row no./ Line
  READ TABLE it_mseg ASSIGNING <lw_mseg> INDEX lv_line.
  IF sy-subrc 0.
    SELECT matnrwerkslgortcharg
      FROM mchb INTO TABLE @DATA(lt_mchb)
      WHERE matnr @<lw_mseg>-matnr.

    IF sy-subrc 0.
      "--It will Pop Up the help table
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          retfield        'MSEG-CHARG'
          dynpprog        sy-cprog
          dynpnr          sy-dynnr
          dynprofield     'MSEG-CHARG'
          window_title    'Batch wise Plant & Storage'
          value_org       'S'
        TABLES
          value_tab       lt_mchb
          return_tab      lt_return
        EXCEPTIONS
          parameter_error 1
          no_values_found 2
          OTHERS          3.

      READ TABLE lt_return ASSIGNING FIELD-SYMBOL(<lw_ret>INDEX 1.
      IF sy-subrc 0.
        READ TABLE lt_mchb ASSIGNING FIELD-SYMBOL(<lw_mchb>)
        WITH KEY charg <lw_ret>-fieldval.
        IF sy-subrc 0.

          DATAlw_dynp TYPE dynpread,
                lt_dynp TYPE TABLE OF dynpread.

          "--Based on the line no. Plant & Storage are populated
          lw_dynp-stepl lv_line.
          lw_dynp-fieldname  'MSEG-WERKS'.
          lw_dynp-fieldvalue <lw_mchb>-werks.
          APPEND lw_dynp TO lt_dynpCLEAR lw_dynp.

          lw_dynp-stepl lv_line.
          lw_dynp-fieldname  'MSEG-LGORT'.
          lw_dynp-fieldvalue <lw_mchb>-lgort.
          APPEND lw_dynp TO lt_dynpCLEAR lw_dynp.

          lw_dynp-stepl lv_line.
          lw_dynp-fieldname  'BATCH'.
          lw_dynp-fieldvalue <lw_mchb>-charg.
          APPEND lw_dynp TO lt_dynpCLEAR lw_dynp.

          "--It will start the Before Output event
          "--where the required fields are updated
          CALL FUNCTION 'DYNP_VALUES_UPDATE'
            EXPORTING
              dyname               sy-cprog
              dynumb               sy-dynnr
            TABLES
              dynpfields           lt_dynp
            EXCEPTIONS
              invalid_abapworkarea 1
              invalid_dynprofield  2
              invalid_dynproname   3
              invalid_dynpronummer 4
              invalid_request      5
              no_fielddescription  6
              undefind_error       7
              OTHERS               8.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

ENDMODULE.


Output:



No comments: