Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Determining field length


I have a delimited file (seperated by #). There are about 40 fields in each record of the file, which are separated by # as mentioned above.Please note that it is not necessary that each of these fields be populated, which means that some fields might be left blank.

I have a requirement of validating the length of the 35th field, as to whether it exceeds a certain length (20 in this case).

Can anyone suggest how can i determine the length of the field, especially when we dont know whether the previous fields are filled or empty, which makes it impossible to determine the correct offset for the 35th field.

I have tried using the SPLIT command, and SY-SUBRC is set to 4 if any of the fields exceed the specified length. but i dont know WHICH field is exceeding its length. this is what i want to know precisely.




Edited by: Alvaro Tejada Galindo on Mar 19, 2008 5:10 PM

Former Member
Former Member replied

Well firstly,you need to find out the value of the hexa-decimal character. Second if you are on Non-Unicode enabled system you can define a variable with the same value of type X, On unicode enabled system you might want to use predefined characters. As in Chandra's example he has used the same for TAB Character. Useful class for the same is CL_ABAP_CHAR_UTILITIES. As per what i understand, you need to find the length of the 35th field and considering "#" represents TAB Character, check below example:

DATA: str TYPE string,
      itab TYPE TABLE OF string,
      wa TYPE string,
      len TYPE i.
" Use the Definition as per your system(UNICODE/NON-UNICODE)
* Unicode system definition
DATA: tab TYPE char1 VALUE cl_abap_char_utilities=>horizontal_tab.  " TAB Character

* Non-Unicide System
DATA: tab(1) TYPE x VALUE '09'.  " TAB Character

IF sy-subrc NE 0.
   SPLIT str AT tab INTO TABLE itab.
   READ TABLE itab INTO wa INDEX 35.  " Fetch Contents of 35th Field
   IF sy-subrc EQ 0.
      CLEAR len.
      len = STRLEN( wa ).
      IF len > 20.
         " Error Message
         " Required Action

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question