ABAP Select data from SAP table N0FDBS0000000000 into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP N0FDBS0000000000 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to N0FDBS0000000000. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the N0FDBS0000000000 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_N0FDBS0000000000 TYPE STANDARD TABLE OF N0FDBS0000000000,
      WA_N0FDBS0000000000 TYPE N0FDBS0000000000,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <N0FDBS0000000000> TYPE N0FDBS0000000000.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_N0FDBS0000000000.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM N0FDBS0000000000
  INTO TABLE IT_N0FDBS0000000000.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM N0FDBS0000000000
*  INTO TABLE @DATA(IT_N0FDBS00000000002).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_N0FDBS0000000000 INDEX 1 INTO DATA(WA_N0FDBS00000000002).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_N0FDBS0000000000 ASSIGNING <N0FDBS0000000000>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<N0FDBS0000000000>-MANDT = 1.
<N0FDBS0000000000>-DOKAR = 1.
<N0FDBS0000000000>-DOKNR = 1.
<N0FDBS0000000000>-DOKVR = 1.
<N0FDBS0000000000>-DOKTL = 1.
ENDLOOP.

LOOP AT IT_N0FDBS0000000000 INTO WA_N0FDBS0000000000.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_N0FDBS0000000000-ISHMPATDAT, sy-vline,
WA_N0FDBS0000000000-ISHMPATNAM, sy-vline,
WA_N0FDBS0000000000-ISHMPATANR, sy-vline,
WA_N0FDBS0000000000-ISHMPATTIT, sy-vline,
WA_N0FDBS0000000000-ISHMPATNNA, sy-vline,
WA_N0FDBS0000000000-ISHMPATVNA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_N0FDBS0000000000 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_N0FDBS0000000000 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_N0FDBS0000000000 INTO WA_N0FDBS0000000000. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit ALPHA, internal->external for field DOKNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-DOKNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-DOKNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATNUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATUVN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATUVN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATUVN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATKVN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATKVN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATKVN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATFAL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATFAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATFAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATFBK CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATFBK IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATFBK.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATENR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATENR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATFOE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATFOE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATFOE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATPOE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATPOE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATPOE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATLOE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATLOE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATLOE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATAFO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATAFO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATAFO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATAPO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATAPO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATAPO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMPATDOE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMPATDOE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMPATDOE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMUNFNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMUNFNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMUNFNUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMUNFRTN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMUNFRTN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMUNFRTN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ISHMVMAKRZ CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-ISHMVMAKRZ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-ISHMVMAKRZ.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field X00MVMAKRZ CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_N0FDBS0000000000-X00MVMAKRZ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_N0FDBS0000000000-X00MVMAKRZ.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_N0FDBS0000000000_STR,
MANDT TYPE STRING,
DOKAR TYPE STRING,
DOKNR TYPE STRING,
DOKVR TYPE STRING,
DOKTL TYPE STRING,
ISHMPATDAT TYPE STRING,
ISHMPATNAM TYPE STRING,
ISHMPATANR TYPE STRING,
ISHMPATTIT TYPE STRING,
ISHMPATNNA TYPE STRING,
ISHMPATVNA TYPE STRING,
ISHMPATZNA TYPE STRING,
ISHMPATGES TYPE STRING,
ISHMPATGST TYPE STRING,
ISHMPATGEB TYPE STRING,
ISHMPATNUM TYPE STRING,
ISHMPATP01 TYPE STRING,
ISHMPATBER TYPE STRING,
ISHMPATNAT TYPE STRING,
ISHMPATALT TYPE STRING,
ISHMPATALE TYPE STRING,
ISHMPATLAN TYPE STRING,
ISHMPATPLZ TYPE STRING,
ISHMPATORT TYPE STRING,
ISHMPATOR2 TYPE STRING,
ISHMPATSTR TYPE STRING,
ISHMPATTEL TYPE STRING,
ISHMPATADR TYPE STRING,
ISHMPATAGA TYPE STRING,
ISHMPATAGN TYPE STRING,
ISHMPATAGL TYPE STRING,
ISHMPATAGP TYPE STRING,
ISHMPATAGO TYPE STRING,
ISHMPATAGS TYPE STRING,
ISHMPATAGT TYPE STRING,
ISHMPATUVT TYPE STRING,
ISHMPATUVN TYPE STRING,
ISHMPATKVN TYPE STRING,
ISHMPATKVT TYPE STRING,
ISHMPATKVK TYPE STRING,
ISHMPATKVL TYPE STRING,
ISHMPATFAL TYPE STRING,
ISHMPATF01 TYPE STRING,
ISHMPATFAR TYPE STRING,
ISHMPATFAT TYPE STRING,
ISHMPATFBK TYPE STRING,
ISHMPATADT TYPE STRING,
ISHMPATAZT TYPE STRING,
ISHMPATAPL TYPE STRING,
ISHMPATEDT TYPE STRING,
ISHMPATEZT TYPE STRING,
ISHMPATEPL TYPE STRING,
ISHMPATENR TYPE STRING,
ISHMPATEKB TYPE STRING,
ISHMPATFOE TYPE STRING,
ISHMPATFOT TYPE STRING,
ISHMPATPOE TYPE STRING,
ISHMPATPOT TYPE STRING,
ISHMPATLOE TYPE STRING,
ISHMPATAFO TYPE STRING,
ISHMPATAPO TYPE STRING,
ISHMPATDOE TYPE STRING,
ISHMPATDOT TYPE STRING,
PERSTAB TYPE STRING,
HAUSARZT TYPE STRING,
X00MHANAM TYPE STRING,
ISHMHANAM TYPE STRING,
ISHMHASTR TYPE STRING,
ISHMHAORT TYPE STRING,
ISHMHAPLZ TYPE STRING,
EINWEISER TYPE STRING,
X00MEANAM TYPE STRING,
ISHMEANAM TYPE STRING,
ISHMEAORT TYPE STRING,
ISHMEAPLZ TYPE STRING,
ISHMEASTR TYPE STRING,
UNFALL TYPE STRING,
ISHMUNFBDT TYPE STRING,
ISHMUNFBZT TYPE STRING,
ISHMUNFNUM TYPE STRING,
ISHMUNFART TYPE STRING,
ISHMUNFDAT TYPE STRING,
ISHMUNFZET TYPE STRING,
ISHMUNFORT TYPE STRING,
ISHMUNFRTN TYPE STRING,
ISHMUNFVER TYPE STRING,
ISHMUNFBEM TYPE STRING,
ISHMUNFLTX TYPE STRING,
UNTERSCHRS TYPE STRING,
ISHMVMAKRZ TYPE STRING,
ISHMVMANAM TYPE STRING,
UNTERSCHR2 TYPE STRING,
X00MVMAKRZ TYPE STRING,
ISHMVMANA2 TYPE STRING,
ISHMVMARNG TYPE STRING,
ISHMVMAFAR TYPE STRING,
X01MVMAKRZ TYPE STRING,
X00MVMANA2 TYPE STRING,
X02MVMAKRZ TYPE STRING,
X00MVMANAM TYPE STRING,
MITARBEITE TYPE STRING,
ISHMDIATAB TYPE STRING,END OF T_EKKO_STR. DATA: WA_N0FDBS0000000000_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_N0FDBS0000000000_STR-MANDT sy-vline
WA_N0FDBS0000000000_STR-DOKAR sy-vline
WA_N0FDBS0000000000_STR-DOKNR sy-vline
WA_N0FDBS0000000000_STR-DOKVR sy-vline
WA_N0FDBS0000000000_STR-DOKTL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATDAT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATNAM sy-vline
WA_N0FDBS0000000000_STR-ISHMPATANR sy-vline
WA_N0FDBS0000000000_STR-ISHMPATTIT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATNNA sy-vline
WA_N0FDBS0000000000_STR-ISHMPATVNA sy-vline
WA_N0FDBS0000000000_STR-ISHMPATZNA sy-vline
WA_N0FDBS0000000000_STR-ISHMPATGES sy-vline
WA_N0FDBS0000000000_STR-ISHMPATGST sy-vline
WA_N0FDBS0000000000_STR-ISHMPATGEB sy-vline
WA_N0FDBS0000000000_STR-ISHMPATNUM sy-vline
WA_N0FDBS0000000000_STR-ISHMPATP01 sy-vline
WA_N0FDBS0000000000_STR-ISHMPATBER sy-vline
WA_N0FDBS0000000000_STR-ISHMPATNAT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATALT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATALE sy-vline
WA_N0FDBS0000000000_STR-ISHMPATLAN sy-vline
WA_N0FDBS0000000000_STR-ISHMPATPLZ sy-vline
WA_N0FDBS0000000000_STR-ISHMPATORT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATOR2 sy-vline
WA_N0FDBS0000000000_STR-ISHMPATSTR sy-vline
WA_N0FDBS0000000000_STR-ISHMPATTEL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATADR sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGA sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGN sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGP sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGO sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGS sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAGT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATUVT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATUVN sy-vline
WA_N0FDBS0000000000_STR-ISHMPATKVN sy-vline
WA_N0FDBS0000000000_STR-ISHMPATKVT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATKVK sy-vline
WA_N0FDBS0000000000_STR-ISHMPATKVL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFAL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATF01 sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFAR sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFAT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFBK sy-vline
WA_N0FDBS0000000000_STR-ISHMPATADT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAZT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAPL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATEDT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATEZT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATEPL sy-vline
WA_N0FDBS0000000000_STR-ISHMPATENR sy-vline
WA_N0FDBS0000000000_STR-ISHMPATEKB sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFOE sy-vline
WA_N0FDBS0000000000_STR-ISHMPATFOT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATPOE sy-vline
WA_N0FDBS0000000000_STR-ISHMPATPOT sy-vline
WA_N0FDBS0000000000_STR-ISHMPATLOE sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAFO sy-vline
WA_N0FDBS0000000000_STR-ISHMPATAPO sy-vline
WA_N0FDBS0000000000_STR-ISHMPATDOE sy-vline
WA_N0FDBS0000000000_STR-ISHMPATDOT sy-vline
WA_N0FDBS0000000000_STR-PERSTAB sy-vline
WA_N0FDBS0000000000_STR-HAUSARZT sy-vline
WA_N0FDBS0000000000_STR-X00MHANAM sy-vline
WA_N0FDBS0000000000_STR-ISHMHANAM sy-vline
WA_N0FDBS0000000000_STR-ISHMHASTR sy-vline
WA_N0FDBS0000000000_STR-ISHMHAORT sy-vline
WA_N0FDBS0000000000_STR-ISHMHAPLZ sy-vline
WA_N0FDBS0000000000_STR-EINWEISER sy-vline
WA_N0FDBS0000000000_STR-X00MEANAM sy-vline
WA_N0FDBS0000000000_STR-ISHMEANAM sy-vline
WA_N0FDBS0000000000_STR-ISHMEAORT sy-vline
WA_N0FDBS0000000000_STR-ISHMEAPLZ sy-vline
WA_N0FDBS0000000000_STR-ISHMEASTR sy-vline
WA_N0FDBS0000000000_STR-UNFALL sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFBDT sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFBZT sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFNUM sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFART sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFDAT sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFZET sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFORT sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFRTN sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFVER sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFBEM sy-vline
WA_N0FDBS0000000000_STR-ISHMUNFLTX sy-vline
WA_N0FDBS0000000000_STR-UNTERSCHRS sy-vline
WA_N0FDBS0000000000_STR-ISHMVMAKRZ sy-vline
WA_N0FDBS0000000000_STR-ISHMVMANAM sy-vline
WA_N0FDBS0000000000_STR-UNTERSCHR2 sy-vline
WA_N0FDBS0000000000_STR-X00MVMAKRZ sy-vline
WA_N0FDBS0000000000_STR-ISHMVMANA2 sy-vline
WA_N0FDBS0000000000_STR-ISHMVMARNG sy-vline
WA_N0FDBS0000000000_STR-ISHMVMAFAR sy-vline
WA_N0FDBS0000000000_STR-X01MVMAKRZ sy-vline
WA_N0FDBS0000000000_STR-X00MVMANA2 sy-vline
WA_N0FDBS0000000000_STR-X02MVMAKRZ sy-vline
WA_N0FDBS0000000000_STR-X00MVMANAM sy-vline
WA_N0FDBS0000000000_STR-MITARBEITE sy-vline
WA_N0FDBS0000000000_STR-ISHMDIATAB sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.