banner ads

Table Control with Uploading from Clip Board

Table Control with Uploading from Clip Board

Sometimes we just need to copy & paste a lot of records into table control. 
Now table control lines are specific (say 13 lines) as per design level. 
If we want to paste more lines (say 100) into this table control then it will not happen.
 In this case the system will paste only first 13 lines into the table control which is visible though the copy 
is there (RAM). At this point we need to paste total 100 lines into that table control.

We cannot achieve this by just paste (ctrl + v) option. Here we create a button by which we shall achieve 
this purpose. This button functions exactly like ‘Upload from Clip Board’ which is standard. Here we need to call method: cl_gui_frontend_services=>clipboard_import

This method generates an internal table which contains the total copy data. If we select only one 
field then the table will have only one field. If we select more than one field then internal table will
 have more than one field. Hence the table structure depends on the selected copy.


In the following example we just create a table control.

INCLUDE ztabc_top                               .  " global Data
INCLUDE ztabc_o01                               .  " PBO-Modules
INCLUDE ztabc_i01                               .  " PAI-Modules
INCLUDE ztabc_f01                               .  " FORM-Routines 

Top Include:

TABLESzsd_pallet_ser.
TYPESBEGIN OF ty_ser,
         sernr TYPE zsd_pallet_ser-sernr,
       END OF ty_ser.
DATAwa_ser TYPE ty_ser,
      it_ser TYPE TABLE OF ty_ser.

DATAok_code_9000 TYPE sy-ucomm.

CONTROLStabc_9000 TYPE TABLEVIEW USING SCREEN 9000.

PBO Include:

MODULE status_9000 OUTPUT.
  SET PF-STATUS 'PF_9000'.
  SET TITLEBAR 'T_9000'.
ENDMODULE.

MODULE tabc_9000_pbo OUTPUT.

  DESCRIBE TABLE it_ser LINES sy-dbcnt.
  tabc_9000-current_line sy-loopc.
  tabc_9000-lines sy-dbcnt.

  zsd_pallet_ser-sernr wa_ser-sernr.

ENDMODULE.

PAI Include:

MODULE user_command_9000 INPUT.

  CASE ok_code_9000.
    WHEN 'BACK'.
      PERFORM back_9000.
    WHEN 'UPL'.
      PERFORM upload_data.
  ENDCASE.

ENDMODULE.

MODULE tabc_9000_pai INPUT.

  READ TABLE it_ser INTO wa_ser INDEX tabc_9000-current_line.
  IF sy-subrc 0.
    MODIFY it_ser FROM wa_ser INDEX tabc_9000-current_line.
  ENDIF.

ENDMODULE.

Form Include:

FORM back_9000 .

  CLEARok_code_9000.
  LEAVE PROGRAM.

ENDFORM.

FORM upload_data .

  TYPESBEGIN OF ty_clip,
           data TYPE char18,
         END OF ty_clip.

  DATAit_clip TYPE TABLE OF ty_clip,
        wa_clip TYPE ty_clip.

  CALL METHOD cl_gui_frontend_services=>clipboard_import
    IMPORTING
      data                 it_clip
    EXCEPTIONS
      cntl_error           1
      error_no_gui         2
      not_supported_by_gui 3
      OTHERS               4.

  IF sy-subrc 0.
    LOOP AT it_clip INTO wa_clip.
      wa_ser-sernr wa_clip-data.
      APPEND wa_ser TO it_ser.
      CLEARwa_serwa_clip.
    ENDLOOP.
  ENDIF.

  CLEAR ok_code_9000.

ENDFORM.

Here we have generated the internal table by that method and then populate the table control’s internal table. 
To avoid duplicate entries we just clear the OK code inside there.

Now create a T-code and execute it. The table control will look like follows.
 We have created an upload button to copy from clipboard. In the visible section we have only 13 rows.


Now from excel we have selected 25 rows and copy (ctrl + c) it.


Now go to SAP screen and click on UPLOAD button. The 25 rows have been inserted and only 13 rows 
are visible because of table control design.


Now we scroll and check whether the purpose got successful or not.



No comments