Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

write internal table to cluster table

Former Member
0 Likes
486

Hello,

I have the following problem:

i have an internal table with 10000 datasets and I want to write always 100 datasets into a cluster table.

what is the best possibility to split the 10000 into packages of 100? isn't there any other possibility than to loop at the internal table?

thanks!

3 REPLIES 3
Read only

Former Member
0 Likes
454

no other way...

DESCRIBE TABLE lt_component LINES lv_lines.

lv_count = 0.

lv_last = 0.

LOOP AT lt_component INTO lwa_component.

lv_count = lv_count + 1.

lv_last = lv_last + 1.

IF lv_count EQ 1000 OR lv_last EQ lv_lines.

write to table

endif.

endloop.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
454

Hello Margit,

I do not think there is any way other than loop at the table.

Try the code below, it will split your table into datasets of 100 recs. You can then process these individual tables:


TYPES:
  BEGIN OF TY_VBAK,
    VBELN TYPE VBELN_VA,
    VBTYP TYPE VBTYP,
    ERDAT TYPE ERDAT,
  END OF TY_VBAK.

TYPES:
  BEGIN OF TY_DREF,
    DREF TYPE REF TO DATA,
  END OF TY_DREF.

DATA: V_ROWS TYPE I,
      IT_VBAK TYPE STANDARD TABLE OF TY_VBAK,
      WA_VBAK  TYPE TY_VBAK,
      IT_DREF TYPE STANDARD TABLE OF TY_DREF,
      WA_DREF TYPE TY_DREF,
      V_COUNT TYPE I,
      IT_VBAK_TMP TYPE STANDARD TABLE OF TY_VBAK,
      V_FILENAM TYPE STRING.

FIELD-SYMBOLS <FS_TAB> TYPE TABLE.

PARAMETERS:
  P_DATA TYPE NUMC2 DEFAULT '25',
  P_FILE TYPE LOCALFILE DEFAULT
              'C:\Documents and Settings\ssaha\Desktop\'.

START-OF-SELECTION.

  V_ROWS = P_DATA.

  SELECT VBELN VBTYP ERDAT UP TO V_ROWS ROWS
  INTO TABLE IT_VBAK
  FROM VBAK
  WHERE ERDAT <= '20081231'
  OR    ERDAT >  '20080901'.

  LOOP AT IT_VBAK INTO WA_VBAK.
    V_COUNT = V_COUNT + 1.
    APPEND WA_VBAK TO IT_VBAK_TMP.
    CLEAR WA_VBAK .

    IF V_COUNT = 100. "This is where you split the parent table into smaller tables
      CREATE DATA WA_DREF-DREF TYPE STANDARD TABLE OF TY_VBAK.
      APPEND WA_DREF TO IT_DREF.

      ASSIGN WA_DREF-DREF->* TO <FS_TAB>.

      IF <FS_TAB> IS ASSIGNED.
        <FS_TAB> = IT_VBAK_TMP.
      ENDIF.

      CLEAR: V_COUNT, WA_DREF.
      REFRESH IT_VBAK_TMP.
    ENDIF.

    AT LAST.
      CREATE DATA WA_DREF-DREF TYPE STANDARD TABLE OF TY_VBAK.
      APPEND WA_DREF TO IT_DREF.

      ASSIGN WA_DREF-DREF->* TO <FS_TAB>.

      IF <FS_TAB> IS ASSIGNED.
        <FS_TAB> = IT_VBAK_TMP.
      ENDIF.

      CLEAR: V_COUNT, WA_DREF.
      REFRESH IT_VBAK_TMP.
    ENDAT.

  ENDLOOP.

END-OF-SELECTION.

  BREAK SSAHA.

  LOOP AT IT_DREF INTO WA_DREF.
    ASSIGN WA_DREF-DREF->* TO <FS_TAB>.

    IF <FS_TAB> IS ASSIGNED.

      WRITE: / 'SPLIT TABLE'.

      LOOP AT <FS_TAB> INTO WA_VBAK.
        WRITE: / WA_VBAK.
      ENDLOOP.

      CONCATENATE P_FILE SY-DATUM SY-UZEIT '.txt' INTO V_FILENAM.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                = V_FILENAM
          WRITE_FIELD_SEPARATOR   = 'X'
        TABLES
          DATA_TAB                = <FS_TAB>
        EXCEPTIONS
          FILE_WRITE_ERROR        = 1
          NO_BATCH                = 2
          GUI_REFUSE_FILETRANSFER = 3
          INVALID_TYPE            = 4
          NO_AUTHORITY            = 5
          UNKNOWN_ERROR           = 6
          HEADER_NOT_ALLOWED      = 7
          SEPARATOR_NOT_ALLOWED   = 8
          FILESIZE_NOT_ALLOWED    = 9
          HEADER_TOO_LONG         = 10
          DP_ERROR_CREATE         = 11
          DP_ERROR_SEND           = 12
          DP_ERROR_WRITE          = 13
          UNKNOWN_DP_ERROR        = 14
          ACCESS_DENIED           = 15
          DP_OUT_OF_MEMORY        = 16
          DISK_FULL               = 17
          DP_TIMEOUT              = 18
          FILE_NOT_FOUND          = 19
          DATAPROVIDER_EXCEPTION  = 20
          CONTROL_FLUSH_ERROR     = 21
          OTHERS                  = 22.
      IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDIF.
  ENDLOOP.

Hope this will be of some help.

BR,

Suhas

Read only

Former Member
0 Likes
454

Hi

U can try to use a code like this:

DESCRIBE TABLE ITAB1 LINES TOT_LINE.

IF TOT_LINE <= 100.
  TO_LINE = 100.
ENDIF.
FROM_LINE = 1.

DO.
  APPEND LINES OF ITAB TO ITAB2 FROM FROM_LINE TO TO_LINE.

* Do something.......
  
  FROM_LINE = TO_LINE + 1.
  IF FROM_LINE > TOT_LINE.
    EXIT.
  ENDIF.
  
  TO_LINE = TO_LINE + 100.
  IF TO_LINE > TOT_LINE.
    TO_LINE = TOT_LINE.
  ENDIF.
  
  REFRESH ITAB2.
ENDDO.

Max