Friday, May 15, 2026

abap dbf other idea

 *-- 1. Define your internal table structure (All fields MUST be type C)

DATA: BEGIN OF ty_record,

        field1(10) TYPE c, " Length 10

        field2(5)  TYPE c, " Length 5

        field3(8)  TYPE c, " Length 8

      END OF ty_record.


DATA: itab LIKE ty_record OCCURS 0 WITH HEADER LINE.


*-- 2. Variables for file reading

DATA: lv_header_size TYPE i,

      lv_record_size TYPE i,

      lv_dummy(2000) TYPE c, " Large buffer to skip header

      lv_buffer(1000) TYPE c. " Must match your exact DBF record size


*-- 3. Calculate your offsets manually based on DBF layout

*-- Remember: The first byte of every DBF record is the 1-byte "Deleted Flag"

lv_record_size = 24. " Example: 1 (flag) + 10 + 5 + 8 = 24 bytes

lv_header_size = 129. " Example: 32 + (32 * 3 fields) + 1 = 129 bytes


*-- 4. Open the file on the Application Server

OPEN DATASET 'your_file.dbf' FOR INPUT IN BINARY MODE.

IF sy-subrc <> 0.

  EXIT.

ENDIF.


*-- 5. Move the file pointer past the header

READ DATASET 'your_file.dbf' INTO lv_dummy MAXIMUM LENGTH lv_header_size.


*-- 6. Loop through the records (approx 70,000 iterations)

DO.

  " Read exactly one record into the flat buffer

  READ DATASET 'your_file.dbf' INTO lv_buffer MAXIMUM LENGTH lv_record_size.

  

  " Exit the loop if End of File is reached or EOF byte (0x1A) is found

  IF sy-subrc <> 0 OR lv_buffer(1) =  '#'. " Use hex representation of 0x1A if needed

    EXIT.

  ENDIF.


  " Check deleted flag (0x20 / space = active, 0x2A / * = deleted)

  IF lv_buffer(1) = ' '. 

    

    " Use ABAP offsets to slice the flat string into the itab structure

    " Syntax: lv_buffer+OFFSET(LENGTH)

    itab-field1 = lv_buffer+1(10).  " Skip byte 0 (deleted flag), take 10 bytes

    itab-field2 = lv_buffer+11(5). " Offset is 1 + 10 = 11, take 5 bytes

    itab-field3 = lv_buffer+16(8). " Offset is 11 + 5 = 16, take 8 bytes

    

    APPEND itab.

  ENDIF.

ENDDO.


CLOSE DATASET 'your_file.dbf'.


No comments:

Post a Comment

Dbf не чіпаємо, маніпуляції тільки з itab

 1. Dbf tab містить ВСІ 67-68 полів,  Ztab - тільки ті 25-45 полів що використовуються в продовженні ресурсів, їх і копіюємо Dbf не редагува...