ABAP Select data from SAP table RPBARBA0L 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 RPBARBA0L 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 RPBARBA0L. 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 RPBARBA0L 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_RPBARBA0L TYPE STANDARD TABLE OF RPBARBA0L,
      WA_RPBARBA0L TYPE RPBARBA0L,
      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: <RPBARBA0L> TYPE RPBARBA0L.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RPBARBA0L
*  INTO TABLE @DATA(IT_RPBARBA0L2).
*--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_RPBARBA0L INDEX 1 INTO DATA(WA_RPBARBA0L2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RPBARBA0L ASSIGNING <RPBARBA0L>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RPBARBA0L>-MANDT = 1.
<RPBARBA0L>-PERNR = 1.
<RPBARBA0L>-FIRED = 1.
<RPBARBA0L>-AUSST = 1.
<RPBARBA0L>-ZWEIT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RPBARBA0L-HIRED, sy-vline,
WA_RPBARBA0L-FORML, sy-vline,
WA_RPBARBA0L-AUSVL, sy-vline,
WA_RPBARBA0L-AUSVG, sy-vline,
WA_RPBARBA0L-NACHN, sy-vline,
WA_RPBARBA0L-VORNA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RPBARBA0L 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_RPBARBA0L 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_RPBARBA0L INTO WA_RPBARBA0L. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_RPBARBA0L_STR,
MANDT TYPE STRING,
PERNR TYPE STRING,
FIRED TYPE STRING,
AUSST TYPE STRING,
ZWEIT TYPE STRING,
HIRED TYPE STRING,
FORML TYPE STRING,
AUSVL TYPE STRING,
AUSVG TYPE STRING,
NACHN TYPE STRING,
VORNA TYPE STRING,
ADDRE TYPE STRING,
NATIO TYPE STRING,
ENTGB TYPE STRING,
BEALS TYPE STRING,
LEHRV TYPE STRING,
LEHRB TYPE STRING,
ASVGR TYPE STRING,
AUSVA TYPE STRING,
ANSTA TYPE STRING,
GESCH TYPE STRING,
DGSVN TYPE STRING,
AUSTG TYPE STRING,
GRTXT TYPE STRING,
UETAG TYPE STRING,
NIUEG TYPE STRING,
KEVON TYPE STRING,
KEBIS TYPE STRING,
NIKEG TYPE STRING,
BEZBI TYPE STRING,
DGTEL TYPE STRING,
DGADR TYPE STRING,
ADRL1 TYPE STRING,
ADRL2 TYPE STRING,
ADRL3 TYPE STRING,
ADRL4 TYPE STRING,
ADRL5 TYPE STRING,
UNAME TYPE STRING,
DATUM TYPE STRING,
UZEIT TYPE STRING,
TEILV TYPE STRING,
TEILB TYPE STRING,
SVGRANS TYPE STRING,
STATUS TYPE STRING,
ZTABL TYPE STRING,
FRLOS TYPE STRING,
KUEDG TYPE STRING,
KUEDN TYPE STRING,
VORZT TYPE STRING,
ENVST TYPE STRING,
PZTDG TYPE STRING,
PZTDN TYPE STRING,
UGEZA TYPE STRING,
UNGEZ TYPE STRING,
UKANS TYPE STRING,
UKONS TYPE STRING,
UANST TYPE STRING,
UINSV TYPE STRING,
KGEZA TYPE STRING,
KNGEZ TYPE STRING,
KANST TYPE STRING,
KINSV TYPE STRING,
TDSPOOLID TYPE STRING,
AUSVG2_6 TYPE STRING,
P_TEST TYPE STRING,END OF T_EKKO_STR. DATA: WA_RPBARBA0L_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_RPBARBA0L_STR-MANDT sy-vline
WA_RPBARBA0L_STR-PERNR sy-vline
WA_RPBARBA0L_STR-FIRED sy-vline
WA_RPBARBA0L_STR-AUSST sy-vline
WA_RPBARBA0L_STR-ZWEIT sy-vline
WA_RPBARBA0L_STR-HIRED sy-vline
WA_RPBARBA0L_STR-FORML sy-vline
WA_RPBARBA0L_STR-AUSVL sy-vline
WA_RPBARBA0L_STR-AUSVG sy-vline
WA_RPBARBA0L_STR-NACHN sy-vline
WA_RPBARBA0L_STR-VORNA sy-vline
WA_RPBARBA0L_STR-ADDRE sy-vline
WA_RPBARBA0L_STR-NATIO sy-vline
WA_RPBARBA0L_STR-ENTGB sy-vline
WA_RPBARBA0L_STR-BEALS sy-vline
WA_RPBARBA0L_STR-LEHRV sy-vline
WA_RPBARBA0L_STR-LEHRB sy-vline
WA_RPBARBA0L_STR-ASVGR sy-vline
WA_RPBARBA0L_STR-AUSVA sy-vline
WA_RPBARBA0L_STR-ANSTA sy-vline
WA_RPBARBA0L_STR-GESCH sy-vline
WA_RPBARBA0L_STR-DGSVN sy-vline
WA_RPBARBA0L_STR-AUSTG sy-vline
WA_RPBARBA0L_STR-GRTXT sy-vline
WA_RPBARBA0L_STR-UETAG sy-vline
WA_RPBARBA0L_STR-NIUEG sy-vline
WA_RPBARBA0L_STR-KEVON sy-vline
WA_RPBARBA0L_STR-KEBIS sy-vline
WA_RPBARBA0L_STR-NIKEG sy-vline
WA_RPBARBA0L_STR-BEZBI sy-vline
WA_RPBARBA0L_STR-DGTEL sy-vline
WA_RPBARBA0L_STR-DGADR sy-vline
WA_RPBARBA0L_STR-ADRL1 sy-vline
WA_RPBARBA0L_STR-ADRL2 sy-vline
WA_RPBARBA0L_STR-ADRL3 sy-vline
WA_RPBARBA0L_STR-ADRL4 sy-vline
WA_RPBARBA0L_STR-ADRL5 sy-vline
WA_RPBARBA0L_STR-UNAME sy-vline
WA_RPBARBA0L_STR-DATUM sy-vline
WA_RPBARBA0L_STR-UZEIT sy-vline
WA_RPBARBA0L_STR-TEILV sy-vline
WA_RPBARBA0L_STR-TEILB sy-vline
WA_RPBARBA0L_STR-SVGRANS sy-vline
WA_RPBARBA0L_STR-STATUS sy-vline
WA_RPBARBA0L_STR-ZTABL sy-vline
WA_RPBARBA0L_STR-FRLOS sy-vline
WA_RPBARBA0L_STR-KUEDG sy-vline
WA_RPBARBA0L_STR-KUEDN sy-vline
WA_RPBARBA0L_STR-VORZT sy-vline
WA_RPBARBA0L_STR-ENVST sy-vline
WA_RPBARBA0L_STR-PZTDG sy-vline
WA_RPBARBA0L_STR-PZTDN sy-vline
WA_RPBARBA0L_STR-UGEZA sy-vline
WA_RPBARBA0L_STR-UNGEZ sy-vline
WA_RPBARBA0L_STR-UKANS sy-vline
WA_RPBARBA0L_STR-UKONS sy-vline
WA_RPBARBA0L_STR-UANST sy-vline
WA_RPBARBA0L_STR-UINSV sy-vline
WA_RPBARBA0L_STR-KGEZA sy-vline
WA_RPBARBA0L_STR-KNGEZ sy-vline
WA_RPBARBA0L_STR-KANST sy-vline
WA_RPBARBA0L_STR-KINSV sy-vline
WA_RPBARBA0L_STR-TDSPOOLID sy-vline
WA_RPBARBA0L_STR-AUSVG2_6 sy-vline
WA_RPBARBA0L_STR-P_TEST sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.